Deployment Flavour created incorrect Component Id 57/57057/1
authorsiddharth0905 <siddharth.singh4@amdocs.com>
Fri, 20 Jul 2018 14:44:53 +0000 (20:14 +0530)
committersiddharth0905 <siddharth.singh4@amdocs.com>
Fri, 20 Jul 2018 14:47:02 +0000 (20:17 +0530)
Deployment flavour created
with incorrect component id

Change-Id: I463a74b8139ec9689457e01602faf37384d01993
Issue-ID: SDC-1548
Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/DeploymentFlavorErrorBuilder.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerFactoryImpl.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/DeploymentFlavorManagerImpl.java
openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/VendorSoftwareProductErrorCodes.java

index b1b1b76..979b6c6 100644 (file)
@@ -8,5 +8,6 @@
   "VENDOR_LICENSE_ENTITY_NOT_FOUND": "NOT_FOUND",
   "VERSIONABLE_SUB_ENTITY_NOT_FOUND": "NOT_FOUND",
   "FEATURE_GROUP_NOT_EXIST_FOR_VSP": "NOT_FOUND",
-  "INVALID_COMPUTE_FLAVOR_ID": "NOT_FOUND"
+  "INVALID_COMPUTE_FLAVOR_ID": "NOT_FOUND",
+  "INVALID_COMPONENT_ID": "NOT_FOUND"
 }
\ No newline at end of file
index 8fa8bd2..ab08812 100644 (file)
@@ -35,6 +35,8 @@ public class DeploymentFlavorErrorBuilder {
             + ": name : must match %s";
     private static final String INVALID_COMPUTE_FLAVOR_ID_MSG =
             "Invalid request, Compute Flavor provided does not exist for this VFC.";
+    private static final String INVALID_COMPONENT_ID_MSG =
+            "Invalid request, Component provided does not exist for this VSP.";
     private static final String INVALID_COMPONENT_COMPUTE_ASSOCIATION_ERROR_MSG="VSP cannot be " +
             "submitted with an invalid Deployment Flavor. All Deployment Flavor should have atleast a VFC included with it's required Compute needs. " +
             "Please fix the Deployment Flavor %s and re-submit the VSP.";
@@ -55,8 +57,7 @@ public class DeploymentFlavorErrorBuilder {
         return builder.build();
     }
 
-    public static ErrorCode getFeatureGroupNotexistErrorBuilder( String featureGroupId, String
-            vspId, Version activeVersion){
+    public static ErrorCode getFeatureGroupNotexistErrorBuilder(){
         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
         builder.withId(VendorSoftwareProductErrorCodes.FEATURE_GROUP_NOT_EXIST_FOR_VSP);
         builder.withCategory(ErrorCategory.APPLICATION);
@@ -89,13 +90,20 @@ public class DeploymentFlavorErrorBuilder {
         builder.withMessage(String.format(DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED_MSG,name,vspId));
         return builder.build();
     }
-    public static ErrorCode getInvalidComputeIdErrorBuilder(String computeFlavorId, String
-            vfcId){
+
+    public static ErrorCode getInvalidComputeIdErrorBuilder() {
         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
         builder.withId(VendorSoftwareProductErrorCodes.INVALID_COMPUTE_FLAVOR_ID);
         builder.withCategory(ErrorCategory.APPLICATION);
-        builder.withMessage(String.format(INVALID_COMPUTE_FLAVOR_ID_MSG,computeFlavorId,
-                vfcId));
+        builder.withMessage(INVALID_COMPUTE_FLAVOR_ID_MSG);
+        return builder.build();
+    }
+
+    public static ErrorCode getInvalidComponentIdErrorBuilder() {
+        ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+        builder.withId(VendorSoftwareProductErrorCodes.INVALID_COMPONENT_ID);
+        builder.withCategory(ErrorCategory.APPLICATION);
+        builder.withMessage(INVALID_COMPONENT_ID_MSG);
         return builder.build();
     }
 
index 0eef524..4c0d8de 100644 (file)
@@ -19,6 +19,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
 import org.openecomp.sdc.vendorsoftwareproduct.DeploymentFlavorManager;
 import org.openecomp.sdc.vendorsoftwareproduct.DeploymentFlavorManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
@@ -30,7 +31,8 @@ public class DeploymentFlavorManagerFactoryImpl extends DeploymentFlavorManagerF
       VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(),
       DeploymentFlavorDaoFactory.getInstance().createInterface(),
       CompositionEntityDataManagerFactory.getInstance().createInterface(),
-      ComputeDaoFactory.getInstance().createInterface()
+      ComputeDaoFactory.getInstance().createInterface(),
+      ComponentDaoFactory.getInstance().createInterface()
   );
 
   @Override
index 56678ab..cb5533a 100644 (file)
 
 package org.openecomp.sdc.vendorsoftwareproduct.impl;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.errors.ErrorCode;
 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
 import org.openecomp.sdc.vendorsoftwareproduct.DeploymentFlavorManager;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDao;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
@@ -40,26 +49,22 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTempl
 import org.openecomp.sdc.versioning.VersioningUtil;
 import org.openecomp.sdc.versioning.dao.types.Version;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 public class DeploymentFlavorManagerImpl implements DeploymentFlavorManager {
   private final VendorSoftwareProductInfoDao vspInfoDao;
   private final DeploymentFlavorDao deploymentFlavorDao;
   private final CompositionEntityDataManager compositionEntityDataManager;
   private final ComputeDao computeDao;
+  private final ComponentDao componentDao;
 
   public DeploymentFlavorManagerImpl(VendorSoftwareProductInfoDao vspInfoDao,
                                      DeploymentFlavorDao deploymentFlavorDao,
                                      CompositionEntityDataManager compositionEntityDataManager,
-                                     ComputeDao computeDao) {
+                                     ComputeDao computeDao, ComponentDao componentDao) {
     this.vspInfoDao = vspInfoDao;
     this.deploymentFlavorDao = deploymentFlavorDao;
     this.compositionEntityDataManager = compositionEntityDataManager;
     this.computeDao = computeDao;
+    this.componentDao = componentDao;
 
   }
 
@@ -72,8 +77,7 @@ public class DeploymentFlavorManagerImpl implements DeploymentFlavorManager {
   public DeploymentFlavorEntity createDeploymentFlavor(
       DeploymentFlavorEntity deploymentFlavorEntity) {
     DeploymentFlavorEntity createDeploymentFlavor;
-    if (!vspInfoDao.isManual(deploymentFlavorEntity.getVspId(),
-        deploymentFlavorEntity.getVersion())) {
+    if (!vspInfoDao.isManual(deploymentFlavorEntity.getVspId(), deploymentFlavorEntity.getVersion())) {
       ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
           .getAddDeploymentNotSupportedHeatOnboardErrorBuilder();
       throw new CoreException(deploymentFlavorErrorBuilder);
@@ -100,8 +104,7 @@ public class DeploymentFlavorManagerImpl implements DeploymentFlavorManager {
     if (featureGroup != null && featureGroup.trim().length() > 0
           && (isEmpty(featureGroups) || (!(validFeatureGroup(featureGroups, featureGroup))))) {
         ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder
-            .getFeatureGroupNotexistErrorBuilder(featureGroup, deploymentFlavorEntity.getVspId(),
-                version);
+            .getFeatureGroupNotexistErrorBuilder();
         throw new CoreException(deploymentFlavorErrorBuilder);
     }
     validateComponentComputeAssociation(deploymentFlavorEntity, version);
@@ -145,47 +148,66 @@ public class DeploymentFlavorManagerImpl implements DeploymentFlavorManager {
     return valid;
   }
 
-  private void validateComponentComputeAssociation(DeploymentFlavorEntity deploymentFlavorEntity,
-                                                   Version version) {
-    List<ComponentComputeAssociation> componentComputeAssociationList = deploymentFlavorEntity
-        .getDeploymentFlavorCompositionData().getComponentComputeAssociations();
-    List<String> vfcList = new ArrayList<>();
-    if (!isEmpty(componentComputeAssociationList)) {
-      componentComputeAssociationList.forEach(componentComputeAssociation ->
-        validateComponentComputeAssocoationList(deploymentFlavorEntity,
-                version, vfcList, componentComputeAssociation));
-      Map<String, Integer> frequencyMapping = CollectionUtils.getCardinalityMap(vfcList);
-
-      for (Integer vfcCount : frequencyMapping.values()) {
-        if (vfcCount != 1) {
-          ErrorCode duplicateVfcAssociationErrorBuilder = DeploymentFlavorErrorBuilder
-              .getDuplicateVfcAssociationErrorBuilder();
-          throw new CoreException(duplicateVfcAssociationErrorBuilder);
+    private void validateComponentComputeAssociation(DeploymentFlavorEntity deploymentFlavorEntity,
+                                                     Version version) {
+        List<ComponentComputeAssociation> componentComputeAssociationList =
+                deploymentFlavorEntity.getDeploymentFlavorCompositionData().getComponentComputeAssociations();
+        List<String> vfcList = new ArrayList<>();
+        if (!isEmpty(componentComputeAssociationList)) {
+            componentComputeAssociationList.forEach(
+                    componentComputeAssociation -> validateComponentComputeAssocoationList(deploymentFlavorEntity,
+                            version,
+                            vfcList, componentComputeAssociation));
+            Map<String, Integer> frequencyMapping = CollectionUtils.getCardinalityMap(vfcList);
+
+            for (Integer vfcCount : frequencyMapping.values()) {
+                if (vfcCount != 1) {
+                    ErrorCode duplicateVfcAssociationErrorBuilder =
+                            DeploymentFlavorErrorBuilder.getDuplicateVfcAssociationErrorBuilder();
+                    throw new CoreException(duplicateVfcAssociationErrorBuilder);
+                }
+            }
         }
-      }
     }
-  }
 
-  private void validateComponentComputeAssocoationList(
-              DeploymentFlavorEntity deploymentFlavorEntity,
-              Version version,
-              List<String> vfcList,
-              ComponentComputeAssociation componentComputeAssociation) {
-    if ((componentComputeAssociation.getComponentId() == null || componentComputeAssociation
-        .getComponentId().trim().length() == 0)
-            && (componentComputeAssociation
-            .getComputeFlavorId() != null && componentComputeAssociation
-            .getComputeFlavorId().trim().length() > 0)) {
-      ErrorCode invalidAssociationErrorBuilder = DeploymentFlavorErrorBuilder
-          .getInvalidAssociationErrorBuilder();
-      throw new CoreException(invalidAssociationErrorBuilder);
-    } else if (componentComputeAssociation.getComponentId() != null
-            && componentComputeAssociation.getComponentId().trim().length() > 0) {
-      validateComponentComputeAssociationFlavour(deploymentFlavorEntity,
-              version, componentComputeAssociation);
-      vfcList.add(componentComputeAssociation.getComponentId());
+    private void validateComponentComputeAssocoationList(
+            DeploymentFlavorEntity deploymentFlavorEntity,
+            Version version,
+            List<String> vfcList,
+            ComponentComputeAssociation componentComputeAssociation) {
+        if ((componentComputeAssociation.getComponentId() == null || componentComputeAssociation
+                .getComponentId().trim().length() == 0)
+                && (componentComputeAssociation
+                .getComputeFlavorId() != null && componentComputeAssociation
+                .getComputeFlavorId().trim().length() > 0)) {
+            ErrorCode invalidAssociationErrorBuilder = DeploymentFlavorErrorBuilder
+                    .getInvalidAssociationErrorBuilder();
+            throw new CoreException(invalidAssociationErrorBuilder);
+        } else if (componentComputeAssociation.getComponentId() != null
+                && componentComputeAssociation.getComponentId().trim().length() > 0) {
+            validateComponentAssociation(deploymentFlavorEntity,
+                    version, componentComputeAssociation);
+
+            validateComponentComputeAssociationFlavour(deploymentFlavorEntity,
+                    version, componentComputeAssociation);
+            vfcList.add(componentComputeAssociation.getComponentId());
+        }
+    }
+
+    private void validateComponentAssociation(DeploymentFlavorEntity deploymentFlavorEntity, Version version,
+                                              ComponentComputeAssociation componentComputeAssociation) {
+
+        if (StringUtils.isNotBlank(componentComputeAssociation.getComponentId())) {
+            ComponentEntity componentEntity =
+                    componentDao.get(new ComponentEntity(deploymentFlavorEntity.getVspId(), version,
+                            componentComputeAssociation.getComponentId()));
+            if (componentEntity == null) {
+                ErrorCode invalidComputeIdErrorBuilder =
+                        DeploymentFlavorErrorBuilder.getInvalidComponentIdErrorBuilder();
+                throw new CoreException(invalidComputeIdErrorBuilder);
+            }
+        }
     }
-  }
 
   private void validateComponentComputeAssociationFlavour(
           DeploymentFlavorEntity deploymentFlavorEntity,
@@ -199,8 +221,7 @@ public class DeploymentFlavorManagerImpl implements DeploymentFlavorManager {
           componentComputeAssociation.getComputeFlavorId()));
       if (computeFlavor == null) {
         ErrorCode invalidComputeIdErrorBuilder = DeploymentFlavorErrorBuilder
-            .getInvalidComputeIdErrorBuilder(componentComputeAssociation.getComputeFlavorId(),
-                componentComputeAssociation.getComponentId());
+            .getInvalidComputeIdErrorBuilder();
         throw new CoreException(invalidComputeIdErrorBuilder);
       }
     }
index 4a4e883..83abbfb 100644 (file)
@@ -114,6 +114,7 @@ public class VendorSoftwareProductErrorCodes {
   public static final String DEPLOYMENT_FLAVOR_NAME_FORMAT_NOT_ALLOWED =
           "DEPLOYMENT_FLAVOR_NAME_FORMAT_NOT_ALLOWED";
   public static final String INVALID_COMPUTE_FLAVOR_ID = "INVALID_COMPUTE_FLAVOR_ID";
+  public static final String INVALID_COMPONENT_ID = "INVALID_COMPONENT_ID";
   public static final String DUPLICATE_COMPUTE_NAME_NOT_ALLOWED = "DUPLICATE_COMPUTE_NAME_NOT_ALLOWED";
   public static final String COMPUTE_NAME_FORMAT_NOT_ALLOWED = "COMPUTE_NAME_FORMAT_NOT_ALLOWED";