Add sync entry to region_sunc table on region api failure

This commit is contained in:
Kishan Kavala 2013-01-29 11:49:23 +05:30
parent ea660cd06d
commit 158ee8b2fa
6 changed files with 29 additions and 103 deletions

View File

@ -160,6 +160,7 @@ import com.cloud.projects.dao.ProjectDaoImpl;
import com.cloud.projects.dao.ProjectInvitationDaoImpl;
import com.cloud.region.RegionManagerImpl;
import com.cloud.region.dao.RegionDaoImpl;
import com.cloud.region.dao.RegionSyncDaoImpl;
import com.cloud.resource.ResourceManagerImpl;
import com.cloud.resourcelimit.ResourceLimitManagerImpl;
import com.cloud.service.dao.ServiceOfferingDaoImpl;
@ -401,6 +402,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
addDao("DiskOfferingJoinDao", DiskOfferingJoinDaoImpl.class);
addDao("ServiceOfferingJoinDao", ServiceOfferingJoinDaoImpl.class);
addDao("DataCenterJoinDao", DataCenterJoinDaoImpl.class);
addDao("RegionSyncDao", RegionSyncDaoImpl.class);
}
@Override

View File

@ -1,36 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
import com.cloud.domain.Domain;
public class FindDomainResponse {
private Domain domain;
public FindDomainResponse(){
}
public Domain getDomain() {
return domain;
}
public void setDomain(Domain domain) {
this.domain = domain;
}
}

View File

@ -1,34 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
public class FindUserResponse {
private RegionUser user;
public FindUserResponse(){
}
public RegionUser getUser() {
return user;
}
public void setUser(RegionUser user) {
this.user = user;
}
}

View File

@ -39,6 +39,7 @@ import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.region.dao.RegionDao;
import com.cloud.region.dao.RegionSyncDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO;
@ -73,6 +74,8 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
private UserAccountDao _userAccountDao;
@Inject
private IdentityDao _identityDao;
@Inject
private RegionSyncDao _regionSyncDao;
private String _name;
private int _id;
@ -195,6 +198,7 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
if (RegionsApiUtil.makeAPICall(region, command, params)) {
s_logger.debug("Successfully added account :"+accountName+" to Region: "+region.getId());
} else {
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding account :"+accountName+" to Region: "+region.getId());
}
}
@ -737,6 +741,7 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
if (RegionsApiUtil.makeAPICall(region, command, params)) {
s_logger.debug("Successfully added user :"+userName+" to Region: "+region.getId());
} else {
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding user :"+userName+" to Region: "+region.getId());
}
}
@ -768,10 +773,19 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
if (RegionsApiUtil.makeAPICall(region, command, params)) {
s_logger.debug("Successfully added domain :"+name+" to Region: "+region.getId());
} else {
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding domain :"+name+" to Region: "+region.getId());
}
}
return;
}
private void addRegionSyncItem(int regionId, String command, List<NameValuePair> params){
String api = RegionsApiUtil.buildParams(command, params);
RegionSyncVO sync = new RegionSyncVO(regionId, api);
if(_regionSyncDao.persist(sync) == null){
s_logger.error("Failed to add Region Sync Item. RegionId: "+regionId + "API command: "+api);
}
}
}

View File

@ -38,14 +38,10 @@ import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.log4j.Logger;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.user.Account;
import com.cloud.user.AccountVO;
import com.cloud.user.UserAccount;
import com.cloud.user.UserAccountVO;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.extended.ISO8601DateConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class RegionsApiUtil {
@ -53,7 +49,8 @@ public class RegionsApiUtil {
protected static boolean makeAPICall(Region region, String command, List<NameValuePair> params){
try {
String url = buildUrl(buildParams(command, params), region);
String apiParams = buildParams(command, params);
String url = buildUrl(apiParams, region);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
if( client.executeMethod(method) == 200){
@ -160,34 +157,7 @@ public class RegionsApiUtil {
}
}
protected static RegionUser makeUserAPICall(Region region, String command, List<NameValuePair> params){
try {
String url = buildUrl(buildParams(command, params), region);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
if( client.executeMethod(method) == 200){
InputStream is = method.getResponseBodyAsStream();
XStream xstream = new XStream(new DomDriver());
xstream.alias("finduserresponse", FindUserResponse.class);
xstream.alias("user", RegionUser.class);
xstream.aliasField("id", RegionUser.class, "uuid");
xstream.aliasField("accountId", RegionUser.class, "accountUuid");
xstream.registerConverter(new ISO8601DateConverter());
FindUserResponse response = (FindUserResponse)xstream.fromXML(is);
return response.getUser();
} else {
return null;
}
} catch (HttpException e) {
s_logger.error(e.getMessage());
return null;
} catch (IOException e) {
s_logger.error(e.getMessage());
return null;
}
}
private static String buildParams(String command, List<NameValuePair> params) {
protected static String buildParams(String command, List<NameValuePair> params) {
StringBuffer paramString = new StringBuffer("command="+command);
Iterator<NameValuePair> iter = params.iterator();
try {
@ -282,4 +252,5 @@ public class RegionsApiUtil {
return null;
}
}
}

View File

@ -2551,6 +2551,15 @@ CREATE TABLE `cloud`.`autoscale_vmgroup_policy_map` (
INDEX `i_autoscale_vmgroup_policy_map__vmgroup_id`(`vmgroup_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`region_sync` (
`id` bigint unsigned NOT NULL auto_increment,
`region_id` int unsigned NOT NULL,
`api` varchar(1024) NOT NULL,
`created` datetime NOT NULL COMMENT 'date created',
`processed` tinyint NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
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());
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());
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());