Refactor code Sdc-controller 93/42493/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Thu, 12 Apr 2018 12:54:26 +0000 (14:54 +0200)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Thu, 12 Apr 2018 12:54:26 +0000 (14:54 +0200)
Rework the Sdc-controller and mainly blueprintArtifact so that the
resource attached is fully available in this class

Issue-ID: CLAMP-151
Change-Id: I77210cfa90a04df505566ff7e5f093c768cbbda9
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java
src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java
src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java

index 5a29264..71d5ae3 100644 (file)
  * ===================================================================
  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
-
 /**
  * This class is useful to store the information concerning
  * blueprint artifact extracted from SDC CSAR
  */
+
 package org.onap.clamp.clds.sdc.controller.installer;
 
+import org.onap.sdc.api.notification.IResourceInstance;
+
 public class BlueprintArtifact {
 
     private String dcaeBlueprint;
     private String blueprintArtifactName;
-    private String blueprintInvariantResourceUuid;
     private String blueprintInvariantServiceUuid;
-    private String blueprintResourceInstanceName;
+    private IResourceInstance resourceAttached;
 
     public String getDcaeBlueprint() {
         return dcaeBlueprint;
@@ -51,14 +52,6 @@ public class BlueprintArtifact {
         this.blueprintArtifactName = blueprintArtifactName;
     }
 
-    public String getBlueprintInvariantResourceUuid() {
-        return blueprintInvariantResourceUuid;
-    }
-
-    public void setBlueprintInvariantResourceUuid(String blueprintInvariantResourceUuid) {
-        this.blueprintInvariantResourceUuid = blueprintInvariantResourceUuid;
-    }
-
     public String getBlueprintInvariantServiceUuid() {
         return blueprintInvariantServiceUuid;
     }
@@ -67,11 +60,11 @@ public class BlueprintArtifact {
         this.blueprintInvariantServiceUuid = blueprintInvariantServiceUuid;
     }
 
-    public String getBlueprintResourceInstanceName() {
-        return blueprintResourceInstanceName;
+    public IResourceInstance getResourceAttached() {
+        return resourceAttached;
     }
 
-    public void setBlueprintResourceInstanceName(String blueprintResourceInstanceName) {
-        this.blueprintResourceInstanceName = blueprintResourceInstanceName;
+    public void setResourceAttached(IResourceInstance resourceAttached) {
+        this.resourceAttached = resourceAttached;
     }
 }
index aacef0a..c2652bc 100644 (file)
@@ -135,15 +135,15 @@ public class CsarHandler {
                     try (InputStream stream = zipFile.getInputStream(entry)) {
                         blueprintArtifact.setDcaeBlueprint(IOUtils.toString(stream));
                     }
-                    IResourceInstance resource = searchForResourceByInstanceName(entry.getName().substring(
+                    blueprintArtifact.setResourceAttached(searchForResourceByInstanceName(entry.getName().substring(
                             entry.getName().indexOf(RESOURCE_INSTANCE_NAME_PREFIX)
                                     + RESOURCE_INSTANCE_NAME_PREFIX.length(),
-                            entry.getName().indexOf(RESOURCE_INSTANCE_NAME_SUFFIX)));
-                    blueprintArtifact.setBlueprintInvariantResourceUuid(resource.getResourceInvariantUUID());
-                    blueprintArtifact.setBlueprintResourceInstanceName(resource.getResourceInstanceName());
+                            entry.getName().indexOf(RESOURCE_INSTANCE_NAME_SUFFIX))));
+                    this.mapOfBlueprints.put(blueprintArtifact.getResourceAttached().getResourceInstanceName(),
+                            blueprintArtifact);
                     logger.info("Found a blueprint entry in the CSAR " + blueprintArtifact.getBlueprintArtifactName()
-                            + " for resource instance Name " + resource.getResourceInstanceName());
-                    this.mapOfBlueprints.put(blueprintArtifact.getBlueprintResourceInstanceName(), blueprintArtifact);
+                            + " for resource instance Name "
+                            + blueprintArtifact.getResourceAttached().getResourceInstanceName());
                 }
             }
             logger.info(this.mapOfBlueprints.size() + " blueprint(s) will be converted to closed loop");
index ded75dd..5a00a82 100644 (file)
@@ -173,7 +173,7 @@ public class CsarInstallerImpl implements CsarInstaller {
             throws IOException, ParseException, InterruptedException {
         return dcaeInventoryService.getDcaeInformation(blueprintArtifact.getBlueprintArtifactName(),
                 blueprintArtifact.getBlueprintInvariantServiceUuid(),
-                blueprintArtifact.getBlueprintInvariantResourceUuid()).getTypeId();
+                blueprintArtifact.getResourceAttached().getResourceInvariantUUID()).getTypeId();
     }
 
     private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintArtifact blueprintArtifact,
@@ -209,7 +209,7 @@ public class CsarInstallerImpl implements CsarInstaller {
         cldsModel.setTemplateId(cldsTemplate.getId());
         cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\""
                 + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\""
-                + blueprintArtifact.getBlueprintInvariantResourceUuid()
+                + blueprintArtifact.getResourceAttached().getResourceInvariantUUID()
                 + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]},{\"name\":\"deployParameters\",\"value\":{\n"
                 + "        \"policy_id\": \"" + "test" + "\"" + "      }}]}");
         cldsModel.setBpmnText(cldsTemplate.getBpmnText());
index b741f7c..9009d37 100644 (file)
@@ -67,6 +67,7 @@ public class CsarInstallerItCase {
     private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar";
     private static final String INVARIANT_SERVICE_UUID = "4cc5b45a-1f63-4194-8100-cd8e14248c92";
     private static final String INVARIANT_RESOURCE1_UUID = "07e266fc-49ab-4cd7-8378-ca4676f1b9ec";
+    private static final String INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName";
     @Autowired
     private CsarInstaller csarInstaller;
     @Autowired
@@ -77,6 +78,7 @@ public class CsarInstallerItCase {
             throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
         CsarHandler csarHandler = Mockito.mock(CsarHandler.class);
         BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class);
+        Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(Mockito.mock(IResourceInstance.class));
         Map<String, BlueprintArtifact> blueprintMap = new HashMap<>();
         blueprintMap.put("resourceid", blueprintArtifact);
         Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap);
@@ -93,8 +95,9 @@ public class CsarInstallerItCase {
         // Create fake resource in notification
         List<IResourceInstance> listResources = new ArrayList<>();
         IResourceInstance resource = Mockito.mock(IResourceInstance.class);
-        Mockito.when(resource.getResourceInstanceName()).thenReturn("mm-e 0");
-        Mockito.when(resource.getResourceInvariantUUID()).thenReturn("mme0-invariantUuid");
+        Mockito.when(resource.getResourceInstanceName()).thenReturn(INSTANCE_NAME_RESOURCE1);
+        Mockito.when(resource.getResourceInvariantUUID()).thenReturn(INVARIANT_RESOURCE1_UUID);
+        listResources.add(resource);
         Mockito.when(notificationData.getResources()).thenReturn(listResources);
         // Create fake blueprint artifact
         BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class);
@@ -102,7 +105,7 @@ public class CsarInstallerItCase {
                 .thenReturn(ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml"));
         Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(CSAR_ARTIFACT_NAME);
         Mockito.when(blueprintArtifact.getBlueprintInvariantServiceUuid()).thenReturn(INVARIANT_SERVICE_UUID);
-        Mockito.when(blueprintArtifact.getBlueprintInvariantResourceUuid()).thenReturn(INVARIANT_RESOURCE1_UUID);
+        Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(resource);
         Map<String, BlueprintArtifact> blueprintMap = new HashMap<>();
         blueprintMap.put("resourceid", blueprintArtifact);
         // Build fake csarhandler
index b02e8ba..397a6a6 100644 (file)
@@ -132,8 +132,8 @@ public class CsarHandlerTest {
         // Test additional properties from Sdc notif
         assertEquals(BLUEPRINT1_NAME,
                 csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName());
-        assertEquals(RESOURCE1_UUID,
-                csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantResourceUuid());
+        assertEquals(RESOURCE1_UUID, csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getResourceAttached()
+                .getResourceInvariantUUID());
         assertEquals(SERVICE_UUID,
                 csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid());
         // Do some cleanup
@@ -158,8 +158,8 @@ public class CsarHandlerTest {
         // Test additional properties from Sdc notif
         assertEquals(BLUEPRINT1_NAME,
                 csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName());
-        assertEquals(RESOURCE1_UUID,
-                csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantResourceUuid());
+        assertEquals(RESOURCE1_UUID, csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getResourceAttached()
+                .getResourceInvariantUUID());
         assertEquals(SERVICE_UUID,
                 csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid());
         Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME);