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/05/11 08:50:10 UTC
[5/7] stratos git commit: Adding
InvalidCartridgeGroupDefinitionException
Adding InvalidCartridgeGroupDefinitionException
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/0a6518d8
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/0a6518d8
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/0a6518d8
Branch: refs/heads/master
Commit: 0a6518d839a532d88fe39de15e783ed9efc83d97
Parents: 2fdac39
Author: Vishanth <vi...@gmail.com>
Authored: Fri May 8 12:24:49 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon May 11 12:19:59 2015 +0530
----------------------------------------------------------------------
.../rest/endpoint/api/StratosApiV41.java | 17 ++---
.../rest/endpoint/api/StratosApiV41Utils.java | 39 ++++++-----
...nvalidCartridgeGroupDefinitionException.java | 68 ++++++++++++++++++++
3 files changed, 95 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/0a6518d8/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 543a19b..ab04a31 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
@@ -443,7 +443,7 @@ public class StratosApiV41 extends AbstractApi {
@AuthorizationAction("/permission/protected/manage/addServiceGroup")
@SuperTenantService(true)
public Response addServiceGroup(
- GroupBean serviceGroupDefinition) throws RestAPIException {
+ GroupBean serviceGroupDefinition) throws RestAPIException, InvalidCartridgeGroupDefinitionException {
try {
StratosApiV41Utils.addServiceGroup(serviceGroupDefinition);
URI url = uriInfo.getAbsolutePathBuilder().path(serviceGroupDefinition.getName()).build();
@@ -451,22 +451,13 @@ public class StratosApiV41 extends AbstractApi {
return Response.created(url).entity(new StatusResponseBean(Response.Status.CREATED.getStatusCode(),
String.format("Cartridge Group added successfully: [cartridge-group] %s",
serviceGroupDefinition.getName()))).build();
+ } catch (InvalidCartridgeGroupDefinitionException e) {
+ return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponseBean(
+ Response.Status.BAD_REQUEST.getStatusCode(), e.getMessage())).build();
} catch (RestAPIException e) {
if (e.getCause().getMessage().contains("already exists")) {
return Response.status(Response.Status.CONFLICT).entity(new StatusResponseBean(
Response.Status.CONFLICT.getStatusCode(), "Cartridge group not found")).build();
- } else if (e.getCause().getMessage().contains("duplicate cartridges")) {
- return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponseBean(
- Response.Status.BAD_REQUEST.getStatusCode(), "Cartridges duplicated in the group " +
- "definition")).build();
- } else if (e.getCause().getMessage().contains("duplicate groups")) {
- return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponseBean(
- Response.Status.BAD_REQUEST.getStatusCode(), "Groups duplicated in the group " +
- "definition")).build();
- } else if (e.getCause().getMessage().contains("cyclic group")) {
- return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponseBean(
- Response.Status.BAD_REQUEST.getStatusCode(), "Cyclic group behaviour identified in the group " +
- "definition")).build();
} else {
throw e;
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/0a6518d8/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
index f611035..85fb00d 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
@@ -970,10 +970,11 @@ public class StratosApiV41Utils {
* @param serviceGroupDefinition serviceGroupDefinition
* @throws RestAPIException
*/
- public static void addServiceGroup(GroupBean serviceGroupDefinition) throws RestAPIException {
+ public static void addServiceGroup(GroupBean serviceGroupDefinition)
+ throws InvalidCartridgeGroupDefinitionException, RestAPIException {
try {
if (serviceGroupDefinition == null) {
- throw new RuntimeException("Service Group definition is null");
+ throw new RuntimeException("Cartridge group definition is null");
}
List<String> cartridgeTypes = new ArrayList<String>();
@@ -982,7 +983,7 @@ public class StratosApiV41Utils {
String[] cartridgeGroupNames;
if (log.isDebugEnabled()) {
- log.debug("checking cartridges in cartridge group " + serviceGroupDefinition.getName());
+ log.debug("Checking cartridges in cartridge group " + serviceGroupDefinition.getName());
}
findCartridgesInGroupBean(serviceGroupDefinition, cartridgeTypes);
@@ -1009,7 +1010,9 @@ public class StratosApiV41Utils {
j++;
}
} catch (RemoteException e) {
- throw new RestAPIException(e);
+ String message = "Could not add the cartridge group: " + serviceGroupDefinition.getName();
+ log.error(message, e);
+ throw new RestAPIException(message, e);
} catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
throw new RestAPIException(e);
}
@@ -1040,9 +1043,9 @@ public class StratosApiV41Utils {
duplicatesOutput.append(dup).append(" ");
}
if (log.isDebugEnabled()) {
- log.debug("duplicate subGroups defined: " + duplicatesOutput.toString());
+ log.debug("duplicate sub-groups defined: " + duplicatesOutput.toString());
}
- throw new RestAPIException("Invalid Service Group definition, duplicate subGroups defined:" +
+ throw new RestAPIException("Invalid cartridge group definition, duplicate sub-groups defined:" +
duplicatesOutput.toString());
}
}
@@ -1056,6 +1059,8 @@ public class StratosApiV41Utils {
// Add cartridge group elements to SM cache - done after service group has been added
StratosManagerServiceClient smServiceClient = getStratosManagerServiceClient();
smServiceClient.addUsedCartridgesInCartridgeGroups(serviceGroupDefinition.getName(), cartridgeNames);
+ } catch (InvalidCartridgeGroupDefinitionException e) {
+ throw e;
} catch (Exception e) {
// TODO: InvalidServiceGroupException is not received, only AxisFault. Need to fix get the custom exception
String message = "Could not add cartridge group";
@@ -3231,7 +3236,8 @@ public class StratosApiV41Utils {
* @param groupBean - cartridge group definition
* @throws RestAPIException - throws the rest api exception when the group definition is invalid
*/
- private static void validateCartridgeDuplicationInGroupDefinition(GroupBean groupBean) throws RestAPIException {
+ private static void validateCartridgeDuplicationInGroupDefinition(GroupBean groupBean)
+ throws InvalidCartridgeGroupDefinitionException {
if (groupBean == null) {
return;
}
@@ -3256,7 +3262,8 @@ public class StratosApiV41Utils {
* @param cartridges - list of strings which holds the cartridgeTypes values
* @throws RestAPIException - throws the rest api exception when the cartridges are duplicated
*/
- private static void validateCartridgeDuplicationInGroup(List<String> cartridges) throws RestAPIException {
+ private static void validateCartridgeDuplicationInGroup(List<String> cartridges)
+ throws InvalidCartridgeGroupDefinitionException {
List<String> checkList = new ArrayList<String>();
for (String cartridge : cartridges) {
if (!checkList.contains(cartridge)) {
@@ -3265,8 +3272,8 @@ public class StratosApiV41Utils {
if (log.isDebugEnabled()) {
log.debug("duplicate cartridges defined: " + cartridge);
}
- throw new RestAPIException("Invalid Service Group definition, duplicate cartridges defined: " +
- cartridge);
+ throw new InvalidCartridgeGroupDefinitionException("Invalid cartridge group definition, " +
+ "duplicate cartridges defined: " + cartridge);
}
}
}
@@ -3279,7 +3286,7 @@ public class StratosApiV41Utils {
* @throws RestAPIException - throws the rest api exception when the group definition is invalid
*/
private static void validateGroupDuplicationInGroupDefinition(GroupBean groupBean, List<String> parentGroups)
- throws RestAPIException {
+ throws InvalidCartridgeGroupDefinitionException {
if (groupBean == null) {
return;
}
@@ -3310,7 +3317,7 @@ public class StratosApiV41Utils {
* @throws RestAPIException - throws the rest api exception when group duplicate or when cyclic behaviour occurs
*/
private static void validateGroupDuplicationInGroup(List<String> groups, List<String> parentGroups)
- throws RestAPIException {
+ throws InvalidCartridgeGroupDefinitionException {
List<String> checkList = new ArrayList<String>();
for (String group : groups) {
if (!checkList.contains(group)) {
@@ -3319,15 +3326,15 @@ public class StratosApiV41Utils {
if (log.isDebugEnabled()) {
log.debug("duplicate group defined: " + group);
}
- throw new RestAPIException("Invalid Service Group definition, duplicate groups defined: " +
- group);
+ throw new InvalidCartridgeGroupDefinitionException("Invalid cartridge group definition, " +
+ "duplicate groups defined: " + group);
}
if (parentGroups.contains(group)) {
if (log.isDebugEnabled()) {
log.debug("cyclic group behaviour identified [group-name]: " + group);
}
- throw new RestAPIException("Invalid Service Group definition, cyclic group behaviour identified: " +
- group);
+ throw new InvalidCartridgeGroupDefinitionException("Invalid cartridge group definition, " +
+ "cyclic group behaviour identified: " + group);
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/0a6518d8/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/InvalidCartridgeGroupDefinitionException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/InvalidCartridgeGroupDefinitionException.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/InvalidCartridgeGroupDefinitionException.java
new file mode 100644
index 0000000..c4c3b19
--- /dev/null
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/InvalidCartridgeGroupDefinitionException.java
@@ -0,0 +1,68 @@
+/*
+ * 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.rest.endpoint.exception;
+
+import javax.ws.rs.core.Response;
+
+public class InvalidCartridgeGroupDefinitionException extends Exception {
+
+ private static final long serialVersionUID = 7396616678984911736L;
+
+ private String message;
+ private Response.Status httpStatusCode;
+
+ public InvalidCartridgeGroupDefinitionException() {
+ super();
+ }
+
+ public InvalidCartridgeGroupDefinitionException(String message, Throwable cause) {
+ super(message, cause);
+ this.message = message;
+ }
+
+ public InvalidCartridgeGroupDefinitionException(Response.Status httpStatusCode, String message, Throwable cause) {
+ super(message, cause);
+ this.message = message;
+ this.httpStatusCode = httpStatusCode;
+ }
+
+ public InvalidCartridgeGroupDefinitionException(String message) {
+ super(message);
+ this.message = message;
+ }
+
+ public InvalidCartridgeGroupDefinitionException(Response.Status httpStatusCode, String message) {
+ super(message);
+ this.message = message;
+ this.httpStatusCode = httpStatusCode;
+ }
+
+ public InvalidCartridgeGroupDefinitionException(Throwable cause) {
+ super(cause);
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public Response.Status getHTTPStatusCode() {
+ return httpStatusCode;
+ }
+}