Skip to content

Commit 158ee8b

Browse files
author
Kishan Kavala
committed
Add sync entry to region_sunc table on region api failure
1 parent ea660cd commit 158ee8b

6 files changed

Lines changed: 29 additions & 103 deletions

File tree

‎server/src/com/cloud/configuration/DefaultComponentLibrary.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
import com.cloud.projects.dao.ProjectInvitationDaoImpl;
161161
import com.cloud.region.RegionManagerImpl;
162162
import com.cloud.region.dao.RegionDaoImpl;
163+
import com.cloud.region.dao.RegionSyncDaoImpl;
163164
import com.cloud.resource.ResourceManagerImpl;
164165
import com.cloud.resourcelimit.ResourceLimitManagerImpl;
165166
import com.cloud.service.dao.ServiceOfferingDaoImpl;
@@ -401,6 +402,7 @@ protected void populateDaos() {
401402
addDao("DiskOfferingJoinDao", DiskOfferingJoinDaoImpl.class);
402403
addDao("ServiceOfferingJoinDao", ServiceOfferingJoinDaoImpl.class);
403404
addDao("DataCenterJoinDao", DataCenterJoinDaoImpl.class);
405+
addDao("RegionSyncDao", RegionSyncDaoImpl.class);
404406
}
405407

406408
@Override

‎server/src/com/cloud/region/FindDomainResponse.java‎

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎server/src/com/cloud/region/FindUserResponse.java‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎server/src/com/cloud/region/RegionManagerImpl.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.cloud.exception.InvalidParameterValueException;
4040
import com.cloud.exception.ResourceUnavailableException;
4141
import com.cloud.region.dao.RegionDao;
42+
import com.cloud.region.dao.RegionSyncDao;
4243
import com.cloud.user.Account;
4344
import com.cloud.user.AccountManager;
4445
import com.cloud.user.AccountVO;
@@ -73,6 +74,8 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
7374
private UserAccountDao _userAccountDao;
7475
@Inject
7576
private IdentityDao _identityDao;
77+
@Inject
78+
private RegionSyncDao _regionSyncDao;
7679

7780
private String _name;
7881
private int _id;
@@ -195,6 +198,7 @@ public boolean propogateAddAccount(String userName, String password, String firs
195198
if (RegionsApiUtil.makeAPICall(region, command, params)) {
196199
s_logger.debug("Successfully added account :"+accountName+" to Region: "+region.getId());
197200
} else {
201+
addRegionSyncItem(region.getId(), command, params);
198202
s_logger.error("Error while Adding account :"+accountName+" to Region: "+region.getId());
199203
}
200204
}
@@ -737,6 +741,7 @@ public void propogateAddUser(String userName, String password,
737741
if (RegionsApiUtil.makeAPICall(region, command, params)) {
738742
s_logger.debug("Successfully added user :"+userName+" to Region: "+region.getId());
739743
} else {
744+
addRegionSyncItem(region.getId(), command, params);
740745
s_logger.error("Error while Adding user :"+userName+" to Region: "+region.getId());
741746
}
742747
}
@@ -768,10 +773,19 @@ public void propogateAddDomain(String name, Long parentId, String networkDomain,
768773
if (RegionsApiUtil.makeAPICall(region, command, params)) {
769774
s_logger.debug("Successfully added domain :"+name+" to Region: "+region.getId());
770775
} else {
776+
addRegionSyncItem(region.getId(), command, params);
771777
s_logger.error("Error while Adding domain :"+name+" to Region: "+region.getId());
772778
}
773779
}
774780
return;
775781
}
782+
783+
private void addRegionSyncItem(int regionId, String command, List<NameValuePair> params){
784+
String api = RegionsApiUtil.buildParams(command, params);
785+
RegionSyncVO sync = new RegionSyncVO(regionId, api);
786+
if(_regionSyncDao.persist(sync) == null){
787+
s_logger.error("Failed to add Region Sync Item. RegionId: "+regionId + "API command: "+api);
788+
}
789+
}
776790

777791
}

‎server/src/com/cloud/region/RegionsApiUtil.java‎

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,19 @@
3838
import org.apache.commons.httpclient.methods.GetMethod;
3939
import org.apache.log4j.Logger;
4040

41-
import com.cloud.domain.Domain;
4241
import com.cloud.domain.DomainVO;
43-
import com.cloud.user.Account;
44-
import com.cloud.user.AccountVO;
4542
import com.cloud.user.UserAccount;
4643
import com.cloud.user.UserAccountVO;
4744
import com.thoughtworks.xstream.XStream;
48-
import com.thoughtworks.xstream.converters.extended.ISO8601DateConverter;
4945
import com.thoughtworks.xstream.io.xml.DomDriver;
5046

5147
public class RegionsApiUtil {
5248
public static final Logger s_logger = Logger.getLogger(RegionsApiUtil.class);
5349

5450
protected static boolean makeAPICall(Region region, String command, List<NameValuePair> params){
5551
try {
56-
String url = buildUrl(buildParams(command, params), region);
52+
String apiParams = buildParams(command, params);
53+
String url = buildUrl(apiParams, region);
5754
HttpClient client = new HttpClient();
5855
HttpMethod method = new GetMethod(url);
5956
if( client.executeMethod(method) == 200){
@@ -160,34 +157,7 @@ protected static UserAccount makeUserAccountAPICall(Region region, String comman
160157
}
161158
}
162159

163-
protected static RegionUser makeUserAPICall(Region region, String command, List<NameValuePair> params){
164-
try {
165-
String url = buildUrl(buildParams(command, params), region);
166-
HttpClient client = new HttpClient();
167-
HttpMethod method = new GetMethod(url);
168-
if( client.executeMethod(method) == 200){
169-
InputStream is = method.getResponseBodyAsStream();
170-
XStream xstream = new XStream(new DomDriver());
171-
xstream.alias("finduserresponse", FindUserResponse.class);
172-
xstream.alias("user", RegionUser.class);
173-
xstream.aliasField("id", RegionUser.class, "uuid");
174-
xstream.aliasField("accountId", RegionUser.class, "accountUuid");
175-
xstream.registerConverter(new ISO8601DateConverter());
176-
FindUserResponse response = (FindUserResponse)xstream.fromXML(is);
177-
return response.getUser();
178-
} else {
179-
return null;
180-
}
181-
} catch (HttpException e) {
182-
s_logger.error(e.getMessage());
183-
return null;
184-
} catch (IOException e) {
185-
s_logger.error(e.getMessage());
186-
return null;
187-
}
188-
}
189-
190-
private static String buildParams(String command, List<NameValuePair> params) {
160+
protected static String buildParams(String command, List<NameValuePair> params) {
191161
StringBuffer paramString = new StringBuffer("command="+command);
192162
Iterator<NameValuePair> iter = params.iterator();
193163
try {
@@ -282,4 +252,5 @@ private static String signRequest(String request, String key) {
282252
return null;
283253
}
284254
}
255+
285256
}

‎setup/db/create-schema.sql‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,15 @@ CREATE TABLE `cloud`.`autoscale_vmgroup_policy_map` (
25512551
INDEX `i_autoscale_vmgroup_policy_map__vmgroup_id`(`vmgroup_id`)
25522552
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
25532553

2554+
CREATE TABLE `cloud`.`region_sync` (
2555+
`id` bigint unsigned NOT NULL auto_increment,
2556+
`region_id` int unsigned NOT NULL,
2557+
`api` varchar(1024) NOT NULL,
2558+
`created` datetime NOT NULL COMMENT 'date created',
2559+
`processed` tinyint NOT NULL default '0',
2560+
PRIMARY KEY (`id`)
2561+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2562+
25542563
INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (1, UUID(), 'snmp','Linux User CPU - percentage', '1.3.6.1.4.1.2021.11.9.0', now());
25552564
INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (2, UUID(), 'snmp','Linux System CPU - percentage', '1.3.6.1.4.1.2021.11.10.0', now());
25562565
INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (3, UUID(), 'snmp','Linux CPU Idle - percentage', '1.3.6.1.4.1.2021.11.11.0', now());

0 commit comments

Comments
 (0)