aboutsummaryrefslogtreecommitdiffstats
path: root/asdc-controller/src
diff options
context:
space:
mode:
Diffstat (limited to 'asdc-controller/src')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java3
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java84
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/WatchdogDistribution.java14
-rw-r--r--asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInputTest.java22
-rw-r--r--asdc-controller/src/test/resources/schema.sql1
5 files changed, 89 insertions, 35 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 faa40a694b..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
@@ -643,6 +643,8 @@ public class ASDCController {
}
}
+ wd.updateCatalogDBStatus(iNotif.getServiceInvariantUUID(), overallStatus);
+
if (isDeploySuccess && watchdogError == null) {
sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK,
null);
@@ -657,7 +659,6 @@ public class ASDCController {
wdsRepo.save(wds);
}
-
} catch (ObjectOptimisticLockingFailureException e) {
logger.debug(
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 b3741584f4..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;
@@ -565,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)
@@ -1846,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) {
@@ -1870,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,
@@ -2328,7 +2354,7 @@ public class ToscaResourceInstaller {
// setting resource input for vnf customization
vnfResourceCustomization.setResourceInput(
getResourceInput(toscaResourceStructure, vnfResourceCustomization.getModelCustomizationUUID()));
- vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization);
+ service.getVnfCustomizations().add(vnfResourceCustomization);
}
return vnfResourceCustomization;
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/WatchdogDistribution.java b/asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/WatchdogDistribution.java
index 3659ceed12..0128078a59 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/WatchdogDistribution.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/tenantIsolation/WatchdogDistribution.java
@@ -30,6 +30,7 @@ import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.graphinventory.entities.uri.Depth;
+import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.data.repository.ServiceRepository;
import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
import org.onap.so.db.request.beans.WatchdogDistributionStatus;
@@ -140,7 +141,6 @@ public class WatchdogDistribution {
logger.debug("Updating overall DistributionStatus to: {} for distributionId: ", status,
distributionId);
- watchdogDistributionStatus.setDistributionIdStatus(status);
watchdogDistributionStatusRepository.save(watchdogDistributionStatus);
} else {
logger.debug("Components Size Didn't match with the WatchdogComponentDistributionStatus results.");
@@ -181,6 +181,8 @@ public class WatchdogDistribution {
throw new Exception(error);
}
+
+
AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, serviceModelInvariantUUID,
serviceModelVersionId);
aaiUri.depth(Depth.ZERO); // Do not return relationships if any
@@ -198,6 +200,16 @@ public class WatchdogDistribution {
}
}
+ public void updateCatalogDBStatus(String serviceModelVersionId, String status) {
+ try {
+ Service foundService = serviceRepo.findOneByModelUUID(serviceModelVersionId);
+ foundService.setDistrobutionStatus(status);
+ serviceRepo.save(foundService);
+ } catch (Exception e) {
+ logger.error("Error updating CatalogDBStatus", e);
+ }
+ }
+
public AAIResourcesClient getAaiClient() {
if (aaiClient == null) {
aaiClient = new AAIResourcesClient();
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/resources/schema.sql b/asdc-controller/src/test/resources/schema.sql
index bdd906d870..0e8024da0a 100644
--- a/asdc-controller/src/test/resources/schema.sql
+++ b/asdc-controller/src/test/resources/schema.sql
@@ -806,6 +806,7 @@ CREATE TABLE `service` (
`WORKLOAD_CONTEXT` varchar(200) DEFAULT NULL,
`SERVICE_CATEGORY` varchar(200) DEFAULT NULL,
`RESOURCE_ORDER` varchar(200) default NULL,
+ OVERALL_DISTRIBUTION_STATUS varchar(45),
PRIMARY KEY (`MODEL_UUID`),
KEY `fk_service__tosca_csar1_idx` (`TOSCA_CSAR_ARTIFACT_UUID`),
CONSTRAINT `fk_service__tosca_csar1` FOREIGN KEY (`TOSCA_CSAR_ARTIFACT_UUID`) REFERENCES `tosca_csar` (`ARTIFACT_UUID`) ON DELETE CASCADE ON UPDATE CASCADE