From 0c8c6ff37abb1080fec59ee2558689c312a953a1 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Thu, 12 Apr 2018 14:54:26 +0200 Subject: Refactor code Sdc-controller Rework the Sdc-controller and mainly blueprintArtifact so that the resource attached is fully available in this class Issue-ID: CLAMP-151 Change-Id: I77210cfa90a04df505566ff7e5f093c768cbbda9 Signed-off-by: Determe, Sebastien (sd378r) --- .../controller/installer/BlueprintArtifact.java | 23 ++++++++-------------- .../clds/sdc/controller/installer/CsarHandler.java | 12 +++++------ .../controller/installer/CsarInstallerImpl.java | 4 ++-- 3 files changed, 16 insertions(+), 23 deletions(-) (limited to 'src/main') 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 index 5a29264f..71d5ae36 100644 --- 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 @@ -20,20 +20,21 @@ * =================================================================== * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ - /** * This class is useful to store the information concerning * blueprint artifact extracted from SDC CSAR */ + package org.onap.clamp.clds.sdc.controller.installer; +import org.onap.sdc.api.notification.IResourceInstance; + public class BlueprintArtifact { private String dcaeBlueprint; private String blueprintArtifactName; - private String blueprintInvariantResourceUuid; private String blueprintInvariantServiceUuid; - private String blueprintResourceInstanceName; + private IResourceInstance resourceAttached; public String getDcaeBlueprint() { return dcaeBlueprint; @@ -51,14 +52,6 @@ public class BlueprintArtifact { this.blueprintArtifactName = blueprintArtifactName; } - public String getBlueprintInvariantResourceUuid() { - return blueprintInvariantResourceUuid; - } - - public void setBlueprintInvariantResourceUuid(String blueprintInvariantResourceUuid) { - this.blueprintInvariantResourceUuid = blueprintInvariantResourceUuid; - } - public String getBlueprintInvariantServiceUuid() { return blueprintInvariantServiceUuid; } @@ -67,11 +60,11 @@ public class BlueprintArtifact { this.blueprintInvariantServiceUuid = blueprintInvariantServiceUuid; } - public String getBlueprintResourceInstanceName() { - return blueprintResourceInstanceName; + public IResourceInstance getResourceAttached() { + return resourceAttached; } - public void setBlueprintResourceInstanceName(String blueprintResourceInstanceName) { - this.blueprintResourceInstanceName = blueprintResourceInstanceName; + public void setResourceAttached(IResourceInstance resourceAttached) { + this.resourceAttached = resourceAttached; } } 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 aacef0a4..c2652bc6 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 @@ -135,15 +135,15 @@ public class CsarHandler { try (InputStream stream = zipFile.getInputStream(entry)) { blueprintArtifact.setDcaeBlueprint(IOUtils.toString(stream)); } - IResourceInstance resource = searchForResourceByInstanceName(entry.getName().substring( + blueprintArtifact.setResourceAttached(searchForResourceByInstanceName(entry.getName().substring( entry.getName().indexOf(RESOURCE_INSTANCE_NAME_PREFIX) + RESOURCE_INSTANCE_NAME_PREFIX.length(), - entry.getName().indexOf(RESOURCE_INSTANCE_NAME_SUFFIX))); - blueprintArtifact.setBlueprintInvariantResourceUuid(resource.getResourceInvariantUUID()); - blueprintArtifact.setBlueprintResourceInstanceName(resource.getResourceInstanceName()); + entry.getName().indexOf(RESOURCE_INSTANCE_NAME_SUFFIX)))); + this.mapOfBlueprints.put(blueprintArtifact.getResourceAttached().getResourceInstanceName(), + blueprintArtifact); logger.info("Found a blueprint entry in the CSAR " + blueprintArtifact.getBlueprintArtifactName() - + " for resource instance Name " + resource.getResourceInstanceName()); - this.mapOfBlueprints.put(blueprintArtifact.getBlueprintResourceInstanceName(), blueprintArtifact); + + " for resource instance Name " + + blueprintArtifact.getResourceAttached().getResourceInstanceName()); } } logger.info(this.mapOfBlueprints.size() + " blueprint(s) will be converted to closed loop"); 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 ded75dd5..5a00a828 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 @@ -173,7 +173,7 @@ public class CsarInstallerImpl implements CsarInstaller { throws IOException, ParseException, InterruptedException { return dcaeInventoryService.getDcaeInformation(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact.getBlueprintInvariantServiceUuid(), - blueprintArtifact.getBlueprintInvariantResourceUuid()).getTypeId(); + blueprintArtifact.getResourceAttached().getResourceInvariantUUID()).getTypeId(); } private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintArtifact blueprintArtifact, @@ -209,7 +209,7 @@ public class CsarInstallerImpl implements CsarInstaller { cldsModel.setTemplateId(cldsTemplate.getId()); cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" - + blueprintArtifact.getBlueprintInvariantResourceUuid() + + blueprintArtifact.getResourceAttached().getResourceInvariantUUID() + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]},{\"name\":\"deployParameters\",\"value\":{\n" + " \"policy_id\": \"" + "test" + "\"" + " }}]}"); cldsModel.setBpmnText(cldsTemplate.getBpmnText()); -- cgit 1.2.3-korg From c322f5b44ef208ebf8d72bf8e710b2d7881cac2f Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Thu, 12 Apr 2018 15:28:59 +0200 Subject: Fix sonar Fix sonar bugs reported in the new code Issue-ID: CLAMP-147 Change-Id: I77d686ddfd561f260aeb52f82085b73e3e1f1249 Signed-off-by: Determe, Sebastien (sd378r) --- .../org/onap/clamp/clds/sdc/controller/SdcSingleController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/main') 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 a6296044..21deb649 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 @@ -200,10 +200,10 @@ public class SdcSingleController { public void treatNotification(INotificationData iNotif) { CsarHandler csar = null; try { - // wait for a random time, so that 2 running Clamp will not treat the same Notification at the same time - int i = ThreadLocalRandom.current().nextInt(1, 5); - Thread.sleep(i * 1000); - + // wait for a random time, so that 2 running Clamp will not treat + // the same Notification at the same time + long i = ThreadLocalRandom.current().nextInt(1, 5); + Thread.sleep(i * 1000L); logger.info("Notification received for service UUID:" + iNotif.getServiceUUID()); this.changeControllerStatus(SdcSingleControllerStatus.BUSY); csar = new CsarHandler(iNotif, this.sdcConfig.getSdcControllerName(), @@ -247,6 +247,7 @@ public class SdcSingleController { e.getMessage(), System.currentTimeMillis()); } catch (InterruptedException e) { logger.error("Interrupt exception caught during the notification processing", e); + Thread.currentThread().interrupt(); } catch (RuntimeException e) { logger.error("Unexpected exception caught during the notification processing", e); } finally { -- cgit 1.2.3-korg