diff options
Diffstat (limited to 'adapters')
9 files changed, 378 insertions, 244 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index c4ef3678c3..ba4b30903d 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -31,9 +31,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import org.onap.logging.filter.base.ErrorCode; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.adapters.vdu.CloudInfo; @@ -49,6 +50,11 @@ import org.onap.so.adapters.vdu.VduStatus; import org.onap.so.cloud.authentication.KeystoneAuthHolder; import org.onap.so.db.catalog.beans.HeatTemplate; import org.onap.so.db.catalog.beans.HeatTemplateParam; +import org.onap.so.db.catalog.beans.NetworkResource; +import org.onap.so.db.catalog.beans.NetworkResourceCustomization; +import org.onap.so.db.catalog.beans.VfModule; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.CloudApiRequests; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; @@ -108,6 +114,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { public static final String EXCEPTION_ROLLING_BACK_STACK = "{} Create Stack: Nested exception rolling back stack: {} "; public static final String IN_PROGRESS = "in_progress"; + private static final int DEFAULT_POLLING_TIMEOUT = 118; @Autowired private Environment environment; @@ -121,6 +128,9 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { @Autowired RequestsDbClient requestDBClient; + @Autowired + private CatalogDbClient catalogClient; + private static final Logger logger = LoggerFactory.getLogger(MsoHeatUtils.class); // Properties names and variables (with default values) @@ -898,11 +908,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { if (inputs == null) { return new HashMap<>(); } - try { - Set<HeatTemplateParam> paramSet = template.getParameters(); - } catch (Exception e) { - logger.debug("Exception occurred in convertInputMap {} :", e.getMessage(), e); - } for (HeatTemplateParam htp : template.getParameters()) { params.put(htp.getParamName(), htp); @@ -1232,4 +1237,72 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } } + public int getVfHeatTimeoutValue(String modelCustomizationUuid, boolean isVolumeGroup) { + int timeoutMinutes = DEFAULT_POLLING_TIMEOUT; + try { + VfModuleCustomization vfmc = null; + if (modelCustomizationUuid != null) { + vfmc = catalogClient.getVfModuleCustomizationByModelCuztomizationUUID(modelCustomizationUuid); + if (vfmc != null) { + VfModule vf = vfmc.getVfModule(); + if (vf != null) { + HeatTemplate heat = vf.getModuleHeatTemplate(); + if (isVolumeGroup) { + heat = vf.getVolumeHeatTemplate(); + } + if (heat != null && heat.getTimeoutMinutes() != null) { + if (heat.getTimeoutMinutes() < DEFAULT_POLLING_TIMEOUT) { + timeoutMinutes = heat.getTimeoutMinutes(); + } + } + } + } else { + logger.debug( + "Unable to find Vf Module Customization with model customization uuid {}. Using default timeout {}", + modelCustomizationUuid, timeoutMinutes); + } + } + } catch (Exception e) { + logger.warn("Exception occured while getting heat timeout value. Using default timeout {}", timeoutMinutes, + e); + } + return timeoutMinutes; + } + + public int getNetworkHeatTimeoutValue(String modelCustomizationUuid, String networkType) { + int timeoutMinutes = DEFAULT_POLLING_TIMEOUT; + try { + NetworkResource networkResource = null; + if (isBlank(modelCustomizationUuid)) { + if (isNotBlank(networkType)) { + networkResource = catalogClient.getNetworkResourceByModelName(networkType); + } + } else { + NetworkResourceCustomization nrc = + catalogClient.getNetworkResourceCustomizationByModelCustomizationUUID(modelCustomizationUuid); + if (nrc != null) { + networkResource = nrc.getNetworkResource(); + } + } + + if (networkResource != null) { + networkResource.getHeatTemplate().getTimeoutMinutes(); + HeatTemplate heat = networkResource.getHeatTemplate(); + if (heat != null && heat.getTimeoutMinutes() != null) { + if (heat.getTimeoutMinutes() < DEFAULT_POLLING_TIMEOUT) { + timeoutMinutes = heat.getTimeoutMinutes(); + } + } + } else { + logger.debug( + "Unable to find Network Resource with model customization uuid {} or network type {}. Using default timeout {}", + modelCustomizationUuid, networkType, timeoutMinutes); + } + } catch (Exception e) { + logger.warn("Exception occured while getting heat timeout value. Using default timeout {}", timeoutMinutes, + e); + } + return timeoutMinutes; + } + } diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java index 5bd7c29313..f20f6f1448 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java @@ -46,6 +46,12 @@ import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.db.catalog.beans.HeatTemplate; +import org.onap.so.db.catalog.beans.NetworkResource; +import org.onap.so.db.catalog.beans.NetworkResourceCustomization; +import org.onap.so.db.catalog.beans.VfModule; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.CloudApiRequests; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; @@ -103,6 +109,9 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { @Mock private CreateStack mockCreateStack; + @Mock + private CatalogDbClient catalogDbClient; + private String cloudSiteId = "cloudSiteId"; private String tenantId = "tenantId"; @@ -564,4 +573,38 @@ public class MsoHeatUtilsTest extends MsoHeatUtils { Mockito.verify(heatUtils, times(0)).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId); } + @Test + public void testGetVfHeatTimeoutValue() { + + VfModuleCustomization vfmc = new VfModuleCustomization(); + VfModule vf = new VfModule(); + HeatTemplate heat = new HeatTemplate(); + heat.setTimeoutMinutes(110); + vf.setModuleHeatTemplate(heat); + vfmc.setVfModule(vf); + + Mockito.when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("uuid")).thenReturn(vfmc); + + int timeout = heatUtils.getVfHeatTimeoutValue("uuid", false); + assertEquals(110, timeout); + Mockito.verify(catalogDbClient, times(1)).getVfModuleCustomizationByModelCuztomizationUUID("uuid"); + } + + @Test + public void testGetNetworkHeatTimeoutValue() { + + NetworkResourceCustomization mc = new NetworkResourceCustomization(); + NetworkResource nr = new NetworkResource(); + HeatTemplate heat = new HeatTemplate(); + heat.setTimeoutMinutes(110); + nr.setHeatTemplate(heat); + mc.setNetworkResource(nr); + + Mockito.when(catalogDbClient.getNetworkResourceCustomizationByModelCustomizationUUID("uuid")).thenReturn(mc); + + int timeout = heatUtils.getNetworkHeatTimeoutValue("uuid", "type"); + assertEquals(110, timeout); + Mockito.verify(catalogDbClient, times(1)).getNetworkResourceCustomizationByModelCustomizationUUID("uuid"); + } + } 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/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/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/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java index 60826705fd..0214fdd265 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java @@ -52,15 +52,17 @@ public class PollServiceTest { Mockito.when(mockExternalTask.getVariable("openstackAdapterTaskRequest")).thenReturn(xmlString); Mockito.when(mockExternalTask.getVariable("PollRollbackStatus")).thenReturn(false); Mockito.when(mockExternalTask.getVariable("stackId")).thenReturn("stackId/stack123"); - Mockito.when(msoHeatUtils.pollStackForStatus(eq(1), any(Stack.class), eq("CREATE_IN_PROGRESS"), eq("regionOne"), - eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(false))).thenReturn(new Stack()); + Mockito.when(msoHeatUtils.pollStackForStatus(eq(118), any(Stack.class), eq("CREATE_IN_PROGRESS"), + eq("regionOne"), eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(false))).thenReturn(new Stack()); + Mockito.when(msoHeatUtils.getVfHeatTimeoutValue(any(), eq(false))).thenReturn(118); // Mockito.doNothing().when(msoHeatUtils).postProcessStackCreate(Mockito.any(), Mockito.any(), Mockito.any(), // Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); pollService.executeExternalTask(mockExternalTask, mockExternalTaskService); - Mockito.verify(msoHeatUtils).pollStackForStatus(eq(1), any(Stack.class), eq("CREATE_IN_PROGRESS"), + Mockito.verify(msoHeatUtils).pollStackForStatus(eq(118), any(Stack.class), eq("CREATE_IN_PROGRESS"), eq("regionOne"), eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(false)); + Mockito.verify(msoHeatUtils).getVfHeatTimeoutValue(any(), eq(false)); } @@ -72,16 +74,16 @@ public class PollServiceTest { Mockito.when(mockExternalTask.getVariable("openstackAdapterTaskRequest")).thenReturn(xmlString); Mockito.when(mockExternalTask.getVariable("PollRollbackStatus")).thenReturn(true); Mockito.when(mockExternalTask.getVariable("stackId")).thenReturn("stackId/stack123"); - Mockito.when(msoHeatUtils.pollStackForStatus(eq(1), any(), eq("DELETE_IN_PROGRESS"), eq("regionOne"), + Mockito.when(msoHeatUtils.pollStackForStatus(eq(118), any(), eq("DELETE_IN_PROGRESS"), eq("regionOne"), eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(true))).thenReturn(new Stack()); Mockito.doNothing().when(msoHeatUtils).postProcessStackDelete(Mockito.any()); - + Mockito.when(msoHeatUtils.getVfHeatTimeoutValue(any(), eq(false))).thenReturn(118); pollService.executeExternalTask(mockExternalTask, mockExternalTaskService); - Mockito.verify(msoHeatUtils).pollStackForStatus(eq(1), any(), eq("DELETE_IN_PROGRESS"), eq("regionOne"), + Mockito.verify(msoHeatUtils).pollStackForStatus(eq(118), any(), eq("DELETE_IN_PROGRESS"), eq("regionOne"), eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(true)); - + Mockito.verify(msoHeatUtils).getVfHeatTimeoutValue(any(), eq(false)); } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/StackServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/StackServiceTest.java index afe7e17855..7a00cfe145 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/StackServiceTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/StackServiceTest.java @@ -89,14 +89,15 @@ public class StackServiceTest { Map<String, Object> variables = new HashMap<>(); variables.put("backout", true); - variables.put("WorkflowResponse", ""); variables.put("OpenstackInvokeSuccess", true); variables.put("stackId", null); - variables.put("openstackAdapterErrorMessage", null); + variables.put("openstackAdapterErrorMessage", ""); variables.put("PollRollbackStatus", false); variables.put("rollbackPerformed", false); variables.put("OpenstackRollbackSuccess", false); variables.put("OpenstackPollSuccess", false); + variables.put("os3Nw", false); + Mockito.verify(vnfAdapterImpl, Mockito.times(1)).createVfModule(Mockito.eq("regionOne"), Mockito.eq("CloudOwner"), Mockito.eq("0422ffb57ba042c0800a29dc85ca70f8"), |