From 1e1f4b271a1531b01e3cf76b53d19470f31f3262 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Thu, 1 Mar 2018 18:33:26 +0100 Subject: Fix Clamp runtime Add the missing file for SDC Config in resource and docker clamp.env. Issue-ID: CLAMP-81 Change-Id: Ie1a22fcc1a8d95fcc5dd826353e989c7e1707abd Signed-off-by: Determe, Sebastien (sd378r) --- .../resources/clds/sdc-controllers-config.json | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/resources/clds/sdc-controllers-config.json (limited to 'src/main/resources/clds/sdc-controllers-config.json') diff --git a/src/main/resources/clds/sdc-controllers-config.json b/src/main/resources/clds/sdc-controllers-config.json new file mode 100644 index 000000000..df73a504f --- /dev/null +++ b/src/main/resources/clds/sdc-controllers-config.json @@ -0,0 +1,26 @@ +{ + "sdc-connections":{ + "sdc-controller1":{ + "user": "User1", + "consumerGroup": "consumerGroup1", + "consumerId": "consumerId1", + "environmentName": "environmentName1", + "sdcAddress": "hostname1", + "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", + "pollingInterval":10, + "pollingTimeout":30 + + }, + "sdc-controller2":{ + "user": "User2", + "consumerGroup": "consumerGroup2", + "consumerId": "consumerId2", + "environmentName": "environmentName2", + "sdcAddress": "hostname2", + "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", + "pollingInterval":10, + "pollingTimeout":30 + + } + } +} -- cgit 1.2.3-korg From 78100b4cad47bfb6171af3f4d9b84f9fd42f95b7 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Tue, 3 Apr 2018 16:57:38 +0200 Subject: New parameter Sdc controller There is a need to have that new parameter (message bus addresses) if the sdcAddress is not present Issue-ID: CLAMP-149 Change-Id: I336e7af6784a70b0b65c9610fc2e69e40126bdc0 Signed-off-by: Determe, Sebastien (sd378r) --- .../config/sdc/SdcSingleControllerConfiguration.java | 17 ++++++++++++++--- src/main/resources/clds/sdc-controllers-config.json | 10 ++++++---- .../sdc/SdcSingleControllerConfigurationTest.java | 13 +++++++++++++ src/test/resources/clds/sdc-controller-config-TLS.json | 5 +++-- .../clds/sdc-controller-config-bad-address.json | 12 ++++++++++++ src/test/resources/clds/sdc-controllers-config.json | 11 ++++++----- 6 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 src/test/resources/clds/sdc-controller-config-bad-address.json (limited to 'src/main/resources/clds/sdc-controllers-config.json') diff --git a/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java b/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java index d8bd992e9..e2aac55f1 100644 --- a/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java @@ -28,6 +28,7 @@ import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; import java.security.GeneralSecurityException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -65,6 +66,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration { public static final String ACTIVATE_SERVER_TLS_AUTH = "activateServerTLSAuth"; public static final String KEY_STORE_KEY = "keyStorePassword"; public static final String KEY_STORE_PATH = "keyStorePath"; + public static final String MESSAGE_BUS_ADDRESSES = "messageBusAddresses"; private String errorMessageKeyNotFound; /** * Supported artifact types. @@ -239,7 +241,10 @@ public class SdcSingleControllerConfiguration implements IConfiguration { throw new SdcParametersException(ENVIRONMENT_NAME_ATTRIBUTE_NAME + errorMessageKeyNotFound); } if (this.getAsdcAddress() == null || this.getAsdcAddress().isEmpty()) { - throw new SdcParametersException(SDC_ADDRESS_ATTRIBUTE_NAME + errorMessageKeyNotFound); + if (this.getMsgBusAddress() == null || this.getMsgBusAddress().isEmpty()) { + throw new SdcParametersException(SDC_ADDRESS_ATTRIBUTE_NAME + " and " + MESSAGE_BUS_ADDRESSES + + " are not set, one of them should be set for SDC client" + errorMessageKeyNotFound); + } } if (this.getPassword() == null || this.getPassword().isEmpty()) { throw new SdcParametersException(SDC_KEY_ATTRIBUTE_NAME + errorMessageKeyNotFound); @@ -265,11 +270,17 @@ public class SdcSingleControllerConfiguration implements IConfiguration { */ @Override public boolean isFilterInEmptyResources() { - return true; + return false; } @Override public List getMsgBusAddress() { - return null; + List addressesList = new ArrayList<>(); + if (jsonRootNode != null && jsonRootNode.get(MESSAGE_BUS_ADDRESSES) != null) { + jsonRootNode.get(MESSAGE_BUS_ADDRESSES).forEach(k -> addressesList.add(k.asText())); + return addressesList; + } else { + return addressesList; + } } } diff --git a/src/main/resources/clds/sdc-controllers-config.json b/src/main/resources/clds/sdc-controllers-config.json index df73a504f..bf1a758a8 100644 --- a/src/main/resources/clds/sdc-controllers-config.json +++ b/src/main/resources/clds/sdc-controllers-config.json @@ -5,10 +5,11 @@ "consumerGroup": "consumerGroup1", "consumerId": "consumerId1", "environmentName": "environmentName1", - "sdcAddress": "hostname1", + "sdcAddress": "sdc.api.simpledemo.onap.org:8080", "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", "pollingInterval":10, - "pollingTimeout":30 + "pollingTimeout":30, + "messageBusAddresses":["localhost"] }, "sdc-controller2":{ @@ -16,10 +17,11 @@ "consumerGroup": "consumerGroup2", "consumerId": "consumerId2", "environmentName": "environmentName2", - "sdcAddress": "hostname2", + "sdcAddress": "sdc.api.simpledemo.onap.org:8080", "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", "pollingInterval":10, - "pollingTimeout":30 + "pollingTimeout":30, + "messageBusAddresses":["localhost"] } } diff --git a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java index ecef30ee4..dd60d2796 100644 --- a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java +++ b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java @@ -20,6 +20,7 @@ package org.onap.clamp.clds.config.sdc; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -65,6 +66,9 @@ public class SdcSingleControllerConfigurationTest { sdcConfig.getRelevantArtifactTypes().size()); assertTrue(sdcConfig.activateServerTLSAuth()); assertEquals("ThePassword", sdcConfig.getKeyStorePassword()); + assertArrayEquals(new String[] { + "localhost" + }, sdcConfig.getMsgBusAddress().toArray()); } @Test(expected = SdcParametersException.class) @@ -77,6 +81,15 @@ public class SdcSingleControllerConfigurationTest { fail("Should have raised an exception"); } + @Test(expected = SdcParametersException.class) + public final void testAllRequiredParametersAddresses() + throws JsonParseException, JsonMappingException, IOException { + SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration( + "clds/sdc-controller-config-bad-address.json", "sdc-controller1"); + sdcConfig.testAllRequiredParameters(); + fail("Should have raised an exception"); + } + @Test public final void testConsumerGroupWithNull() throws JsonParseException, JsonMappingException, IOException { SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json", diff --git a/src/test/resources/clds/sdc-controller-config-TLS.json b/src/test/resources/clds/sdc-controller-config-TLS.json index d7642e6b1..066448ee3 100644 --- a/src/test/resources/clds/sdc-controller-config-TLS.json +++ b/src/test/resources/clds/sdc-controller-config-TLS.json @@ -8,6 +8,7 @@ "pollingInterval":10, "pollingTimeout":30, "activateServerTLSAuth": true, - "keyStorePassword":"bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", - "keyStorePath": "/test" + "keyStorePassword":"bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", + "keyStorePath": "/test", + "messageBusAddresses":["localhost"] } diff --git a/src/test/resources/clds/sdc-controller-config-bad-address.json b/src/test/resources/clds/sdc-controller-config-bad-address.json new file mode 100644 index 000000000..6775c6b3c --- /dev/null +++ b/src/test/resources/clds/sdc-controller-config-bad-address.json @@ -0,0 +1,12 @@ +{ + "user": "User", + "consumerGroup": "consumerGroup", + "consumerId": "consumerId", + "environmentName": "environmentName", + "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", + "pollingInterval":10, + "pollingTimeout":30, + "activateServerTLSAuth": true, + "keyStorePassword":"bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", + "keyStorePath": "/test" +} diff --git a/src/test/resources/clds/sdc-controllers-config.json b/src/test/resources/clds/sdc-controllers-config.json index df73a504f..ce56fef27 100644 --- a/src/test/resources/clds/sdc-controllers-config.json +++ b/src/test/resources/clds/sdc-controllers-config.json @@ -5,21 +5,22 @@ "consumerGroup": "consumerGroup1", "consumerId": "consumerId1", "environmentName": "environmentName1", - "sdcAddress": "hostname1", + "sdcAddress": "localhost:${docker.http-cache.port.host}", "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", "pollingInterval":10, - "pollingTimeout":30 - + "pollingTimeout":30, + "messageBusAddresses":["localhost"] }, "sdc-controller2":{ "user": "User2", "consumerGroup": "consumerGroup2", "consumerId": "consumerId2", "environmentName": "environmentName2", - "sdcAddress": "hostname2", + "sdcAddress": "localhost:${docker.http-cache.port.host}", "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", "pollingInterval":10, - "pollingTimeout":30 + "pollingTimeout":30, + "messageBusAddresses":["localhost"] } } -- cgit 1.2.3-korg From dd2d790dd97ec4260531bc1fdce5766bf85797d8 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Fri, 6 Apr 2018 11:48:07 +0200 Subject: Update SDC library Upgrade SDC library to latest and remove the message bus condition, it's now a mandatory parameter as well Issue-ID: CLAMP-149 Change-Id: I4c7ddcca6ac176380821bd8f1e4e3ef3d9fcea30 Signed-off-by: Determe, Sebastien (sd378r) --- pom.xml | 8 +++--- .../sdc/SdcSingleControllerConfiguration.java | 14 +++++----- .../sdc/controller/DistributionStatusMessage.java | 4 +-- .../clds/sdc/controller/SdcSingleController.java | 22 ++++++++-------- .../clds/sdc/controller/installer/CsarHandler.java | 14 +++++----- .../resources/clds/sdc-controllers-config.json | 30 ++++++++-------------- .../sdc/SdcSingleControllerConfigurationTest.java | 11 ++++---- .../sdc/controller/installer/CsarHandlerTest.java | 10 ++++---- .../resources/clds/sdc-controller-config-NULL.json | 5 ++-- .../resources/clds/sdc-controller-config-TLS.json | 2 +- .../clds/sdc-controller-config-bad-address.json | 12 --------- .../resources/clds/sdc-controller-config-bad.json | 2 +- .../sdc-controller-config-empty-encrypted.json | 14 ++++++++++ 13 files changed, 71 insertions(+), 77 deletions(-) delete mode 100644 src/test/resources/clds/sdc-controller-config-bad-address.json create mode 100644 src/test/resources/clds/sdc-controller-config-empty-encrypted.json (limited to 'src/main/resources/clds/sdc-controllers-config.json') diff --git a/pom.xml b/pom.xml index 007b6605e..608702997 100644 --- a/pom.xml +++ b/pom.xml @@ -479,14 +479,14 @@ - org.openecomp.sdc.sdc-distribution-client + org.onap.sdc.sdc-distribution-client sdc-distribution-client - 1.2.2 + 1.3.0 - org.openecomp.sdc.sdc-tosca + org.onap.sdc.sdc-tosca sdc-tosca - 1.2.2 + 1.3.3 diff --git a/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java b/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java index e2aac55f1..bc3d1b986 100644 --- a/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java @@ -36,7 +36,7 @@ import java.util.List; import org.apache.commons.codec.DecoderException; import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException; import org.onap.clamp.clds.util.CryptoUtils; -import org.openecomp.sdc.api.consumer.IConfiguration; +import org.onap.sdc.api.consumer.IConfiguration; /** * This class maps the SDC config JSON for one controller. @@ -129,8 +129,8 @@ public class SdcSingleControllerConfiguration implements IConfiguration { private String getEncryptedStringConfig(String key) throws GeneralSecurityException, DecoderException { if (jsonRootNode != null && jsonRootNode.get(key) != null) { - String config = CryptoUtils.decrypt(jsonRootNode.get(key).asText()); - return config.isEmpty() ? null : config; + return jsonRootNode.get(key).asText().isEmpty() ? null + : CryptoUtils.decrypt(jsonRootNode.get(key).asText()); } return null; } @@ -241,10 +241,10 @@ public class SdcSingleControllerConfiguration implements IConfiguration { throw new SdcParametersException(ENVIRONMENT_NAME_ATTRIBUTE_NAME + errorMessageKeyNotFound); } if (this.getAsdcAddress() == null || this.getAsdcAddress().isEmpty()) { - if (this.getMsgBusAddress() == null || this.getMsgBusAddress().isEmpty()) { - throw new SdcParametersException(SDC_ADDRESS_ATTRIBUTE_NAME + " and " + MESSAGE_BUS_ADDRESSES - + " are not set, one of them should be set for SDC client" + errorMessageKeyNotFound); - } + throw new SdcParametersException(SDC_ADDRESS_ATTRIBUTE_NAME + errorMessageKeyNotFound); + } + if (this.getMsgBusAddress() == null || this.getMsgBusAddress().isEmpty()) { + throw new SdcParametersException(MESSAGE_BUS_ADDRESSES + errorMessageKeyNotFound); } if (this.getPassword() == null || this.getPassword().isEmpty()) { throw new SdcParametersException(SDC_KEY_ATTRIBUTE_NAME + errorMessageKeyNotFound); diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java b/src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java index db5d271b0..ca4f97b1d 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java @@ -23,8 +23,8 @@ package org.onap.clamp.clds.sdc.controller; -import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; -import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +import org.onap.sdc.utils.DistributionStatusEnum; public class DistributionStatusMessage implements IDistributionStatusMessage { diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java index c02edbbf9..2744ef7ae 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java @@ -38,17 +38,17 @@ import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException; import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; import org.onap.clamp.clds.util.LoggingUtils; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; -import org.openecomp.sdc.api.consumer.INotificationCallback; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.impl.DistributionClientFactory; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.utils.DistributionActionResultEnum; -import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +import org.onap.sdc.api.consumer.INotificationCallback; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.impl.DistributionClientFactory; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.utils.DistributionStatusEnum; /** * This class handles one sdc controller defined in the config. 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 97ab05868..2b83905a8 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 @@ -41,13 +41,13 @@ import java.util.zip.ZipFile; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; /** * CsarDescriptor that will be used to deploy file in CLAMP file system. Some diff --git a/src/main/resources/clds/sdc-controllers-config.json b/src/main/resources/clds/sdc-controllers-config.json index bf1a758a8..d18a161a5 100644 --- a/src/main/resources/clds/sdc-controllers-config.json +++ b/src/main/resources/clds/sdc-controllers-config.json @@ -1,28 +1,18 @@ { "sdc-connections":{ - "sdc-controller1":{ - "user": "User1", + "sdc-controller":{ + "user": "clamp", "consumerGroup": "consumerGroup1", "consumerId": "consumerId1", - "environmentName": "environmentName1", - "sdcAddress": "sdc.api.simpledemo.onap.org:8080", - "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", - "pollingInterval":10, + "environmentName": "AUTO", + "sdcAddress": "sdc.api.simpledemo.onap.org:8443", + "password": "b7acccda32b98c5bb7acccda32b98c5b05D511BD6D93626E90D18E9D24D9B78CD34C7EE8012F0A189A28763E82271E50A5D4EC10C7D93E06E0A2D27CAE66B981", + "pollingInterval":30, "pollingTimeout":30, - "messageBusAddresses":["localhost"] - - }, - "sdc-controller2":{ - "user": "User2", - "consumerGroup": "consumerGroup2", - "consumerId": "consumerId2", - "environmentName": "environmentName2", - "sdcAddress": "sdc.api.simpledemo.onap.org:8080", - "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", - "pollingInterval":10, - "pollingTimeout":30, - "messageBusAddresses":["localhost"] - + "activateServerTLSAuth":"false", + "keyStorePassword":"", + "keyStorePath":"", + "messageBusAddresses":["ueb.api.simpledemo.onap.org"] } } } diff --git a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java index dd60d2796..00d5dffbb 100644 --- a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java +++ b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java @@ -22,6 +22,7 @@ package org.onap.clamp.clds.config.sdc; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -59,7 +60,7 @@ public class SdcSingleControllerConfigurationTest { assertEquals("consumerGroup", sdcConfig.getConsumerGroup()); assertEquals("consumerId", sdcConfig.getConsumerID()); assertEquals("environmentName", sdcConfig.getEnvironmentName()); - assertEquals("hostname", sdcConfig.getAsdcAddress()); + assertEquals("hostname:8080", sdcConfig.getAsdcAddress()); assertEquals(10, sdcConfig.getPollingInterval()); assertEquals(30, sdcConfig.getPollingTimeout()); assertEquals(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST.size(), @@ -81,13 +82,13 @@ public class SdcSingleControllerConfigurationTest { fail("Should have raised an exception"); } - @Test(expected = SdcParametersException.class) - public final void testAllRequiredParametersAddresses() + @Test + public final void testAllRequiredParametersEmptyEncrypted() throws JsonParseException, JsonMappingException, IOException { SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration( - "clds/sdc-controller-config-bad-address.json", "sdc-controller1"); + "clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1"); sdcConfig.testAllRequiredParameters(); - fail("Should have raised an exception"); + assertNull(sdcConfig.getKeyStorePassword()); } @Test 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 5486e652b..46bddaf4f 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 @@ -43,11 +43,11 @@ import org.mockito.Mockito; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; import org.onap.clamp.clds.util.ResourceFileUtil; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; public class CsarHandlerTest { diff --git a/src/test/resources/clds/sdc-controller-config-NULL.json b/src/test/resources/clds/sdc-controller-config-NULL.json index 5c8ec0cfe..bf310c706 100644 --- a/src/test/resources/clds/sdc-controller-config-NULL.json +++ b/src/test/resources/clds/sdc-controller-config-NULL.json @@ -3,8 +3,9 @@ "consumerGroup": "NULL", "consumerId": "consumerId", "environmentName": "environmentName", - "sdcAddress": "hostname", + "sdcAddress": "hostname:8080", "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", "pollingInterval":10, - "pollingTimeout":30 + "pollingTimeout":30, + "messageBusAddresses":["localhost"] } diff --git a/src/test/resources/clds/sdc-controller-config-TLS.json b/src/test/resources/clds/sdc-controller-config-TLS.json index 066448ee3..99366b765 100644 --- a/src/test/resources/clds/sdc-controller-config-TLS.json +++ b/src/test/resources/clds/sdc-controller-config-TLS.json @@ -3,7 +3,7 @@ "consumerGroup": "consumerGroup", "consumerId": "consumerId", "environmentName": "environmentName", - "sdcAddress": "hostname", + "sdcAddress": "hostname:8080", "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", "pollingInterval":10, "pollingTimeout":30, diff --git a/src/test/resources/clds/sdc-controller-config-bad-address.json b/src/test/resources/clds/sdc-controller-config-bad-address.json deleted file mode 100644 index 6775c6b3c..000000000 --- a/src/test/resources/clds/sdc-controller-config-bad-address.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "user": "User", - "consumerGroup": "consumerGroup", - "consumerId": "consumerId", - "environmentName": "environmentName", - "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", - "pollingInterval":10, - "pollingTimeout":30, - "activateServerTLSAuth": true, - "keyStorePassword":"bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", - "keyStorePath": "/test" -} diff --git a/src/test/resources/clds/sdc-controller-config-bad.json b/src/test/resources/clds/sdc-controller-config-bad.json index d99ed5801..194ff5f4b 100644 --- a/src/test/resources/clds/sdc-controller-config-bad.json +++ b/src/test/resources/clds/sdc-controller-config-bad.json @@ -5,7 +5,7 @@ "consumerGroup": "consumerGroup", "consumerId": "consumerId", "environmentName": "environmentName", - "sdcAddress": "hostname1", + "sdcAddress": "hostname1:8080", "pollingInterval": 10, "pollingTimeout": 30 } diff --git a/src/test/resources/clds/sdc-controller-config-empty-encrypted.json b/src/test/resources/clds/sdc-controller-config-empty-encrypted.json new file mode 100644 index 000000000..2a70b9edc --- /dev/null +++ b/src/test/resources/clds/sdc-controller-config-empty-encrypted.json @@ -0,0 +1,14 @@ +{ + "user": "User", + "consumerGroup": "consumerGroup", + "consumerId": "consumerId", + "environmentName": "environmentName", + "sdcAddress": "hostname:8080", + "password": "bb3871669d893c7fb8aaacda31b77b4f537E67A081C2726889548ED7BC4C2DE6", + "pollingInterval":10, + "pollingTimeout":30, + "activateServerTLSAuth": true, + "keyStorePassword":"", + "keyStorePath": "/test", + "messageBusAddresses":["localhost"] +} -- cgit 1.2.3-korg From b63acb4254bfaa58ec50cc78c5ead40ab04034cd Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Wed, 11 Apr 2018 17:35:30 +0200 Subject: Fix the sdc-controller The field Resource UUID war incorrectly set as the blueprint can't be found in the sdc notification, it must retrieved from the csar. Issue-ID: CLAMP-151 Change-Id: I5a80047bcc7f009f67a2dac1891f47bdde0e9bcc Signed-off-by: Determe, Sebastien (sd378r) --- .../controller/installer/BlueprintArtifact.java | 77 ++++++++++++++++++++++ .../clds/sdc/controller/installer/CsarHandler.java | 69 +++++++++---------- .../controller/installer/CsarInstallerImpl.java | 54 ++++++++------- .../resources/clds/sdc-controllers-config.json | 8 +-- .../controller/installer/CsarInstallerItCase.java | 52 +++++++++++---- .../sdc/controller/installer/CsarHandlerTest.java | 28 +++++--- 6 files changed, 203 insertions(+), 85 deletions(-) create mode 100644 src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java (limited to 'src/main/resources/clds/sdc-controllers-config.json') diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java new file mode 100644 index 000000000..5a29264f9 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END============================================ + * =================================================================== + * 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; + +public class BlueprintArtifact { + + private String dcaeBlueprint; + private String blueprintArtifactName; + private String blueprintInvariantResourceUuid; + private String blueprintInvariantServiceUuid; + private String blueprintResourceInstanceName; + + public String getDcaeBlueprint() { + return dcaeBlueprint; + } + + public void setDcaeBlueprint(String dcaeBlueprint) { + this.dcaeBlueprint = dcaeBlueprint; + } + + public String getBlueprintArtifactName() { + return blueprintArtifactName; + } + + public void setBlueprintArtifactName(String blueprintArtifactName) { + this.blueprintArtifactName = blueprintArtifactName; + } + + public String getBlueprintInvariantResourceUuid() { + return blueprintInvariantResourceUuid; + } + + public void setBlueprintInvariantResourceUuid(String blueprintInvariantResourceUuid) { + this.blueprintInvariantResourceUuid = blueprintInvariantResourceUuid; + } + + public String getBlueprintInvariantServiceUuid() { + return blueprintInvariantServiceUuid; + } + + public void setBlueprintInvariantServiceUuid(String blueprintInvariantServiceUuid) { + this.blueprintInvariantServiceUuid = blueprintInvariantServiceUuid; + } + + public String getBlueprintResourceInstanceName() { + return blueprintResourceInstanceName; + } + + public void setBlueprintResourceInstanceName(String blueprintResourceInstanceName) { + this.blueprintResourceInstanceName = blueprintResourceInstanceName; + } +} 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 62169379c..89339733d 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 @@ -33,9 +33,10 @@ import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Enumeration; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -61,13 +62,12 @@ public class CsarHandler { private String controllerName; private SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); private ISdcCsarHelper sdcCsarHelper; - private String dcaeBlueprint; - private String blueprintArtifactName; - private String blueprintInvariantResourceUuid; - private String blueprintInvariantServiceUuid; + private Map mapOfBlueprints = new HashMap<>(); public static final String CSAR_TYPE = "TOSCA_CSAR"; public static final String BLUEPRINT_TYPE = "DCAE_INVENTORY_BLUEPRINT"; private INotificationData sdcNotification; + public static final String RESOURCE_INSTANCE_NAME_PREFIX = "/Artifacts/Resources/"; + public static final String RESOURCE_INSTANCE_NAME_SUFFIX = "/Deployment/"; public CsarHandler(INotificationData iNotif, String controller, String clampCsarPath) throws CsarHandlerException { this.sdcNotification = iNotif; @@ -103,43 +103,48 @@ public class CsarHandler { } sdcCsarHelper = factory.getSdcCsarHelper(csarFilePath); this.loadDcaeBlueprint(); - this.loadBlueprintArtifactDetails(); } catch (IOException e) { throw new SdcArtifactInstallerException( "Exception caught when trying to write the CSAR on the file system to " + csarFilePath, e); } } - private void loadBlueprintArtifactDetails() { - blueprintInvariantServiceUuid = this.getSdcNotification().getServiceInvariantUUID(); - for (IResourceInstance resource : this.getSdcNotification().getResources()) { - if ("VF".equals(resource.getResourceType())) { - for (IArtifactInfo artifact : resource.getArtifacts()) { - if (BLUEPRINT_TYPE.equals(artifact.getArtifactType())) { - blueprintArtifactName = artifact.getArtifactName(); - blueprintInvariantResourceUuid = resource.getResourceInvariantUUID(); - } - } + private IResourceInstance searchForResourceByInstanceName(String blueprintResourceInstanceName) + throws SdcArtifactInstallerException { + for (IResourceInstance resource : this.sdcNotification.getResources()) { + String filteredString = resource.getResourceInstanceName().replaceAll("-", ""); + filteredString = filteredString.replaceAll(" ", ""); + if (filteredString.equals(blueprintResourceInstanceName)) { + return resource; } } + throw new SdcArtifactInstallerException("Error when searching for " + blueprintResourceInstanceName + + " as ResourceInstanceName in Sdc notification and did not find it"); } private void loadDcaeBlueprint() throws IOException, SdcArtifactInstallerException { - List listEntries = new ArrayList<>(); try (ZipFile zipFile = new ZipFile(csarFilePath)) { Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().contains(BLUEPRINT_TYPE)) { - listEntries.add(entry); + BlueprintArtifact blueprintArtifact = new BlueprintArtifact(); + blueprintArtifact.setBlueprintArtifactName( + entry.getName().substring(entry.getName().lastIndexOf('/') + 1, entry.getName().length())); + blueprintArtifact + .setBlueprintInvariantServiceUuid(this.getSdcNotification().getServiceInvariantUUID()); + try (InputStream stream = zipFile.getInputStream(entry)) { + blueprintArtifact.setDcaeBlueprint(IOUtils.toString(stream)); + } + IResourceInstance resource = 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()); + this.mapOfBlueprints.put(blueprintArtifact.getBlueprintResourceInstanceName(), blueprintArtifact); } } - if (listEntries.size() > 1) { - throw new SdcArtifactInstallerException("There are multiple entries in the DCAE inventory"); - } - try (InputStream stream = zipFile.getInputStream(listEntries.get(0))) { - this.dcaeBlueprint = IOUtils.toString(stream); - } } } @@ -155,23 +160,11 @@ public class CsarHandler { return sdcCsarHelper; } - public synchronized String getDcaeBlueprint() { - return dcaeBlueprint; - } - public INotificationData getSdcNotification() { return sdcNotification; } - public String getBlueprintArtifactName() { - return blueprintArtifactName; - } - - public String getBlueprintInvariantResourceUuid() { - return blueprintInvariantResourceUuid; - } - - public String getBlueprintInvariantServiceUuid() { - return blueprintInvariantServiceUuid; + public Map getMapOfBlueprints() { + return mapOfBlueprints; } } 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 cb0da0aa0..d282588bb 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 @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import javax.annotation.PostConstruct; @@ -85,16 +86,23 @@ public class CsarInstallerImpl implements CsarInstaller { @Override public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException { - return (CldsModel.retrieve(cldsDao, csar.getSdcCsarHelper().getServiceMetadata().getValue("name"), true) - .getId() != null) ? true : false; + return (CldsModel.retrieve(cldsDao, buildModelName(csar), true).getId() != null) ? true : false; + } + + public static String buildModelName(CsarHandler csar) { + return csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + " v" + + csar.getSdcNotification().getServiceVersion(); } @Override @Transactional public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException { try { - String serviceTypeId = queryDcaeToGetServiceTypeId(csar); - createFakeCldsModel(csar, createFakeCldsTemplate(csar, this.searchForRightMapping(csar)), serviceTypeId); + for (Entry blueprint : csar.getMapOfBlueprints().entrySet()) { + String serviceTypeId = queryDcaeToGetServiceTypeId(blueprint.getValue()); + createFakeCldsModel(csar, blueprint.getValue(), createFakeCldsTemplate(csar, blueprint.getValue(), + this.searchForRightMapping(blueprint.getValue())), serviceTypeId); + } } catch (IOException e) { throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e); } catch (ParseException | InterruptedException e) { @@ -102,12 +110,12 @@ public class CsarInstallerImpl implements CsarInstaller { } } - private BlueprintParserFilesConfiguration searchForRightMapping(CsarHandler csar) + private BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact) throws SdcArtifactInstallerException { List listConfig = new ArrayList<>(); Yaml yaml = new Yaml(); Map templateNodes = ((Map) ((Map) yaml - .load(csar.getDcaeBlueprint())).get("node_templates")); + .load(blueprintArtifact.getDcaeBlueprint())).get("node_templates")); bpmnMapping.entrySet().forEach(e -> { if (templateNodes.keySet().stream().anyMatch(t -> t.contains(e.getKey()))) { listConfig.add(e.getValue()); @@ -122,12 +130,12 @@ public class CsarInstallerImpl implements CsarInstaller { return listConfig.get(0); } - private String searchForPolicyName(CsarHandler csar) throws SdcArtifactInstallerException { + private String searchForPolicyName(BlueprintArtifact blueprintArtifact) throws SdcArtifactInstallerException { String policyName = null; Yaml yaml = new Yaml(); List policyNameList = new ArrayList<>(); Map templateNodes = ((Map) ((Map) yaml - .load(csar.getDcaeBlueprint())).get("node_templates")); + .load(blueprintArtifact.getDcaeBlueprint())).get("node_templates")); templateNodes.entrySet().stream().filter(e -> e.getKey().contains("policy_")).forEach(ef -> { String filteredPolicyName = (String) ((Map) ((Map) ef.getValue()) .get("properties")).get("policy_filter"); @@ -151,42 +159,44 @@ public class CsarInstallerImpl implements CsarInstaller { return policyNameList.get(0); } - private String queryDcaeToGetServiceTypeId(CsarHandler csar) throws IOException, ParseException, InterruptedException { - return dcaeInventoryService.getDcaeInformation(csar.getBlueprintArtifactName(), - csar.getBlueprintInvariantServiceUuid(), csar.getBlueprintInvariantResourceUuid()).getTypeId(); + private String queryDcaeToGetServiceTypeId(BlueprintArtifact blueprintArtifact) throws IOException, ParseException { + return dcaeInventoryService.getDcaeInformation(blueprintArtifact.getBlueprintArtifactName(), + blueprintArtifact.getBlueprintInvariantServiceUuid(), + blueprintArtifact.getBlueprintInvariantResourceUuid()).getTypeId(); } - private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintParserFilesConfiguration configFiles) - throws IOException { + private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintArtifact blueprintArtifact, + BlueprintParserFilesConfiguration configFiles) throws IOException { CldsTemplate template = new CldsTemplate(); template.setBpmnId("Sdc-Generated"); template.setBpmnText( IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream())); - template.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" + csar.getDcaeBlueprint() + "\"]}]}"); + template.setPropText( + "{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getDcaeBlueprint() + "\"]}]}"); template.setImageText( IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream())); - template.setName(TEMPLATE_NAME_PREFIX + csar.getSdcCsarHelper().getServiceMetadata().getValue("name")); + template.setName(TEMPLATE_NAME_PREFIX + buildModelName(csar)); template.save(cldsDao, null); return template; } - private CldsModel createFakeCldsModel(CsarHandler csar, CldsTemplate cldsTemplate, String serviceTypeId) - throws SdcArtifactInstallerException { + private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintArtifact blueprintArtifact, + CldsTemplate cldsTemplate, String serviceTypeId) throws SdcArtifactInstallerException { CldsModel cldsModel = new CldsModel(); - String policyName = searchForPolicyName(csar); + String policyName = searchForPolicyName(blueprintArtifact); if (policyName.contains("*")) { // It's a filter must add a specific prefix cldsModel.setControlNamePrefix(policyName); } else { cldsModel.setControlNamePrefix(MODEL_NAME_PREFIX); } - cldsModel.setName(csar.getSdcCsarHelper().getServiceMetadata().getValue("name")); - cldsModel.setBlueprintText(csar.getDcaeBlueprint()); + cldsModel.setName(buildModelName(csar)); + cldsModel.setBlueprintText(blueprintArtifact.getDcaeBlueprint()); cldsModel.setTemplateName(cldsTemplate.getName()); cldsModel.setTemplateId(cldsTemplate.getId()); cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" - + csar.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" - + csar.getBlueprintInvariantResourceUuid() + + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" + + blueprintArtifact.getBlueprintInvariantResourceUuid() + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]},{\"name\":\"deployParameters\",\"value\":{\n" + " \"policy_id\": \"" + "test" + "\"" + " }}]}"); cldsModel.setBpmnText(cldsTemplate.getBpmnText()); diff --git a/src/main/resources/clds/sdc-controllers-config.json b/src/main/resources/clds/sdc-controllers-config.json index d18a161a5..fa1533de0 100644 --- a/src/main/resources/clds/sdc-controllers-config.json +++ b/src/main/resources/clds/sdc-controllers-config.json @@ -2,17 +2,17 @@ "sdc-connections":{ "sdc-controller":{ "user": "clamp", - "consumerGroup": "consumerGroup1", - "consumerId": "consumerId1", + "consumerGroup": "consumerGroup2", + "consumerId": "consumerId2", "environmentName": "AUTO", - "sdcAddress": "sdc.api.simpledemo.onap.org:8443", + "sdcAddress": "10.12.6.0:8443", "password": "b7acccda32b98c5bb7acccda32b98c5b05D511BD6D93626E90D18E9D24D9B78CD34C7EE8012F0A189A28763E82271E50A5D4EC10C7D93E06E0A2D27CAE66B981", "pollingInterval":30, "pollingTimeout":30, "activateServerTLSAuth":"false", "keyStorePassword":"", "keyStorePath":"", - "messageBusAddresses":["ueb.api.simpledemo.onap.org"] + "messageBusAddresses":["10.12.5.235"] } } } 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 c0300eff6..b741f7c75 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 @@ -33,6 +33,10 @@ import com.att.aft.dme2.internal.apache.commons.io.IOUtils; import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,10 +46,13 @@ import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; import org.onap.clamp.clds.model.CldsModel; import org.onap.clamp.clds.model.CldsTemplate; +import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact; import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl; import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.toscaparser.api.elements.Metadata; @@ -69,24 +76,45 @@ public class CsarInstallerItCase { public void testInstallTheCsarFail() throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { CsarHandler csarHandler = Mockito.mock(CsarHandler.class); - Mockito.when(csarHandler.getDcaeBlueprint()).thenReturn(IOUtils + BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); + Map blueprintMap = new HashMap<>(); + 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"))); csarInstaller.installTheCsar(csarHandler); fail("Should have raised an SdcArtifactInstallerException"); } private CsarHandler buildFakeCsarHandler(String generatedName) throws IOException { - CsarHandler csarHandler = Mockito.mock(CsarHandler.class); - Mockito.when(csarHandler.getDcaeBlueprint()) + // Create fake notification + INotificationData notificationData = Mockito.mock(INotificationData.class); + Mockito.when(notificationData.getServiceVersion()).thenReturn("1.0"); + // Create fake resource in notification + List 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(notificationData.getResources()).thenReturn(listResources); + // Create fake blueprint artifact + BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); + Mockito.when(blueprintArtifact.getDcaeBlueprint()) .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); + Map blueprintMap = new HashMap<>(); + blueprintMap.put("resourceid", blueprintArtifact); + // Build fake csarhandler + CsarHandler csarHandler = Mockito.mock(CsarHandler.class); + Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); + Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); + // Build fake csar Helper ISdcCsarHelper csarHelper = Mockito.mock(ISdcCsarHelper.class); Metadata data = Mockito.mock(Metadata.class); Mockito.when(data.getValue("name")).thenReturn(generatedName); Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data); Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper); - Mockito.when(csarHandler.getBlueprintArtifactName()).thenReturn(CSAR_ARTIFACT_NAME); - Mockito.when(csarHandler.getBlueprintInvariantServiceUuid()).thenReturn(INVARIANT_SERVICE_UUID); - Mockito.when(csarHandler.getBlueprintInvariantResourceUuid()).thenReturn(INVARIANT_RESOURCE1_UUID); return csarHandler; } @@ -104,24 +132,26 @@ public class CsarInstallerItCase { public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException { String generatedName = RandomStringUtils.randomAlphanumeric(5); - csarInstaller.installTheCsar(buildFakeCsarHandler(generatedName)); + CsarHandler csar = buildFakeCsarHandler(generatedName); + csarInstaller.installTheCsar(csar); // Get the template back from DB CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, - CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName, false); + CsarInstallerImpl.TEMPLATE_NAME_PREFIX + CsarInstallerImpl.buildModelName(csar), 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 + generatedName); + assertEquals(templateFromDb.getName(), + CsarInstallerImpl.TEMPLATE_NAME_PREFIX + CsarInstallerImpl.buildModelName(csar)); // Get the Model back from DB - CldsModel modelFromDb = CldsModel.retrieve(cldsDao, generatedName, true); + CldsModel modelFromDb = CldsModel.retrieve(cldsDao, CsarInstallerImpl.buildModelName(csar), true); assertNotNull(modelFromDb); assertNotNull(modelFromDb.getBpmnText()); assertNotNull(modelFromDb.getImageText()); assertNotNull(modelFromDb.getPropText()); - assertEquals(modelFromDb.getName(), generatedName); + assertEquals(CsarInstallerImpl.buildModelName(csar), modelFromDb.getName()); assertEquals(CsarInstallerImpl.MODEL_NAME_PREFIX, modelFromDb.getControlNamePrefix()); } } 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 3a37f9457..b02e8bab4 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 @@ -55,7 +55,9 @@ public class CsarHandlerTest { private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar"; private static final String SERVICE_UUID = "serviceUUID"; private static final String RESOURCE1_UUID = "resource1UUID"; - private static final String BLUEPRINT1_NAME = "blueprint1-name"; + 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"; @Test public void testConstructor() throws CsarHandlerException { @@ -93,10 +95,10 @@ public class CsarHandlerTest { IResourceInstance resource1 = Mockito.mock(IResourceInstance.class); Mockito.when(resource1.getResourceType()).thenReturn("VF"); Mockito.when(resource1.getResourceInvariantUUID()).thenReturn(RESOURCE1_UUID); + Mockito.when(resource1.getResourceInstanceName()).thenReturn(RESOURCE1_INSTANCE_NAME); // Create a fake artifact for resource IArtifactInfo blueprintArtifact = Mockito.mock(IArtifactInfo.class); Mockito.when(blueprintArtifact.getArtifactType()).thenReturn(CsarHandler.BLUEPRINT_TYPE); - Mockito.when(blueprintArtifact.getArtifactName()).thenReturn(BLUEPRINT1_NAME); List artifactsListForResource = new ArrayList<>(); artifactsListForResource.add(blueprintArtifact); Mockito.when(resource1.getArtifacts()).thenReturn(artifactsListForResource); @@ -123,14 +125,17 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_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.getBlueprintArtifactName()); - assertEquals(RESOURCE1_UUID, csar.getBlueprintInvariantResourceUuid()); - assertEquals(SERVICE_UUID, csar.getBlueprintInvariantServiceUuid()); + assertEquals(BLUEPRINT1_NAME, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); + assertEquals(RESOURCE1_UUID, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantResourceUuid()); + assertEquals(SERVICE_UUID, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); // Do some cleanup Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); Files.deleteIfExists(path); @@ -146,14 +151,17 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_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.getBlueprintArtifactName()); - assertEquals(RESOURCE1_UUID, csar.getBlueprintInvariantResourceUuid()); - assertEquals(SERVICE_UUID, csar.getBlueprintInvariantServiceUuid()); + assertEquals(BLUEPRINT1_NAME, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); + assertEquals(RESOURCE1_UUID, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantResourceUuid()); + assertEquals(SERVICE_UUID, + csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); // A double save should simply overwrite the existing csar.save(buildFakeSdcResut()); -- cgit 1.2.3-korg From 14fd9e6cc1ae80f422bdea8f53f65bdc56c9d9a9 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Thu, 12 Apr 2018 11:44:31 +0200 Subject: Add default config Add the default configuration for sdc-controller so that it can work with oom or docker instances Issue-ID: CLAMP-151 Change-Id: Ia69c740efceddfaec6d7e0d5e31cc3d7eecb4545 Signed-off-by: Determe, Sebastien (sd378r) --- src/main/resources/clds/sdc-controllers-config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/resources/clds/sdc-controllers-config.json') diff --git a/src/main/resources/clds/sdc-controllers-config.json b/src/main/resources/clds/sdc-controllers-config.json index fa1533de0..2b99a2cc6 100644 --- a/src/main/resources/clds/sdc-controllers-config.json +++ b/src/main/resources/clds/sdc-controllers-config.json @@ -5,14 +5,14 @@ "consumerGroup": "consumerGroup2", "consumerId": "consumerId2", "environmentName": "AUTO", - "sdcAddress": "10.12.6.0:8443", + "sdcAddress": "sdc.api.simpledemo.onap.org:8443", "password": "b7acccda32b98c5bb7acccda32b98c5b05D511BD6D93626E90D18E9D24D9B78CD34C7EE8012F0A189A28763E82271E50A5D4EC10C7D93E06E0A2D27CAE66B981", "pollingInterval":30, "pollingTimeout":30, "activateServerTLSAuth":"false", "keyStorePassword":"", "keyStorePath":"", - "messageBusAddresses":["10.12.5.235"] + "messageBusAddresses":["ueb.api.simpledemo.onap.org"] } } } -- cgit 1.2.3-korg From 56bd2eda36902b273a44407b16a54287b4dd45ce Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Wed, 25 Apr 2018 14:42:39 +0200 Subject: Sdc controller config Change the sdc-controller config so that clamp is defined as sdc consumer group and id Issue-ID: CLAMP-151 Change-Id: Ie97a891e3c01d94f3099a5f75097e54ac37ecbe5 Signed-off-by: Determe, Sebastien (sd378r) --- src/main/resources/clds/sdc-controllers-config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/resources/clds/sdc-controllers-config.json') diff --git a/src/main/resources/clds/sdc-controllers-config.json b/src/main/resources/clds/sdc-controllers-config.json index 2b99a2cc6..b86732ec7 100644 --- a/src/main/resources/clds/sdc-controllers-config.json +++ b/src/main/resources/clds/sdc-controllers-config.json @@ -2,8 +2,8 @@ "sdc-connections":{ "sdc-controller":{ "user": "clamp", - "consumerGroup": "consumerGroup2", - "consumerId": "consumerId2", + "consumerGroup": "clamp", + "consumerId": "clamp", "environmentName": "AUTO", "sdcAddress": "sdc.api.simpledemo.onap.org:8443", "password": "b7acccda32b98c5bb7acccda32b98c5b05D511BD6D93626E90D18E9D24D9B78CD34C7EE8012F0A189A28763E82271E50A5D4EC10C7D93E06E0A2D27CAE66B981", -- cgit 1.2.3-korg