You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ki...@apache.org on 2013/01/29 07:24:37 UTC
[35/36] git commit: Add sync entry to region_sunc table on region api
failure
Add sync entry to region_sunc table on region api failure
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/158ee8b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/158ee8b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/158ee8b2
Branch: refs/heads/regions
Commit: 158ee8b2fa0d7984229c7e647a15a003ea084017
Parents: ea660cd
Author: Kishan Kavala <ki...@cloud.com>
Authored: Tue Jan 29 11:49:23 2013 +0530
Committer: Kishan Kavala <ki...@cloud.com>
Committed: Tue Jan 29 11:49:23 2013 +0530
----------------------------------------------------------------------
.../configuration/DefaultComponentLibrary.java | 2 +
.../src/com/cloud/region/FindDomainResponse.java | 36 --------------
server/src/com/cloud/region/FindUserResponse.java | 34 -------------
server/src/com/cloud/region/RegionManagerImpl.java | 14 ++++++
server/src/com/cloud/region/RegionsApiUtil.java | 37 ++-------------
setup/db/create-schema.sql | 9 ++++
6 files changed, 29 insertions(+), 103 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/158ee8b2/server/src/com/cloud/configuration/DefaultComponentLibrary.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java
index ee70b55..9fcfb81 100755
--- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java
+++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java
@@ -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
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/158ee8b2/server/src/com/cloud/region/FindDomainResponse.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/region/FindDomainResponse.java b/server/src/com/cloud/region/FindDomainResponse.java
deleted file mode 100644
index 075bcf2..0000000
--- a/server/src/com/cloud/region/FindDomainResponse.java
+++ /dev/null
@@ -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;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/158ee8b2/server/src/com/cloud/region/FindUserResponse.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/region/FindUserResponse.java b/server/src/com/cloud/region/FindUserResponse.java
deleted file mode 100644
index b6eba46..0000000
--- a/server/src/com/cloud/region/FindUserResponse.java
+++ /dev/null
@@ -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;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/158ee8b2/server/src/com/cloud/region/RegionManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/region/RegionManagerImpl.java b/server/src/com/cloud/region/RegionManagerImpl.java
index a2a79e4..988231e 100755
--- a/server/src/com/cloud/region/RegionManagerImpl.java
+++ b/server/src/com/cloud/region/RegionManagerImpl.java
@@ -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);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/158ee8b2/server/src/com/cloud/region/RegionsApiUtil.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/region/RegionsApiUtil.java b/server/src/com/cloud/region/RegionsApiUtil.java
index 3e20fd3..a7c7137 100644
--- a/server/src/com/cloud/region/RegionsApiUtil.java
+++ b/server/src/com/cloud/region/RegionsApiUtil.java
@@ -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;
}
}
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/158ee8b2/setup/db/create-schema.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index 31f6d78..2a6dc1a 100755
--- a/setup/db/create-schema.sql
+++ b/setup/db/create-schema.sql
@@ -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());