From feb3f66334092f8d28cdba41450d0a11970319de Mon Sep 17 00:00:00 2001 From: "Kalkere Ramesh, Sharan (sk720x)" Date: Thu, 6 Dec 2018 14:11:29 -0500 Subject: creating relationships vnf and tenant Change-Id: I515fc40c7924c2fdb3f0bc4dd3a620eb0a3bf948 Issue-ID: SO-1284 Signed-off-by: Kalkere Ramesh, Sharan (sk720x) --- .../servicedecomposition/tasks/BBInputSetup.java | 15 +++- .../tasks/CloudInfoFromAAI.java | 93 ++++++++++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAI.java (limited to 'bpmn/MSOCommonBPMN/src/main') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 7edf39df14..c0f1c48b76 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -90,6 +90,7 @@ import org.onap.so.serviceinstancebeans.Vnfs; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -112,6 +113,9 @@ public class BBInputSetup implements JavaDelegate { @Autowired private BBInputSetupMapperLayer mapperLayer; + + @Autowired + private CloudInfoFromAAI bbInputSetupHelper; @Autowired private ExceptionBuilder exceptionUtil; @@ -981,11 +985,18 @@ public class BBInputSetup implements JavaDelegate { Map lookupKeyMap, String bbName, GeneralBuildingBlock gBB, Service service, String requestAction, CloudConfiguration cloudConfiguration) throws Exception { ServiceInstance serviceInstance = gBB.getServiceInstance(); + CloudRegion cloudRegion = null; + if(cloudConfiguration == null) { + Optional cloudRegionOp = bbInputSetupHelper.getCloudInfoFromAAI(serviceInstance); + if(cloudRegionOp.isPresent()) { + cloudRegion = cloudRegionOp.get(); + } + } if (cloudConfiguration != null && requestAction.equalsIgnoreCase("deleteInstance")) { org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration); - CloudRegion cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion); - gBB.setCloudRegion(cloudRegion); + cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion); } + gBB.setCloudRegion(cloudRegion); if (bbName.contains(VNF)) { for (GenericVnf genericVnf : serviceInstance.getVnfs()) { if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAI.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAI.java new file mode 100644 index 0000000000..37088022bc --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAI.java @@ -0,0 +1,93 @@ +package org.onap.so.bpmn.servicedecomposition.tasks; + +import java.util.List; +import java.util.Optional; + +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.core.JsonProcessingException; + +@Component +public class CloudInfoFromAAI { + + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CloudInfoFromAAI.class); + @Autowired + private BBInputSetupUtils bbInputSetupUtils; + + public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { + this.bbInputSetupUtils = bbInputSetupUtils; + } + + protected Optional getCloudInfoFromAAI(ServiceInstance serviceInstance) throws JsonProcessingException { + Optional relationshipsOp = Optional.empty(); + if(!serviceInstance.getVnfs().isEmpty()) { + GenericVnf vnf = serviceInstance.getVnfs().get(0); + org.onap.aai.domain.yang.GenericVnf aaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()); + AAIResultWrapper vnfWrapper = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVnf)); + relationshipsOp = getRelationshipsFromWrapper(vnfWrapper); + } else if(!serviceInstance.getNetworks().isEmpty()) { + L3Network network = serviceInstance.getNetworks().get(0); + org.onap.aai.domain.yang.L3Network aaiL3Network = bbInputSetupUtils.getAAIL3Network(network.getNetworkId()); + AAIResultWrapper networkWrapper = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiL3Network)); + relationshipsOp = getRelationshipsFromWrapper(networkWrapper); + } else { + msoLogger.debug("BBInputSetup could not find a cloud region or tenant, since there are no resources under the SI."); + return Optional.empty(); + } + if (relationshipsOp.isPresent()) { + return getRelatedCloudRegionAndTenant(relationshipsOp.get()); + } else { + msoLogger.debug("BBInputSetup could not find a cloud region or tenant"); + return Optional.empty(); + } + } + + protected Optional getRelationshipsFromWrapper(AAIResultWrapper wrapper) { + Optional relationshipsOp; + relationshipsOp = wrapper.getRelationships(); + if(relationshipsOp.isPresent()) { + return relationshipsOp; + } + return Optional.empty(); + } + + protected Optional getRelatedCloudRegionAndTenant(Relationships relationships) { + CloudRegion cloudRegion = new CloudRegion(); + List cloudRegions = relationships.getByType(AAIObjectType.CLOUD_REGION); + List tenants = relationships.getByType(AAIObjectType.TENANT); + if(!cloudRegions.isEmpty()) { + AAIResultWrapper cloudRegionWrapper = cloudRegions.get(0); + Optional aaiCloudRegionOp = cloudRegionWrapper + .asBean(org.onap.aai.domain.yang.CloudRegion.class); + if(aaiCloudRegionOp.isPresent()) { + org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = aaiCloudRegionOp.get(); + cloudRegion.setCloudOwner(aaiCloudRegion.getCloudOwner()); + cloudRegion.setCloudRegionVersion(aaiCloudRegion.getCloudRegionVersion()); + cloudRegion.setLcpCloudRegionId(aaiCloudRegion.getCloudRegionId()); + cloudRegion.setComplex(aaiCloudRegion.getComplexName()); + } + } + if(!tenants.isEmpty()) { + AAIResultWrapper tenantWrapper = tenants.get(0); + Optional aaiTenantOp = tenantWrapper + .asBean(org.onap.aai.domain.yang.Tenant.class); + if(aaiTenantOp.isPresent()) { + org.onap.aai.domain.yang.Tenant aaiTenant = aaiTenantOp.get(); + cloudRegion.setTenantId(aaiTenant.getTenantId()); + } + } + return Optional.of(cloudRegion); + } +} -- cgit 1.2.3-korg