You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/01/24 18:31:30 UTC
[2/2] stratos git commit: Removing logic that re-add cartridges in
cloud controller service addCartridge() method and returns HTTP status code
409
Removing logic that re-add cartridges in cloud controller service addCartridge() method and returns HTTP status code 409
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/205f60a4
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/205f60a4
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/205f60a4
Branch: refs/heads/master
Commit: 205f60a420660b9cecab552c5594c1b380cde8b0
Parents: c41e66b
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sat Jan 24 23:01:19 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat Jan 24 23:01:19 2015 +0530
----------------------------------------------------------------------
.../CartridgeAlreadyExistsException.java | 30 +
.../services/CloudControllerService.java | 2 +-
.../impl/CloudControllerServiceImpl.java | 21 +-
.../client/CloudControllerServiceClient.java | 3 +-
.../rest/endpoint/api/StratosApiV40Utils.java | 24 +-
.../rest/endpoint/api/StratosApiV41.java | 17 +-
.../main/resources/CloudControllerService.wsdl | 710 ++++++++++---------
7 files changed, 433 insertions(+), 374 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/205f60a4/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/CartridgeAlreadyExistsException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/CartridgeAlreadyExistsException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/CartridgeAlreadyExistsException.java
new file mode 100644
index 0000000..08cc7c7
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/CartridgeAlreadyExistsException.java
@@ -0,0 +1,30 @@
+/*
+ * 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 org.apache.stratos.cloud.controller.exception;
+
+/**
+ * Cartridge already exists exception.
+ */
+public class CartridgeAlreadyExistsException extends Exception {
+
+ public CartridgeAlreadyExistsException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/205f60a4/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/CloudControllerService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/CloudControllerService.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/CloudControllerService.java
index 80c890a..1bbcdf7 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/CloudControllerService.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/CloudControllerService.java
@@ -40,7 +40,7 @@ public interface CloudControllerService {
* @throws IllegalArgumentException if the provided argument is not valid.
*/
void addCartridge(CartridgeConfig cartridgeConfig)
- throws InvalidCartridgeDefinitionException, InvalidIaasProviderException;
+ throws InvalidCartridgeDefinitionException, InvalidIaasProviderException, CartridgeAlreadyExistsException;
/**
* Remove a cartridge
http://git-wip-us.apache.org/repos/asf/stratos/blob/205f60a4/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
index 0f1ee46..4d63db3 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
@@ -67,7 +67,7 @@ public class CloudControllerServiceImpl implements CloudControllerService {
}
public void addCartridge(CartridgeConfig cartridgeConfig) throws InvalidCartridgeDefinitionException,
- InvalidIaasProviderException {
+ InvalidIaasProviderException, CartridgeAlreadyExistsException {
handleNullObject(cartridgeConfig, "Cartridge definition is null");
@@ -82,22 +82,16 @@ public class CloudControllerServiceImpl implements CloudControllerService {
try {
cartridge = CloudControllerUtil.toCartridge(cartridgeConfig);
} catch (Exception e) {
- String msg = "Invalid cartridge definition: [cartridge-type] " + cartridgeConfig.getType();
- log.error(msg, e);
- throw new InvalidCartridgeDefinitionException(msg, e);
+ String message = "Invalid cartridge definition: [cartridge-type] " + cartridgeConfig.getType();
+ log.error(message, e);
+ throw new InvalidCartridgeDefinitionException(message, e);
}
- // TODO transaction begins
String cartridgeType = cartridge.getType();
- // Undeploy if already deployed
if (cloudControllerContext.getCartridge(cartridgeType) != null) {
- Cartridge cartridgeToBeRemoved = cloudControllerContext.getCartridge(cartridgeType);
- // undeploy
- try {
- removeCartridge(cartridgeToBeRemoved.getType());
- } catch (InvalidCartridgeTypeException ignore) {
- }
- copyIaasProviders(cartridge, cartridgeToBeRemoved);
+ String message = "Cartridge already exists: [cartridge-type] " + cartridgeType;
+ log.error(message);
+ throw new CartridgeAlreadyExistsException(message);
}
// Add cartridge to the cloud controller context and persist
@@ -108,7 +102,6 @@ public class CloudControllerServiceImpl implements CloudControllerService {
cartridgeList.add(cartridge);
TopologyBuilder.handleServiceCreated(cartridgeList);
- // transaction ends
if(log.isInfoEnabled()) {
log.info("Successfully added cartridge: [cartridge-type] " + cartridgeType);
http://git-wip-us.apache.org/repos/asf/stratos/blob/205f60a4/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/CloudControllerServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/CloudControllerServiceClient.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/CloudControllerServiceClient.java
index 1ff00f8..ee63797 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/CloudControllerServiceClient.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/CloudControllerServiceClient.java
@@ -79,7 +79,8 @@ public class CloudControllerServiceClient {
}
public void addCartridge(CartridgeConfig cartridgeConfig)
- throws RemoteException, CloudControllerServiceInvalidCartridgeDefinitionExceptionException,
+ throws RemoteException, CloudControllerServiceCartridgeAlreadyExistsExceptionException,
+ CloudControllerServiceInvalidCartridgeDefinitionExceptionException,
CloudControllerServiceInvalidIaasProviderExceptionException {
stub.addCartridge(cartridgeConfig);
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/205f60a4/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
index ee46472..95bff13 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV40Utils.java
@@ -24,27 +24,29 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.stub.AutoscalerServiceInvalidPolicyExceptionException;
import org.apache.stratos.autoscaler.stub.deployment.policy.DeploymentPolicy;
-import org.apache.stratos.cloud.controller.stub.domain.CartridgeConfig;
-import org.apache.stratos.cloud.controller.stub.domain.CartridgeInfo;
+import org.apache.stratos.cloud.controller.stub.CloudControllerServiceCartridgeAlreadyExistsExceptionException;
import org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidCartridgeDefinitionExceptionException;
import org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidCartridgeTypeExceptionException;
import org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidIaasProviderExceptionException;
+import org.apache.stratos.cloud.controller.stub.domain.CartridgeConfig;
+import org.apache.stratos.cloud.controller.stub.domain.CartridgeInfo;
+import org.apache.stratos.common.beans.ApiResponseBean;
+import org.apache.stratos.common.beans.artifact.repository.GitNotificationPayloadBean;
+import org.apache.stratos.common.beans.cartridge.CartridgeBean;
+import org.apache.stratos.common.beans.partition.PartitionBean;
+import org.apache.stratos.common.beans.policy.autoscale.AutoscalePolicyBean;
import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean;
import org.apache.stratos.common.client.AutoscalerServiceClient;
import org.apache.stratos.common.client.CloudControllerServiceClient;
import org.apache.stratos.common.client.StratosManagerServiceClient;
import org.apache.stratos.manager.utils.ApplicationManagementUtil;
import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.apache.stratos.common.beans.ApiResponseBean;
-import org.apache.stratos.common.beans.partition.PartitionBean;
-import org.apache.stratos.common.beans.policy.autoscale.AutoscalePolicyBean;
-import org.apache.stratos.common.beans.cartridge.CartridgeBean;
-import org.apache.stratos.common.beans.artifact.repository.GitNotificationPayloadBean;
-import org.apache.stratos.rest.endpoint.util.converter.ObjectConverter;
import org.apache.stratos.rest.endpoint.exception.RestAPIException;
+import org.apache.stratos.rest.endpoint.util.converter.ObjectConverter;
import java.rmi.RemoteException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
import java.util.regex.Pattern;
/**
@@ -87,6 +89,10 @@ public class StratosApiV40Utils {
String message = e.getFaultMessage().getInvalidCartridgeDefinitionException().getMessage();
log.error(message, e);
throw new RestAPIException(message, e);
+ } catch (CloudControllerServiceCartridgeAlreadyExistsExceptionException e) {
+ String message = e.getMessage();
+ log.error(message, e);
+ throw new RestAPIException(message, e);
} catch (CloudControllerServiceInvalidIaasProviderExceptionException e) {
String message = e.getFaultMessage().getInvalidIaasProviderException().getMessage();
log.error(message, e);
http://git-wip-us.apache.org/repos/asf/stratos/blob/205f60a4/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
index 4a4d863..250d640 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
@@ -140,10 +140,17 @@ public class StratosApiV41 extends AbstractApi {
@AuthorizationAction("/permission/admin/manage/add/cartridgeDefinition")
public Response addCartridge(CartridgeBean cartridgeDefinitionBean)
throws RestAPIException {
+
+ String cartridgeType = cartridgeDefinitionBean.getType();
+ CartridgeBean cartridgeBean = StratosApiV41Utils.getCartridge(cartridgeType);
+ if(cartridgeBean != null) {
+ log.warn(String.format("Cartridge already exists: [cartridge-type] %s", cartridgeType));
+ return Response.status(Response.Status.CONFLICT).build();
+ }
+
StratosApiV41Utils.addCartridge(cartridgeDefinitionBean);
- URI url = uriInfo.getAbsolutePathBuilder().path(cartridgeDefinitionBean.getType()).build();
+ URI url = uriInfo.getAbsolutePathBuilder().path(cartridgeType).build();
return Response.created(url).build();
-
}
/**
@@ -349,12 +356,14 @@ public class StratosApiV41 extends AbstractApi {
@AuthorizationAction("/permission/protected/manage/monitor/tenants")
public Response addNetworkPartition(NetworkPartitionBean networkPartitionBean)
throws RestAPIException {
- NetworkPartitionBean networkPartition = StratosApiV41Utils.getNetworkPartition(networkPartitionBean.getId());
+ String networkPartitionId = networkPartitionBean.getId();
+ NetworkPartitionBean networkPartition = StratosApiV41Utils.getNetworkPartition(networkPartitionId);
if(networkPartition != null) {
+ log.warn(String.format("Network partition already exists: [network-partition-id] %s", networkPartitionId));
return Response.status(Response.Status.CONFLICT).build();
}
StratosApiV41Utils.addNetworkPartition(networkPartitionBean);
- URI url = uriInfo.getAbsolutePathBuilder().path(networkPartitionBean.getId()).build();
+ URI url = uriInfo.getAbsolutePathBuilder().path(networkPartitionId).build();
return Response.created(url).build();
}