aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/Application.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java37
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java16
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java77
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java75
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java70
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsUser.java7
-rw-r--r--src/main/resources/application.properties2
-rw-r--r--src/main/resources/clds/sdc-controllers-config.json4
-rw-r--r--src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java52
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java28
11 files changed, 272 insertions, 98 deletions
diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java
index ae8b6d82b..f4fe70652 100644
--- a/src/main/java/org/onap/clamp/clds/Application.java
+++ b/src/main/java/org/onap/clamp/clds/Application.java
@@ -85,7 +85,7 @@ public class Application extends SpringBootServletInitializer {
// This is to initialize some Onap Clamp components
initializeComponents();
// Start the Spring application
- SpringApplication.run(Application.class, args); // NOSONAR
+ SpringApplication.run(Application.class, args);
}
private static void initializeComponents() {
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
index ffc9b8e28..f1cfd18f3 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
@@ -61,6 +61,8 @@ public class DcaeInventoryServices {
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
public static final String DCAE_INVENTORY_URL = "dcae.inventory.url";
+ public static final String DCAE_INVENTORY_RETRY_INTERVAL = "dcae.intentory.retry.interval";
+ public static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit";
public static final String DCAE_TYPE_NAME = "typeName";
public static final String DCAE_TYPE_ID = "typeId";
@Autowired
@@ -78,7 +80,7 @@ public class DcaeInventoryServices {
* @throws ParseException
* In case of DCAE Json parse exception
*/
- public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException {
+ public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException, InterruptedException {
String artifactName = cldsModel.getControlName();
DcaeEvent dcaeEvent = new DcaeEvent();
DcaeInventoryResponse dcaeResponse = null;
@@ -159,7 +161,7 @@ public class DcaeInventoryServices {
* In case of issues with the Json parsing
*/
public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)
- throws IOException, ParseException {
+ throws IOException, ParseException, InterruptedException {
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");
String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName="
@@ -167,7 +169,8 @@ public class DcaeInventoryServices {
String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types" + queryString;
logger.info("Dcae Inventory Service full url - " + fullUrl);
String dcaeInventoryResponse = null;
- String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);
+
+ String responseStr = queryDCAEInventory (fullUrl);
JSONParser parser = new JSONParser();
Object obj0 = parser.parse(responseStr);
JSONObject jsonObj = (JSONObject) obj0;
@@ -185,6 +188,34 @@ public class DcaeInventoryServices {
return JacksonUtils.getObjectMapperInstance().readValue(dcaeInventoryResponse, DcaeInventoryResponse.class);
}
+ private String queryDCAEInventory (String fullUrl) throws IOException, InterruptedException {
+ int retryInterval = 0;
+ int retryLimit = 1;
+ if (refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT) != null) {
+ retryLimit = Integer.valueOf(refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT));
+ }
+ if (refProp.getStringValue(DCAE_INVENTORY_RETRY_INTERVAL) != null) {
+ retryInterval = Integer.valueOf(refProp.getStringValue(DCAE_INVENTORY_RETRY_INTERVAL));
+ }
+
+ int i = 0;
+ while (i < retryLimit) {
+ i++;
+ try {
+ return DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);
+ } catch (BadRequestException e) {
+ if (i == retryLimit) {
+ // reach the retry limit, but still failed to connect to DCAE
+ throw e;
+ } else {
+ // wait for a while and try to connect to DCAE again
+ Thread.sleep(retryInterval);
+ }
+ }
+ }
+ // normally it should not go to this branch. It should either return the DCAE query result, or throw exception
+ return null;
+ }
/**
* Inserts a new DCAEServiceType or updates an existing instance. If the
* typeName is same second time(already exists) then the
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 627bc72ad..a62960440 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
@@ -27,6 +27,7 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.util.Date;
+import java.util.concurrent.ThreadLocalRandom;
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
@@ -83,8 +84,7 @@ public class SdcSingleController {
@Override
public void activateCallback(INotificationData iNotif) {
Date startTime = new Date();
- String event = "Receive a callback notification in SDC, nb of resources: " + iNotif.getResources().size();
- logger.debug(event);
+ logger.info("Receive a callback notification in SDC, nb of resources: " + iNotif.getResources().size());
sdcController.treatNotification(iNotif);
LoggingUtils.setTimeContext(startTime, new Date());
LoggingUtils.setResponseContext("0", "SDC Notification received and processed successfully",
@@ -143,7 +143,7 @@ public class SdcSingleController {
* If there is an issue with the parameters provided
*/
public void initSdc() throws SdcControllerException {
- logger.debug("Attempt to initialize the SDC Controller");
+ logger.info("Attempt to initialize the SDC Controller");
if (this.getControllerStatus() != SdcSingleControllerStatus.STOPPED) {
throw new SdcControllerException("The controller is already initialized, call the closeSDC method first");
}
@@ -159,7 +159,7 @@ public class SdcSingleController {
}
result = this.distributionClient.start();
if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
- logger.debug("SDC distribution client start failed with reason:" + result.getDistributionMessageResult());
+ logger.error("SDC distribution client start failed with reason:" + result.getDistributionMessageResult());
this.changeControllerStatus(SdcSingleControllerStatus.STOPPED);
throw new SdcControllerException(
"Startup of the SDC Controller failed with reason: " + result.getDistributionMessageResult());
@@ -200,6 +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);
+
logger.info("Notification received for service UUID:" + iNotif.getServiceUUID());
this.changeControllerStatus(SdcSingleControllerStatus.BUSY);
csar = new CsarHandler(iNotif, this.sdcConfig.getSdcControllerName(),
@@ -241,6 +245,8 @@ public class SdcSingleController {
this.sendSdcNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),
sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,
e.getMessage(), System.currentTimeMillis());
+ } catch (InterruptedException e) {
+ logger.error("Interrupt exception caught during the notification processing", e);
} catch (RuntimeException e) {
logger.error("Unexpected exception caught during the notification processing", e);
} finally {
@@ -253,7 +259,7 @@ public class SdcSingleController {
}
private IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact) throws SdcDownloadException {
- logger.debug("Trying to download the artifact : " + artifact.getArtifactURL() + " UUID: "
+ logger.info("Trying to download the artifact : " + artifact.getArtifactURL() + " UUID: "
+ artifact.getArtifactUUID());
IDistributionClientDownloadResult downloadResult;
try {
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..aacef0a4f 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<String, BlueprintArtifact> 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;
@@ -93,8 +93,7 @@ public class CsarHandler {
public synchronized void save(IDistributionClientDownloadResult resultArtifact)
throws SdcArtifactInstallerException, SdcToscaParserException {
try {
- logger.info("Writing CSAR file : " + artifactElement.getArtifactURL() + " UUID "
- + artifactElement.getArtifactUUID() + ")");
+ logger.info("Writing CSAR file to: " + csarFilePath + " UUID " + artifactElement.getArtifactUUID() + ")");
Path path = Paths.get(csarFilePath);
Files.createDirectories(path.getParent());
// Create or replace the file
@@ -103,43 +102,51 @@ 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<ZipEntry> listEntries = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(csarFilePath)) {
Enumeration<? extends ZipEntry> 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());
+ logger.info("Found a blueprint entry in the CSAR " + blueprintArtifact.getBlueprintArtifactName()
+ + " for resource instance Name " + 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);
- }
+ logger.info(this.mapOfBlueprints.size() + " blueprint(s) will be converted to closed loop");
}
}
@@ -155,23 +162,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<String, BlueprintArtifact> 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 91c0b6a64..6a9828df0 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
@@ -24,12 +24,15 @@
package org.onap.clamp.clds.sdc.controller.installer;
import com.att.aft.dme2.internal.apache.commons.io.IOUtils;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
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;
@@ -56,6 +59,7 @@ import org.yaml.snakeyaml.Yaml;
*/
public class CsarInstallerImpl implements CsarInstaller {
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class);
private Map<String, BlueprintParserFilesConfiguration> bpmnMapping = new HashMap<>();
public static final String TEMPLATE_NAME_PREFIX = "DCAE-Designer-ClosedLoopTemplate-";
public static final String MODEL_NAME_PREFIX = "ClosedLoop-";
@@ -85,29 +89,39 @@ 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);
+ logger.info("Installing the CSAR " + csar.getFilePath());
+ for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) {
+ logger.info("Processing blueprint " + blueprint.getValue().getBlueprintArtifactName());
+ String serviceTypeId = queryDcaeToGetServiceTypeId(blueprint.getValue());
+ createFakeCldsModel(csar, blueprint.getValue(), createFakeCldsTemplate(csar, blueprint.getValue(),
+ this.searchForRightMapping(blueprint.getValue())), serviceTypeId);
+ }
+ logger.info("Successfully installed the CSAR " + csar.getFilePath());
} catch (IOException e) {
throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e);
- } catch (ParseException e) {
+ } catch (ParseException | InterruptedException e) {
throw new SdcArtifactInstallerException("Exception caught during the Dcae query to get ServiceTypeId", e);
}
}
- private BlueprintParserFilesConfiguration searchForRightMapping(CsarHandler csar)
+ private BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact)
throws SdcArtifactInstallerException {
List<BlueprintParserFilesConfiguration> listConfig = new ArrayList<>();
Yaml yaml = new Yaml();
Map<String, Object> templateNodes = ((Map<String, Object>) ((Map<String, Object>) 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());
@@ -119,15 +133,17 @@ public class CsarInstallerImpl implements CsarInstaller {
} else if (listConfig.isEmpty()) {
throw new SdcArtifactInstallerException("There is no recognized MicroService found in the blueprint");
}
+ logger.info("Mapping found for blueprint " + blueprintArtifact.getBlueprintArtifactName() + " is "
+ + listConfig.get(0).getBpmnXmlFilePath());
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<String> policyNameList = new ArrayList<>();
Map<String, Object> templateNodes = ((Map<String, Object>) ((Map<String, Object>) 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<String, Object>) ((Map<String, Object>) ef.getValue())
.get("properties")).get("policy_filter");
@@ -148,50 +164,58 @@ public class CsarInstallerImpl implements CsarInstaller {
throw new SdcArtifactInstallerException(
"There is no recognized Policy MicroService found in the blueprint");
}
+ logger.info("policyName found in blueprint " + blueprintArtifact.getBlueprintArtifactName() + " is "
+ + policyNameList.get(0));
return policyNameList.get(0);
}
- private String queryDcaeToGetServiceTypeId(CsarHandler csar) throws IOException, ParseException {
- 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);
+ logger.info("Fake Clds Template created for blueprint " + blueprintArtifact.getBlueprintArtifactName()
+ + " with name " + template.getName());
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());
cldsModel.setTypeId(serviceTypeId);
cldsModel.save(cldsDao, null);
+ logger.info("Fake Clds Model created for blueprint " + blueprintArtifact.getBlueprintArtifactName()
+ + " with name " + cldsModel.getName());
return cldsModel;
}
}
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsUser.java b/src/main/java/org/onap/clamp/clds/service/CldsUser.java
index fa7a738dd..36db301cd 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsUser.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsUser.java
@@ -29,8 +29,9 @@ import java.util.Arrays;
* The class represents the CldsUser that can be extracted from cldsusers.json.
*/
public class CldsUser {
- private String user;
- private String password;
+
+ private String user;
+ private String password;
private SecureServicePermission[] permissions;
/**
@@ -81,7 +82,7 @@ public class CldsUser {
}
public String[] getPermissionsString() {
- return Arrays.stream(getPermissions()).map(SecureServicePermission::getKey).toArray(String[]::new);// NOSONAR
+ return Arrays.stream(getPermissions()).map(SecureServicePermission::getKey).toArray(String[]::new);
}
/**
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 1411b8b2b..0d58350e7 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -206,6 +206,8 @@ clamp.config.clds.service.cache.invalidate.after.seconds=120
#DCAE Inventory Url Properties
clamp.config.dcae.inventory.url=http://dcae.api.simpledemo.onap.org:8080
+clamp.config.dcae.intentory.retry.interval=10000
+clamp.config.dcae.intentory.retry.limit=3
#DCAE Dispatcher Url Properties
clamp.config.dcae.dispatcher.url=http://dcae.api.simpledemo.onap.org:8080
diff --git a/src/main/resources/clds/sdc-controllers-config.json b/src/main/resources/clds/sdc-controllers-config.json
index d18a161a5..2b99a2cc6 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": "consumerGroup1",
- "consumerId": "consumerId1",
+ "consumerGroup": "consumerGroup2",
+ "consumerId": "consumerId2",
"environmentName": "AUTO",
"sdcAddress": "sdc.api.simpledemo.onap.org:8443",
"password": "b7acccda32b98c5bb7acccda32b98c5b05D511BD6D93626E90D18E9D24D9B78CD34C7EE8012F0A189A28763E82271E50A5D4EC10C7D93E06E0A2D27CAE66B981",
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<String, BlueprintArtifact> 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<IResourceInstance> listResources = new ArrayList<>();
+ IResourceInstance resource = Mockito.mock(IResourceInstance.class);
+ Mockito.when(resource.getResourceInstanceName()).thenReturn("mm-e 0");
+ Mockito.when(resource.getResourceInvariantUUID()).thenReturn("mme0-invariantUuid");
+ Mockito.when(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<String, BlueprintArtifact> 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<IArtifactInfo> 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());