summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-05-28 17:26:39 +0200
committersebdet <sebastien.determe@intl.att.com>2020-05-28 17:36:09 +0200
commitbadc1b5e02d60e15d08e231883cf74d2a28d92e1 (patch)
tree8f3b37ecf59df9a97bfedfa4d89121ed83660ff2 /src
parent9e25792898ae648234239403374db8bb923bc180 (diff)
Fix crash at SDC deploy
If CDS properties are not there, it can crash a standard VF resource blueprint deployment. Issue-ID: CLAMP-857 Signed-off-by: sebdet <sebastien.determe@intl.att.com> Change-Id: I4172427046250fed52984c2b94531370727f0fa0
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/loop/cds/CdsDataInstaller.java16
-rw-r--r--src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java26
-rw-r--r--src/test/resources/example/sdc/service_Vloadbalancerms_cds.csar (renamed from src/test/resources/example/sdc/service_Vloadbalancerms_csar.csar)bin115771 -> 115771 bytes
-rw-r--r--src/test/resources/example/sdc/service_Vloadbalancerms_no_cds.csarbin0 -> 115690 bytes
4 files changed, 31 insertions, 11 deletions
diff --git a/src/main/java/org/onap/clamp/loop/cds/CdsDataInstaller.java b/src/main/java/org/onap/clamp/loop/cds/CdsDataInstaller.java
index 9c1cd3bc2..d18cae1d6 100644
--- a/src/main/java/org/onap/clamp/loop/cds/CdsDataInstaller.java
+++ b/src/main/java/org/onap/clamp/loop/cds/CdsDataInstaller.java
@@ -73,18 +73,23 @@ public class CdsDataInstaller {
for (NodeTemplate nodeTemplate : csar.getSdcCsarHelper().getServiceNodeTemplateBySdcType(type)) {
// get cds artifact information and save in resources Prop
if (SdcTypes.PNF == type || SdcTypes.VF == type) {
- JsonObject controllerProperties = createCdsArtifactProperties(nodeTemplate.getPropertyValue(
- SDNC_MODEL_NAME).toString(),
- nodeTemplate.getPropertyValue(SDNC_MODEL_VERSION).toString());
+ JsonObject controllerProperties = createCdsArtifactProperties(
+ String.valueOf(nodeTemplate.getPropertyValue(SDNC_MODEL_NAME)),
+ String.valueOf(nodeTemplate.getPropertyValue(SDNC_MODEL_VERSION)));
if (controllerProperties != null) {
resourcesPropByType.getAsJsonObject(nodeTemplate.getName())
.add(CONTROLLER_PROPERTIES, controllerProperties);
+ logger.info("Successfully installed the CDS data in Service");
+ }
+ else {
+ logger.warn("Skipping CDS data installation in Service, as sdnc_model_name and "
+ + "sdnc_model_version are not provided in the CSAR");
}
}
}
}
serviceRepository.save(service);
- logger.info("Successfully installed the CDS data in Service");
+
return service;
}
@@ -129,7 +134,8 @@ public class CdsDataInstaller {
* @return Returns CDS artifacts information
*/
private JsonObject createCdsArtifactProperties(String sdncModelName, String sdncModelVersion) {
- if (sdncModelName != null && sdncModelVersion != null) {
+ if (sdncModelName != null && !"null".equals(sdncModelName)
+ && sdncModelVersion != null && !"null".equals(sdncModelVersion)) {
JsonObject controllerProperties = new JsonObject();
controllerProperties.addProperty(SDNC_MODEL_NAME, sdncModelName);
controllerProperties.addProperty(SDNC_MODEL_VERSION, sdncModelVersion);
diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
index 7e1488604..ffb9244d6 100644
--- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
@@ -77,7 +77,8 @@ import org.springframework.test.context.junit4.SpringRunner;
@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller,legacy-operational-policy")
public class CsarInstallerItCase {
- private static final String CSAR_ARTIFACT_NAME = "example/sdc/service_Vloadbalancerms_csar.csar";
+ private static final String CSAR_ARTIFACT_NAME_CDS = "example/sdc/service_Vloadbalancerms_cds.csar";
+ private static final String CSAR_ARTIFACT_NAME_NO_CDS = "example/sdc/service_Vloadbalancerms_no_cds.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";
@@ -112,7 +113,8 @@ public class CsarInstallerItCase {
return blueprintArtifact;
}
- private CsarHandler buildFakeCsarHandler(String generatedName) throws IOException, SdcToscaParserException {
+ private CsarHandler buildFakeCsarHandler(String generatedName, String csarFileName) throws IOException,
+ SdcToscaParserException {
// Create fake notification
INotificationData notificationData = Mockito.mock(INotificationData.class);
Mockito.when(notificationData.getServiceVersion()).thenReturn("1.0");
@@ -151,7 +153,7 @@ public class CsarInstallerItCase {
// Create helper based on real csar to test policy yaml and global properties
// set
SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
- String path = Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile();
+ String path = Thread.currentThread().getContextClassLoader().getResource(csarFileName).getFile();
ISdcCsarHelper sdcHelper = factory.getSdcCsarHelper(path);
Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(sdcHelper);
@@ -180,7 +182,7 @@ public class CsarInstallerItCase {
CsarHandler csarHandler = new CsarHandler(notificationData, "", "");
csarHandler
- .setFilePath(Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile());
+ .setFilePath(Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME_CDS).getFile());
Assert.assertEquals(csarHandler.getPolicyModelYaml(), Optional
.ofNullable(ResourceFileUtil.getResourceAsString("example/sdc/expected-result/policy-data.yaml")));
}
@@ -190,7 +192,19 @@ public class CsarInstallerItCase {
public void testIsCsarAlreadyDeployedTca() throws SdcArtifactInstallerException, SdcToscaParserException,
CsarHandlerException, IOException, InterruptedException, BlueprintParserException {
String generatedName = RandomStringUtils.randomAlphanumeric(5);
- CsarHandler csarHandler = buildFakeCsarHandler(generatedName);
+ CsarHandler csarHandler = buildFakeCsarHandler(generatedName, CSAR_ARTIFACT_NAME_CDS);
+ assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isFalse();
+ csarInstaller.installTheCsar(csarHandler);
+ assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isTrue();
+ }
+
+ @Test
+ @Transactional
+ public void testWithoutCdsTca() throws SdcArtifactInstallerException, SdcToscaParserException,
+ CsarHandlerException, IOException, InterruptedException, BlueprintParserException {
+ String generatedName = RandomStringUtils.randomAlphanumeric(5);
+ CsarHandler csarHandler = buildFakeCsarHandler(generatedName, CSAR_ARTIFACT_NAME_NO_CDS);
+
assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isFalse();
csarInstaller.installTheCsar(csarHandler);
assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isTrue();
@@ -202,7 +216,7 @@ public class CsarInstallerItCase {
public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException,
CsarHandlerException, IOException, JSONException, InterruptedException, BlueprintParserException {
String generatedName = RandomStringUtils.randomAlphanumeric(5);
- CsarHandler csar = buildFakeCsarHandler(generatedName);
+ CsarHandler csar = buildFakeCsarHandler(generatedName, CSAR_ARTIFACT_NAME_CDS);
csarInstaller.installTheCsar(csar);
assertThat(serviceRepository.existsById("63cac700-ab9a-4115-a74f-7eac85e3fce0")).isTrue();
// We should have CDS info
diff --git a/src/test/resources/example/sdc/service_Vloadbalancerms_csar.csar b/src/test/resources/example/sdc/service_Vloadbalancerms_cds.csar
index ff337993a..ff337993a 100644
--- a/src/test/resources/example/sdc/service_Vloadbalancerms_csar.csar
+++ b/src/test/resources/example/sdc/service_Vloadbalancerms_cds.csar
Binary files differ
diff --git a/src/test/resources/example/sdc/service_Vloadbalancerms_no_cds.csar b/src/test/resources/example/sdc/service_Vloadbalancerms_no_cds.csar
new file mode 100644
index 000000000..3330dd1e8
--- /dev/null
+++ b/src/test/resources/example/sdc/service_Vloadbalancerms_no_cds.csar
Binary files differ