diff options
Diffstat (limited to 'asdc-controller')
9 files changed, 255 insertions, 154 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/ActivitySpecsActions.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/ActivitySpecsActions.java index c37eccf594..06887f1253 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/activity/ActivitySpecsActions.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/ActivitySpecsActions.java @@ -29,7 +29,8 @@ import org.onap.so.asdc.activity.beans.ActivitySpec; import org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse; import org.onap.so.client.HttpClient; import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; +import org.onap.so.logger.LoggingAnchor; +import org.onap.logging.filter.base.ONAPComponents; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -62,7 +63,7 @@ public class ActivitySpecsActions { String urlString = UriBuilder.fromUri(hostname).path(ACTIVITY_SPEC_URI).build().toString(); URL url = new URL(urlString); - HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.SDC); + HttpClient httpClient = httpClientFactory.newJsonClient(url, ONAPComponents.SDC); httpClient.addAdditionalHeader("Content-Type", ContentType.APPLICATION_JSON.toString()); Response response = httpClient.post(payload); @@ -104,7 +105,7 @@ public class ActivitySpecsActions { String urlString = UriBuilder.fromUri(hostname).path(path).build().toString(); URL url = new URL(urlString); - HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.SDC); + HttpClient httpClient = httpClientFactory.newJsonClient(url, ONAPComponents.SDC); httpClient.addAdditionalHeader("Content-Type", ContentType.APPLICATION_JSON.toString()); Response response = httpClient.put(CERTIFY_ACTIVITY_PAYLOAD); 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 0fc94c8bd6..7f1c1968c1 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,6 +20,8 @@ package org.onap.so.asdc.activity; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.ArrayList; import java.util.List; import org.onap.so.logger.LoggingAnchor; @@ -27,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import org.apache.http.HttpStatus; import org.onap.so.asdc.activity.beans.ActivitySpec; import org.onap.so.asdc.activity.beans.Input; import org.onap.so.asdc.activity.beans.Output; @@ -59,6 +62,11 @@ public class DeployActivitySpecs { String hostname = env.getProperty(SDC_ENDPOINT); logger.debug("{} {}", "SDC ActivitySpec endpoint: ", hostname); if (hostname == null || hostname.isEmpty()) { + logger.warn("The hostname for SDC activities deployment is not configured in SO"); + return; + } + if (!checkHttpOk(hostname)) { + logger.warn("The sdc end point is not alive"); return; } List<org.onap.so.db.catalog.beans.ActivitySpec> activitySpecsFromCatalog = activitySpecRepository.findAll(); @@ -135,4 +143,22 @@ public class DeployActivitySpecs { activitySpec.setOutputs(outputs); return; } + + public boolean checkHttpOk(String host) { + URL url = null; + boolean isOk = false; + + int responseCode = 0; + try { + url = new URL(host); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + responseCode = connection.getResponseCode(); + } catch (Exception e) { + logger.warn("Exception on connecting to SDC WFD endpoint: " + e.getMessage()); + } + if (responseCode == HttpStatus.SC_OK) { + isOk = true; + } + return isOk; + } } 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 90116ad4f5..0080ed543c 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 @@ -723,7 +723,6 @@ public class ASDCController { // For each artifact, create a structure describing the VFModule in a ordered flat level ResourceStructure resourceStructure = null; String msoConfigPath = getMsoConfigPath(); - boolean hasVFResource = false; ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath); DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK; String errorMessage = null; @@ -738,7 +737,7 @@ public class ASDCController { for (IResourceInstance resource : iNotif.getResources()) { String resourceType = resource.getResourceType(); - + boolean hasVFResource = false; logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID()); @@ -801,19 +800,19 @@ public class ASDCController { errorMessage = e.getMessage(); logger.error("Exception occurred", e); } - } - if (!hasVFResource) { + if (!hasVFResource) { - logger.debug("No resources found for Service: " + iNotif.getServiceUUID()); + logger.debug("No resources found for Service: " + iNotif.getServiceUUID()); - logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID()); - try { - this.deployResourceStructure(resourceStructure, toscaResourceStructure); - } catch (ArtifactInstallerException e) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - errorMessage = e.getMessage(); - logger.error("Exception occurred", e); + logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID()); + try { + this.deployResourceStructure(resourceStructure, toscaResourceStructure); + } catch (ArtifactInstallerException e) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + errorMessage = e.getMessage(); + logger.error("Exception occurred", e); + } } } 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 c3ee081c69..e8e068a71a 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 @@ -26,6 +26,7 @@ package org.onap.so.asdc.installer.heat; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -437,13 +438,15 @@ public class ToscaResourceInstaller { List<IEntityDetails> vfEntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.VF), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false); + List<IEntityDetails> arEntityDetails = new ArrayList<IEntityDetails>(); + for (IEntityDetails vfEntityDetails : vfEntityList) { Metadata metadata = vfEntityDetails.getMetadata(); String category = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY); if (ALLOTTED_RESOURCE.equalsIgnoreCase(category)) { - continue; + arEntityDetails.add(vfEntityDetails); } processVfModules(vfEntityDetails, vfNodeTemplatesList.get(0), toscaResourceStruct, vfResourceStructure, @@ -451,8 +454,7 @@ public class ToscaResourceInstaller { } processResourceSequence(toscaResourceStruct, service); - List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources(); - processAllottedResources(toscaResourceStruct, service, allottedResourceList); + processAllottedResources(arEntityDetails, toscaResourceStruct, service); processNetworks(toscaResourceStruct, service); // process Network Collections processNetworkCollections(toscaResourceStruct, service); @@ -579,7 +581,8 @@ public class ToscaResourceInstaller { String outInput; String defaultValue = null; if (value instanceof Map) { - outInput = ((LinkedHashMap) value).values().toArray()[0].toString(); + Collection values = ((LinkedHashMap) value).values(); + outInput = (values.size() > 0) ? values.toArray()[0].toString() : ""; } else if (value instanceof GetInput) { String inputName = ((GetInput) value).getInputName(); Optional<Input> inputOptional = @@ -678,14 +681,31 @@ public class ToscaResourceInstaller { } } - protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service, - List<NodeTemplate> allottedResourceList) throws ArtifactInstallerException { - if (allottedResourceList != null) { - for (NodeTemplate allottedNode : allottedResourceList) { + protected void processAllottedResources(List<IEntityDetails> arEntityDetails, + ToscaResourceStructure toscaResourceStruct, Service service) throws ArtifactInstallerException { + + List<IEntityDetails> pnfAREntityList = getEntityDetails(toscaResourceStruct, + EntityQuery.newBuilder(SdcTypes.PNF), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false); + + for (IEntityDetails pnfEntity : pnfAREntityList) { + + Metadata metadata = pnfEntity.getMetadata(); + String category = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY); + if (ALLOTTED_RESOURCE.equalsIgnoreCase(category)) { + arEntityDetails.add(pnfEntity); + } + + } + + if (arEntityDetails != null) { + for (IEntityDetails arEntity : arEntityDetails) { AllottedResourceCustomization allottedResource = - createAllottedResource(allottedNode, toscaResourceStruct, service); - allottedResource.setResourceInput( - getResourceInput(toscaResourceStruct, allottedResource.getModelCustomizationUUID())); + createAllottedResource(arEntity, toscaResourceStruct, service); + String resourceInput = + getResourceInput(toscaResourceStruct, allottedResource.getModelCustomizationUUID()); + if (!"{}".equals(resourceInput)) { + allottedResource.setResourceInput(resourceInput); + } service.getAllottedCustomizations().add(allottedResource); } } @@ -821,13 +841,13 @@ public class ToscaResourceInstaller { protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) { - List<NodeTemplate> networkCollectionList = - toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR); + List<IEntityDetails> crEntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.CR), + TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false); - if (networkCollectionList != null) { - for (NodeTemplate crNode : networkCollectionList) { + if (crEntityList != null) { + for (IEntityDetails ncEntity : crEntityList) { - createNetworkCollection(crNode, toscaResourceStruct, service); + createNetworkCollection(ncEntity, toscaResourceStruct, service); collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource()); List<NetworkInstanceGroup> networkInstanceGroupList = @@ -1658,7 +1678,7 @@ public class ToscaResourceInstaller { return networkResource; } - protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate, + protected CollectionNetworkResourceCustomization createNetworkCollection(IEntityDetails cnrEntity, ToscaResourceStructure toscaResourceStructure, Service service) { CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = @@ -1667,33 +1687,26 @@ public class ToscaResourceInstaller { // **** Build Object to populate Collection_Resource table CollectionResource collectionResource = new CollectionResource(); + collectionResource.setModelName(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); collectionResource - .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - collectionResource.setModelInvariantUUID( - networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - collectionResource - .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - collectionResource - .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - collectionResource - .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - collectionResource.setToscaNodeType(networkNodeTemplate.getType()); + .setModelInvariantUUID(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + collectionResource.setModelUUID(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + collectionResource.setModelVersion(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + collectionResource.setDescription(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + collectionResource.setToscaNodeType(cnrEntity.getToscaType()); toscaResourceStructure.setCatalogCollectionResource(collectionResource); // **** Build object to populate Collection_Resource_Customization table NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization(); - ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - "cr_function")); - ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - "cr_role")); - ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - "cr_type")); + ncfc.setFunction(getLeafPropertyValue(cnrEntity, "cr_function")); + ncfc.setRole(getLeafPropertyValue(cnrEntity, "cr_role")); + ncfc.setType(getLeafPropertyValue(cnrEntity, "cr_type")); - ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + ncfc.setModelInstanceName(cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); ncfc.setModelCustomizationUUID( - networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>(); networkResourceCustomizationSet.add(collectionNetworkResourceCustomization); @@ -1704,25 +1717,28 @@ public class ToscaResourceInstaller { toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc); // *** Build object to populate the Instance_Group table - List<Group> groupList = - toscaResourceStructure.getSdcCsarHelper().getGroupsOfOriginOfNodeTemplateByToscaGroupType( - networkNodeTemplate, "org.openecomp.groups.NetworkCollection"); + List<IEntityDetails> ncEntityList = + getEntityDetails(toscaResourceStructure, + EntityQuery.newBuilder("org.openecomp.groups.NetworkCollection"), + TopologyTemplateQuery.newBuilder(SdcTypes.CR).customizationUUID( + cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)), + false); List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>(); List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<>(); - for (Group group : groupList) { + for (IEntityDetails ncGroupEntity : ncEntityList) { NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup(); - Metadata instanceMetadata = group.getMetadata(); + Metadata instanceMetadata = ncGroupEntity.getMetadata(); networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); networkInstanceGroup .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - networkInstanceGroup.setToscaNodeType(group.getType()); + networkInstanceGroup.setToscaNodeType(ncGroupEntity.getToscaType()); networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set // Role networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set @@ -1736,27 +1752,26 @@ public class ToscaResourceInstaller { crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup); crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); crInstanceGroupCustomization.setModelCustomizationUUID( - networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); // Loop through the template policy to find the subinterface_network_quantity property name. Then extract // the value for it. - List<Policy> policyList = - toscaResourceStructure.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType( - networkNodeTemplate, "org.openecomp.policies.scaling.Fixed"); + List<IEntityDetails> policyEntityList = getEntityDetails(toscaResourceStructure, + EntityQuery.newBuilder("org.openecomp.policies.scaling.Fixed"), + TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), true); - if (policyList != null) { - for (Policy policy : policyList) { - for (String policyNetworkCollection : policy.getTargets()) { + if (policyEntityList != null) { + for (IEntityDetails policyEntity : policyEntityList) { + for (String policyNetworkCollection : policyEntity.getTargets()) { - if (policyNetworkCollection.equalsIgnoreCase(group.getName())) { + if (policyNetworkCollection.equalsIgnoreCase(ncGroupEntity.getName())) { - Map<String, Object> propMap = policy.getPolicyProperties(); + Map<String, Property> propMap = policyEntity.getProperties(); if (propMap.get("quantity") != null) { - String quantity = toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(networkNodeTemplate, - getPropertyInput(propMap.get("quantity").toString())); + String quantity = getLeafPropertyValue(cnrEntity, + getPropertyInput(propMap.get("quantity").toString())); if (quantity != null) { crInstanceGroupCustomization @@ -1771,13 +1786,12 @@ public class ToscaResourceInstaller { } crInstanceGroupCustomization.setDescription( - toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) - + "_network_collection_description")); - crInstanceGroupCustomization.setFunction( - toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) - + "_network_collection_function")); + getLeafPropertyValue(cnrEntity, instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) + + "_network_collection_description")); + + crInstanceGroupCustomization.setFunction(getLeafPropertyValue(cnrEntity, + instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) + "_network_collection_function")); + crInstanceGroupCustomization.setCollectionResourceCust(ncfc); collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization); @@ -1789,18 +1803,21 @@ public class ToscaResourceInstaller { toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList); - List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL); + List<IEntityDetails> networkEntityList = + getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(SdcTypes.VL), + TopologyTemplateQuery.newBuilder(SdcTypes.CR).customizationUUID( + cnrEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)), + false); List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>(); // *****Build object to populate the NetworkResource table NetworkResource networkResource = new NetworkResource(); - for (NodeTemplate vlNodeTemplate : vlNodeList) { + for (IEntityDetails networkEntity : networkEntityList) { - String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue( - vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK); + String providerNetwork = getLeafPropertyValue(networkEntity, + SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK); if ("true".equalsIgnoreCase(providerNetwork)) { networkResource.setNeutronNetworkType(PROVIDER); @@ -1808,22 +1825,20 @@ public class ToscaResourceInstaller { networkResource.setNeutronNetworkType(BASIC); } - networkResource - .setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + networkResource.setModelName(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); networkResource.setModelInvariantUUID( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - networkResource - .setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + networkResource.setModelUUID(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); networkResource - .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + .setModelVersion(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); networkResource.setAicVersionMax( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)); + networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)); TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); if (tempNetworkLookUp != null) { @@ -1835,29 +1850,28 @@ public class ToscaResourceInstaller { } - networkResource.setToscaNodeType(vlNodeTemplate.getType()); + networkResource.setToscaNodeType(networkEntity.getToscaType()); networkResource.setDescription( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); networkResource.setOrchestrationMode(HEAT); // Build object to populate the // Collection_Network_Resource_Customization table - for (NodeTemplate memberNode : group.getMemberNodes()) { - collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName()); + for (IEntityDetails networkMemberEntity : ncGroupEntity.getMemberNodes()) { + collectionNetworkResourceCustomization.setModelInstanceName(networkMemberEntity.getName()); } collectionNetworkResourceCustomization.setModelCustomizationUUID( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); collectionNetworkResourceCustomization.setNetworkTechnology( - toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate, - SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)); - collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)); - collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)); - collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)); + getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)); + collectionNetworkResourceCustomization.setNetworkType( + getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)); + collectionNetworkResourceCustomization.setNetworkRole( + getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)); + collectionNetworkResourceCustomization.setNetworkScope( + getLeafPropertyValue(networkEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)); collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup); collectionNetworkResourceCustomization.setNetworkResource(networkResource); collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc); @@ -2601,21 +2615,21 @@ public class ToscaResourceInstaller { return vnfResource; } - protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate, + protected AllottedResourceCustomization createAllottedResource(IEntityDetails arEntity, ToscaResourceStructure toscaResourceStructure, Service service) { AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo.findOneByModelCustomizationUUID( - nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); if (allottedResourceCustomization == null) { AllottedResource allottedResource = findExistingAllottedResource(service, - nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); if (allottedResource == null) - allottedResource = createAR(nodeTemplate); + allottedResource = createAR(arEntity); toscaResourceStructure.setAllottedResource(allottedResource); - allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure); + allottedResourceCustomization = createAllottedResourceCustomization(arEntity, toscaResourceStructure); allottedResourceCustomization.setAllottedResource(allottedResource); allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization); } @@ -2636,73 +2650,81 @@ public class ToscaResourceInstaller { return allottedResource; } - protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate, + protected AllottedResourceCustomization createAllottedResourceCustomization(IEntityDetails arEntity, ToscaResourceStructure toscaResourceStructure) { AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization(); allottedResourceCustomization.setModelCustomizationUUID( - testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); - allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName()); + testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); + allottedResourceCustomization.setModelInstanceName(arEntity.getName()); + + allottedResourceCustomization + .setNfFunction(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); + allottedResourceCustomization.setNfNamingCode(getLeafPropertyValue(arEntity, "nf_naming_code")); + allottedResourceCustomization.setNfRole(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFROLE)); + allottedResourceCustomization.setNfType(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); + + EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.VFC).build(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) + .customizationUUID(allottedResourceCustomization.getModelCustomizationUUID()).build(); - allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION))); - allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code"))); - allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE))); - allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE))); + List<IEntityDetails> vfcEntities = + toscaResourceStructure.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, false); - List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper() - .getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID()); - if (vfcNodes != null) { - for (NodeTemplate vfcNode : vfcNodes) { + if (vfcEntities != null) { + for (IEntityDetails vfcEntity : vfcEntities) { - allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid")); allottedResourceCustomization - .setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid")); - allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name")); + .setProvidingServiceModelUUID(getLeafPropertyValue(vfcEntity, "providing_service_uuid")); + allottedResourceCustomization.setProvidingServiceModelInvariantUUID( + getLeafPropertyValue(vfcEntity, "providing_service_invariant_uuid")); + allottedResourceCustomization + .setProvidingServiceModelName(getLeafPropertyValue(vfcEntity, "providing_service_name")); } } + Map<String, CapabilityAssignment> capAssignmentList = arEntity.getCapabilities(); - CapabilityAssignments arCustomizationCapability = - toscaResourceStructure.getSdcCsarHelper().getCapabilitiesOf(nodeTemplate); + if (capAssignmentList != null) { - if (arCustomizationCapability != null) { - CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE); + for (Map.Entry<String, CapabilityAssignment> entry : capAssignmentList.entrySet()) { + CapabilityAssignment arCapability = entry.getValue(); + + if (arCapability != null) { + + String capabilityName = arCapability.getName(); + + if (capabilityName.equals(SCALABLE)) { + + allottedResourceCustomization + .setMinInstances(Integer.getInteger(getCapabilityLeafPropertyValue(arCapability, + SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); + allottedResourceCustomization + .setMinInstances(Integer.getInteger(getCapabilityLeafPropertyValue(arCapability, + SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); + + } + } - if (capAssign != null) { - allottedResourceCustomization.setMinInstances( - Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue( - capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); - allottedResourceCustomization.setMaxInstances( - Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue( - capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); } } + return allottedResourceCustomization; } - protected AllottedResource createAR(NodeTemplate nodeTemplate) { + protected AllottedResource createAR(IEntityDetails arEntity) { AllottedResource allottedResource = new AllottedResource(); - allottedResource - .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); + allottedResource.setModelUUID(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); allottedResource.setModelInvariantUUID( - testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); + testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); + allottedResource.setModelName(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); allottedResource - .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); + .setModelVersion(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + allottedResource.setToscaNodeType(testNull(arEntity.getToscaType())); allottedResource - .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); - allottedResource.setToscaNodeType(testNull(nodeTemplate.getType())); - allottedResource.setSubcategory( - testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY))); - allottedResource - .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + .setSubcategory(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY))); + allottedResource.setDescription(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); return allottedResource; } @@ -2794,14 +2816,26 @@ public class ToscaResourceInstaller { return null; } + protected String getCapabilityLeafPropertyValue(CapabilityAssignment capAssign, String propName) { + + Property leafProperty = capAssign.getProperties().get(propName); + + if (leafProperty != null && leafProperty.getValue() != null) { + return leafProperty.getValue().toString(); + } + + return null; + } + protected String getPropertyInput(String propertyName) { String inputName = new String(); if (propertyName != null) { int getInputIndex = propertyName.indexOf("{get_input="); + int getClosingIndex = propertyName.indexOf("}"); if (getInputIndex > -1) { - inputName = propertyName.substring(getInputIndex + 11, propertyName.length() - 1); + inputName = propertyName.substring(getInputIndex + 11, getClosingIndex); } } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java b/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java index a154734690..4b069e6ac7 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java @@ -724,6 +724,9 @@ public class ASDCNotificationLogging { buffer.append("Model Subcategory:"); buffer.append(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)); buffer.append(System.lineSeparator()); + buffer.append("Model Category:"); + buffer.append(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)); + buffer.append(System.lineSeparator()); buffer.append("Model Description:"); buffer.append(allottedNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); buffer.append(System.lineSeparator()); diff --git a/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java b/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java index 81977da278..b41fbaf658 100644 --- a/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java +++ b/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java @@ -22,7 +22,10 @@ package org.onap.asdc.activity; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import org.junit.Test; @@ -73,4 +76,32 @@ public class DeployActivitySpecsITTest extends BaseTest { deployActivitySpecs.deployActivities(); assertTrue(activitySpecCreateResponse.getId().equals("testActivityId")); } + + @Test + public void deployActivitySpecsIT_SDCEndpointDown_Test() throws Exception { + ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse(); + activitySpecCreateResponse.setId("testActivityId"); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + + ObjectMapper mapper = new ObjectMapper(); + String body = mapper.writeValueAsString(activitySpecCreateResponse); + + wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(org.springframework.http.HttpStatus.OK.value()).withBody(body))); + + when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://localhost:8090"); + + String urlPath = "/v1.0/activity-spec/testActivityId/versions/latest/actions"; + + wireMockServer.stubFor( + put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(org.springframework.http.HttpStatus.OK.value()))); + + deployActivitySpecs.deployActivities(); + verify(0, putRequestedFor(urlEqualTo(urlPath))); + } + } diff --git a/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java b/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java index aae5e5dc53..7a876a67a2 100644 --- a/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java +++ b/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java @@ -30,6 +30,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.asdc.activity.ActivitySpecsActions; import org.onap.so.asdc.activity.DeployActivitySpecs; @@ -54,6 +55,7 @@ public class DeployActivitySpecsTest { protected ActivitySpecsActions activitySpecsActions; @InjectMocks + @Spy private DeployActivitySpecs deployActivitySpecs; @Test @@ -68,7 +70,8 @@ public class DeployActivitySpecsTest { List<org.onap.so.db.catalog.beans.ActivitySpec> catalogActivitySpecList = new ArrayList<org.onap.so.db.catalog.beans.ActivitySpec>(); catalogActivitySpecList.add(catalogActivitySpec); - when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("testEndpoint"); + when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://testEndpoint"); + doReturn(true).when(deployActivitySpecs).checkHttpOk("http://testEndpoint"); when(activitySpecRepository.findAll()).thenReturn(catalogActivitySpecList); doReturn("testActivityId").when(activitySpecsActions).createActivitySpec(Mockito.any(), Mockito.any()); doReturn(true).when(activitySpecsActions).certifyActivitySpec(Mockito.any(), Mockito.any()); diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java index fc72f9bc6e..e1b124775b 100644 --- a/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java +++ b/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java @@ -51,11 +51,13 @@ import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator; import org.onap.so.asdc.client.test.emulators.NotificationDataImpl; import org.onap.so.db.catalog.beans.AllottedResource; import org.onap.so.db.catalog.beans.AllottedResourceCustomization; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; import org.onap.so.db.catalog.beans.NetworkResource; import org.onap.so.db.catalog.beans.NetworkResourceCustomization; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ToscaCsar; import org.onap.so.db.catalog.beans.Workflow; +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.NetworkResourceRepository; import org.onap.so.db.catalog.data.repository.ServiceRepository; @@ -77,6 +79,9 @@ public class ASDCRestInterfaceTest extends BaseTest { private AllottedResourceRepository allottedRepo; @Autowired + private AllottedResourceCustomizationRepository allottedCustomRepo; + + @Autowired private ServiceRepository serviceRepo; @Autowired @@ -148,7 +153,6 @@ public class ASDCRestInterfaceTest extends BaseTest { AllottedResourceCustomization arCustomization = new AllottedResourceCustomization(); arCustomization.setModelCustomizationUUID("f62bb612-c5d4-4406-865c-0abec30631ba"); arCustomization.setModelInstanceName("rege1802pnf 0"); - arCustomization.setResourceInput("{}"); arCustomizationSet.add(arCustomization); arCustomization.setAllottedResource(expectedService); diff --git a/asdc-controller/src/test/resources/schema.sql b/asdc-controller/src/test/resources/schema.sql index ad6b156956..f2c04802a5 100644 --- a/asdc-controller/src/test/resources/schema.sql +++ b/asdc-controller/src/test/resources/schema.sql @@ -1447,7 +1447,7 @@ CREATE TABLE `infra_active_requests` ( `VF_MODULE_NAME` varchar(200) DEFAULT NULL, `VF_MODULE_MODEL_NAME` varchar(200) DEFAULT NULL, `AAI_SERVICE_ID` varchar(50) DEFAULT NULL, - `AIC_CLOUD_REGION` varchar(11) DEFAULT NULL, + `CLOUD_REGION` varchar(11) DEFAULT NULL, `CALLBACK_URL` varchar(200) DEFAULT NULL, `CORRELATOR` varchar(80) DEFAULT NULL, `NETWORK_ID` varchar(45) DEFAULT NULL, @@ -1500,7 +1500,7 @@ CREATE TABLE `archived_infra_requests` ( `VF_MODULE_NAME` varchar(200) DEFAULT NULL, `VF_MODULE_MODEL_NAME` varchar(200) DEFAULT NULL, `AAI_SERVICE_ID` varchar(50) DEFAULT NULL, - `AIC_CLOUD_REGION` varchar(11) DEFAULT NULL, + `CLOUD_REGION` varchar(11) DEFAULT NULL, `CALLBACK_URL` varchar(200) DEFAULT NULL, `CORRELATOR` varchar(80) DEFAULT NULL, `NETWORK_ID` varchar(45) DEFAULT NULL, |