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:06 UTC
[1/7] stratos git commit: This closes #296 on GitHub
Repository: stratos
Updated Branches:
refs/heads/master 25b09fa3f -> e5b63de71
This closes #296 on GitHub
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/e5b63de7
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/e5b63de7
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/e5b63de7
Branch: refs/heads/master
Commit: e5b63de71c66c6c30edf37b38d2fceefbe07ad14
Parents: 4194168
Author: Imesh Gunaratne <im...@apache.org>
Authored: Mon May 11 12:19:59 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon May 11 12:19:59 2015 +0530
----------------------------------------------------------------------
----------------------------------------------------------------------
[6/7] stratos git commit: method overload to avoid passing a new
object: validateGroupDuplicationInGroupDefinition
Posted by im...@apache.org.
method overload to avoid passing a new object: validateGroupDuplicationInGroupDefinition
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/4194168c
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/4194168c
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/4194168c
Branch: refs/heads/master
Commit: 4194168c8c398c40c5aaf64f2441b61e61ab6ca2
Parents: 1bea6c8
Author: Vishanth <vi...@gmail.com>
Authored: Mon May 11 10:46:56 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon May 11 12:19:59 2015 +0530
----------------------------------------------------------------------
.../rest/endpoint/api/StratosApiV41Utils.java | 22 +++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/4194168c/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 2081713..6fb0dac 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
@@ -994,7 +994,7 @@ public class StratosApiV41Utils {
//validate the group definition to check if groups duplicate in any groups and
//validate the group definition to check for cyclic group behaviour
- validateGroupDuplicationInGroupDefinition(serviceGroupDefinition, new ArrayList<String>());
+ validateGroupDuplicationInGroupDefinition(serviceGroupDefinition);
CloudControllerServiceClient ccServiceClient = getCloudControllerServiceClient();
@@ -3279,13 +3279,25 @@ public class StratosApiV41Utils {
}
}
+
/**
- * This method is to validate the group duplication in the group definition recursively for group within groups
+ * This is a wrapper method to invoke validateGroupDuplicationInGroupDefinition with a new arraylist of string
*
- * @param groupBean - cartridge group definition
- * @param parentGroups - list of string which holds the parent group names (all parents in the hierarchy)
- * @throws InvalidCartridgeGroupDefinitionException - throws when the group definition is invalid
+ * @param groupBean - cartridge group definition
+ * @throws InvalidCartridgeGroupDefinitionException
*/
+ private static void validateGroupDuplicationInGroupDefinition(GroupBean groupBean)
+ throws InvalidCartridgeGroupDefinitionException {
+ validateGroupDuplicationInGroupDefinition(groupBean, new ArrayList<String>());
+ }
+
+ /**
+ * This is to validate the group duplication in the group definition recursively for group within groups
+ *
+ * @param groupBean - cartridge group definition
+ * @param parentGroups - list of string which holds the parent group names (all parents in the hierarchy)
+ * @throws InvalidCartridgeGroupDefinitionException - throws when the group definition is invalid
+ */
private static void validateGroupDuplicationInGroupDefinition(GroupBean groupBean, List<String> parentGroups)
throws InvalidCartridgeGroupDefinitionException {
if (groupBean == null) {
[3/7] stratos git commit: Refactoring
Posted by im...@apache.org.
Refactoring
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/2fdac39d
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/2fdac39d
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/2fdac39d
Branch: refs/heads/master
Commit: 2fdac39d7f8c2907511383524b1ef8afced23c3b
Parents: ea8fce5
Author: Vishanth <vi...@gmail.com>
Authored: Wed May 6 18:19:55 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon May 11 12:19:59 2015 +0530
----------------------------------------------------------------------
.../rest/endpoint/api/StratosApiV41.java | 15 +++++----
.../rest/endpoint/api/StratosApiV41Utils.java | 33 ++++++++++----------
2 files changed, 26 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fdac39d/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 4578019..543a19b 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
@@ -455,15 +455,18 @@ public class StratosApiV41 extends AbstractApi {
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")) {
+ } 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")) {
+ 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")) {
+ 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();
+ 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/2fdac39d/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 96f0c18..f611035 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
@@ -966,6 +966,7 @@ public class StratosApiV41Utils {
/**
* Add a Service Group
+ *
* @param serviceGroupDefinition serviceGroupDefinition
* @throws RestAPIException
*/
@@ -980,11 +981,11 @@ public class StratosApiV41Utils {
List<String> groupNames;
String[] cartridgeGroupNames;
- if (log.isDebugEnabled()) {
- log.debug("checking cartridges in cartridge group " + serviceGroupDefinition.getName());
- }
+ if (log.isDebugEnabled()) {
+ log.debug("checking cartridges in cartridge group " + serviceGroupDefinition.getName());
+ }
- findCartridgesInGroupBean(serviceGroupDefinition, cartridgeTypes);
+ findCartridgesInGroupBean(serviceGroupDefinition, cartridgeTypes);
//validate the group definition to check if cartridges duplicate in any groups defined
validateCartridgeDuplicationInGroupDefinition(serviceGroupDefinition);
@@ -993,7 +994,7 @@ public class StratosApiV41Utils {
//validate the group definition to check for cyclic group behaviour
validateGroupDuplicationInGroupDefinition(serviceGroupDefinition, new ArrayList<String>());
- CloudControllerServiceClient ccServiceClient = getCloudControllerServiceClient();
+ CloudControllerServiceClient ccServiceClient = getCloudControllerServiceClient();
cartridgeNames = new String[cartridgeTypes.size()];
int j = 0;
@@ -3230,7 +3231,7 @@ 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 RestAPIException {
if (groupBean == null) {
return;
}
@@ -3248,19 +3249,19 @@ public class StratosApiV41Utils {
}
}
}
+
/**
* This method is to validate the duplication of cartridges from the given list
*
* @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 RestAPIException {
List<String> checkList = new ArrayList<String>();
for (String cartridge : cartridges) {
if (!checkList.contains(cartridge)) {
checkList.add(cartridge);
- }
- else {
+ } else {
if (log.isDebugEnabled()) {
log.debug("duplicate cartridges defined: " + cartridge);
}
@@ -3269,15 +3270,16 @@ public class StratosApiV41Utils {
}
}
}
+
/**
* This method is to validate the group duplication in the group definition recursively for group within groups
*
- * @param groupBean - cartridge group definition
+ * @param groupBean - cartridge group definition
* @param parentGroups - list of string which holds the parent group names (all parents in the hierarchy)
* @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 RestAPIException {
if (groupBean == null) {
return;
}
@@ -3299,21 +3301,21 @@ public class StratosApiV41Utils {
}
}
}
+
/**
* This method is to validate the duplication of groups in the same level and to validate cyclic behaviour of groups
*
- * @param groups - cartridge group definition
+ * @param groups - cartridge group definition
* @param parentGroups - list of string which holds the parent group names (all parents in the hierarchy)
* @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 RestAPIException {
List<String> checkList = new ArrayList<String>();
for (String group : groups) {
if (!checkList.contains(group)) {
checkList.add(group);
- }
- else {
+ } else {
if (log.isDebugEnabled()) {
log.debug("duplicate group defined: " + group);
}
@@ -3329,5 +3331,4 @@ public class StratosApiV41Utils {
}
}
}
-
}
[5/7] stratos git commit: Adding
InvalidCartridgeGroupDefinitionException
Posted by im...@apache.org.
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;
+ }
+}
[4/7] stratos git commit: Service group validation
Posted by im...@apache.org.
Service group validation
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/ea8fce5c
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/ea8fce5c
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/ea8fce5c
Branch: refs/heads/master
Commit: ea8fce5c0b77fd82b696c3af5523bb6ebd720c77
Parents: 25b09fa
Author: Vishanth <vi...@gmail.com>
Authored: Wed May 6 17:51:31 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon May 11 12:19:59 2015 +0530
----------------------------------------------------------------------
.../rest/endpoint/api/StratosApiV41.java | 9 +
.../rest/endpoint/api/StratosApiV41Utils.java | 187 ++++++++++++++-----
2 files changed, 153 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/ea8fce5c/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 d308e6e..4578019 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
@@ -455,6 +455,15 @@ public class StratosApiV41 extends AbstractApi {
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/ea8fce5c/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 2d878bc..96f0c18 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
@@ -980,50 +980,41 @@ public class StratosApiV41Utils {
List<String> groupNames;
String[] cartridgeGroupNames;
- // if any cartridges are specified in the group, they should be already deployed
- if (serviceGroupDefinition.getCartridges() != null) {
-
if (log.isDebugEnabled()) {
log.debug("checking cartridges in cartridge group " + serviceGroupDefinition.getName());
}
findCartridgesInGroupBean(serviceGroupDefinition, cartridgeTypes);
- Set<String> duplicates = findDuplicates(cartridgeTypes);
- if (duplicates.size() > 0) {
- StringBuilder duplicatesOutput = new StringBuilder();
- for (String dup : duplicates) {
- duplicatesOutput.append(dup).append(" ");
- }
- if (log.isDebugEnabled()) {
- log.debug("duplicate cartridges defined: " + duplicatesOutput.toString());
- }
- throw new RestAPIException("Invalid Service Group definition, duplicate cartridges defined:" +
- duplicatesOutput.toString());
- }
+ //validate the group definition to check if cartridges duplicate in any groups defined
+ validateCartridgeDuplicationInGroupDefinition(serviceGroupDefinition);
+
+ //validate the group definition to check if groups duplicate in any groups and
+ //validate the group definition to check for cyclic group behaviour
+ validateGroupDuplicationInGroupDefinition(serviceGroupDefinition, new ArrayList<String>());
CloudControllerServiceClient ccServiceClient = getCloudControllerServiceClient();
- cartridgeNames = new String[cartridgeTypes.size()];
- int i = 0;
- for (String cartridgeType : cartridgeTypes) {
- try {
- if (ccServiceClient.getCartridge(cartridgeType) == null) {
- // cartridge is not deployed, can't continue
- log.error("Invalid cartridge found in cartridge group " + cartridgeType);
- throw new RestAPIException("No Cartridge Definition found with type " + cartridgeType);
- } else {
- cartridgeNames[i] = cartridgeType;
- i++;
- }
- } catch (RemoteException e) {
- throw new RestAPIException(e);
- } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
- throw new RestAPIException(e);
+ cartridgeNames = new String[cartridgeTypes.size()];
+ int j = 0;
+ for (String cartridgeType : cartridgeTypes) {
+ try {
+ if (ccServiceClient.getCartridge(cartridgeType) == null) {
+ // cartridge is not deployed, can't continue
+ log.error("Invalid cartridge found in cartridge group " + cartridgeType);
+ throw new RestAPIException("No Cartridge Definition found with type " + cartridgeType);
+ } else {
+ cartridgeNames[j] = cartridgeType;
+ j++;
}
+ } catch (RemoteException e) {
+ throw new RestAPIException(e);
+ } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
+ throw new RestAPIException(e);
}
}
+
// if any sub groups are specified in the group, they should be already deployed
if (serviceGroupDefinition.getGroups() != null) {
if (log.isDebugEnabled()) {
@@ -1188,12 +1179,12 @@ public class StratosApiV41Utils {
// Remove the dependent cartridges and cartridge groups from Stratos Manager cache
// - done after service group has been removed
- if (serviceGroup.getCartridges() != null) {
- List<String> cartridgeList = new ArrayList<String>();
- findCartridgesInServiceGroup(serviceGroup, cartridgeList);
- String[] cartridgeNames = cartridgeList.toArray(new String[cartridgeList.size()]);
- smServiceClient.removeUsedCartridgesInCartridgeGroups(name, cartridgeNames);
- }
+
+ List<String> cartridgeList = new ArrayList<String>();
+ findCartridgesInServiceGroup(serviceGroup, cartridgeList);
+ String[] cartridgeNames = cartridgeList.toArray(new String[cartridgeList.size()]);
+ smServiceClient.removeUsedCartridgesInCartridgeGroups(name, cartridgeNames);
+
} catch (RemoteException e) {
throw new RestAPIException("Could not remove cartridge groups", e);
}
@@ -1213,9 +1204,11 @@ public class StratosApiV41Utils {
return;
}
- for (String cartridge : serviceGroup.getCartridges()) {
- if (!cartridges.contains(cartridge)) {
- cartridges.add(cartridge);
+ if (serviceGroup.getCartridges() != null) {
+ for (String cartridge : serviceGroup.getCartridges()) {
+ if (!cartridges.contains(cartridge)) {
+ cartridges.add(cartridge);
+ }
}
}
@@ -1238,9 +1231,11 @@ public class StratosApiV41Utils {
return;
}
- for (String cartridge : groupBean.getCartridges()) {
- if (!cartridges.contains(cartridge)) {
- cartridges.add(cartridge);
+ if (groupBean.getCartridges() != null) {
+ for (String cartridge : groupBean.getCartridges()) {
+ if (!cartridges.contains(cartridge)) {
+ cartridges.add(cartridge);
+ }
}
}
@@ -3229,4 +3224,110 @@ public class StratosApiV41Utils {
return userList;
}
+ /**
+ * This method is to validate the cartridge duplication in the group definition recursively for group within groups
+ *
+ * @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{
+ if (groupBean == null) {
+ return;
+ }
+ List<String> cartridges = new ArrayList<String>();
+ if (groupBean.getCartridges() != null) {
+ if (groupBean.getCartridges().size() > 1) {
+ cartridges.addAll(groupBean.getCartridges());
+ validateCartridgeDuplicationInGroup(cartridges);
+ }
+ }
+ if (groupBean.getGroups() != null) {
+ //Recursive because to check groups inside groups
+ for (GroupBean group : groupBean.getGroups()) {
+ validateCartridgeDuplicationInGroupDefinition(group);
+ }
+ }
+ }
+ /**
+ * This method is to validate the duplication of cartridges from the given list
+ *
+ * @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{
+ List<String> checkList = new ArrayList<String>();
+ for (String cartridge : cartridges) {
+ if (!checkList.contains(cartridge)) {
+ checkList.add(cartridge);
+ }
+ else {
+ if (log.isDebugEnabled()) {
+ log.debug("duplicate cartridges defined: " + cartridge);
+ }
+ throw new RestAPIException("Invalid Service Group definition, duplicate cartridges defined: " +
+ cartridge);
+ }
+ }
+ }
+ /**
+ * This method is to validate the group duplication in the group definition recursively for group within groups
+ *
+ * @param groupBean - cartridge group definition
+ * @param parentGroups - list of string which holds the parent group names (all parents in the hierarchy)
+ * @throws RestAPIException - throws the rest api exception when the group definition is invalid
+ */
+ private static void validateGroupDuplicationInGroupDefinition(GroupBean groupBean, List<String> parentGroups)
+ throws RestAPIException{
+ if (groupBean == null) {
+ return;
+ }
+ List<String> groups = new ArrayList<String>();
+ parentGroups.add(groupBean.getName());
+ if (groupBean.getGroups() != null) {
+ if (!groupBean.getGroups().isEmpty()) {
+ for (GroupBean g : groupBean.getGroups()) {
+ groups.add(g.getName());
+ }
+ validateGroupDuplicationInGroup(groups, parentGroups);
+ }
+ }
+ if (groupBean.getGroups() != null) {
+ //Recursive because to check groups inside groups
+ for (GroupBean group : groupBean.getGroups()) {
+ validateGroupDuplicationInGroupDefinition(group, parentGroups);
+ parentGroups.remove(group.getName());
+ }
+ }
+ }
+ /**
+ * This method is to validate the duplication of groups in the same level and to validate cyclic behaviour of groups
+ *
+ * @param groups - cartridge group definition
+ * @param parentGroups - list of string which holds the parent group names (all parents in the hierarchy)
+ * @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{
+ List<String> checkList = new ArrayList<String>();
+ for (String group : groups) {
+ if (!checkList.contains(group)) {
+ checkList.add(group);
+ }
+ else {
+ if (log.isDebugEnabled()) {
+ log.debug("duplicate group defined: " + group);
+ }
+ throw new RestAPIException("Invalid Service 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);
+ }
+ }
+ }
+
}
[2/7] stratos git commit: Correcting the exception throwing
Posted by im...@apache.org.
Correcting the exception throwing
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/1bea6c81
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/1bea6c81
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/1bea6c81
Branch: refs/heads/master
Commit: 1bea6c8191310403a3c60b70e1159d8679e67bad
Parents: 27ee9ea
Author: Vishanth <vi...@gmail.com>
Authored: Mon May 11 09:37:07 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon May 11 12:19:59 2015 +0530
----------------------------------------------------------------------
.../java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/1bea6c81/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 ab04a31..8c941d5 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, InvalidCartridgeGroupDefinitionException {
+ GroupBean serviceGroupDefinition) throws RestAPIException {
try {
StratosApiV41Utils.addServiceGroup(serviceGroupDefinition);
URI url = uriInfo.getAbsolutePathBuilder().path(serviceGroupDefinition.getName()).build();
[7/7] stratos git commit: Updating the method comments
Posted by im...@apache.org.
Updating the method comments
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/27ee9ea2
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/27ee9ea2
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/27ee9ea2
Branch: refs/heads/master
Commit: 27ee9ea253c26dfbe7cf7e1f5071127592f0114c
Parents: 0a6518d
Author: Vishanth <vi...@gmail.com>
Authored: Fri May 8 12:29:01 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon May 11 12:19:59 2015 +0530
----------------------------------------------------------------------
.../stratos/rest/endpoint/api/StratosApiV41Utils.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/27ee9ea2/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 85fb00d..2081713 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
@@ -968,6 +968,7 @@ public class StratosApiV41Utils {
* Add a Service Group
*
* @param serviceGroupDefinition serviceGroupDefinition
+ * @throws InvalidCartridgeGroupDefinitionException
* @throws RestAPIException
*/
public static void addServiceGroup(GroupBean serviceGroupDefinition)
@@ -3234,7 +3235,7 @@ public class StratosApiV41Utils {
* This method is to validate the cartridge duplication in the group definition recursively for group within groups
*
* @param groupBean - cartridge group definition
- * @throws RestAPIException - throws the rest api exception when the group definition is invalid
+ * @throws InvalidCartridgeGroupDefinitionException - throws when the group definition is invalid
*/
private static void validateCartridgeDuplicationInGroupDefinition(GroupBean groupBean)
throws InvalidCartridgeGroupDefinitionException {
@@ -3260,7 +3261,7 @@ public class StratosApiV41Utils {
* This method is to validate the duplication of cartridges from the given list
*
* @param cartridges - list of strings which holds the cartridgeTypes values
- * @throws RestAPIException - throws the rest api exception when the cartridges are duplicated
+ * @throws InvalidCartridgeGroupDefinitionException - throws when the cartridges are duplicated
*/
private static void validateCartridgeDuplicationInGroup(List<String> cartridges)
throws InvalidCartridgeGroupDefinitionException {
@@ -3283,7 +3284,7 @@ public class StratosApiV41Utils {
*
* @param groupBean - cartridge group definition
* @param parentGroups - list of string which holds the parent group names (all parents in the hierarchy)
- * @throws RestAPIException - throws the rest api exception when the group definition is invalid
+ * @throws InvalidCartridgeGroupDefinitionException - throws when the group definition is invalid
*/
private static void validateGroupDuplicationInGroupDefinition(GroupBean groupBean, List<String> parentGroups)
throws InvalidCartridgeGroupDefinitionException {
@@ -3314,7 +3315,7 @@ public class StratosApiV41Utils {
*
* @param groups - cartridge group definition
* @param parentGroups - list of string which holds the parent group names (all parents in the hierarchy)
- * @throws RestAPIException - throws the rest api exception when group duplicate or when cyclic behaviour occurs
+ * @throws InvalidCartridgeGroupDefinitionException - throws when group duplicate or when cyclic behaviour occurs
*/
private static void validateGroupDuplicationInGroup(List<String> groups, List<String> parentGroups)
throws InvalidCartridgeGroupDefinitionException {