summaryrefslogtreecommitdiffstats
path: root/asdc-controller
diff options
context:
space:
mode:
Diffstat (limited to 'asdc-controller')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java88
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java257
-rw-r--r--asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java22
-rw-r--r--asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java38
4 files changed, 294 insertions, 111 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
index dd159c0b38..ea1d194c68 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
@@ -62,7 +62,9 @@ import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
import org.onap.so.asdc.tenantIsolation.DistributionStatus;
import org.onap.so.asdc.tenantIsolation.WatchdogDistribution;
import org.onap.so.asdc.util.ASDCNotificationLogging;
+import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
import org.onap.so.db.request.beans.WatchdogDistributionStatus;
+import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
import org.onap.so.logger.ErrorCode;
import org.onap.so.logger.MessageEnum;
@@ -94,6 +96,9 @@ public class ASDCController {
private WatchdogDistributionStatusRepository wdsRepo;
@Autowired
+ protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
+
+ @Autowired
private ASDCConfiguration asdcConfig;
@Autowired
@@ -106,6 +111,8 @@ public class ASDCController {
private static final String UUID_PARAM = "(UUID:";
+ protected static final String MSO = "SO";
+
@Autowired
private WatchdogDistribution wd;
@@ -270,6 +277,52 @@ public class ASDCController {
}
}
+ protected void notifyErrorToAsdc(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure,
+ DistributionStatusEnum deployStatus, VfResourceStructure resourceStructure, String errorMessage) {
+ // do csar lever first
+ this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deployStatus, errorMessage);
+ // at resource level
+ for (IResourceInstance resource : iNotif.getResources()) {
+ resourceStructure = new VfResourceStructure(iNotif, resource);
+ errorMessage = String.format("Resource with UUID: %s already exists", resource.getResourceUUID());
+ this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deployStatus,
+ errorMessage);
+ }
+ }
+
+ protected boolean isCsarAlreadyDeployed(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
+ VfResourceStructure resourceStructure = null;
+ String errorMessage = "";
+ boolean csarAlreadyDeployed = false;
+ DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK;
+ WatchdogComponentDistributionStatus wdStatus =
+ new WatchdogComponentDistributionStatus(iNotif.getDistributionID(), MSO);
+ try {
+ csarAlreadyDeployed = toscaInstaller.isCsarAlreadyDeployed(toscaResourceStructure);
+ if (csarAlreadyDeployed) {
+ deployStatus = DistributionStatusEnum.ALREADY_DEPLOYED;
+ resourceStructure = new VfResourceStructure(iNotif, null);
+ errorMessage = String.format("Csar with UUID: %s already exists",
+ toscaResourceStructure.getToscaArtifact().getArtifactUUID());
+ wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
+ watchdogCDStatusRepository.saveAndFlush(wdStatus);
+ logger.error(errorMessage);
+ }
+ } catch (ArtifactInstallerException e) {
+ deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
+ resourceStructure = new VfResourceStructure(iNotif, null);
+ errorMessage = e.getMessage();
+ wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
+ watchdogCDStatusRepository.saveAndFlush(wdStatus);
+ logger.warn("Tosca Checksums don't match, Tosca validation check failed", e);
+ }
+
+ if (deployStatus != DistributionStatusEnum.DEPLOY_OK) {
+ notifyErrorToAsdc(iNotif, toscaResourceStructure, deployStatus, resourceStructure, errorMessage);
+ }
+
+ return csarAlreadyDeployed;
+ }
protected IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact, String distributionId)
throws ASDCDownloadException {
@@ -378,23 +431,14 @@ public class ASDCController {
}
protected void sendCsarDeployNotification(INotificationData iNotif, ResourceStructure resourceStructure,
- ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) {
+ ToscaResourceStructure toscaResourceStructure, DistributionStatusEnum statusEnum, String errorReason) {
IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact();
- if (deploySuccessful) {
-
- this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(),
- asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(),
- DistributionStatusEnum.DEPLOY_OK, errorReason, System.currentTimeMillis());
+ this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(), asdcConfig.getConsumerID(),
+ resourceStructure.getNotification().getDistributionID(), statusEnum, errorReason,
+ System.currentTimeMillis());
- } else {
-
- this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(),
- asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(),
- DistributionStatusEnum.DEPLOY_ERROR, errorReason, System.currentTimeMillis());
-
- }
}
protected void deployResourceStructure(ResourceStructure resourceStructure,
@@ -660,7 +704,7 @@ public class ASDCController {
String msoConfigPath = getMsoConfigPath();
boolean hasVFResource = false;
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath);
- boolean deploySuccessful = true;
+ DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK;
String errorMessage = null;
boolean serviceDeployed = false;
@@ -672,6 +716,10 @@ public class ASDCController {
File csarFile = new File(filePath);
+ if (isCsarAlreadyDeployed(iNotif, toscaResourceStructure)) {
+ return;
+ }
+
for (IResourceInstance resource : iNotif.getResources()) {
String resourceType = resource.getResourceType();
@@ -679,7 +727,8 @@ public class ASDCController {
logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID());
- if ("VF".equals(resourceType)) {
+ if ("VF".equals(resourceType) && resource.getArtifacts() != null
+ && !resource.getArtifacts().isEmpty()) {
resourceStructure = new VfResourceStructure(iNotif, resource);
} else if ("PNF".equals(resourceType)) {
resourceStructure = new PnfResourceStructure(iNotif, resource);
@@ -697,7 +746,8 @@ public class ASDCController {
logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: "
+ resourceStructure.getResourceInstance().getResourceUUID());
- if ("VF".equals(resourceType)) {
+ if ("VF".equals(resourceType) && resource.getArtifacts() != null
+ && !resource.getArtifacts().isEmpty()) {
hasVFResource = true;
for (IArtifactInfo artifact : resource.getArtifacts()) {
IDistributionClientDownloadResult resultArtifact =
@@ -733,7 +783,7 @@ public class ASDCController {
}
} catch (ArtifactInstallerException e) {
- deploySuccessful = false;
+ deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
errorMessage = e.getMessage();
logger.error("Exception occurred", e);
}
@@ -746,12 +796,12 @@ public class ASDCController {
try {
this.deployResourceStructure(resourceStructure, toscaResourceStructure);
} catch (ArtifactInstallerException e) {
- deploySuccessful = false;
+ deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
errorMessage = e.getMessage();
logger.error("Exception occurred", e);
}
}
- this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deploySuccessful,
+ this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deployStatus,
errorMessage);
}
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
index fce8c5655b..179fa44547 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
@@ -35,6 +35,8 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.hibernate.StaleObjectStateException;
import org.hibernate.exception.ConstraintViolationException;
@@ -48,14 +50,7 @@ import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
-import org.onap.sdc.toscaparser.api.CapabilityAssignment;
-import org.onap.sdc.toscaparser.api.CapabilityAssignments;
-import org.onap.sdc.toscaparser.api.Group;
-import org.onap.sdc.toscaparser.api.NodeTemplate;
-import org.onap.sdc.toscaparser.api.Policy;
-import org.onap.sdc.toscaparser.api.Property;
-import org.onap.sdc.toscaparser.api.RequirementAssignment;
-import org.onap.sdc.toscaparser.api.RequirementAssignments;
+import org.onap.sdc.toscaparser.api.*;
import org.onap.sdc.toscaparser.api.elements.Metadata;
import org.onap.sdc.toscaparser.api.functions.GetInput;
import org.onap.sdc.toscaparser.api.parameters.Input;
@@ -113,6 +108,8 @@ import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomization
import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
+import org.onap.so.db.catalog.data.repository.HeatEnvironmentRepository;
+import org.onap.so.db.catalog.data.repository.HeatFilesRepository;
import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
@@ -122,6 +119,7 @@ import org.onap.so.db.catalog.data.repository.PnfResourceRepository;
import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
import org.onap.so.db.catalog.data.repository.ServiceRepository;
import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
+import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
import org.onap.so.db.catalog.data.repository.VFModuleRepository;
import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
@@ -228,6 +226,12 @@ public class ToscaResourceInstaller {
protected HeatTemplateRepository heatRepo;
@Autowired
+ protected HeatEnvironmentRepository heatEnvRepo;
+
+ @Autowired
+ protected HeatFilesRepository heatFilesRepo;
+
+ @Autowired
protected NetworkResourceCustomizationRepository networkCustomizationRepo;
@Autowired
@@ -244,6 +248,9 @@ public class ToscaResourceInstaller {
protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
@Autowired
+ protected ToscaCsarRepository toscaCsarRepo;
+
+ @Autowired
protected PnfResourceRepository pnfResourceRepository;
@Autowired
@@ -254,6 +261,31 @@ public class ToscaResourceInstaller {
protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class);
+ public boolean isCsarAlreadyDeployed(ToscaResourceStructure toscaResourceStructure)
+ throws ArtifactInstallerException {
+ boolean deployed = false;
+ if (toscaResourceStructure == null) {
+ return deployed;
+ }
+
+ IArtifactInfo inputToscaCsar = toscaResourceStructure.getToscaArtifact();
+ String checkSum = inputToscaCsar.getArtifactChecksum();
+ String artifactUuid = inputToscaCsar.getArtifactUUID();
+
+ Optional<ToscaCsar> toscaCsarObj = toscaCsarRepo.findById(artifactUuid);
+ if (toscaCsarObj.isPresent()) {
+ ToscaCsar toscaCsar = toscaCsarObj.get();
+ if (!toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
+ String errorMessage =
+ String.format("Csar with UUID: %s already exists.Their checksums don't match", artifactUuid);
+ throw new ArtifactInstallerException(errorMessage);
+ } else if (toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
+ deployed = true;
+ }
+ }
+ return deployed;
+ }
+
public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed)
throws ArtifactInstallerException {
boolean status = false;
@@ -528,27 +560,35 @@ public class ToscaResourceInstaller {
logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
}
- private static String getValue(Object value, List<Input> servInputs) {
- String output = null;
+
+ // this of temporary solution
+ private static String getValue(Object value, List<Input> inputs) {
+ String outInput;
+ String defaultValue = null;
if (value instanceof Map) {
- // currently this logic handles only one level of nesting.
- return ((LinkedHashMap) value).values().toArray()[0].toString();
+ outInput = ((LinkedHashMap) value).values().toArray()[0].toString();
} else if (value instanceof GetInput) {
String inputName = ((GetInput) value).getInputName();
-
- for (Input input : servInputs) {
- if (input.getName().equals(inputName)) {
- // keep both input name and default value
- // if service input does not supplies value the use default value
- String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : "";
- output = inputName + "|" + defaultValue;// return default value
- }
+ Optional<Input> inputOptional =
+ inputs.stream().filter(input -> input.getName().equals(inputName)).findFirst();
+ if (inputOptional.isPresent()) {
+ Input input = inputOptional.get();
+ defaultValue = input.getDefault() != null ? input.getDefault().toString() : "";
}
-
+ String valueStr = value.toString();
+ String regex = "(?<=\\[).*?(?=\\])";
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(valueStr);
+ if (matcher.find()) {
+ valueStr = matcher.group();
+ } else {
+ valueStr = inputName;
+ }
+ outInput = valueStr + "|" + defaultValue;
} else {
- output = value != null ? value.toString() : "";
+ outInput = value != null ? value.toString() : "";
}
- return output; // return property value
+ return outInput;
}
String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid)
@@ -1196,77 +1236,95 @@ public class ToscaResourceInstaller {
protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
- HeatTemplate heatTemplate = new HeatTemplate();
- List<String> typeList = new ArrayList<>();
- typeList.add(ASDCConfiguration.HEAT_NESTED);
- typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
- heatTemplate.setTemplateBody(
- verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
- heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
+ HeatTemplate existingHeatTemplate =
+ heatRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
- if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
- heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
- } else {
- heatTemplate.setTimeoutMinutes(240);
- }
+ if (existingHeatTemplate == null) {
+ HeatTemplate heatTemplate = new HeatTemplate();
+ List<String> typeList = new ArrayList<>();
+ typeList.add(ASDCConfiguration.HEAT_NESTED);
+ typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
- heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
- heatTemplate.setVersion(BigDecimalVersion
- .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
- heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+ heatTemplate.setTemplateBody(
+ verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
+ heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
- if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
- heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
- } else {
- heatTemplate.setArtifactChecksum(MANUAL_RECORD);
- }
+ if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
+ heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
+ } else {
+ heatTemplate.setTimeoutMinutes(240);
+ }
+
+ heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
+ heatTemplate.setVersion(BigDecimalVersion
+ .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
+ heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+
+ if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
+ heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
+ } else {
+ heatTemplate.setArtifactChecksum(MANUAL_RECORD);
+ }
- Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(),
- vfModuleArtifact.getArtifactInfo().getArtifactUUID());
- heatTemplate.setParameters(heatParam);
- vfModuleArtifact.setHeatTemplate(heatTemplate);
+ Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(),
+ vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+ heatTemplate.setParameters(heatParam);
+ vfModuleArtifact.setHeatTemplate(heatTemplate);
+ }
}
protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
VfModuleArtifact vfModuleArtifact) {
- HeatEnvironment heatEnvironment = new HeatEnvironment();
- heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
- List<String> typeList = new ArrayList<>();
- typeList.add(ASDCConfiguration.HEAT);
- typeList.add(ASDCConfiguration.HEAT_VOL);
- heatEnvironment.setEnvironment(
- verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
- heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
- heatEnvironment.setVersion(BigDecimalVersion
- .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
- heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
-
- if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
- heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
- } else {
- heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
+
+ HeatEnvironment existingHeatEnvironment =
+ heatEnvRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+
+ if (existingHeatEnvironment == null) {
+ HeatEnvironment heatEnvironment = new HeatEnvironment();
+ heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
+ List<String> typeList = new ArrayList<>();
+ typeList.add(ASDCConfiguration.HEAT);
+ typeList.add(ASDCConfiguration.HEAT_VOL);
+ heatEnvironment.setEnvironment(
+ verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
+ heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
+ heatEnvironment.setVersion(BigDecimalVersion
+ .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
+ heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+
+ if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
+ heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
+ } else {
+ heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
+ }
+ vfModuleArtifact.setHeatEnvironment(heatEnvironment);
}
- vfModuleArtifact.setHeatEnvironment(heatEnvironment);
}
protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
- HeatFiles heatFile = new HeatFiles();
- heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
- heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
- heatFile.setFileBody(vfModuleArtifact.getResult());
- heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
- heatFile.setVersion(BigDecimalVersion
- .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
- toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
- if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
- heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
- } else {
- heatFile.setArtifactChecksum(MANUAL_RECORD);
+ HeatFiles existingHeatFiles =
+ heatFilesRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+
+ if (existingHeatFiles == null) {
+ HeatFiles heatFile = new HeatFiles();
+ heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+ heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
+ heatFile.setFileBody(vfModuleArtifact.getResult());
+ heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
+ heatFile.setVersion(BigDecimalVersion
+ .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
+ toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+ if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
+ heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
+ } else {
+ heatFile.setArtifactChecksum(MANUAL_RECORD);
+ }
+ vfModuleArtifact.setHeatFiles(heatFile);
+
}
- vfModuleArtifact.setHeatFiles(heatFile);
}
protected Service createService(ToscaResourceStructure toscaResourceStructure,
@@ -1791,13 +1849,16 @@ public class ToscaResourceInstaller {
vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper()
.getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
- createVFCInstanceGroupMembers(vfcInstanceGroupCustom, group);
+
+ ArrayList<Input> inputs = vnfcNodeTemplate.getSubMappingToscaTemplate().getInputs();
+ createVFCInstanceGroupMembers(vfcInstanceGroupCustom, group, inputs);
return vfcInstanceGroupCustom;
}
- private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom, Group group) {
+ private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom, Group group,
+ List<Input> inputList) {
List<NodeTemplate> members = group.getMemberNodes();
if (!CollectionUtils.isEmpty(members)) {
for (NodeTemplate vfcTemplate : members) {
@@ -1815,13 +1876,33 @@ public class ToscaResourceInstaller {
vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
vnfcCustomization
.setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
-
- // @After vfcInstanceGroupCustom merged
- // vfcInstanceGroupCustom.getVnfcCustomizations().add(vnfcCustomization);
+ vnfcCustomization.setResourceInput(getVnfcResourceInput(vfcTemplate, inputList));
+ vfcInstanceGroupCustom.getVnfcCustomizations().add(vnfcCustomization);
}
}
}
+ public String getVnfcResourceInput(NodeTemplate vfcTemplate, List<Input> inputList) {
+ Map<String, String> resouceRequest = new HashMap<>();
+ LinkedHashMap<String, Property> vfcTemplateProperties = vfcTemplate.getProperties();
+ for (String key : vfcTemplateProperties.keySet()) {
+ Property property = vfcTemplateProperties.get(key);
+ String resourceValue = getValue(property.getValue(), inputList);
+ resouceRequest.put(key, resourceValue);
+ }
+
+ String jsonStr = null;
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ jsonStr = objectMapper.writeValueAsString(resouceRequest);
+ jsonStr = jsonStr.replace("\"", "\\\"");
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+
+ return jsonStr;
+ }
+
protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate,
ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service,
@@ -2237,10 +2318,12 @@ public class ToscaResourceInstaller {
vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
vfModuleArtifact.incrementDeployedInDB();
} else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
- if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
- vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
- } else {
- vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
+ if (vfModuleArtifact.getHeatEnvironment() != null) {
+ if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
+ vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
+ } else {
+ vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
+ }
}
vfModuleArtifact.incrementDeployedInDB();
} else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java
index 844adeede2..f6a369e405 100644
--- a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java
+++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java
@@ -33,10 +33,7 @@ import org.onap.sdc.toscaparser.api.parameters.Input;
import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
import org.onap.so.asdc.installer.ToscaResourceStructure;
import org.onap.so.db.catalog.beans.Service;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
+import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
@@ -61,6 +58,23 @@ public class ToscaResourceInputTest {
Input input;
@Test
+ public void getListResourceInput() {
+ ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
+ LinkedHashMap<String, Property> hashMap = new LinkedHashMap<>();
+ hashMap.put("key1", property);
+ when(nodeTemplate.getProperties()).thenReturn(hashMap);
+ when(property.getValue()).thenReturn(getInput);
+ when(getInput.getInputName()).thenReturn("nameKey");
+ when(input.getName()).thenReturn("nameKey");
+ when(input.getDefault()).thenReturn("defaultValue");
+ when(getInput.toString()).thenReturn("getinput:[sites,INDEX,role]");
+ List<Input> inputs = new ArrayList<>();
+ inputs.add(input);
+ String resourceInput = toscaResourceInstaller.getVnfcResourceInput(nodeTemplate, inputs);
+ assertEquals("{\\\"key1\\\":\\\"sites,INDEX,role|defaultValue\\\"}", resourceInput);
+ }
+
+ @Test
public void processResourceSequenceTest() {
ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java
index ce70a252c9..dd107f7775 100644
--- a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java
+++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java
@@ -24,12 +24,14 @@ import static com.shazam.shazamcrest.MatcherAssert.assertThat;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.exception.LockAcquisitionException;
@@ -39,6 +41,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.IResourceInstance;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl;
@@ -58,15 +61,17 @@ import org.onap.so.db.catalog.beans.ConfigurationResource;
import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
+import org.onap.so.db.catalog.beans.ToscaCsar;
import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
import org.onap.so.db.catalog.data.repository.ServiceRepository;
+import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.util.ReflectionTestUtils;
-
+import java.util.Optional;
public class ToscaResourceInstallerTest extends BaseTest {
@Autowired
@@ -117,6 +122,37 @@ public class ToscaResourceInstallerTest extends BaseTest {
}
@Test
+ public void isCsarAlreadyDeployedTest() throws ArtifactInstallerException {
+ IArtifactInfo inputCsar = mock(IArtifactInfo.class);
+ String artifactUuid = "0122c05e-e13a-4c63-b5d2-475ccf13aa74";
+ String checkSum = "MGUzNjJjMzk3OTBkYzExYzQ0MDg2ZDc2M2E2ZjZiZmY=";
+
+ doReturn(checkSum).when(inputCsar).getArtifactChecksum();
+ doReturn(artifactUuid).when(inputCsar).getArtifactUUID();
+
+ doReturn(inputCsar).when(toscaResourceStructure).getToscaArtifact();
+
+ ToscaCsar toscaCsar = mock(ToscaCsar.class);
+
+ Optional<ToscaCsar> returnValue = Optional.of(toscaCsar);
+
+ ToscaCsarRepository toscaCsarRepo = spy(ToscaCsarRepository.class);
+
+
+ doReturn(artifactUuid).when(toscaCsar).getArtifactUUID();
+ doReturn(checkSum).when(toscaCsar).getArtifactChecksum();
+ doReturn(returnValue).when(toscaCsarRepo).findById(artifactUuid);
+
+ ReflectionTestUtils.setField(toscaInstaller, "toscaCsarRepo", toscaCsarRepo);
+
+ boolean isCsarDeployed = toscaInstaller.isCsarAlreadyDeployed(toscaResourceStructure);
+ assertTrue(isCsarDeployed);
+ verify(toscaCsarRepo, times(1)).findById(artifactUuid);
+ verify(toscaResourceStructure, times(1)).getToscaArtifact();
+ verify(toscaCsar, times(2)).getArtifactChecksum();
+ }
+
+ @Test
public void isResourceAlreadyDeployedTest() throws Exception {
notificationData.setServiceName("serviceName");
notificationData.setServiceVersion("123456");