diff options
Diffstat (limited to 'adapters/mso-openstack-adapters/src/main/java')
11 files changed, 322 insertions, 255 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java index 489585c04b..b84d2a8600 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java @@ -31,6 +31,8 @@ import java.util.Map; import java.util.Optional; import javax.jws.WebService; import javax.xml.ws.Holder; +import org.apache.commons.lang3.mutable.MutableBoolean; +import org.onap.logging.filter.base.ErrorCode; import org.onap.so.adapters.network.beans.ContrailPolicyRef; import org.onap.so.adapters.network.beans.ContrailPolicyRefSeq; import org.onap.so.adapters.network.beans.ContrailSubnet; @@ -47,7 +49,6 @@ import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationReposi import org.onap.so.db.catalog.data.repository.NetworkResourceRepository; import org.onap.so.db.catalog.utils.MavenLikeVersioning; import org.onap.so.entity.MsoRequest; -import org.onap.logging.filter.base.ErrorCode; import org.onap.so.logger.LoggingAnchor; import org.onap.so.logger.MessageEnum; import org.onap.so.openstack.beans.HeatStatus; @@ -150,7 +151,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { Holder<String> networkFqdn = new Holder<>(); createNetwork(cloudSiteId, tenantId, networkType, modelCustomizationUuid, networkName, physicalNetworkName, vlans, null, shared, external, failIfExists, backout, subnets, null, null, msoRequest, networkId, - neutronNetworkId, networkFqdn, subnetIdMap, rollback, true); + neutronNetworkId, networkFqdn, subnetIdMap, rollback, true, new MutableBoolean()); } @Deprecated @@ -164,7 +165,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { throws NetworkException { createNetwork(cloudSiteId, tenantId, networkType, modelCustomizationUuid, networkName, null, null, routeTargets, shared, external, failIfExists, backout, subnets, policyFqdns, routeTableFqdns, msoRequest, networkId, - neutronNetworkId, networkFqdn, subnetIdMap, rollback, true); + neutronNetworkId, networkFqdn, subnetIdMap, rollback, true, new MutableBoolean()); } /** @@ -195,13 +196,14 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { String shared, String external, Boolean failIfExists, Boolean backout, List<Subnet> subnets, List<String> policyFqdns, List<String> routeTableFqdns, MsoRequest msoRequest, Holder<String> networkId, Holder<String> neutronNetworkId, Holder<String> networkFqdn, Holder<Map<String, String>> subnetIdMap, - Holder<NetworkRollback> rollback, Boolean pollForCompletion) throws NetworkException { + Holder<NetworkRollback> rollback, Boolean pollForCompletion, MutableBoolean isOs3Nw) + throws NetworkException { logger.debug("*** CREATE Network: {} of type {} in {}/{}", networkName, networkType, cloudSiteId, tenantId); // Will capture execution time for metrics long startTime = System.currentTimeMillis(); - // Build a default rollback object (no actions performed) + // Build a default rollback object (no actions performed) //TODO remove NetworkRollback networkRollback = new NetworkRollback(); networkRollback.setCloudId(cloudSiteId); networkRollback.setTenantId(tenantId); @@ -241,13 +243,13 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { template = template.replaceAll("\r\n", "\n"); boolean os3template = false; - String os3nw = OS3_NW; - os3nw = environment.getProperty(OS3_NW_PROPERTY, OS3_NW); + String os3nw = environment.getProperty(OS3_NW_PROPERTY, OS3_NW); if (template.contains(os3nw)) os3template = true; + isOs3Nw.setValue(os3template); // First, look up to see if the Network already exists (by name). // For HEAT orchestration of networks, the stack name will always match the network name StackInfo heatStack = null; @@ -280,20 +282,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { } Map<String, Object> outputs = heatStack.getOutputs(); - for (Map.Entry<String, Object> entry : outputs.entrySet()) { - String key = entry.getKey(); - if (key != null && key.startsWith("subnet")) { - if (os3template) // one subnet_id output - { - Map<String, String> map = getSubnetUUId(key, outputs, subnets); - sMap.putAll(map); - } else // multiples subnet_%aaid% outputs - { - String subnetUUId = (String) outputs.get(key); - sMap.put(key.substring("subnet_id_".length()), subnetUUId); - } - } - } + sMap = buildSubnetMap(outputs, subnets, os3template); } subnetIdMap.value = sMap; logger.warn("{} {} Found Existing network stack, status={} networkName={} for {}/{}", @@ -390,20 +379,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { Map<String, Object> outputs = heatStack.getOutputs(); Map<String, String> sMap = new HashMap<>(); if (outputs != null) { - for (Map.Entry<String, Object> entry : outputs.entrySet()) { - String key = entry.getKey(); - if (key != null && key.startsWith("subnet")) { - if (os3template) // one subnet output expected - { - Map<String, String> map = getSubnetUUId(key, outputs, subnets); - sMap.putAll(map); - } else // multiples subnet_%aaid% outputs allowed - { - String subnetUUId = (String) outputs.get(key); - sMap.put(key.substring("subnet_id_".length()), subnetUUId); - } - } - } + sMap = buildSubnetMap(outputs, subnets, os3template); networkRollback.setNeutronNetworkId((String) outputs.get(NETWORK_ID)); } subnetIdMap.value = sMap; @@ -686,20 +662,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { Map<String, Object> outputs = heatStack.getOutputs(); Map<String, String> sMap = new HashMap<>(); if (outputs != null) { - for (Map.Entry<String, Object> entry : outputs.entrySet()) { - String key = entry.getKey(); - if (key != null && key.startsWith("subnet")) { - if (os3template) // one subnet output expected - { - Map<String, String> map = getSubnetUUId(key, outputs, subnets); - sMap.putAll(map); - } else // multiples subnet_%aaid% outputs allowed - { - String subnetUUId = (String) outputs.get(key); - sMap.put(key.substring("subnet_id_".length()), subnetUUId); - } - } - } + sMap = buildSubnetMap(outputs, subnets, os3template); } subnetIdMap.value = sMap; @@ -962,31 +925,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { pollForCompletion = true; } - // Retrieve the Network Resource definition - NetworkResource networkResource = null; - if (commonUtils.isNullOrEmpty(modelCustomizationUuid)) { - if (!commonUtils.isNullOrEmpty(networkType)) { - networkResource = networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType); - } - } else { - NetworkResourceCustomization nrc = - networkCustomRepo.findOneByModelCustomizationUUID(modelCustomizationUuid); - if (nrc != null) { - networkResource = nrc.getNetworkResource(); - } - } - - int timeoutMinutes = 118; - if (networkResource != null) { - logger.debug(LOG_DEBUG_MSG, networkResource.toString()); - networkResource.getHeatTemplate().getTimeoutMinutes(); - HeatTemplate heat = networkResource.getHeatTemplate(); - if (heat != null && heat.getTimeoutMinutes() != null) { - if (heat.getTimeoutMinutes() < 118) { - timeoutMinutes = heat.getTimeoutMinutes(); - } - } - } + int timeoutMinutes = heat.getNetworkHeatTimeoutValue(modelCustomizationUuid, networkType); try { StackInfo stack = @@ -1385,7 +1324,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { return heatTemplate; } - private Map<String, String> getSubnetUUId(String key, Map<String, Object> outputs, List<Subnet> subnets) { + // TODO remove + public Map<String, String> getSubnetUUId(String key, Map<String, Object> outputs, List<Subnet> subnets) { Map<String, String> sMap = new HashMap<>(); @@ -1442,4 +1382,24 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { return updatedTemplate; } + public Map<String, String> buildSubnetMap(Map<String, Object> outputs, List<Subnet> subnets, boolean os3template) { + + Map<String, String> sMap = new HashMap<>(); + for (Map.Entry<String, Object> entry : outputs.entrySet()) { + String key = entry.getKey(); + if (key != null && key.startsWith("subnet")) { + if (os3template) // one subnet_id output + { + Map<String, String> map = getSubnetUUId(key, outputs, subnets); + sMap.putAll(map); + } else // multiples subnet_%aaid% outputs + { + String subnetUUId = (String) outputs.get(key); + sMap.put(key.substring("subnet_id_".length()), subnetUUId); + } + } + } + return sMap; + } + } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java index 12e416f43c..cd32cc208a 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/AaiClientPropertiesImpl.java @@ -24,6 +24,7 @@ import java.net.MalformedURLException; import java.net.URL; import org.onap.aaiclient.client.aai.AAIProperties; import org.onap.aaiclient.client.aai.AAIVersion; +import org.onap.so.client.CacheProperties; import org.onap.so.spring.SpringContextHelper; import org.springframework.context.ApplicationContext; @@ -32,6 +33,9 @@ public class AaiClientPropertiesImpl implements AAIProperties { private String aaiEndpoint; private String auth; private String key; + private Long readTimeout; + private boolean enableCaching; + private Long cacheMaxAge; private static final String SYSTEM_NAME = "MSO"; public AaiClientPropertiesImpl() { @@ -39,6 +43,9 @@ public class AaiClientPropertiesImpl implements AAIProperties { aaiEndpoint = context.getEnvironment().getProperty("aai.endpoint"); this.auth = context.getEnvironment().getProperty("aai.auth"); this.key = context.getEnvironment().getProperty("mso.msoKey"); + this.readTimeout = context.getEnvironment().getProperty("aai.readTimeout", Long.class, new Long(60000)); + this.enableCaching = context.getEnvironment().getProperty("aai.caching.enabled", Boolean.class, false); + this.cacheMaxAge = context.getEnvironment().getProperty("aai.caching.maxAge", Long.class, 60000L); } @Override @@ -65,4 +72,24 @@ public class AaiClientPropertiesImpl implements AAIProperties { public String getKey() { return this.key; } + + @Override + public Long getReadTimeout() { + return this.readTimeout; + } + + @Override + public boolean isCachingEnabled() { + return this.enableCaching; + } + + @Override + public CacheProperties getCacheProperties() { + return new AAICacheProperties() { + @Override + public Long getMaxAge() { + return cacheMaxAge; + } + }; + } } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java index 4e0c4ad8a6..bd71474aab 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/TaskServices.java @@ -28,8 +28,6 @@ import org.onap.so.adapters.tasks.orchestration.PollService; import org.onap.so.adapters.tasks.orchestration.RollbackService; import org.onap.so.adapters.tasks.orchestration.StackService; import org.onap.so.utils.ExternalTaskServiceUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -38,8 +36,6 @@ import org.springframework.stereotype.Component; @Profile("!test") public class TaskServices { - private static final Logger logger = LoggerFactory.getLogger(TaskServices.class); - @Autowired private ExternalTaskServiceUtils externalTaskServiceUtils; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java index 14d0b0afc4..0dd7635506 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java @@ -70,9 +70,7 @@ public class CreateAAIInventory { List<String> oobMgtNetNames = new ArrayList<>(); - HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity, - cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(), - cloudInformation.getTenantId(), cloudInformation.getNodeType()); + HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation); heatBridgeClient.authenticate(); @@ -128,6 +126,12 @@ public class CreateAAIInventory { heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false)); } + public HeatBridgeApi createClient(AAIResourcesClient client, CloudSite cloudSite, CloudIdentity cloudIdentity, + CloudInformation cloudInformation) { + return new HeatBridgeImpl(client, cloudIdentity, cloudInformation.getOwner(), cloudInformation.getRegionId(), + cloudSite.getRegionId(), cloudInformation.getTenantId(), cloudInformation.getNodeType()); + } + protected AAIResourcesClient getAaiClient() { if (aaiClient == null) return new AAIResourcesClient(); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteAAIInventory.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteAAIInventory.java index f5a6355529..f9bbf4a75d 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteAAIInventory.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteAAIInventory.java @@ -48,18 +48,28 @@ public class DeleteAAIInventory { @Autowired protected Environment env; + private static final String MULTICLOUD_MODE = "MULTICLOUD"; + public void heatbridge(CloudInformation cloudInformation) throws MsoCloudSiteNotFound, HeatBridgeException { logger.debug("Heatbridge delete executing"); CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId()) .orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId())); + if (cloudSite.getOrchestrator() != null && MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.getOrchestrator())) { + logger.debug("Skipping Heatbridge as CloudSite orchestrator is: " + MULTICLOUD_MODE); + return; + } CloudIdentity cloudIdentity = cloudSite.getIdentityService(); - HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity, - cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(), - cloudInformation.getTenantId(), cloudInformation.getNodeType()); + HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation); heatBridgeClient.authenticate(); heatBridgeClient.deleteVfModuleData(cloudInformation.getVnfId(), cloudInformation.getVfModuleId()); } + public HeatBridgeApi createClient(AAIResourcesClient client, CloudSite cloudSite, CloudIdentity cloudIdentity, + CloudInformation cloudInformation) { + return new HeatBridgeImpl(client, cloudIdentity, cloudInformation.getOwner(), cloudInformation.getRegionId(), + cloudSite.getRegionId(), cloudInformation.getTenantId(), cloudInformation.getNodeType()); + } + protected AAIResourcesClient getAaiClient() { if (aaiClient == null) return new AAIResourcesClient(); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/PollService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/PollService.java index c319fdc23c..14df4e6941 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/PollService.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/PollService.java @@ -33,16 +33,31 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.lang3.mutable.MutableBoolean; import org.camunda.bpm.client.task.ExternalTask; import org.camunda.bpm.client.task.ExternalTaskService; +import org.onap.so.adapters.network.MsoNetworkAdapterImpl; import org.onap.so.adapters.nwrest.CreateNetworkRequest; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.adapters.nwrest.DeleteNetworkRequest; +import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.adapters.nwrest.UpdateNetworkRequest; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; +import org.onap.so.adapters.vnf.MsoVnfAdapterImpl; +import org.onap.so.adapters.vnf.VnfAdapterUtils; import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; +import org.onap.so.adapters.vnfrest.CreateVfModuleResponse; import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse; import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; +import org.onap.so.adapters.vnfrest.DeleteVfModuleResponse; import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest; -import org.onap.so.adapters.nwrest.DeleteNetworkRequest; -import org.onap.so.adapters.nwrest.UpdateNetworkRequest; -import org.onap.so.adapters.vnf.VnfAdapterUtils; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.VfModuleRollback; +import org.onap.so.adapters.vnfrest.VolumeGroupRollback; import org.onap.so.logging.tasks.AuditMDCSetup; +import org.onap.so.openstack.beans.NetworkRollback; +import org.onap.so.openstack.beans.StackInfo; +import org.onap.so.openstack.beans.VnfRollback; import org.onap.so.openstack.exceptions.MsoException; +import org.onap.so.openstack.mappers.StackInfoMapper; import org.onap.so.openstack.utils.MsoHeatUtils; import org.onap.so.utils.ExternalTaskUtils; import org.onap.so.utils.RetrySequenceLevel; @@ -58,6 +73,12 @@ public class PollService extends ExternalTaskUtils { private static final Logger logger = LoggerFactory.getLogger(PollService.class); @Autowired + private MsoVnfAdapterImpl vnfAdapterImpl; + + @Autowired + private MsoNetworkAdapterImpl networkAdapterImpl; + + @Autowired private MsoHeatUtils msoHeatUtils; @Autowired @@ -76,43 +97,66 @@ public class PollService extends ExternalTaskUtils { Map<String, Object> variables = new HashMap<>(); MutableBoolean success = new MutableBoolean(); String errorMessage = null; + Optional<String> response = Optional.empty(); + boolean isMulticloud = false; try { String xmlRequest = externalTask.getVariable("openstackAdapterTaskRequest"); if (xmlRequest != null) { Optional<String> requestType = findRequestType(xmlRequest); if ("createVolumeGroupRequest".equals(requestType.get())) { - determineCreateVolumeGroupStatus(xmlRequest, externalTask, success); + CreateVolumeGroupRequest req = + JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class); + isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); + response = determineCreateVolumeGroupStatus(req, externalTask, success, isMulticloud); } else if ("createVfModuleRequest".equals(requestType.get())) { - determineCreateVfModuleStatus(xmlRequest, externalTask, success); + CreateVfModuleRequest req = + JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class); + isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); + response = determineCreateVfModuleStatus(req, externalTask, success, isMulticloud); } else if ("deleteVfModuleRequest".equals(requestType.get())) { logger.debug("Executing External Task Poll Service for Delete Vf Module"); + String stackId = externalTask.getVariable("stackId"); DeleteVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteVfModuleRequest.class); - boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); + isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); if (!isMulticloud) { - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); - } else { - success.setTrue(); + int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(req.getModelCustomizationUuid(), false); + StackInfo stack = pollDeleteResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), + stackId, success); + DeleteVfModuleResponse deleteResponse = + new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), Boolean.TRUE, + req.getMessageId(), vnfAdapterImpl.copyStringOutputs(stack.getOutputs())); + response = Optional.of(deleteResponse.toXmlString()); } } else if ("deleteVolumeGroupRequest".equals(requestType.get())) { logger.debug("Executing External Task Poll Service for Delete Volume Group"); + String stackId = externalTask.getVariable("stackId"); DeleteVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteVolumeGroupRequest.class); - boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); + isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); if (!isMulticloud) { - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); - } else { - success.setTrue(); + pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), stackId, success); + DeleteVolumeGroupResponse deleteResponse = + new DeleteVolumeGroupResponse(true, req.getMessageId()); + response = Optional.of(deleteResponse.toXmlString()); } } else if ("createNetworkRequest".equals(requestType.get())) { - determineCreateNetworkStatus(xmlRequest, externalTask, success); + CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class); + response = determineCreateNetworkStatus(req, externalTask, success); } else if ("deleteNetworkRequest".equals(requestType.get())) { logger.debug("Executing External Task Poll Service for Delete Network"); + String stackId = externalTask.getVariable("stackId"); DeleteNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteNetworkRequest.class); - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), stackId, success); + DeleteNetworkResponse deleteResponse = + new DeleteNetworkResponse(req.getNetworkId(), true, req.getMessageId()); + response = Optional.of(deleteResponse.toXmlString()); } else if ("updateNetworkRequest".equals(requestType.get())) { UpdateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), UpdateNetworkRequest.class); pollUpdateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + UpdateNetworkResponse updateResponse = + new UpdateNetworkResponse(req.getNetworkId(), null, null, req.getMessageId()); + response = Optional.of(updateResponse.toXmlString()); } } } catch (Exception e) { @@ -121,6 +165,12 @@ public class PollService extends ExternalTaskUtils { variables.put("openstackAdapterErrorMessage", errorMessage); } + if (isMulticloud) { + success.setTrue(); + } + if (response.isPresent()) { + variables.put("WorkflowResponse", response.get()); + } variables.put("OpenstackPollSuccess", success.booleanValue()); if (success.isTrue()) { externalTaskService.complete(externalTask, variables); @@ -144,72 +194,110 @@ public class PollService extends ExternalTaskUtils { } } - private void determineCreateVolumeGroupStatus(String xmlRequest, ExternalTask externalTask, MutableBoolean success) - throws MsoException { - CreateVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class); - boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); - if (!isMulticloud) { - boolean pollRollbackStatus = externalTask.getVariable("PollRollbackStatus"); - if (pollRollbackStatus) { - logger.debug("Executing External Task Poll Service for Rollback Create Volume Group"); - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); - } else { - pollCreateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + private Optional<String> determineCreateVolumeGroupStatus(CreateVolumeGroupRequest req, ExternalTask externalTask, + MutableBoolean success, boolean isMulticloud) throws MsoException { + boolean pollRollbackStatus = externalTask.getVariable("PollRollbackStatus"); + String stackId = externalTask.getVariable("stackId"); + if (pollRollbackStatus) { + logger.debug("Executing External Task Poll Service for Rollback Volume Group"); + if (!isMulticloud) { + pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), stackId, success); } + return Optional.empty(); } else { - success.setTrue(); + logger.debug("Executing External Task Poll Service for Create Volume Group"); + Map<String, String> outputs = new HashMap<String, String>(); + if (!isMulticloud) { + int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(req.getModelCustomizationUuid(), true); + StackInfo stack = + pollCreateResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success); + outputs = vnfAdapterImpl.copyStringOutputs(stack.getOutputs()); + } + VolumeGroupRollback rb = new VolumeGroupRollback(req.getVolumeGroupId(), stackId, true, req.getTenantId(), + req.getCloudOwner(), req.getCloudSiteId(), req.getMsoRequest(), req.getMessageId()); + CreateVolumeGroupResponse createResponse = new CreateVolumeGroupResponse(req.getVolumeGroupId(), stackId, + true, outputs, rb, req.getMessageId()); + return Optional.of(createResponse.toXmlString()); } } - private void determineCreateVfModuleStatus(String xmlRequest, ExternalTask externalTask, MutableBoolean success) - throws MsoException { - CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class); - boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); - if (!isMulticloud) { - boolean pollRollbackStatus = externalTask.getVariable("PollRollbackStatus"); - if (pollRollbackStatus) { - logger.debug("Executing External Task Poll Service for Rollback Create Vf Module"); - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); - } else { - logger.debug("Executing External Task Poll Service for Create Vf Module"); - pollCreateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + private Optional<String> determineCreateVfModuleStatus(CreateVfModuleRequest req, ExternalTask externalTask, + MutableBoolean success, boolean isMulticloud) throws MsoException { + String stackId = externalTask.getVariable("stackId"); + boolean pollRollbackStatus = externalTask.getVariable("PollRollbackStatus"); + int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(req.getModelCustomizationUuid(), false); + if (pollRollbackStatus) { + logger.debug("Executing External Task Poll Service for Rollback Vf Module"); + if (!isMulticloud) { + pollDeleteResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success); } + return Optional.empty(); } else { - success.setTrue(); + logger.debug("Executing External Task Poll Service for Create Vf Module"); + Map<String, String> outputs = new HashMap<String, String>(); + if (!isMulticloud) { + StackInfo stack = + pollCreateResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success); + outputs = vnfAdapterImpl.copyStringOutputs(stack.getOutputs()); + } + VfModuleRollback modRollback = new VfModuleRollback(buildVnfRollback(req, stackId, isMulticloud), + req.getVfModuleId(), stackId, req.getMessageId()); + CreateVfModuleResponse createResponse = new CreateVfModuleResponse(req.getVnfId(), req.getVfModuleId(), + stackId, Boolean.TRUE, outputs, modRollback, req.getMessageId()); + return Optional.of(createResponse.toXmlString()); } } - private void determineCreateNetworkStatus(String xmlRequest, ExternalTask externalTask, MutableBoolean success) - throws MsoException { - CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class); + private Optional<String> determineCreateNetworkStatus(CreateNetworkRequest req, ExternalTask externalTask, + MutableBoolean success) throws MsoException { + String stackId = externalTask.getVariable("stackId"); boolean pollRollbackStatus = externalTask.getVariable("PollRollbackStatus"); + int timeoutMinutes = + msoHeatUtils.getNetworkHeatTimeoutValue(req.getModelCustomizationUuid(), req.getNetworkType()); if (pollRollbackStatus) { - logger.debug("Executing External Task Poll Service for Rollback Create Network"); - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + logger.debug("Executing External Task Poll Service for Rollback Network"); + pollDeleteResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success); + return Optional.empty(); } else { logger.debug("Executing External Task Poll Service for Create Network"); - pollCreateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + boolean os3Nw = externalTask.getVariable("os3Nw"); + StackInfo stack = + pollCreateResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success); + String networkFqdn = ""; + String neutronNetworkId = ""; + Map<String, String> subnetMap = new HashMap<>(); + if (stack.getOutputs() != null) { + networkFqdn = (String) stack.getOutputs().get("network_fqdn"); + neutronNetworkId = (String) stack.getOutputs().get("network_id"); + subnetMap = networkAdapterImpl.buildSubnetMap(stack.getOutputs(), req.getSubnets(), os3Nw); + } + CreateNetworkResponse response = new CreateNetworkResponse(req.getNetworkId(), neutronNetworkId, stackId, + networkFqdn, true, subnetMap, buildNetworkRollback(req, stackId), req.getMessageId()); + return Optional.of(response.toXmlString()); + } } - private void pollCreateResource(String cloudSiteId, String tenantId, ExternalTask externalTask, + private StackInfo pollCreateResource(int pollingTimeout, String cloudSiteId, String tenantId, String stackId, MutableBoolean success) throws MsoException { - Stack currentStack = createCurrentStack(externalTask.getVariable("stackId")); - Stack stack = - msoHeatUtils.pollStackForStatus(1, currentStack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false); + Stack currentStack = createCurrentStack(stackId); + Stack stack = msoHeatUtils.pollStackForStatus(pollingTimeout, currentStack, "CREATE_IN_PROGRESS", cloudSiteId, + tenantId, false); msoHeatUtils.postProcessStackCreate(stack, false, 0, false, cloudSiteId, tenantId, null); success.setTrue(); + return new StackInfoMapper(stack).map(); } - private void pollDeleteResource(String cloudSiteId, String tenantId, ExternalTask externalTask, + private StackInfo pollDeleteResource(int pollingTimeout, String cloudSiteId, String tenantId, String stackId, MutableBoolean success) throws MsoException { - Stack currentStack = createCurrentStack(externalTask.getVariable("stackId")); - Stack stack = - msoHeatUtils.pollStackForStatus(1, currentStack, "DELETE_IN_PROGRESS", cloudSiteId, tenantId, true); + Stack currentStack = createCurrentStack(stackId); + Stack stack = msoHeatUtils.pollStackForStatus(pollingTimeout, currentStack, "DELETE_IN_PROGRESS", cloudSiteId, + tenantId, true); if (stack != null) { // if stack is null it was not found and no need to do post process msoHeatUtils.postProcessStackDelete(stack); } success.setTrue(); + return new StackInfoMapper(stack).map(); } private void pollUpdateResource(String cloudSiteId, String tenantId, ExternalTask externalTask, @@ -246,4 +334,36 @@ public class PollService extends ExternalTaskUtils { return currentStack; } + private VnfRollback buildVnfRollback(CreateVfModuleRequest req, String stackId, boolean isMulticloud) { + VnfRollback vfRollback = new VnfRollback(); + vfRollback.setCloudSiteId(req.getCloudSiteId()); + vfRollback.setCloudOwner(req.getCloudOwner()); + vfRollback.setTenantId(req.getTenantId()); + vfRollback.setMsoRequest(req.getMsoRequest()); + vfRollback.setRequestType(req.getRequestType()); + vfRollback.setVolumeGroupHeatStackId(req.getVolumeGroupStackId()); + vfRollback.setBaseGroupHeatStackId(req.getBaseVfModuleStackId()); + vfRollback.setIsBase(false); + vfRollback.setModelCustomizationUuid(req.getModelCustomizationUuid()); + vfRollback.setVnfId(stackId); + vfRollback.setVnfCreated(true); + if (isMulticloud) { + vfRollback.setMode("CFY"); + } + + return vfRollback; + } + + private NetworkRollback buildNetworkRollback(CreateNetworkRequest req, String stackId) { + NetworkRollback networkRollback = new NetworkRollback(); + networkRollback.setCloudId(req.getCloudSiteId()); + networkRollback.setTenantId(req.getTenantId()); + networkRollback.setMsoRequest(req.getMsoRequest()); + networkRollback.setModelCustomizationUuid(req.getModelCustomizationUuid()); + networkRollback.setNetworkStackId(stackId); + networkRollback.setNetworkCreated(true); + networkRollback.setNetworkType(req.getNetworkType()); + + return networkRollback; + } } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/StackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/StackService.java index 7be1620b0e..6b76c3af9a 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/StackService.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/StackService.java @@ -39,12 +39,9 @@ import org.onap.so.adapters.network.MsoNetworkAdapterImpl; import org.onap.so.adapters.network.exceptions.NetworkException; import org.onap.so.adapters.nwrest.ContrailNetwork; import org.onap.so.adapters.nwrest.CreateNetworkRequest; -import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; -import org.onap.so.adapters.nwrest.DeleteNetworkResponse; import org.onap.so.adapters.nwrest.ProviderVlanNetwork; import org.onap.so.adapters.nwrest.RollbackNetworkRequest; -import org.onap.so.adapters.nwrest.RollbackNetworkResponse; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.adapters.vnf.MsoVnfAdapterImpl; @@ -52,15 +49,9 @@ import org.onap.so.adapters.vnf.MsoVnfPluginAdapterImpl; import org.onap.so.adapters.vnf.VnfAdapterUtils; import org.onap.so.adapters.vnf.exceptions.VnfException; import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; -import org.onap.so.adapters.vnfrest.CreateVfModuleResponse; import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; -import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse; import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; -import org.onap.so.adapters.vnfrest.DeleteVfModuleResponse; import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest; -import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse; -import org.onap.so.adapters.vnfrest.VfModuleRollback; -import org.onap.so.adapters.vnfrest.VolumeGroupRollback; import org.onap.so.logging.tasks.AuditMDCSetup; import org.onap.so.openstack.beans.NetworkRollback; import org.onap.so.openstack.beans.RouteTarget; @@ -94,7 +85,6 @@ public class StackService extends ExternalTaskUtils { private static final String SHARED = "shared"; private static final String EXTERNAL = "external"; - // TODO set backout earlier in case of exception?? public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) { Map<String, Object> variables = new HashMap<>(); mdcSetup.setupMDC(externalTask); @@ -102,7 +92,7 @@ public class StackService extends ExternalTaskUtils { logger.debug("Starting External Task Stack Service. {}", xmlRequest); MutableBoolean success = new MutableBoolean(); MutableBoolean backout = new MutableBoolean(); - String response = ""; + MutableBoolean os3Nw = new MutableBoolean(); Holder<String> canonicalStackId = new Holder<>(); String errorMessage = ""; try { @@ -117,26 +107,26 @@ public class StackService extends ExternalTaskUtils { Holder<NetworkRollback> networkRollback = new Holder<>(); if ("createVolumeGroupRequest".equals(requestType.get())) { logger.debug("Executing External Task Stack Service For Create Volume Group"); - response = createVolumeGroup(xmlRequest, outputs, vnfRollback, canonicalStackId, backout, success); + createVolumeGroup(xmlRequest, outputs, vnfRollback, canonicalStackId, backout, success); } else if ("createVfModuleRequest".equals(requestType.get())) { logger.debug("Executing External Task Stack Service For Create Vf Module"); - response = createVfModule(xmlRequest, outputs, vnfRollback, canonicalStackId, backout, success); + createVfModule(xmlRequest, outputs, vnfRollback, canonicalStackId, backout, success); } else if ("deleteVfModuleRequest".equals(requestType.get())) { logger.debug("Executing External Task Stack Service For Delete Vf Module"); - response = deleteVfModule(xmlRequest, outputs, vnfRollback, canonicalStackId, backout, success); + deleteVfModule(xmlRequest, outputs, vnfRollback, canonicalStackId, backout, success); } else if ("deleteVolumeGroupRequest".equals(requestType.get())) { logger.debug("Executing External Task Stack Service For Delete Volume Group"); - response = deleteVolumeGroup(xmlRequest, outputs, vnfRollback, canonicalStackId, backout, success); + deleteVolumeGroup(xmlRequest, outputs, vnfRollback, canonicalStackId, backout, success); } else if ("createNetworkRequest".equals(requestType.get())) { - response = createNetwork(xmlRequest, networkId, neutronNetworkId, networkFqdn, subnetIdMap, - networkRollback, canonicalStackId, backout, success); + createNetwork(xmlRequest, networkId, neutronNetworkId, networkFqdn, subnetIdMap, networkRollback, + canonicalStackId, backout, success, os3Nw); } else if ("deleteNetworkRequest".equals(requestType.get())) { - response = deleteNetwork(xmlRequest, canonicalStackId, backout, success); + deleteNetwork(xmlRequest, canonicalStackId, backout, success); } else if ("updateNetworkRequest".equals(requestType.get())) { - response = - updateNetwork(xmlRequest, subnetIdMap, networkRollback, canonicalStackId, backout, success); + + updateNetwork(xmlRequest, subnetIdMap, networkRollback, canonicalStackId, backout, success); } else if ("rollbackNetworkRequest".equals(requestType.get())) { - response = rollbackNetwork(xmlRequest, canonicalStackId, backout, success); + rollbackNetwork(xmlRequest, canonicalStackId, backout, success); } } } catch (Exception e) { @@ -144,7 +134,6 @@ public class StackService extends ExternalTaskUtils { errorMessage = e.getMessage(); } variables.put("backout", backout.booleanValue()); - variables.put("WorkflowResponse", response); variables.put("OpenstackInvokeSuccess", success.booleanValue()); variables.put("stackId", canonicalStackId.value); variables.put("openstackAdapterErrorMessage", errorMessage); @@ -152,6 +141,7 @@ public class StackService extends ExternalTaskUtils { variables.put("rollbackPerformed", false); variables.put("OpenstackRollbackSuccess", false); variables.put("OpenstackPollSuccess", false); + variables.put("os3Nw", os3Nw.booleanValue()); if (success.isTrue()) { externalTaskService.complete(externalTask, variables); @@ -162,10 +152,9 @@ public class StackService extends ExternalTaskUtils { } } - private String createVolumeGroup(String xmlRequest, Holder<Map<String, String>> outputs, + private void createVolumeGroup(String xmlRequest, Holder<Map<String, String>> outputs, Holder<VnfRollback> vnfRollback, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success) throws VnfException { - Holder<String> stackId = new Holder<>(); CreateVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class); String completeVnfVfModuleType = req.getVnfType() + "::" + req.getVfModuleType(); boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); @@ -173,28 +162,19 @@ public class StackService extends ExternalTaskUtils { vnfPluginImpl.createVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), completeVnfVfModuleType, req.getVnfVersion(), "", req.getVolumeGroupName(), "", "VOLUME", null, null, req.getModelCustomizationUuid(), req.getVolumeGroupParams(), false, true, - req.getEnableBridge(), req.getMsoRequest(), stackId, outputs, vnfRollback); + req.getEnableBridge(), req.getMsoRequest(), canonicalStackId, outputs, vnfRollback); } else { vnfAdapterImpl.createVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), completeVnfVfModuleType, req.getVnfVersion(), "", req.getVolumeGroupName(), "", "VOLUME", null, null, req.getModelCustomizationUuid(), req.getVolumeGroupParams(), false, true, - req.getEnableBridge(), req.getMsoRequest(), stackId, outputs, vnfRollback); + req.getEnableBridge(), req.getMsoRequest(), canonicalStackId, outputs, vnfRollback); } success.setTrue(); backout.setValue(!req.getSuppressBackout()); - VolumeGroupRollback rb = new VolumeGroupRollback(req.getVolumeGroupId(), stackId.value, - vnfRollback.value.getVnfCreated(), req.getTenantId(), req.getCloudOwner(), req.getCloudSiteId(), - req.getMsoRequest(), req.getMessageId()); - canonicalStackId.value = stackId.value; - CreateVolumeGroupResponse createResponse = new CreateVolumeGroupResponse(req.getVolumeGroupId(), stackId.value, - vnfRollback.value.getVnfCreated(), outputs.value, rb, req.getMessageId()); - return createResponse.toXmlString(); } - private String createVfModule(String xmlRequest, Holder<Map<String, String>> outputs, - Holder<VnfRollback> vnfRollback, Holder<String> canonicalStackId, MutableBoolean backout, - MutableBoolean success) throws VnfException { - Holder<String> stackId = new Holder<>(); + private void createVfModule(String xmlRequest, Holder<Map<String, String>> outputs, Holder<VnfRollback> vnfRollback, + Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success) throws VnfException { CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class); String completeVnfVfModuleType = req.getVnfType() + "::" + req.getVfModuleType(); boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); @@ -203,27 +183,20 @@ public class StackService extends ExternalTaskUtils { completeVnfVfModuleType, req.getVnfVersion(), req.getVnfId(), req.getVfModuleName(), req.getVfModuleId(), req.getRequestType(), req.getVolumeGroupStackId(), req.getBaseVfModuleStackId(), req.getModelCustomizationUuid(), req.getVfModuleParams(), false, - false, req.getEnableBridge(), req.getMsoRequest(), stackId, outputs, vnfRollback); + false, req.getEnableBridge(), req.getMsoRequest(), canonicalStackId, outputs, vnfRollback); } else { vnfAdapterImpl.createVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), completeVnfVfModuleType, req.getVnfVersion(), req.getVnfId(), req.getVfModuleName(), req.getVfModuleId(), req.getRequestType(), req.getVolumeGroupStackId(), req.getBaseVfModuleStackId(), req.getModelCustomizationUuid(), req.getVfModuleParams(), false, - false, req.getEnableBridge(), req.getMsoRequest(), stackId, outputs, vnfRollback); + false, req.getEnableBridge(), req.getMsoRequest(), canonicalStackId, outputs, vnfRollback); } success.setTrue(); backout.setValue(req.getBackout()); - canonicalStackId.value = stackId.value; - VfModuleRollback modRollback = - new VfModuleRollback(vnfRollback.value, req.getVfModuleId(), stackId.value, req.getMessageId()); - CreateVfModuleResponse createResponse = new CreateVfModuleResponse(req.getVnfId(), req.getVfModuleId(), - stackId.value, Boolean.TRUE, outputs.value, modRollback, req.getMessageId()); - return createResponse.toXmlString(); } - private String deleteVfModule(String xmlRequest, Holder<Map<String, String>> outputs, - Holder<VnfRollback> vnfRollback, Holder<String> canonicalStackId, MutableBoolean backout, - MutableBoolean success) throws VnfException { + private void deleteVfModule(String xmlRequest, Holder<Map<String, String>> outputs, Holder<VnfRollback> vnfRollback, + Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success) throws VnfException { backout.setFalse(); DeleteVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteVfModuleRequest.class); boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); @@ -241,12 +214,9 @@ public class StackService extends ExternalTaskUtils { } else { canonicalStackId.value = req.getVfModuleStackId(); } - DeleteVfModuleResponse deleteResponse = new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), - Boolean.TRUE, req.getMessageId(), outputs.value); - return deleteResponse.toXmlString(); } - private String deleteVolumeGroup(String xmlRequest, Holder<Map<String, String>> outputs, + private void deleteVolumeGroup(String xmlRequest, Holder<Map<String, String>> outputs, Holder<VnfRollback> vnfRollback, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success) throws VnfException { backout.setFalse(); @@ -255,14 +225,12 @@ public class StackService extends ExternalTaskUtils { req.getVolumeGroupStackId(), req.getMsoRequest(), false); success.setTrue(); canonicalStackId.value = req.getVolumeGroupStackId(); - DeleteVolumeGroupResponse deleteResponse = new DeleteVolumeGroupResponse(true, req.getMessageId()); - return deleteResponse.toXmlString(); } - private String createNetwork(String xmlRequest, Holder<String> networkId, Holder<String> neutronNetworkId, + private void createNetwork(String xmlRequest, Holder<String> networkId, Holder<String> neutronNetworkId, Holder<String> networkFqdn, Holder<Map<String, String>> subnetIdMap, Holder<NetworkRollback> networkRollback, Holder<String> canonicalStackId, MutableBoolean backout, - MutableBoolean success) throws NetworkException { + MutableBoolean success, MutableBoolean os3) throws NetworkException { CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class); HashMap<String, String> params = (HashMap<String, String>) req.getNetworkParams(); if (params == null) { @@ -306,18 +274,13 @@ public class StackService extends ExternalTaskUtils { networkAdapterImpl.createNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkName(), physicalNetworkName, vlans, routeTargets, shared, external, req.getFailIfExists(), false, req.getSubnets(), fqdns, routeTable, req.getMsoRequest(), - networkId, neutronNetworkId, networkFqdn, subnetIdMap, networkRollback, true); + networkId, neutronNetworkId, networkFqdn, subnetIdMap, networkRollback, true, os3); success.setTrue(); backout.setValue(req.getBackout()); canonicalStackId.value = networkRollback.value.getNetworkStackId(); - - CreateNetworkResponse response = new CreateNetworkResponse(req.getNetworkId(), neutronNetworkId.value, - networkRollback.value.getNetworkStackId(), networkFqdn.value, networkRollback.value.getNetworkCreated(), - subnetIdMap.value, networkRollback.value, req.getMessageId()); - return response.toXmlString(); } - private String deleteNetwork(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, + private void deleteNetwork(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success) throws NetworkException { backout.setFalse(); DeleteNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteNetworkRequest.class); @@ -328,13 +291,9 @@ public class StackService extends ExternalTaskUtils { canonicalStackId.value = req.getNetworkStackId(); success.setTrue(); - - DeleteNetworkResponse response = - new DeleteNetworkResponse(req.getNetworkId(), networkDeleted.value, req.getMessageId()); - return response.toXmlString(); } - private String rollbackNetwork(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, + private void rollbackNetwork(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success) throws NetworkException { backout.setFalse(); RollbackNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), RollbackNetworkRequest.class); @@ -344,9 +303,6 @@ public class StackService extends ExternalTaskUtils { canonicalStackId.value = rollback.getNetworkStackId(); success.setTrue(); - - RollbackNetworkResponse response = new RollbackNetworkResponse(true, req.getMessageId()); - return response.toXmlString(); } private String updateNetwork(String xmlRequest, Holder<Map<String, String>> subnetIdMap, diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java index 26bce5f362..4ee6cf259e 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java @@ -158,6 +158,7 @@ public class MsoVnfAdapterImpl { * @param outputs Holder for Map of VNF outputs from heat (assigned IPs, etc) * @param rollback Holder for returning VnfRollback object */ + @Deprecated public void createVnf(String cloudSiteId, String cloudOwner, String tenantId, String vnfType, String vnfVersion, String vnfName, String requestType, String volumeGroupHeatStackId, Map<String, Object> inputs, Boolean failIfExists, Boolean backout, Boolean enableBridge, MsoRequest msoRequest, Holder<String> vnfId, @@ -212,6 +213,7 @@ public class MsoVnfAdapterImpl { * @param vnfName VNF Name or Openstack ID * @param msoRequest Request tracking information for logs */ + @Deprecated public void deleteVnf(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, MsoRequest msoRequest) throws VnfException { @@ -251,6 +253,7 @@ public class MsoVnfAdapterImpl { * @param vnfName VNF Name or Openstack ID * @param msoRequest Request tracking information for logs */ + @Deprecated public void deleteVnf(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, MsoRequest msoRequest, boolean pollStackStatus) throws VnfException { @@ -315,7 +318,7 @@ public class MsoVnfAdapterImpl { return; } - private Map<String, String> copyStringOutputs(Map<String, Object> stackOutputs) { + public Map<String, String> copyStringOutputs(Map<String, Object> stackOutputs) { Map<String, String> stringOutputs = new HashMap<>(); for (Map.Entry<String, Object> entry : stackOutputs.entrySet()) { String key = entry.getKey(); @@ -405,6 +408,7 @@ public class MsoVnfAdapterImpl { return stringMap; } + // TODO remove rollback and outputs and polling public void createVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfType, String vnfVersion, String genericVnfName, String vnfName, String vfModuleId, String requestType, String volumeGroupHeatStackId, String baseVfHeatStackId, String modelCustomizationUuid, @@ -461,6 +465,7 @@ public class MsoVnfAdapterImpl { logger.debug("requestTypeString = " + requestTypeString + ", nestedStackId = " + nestedStackId + ", nestedBaseStackId = " + nestedBaseStackId); + // TODO remove // Build a default rollback object (no actions performed) VnfRollback vfRollback = new VnfRollback(); vfRollback.setCloudSiteId(cloudSiteId); @@ -960,7 +965,7 @@ public class MsoVnfAdapterImpl { vnfId.value = heatStack.getCanonicalName(); outputs.value = copyStringOutputs(heatStack.getOutputs()); - rollback.value = vfRollback; + rollback.value = vfRollback; // TODO remove logger.debug("VF Module {} successfully created", vfModuleName); } catch (Exception e) { logger.debug("unhandled exception in create VF", e); @@ -988,29 +993,7 @@ public class MsoVnfAdapterImpl { // call method which handles the conversion from Map<String,Object> to Map<String,String> for our expected // Object types outputs.value = this.convertMapStringObjectToStringString(stackOutputs); - int timeoutMinutes = 118; - VfModule vf = null; - VfModuleCustomization vfmc = null; - if (modelCustomizationUuid != null) { - vfmc = vfModuleCustomRepo.findFirstByModelCustomizationUUIDOrderByCreatedDesc(modelCustomizationUuid); - if (vfmc != null) { - vf = vfmc.getVfModule(); - } - if (vf != null) { - logger.trace("Found vfModuleCust entry {}", vfmc.toString()); - HeatTemplate heat = vf.getModuleHeatTemplate(); - if (heat != null && heat.getTimeoutMinutes() != null) { - if (heat.getTimeoutMinutes() < 118) { - timeoutMinutes = heat.getTimeoutMinutes(); - } - } - - } else { - logger.debug( - "Unable to find vfModuleCust with modelCustomizationUuid={} . Using default timeout for polling", - modelCustomizationUuid); - } - } + int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(modelCustomizationUuid, false); try { StackInfo currentStack = diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java index 6b979833eb..58c43be36a 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImpl.java @@ -1120,7 +1120,9 @@ public class MsoVnfPluginAdapterImpl { long subStartTime = System.currentTimeMillis(); try { // TODO: Get an appropriate timeout value - require access to the model - vduPlugin.deleteVdu(cloudInfo, vfModuleId, 5); + if (!vduInstance.getStatus().getState().equals(VduStateType.NOTFOUND)) { + vduPlugin.deleteVdu(cloudInfo, vfModuleId, 5); + } } catch (VduException me) { me.addContext("DeleteVfModule"); // Convert to a generic VnfException diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java index eb0529c85f..0512912b9f 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java @@ -61,9 +61,8 @@ import org.onap.aai.domain.yang.Pserver; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipList; import org.onap.aai.domain.yang.SriovPf; -import org.onap.aai.domain.yang.Subnets; import org.onap.aai.domain.yang.SriovVf; -import org.onap.aai.domain.yang.VfModule; +import org.onap.aai.domain.yang.Subnets; import org.onap.aai.domain.yang.Vlan; import org.onap.aai.domain.yang.Vserver; import org.onap.aaiclient.client.aai.AAIDSLQueryClient; @@ -734,27 +733,15 @@ public class HeatBridgeImpl implements HeatBridgeApi { Objects.requireNonNull(vnfId, "Null vnf-id!"); Objects.requireNonNull(vfModuleId, "Null vf-module-id!"); try { - Optional<VfModule> vfModule = resourcesClient.get(AAIUriFactory + AAIResultWrapper vfModule = resourcesClient.get(AAIUriFactory .createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId)) - .depth(Depth.ONE), NotFoundException.class).asBean(VfModule.class); + .depth(Depth.ONE), NotFoundException.class); - AAIResultWrapper resultWrapper = new AAIResultWrapper(vfModule.get()); - Optional<Relationships> relationships = resultWrapper.getRelationships(); + Optional<Relationships> relationships = vfModule.getRelationships(); logger.debug("VfModule contains relationships in AAI: {}", relationships.isPresent()); if (relationships.isPresent()) { - List<AAIResourceUri> l3NetworkUris = relationships.get().getRelatedUris(Types.L3_NETWORK); - logger.debug("L3Network contains {} relationships in AAI", l3NetworkUris.size()); - - if (!l3NetworkUris.isEmpty()) { - for (AAIResourceUri l3NetworkUri : l3NetworkUris) { - if (env.getProperty("heatBridgeDryrun", Boolean.class, true)) { - logger.debug("Would delete L3Network: {}", l3NetworkUri.build().toString()); - } else { - resourcesClient.delete(l3NetworkUri); - } - } - } + deleteL3Networks(relationships.get()); List<AAIResourceUri> vserverUris = relationships.get().getRelatedUris(Types.VSERVER); logger.debug("VServer contains {} relationships in AAI", vserverUris.size()); @@ -765,7 +752,7 @@ public class HeatBridgeImpl implements HeatBridgeApi { if (env.getProperty("heatBridgeDryrun", Boolean.class, false)) { logger.debug("Would delete Vserver: {}", vserverUri.build().toString()); } else { - resourcesClient.delete(vserverUri); + resourcesClient.deleteIfExists(vserverUri); } } } @@ -782,6 +769,21 @@ public class HeatBridgeImpl implements HeatBridgeApi { } } + protected void deleteL3Networks(Relationships relationships) { + List<AAIResourceUri> l3NetworkUris = relationships.getRelatedUris(Types.L3_NETWORK); + logger.debug("L3Network contains {} relationships in AAI", l3NetworkUris.size()); + + if (!l3NetworkUris.isEmpty()) { + for (AAIResourceUri l3NetworkUri : l3NetworkUris) { + if (env.getProperty("heatBridgeDryrun", Boolean.class, true)) { + logger.debug("Would delete L3Network: {}", l3NetworkUri.build().toString()); + } else { + resourcesClient.delete(l3NetworkUri); + } + } + } + } + private void createTransactionToDeleteSriovPfFromPserver(List<AAIResourceUri> vserverUris) { Map<String, List<String>> pserverToPciIdMap = getPserverToPciIdMap(vserverUris); for (Map.Entry<String, List<String>> entry : pserverToPciIdMap.entrySet()) { diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java index a8fa6535c3..1f6c0df90f 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java @@ -108,6 +108,13 @@ public class AaiHelper { * if (!StringUtils.isEmpty(server.getName())) { * relationships.add(createVnfRelationshiptoVserver(server.getName(), genericVnfId, vfModuleId)); } */ + + // vserver to generic-vnf relationship + Relationship genericVnfRelationship = buildRelationship( + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId))); + relationships.add(genericVnfRelationship); + + // vserver to vf-module relationship Relationship vfModuleRelationship = buildRelationship(AAIUriFactory .createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId))); |