use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.
the class BBInputSetup method getGBBALaCarteNonService.
protected GeneralBuildingBlock getGBBALaCarteNonService(ExecuteBuildingBlock executeBB, RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId, String vnfType) throws Exception {
String bbName = executeBB.getBuildingBlock().getBpmnFlowName();
String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
ServiceModel serviceModel = new ServiceModel();
Service service = null;
Service newService = null;
boolean isReplace = false;
if (serviceInstanceId != null) {
aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
if (aaiServiceInstance != null) {
if (requestAction.equalsIgnoreCase("replaceInstance") || requestAction.equalsIgnoreCase("replaceInstanceRetainAssignments")) {
RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList();
if (relatedInstanceList != null) {
for (RelatedInstanceList relatedInstList : relatedInstanceList) {
RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
newService = bbInputSetupUtils.getCatalogServiceByModelUUID(relatedInstance.getModelInfo().getModelVersionId());
isReplace = true;
}
}
}
}
service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
serviceModel.setNewService(newService);
serviceModel.setCurrentService(service);
if (service == null) {
String message = String.format("Related service instance model not found in MSO CatalogDB: model-version-id=%s", aaiServiceInstance.getModelVersionId());
throw new ServiceModelNotFoundException(message);
} else if (newService == null && isReplace) {
String message = "Related service instance model in Request not found in MSO CatalogDB";
throw new ServiceModelNotFoundException(message);
}
} else {
String message = String.format("Related service instance from AAI not found: service-instance-id=%s", serviceInstanceId);
throw new NoServiceInstanceFoundException(message);
}
}
ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
if (isReplace) {
serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(serviceModel.getNewService()));
} else {
serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(serviceModel.getCurrentService()));
}
BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setRequestId(executeBB.getRequestId()).setRequestDetails(requestDetails).setService(service).setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).setResourceId(resourceId).setVnfType(vnfType).setKey(executeBB.getBuildingBlock().getKey()).setConfigurationResourceKeys(executeBB.getConfigurationResourceKeys()).setExecuteBB(executeBB).setRequestAction(requestAction).setIsReplace(isReplace).setServiceModel(serviceModel).build();
this.populateObjectsOnAssignAndCreateFlows(parameter);
return this.populateGBBWithSIAndAdditionalInfo(parameter);
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.
the class BBInputSetup method getGBBMacroExistingService.
protected GeneralBuildingBlock getGBBMacroExistingService(ExecuteBuildingBlock executeBB, Map<ResourceKey, String> lookupKeyMap, String bbName, String requestAction, CloudConfiguration cloudConfiguration) throws Exception {
org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
RequestDetails requestDetails = executeBB.getRequestDetails();
BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setExecuteBB(executeBB).setLookupKeyMap(lookupKeyMap).setBbName(bbName).setRequestAction(requestAction).setCloudConfiguration(cloudConfiguration).setRequestDetails(requestDetails).setResourceId(serviceInstanceId).build();
GeneralBuildingBlock gBB = null;
Service service = null;
if (serviceInstanceId != null) {
aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
if (aaiServiceInstance != null) {
String modelVersionId = aaiServiceInstance.getModelVersionId();
if ("upgradeInstance".equalsIgnoreCase(requestAction)) {
modelVersionId = requestDetails.getModelInfo().getModelVersionId();
}
service = bbInputSetupUtils.getCatalogServiceByModelUUID(modelVersionId);
if (service == null) {
String message = String.format("Related service instance model not found in MSO CatalogDB: model-version-id=%s", aaiServiceInstance.getModelVersionId());
throw new ServiceModelNotFoundException(message);
}
} else {
String message = String.format("Related service instance from AAI not found: service-instance-id=%s", serviceInstanceId);
throw new NoServiceInstanceFoundException(message);
}
}
ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
parameter.setServiceInstance(serviceInstance);
gBB = populateGBBWithSIAndAdditionalInfo(parameter);
serviceInstance = gBB.getServiceInstance();
CloudRegion cloudRegion = null;
if (cloudConfiguration == null) {
Optional<CloudRegion> cloudRegionOp = cloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance);
if (cloudRegionOp.isPresent()) {
cloudRegion = cloudRegionOp.get();
}
}
if (cloudConfiguration != null) {
org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration);
cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion);
}
gBB.setCloudRegion(cloudRegion);
if (bbName.contains(VNF) || (bbName.contains(CONTROLLER) && (VNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
for (GenericVnf genericVnf : serviceInstance.getVnfs()) {
if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null && genericVnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
org.onap.aai.domain.yang.GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(genericVnf.getVnfId());
ModelInfo modelInfo = new ModelInfo();
if (vnf != null) {
modelInfo.setModelCustomizationUuid(vnf.getModelCustomizationId());
}
this.mapCatalogVnf(genericVnf, modelInfo, service);
}
}
} else if (bbName.contains(VF_MODULE) || (bbName.contains(CONTROLLER) && (VF_MODULE).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
for (GenericVnf vnf : serviceInstance.getVnfs()) {
for (VfModule vfModule : vnf.getVfModules()) {
if (lookupKeyMap.get(ResourceKey.VF_MODULE_ID) != null && vfModule.getVfModuleId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VF_MODULE_ID))) {
String vnfModelCustomizationUUID = this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()).getModelCustomizationId();
ModelInfo vnfModelInfo = new ModelInfo();
vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
this.mapCatalogVnf(vnf, vnfModelInfo, service);
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnf.getVnfId());
String vfModuleCustomizationUUID = this.bbInputSetupUtils.getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()).getModelCustomizationId();
ModelInfo vfModuleModelInfo = new ModelInfo();
vfModuleModelInfo.setModelCustomizationId(vfModuleCustomizationUUID);
this.mapCatalogVfModule(vfModule, vfModuleModelInfo, service, vnfModelCustomizationUUID);
if (cloudRegion != null) {
Optional<String> volumeGroupIdOp = getVolumeGroupIdRelatedToVfModule(vnf, vfModuleModelInfo, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), lookupKeyMap);
if (volumeGroupIdOp.isPresent()) {
lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupIdOp.get());
}
}
if (vfModule.getModelInfoVfModule() != null && vfModule.getModelInfoVfModule().getModelName() != null && vfModule.getModelInfoVfModule().getModelName().contains("helm")) {
gBB.getRequestContext().setIsHelm(true);
}
break;
}
}
}
} else if (bbName.contains(VOLUME_GROUP)) {
for (GenericVnf vnf : serviceInstance.getVnfs()) {
for (VolumeGroup volumeGroup : vnf.getVolumeGroups()) {
if (lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID) != null && volumeGroup.getVolumeGroupId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID))) {
String vnfModelCustomizationUUID = this.bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()).getModelCustomizationId();
ModelInfo vnfModelInfo = new ModelInfo();
vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
this.mapCatalogVnf(vnf, vnfModelInfo, service);
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnf.getVnfId());
if (cloudRegion != null) {
String volumeGroupCustomizationUUID = this.bbInputSetupUtils.getAAIVolumeGroup(cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId()).getModelCustomizationId();
ModelInfo volumeGroupModelInfo = new ModelInfo();
volumeGroupModelInfo.setModelCustomizationId(volumeGroupCustomizationUUID);
this.mapCatalogVolumeGroup(volumeGroup, volumeGroupModelInfo, service, vnfModelCustomizationUUID);
}
break;
}
}
}
} else if (bbName.contains(NETWORK)) {
for (L3Network network : serviceInstance.getNetworks()) {
if (lookupKeyMap.get(ResourceKey.NETWORK_ID) != null && network.getNetworkId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.NETWORK_ID))) {
String networkCustomizationUUID = this.bbInputSetupUtils.getAAIL3Network(network.getNetworkId()).getModelCustomizationId();
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelCustomizationUuid(networkCustomizationUUID);
this.mapCatalogNetwork(network, modelInfo, service);
break;
}
}
} else if (bbName.contains("Fabric")) {
for (Configuration configuration : serviceInstance.getConfigurations()) {
if (lookupKeyMap.get(ResourceKey.CONFIGURATION_ID) != null && configuration.getConfigurationId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID))) {
String configurationCustUUID = this.bbInputSetupUtils.getAAIConfiguration(configuration.getConfigurationId()).getModelCustomizationId();
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelCustomizationUuid(configurationCustUUID);
this.mapCatalogConfiguration(configuration, modelInfo, service, executeBB.getConfigurationResourceKeys());
break;
}
}
} else if (bbName.equals("HealthCheckBB") && (VNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope())) {
this.setisHelmforHealthCheckBB(service, serviceInstance, gBB);
}
if (executeBB.getWorkflowResourceIds() != null) {
parameter.setResourceId(executeBB.getWorkflowResourceIds().getNetworkCollectionId());
parameter.setKey(executeBB.getBuildingBlock().getKey());
this.populateNetworkCollectionAndInstanceGroupAssign(parameter);
}
return gBB;
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.
the class BBInputSetup method getServiceProxy.
protected ServiceProxy getServiceProxy(Service service) {
if (!service.getServiceProxyCustomizations().isEmpty()) {
ServiceProxyResourceCustomization serviceProxyCatalog = getServiceProxyResourceCustomization(service);
ServiceProxy serviceProxy = new ServiceProxy();
serviceProxy.setModelInfoServiceProxy(mapperLayer.mapServiceProxyCustomizationToServiceProxy(serviceProxyCatalog));
Service sourceService = serviceProxyCatalog.getSourceService();
ServiceInstance sourceServiceShell = new ServiceInstance();
sourceServiceShell.setModelInfoServiceInstance(mapperLayer.mapCatalogServiceIntoServiceInstance(sourceService));
serviceProxy.setServiceInstance(sourceServiceShell);
serviceProxy.setType(sourceService.getServiceType());
return serviceProxy;
} else {
return null;
}
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.
the class BBInputSetup method getGBBMacroUserParams.
protected GeneralBuildingBlock getGBBMacroUserParams(ExecuteBuildingBlock executeBB, RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String vnfType, String bbName, String key, GeneralBuildingBlock gBB, RequestParameters requestParams, Service service, String input) throws Exception {
ServiceInstance serviceInstance = gBB.getServiceInstance();
org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue(input, org.onap.so.serviceinstancebeans.Service.class);
Resources resources = serviceMacro.getResources();
Vnfs vnfs = null;
VfModules vfModules = null;
Networks networks = null;
CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
CloudRegion cloudRegion = setCloudConfiguration(gBB, cloudConfiguration);
BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setRequestId(executeBB.getRequestId()).setService(service).setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).build();
if (bbName.contains(VNF) || (bbName.contains(CONTROLLER) && (VNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String vnfInstanceName = lookupKeyMap.get(ResourceKey.VNF_INSTANCE_NAME);
if (StringUtils.isNotBlank(vnfInstanceName)) {
vnfs = findVnfsByInstanceName(vnfInstanceName, resources);
} else {
vnfs = findVnfsByKey(key, resources);
}
// Vnf level cloud configuration takes precedence over service level cloud configuration.
if (vnfs.getCloudConfiguration() != null) {
setCloudConfiguration(gBB, vnfs.getCloudConfiguration());
}
String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
// This stores the vnf id in request db to be retrieved later when
// working on a vf module or volume group
InfraActiveRequests request = this.bbInputSetupUtils.getInfraActiveRequest(executeBB.getRequestId());
if (request != null) {
this.bbInputSetupUtils.updateInfraActiveRequestVnfId(request, vnfId);
}
parameter.setModelInfo(vnfs.getModelInfo());
parameter.setInstanceName(vnfs.getInstanceName());
parameter.setPlatform(vnfs.getPlatform());
parameter.setLineOfBusiness(vnfs.getLineOfBusiness());
parameter.setResourceId(vnfId);
parameter.setVnfType(vnfType);
parameter.setInstanceParams(vnfs.getInstanceParams());
parameter.setProductFamilyId(requestDetails.getRequestInfo().getProductFamilyId());
String applicationId = "";
if (vnfs.getApplicationId() != null) {
applicationId = vnfs.getApplicationId();
}
parameter.setApplicationId(applicationId);
this.populateGenericVnf(parameter);
} else if (bbName.contains(PNF) || (bbName.contains(CONTROLLER) && (PNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String pnfId = lookupKeyMap.get(ResourceKey.PNF);
resources.getPnfs().stream().filter(pnfs -> Objects.equals(key, pnfs.getModelInfo().getModelCustomizationId())).findFirst().ifPresent(pnfs -> BBInputSetupPnf.populatePnfToServiceInstance(pnfs, pnfId, serviceInstance));
} else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP) || (bbName.contains(CONTROLLER) && (VF_MODULE).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String vfModuleInstanceName = lookupKeyMap.get(ResourceKey.VF_MODULE_INSTANCE_NAME);
if (StringUtils.isNotBlank(vfModuleInstanceName)) {
vfModules = getVfModulesByInstanceName(vfModuleInstanceName, resources);
} else {
vfModules = getVfModulesByKey(key, resources);
}
String vfModulesName = vfModules.getInstanceName();
String vfModulesModelCustId = vfModules.getModelInfo().getModelCustomizationId();
// Get the Vnf associated with vfModule
Optional<org.onap.so.serviceinstancebeans.Vnfs> parentVnf = resources.getVnfs().stream().filter(aVnf -> aVnf.getCloudConfiguration() != null).filter(aVnf -> aVnf.getVfModules().stream().anyMatch(aVfModules -> aVfModules.getInstanceName().equals(vfModulesName) && aVfModules.getModelInfo().getModelCustomizationId().equals(vfModulesModelCustId))).findAny();
// Get the cloud configuration from this Vnf
if (parentVnf.isPresent()) {
cloudRegion = setCloudConfiguration(gBB, parentVnf.get().getCloudConfiguration());
}
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, getVnfId(executeBB, lookupKeyMap));
parameter.setModelInfo(vfModules.getModelInfo());
if (bbName.contains(VOLUME_GROUP)) {
parameter.setResourceId(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID));
parameter.setInstanceName(vfModules.getVolumeGroupInstanceName());
parameter.setVnfType(vnfType);
parameter.setInstanceParams(vfModules.getInstanceParams());
ServiceModel serviceModel = new ServiceModel();
serviceModel.setCurrentService(service);
parameter.setServiceModel(serviceModel);
this.populateVolumeGroup(parameter);
} else {
parameter.setResourceId(lookupKeyMap.get(ResourceKey.VF_MODULE_ID));
CloudConfiguration cloudConfig = new CloudConfiguration();
cloudConfig.setLcpCloudRegionId(cloudRegion.getLcpCloudRegionId());
cloudConfig.setCloudOwner(cloudRegion.getCloudOwner());
ServiceModel serviceModel = new ServiceModel();
serviceModel.setCurrentService(service);
parameter.setServiceModel(serviceModel);
parameter.setCloudConfiguration(cloudConfig);
parameter.setInstanceName(vfModules.getInstanceName());
parameter.setInstanceParams(vfModules.getInstanceParams());
this.populateVfModule(parameter);
gBB.getRequestContext().setIsHelm(parameter.getIsHelm());
}
} else if (bbName.contains(NETWORK)) {
networks = findNetworksByKey(key, resources);
String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
if (networks != null) {
// If service level cloud configuration is not provided then get it from networks.
if (cloudConfiguration == null) {
Optional<org.onap.so.serviceinstancebeans.Networks> netWithCloudConfig = resources.getNetworks().stream().filter(aNetwork -> aNetwork.getCloudConfiguration() != null).findAny();
if (netWithCloudConfig.isPresent()) {
setCloudConfiguration(gBB, netWithCloudConfig.get().getCloudConfiguration());
} else {
logger.debug("Could not find any cloud configuration for this request.");
}
}
parameter.setInstanceName(networks.getInstanceName());
parameter.setModelInfo(networks.getModelInfo());
parameter.setInstanceParams(networks.getInstanceParams());
parameter.setResourceId(networkId);
this.populateL3Network(parameter);
}
} else if (bbName.contains("Configuration")) {
String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
ModelInfo configurationModelInfo = new ModelInfo();
configurationModelInfo.setModelCustomizationUuid(key);
ConfigurationResourceCustomization configurationCust = findConfigurationResourceCustomization(configurationModelInfo, service);
if (configurationCust != null) {
parameter.setModelInfo(configurationModelInfo);
parameter.setResourceId(configurationId);
parameter.setConfigurationResourceKeys(executeBB.getConfigurationResourceKeys());
parameter.setRequestDetails(executeBB.getRequestDetails());
this.populateConfiguration(parameter);
} else {
logger.debug("Could not find a configuration customization with key: {}", key);
}
}
return gBB;
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.
the class ServiceTopologyOperationMapperTest method reqMapperTest.
@Test
public void reqMapperTest() throws Exception {
// prepare and set service instance
ServiceInstance serviceInstance = new ServiceInstance();
ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid");
modelInfoServiceInstance.setModelName("modelName");
modelInfoServiceInstance.setModelUuid("modelUuid");
modelInfoServiceInstance.setModelVersion("modelVersion");
serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
// prepare Customer object
Customer customer = new Customer();
customer.setGlobalCustomerId("globalCustomerId");
customer.setServiceSubscription(new ServiceSubscription());
// set Customer on service instance
customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
// prepare RequestContext
RequestContext requestContext = new RequestContext();
Map<String, Object> userParams = new HashMap<>();
userParams.put("key1", "value1");
requestContext.setUserParams(userParams);
requestContext.setProductFamilyId("productFamilyId");
requestContext.setMsoRequestId("MsoRequestId");
GenericResourceApiServiceOperationInformation serviceOpInformation = mapper.reqMapper(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, requestContext);
GenericResourceApiServiceOperationInformation serviceOpInformationNullReqContext = mapper.reqMapper(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, null);
String jsonToCompare = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/BuildingBlocks/genericResourceApiEcompModelInformation.json")));
ObjectMapper omapper = new ObjectMapper();
GenericResourceApiOnapmodelinformationOnapModelInformation reqMapper1 = omapper.readValue(jsonToCompare, GenericResourceApiOnapmodelinformationOnapModelInformation.class);
assertThat(reqMapper1, sameBeanAs(serviceOpInformation.getServiceInformation().getOnapModelInformation()));
assertEquals("MsoRequestId", serviceOpInformation.getRequestInformation().getRequestId());
assertNotNull(serviceOpInformationNullReqContext.getRequestInformation().getRequestId());
}
Aggregations