Github user imesh commented on a diff in the pull request:
https://github.com/apache/stratos/pull/296#discussion_r29760431
--- Diff:
components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
---
@@ -980,50 +981,41 @@ public static void addServiceGroup(GroupBean
serviceGroupDefinition) throws Rest
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());
+ }
- 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);
- 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 groups duplicate
in any groups and
+ //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 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);
--- End diff --
It might be better to add a descriptive error message to this exception
rather than directly wrapping the RemoteException in RestAPIException.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---