summaryrefslogtreecommitdiffstats
path: root/asdc-controller/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'asdc-controller/src/main')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java85
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java100
2 files changed, 133 insertions, 52 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java
index 46d0f78e35..87008f1d8f 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java
@@ -20,14 +20,18 @@
package org.onap.so.asdc.activity;
-import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.onap.so.asdc.activity.beans.ActivitySpec;
-import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.asdc.activity.beans.Input;
+import org.onap.so.asdc.activity.beans.Output;
+import org.onap.so.db.catalog.beans.ActivitySpecActivitySpecCategories;
+import org.onap.so.db.catalog.beans.ActivitySpecActivitySpecParameters;
+import org.onap.so.db.catalog.beans.ActivitySpecParameters;
+import org.onap.so.db.catalog.data.repository.ActivitySpecRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,17 +43,24 @@ public class DeployActivitySpecs {
@Autowired
private Environment env;
+ @Autowired
+ private ActivitySpecRepository activitySpecRepository;
+
private static final String SDC_ENDPOINT = "mso.asdc.config.activity.endpoint";
+ private static final String DIRECTION_INPUT = "input";
+ private static final String DIRECTION_OUTPUT = "output";
protected static final Logger logger = LoggerFactory.getLogger(DeployActivitySpecs.class);
- public void deployActivities() throws Exception {
- String hostname = this.env.getProperty(SDC_ENDPOINT);
- List<ActivitySpec> activitySpecs = new ArrayList<ActivitySpec>();
- // Initialize activitySpecs from Catalog DB
-
- for (ActivitySpec activitySpec : activitySpecs) {
+ public void deployActivities() throws Exception {
+ String hostname = env.getProperty(SDC_ENDPOINT);
+ if (hostname == null || hostname.isEmpty()) {
+ return;
+ }
+ List<org.onap.so.db.catalog.beans.ActivitySpec> activitySpecsFromCatalog = activitySpecRepository.findAll();
+ for (org.onap.so.db.catalog.beans.ActivitySpec activitySpecFromCatalog : activitySpecsFromCatalog) {
+ ActivitySpec activitySpec = mapActivitySpecFromCatalogToSdc(activitySpecFromCatalog);
String activitySpecId = activitySpecsActions.createActivitySpec(hostname, activitySpec);
if (activitySpecId != null) {
logger.info("{} {}", "Successfully created activitySpec", activitySpec.getName());
@@ -64,4 +75,62 @@ public class DeployActivitySpecs {
}
}
}
+
+ public ActivitySpec mapActivitySpecFromCatalogToSdc(
+ org.onap.so.db.catalog.beans.ActivitySpec activitySpecFromCatalog) {
+ ActivitySpec activitySpec = new ActivitySpec();
+ activitySpec.setName(activitySpecFromCatalog.getName());
+ activitySpec.setDescription(activitySpecFromCatalog.getDescription());
+ mapCategoryList(activitySpecFromCatalog.getActivitySpecActivitySpecCategories(), activitySpec);
+ mapInputsAndOutputs(activitySpecFromCatalog.getActivitySpecActivitySpecParameters(), activitySpec);
+ return activitySpec;
+ }
+
+ private void mapCategoryList(List<ActivitySpecActivitySpecCategories> activitySpecActivitySpecCategories,
+ ActivitySpec activitySpec) {
+ if (activitySpecActivitySpecCategories == null || activitySpecActivitySpecCategories.size() == 0) {
+ return;
+ }
+ List<String> categoryList = new ArrayList<String>();
+ for (ActivitySpecActivitySpecCategories activitySpecCat : activitySpecActivitySpecCategories) {
+ if (activitySpecCat != null) {
+ if (activitySpecCat.getActivitySpecCategories() != null) {
+ categoryList.add(activitySpecCat.getActivitySpecCategories().getName());
+ }
+ }
+ }
+ activitySpec.setCategoryList(categoryList);
+ }
+
+ private void mapInputsAndOutputs(List<ActivitySpecActivitySpecParameters> activitySpecActivitySpecParameters,
+ ActivitySpec activitySpec) {
+ if (activitySpecActivitySpecParameters == null || activitySpecActivitySpecParameters.size() == 0) {
+ return;
+ }
+ List<Input> inputs = new ArrayList<Input>();
+ List<Output> outputs = new ArrayList<Output>();
+ for (ActivitySpecActivitySpecParameters activitySpecParam : activitySpecActivitySpecParameters) {
+ if (activitySpecParam != null) {
+ if (activitySpecParam.getActivitySpecParameters() != null) {
+ ActivitySpecParameters activitySpecParameters = activitySpecParam.getActivitySpecParameters();
+ if (activitySpecParameters != null) {
+ if (activitySpecParameters.getDirection().equals(DIRECTION_INPUT)) {
+ Input input = new Input();
+ input.setName(activitySpecParameters.getName());
+ input.setType(activitySpecParameters.getType());
+ inputs.add(input);
+ } else if (activitySpecParameters.getDirection().equals(DIRECTION_OUTPUT)) {
+ Output output = new Output();
+ output.setName(activitySpecParameters.getName());
+ output.setType(activitySpecParameters.getType());
+ outputs.add(output);
+ }
+ }
+ }
+ }
+ }
+ activitySpec.setInputs(inputs);
+ activitySpec.setOutputs(outputs);
+ return;
+ }
}
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 f3a495825c..d3eab9a3fd 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,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
+import org.hibernate.StaleObjectStateException;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.exception.LockAcquisitionException;
import org.onap.sdc.api.notification.IArtifactInfo;
@@ -55,7 +56,6 @@ 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.elements.Metadata;
-import org.onap.sdc.toscaparser.api.elements.StatefulEntityType;
import org.onap.sdc.toscaparser.api.functions.GetInput;
import org.onap.sdc.toscaparser.api.parameters.Input;
import org.onap.sdc.utils.DistributionStatusEnum;
@@ -122,7 +122,6 @@ 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.VFModuleCustomizationRepository;
import org.onap.so.db.catalog.data.repository.VFModuleRepository;
-import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
@@ -308,6 +307,7 @@ public class ToscaResourceInstaller {
}
}
+
@Transactional(rollbackFor = {ArtifactInstallerException.class})
public void installTheResource(ToscaResourceStructure toscaResourceStruct, ResourceStructure resourceStruct)
throws ArtifactInstallerException {
@@ -408,8 +408,10 @@ public class ToscaResourceInstaller {
processNetworkCollections(toscaResourceStruct, service);
// Process Service Proxy & Configuration
processServiceProxyAndConfiguration(toscaResourceStruct, service);
+
logger.info("Saving Service: {} ", service.getModelName());
- serviceRepo.save(service);
+ service = serviceRepo.save(service);
+ correlateConfigCustomResources(service);
WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(
vfResourceStruct.getNotification().getDistributionID(), MSO);
@@ -637,7 +639,8 @@ public class ToscaResourceInstaller {
}
protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate,
- ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
+ ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization,
+ Service service) {
Metadata metadata = nodeTemplate.getMetaData();
ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
@@ -660,31 +663,15 @@ public class ToscaResourceInstaller {
.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
configCustomizationResource.setConfigurationResource(configResource);
+ configCustomizationResource.setService(service);
configResourceCustomizationSet.add(configCustomizationResource);
configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
+
return configCustomizationResource;
}
- protected Optional<ConfigurationResourceCustomization> getVnrNodeTemplate(
- List<NodeTemplate> configurationNodeTemplatesList, ToscaResourceStructure toscaResourceStructure,
- ServiceProxyResourceCustomization spResourceCustomization) {
- Optional<ConfigurationResourceCustomization> configurationResourceCust = Optional.empty();
- for (NodeTemplate nodeTemplate : configurationNodeTemplatesList) {
- StatefulEntityType entityType = nodeTemplate.getTypeDefinition();
- String type = entityType.getType();
-
- if (VLAN_NETWORK_RECEPTOR.equals(type)) {
- configurationResourceCust = Optional.of(getConfigurationResourceCustomization(nodeTemplate,
- toscaResourceStructure, spResourceCustomization));
- break;
- }
- }
-
- return configurationResourceCust;
- }
-
protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
List<NodeTemplate> serviceProxyResourceList =
@@ -703,8 +690,6 @@ public class ToscaResourceInstaller {
for (NodeTemplate spNode : serviceProxyResourceList) {
serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
serviceProxyList.add(serviceProxy);
- Optional<ConfigurationResourceCustomization> vnrResourceCustomization =
- getVnrNodeTemplate(configurationNodeTemplatesList, toscaResourceStruct, serviceProxy);
for (NodeTemplate configNode : configurationNodeTemplatesList) {
@@ -712,19 +697,21 @@ public class ToscaResourceInstaller {
toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
for (RequirementAssignment requirement : requirementsList) {
if (requirement.getNodeTemplateName().equals(spNode.getName())) {
- ConfigurationResourceCustomization configurationResource = createConfiguration(configNode,
- toscaResourceStruct, serviceProxy, vnrResourceCustomization);
-
- Optional<ConfigurationResourceCustomization> matchingObject = configurationResourceList
- .stream()
- .filter(configurationResourceCustomization -> configNode.getMetaData()
- .getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)
- .equals(configurationResource.getModelCustomizationUUID()))
- .findFirst();
+ ConfigurationResourceCustomization configurationResource =
+ createConfiguration(configNode, toscaResourceStruct, serviceProxy, service);
+
+ Optional<ConfigurationResourceCustomization> matchingObject =
+ configurationResourceList.stream()
+ .filter(configurationResourceCustomization -> configNode.getMetaData()
+ .getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)
+ .equals(configurationResource.getModelCustomizationUUID()))
+ .filter(configurationResourceCustomization -> configurationResourceCustomization
+ .getModelInstanceName()
+ .equals(configurationResource.getModelInstanceName()))
+ .findFirst();
if (!matchingObject.isPresent()) {
configurationResourceList.add(configurationResource);
}
-
break;
}
}
@@ -737,6 +724,37 @@ public class ToscaResourceInstaller {
service.setServiceProxyCustomizations(serviceProxyList);
}
+ /*
+ * ConfigurationResourceCustomization objects have their IDs auto incremented in the database. Unless we know their
+ * IDs we cannot possibly associate their related records. So these ConfigResourceCustomizations are persisted first
+ * and subsequently correlated.
+ */
+
+ protected void correlateConfigCustomResources(Service service) {
+ /* Assuming that we have only one pair of VRF-VNR */
+ ConfigurationResourceCustomization vrfConfigCustomResource = null;
+ ConfigurationResourceCustomization vnrConfigCustomResource = null;
+ List<ConfigurationResourceCustomization> configCustomList = service.getConfigurationCustomizations();
+ for (ConfigurationResourceCustomization configResource : configCustomList) {
+ String nodeType = configResource.getConfigurationResource().getToscaNodeType();
+ if (NODES_VRF_ENTRY.equalsIgnoreCase(nodeType)) {
+ vrfConfigCustomResource = configResource;
+ } else if (VLAN_NETWORK_RECEPTOR.equalsIgnoreCase(nodeType)) {
+ vnrConfigCustomResource = configResource;
+ }
+ }
+
+ if (vrfConfigCustomResource != null) {
+ vrfConfigCustomResource.setConfigResourceCustomization(vnrConfigCustomResource);
+ configCustomizationRepo.save(vrfConfigCustomResource);
+
+ }
+ if (vnrConfigCustomResource != null) {
+ vnrConfigCustomResource.setConfigResourceCustomization(vrfConfigCustomResource);
+ configCustomizationRepo.save(vnrConfigCustomResource);
+ }
+ }
+
protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
List<NodeTemplate> networkCollectionList =
@@ -1229,22 +1247,15 @@ public class ToscaResourceInstaller {
protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate,
ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization,
- Optional<ConfigurationResourceCustomization> vnrResourceCustomization) {
+ Service service) {
- ConfigurationResourceCustomization configCustomizationResource =
- getConfigurationResourceCustomization(nodeTemplate, toscaResourceStructure, spResourceCustomization);
+ ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization(
+ nodeTemplate, toscaResourceStructure, spResourceCustomization, service);
ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
- StatefulEntityType entityType = nodeTemplate.getTypeDefinition();
- String type = entityType.getType();
-
- if (NODES_VRF_ENTRY.equals(type)) {
- configCustomizationResource.setConfigResourceCustomization(vnrResourceCustomization.orElse(null));
- }
-
configCustomizationResource.setConfigurationResource(configResource);
configResourceCustomizationSet.add(configCustomizationResource);
@@ -1353,6 +1364,7 @@ public class ToscaResourceInstaller {
networkCustomizationRepo.saveAndFlush(networkResourceCustomization);
+
} else if (networkResourceCustomization == null) {
networkResourceCustomization =
createNetworkResourceCustomization(networkNodeTemplate, toscaResourceStructure);