From 354c56a9887cb1a3bfdfbdfa00ce34bc96ee8037 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Tue, 15 Jan 2013 14:21:44 -0700 Subject: [PATCH 1/8] Summary: Adding apache license headers to various devcloud configs Signed-off-by: Marcus Sorensen 1358284904 -0700 --- tools/devcloud-kvm/devcloud-kvm-advanced.cfg | 19 ++++++++++++++++++ tools/devcloud-kvm/devcloud-kvm.cfg | 20 +++++++++++++++++++ tools/devcloud/devcloud-advanced.cfg | 17 ++++++++++++++++ .../devcloud-advanced_internal-mgt.cfg | 17 ++++++++++++++++ tools/devcloud/devcloud.cfg | 18 +++++++++++++++++ 5 files changed, 91 insertions(+) diff --git a/tools/devcloud-kvm/devcloud-kvm-advanced.cfg b/tools/devcloud-kvm/devcloud-kvm-advanced.cfg index 1110863d848..10cbce00779 100644 --- a/tools/devcloud-kvm/devcloud-kvm-advanced.cfg +++ b/tools/devcloud-kvm/devcloud-kvm-advanced.cfg @@ -1,3 +1,22 @@ +# 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. +# + + { "zones": [ { diff --git a/tools/devcloud-kvm/devcloud-kvm.cfg b/tools/devcloud-kvm/devcloud-kvm.cfg index 47a128fea14..b3f048aac97 100644 --- a/tools/devcloud-kvm/devcloud-kvm.cfg +++ b/tools/devcloud-kvm/devcloud-kvm.cfg @@ -1,3 +1,23 @@ +# 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. +# +# This is a stock devcloud config converted from the file +# tools/devcloud/devcloud.cfg. + { "zones": [ { diff --git a/tools/devcloud/devcloud-advanced.cfg b/tools/devcloud/devcloud-advanced.cfg index cfbc815dc69..75c3a4f7147 100644 --- a/tools/devcloud/devcloud-advanced.cfg +++ b/tools/devcloud/devcloud-advanced.cfg @@ -1,3 +1,20 @@ +# 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. +# # This configuration is meant for running advanced networking, with management server on the laptop. # It requires that the user run a DNS resolver within devcloud via 'apt-get install dnsmasq' diff --git a/tools/devcloud/devcloud-advanced_internal-mgt.cfg b/tools/devcloud/devcloud-advanced_internal-mgt.cfg index e360b6b9e37..a1a8cb54722 100644 --- a/tools/devcloud/devcloud-advanced_internal-mgt.cfg +++ b/tools/devcloud/devcloud-advanced_internal-mgt.cfg @@ -1,3 +1,20 @@ +# 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. +# # This config is designed to run as an advanced network, with management server in devcloud # It also requires an 'apt-get install dnsmasq' to run a resolver in devcloud for internal dns diff --git a/tools/devcloud/devcloud.cfg b/tools/devcloud/devcloud.cfg index 8d296eb7b98..c41f8bcef58 100644 --- a/tools/devcloud/devcloud.cfg +++ b/tools/devcloud/devcloud.cfg @@ -1,3 +1,21 @@ +# 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. +# + { "zones": [ { From f7b8ad5e8bc97c01db7ece539a490e929b050f70 Mon Sep 17 00:00:00 2001 From: Chip Childers Date: Tue, 15 Jan 2013 16:28:16 -0500 Subject: [PATCH 2/8] Updating the RAT exclude list to no longer exclude devcloud .cfg files Signed-off-by: Chip Childers --- pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pom.xml b/pom.xml index f752d266a9d..c440a660322 100644 --- a/pom.xml +++ b/pom.xml @@ -244,10 +244,6 @@ dist/console-proxy/js/jquery.js scripts/vm/systemvm/id_rsa.cloud tools/devcloud/basebuild/puppet-devcloudinitial/files/network.conf - tools/devcloud/devcloud.cfg - tools/devcloud/devcloud-advanced.cfg - tools/devcloud-kvm/devcloud-kvm.cfg - tools/devcloud-kvm/devcloud-kvm-advanced.cfg ui/lib/flot/jquery.colorhelpers.js ui/lib/flot/jquery.flot.crosshair.js ui/lib/flot/jquery.flot.fillbetween.js From 47251b51a7bad37c66c0fa460723ede6a3e7b0a9 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Tue, 15 Jan 2013 14:26:30 -0700 Subject: [PATCH 3/8] Summary: Allow ssh keypairs to be created if developer flag set and user ! cloud Detail: Previously in the code we allowed the configuration to create ssh keypairs and put them in the configuration table so that systemvms could have ssh key auth and work properly if the user was 'cloud' or if the developer configuration item was set to true. It got changed to requiring both the cloud user and the developer flag (using an || on a negative) somwhere along the way. This changes it back to && on a negative to allow us to run as non-cloud users with the dev flag set, and for cloud to deploy properly without the developer flag. Signed-off-by: Marcus Sorensen 1358285190 -0700 --- server/src/com/cloud/server/ConfigurationServerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index b25c63f6d7f..7e5f42445d5 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -549,7 +549,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { String username = System.getProperty("user.name"); Boolean devel = Boolean.valueOf(_configDao.getValue("developer")); - if (!username.equalsIgnoreCase("cloud") || !devel) { + if (!username.equalsIgnoreCase("cloud") && !devel) { s_logger.warn("Systemvm keypairs could not be set. Management server should be run as cloud user, or in development mode."); return; } From c32dbec468b176d4a6019d9e642eb9adc593bf36 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Tue, 15 Jan 2013 14:51:59 -0800 Subject: [PATCH 4/8] CLOUDSTACK-985: Revert "Using different MAC for a pair of redundant routers" The different MAC address for a pair of redundant router have issues when short time network outrage happened. When this happened: 1. BACKUP(r-2) cannot receive the broadcast from MASTER(r-1). 2. Then r-2 would announce it's MASTER after 3 seconds, and send gratuitous ARP to the gateway of public ip(usually a rack router). 3. The gateway of public ip would update it's ARP cache to associate the public ip of the network to the MAC of r-2. 4. In the meantime, r-1 still sending out VRRP broadcast(due to network issue, the broadcast never arrived at r-2), and acting as MASTER. 5. After network outrage, r-2 would receive the higher priority VRRP broadcast from MASTER again, then receded as BACKUP. 6. But the public gateway would still associate public ip with MAC of r-2, thus caused the issue. r-1 would no longer able to receive any packets from public network. And there is no way for r-1 to send gratuitous ARP again, because it's always consider itself as MASTER, no state changed, and no hook existed for receiving lower priority broadcast. So I would revert this change, and introduce another commit to ensure the newly create redundant router would share the same MAC as the first one. This reverts commit 9f257aa60b62f24193bba3f7c902e7779632e01e. --- .../VirtualNetworkApplianceManagerImpl.java | 26 ++++--------------- server/src/com/cloud/vm/dao/NicDao.java | 2 -- server/src/com/cloud/vm/dao/NicDaoImpl.java | 8 ------ 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 492e1dc20b1..c8fd86e821c 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1469,31 +1469,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian offeringId = _offering.getId(); } + PublicIp sourceNatIp = null; + if (publicNetwork) { + sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); + } + // 3) deploy virtual router(s) int count = routerCount - routers.size(); DeploymentPlan plan = planAndRouters.first(); for (int i = 0; i < count; i++) { - PublicIp sourceNatIp = null; - if (publicNetwork) { - int failCount = 0; - // Generate different MAC for VR - while (sourceNatIp == null) { - sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); - NicVO nic = _nicDao.findByMacAddress(sourceNatIp.getMacAddress()); - // We got duplicate MAC here, so regenerate the mac - if (nic != null) { - s_logger.debug("Failed to find a different mac for redundant router. Try again. The current mac is " + sourceNatIp.getMacAddress()); - sourceNatIp = null; - failCount ++; - } - //Prevent infinite loop - if (failCount > 3) { - s_logger.error("Failed to find a different mac for redundant router! Abort operation!"); - throw new InsufficientAddressCapacityException("Failed to find a different mac for redundant router", null, offeringId); - } - } - } - List> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork, new Pair(publicNetwork, sourceNatIp)); //don't start the router as we are holding the network lock that needs to be released at the end of router allocation diff --git a/server/src/com/cloud/vm/dao/NicDao.java b/server/src/com/cloud/vm/dao/NicDao.java index af3c7b379c1..762048b65bf 100644 --- a/server/src/com/cloud/vm/dao/NicDao.java +++ b/server/src/com/cloud/vm/dao/NicDao.java @@ -58,6 +58,4 @@ public interface NicDao extends GenericDao { NicVO findByNetworkIdInstanceIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri); NicVO findByIp4AddressAndNetworkIdAndInstanceId(long networkId, long instanceId, String ip4Address); - - NicVO findByMacAddress(String macAddress); } diff --git a/server/src/com/cloud/vm/dao/NicDaoImpl.java b/server/src/com/cloud/vm/dao/NicDaoImpl.java index 00da2eb96a4..3cd7fa6b488 100644 --- a/server/src/com/cloud/vm/dao/NicDaoImpl.java +++ b/server/src/com/cloud/vm/dao/NicDaoImpl.java @@ -50,7 +50,6 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ); AllFieldsSearch.and("isDefault", AllFieldsSearch.entity().isDefaultNic(), Op.EQ); AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ); - AllFieldsSearch.and("macAddress", AllFieldsSearch.entity().getMacAddress(), Op.EQ); AllFieldsSearch.done(); IpSearch = createSearchBuilder(String.class); @@ -200,11 +199,4 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { sc.setParameters("address", ip4Address); return findOneBy(sc); } - - @Override - public NicVO findByMacAddress(String macAddress) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("macAddress", macAddress); - return findOneBy(sc); - } } From 4f889bd426ea841918b570bb008cf5e348715730 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Tue, 15 Jan 2013 15:22:41 -0800 Subject: [PATCH 5/8] CLOUDSTACK-985: Make sure RvR would always have same MAC address Even with newly created RvR using "restartNetwork&cleanup=false" API. --- .../network/router/VirtualNetworkApplianceManagerImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index c8fd86e821c..717da054ac5 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1699,6 +1699,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0); List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); + String publicIp = defaultNic.getIp4Address(); + // We want to use the identical MAC address for RvR on public interface if possible + NicVO peerNic = _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId()); + if (peerNic != null) { + s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress()); + defaultNic.setMacAddress(peerNic.getMacAddress()); + } networks.add(new Pair(publicNetworks.get(0), defaultNic)); } From f6a8b45de52ad57646adb71dc55ddf3ee9dbd194 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Tue, 15 Jan 2013 16:06:21 -0800 Subject: [PATCH 6/8] ApiDiscovery: Use UserContext getCallerUser, do a lazy eval to get account service Impl. and use UserContext to get User. CloudStack's @Inject is horrible, it may sometimes fail to inject account service during startup. Do a lazy injection using ComponentLocator when needed. Signed-off-by: Rohit Yadav --- api/src/com/cloud/user/UserContext.java | 4 ++ .../command/user/discovery/ListApisCmd.java | 8 +--- .../discovery/ApiDiscoveryServiceImpl.java | 41 +++++++++---------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/api/src/com/cloud/user/UserContext.java b/api/src/com/cloud/user/UserContext.java index b140728e596..539e11812af 100644 --- a/api/src/com/cloud/user/UserContext.java +++ b/api/src/com/cloud/user/UserContext.java @@ -50,6 +50,10 @@ public class UserContext { return userId; } + public User getCallerUser() { + return _accountMgr.getActiveUser(userId); + } + public void setCallerUserId(long userId) { this.userId = userId; } diff --git a/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java b/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java index 132416bac05..bad7ca7b5f6 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java @@ -16,11 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.discovery; -import com.cloud.user.AccountService; import com.cloud.user.User; import com.cloud.user.UserContext; -import com.cloud.utils.component.Inject; -import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseCmd; @@ -42,16 +39,13 @@ public class ListApisCmd extends BaseCmd { @PlugService ApiDiscoveryService _apiDiscoveryService; - @Inject - private AccountService _accountService; - @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="API name") private String name; @Override public void execute() throws ServerApiException { if (_apiDiscoveryService != null) { - User user = _accountService.getActiveUser(UserContext.current().getCallerUserId()); + User user = UserContext.current().getCallerUser(); ListResponse response = (ListResponse) _apiDiscoveryService.listApis(user, name); if (response == null) { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Api Discovery plugin was unable to find an api by that name or process any apis"); diff --git a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java index 7e2ed17ecdc..f06e2005552 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java @@ -17,17 +17,13 @@ package org.apache.cloudstack.discovery; import com.cloud.serializer.Param; -import com.cloud.server.ManagementServer; import com.cloud.user.User; import com.cloud.utils.ReflectUtil; import com.cloud.utils.StringUtils; import com.cloud.utils.component.Adapters; import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.component.Inject; -import com.cloud.utils.component.PluggableService; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.acl.APIChecker; -import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.BaseAsyncCmd; @@ -54,16 +50,14 @@ import java.util.Set; public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { private static final Logger s_logger = Logger.getLogger(ApiDiscoveryServiceImpl.class); - @Inject(adapter = APIChecker.class) - protected Adapters _apiAccessCheckers; - - private static Map _apiNameDiscoveryResponseMap = null; + protected static Adapters s_apiAccessCheckers = null; + private static Map s_apiNameDiscoveryResponseMap = null; protected ApiDiscoveryServiceImpl() { super(); - if (_apiNameDiscoveryResponseMap == null) { + if (s_apiNameDiscoveryResponseMap == null) { long startTime = System.nanoTime(); - _apiNameDiscoveryResponseMap = new HashMap(); + s_apiNameDiscoveryResponseMap = new HashMap(); cacheResponseMap(); long endTime = System.nanoTime(); s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms"); @@ -142,11 +136,11 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { } } response.setObjectName("api"); - _apiNameDiscoveryResponseMap.put(apiName, response); + s_apiNameDiscoveryResponseMap.put(apiName, response); } - for (String apiName : _apiNameDiscoveryResponseMap.keySet()) { - ApiDiscoveryResponse response = _apiNameDiscoveryResponseMap.get(apiName); + for (String apiName : s_apiNameDiscoveryResponseMap.keySet()) { + ApiDiscoveryResponse response = s_apiNameDiscoveryResponseMap.get(apiName); Set processedParams = new HashSet(); for (ApiParameterResponse param : response.getParams()) { if (responseApiNameListMap.containsKey(param.getRelated())) { @@ -166,7 +160,7 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { } else { response.setRelated(null); } - _apiNameDiscoveryResponseMap.put(apiName, response); + s_apiNameDiscoveryResponseMap.put(apiName, response); } } @@ -175,34 +169,39 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { ListResponse response = new ListResponse(); List responseList = new ArrayList(); + if (s_apiAccessCheckers == null) { + ComponentLocator locator = ComponentLocator.getCurrentLocator(); + s_apiAccessCheckers = locator.getAdapters(APIChecker.class); + } + if (user == null) return null; if (name != null) { - if (!_apiNameDiscoveryResponseMap.containsKey(name)) + if (!s_apiNameDiscoveryResponseMap.containsKey(name)) return null; - for (APIChecker apiChecker : _apiAccessCheckers) { + for (APIChecker apiChecker : s_apiAccessCheckers) { try { apiChecker.checkAccess(user, name); } catch (Exception ex) { return null; } } - responseList.add(_apiNameDiscoveryResponseMap.get(name)); + responseList.add(s_apiNameDiscoveryResponseMap.get(name)); } else { - for (String apiName : _apiNameDiscoveryResponseMap.keySet()) { + for (String apiName : s_apiNameDiscoveryResponseMap.keySet()) { boolean isAllowed = true; - for (APIChecker apiChecker : _apiAccessCheckers) { + for (APIChecker apiChecker : s_apiAccessCheckers) { try { - apiChecker.checkAccess(user, name); + apiChecker.checkAccess(user, apiName); } catch (Exception ex) { isAllowed = false; } } if (isAllowed) - responseList.add(_apiNameDiscoveryResponseMap.get(apiName)); + responseList.add(s_apiNameDiscoveryResponseMap.get(apiName)); } } response.setResponses(responseList); From 8608925216e87691bc49fa4417d3446c2b81a5a7 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Tue, 15 Jan 2013 18:07:08 -0800 Subject: [PATCH 7/8] Consolidate RuntimeCloudException and CloudRuntimeException into one class CloudRuntimeException, and removed RuntimeCloudException to avoid confusion. --- .../CloudAuthenticationException.java | 4 +- .../exception/CloudExecutionException.java | 4 +- .../cloudstack/api/ServerApiException.java | 4 +- .../simulator/SimulatorRuntimeException.java | 4 +- .../com/cloud/async/AsyncCommandQueued.java | 4 +- .../exception/CloudRuntimeException.java | 48 ++++++++++-- .../HypervisorVersionChangedException.java | 4 +- .../exception/RuntimeCloudException.java | 75 ------------------- 8 files changed, 55 insertions(+), 92 deletions(-) delete mode 100644 utils/src/com/cloud/utils/exception/RuntimeCloudException.java diff --git a/api/src/com/cloud/exception/CloudAuthenticationException.java b/api/src/com/cloud/exception/CloudAuthenticationException.java index 2bba79bab1e..0bf114c0394 100644 --- a/api/src/com/cloud/exception/CloudAuthenticationException.java +++ b/api/src/com/cloud/exception/CloudAuthenticationException.java @@ -17,9 +17,9 @@ package com.cloud.exception; import com.cloud.utils.SerialVersionUID; -import com.cloud.utils.exception.RuntimeCloudException; +import com.cloud.utils.exception.CloudRuntimeException; -public class CloudAuthenticationException extends RuntimeCloudException { +public class CloudAuthenticationException extends CloudRuntimeException { private static final long serialVersionUID = SerialVersionUID.CloudAuthenticationException; public CloudAuthenticationException(String message) { diff --git a/api/src/com/cloud/exception/CloudExecutionException.java b/api/src/com/cloud/exception/CloudExecutionException.java index d8d70f8ddb5..c19fc459a8d 100755 --- a/api/src/com/cloud/exception/CloudExecutionException.java +++ b/api/src/com/cloud/exception/CloudExecutionException.java @@ -17,14 +17,14 @@ package com.cloud.exception; import java.util.HashMap; -import com.cloud.utils.exception.RuntimeCloudException; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.SerialVersionUID; /** * */ -public class CloudExecutionException extends RuntimeCloudException { +public class CloudExecutionException extends CloudRuntimeException { private final static long serialVersionUID = SerialVersionUID.CloudExecutionException; private final ErrorCode code; diff --git a/api/src/org/apache/cloudstack/api/ServerApiException.java b/api/src/org/apache/cloudstack/api/ServerApiException.java index 70fd34e5cf7..1f57b74745d 100644 --- a/api/src/org/apache/cloudstack/api/ServerApiException.java +++ b/api/src/org/apache/cloudstack/api/ServerApiException.java @@ -15,10 +15,10 @@ // specific language governing permissions and limitations // under the License. package org.apache.cloudstack.api; -import com.cloud.utils.exception.RuntimeCloudException; +import com.cloud.utils.exception.CloudRuntimeException; @SuppressWarnings("serial") -public class ServerApiException extends RuntimeCloudException { +public class ServerApiException extends CloudRuntimeException { private int _errorCode; private String _description; diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorRuntimeException.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorRuntimeException.java index 9891bc82556..9f24bbd0cfc 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorRuntimeException.java +++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorRuntimeException.java @@ -18,12 +18,12 @@ package com.cloud.simulator; import com.cloud.utils.SerialVersionUID; -import com.cloud.utils.exception.RuntimeCloudException; +import com.cloud.utils.exception.CloudRuntimeException; /** * wrap exceptions that you know there's no point in dealing with. */ -public class SimulatorRuntimeException extends RuntimeCloudException { +public class SimulatorRuntimeException extends CloudRuntimeException { private static final long serialVersionUID = SerialVersionUID.CloudRuntimeException; diff --git a/server/src/com/cloud/async/AsyncCommandQueued.java b/server/src/com/cloud/async/AsyncCommandQueued.java index 200b40e71b5..f01c214564b 100644 --- a/server/src/com/cloud/async/AsyncCommandQueued.java +++ b/server/src/com/cloud/async/AsyncCommandQueued.java @@ -17,9 +17,9 @@ package com.cloud.async; import com.cloud.utils.SerialVersionUID; -import com.cloud.utils.exception.RuntimeCloudException; +import com.cloud.utils.exception.CloudRuntimeException; -public class AsyncCommandQueued extends RuntimeCloudException { +public class AsyncCommandQueued extends CloudRuntimeException { private static final long serialVersionUID = SerialVersionUID.AsyncCommandQueued; private SyncQueueVO _queue = null; diff --git a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java b/utils/src/com/cloud/utils/exception/CloudRuntimeException.java index 78075947d3f..3862e2223d6 100755 --- a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java +++ b/utils/src/com/cloud/utils/exception/CloudRuntimeException.java @@ -16,24 +16,62 @@ // under the License. package com.cloud.utils.exception; +import java.util.ArrayList; + +import com.cloud.utils.AnnotationHelper; import com.cloud.utils.SerialVersionUID; /** * wrap exceptions that you know there's no point in dealing with. */ -public class CloudRuntimeException extends RuntimeCloudException { +public class CloudRuntimeException extends RuntimeException { private static final long serialVersionUID = SerialVersionUID.CloudRuntimeException; - + + // This holds a list of uuids and their names. Add uuid:fieldname pairs + protected ArrayList idList = new ArrayList(); + + protected int csErrorCode; + + public CloudRuntimeException(String message) { super(message); + setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); } - + public CloudRuntimeException(String message, Throwable th) { super(message, th); + setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); } - - protected CloudRuntimeException() { + + public CloudRuntimeException() { super(); + setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); + } + + public void addProxyObject(String uuid) { + idList.add(uuid); + return; + } + + public void addProxyObject(Object voObj, Long id, String idFieldName) { + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(voObj); + if (tablename != null) { + addProxyObject(tablename, id, idFieldName); + } + return; + } + + public ArrayList getIdProxyList() { + return idList; + } + + public void setCSErrorCode(int cserrcode) { + this.csErrorCode = cserrcode; + } + + public int getCSErrorCode() { + return this.csErrorCode; } } diff --git a/utils/src/com/cloud/utils/exception/HypervisorVersionChangedException.java b/utils/src/com/cloud/utils/exception/HypervisorVersionChangedException.java index 4f637cb46be..2c0c1ccd68b 100755 --- a/utils/src/com/cloud/utils/exception/HypervisorVersionChangedException.java +++ b/utils/src/com/cloud/utils/exception/HypervisorVersionChangedException.java @@ -18,10 +18,10 @@ package com.cloud.utils.exception; import com.cloud.utils.SerialVersionUID; -public class HypervisorVersionChangedException extends RuntimeCloudException { +public class HypervisorVersionChangedException extends CloudRuntimeException { private static final long serialVersionUID = SerialVersionUID.CloudRuntimeException; - + public HypervisorVersionChangedException(String message) { super(message); } diff --git a/utils/src/com/cloud/utils/exception/RuntimeCloudException.java b/utils/src/com/cloud/utils/exception/RuntimeCloudException.java deleted file mode 100644 index 52229800785..00000000000 --- a/utils/src/com/cloud/utils/exception/RuntimeCloudException.java +++ /dev/null @@ -1,75 +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 -// 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.utils.exception; - -import com.cloud.utils.AnnotationHelper; -import java.util.ArrayList; - -/** - * by the API response serializer. Any exceptions that are thrown by - * class, which extends Exception instead of RuntimeException like this - * class does. - */ - -public class RuntimeCloudException extends RuntimeException { - - // This holds a list of uuids and their names. Add uuid:fieldname pairs - protected ArrayList idList = new ArrayList(); - - protected int csErrorCode; - - public void addProxyObject(String uuid) { - idList.add(uuid); - return; - } - - public RuntimeCloudException(String message) { - super(message); - setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); - } - - public RuntimeCloudException(String message, Throwable cause) { - super(message, cause); - setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); - } - - public void addProxyObject(Object voObj, Long id, String idFieldName) { - // Get the VO object's table name. - String tablename = AnnotationHelper.getTableName(voObj); - if (tablename != null) { - addProxyObject(tablename, id, idFieldName); - } - return; - } - - public RuntimeCloudException() { - super(); - setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); - } - - public ArrayList getIdProxyList() { - return idList; - } - - public void setCSErrorCode(int cserrcode) { - this.csErrorCode = cserrcode; - } - - public int getCSErrorCode() { - return this.csErrorCode; - } -} From 939acb0f4c951f8c04de78cf897c8f6a25b1f05d Mon Sep 17 00:00:00 2001 From: Min Chen Date: Tue, 15 Jan 2013 18:17:35 -0800 Subject: [PATCH 8/8] Remove unused CloudExecutionException. --- .../exception/CloudExecutionException.java | 57 ------------------- api/src/com/cloud/exception/ErrorCode.java | 52 ----------------- 2 files changed, 109 deletions(-) delete mode 100755 api/src/com/cloud/exception/CloudExecutionException.java delete mode 100755 api/src/com/cloud/exception/ErrorCode.java diff --git a/api/src/com/cloud/exception/CloudExecutionException.java b/api/src/com/cloud/exception/CloudExecutionException.java deleted file mode 100755 index c19fc459a8d..00000000000 --- a/api/src/com/cloud/exception/CloudExecutionException.java +++ /dev/null @@ -1,57 +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.exception; - -import java.util.HashMap; - -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.SerialVersionUID; - -/** - * - */ -public class CloudExecutionException extends CloudRuntimeException { - private final static long serialVersionUID = SerialVersionUID.CloudExecutionException; - - private final ErrorCode code; - private final HashMap details; - - public CloudExecutionException(ErrorCode code, String message, Throwable cause) { - super(message, cause); - this.code = code; - details = new HashMap(); - } - - public ErrorCode getErrorCode() { - return code; - } - - public String getErrorMessage() { - return new StringBuilder("Error Code=").append(code).append("; Error Message=").append(super.toString()).toString(); - } - - @Override - public String toString() { - StringBuilder buff = new StringBuilder(); - buff.append("Error Code=").append(code); - buff.append("; Error Message=").append(super.toString()); - if (details.size() > 0) { - buff.append("; Error Details=").append(details.toString()); - } - return buff.toString(); - } -} diff --git a/api/src/com/cloud/exception/ErrorCode.java b/api/src/com/cloud/exception/ErrorCode.java deleted file mode 100755 index 8f048b84800..00000000000 --- a/api/src/com/cloud/exception/ErrorCode.java +++ /dev/null @@ -1,52 +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.exception; - -import java.util.HashSet; - -/** - */ -public class ErrorCode { - String code; - private static HashSet s_codes = new HashSet(); - - public ErrorCode(String code) { - this.code = code; - assert !s_codes.contains(this) : "There is already an error code registered for this code: " + code; - s_codes.add(this); - } - - public String getCode() { - return code; - } - - @Override - public int hashCode() { - return code.hashCode(); - } - - @Override - public boolean equals(Object that) { - if (!(that instanceof ErrorCode)) { - return false; - } - - return this.code.equals(((ErrorCode)that).code); - } - - public final static ErrorCode UnableToReachResource = new ErrorCode("resource.unavailable"); -}