From 2029624f01d163a06bb6f8b6ddc87975571b088a Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Mon, 12 Mar 2018 19:37:34 +0100 Subject: Add csar Handler Add a csar handler to save the Csar downloaded from SDC Issue-ID: CLAMP-81 Change-Id: I59d33ea3754e8e6acbe107c32fdcf83c1f236171 Signed-off-by: Determe, Sebastien (sd378r) --- .../resources/example/sdc/service-Simsfoimap0112.csar | Bin 0 -> 51391 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/test/resources/example/sdc/service-Simsfoimap0112.csar (limited to 'src/test/resources/example/sdc/service-Simsfoimap0112.csar') diff --git a/src/test/resources/example/sdc/service-Simsfoimap0112.csar b/src/test/resources/example/sdc/service-Simsfoimap0112.csar new file mode 100644 index 000000000..160c8f2cc Binary files /dev/null and b/src/test/resources/example/sdc/service-Simsfoimap0112.csar differ -- cgit 1.2.3-korg From 1c6610921488ad9e8ddf69708949f27bd8736bc0 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Thu, 29 Mar 2018 17:55:09 +0200 Subject: Remove useles file in CSAR Remove the file in CSAR that was useless Issue-ID: CLAMP-146 Change-Id: Ia945af65bb8bfd39cdaf6631825b0480f1e6ad53 Signed-off-by: Determe, Sebastien (sd378r) --- .../example/sdc/service-Simsfoimap0112.csar | Bin 51391 -> 49933 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'src/test/resources/example/sdc/service-Simsfoimap0112.csar') diff --git a/src/test/resources/example/sdc/service-Simsfoimap0112.csar b/src/test/resources/example/sdc/service-Simsfoimap0112.csar index 160c8f2cc..fac487cec 100644 Binary files a/src/test/resources/example/sdc/service-Simsfoimap0112.csar and b/src/test/resources/example/sdc/service-Simsfoimap0112.csar differ -- cgit 1.2.3-korg From 6914f938afd9cec84d6bb2b044cef74f4e997ab1 Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 12 Feb 2019 21:34:58 +0100 Subject: support multiple CL Support multiple CL CSAR deployment per service/vnf Issue-ID: CLAMP-289 Change-Id: I6e52da07b393bffeff18e16a5afa78ef14162935 Signed-off-by: sebdet --- .../clds/sdc/controller/installer/CsarHandler.java | 3 +- .../controller/installer/CsarInstallerImpl.java | 32 +++---- .../controller/installer/CsarInstallerItCase.java | 59 +++++++----- .../sdc/controller/installer/CsarHandlerTest.java | 29 +++--- .../example/sdc/blueprint-dcae/tca_3.yaml | 104 +++++++++++++++++++++ .../example/sdc/service-Simsfoimap0112.csar | Bin 49933 -> 52391 bytes 6 files changed, 173 insertions(+), 54 deletions(-) create mode 100644 src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml (limited to 'src/test/resources/example/sdc/service-Simsfoimap0112.csar') diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java index 1b7cb28c2..1a99919ee 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java @@ -138,8 +138,7 @@ public class CsarHandler { 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)))); - this.mapOfBlueprints.put(blueprintArtifact.getResourceAttached().getResourceInstanceName(), - blueprintArtifact); + this.mapOfBlueprints.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); logger.info("Found a blueprint entry in the CSAR " + blueprintArtifact.getBlueprintArtifactName() + " for resource instance Name " + blueprintArtifact.getResourceAttached().getResourceInstanceName()); diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java index 50090920e..bfda6924d 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java @@ -25,8 +25,8 @@ package org.onap.clamp.clds.sdc.controller.installer; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; - import com.google.gson.JsonObject; + import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -59,8 +59,9 @@ import org.springframework.transaction.annotation.Transactional; import org.yaml.snakeyaml.Yaml; /** - * This class will be instantiated by spring config, and used by Sdc Controller. There is no state kept by the bean. - * It's used to deploy the csar/notification received from SDC in DB. + * This class will be instantiated by spring config, and used by Sdc Controller. + * There is no state kept by the bean. It's used to deploy the csar/notification + * received from SDC in DB. */ public class CsarInstallerImpl implements CsarInstaller { @@ -101,15 +102,14 @@ public class CsarInstallerImpl implements CsarInstaller { boolean alreadyInstalled = true; for (Entry blueprint : csar.getMapOfBlueprints().entrySet()) { alreadyInstalled = alreadyInstalled - && (CldsModel.retrieve(cldsDao, buildModelName(csar, blueprint.getKey()), true).getId() != null) ? true - : false; + && CldsModel.retrieve(cldsDao, buildModelName(csar, blueprint.getValue()), true).getId() != null; } return alreadyInstalled; } - public static String buildModelName(CsarHandler csar, String resourceInstanceName) + public static String buildModelName(CsarHandler csar, BlueprintArtifact artifact) throws SdcArtifactInstallerException { - String policyScopePrefix = searchForPolicyScopePrefix(csar.getMapOfBlueprints().get(resourceInstanceName)); + String policyScopePrefix = searchForPolicyScopePrefix(artifact); if (policyScopePrefix.contains("*")) { // This is policy_filter type policyScopePrefix = policyScopePrefix.replaceAll("\\*", ""); @@ -117,9 +117,10 @@ public class CsarInstallerImpl implements CsarInstaller { // This is normally the get_input case policyScopePrefix = MODEL_NAME_PREFIX; } - return policyScopePrefix + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v" - + csar.getSdcNotification().getServiceVersion().replace('.', '_') + "_" - + resourceInstanceName.replaceAll(" ", ""); + return (policyScopePrefix + "_" + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v" + + csar.getSdcNotification().getServiceVersion() + "_" + + artifact.getResourceAttached().getResourceInstanceName().replaceAll(" ", "") + "_" + + artifact.getBlueprintArtifactName().replace(".yaml", "")).replace('.', '_'); } @Override @@ -214,8 +215,8 @@ public class CsarInstallerImpl implements CsarInstaller { } /** - * This call must be done when deploying the SDC notification as this call get the latest version of the artifact - * (version can be specified to DCAE call) + * This call must be done when deploying the SDC notification as this call get + * the latest version of the artifact (version can be specified to DCAE call) * * @return The DcaeInventoryResponse object containing the dcae values */ @@ -236,8 +237,7 @@ public class CsarInstallerImpl implements CsarInstaller { "{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getDcaeBlueprint() + "\"]}]}"); template .setImageText(IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream())); - template.setName(TEMPLATE_NAME_PREFIX - + buildModelName(csar, blueprintArtifact.getResourceAttached().getResourceInstanceName())); + template.setName(TEMPLATE_NAME_PREFIX + buildModelName(csar, blueprintArtifact)); template.save(cldsDao, null); logger.info("Fake Clds Template created for blueprint " + blueprintArtifact.getBlueprintArtifactName() + " with name " + template.getName()); @@ -246,14 +246,14 @@ public class CsarInstallerImpl implements CsarInstaller { private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintArtifact blueprintArtifact, CldsTemplate cldsTemplate, DcaeInventoryResponse dcaeInventoryResponse) throws SdcArtifactInstallerException { - + if (dcaeInventoryResponse == null) { throw new SdcArtifactInstallerException( "DCAE inventory response is NULL, query to DCAE fail to be answered properly, this is required to deploy CSAR properly !!!"); } try { CldsModel cldsModel = new CldsModel(); - cldsModel.setName(buildModelName(csar, blueprintArtifact.getResourceAttached().getResourceInstanceName())); + cldsModel.setName(buildModelName(csar, blueprintArtifact)); cldsModel.setBlueprintText(blueprintArtifact.getDcaeBlueprint()); cldsModel.setTemplateName(cldsTemplate.getName()); cldsModel.setTemplateId(cldsTemplate.getId()); diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java index 276f50910..2c24dcb5c 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java @@ -69,8 +69,8 @@ public class CsarInstallerItCase { 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 INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad"; - private static final String INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1"; - private static final String INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2"; + private static final String RESOURCE_INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1"; + private static final String RESOURCE_INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2"; @Autowired private CsarInstaller csarInstaller; @Autowired @@ -92,14 +92,14 @@ public class CsarInstallerItCase { } private BlueprintArtifact buildFakeBuildprintArtifact(String instanceName, String invariantResourceUuid, - String blueprintFilePath, String csarArtifactName, String invariantServiceUuid) throws IOException { + String blueprintFilePath, String artifactName, String invariantServiceUuid) throws IOException { IResourceInstance resource = Mockito.mock(IResourceInstance.class); Mockito.when(resource.getResourceInstanceName()).thenReturn(instanceName); Mockito.when(resource.getResourceInvariantUUID()).thenReturn(invariantResourceUuid); BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); Mockito.when(blueprintArtifact.getDcaeBlueprint()) .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath)); - Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(csarArtifactName); + Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(artifactName); Mockito.when(blueprintArtifact.getBlueprintInvariantServiceUuid()).thenReturn(invariantServiceUuid); Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(resource); return blueprintArtifact; @@ -115,17 +115,23 @@ public class CsarInstallerItCase { Mockito.when(notificationData.getResources()).thenReturn(listResources); Map blueprintMap = new HashMap<>(); Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); - // Create fake blueprint artifact 1 - BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact(INSTANCE_NAME_RESOURCE1, - INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", CSAR_ARTIFACT_NAME, - INVARIANT_SERVICE_UUID); + // Create fake blueprint artifact 1 on resource1 + BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, + INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", "tca.yaml", INVARIANT_SERVICE_UUID); listResources.add(blueprintArtifact.getResourceAttached()); - blueprintMap.put(blueprintArtifact.getResourceAttached().getResourceInstanceName(), blueprintArtifact); - // Create fake blueprint artifact 2 - blueprintArtifact = buildFakeBuildprintArtifact(INSTANCE_NAME_RESOURCE2, INVARIANT_RESOURCE2_UUID, - "example/sdc/blueprint-dcae/tca_2.yaml", CSAR_ARTIFACT_NAME, INVARIANT_SERVICE_UUID); + blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); + // Create fake blueprint artifact 2 on resource2 + blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE2, INVARIANT_RESOURCE2_UUID, + "example/sdc/blueprint-dcae/tca_2.yaml", "tca_2.yaml", INVARIANT_SERVICE_UUID); listResources.add(blueprintArtifact.getResourceAttached()); - blueprintMap.put(blueprintArtifact.getResourceAttached().getResourceInstanceName(), blueprintArtifact); + blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); + + // Create fake blueprint artifact 3 on resource 1 so that it's possible to + // test multiple CL deployment per Service/vnf + blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, INVARIANT_RESOURCE1_UUID, + "example/sdc/blueprint-dcae/tca_3.yaml", "tca_3.yaml", INVARIANT_SERVICE_UUID); + blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); + // Build fake csarhandler Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); // Build fake csar Helper @@ -153,40 +159,45 @@ public class CsarInstallerItCase { String generatedName = RandomStringUtils.randomAlphanumeric(5); CsarHandler csar = buildFakeCsarHandler(generatedName); csarInstaller.installTheCsar(csar); - CldsModel cldsModel1 = verifyClosedLoopModelLoadedInDb(csar, generatedName, INSTANCE_NAME_RESOURCE1); + CldsModel cldsModel1 = verifyClosedLoopModelLoadedInDb(csar, "tca.yaml"); JSONAssert.assertEquals( IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json")), cldsModel1.getPropText(), true); - CldsModel cldsModel2 = verifyClosedLoopModelLoadedInDb(csar, generatedName, INSTANCE_NAME_RESOURCE2); + CldsModel cldsModel2 = verifyClosedLoopModelLoadedInDb(csar, "tca_2.yaml"); JSONAssert.assertEquals( IOUtils .toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json")), cldsModel2.getPropText(), true); + CldsModel cldsModel3 = verifyClosedLoopModelLoadedInDb(csar, "tca_3.yaml"); + JSONAssert.assertEquals( + IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json")), + cldsModel3.getPropText(), true); } - private CldsModel verifyClosedLoopModelLoadedInDb(CsarHandler csar, String generatedName, - String instanceNameResource) throws SdcArtifactInstallerException { + private CldsModel verifyClosedLoopModelLoadedInDb(CsarHandler csar, String artifactName) + throws SdcArtifactInstallerException { + // Get the template back from DB - CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, - CsarInstallerImpl.TEMPLATE_NAME_PREFIX + CsarInstallerImpl.buildModelName(csar, instanceNameResource), - false); + CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, CsarInstallerImpl.TEMPLATE_NAME_PREFIX + + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), false); assertNotNull(templateFromDb); assertNotNull(templateFromDb.getBpmnText()); assertNotNull(templateFromDb.getImageText()); assertNotNull(templateFromDb.getPropText()); assertTrue(templateFromDb.getPropText().contains("global") && templateFromDb.getPropText().contains("node_templates:")); - assertEquals(templateFromDb.getName(), - CsarInstallerImpl.TEMPLATE_NAME_PREFIX + CsarInstallerImpl.buildModelName(csar, instanceNameResource)); + assertEquals(templateFromDb.getName(), CsarInstallerImpl.TEMPLATE_NAME_PREFIX + + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName))); // Get the Model back from DB CldsModel modelFromDb = CldsModel.retrieve(cldsDao, - CsarInstallerImpl.buildModelName(csar, instanceNameResource), true); + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), true); assertNotNull(modelFromDb); assertNotNull(modelFromDb.getBpmnText()); assertNotNull(modelFromDb.getImageText()); assertNotNull(modelFromDb.getPropText()); assertTrue(modelFromDb.getPropText().contains("policy_id")); - assertEquals(CsarInstallerImpl.buildModelName(csar, instanceNameResource), modelFromDb.getName()); + assertEquals(CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), + modelFromDb.getName()); assertEquals(CsarInstallerImpl.CONTROL_NAME_PREFIX, modelFromDb.getControlNamePrefix()); return modelFromDb; } diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java index 725b1ff1c..bb4fd01f2 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java @@ -57,6 +57,7 @@ public class CsarHandlerTest { private static final String RESOURCE1_INSTANCE_NAME = "sim-1802 0"; private static final String RESOURCE1_INSTANCE_NAME_IN_CSAR = "sim18020"; private static final String BLUEPRINT1_NAME = "FOI.Simfoimap223S0112.event_proc_bp.yaml"; + private static final String BLUEPRINT2_NAME = "FOI.Simfoimap223S0112.event_proc_bp2.yaml"; @Test public void testConstructor() throws CsarHandlerException { @@ -124,20 +125,26 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getDcaeBlueprint(); assertNotNull(blueprint); assertTrue(!blueprint.isEmpty()); assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); // Test additional properties from Sdc notif - assertEquals(BLUEPRINT1_NAME, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); + assertEquals(BLUEPRINT1_NAME, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintArtifactName()); assertEquals(RESOURCE1_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getResourceAttached().getResourceInvariantUUID()); - assertEquals(SERVICE_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); + csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getResourceAttached().getResourceInvariantUUID()); + assertEquals(SERVICE_UUID, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintInvariantServiceUuid()); + + // Just check the second one is there as well + assertEquals(BLUEPRINT2_NAME, csar.getMapOfBlueprints().get(BLUEPRINT2_NAME).getBlueprintArtifactName()); + blueprint = csar.getMapOfBlueprints().get(BLUEPRINT2_NAME).getDcaeBlueprint(); + assertNotNull(blueprint); + assertTrue(!blueprint.isEmpty()); + assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); // Do some cleanup Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); Files.deleteIfExists(path); + } @Test @@ -150,17 +157,15 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getDcaeBlueprint(); assertNotNull(blueprint); assertTrue(!blueprint.isEmpty()); assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); // Test additional properties from Sdc notif - assertEquals(BLUEPRINT1_NAME, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); + assertEquals(BLUEPRINT1_NAME, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintArtifactName()); assertEquals(RESOURCE1_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getResourceAttached().getResourceInvariantUUID()); - assertEquals(SERVICE_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); + csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getResourceAttached().getResourceInvariantUUID()); + assertEquals(SERVICE_UUID, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintInvariantServiceUuid()); Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); // A double save should simply overwrite the existing csar.save(buildFakeSdcResut()); diff --git a/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml b/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml new file mode 100644 index 000000000..0ab831712 --- /dev/null +++ b/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml @@ -0,0 +1,104 @@ +tosca_definitions_version: cloudify_dsl_1_3 +imports: +- http://www.getcloudify.org/spec/cloudify/3.4/types.yaml +- https://onap.org:8443/repository/solutioning01-mte2-raw/type_files/docker/2.2.0/node-type.yaml +- https://onap.org:8443/repository/solutioning01-mte2-raw/type_files/relationship/1.0.0/node-type.yaml +- http://onap.org:8081/repository/solutioning01-mte2-raw/type_files/dmaap/dmaap_mr.yaml +inputs: + location_id: + type: string + service_id: + type: string + policy_id: + type: string +node_templates: + policy_0: + type: dcae.nodes.policy + properties: + policy_id: + get_input: policy_id + cdap_host_host: + type: dcae.nodes.StreamingAnalytics.SelectedCDAPInfrastructure + properties: + location_id: + get_input: location_id + scn_override: cdap_broker.solutioning-central.dcae.onap.org + interfaces: + cloudify.interfaces.lifecycle: { + } + tca_tca: + type: dcae.nodes.MicroService.cdap + properties: + app_config: + appDescription: DCAE Analytics Threshold Crossing Alert Application + appName: dcae-tca + tcaSubscriberOutputStreamName: TCASubscriberOutputStream + tcaVESAlertsTableName: TCAVESAlertsTable + tcaVESAlertsTableTTLSeconds: '1728000' + tcaVESMessageStatusTableName: TCAVESMessageStatusTable + tcaVESMessageStatusTableTTLSeconds: '86400' + thresholdCalculatorFlowletInstances: '2' + app_preferences: + publisherContentType: application/json + publisherHostName: mrlocal-mtnjftle01.onap.org + publisherHostPort: '3905' + publisherMaxBatchSize: '10' + publisherMaxRecoveryQueueSize: '100000' + publisherPollingInterval: '20000' + publisherProtocol: https + publisherTopicName: org.onap.dcae.dmaap.mtnje2.DcaeTestVESPub + publisherUserName: test@tca.af.dcae.onap.org + publisherUserPassword: password + subscriberConsumerGroup: OpenDCAE-c12 + subscriberConsumerId: c12 + subscriberContentType: application/json + subscriberHostName: mrlocal-mtnjftle01.onap.org + subscriberHostPort: '3905' + subscriberMessageLimit: '-1' + subscriberPollingInterval: '20000' + subscriberProtocol: https + subscriberTimeoutMS: '-1' + subscriberTopicName: org.onap.dcae.dmaap.mtnje2.DcaeTestVESSub + subscriberUserName: test@tca.af.dcae.onap.org + subscriberUserPassword: password + tca_policy: null + artifact_name: dcae-analytics-tca + artifact_version: 1.0.0 + connections: + streams_publishes: [ + ] + streams_subscribes: [ + ] + jar_url: http://somejar + location_id: + get_input: location_id + namespace: cdap_tca_hi_lo + programs: + - program_id: TCAVESCollectorFlow + program_type: flows + - program_id: TCADMaaPMRSubscriberWorker + program_type: workers + - program_id: TCADMaaPMRPublisherWorker + program_type: workers + service_component_type: cdap_app_tca + service_id: + get_input: service_id + streamname: TCASubscriberOutputStream + relationships: + - target: topic0 + type: dcae.relationships.subscribe_to_events + - target: topic1 + type: dcae.relationships.publish_events + - target: cdap_host_host + type: dcae.relationships.component_contained_in + - target: policy_0 + type: dcae.relationships.depends_on + topic0: + type: dcae.nodes.Topic + properties: + topic_name: '' + topic1: + type: dcae.nodes.Topic + properties: + topic_name: '' + diff --git a/src/test/resources/example/sdc/service-Simsfoimap0112.csar b/src/test/resources/example/sdc/service-Simsfoimap0112.csar index fac487cec..ea0e44a22 100644 Binary files a/src/test/resources/example/sdc/service-Simsfoimap0112.csar and b/src/test/resources/example/sdc/service-Simsfoimap0112.csar differ -- cgit 1.2.3-korg From 92cc4185fca63ddd882be5bcd9d4a626b627164f Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 12 Mar 2019 15:08:11 +0100 Subject: Add unit tests Add unit tests and fix code to support them, columns modified and csar installer fixed as well Issue-ID: CLAMP-306 Change-Id: I946ef1aa957ca36bbb00357308ac67a3f07dcdce Signed-off-by: sebdet --- extra/sql/bulkload/create-tables.sql | 4 +- .../clamp/clds/tosca/ToscaYamlToJsonConvertor.java | 10 ++- .../org/onap/clamp/loop/CsarInstallerImpl.java | 81 ++++++++------------- src/main/java/org/onap/clamp/loop/Loop.java | 2 +- .../policy/microservice/MicroServicePolicy.java | 15 +++- .../controller/installer/CsarInstallerItCase.java | 18 +++-- .../sdc/controller/installer/CsarHandlerTest.java | 2 +- .../org/onap/clamp/loop/CsarInstallerItCase.java | 48 +++++++++--- .../example/sdc/service-Simsfoimap0112.csar | Bin 52391 -> 52568 bytes 9 files changed, 100 insertions(+), 80 deletions(-) (limited to 'src/test/resources/example/sdc/service-Simsfoimap0112.csar') diff --git a/extra/sql/bulkload/create-tables.sql b/extra/sql/bulkload/create-tables.sql index 6d490c305..93c80cb36 100644 --- a/extra/sql/bulkload/create-tables.sql +++ b/extra/sql/bulkload/create-tables.sql @@ -16,7 +16,7 @@ create table loops ( name varchar(255) not null, - blueprint_yaml varchar(255) not null, + blueprint_yaml MEDIUMTEXT not null, dcae_blueprint_id varchar(255), dcae_deployment_id varchar(255), dcae_deployment_status_url varchar(255), @@ -36,7 +36,7 @@ create table micro_service_policies ( name varchar(255) not null, json_representation json not null, - policy_tosca varchar(255) not null, + policy_tosca MEDIUMTEXT not null, properties json, shared bit not null, primary key (name) diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java index 784d95e94..8a172abbc 100644 --- a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java +++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java @@ -82,13 +82,15 @@ public class ToscaYamlToJsonConvertor { this.cldsDao = cldsDao; } - @SuppressWarnings("unchecked") public String parseToscaYaml(String yamlString) { Yaml yaml = new Yaml(); - LinkedHashMap loadedYaml = (LinkedHashMap) yaml.load(yamlString); - LinkedHashMap nodeTypes = new LinkedHashMap(); - LinkedHashMap dataNodes = new LinkedHashMap(); + LinkedHashMap loadedYaml = yaml.load(yamlString); + if (loadedYaml == null) { + return ""; + } + LinkedHashMap nodeTypes = new LinkedHashMap<>(); + LinkedHashMap dataNodes = new LinkedHashMap<>(); JSONObject jsonEditorObject = new JSONObject(); JSONObject jsonParentObject = new JSONObject(); JSONObject jsonTempObject = new JSONObject(); diff --git a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java index 9627445d6..6e12f2940 100644 --- a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java @@ -33,7 +33,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; -import java.util.Optional; import org.json.simple.parser.ParseException; import org.onap.clamp.clds.client.DcaeInventoryServices; @@ -53,6 +52,7 @@ import org.onap.clamp.policy.operational.OperationalPolicy; import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.yaml.snakeyaml.Yaml; @@ -71,63 +71,40 @@ public class CsarInstallerImpl implements CsarInstaller { public static final String MODEL_NAME_PREFIX = "Loop_"; @Autowired - protected LoopsRepository loopRepository; + LoopsRepository loopRepository; @Autowired - private BlueprintParser blueprintParser; + BlueprintParser blueprintParser; @Autowired - private ChainGenerator chainGenerator; + ChainGenerator chainGenerator; @Autowired DcaeInventoryServices dcaeInventoryService; - @Autowired - public void CsarInstallerImpl(LoopsRepository loopRepository, BlueprintParser blueprintParser, - ChainGenerator chainGenerator, DcaeInventoryServices dcaeInventoryService) { - this.loopRepository = loopRepository; - this.blueprintParser = blueprintParser; - this.chainGenerator = chainGenerator; - this.dcaeInventoryService = dcaeInventoryService; - } - @Override public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException { boolean alreadyInstalled = true; for (Entry blueprint : csar.getMapOfBlueprints().entrySet()) { alreadyInstalled = alreadyInstalled - && loopRepository.existsById(buildModelName(csar, blueprint.getValue())); + && loopRepository.existsById(Loop.generateLoopName(csar.getSdcNotification().getServiceName(), + csar.getSdcNotification().getServiceVersion(), + blueprint.getValue().getResourceAttached().getResourceInstanceName(), + blueprint.getValue().getBlueprintArtifactName())); } return alreadyInstalled; } - public static String buildModelName(CsarHandler csar, BlueprintArtifact artifact) { - - return (MODEL_NAME_PREFIX + "_" + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v" - + csar.getSdcNotification().getServiceVersion() + "_" - + artifact.getResourceAttached().getResourceInstanceName().replaceAll(" ", "") + "_" - + artifact.getBlueprintArtifactName().replace(".yaml", "")).replace('.', '_'); - } - - public static String buildOperationalPolicyName(CsarHandler csar, BlueprintArtifact artifact) { - - return (MODEL_NAME_PREFIX + "_" + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v" - + csar.getSdcNotification().getServiceVersion() + "_" - + artifact.getResourceAttached().getResourceInstanceName().replaceAll(" ", "") + "_" - + artifact.getBlueprintArtifactName().replace(".yaml", "")).replace('.', '_'); - } - @Override - @Transactional + @Transactional(propagation = Propagation.REQUIRED) public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException, InterruptedException, PolicyModelException { try { logger.info("Installing the CSAR " + csar.getFilePath()); for (Entry blueprint : csar.getMapOfBlueprints().entrySet()) { logger.info("Processing blueprint " + blueprint.getValue().getBlueprintArtifactName()); - createLoopFromBlueprint(csar, blueprint.getValue()); + loopRepository.save(createLoopFromBlueprint(csar, blueprint.getValue())); } - createPolicyModel(csar); logger.info("Successfully installed the CSAR " + csar.getFilePath()); } catch (IOException e) { throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e); @@ -136,15 +113,6 @@ public class CsarInstallerImpl implements CsarInstaller { } } - private void createPolicyModel(CsarHandler csar) throws PolicyModelException { - try { - Optional policyModelYaml = csar.getPolicyModelYaml(); - // save policy model into the database - } catch (IOException e) { - throw new PolicyModelException("TransformerException when decoding the YamlText", e); - } - } - private Loop createLoopFromBlueprint(CsarHandler csar, BlueprintArtifact blueprintArtifact) throws IOException, ParseException, InterruptedException { Loop newLoop = new Loop(); @@ -154,15 +122,8 @@ public class CsarInstallerImpl implements CsarInstaller { blueprintArtifact.getResourceAttached().getResourceInstanceName(), blueprintArtifact.getBlueprintArtifactName())); newLoop.setLastComputedState(LoopState.DESIGN); - for (MicroService microService : blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint())) { - newLoop.getMicroServicePolicies().add(new MicroServicePolicy(microService.getName(), - csar.getPolicyModelYaml().orElse(""), false, new JsonObject(), new HashSet<>(Arrays.asList(newLoop)))); - } - newLoop.setOperationalPolicies( - new HashSet<>(Arrays.asList(new OperationalPolicy(Policy.generatePolicyName("OPERATIONAL", - csar.getSdcNotification().getServiceName(), csar.getSdcNotification().getServiceVersion(), - blueprintArtifact.getResourceAttached().getResourceInstanceName(), - blueprintArtifact.getBlueprintArtifactName()), newLoop, new JsonObject())))); + newLoop.setMicroServicePolicies(createMicroServicePolicies(csar, blueprintArtifact, newLoop)); + newLoop.setOperationalPolicies(createOperationalPolicies(csar, blueprintArtifact, newLoop)); // Set SVG XML computed // newLoop.setSvgRepresentation(svgRepresentation); newLoop.setGlobalPropertiesJson(createGlobalPropertiesJson(csar, blueprintArtifact)); @@ -172,6 +133,24 @@ public class CsarInstallerImpl implements CsarInstaller { return newLoop; } + private HashSet createOperationalPolicies(CsarHandler csar, BlueprintArtifact blueprintArtifact, + Loop newLoop) { + return new HashSet<>(Arrays.asList(new OperationalPolicy(Policy.generatePolicyName("OPERATIONAL", + csar.getSdcNotification().getServiceName(), csar.getSdcNotification().getServiceVersion(), + blueprintArtifact.getResourceAttached().getResourceInstanceName(), + blueprintArtifact.getBlueprintArtifactName()), newLoop, new JsonObject()))); + } + + private HashSet createMicroServicePolicies(CsarHandler csar, + BlueprintArtifact blueprintArtifact, Loop newLoop) throws IOException { + HashSet newSet = new HashSet<>(); + for (MicroService microService : blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint())) { + newSet.add(new MicroServicePolicy(microService.getName(), csar.getPolicyModelYaml().orElse(""), false, + new HashSet<>(Arrays.asList(newLoop)))); + } + return newSet; + } + private JsonObject createGlobalPropertiesJson(CsarHandler csar, BlueprintArtifact blueprintArtifact) { JsonObject globalProperties = new JsonObject(); globalProperties.add("dcaeDeployParameters", getAllBlueprintParametersInJson(blueprintArtifact)); diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java index cc7f1803c..a4cd86d07 100644 --- a/src/main/java/org/onap/clamp/loop/Loop.java +++ b/src/main/java/org/onap/clamp/loop/Loop.java @@ -91,7 +91,7 @@ public class Loop implements Serializable { @Column(columnDefinition = "json", name = "model_properties_json") private JsonObject modelPropertiesJson; - @Column(nullable = false, name = "blueprint_yaml") + @Column(columnDefinition = "MEDIUMTEXT", nullable = false, name = "blueprint_yaml") private String blueprint; @Expose diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java index 7ebe0edb2..857a3d747 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java @@ -39,6 +39,8 @@ import javax.persistence.Table; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; +import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor; +import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.dao.model.jsontype.StringJsonUserType; import org.onap.clamp.loop.Loop; import org.onap.clamp.policy.Policy; @@ -66,7 +68,7 @@ public class MicroServicePolicy implements Serializable, Policy { @Column(name = "shared", nullable = false) private Boolean shared; - @Column(name = "policy_tosca", nullable = false) + @Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca", nullable = false) private String policyTosca; @Expose @@ -81,13 +83,22 @@ public class MicroServicePolicy implements Serializable, Policy { // serialization } + public MicroServicePolicy(String name, String policyTosca, Boolean shared, Set usedByLoops) { + this.name = name; + this.policyTosca = policyTosca; + this.shared = shared; + this.jsonRepresentation = JsonUtils.GSON_JPA_MODEL + .fromJson(new ToscaYamlToJsonConvertor(null).parseToscaYaml(policyTosca), JsonObject.class); + this.usedByLoops = usedByLoops; + } + public MicroServicePolicy(String name, String policyTosca, Boolean shared, JsonObject jsonRepresentation, Set usedByLoops) { this.name = name; this.policyTosca = policyTosca; this.shared = shared; - this.jsonRepresentation = jsonRepresentation; this.usedByLoops = usedByLoops; + this.jsonRepresentation = jsonRepresentation; } @Override diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java index ce8a493da..d3a823fbc 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java @@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -68,7 +69,6 @@ import org.springframework.test.context.junit4.SpringRunner; @ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller") 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 INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad"; @@ -89,7 +89,8 @@ public class CsarInstallerItCase { blueprintMap.put("resourceid", blueprintArtifact); Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); Mockito.when(blueprintArtifact.getDcaeBlueprint()).thenReturn( - IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/not-recognized.yaml"))); + IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/not-recognized.yaml"), + StandardCharsets.UTF_8)); csarInstaller.installTheCsar(csarHandler); fail("Should have raised an SdcArtifactInstallerException"); } @@ -164,16 +165,17 @@ public class CsarInstallerItCase { csarInstaller.installTheCsar(csar); CldsModel cldsModel1 = verifyClosedLoopModelLoadedInDb(csar, "tca.yaml"); JSONAssert.assertEquals( - IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json")), + IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json"), + StandardCharsets.UTF_8), cldsModel1.getPropText(), true); CldsModel cldsModel2 = verifyClosedLoopModelLoadedInDb(csar, "tca_2.yaml"); - JSONAssert.assertEquals( - IOUtils - .toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json")), - cldsModel2.getPropText(), true); + JSONAssert.assertEquals(IOUtils.toString( + ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json"), + StandardCharsets.UTF_8), cldsModel2.getPropText(), true); CldsModel cldsModel3 = verifyClosedLoopModelLoadedInDb(csar, "tca_3.yaml"); JSONAssert.assertEquals( - IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json")), + IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json"), + StandardCharsets.UTF_8), cldsModel3.getPropText(), true); } diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java index 544c8ca1d..e00887478 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java @@ -161,7 +161,7 @@ public class CsarHandlerTest { CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests"); csar.save(buildFakeSdcResut()); String policyModelYaml = csar.getPolicyModelYaml().get(); - assertTrue(policyModelYaml.contains("tosca_simple_yaml_1_1")); + assertTrue(policyModelYaml.contains("tosca_simple_yaml_1_0_0")); } @Test diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java index 6bfee4c41..d1a4bdc56 100644 --- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java @@ -23,8 +23,7 @@ package org.onap.clamp.loop; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.util.ArrayList; @@ -33,6 +32,8 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import javax.transaction.Transactional; + import org.apache.commons.lang3.RandomStringUtils; import org.json.JSONException; import org.junit.Test; @@ -62,13 +63,16 @@ import org.springframework.test.context.junit4.SpringRunner; @ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller-new") public class CsarInstallerItCase { - private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar"; + private static final String CSAR_ARTIFACT_NAME = "example/sdc/service-Simsfoimap0112.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 INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad"; private static final String RESOURCE_INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1"; private static final String RESOURCE_INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2"; + @Autowired + private LoopsRepository loopsRepo; + @Autowired private CsarInstaller csarInstaller; @@ -113,10 +117,6 @@ public class CsarInstallerItCase { "example/sdc/blueprint-dcae/tca_3.yaml", "tca_3.yaml", INVARIANT_SERVICE_UUID); blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - ISdcCsarHelper sdcHelper = factory.getSdcCsarHelper(Thread.currentThread().getContextClassLoader() - .getResource("example/sdc/service-Simsfoimap0112.csar").getFile()); - // Build fake csarhandler Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); // Build fake csar Helper @@ -125,28 +125,54 @@ public class CsarInstallerItCase { Mockito.when(data.getValue("name")).thenReturn(generatedName); Mockito.when(notificationData.getServiceName()).thenReturn(generatedName); Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data); + + // Create helper based on real csar to test policy yaml and global properties + // set + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + ISdcCsarHelper sdcHelper = factory + .getSdcCsarHelper(Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile()); Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(sdcHelper); + // Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper); - Mockito.when(csarHandler.getPolicyModelYaml()).thenReturn(Optional.ofNullable("")); + Mockito.when(csarHandler.getPolicyModelYaml()) + .thenReturn(Optional.ofNullable(ResourceFileUtil.getResourceAsString("tosca/tca-policy-test.yaml"))); return csarHandler; } + @Test + @Transactional public void testIsCsarAlreadyDeployedTca() throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException, InterruptedException, PolicyModelException { String generatedName = RandomStringUtils.randomAlphanumeric(5); CsarHandler csarHandler = buildFakeCsarHandler(generatedName); - assertFalse(csarInstaller.isCsarAlreadyDeployed(csarHandler)); + assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isFalse(); csarInstaller.installTheCsar(csarHandler); - assertTrue(csarInstaller.isCsarAlreadyDeployed(csarHandler)); + assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isTrue(); } @Test + @Transactional public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException, JSONException, InterruptedException, PolicyModelException { String generatedName = RandomStringUtils.randomAlphanumeric(5); CsarHandler csar = buildFakeCsarHandler(generatedName); csarInstaller.installTheCsar(csar); - + assertThat(loopsRepo + .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml"))) + .isTrue(); + assertThat(loopsRepo + .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml"))) + .isTrue(); + assertThat(loopsRepo + .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml"))) + .isTrue(); + // Verify now that policy and json representation, global properties are well + // set + Loop loop = loopsRepo + .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml")).get(); + + assertThat(loop.getModelPropertiesJson().get("serviceDetails")).isNotNull(); + assertThat(loop.getModelPropertiesJson().get("resourceDetails")).isNotNull(); } } diff --git a/src/test/resources/example/sdc/service-Simsfoimap0112.csar b/src/test/resources/example/sdc/service-Simsfoimap0112.csar index ea0e44a22..8c16d31ee 100644 Binary files a/src/test/resources/example/sdc/service-Simsfoimap0112.csar and b/src/test/resources/example/sdc/service-Simsfoimap0112.csar differ -- cgit 1.2.3-korg