diff options
16 files changed, 282 insertions, 90 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java index ab0239057a..c1c7ed5fd6 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java @@ -100,7 +100,7 @@ public final class AuthenticationMethodFactory { Project project = new Project(); Project.Domain projectDomain = new Project.Domain(); userDomain.setName(cloudIdentity.getUserDomainName()); - projectDomain.setName(cloudIdentity.getProjectDomainName()); + projectDomain.setName(cloudIdentity.getAdminProjectDomainName()); user.setName(cloudIdentity.getMsoId()); user.setPassword(CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass())); user.setDomain(userDomain); 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-catalog-db-adapter/src/main/resources/db/migration/V8.8.1__AddColumnAdminProjectDomainName.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.8.1__AddColumnAdminProjectDomainName.sql new file mode 100644 index 0000000000..a883466515 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.8.1__AddColumnAdminProjectDomainName.sql @@ -0,0 +1,3 @@ +use catalogdb; + +ALTER TABLE identity_services ADD COLUMN ADMIN_PROJECT_DOMAIN_NAME varchar(255) DEFAULT 'Default';
\ No newline at end of file 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..9123ac9f36 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 @@ -962,31 +962,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 = 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..ddbda5da62 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 @@ -90,7 +90,9 @@ public class PollService extends ExternalTaskUtils { JAXB.unmarshal(new StringReader(xmlRequest), DeleteVfModuleRequest.class); boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); if (!isMulticloud) { - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(req.getModelCustomizationUuid(), false); + pollDeleteResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), externalTask, + success); } else { success.setTrue(); } @@ -100,7 +102,7 @@ public class PollService extends ExternalTaskUtils { JAXB.unmarshal(new StringReader(xmlRequest), DeleteVolumeGroupRequest.class); boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); if (!isMulticloud) { - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), externalTask, success); } else { success.setTrue(); } @@ -109,7 +111,7 @@ public class PollService extends ExternalTaskUtils { } else if ("deleteNetworkRequest".equals(requestType.get())) { logger.debug("Executing External Task Poll Service for Delete Network"); DeleteNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteNetworkRequest.class); - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), externalTask, success); } else if ("updateNetworkRequest".equals(requestType.get())) { UpdateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), UpdateNetworkRequest.class); pollUpdateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); @@ -152,9 +154,10 @@ public class PollService extends ExternalTaskUtils { 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); + pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), externalTask, success); } else { - pollCreateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(req.getModelCustomizationUuid(), true); + pollCreateResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), externalTask, success); } } else { success.setTrue(); @@ -167,12 +170,13 @@ public class PollService extends ExternalTaskUtils { boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId()); if (!isMulticloud) { boolean pollRollbackStatus = externalTask.getVariable("PollRollbackStatus"); + int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(req.getModelCustomizationUuid(), false); if (pollRollbackStatus) { logger.debug("Executing External Task Poll Service for Rollback Create Vf Module"); - pollDeleteResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + pollDeleteResource(timeoutMinutes, 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); + pollCreateResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), externalTask, success); } } else { success.setTrue(); @@ -183,29 +187,31 @@ public class PollService extends ExternalTaskUtils { throws MsoException { CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class); 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); + pollDeleteResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), externalTask, success); } else { logger.debug("Executing External Task Poll Service for Create Network"); - pollCreateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success); + pollCreateResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), externalTask, success); } } - private void pollCreateResource(String cloudSiteId, String tenantId, ExternalTask externalTask, + private void pollCreateResource(int pollingTimeout, String cloudSiteId, String tenantId, ExternalTask externalTask, MutableBoolean success) throws MsoException { Stack currentStack = createCurrentStack(externalTask.getVariable("stackId")); - Stack stack = - msoHeatUtils.pollStackForStatus(1, currentStack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false); + Stack stack = msoHeatUtils.pollStackForStatus(pollingTimeout, currentStack, "CREATE_IN_PROGRESS", cloudSiteId, + tenantId, false); msoHeatUtils.postProcessStackCreate(stack, false, 0, false, cloudSiteId, tenantId, null); success.setTrue(); } - private void pollDeleteResource(String cloudSiteId, String tenantId, ExternalTask externalTask, + private void pollDeleteResource(int pollingTimeout, String cloudSiteId, String tenantId, ExternalTask externalTask, MutableBoolean success) throws MsoException { Stack currentStack = createCurrentStack(externalTask.getVariable("stackId")); - Stack stack = - msoHeatUtils.pollStackForStatus(1, currentStack, "DELETE_IN_PROGRESS", cloudSiteId, tenantId, true); + 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); } @@ -245,5 +251,4 @@ public class PollService extends ExternalTaskUtils { currentStack.setStackName(stackName); return currentStack; } - } 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..7acf953282 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 { @@ -988,29 +991,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/heatbridge/HeatBridgeImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java index eb0529c85f..9b20139969 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 @@ -765,7 +765,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); } } } 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/graph-inventory/aai-client/pom.xml b/graph-inventory/aai-client/pom.xml index d1c9742cea..d532103c40 100644 --- a/graph-inventory/aai-client/pom.xml +++ b/graph-inventory/aai-client/pom.xml @@ -93,7 +93,7 @@ <destination>${project.build.directory}/generated-sources</destination> <destinationClasspath>org.onap.aaiclient.client.generated.fluentbuilders</destinationClasspath> <builderName>AAIFluentTypeBuilder</builderName> - <swaggerLocation>${project.build.directory}/swagger/onap/aai_swagger_yaml/aai_swagger_v21.yaml</swaggerLocation> + <swaggerLocation>${project.build.directory}/swagger/onap/aai_swagger_yaml/aai_swagger_LATEST.yaml</swaggerLocation> <singularBuilderClass>org.onap.aaiclient.client.aai.entities.uri.AAIFluentSingleType</singularBuilderClass> <pluralBuilderClass>org.onap.aaiclient.client.aai.entities.uri.AAIFluentPluralType</pluralBuilderClass> <topLevelBuilderClass>org.onap.aaiclient.client.aai.entities.uri.AAIFluentTopLevelType</topLevelBuilderClass> diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java index 343e888ce1..5dbe91586a 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryResourcesClient.java @@ -42,9 +42,13 @@ import org.onap.aaiclient.client.graphinventory.entities.uri.HttpAwareUri; import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryMultipleItemsException; import org.onap.so.client.RestClient; import org.onap.so.client.RestProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInventoryResourceUri<?, ?>, SingleUri extends GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?>, PluralUri extends GraphInventoryPluralResourceUri<?, ?>, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> { + private static final Logger logger = LoggerFactory.getLogger(GraphInventoryResourcesClient.class); + protected GraphInventoryClient client; protected GraphInventoryResourcesClient(GraphInventoryClient client) { @@ -147,6 +151,27 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven String resourceVersion = (String) result.get("resource-version"); giRC = client.createClient(clone.resourceVersion(resourceVersion)); giRC.delete(); + + } + + /** + * Deletes object from GraphInventory only if exists. Automatically handles resource-version. + * + * @param uri + * @return + */ + public void deleteIfExists(SingleUri uri) { + GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> clone = (SingleUri) uri.clone(); + RestClient giRC = client.createClient(clone); + Optional<Map<String, Object>> result = giRC.get(new GenericType<Map<String, Object>>() {}); + if (result.isPresent()) { + String resourceVersion = (String) result.get().get("resource-version"); + giRC = client.createClient(clone.resourceVersion(resourceVersion)); + giRC.delete(); + } else { + logger.warn(clone.build() + " already does not exist in " + client.getGraphDBName() + + " therefore delete call not executed"); + } } /** diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java index 36ba1f3e76..03fd0acd4f 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java @@ -108,6 +108,27 @@ public class AAIResourcesClientTest { } @Test + public void verifyDeleteIfExists() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test2")); + wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(404))); + AAIResourcesClient client = aaiClient; + client.deleteIfExists(path); + } + + @Test + public void verifyDeleteIfExists_exists() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test2")); + wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("aai/resources/mockObject.json").withStatus(200))); + wireMockRule.stubFor(delete(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .withQueryParam("resource-version", equalTo("1234")).willReturn(aResponse().withStatus(204))); + AAIResourcesClient client = aaiClient; + client.deleteIfExists(path); + } + + @Test public void verifyBasicAuth() { AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test3")); wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) diff --git a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java index ec09af8a4e..fc42d9ca0d 100644 --- a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java +++ b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java @@ -1,6 +1,10 @@ package org.onap.graphinventory.generate; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -26,6 +30,9 @@ public class SwaggerConverter { } public Map<String, ObjectType> getDoc(String swaggerLocation) throws JsonProcessingException { + + + swaggerLocation = processLocation(swaggerLocation); Swagger swagger = new SwaggerParser().read(swaggerLocation); Map<String, Path> paths = swagger.getPaths().entrySet().stream() @@ -168,4 +175,19 @@ public class SwaggerConverter { return output; } + + private String processLocation(String swaggerLocation) { + + java.nio.file.Path path = Paths.get(swaggerLocation); + try { + return Files.list(path.getParent()) + .filter(it -> it.getFileName().toString() + .matches(path.getFileName().toString().replaceFirst("LATEST", "v\\\\\\d+"))) + .sorted(Comparator.reverseOrder()).map(it -> it.toString()).findFirst().orElseGet(null); + } catch (IOException e) { + log.error(e); + } + + return null; + } } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java index 61b0b11445..63ee35cd9c 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/CloudIdentity.java @@ -20,13 +20,7 @@ package org.onap.so.db.catalog.beans; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.openpojo.business.annotation.BusinessKey; -import org.apache.commons.lang3.builder.HashCodeBuilder; import java.util.Date; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -36,6 +30,12 @@ import javax.persistence.PrePersist; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.openpojo.business.annotation.BusinessKey; import uk.co.blackpepper.bowman.annotation.RemoteResource; /** @@ -74,6 +74,11 @@ public class CloudIdentity { @Column(name = "PROJECT_DOMAIN_NAME") private String projectDomainName; + @JsonProperty("admin_project_domain_name ") + @BusinessKey + @Column(name = "ADMIN_PROJECT_DOMAIN_NAME") + private String adminProjectDomainName; + @JsonProperty("user_domain_name") @BusinessKey @Column(name = "USER_DOMAIN_NAME") @@ -245,6 +250,14 @@ public class CloudIdentity { this.projectDomainName = projectDomainName; } + public String getAdminProjectDomainName() { + return adminProjectDomainName; + } + + public void setAdminProjectDomainName(String adminProjectDomainName) { + this.adminProjectDomainName = adminProjectDomainName; + } + public String getUserDomainName() { return userDomainName; } @@ -267,6 +280,7 @@ public class CloudIdentity { cloudIdentityCopy.identityServerType = this.identityServerType; cloudIdentityCopy.identityAuthenticationType = this.identityAuthenticationType; cloudIdentityCopy.projectDomainName = this.projectDomainName; + cloudIdentityCopy.adminProjectDomainName = this.adminProjectDomainName; cloudIdentityCopy.userDomainName = this.userDomainName; return cloudIdentityCopy; @@ -279,7 +293,8 @@ public class CloudIdentity { .append("projectDomain", getProjectDomainName()).append("userDomain", getUserDomainName()) .append("adminTenant", getAdminTenant()).append("memberRole", getMemberRole()) .append("tenantMetadata", getTenantMetadata()).append("identityServerType", getIdentityServerType()) - .append("identityAuthenticationType", getIdentityAuthenticationType()).toString(); + .append("identityAuthenticationType", getIdentityAuthenticationType()) + .append("adminProjectDomainName", getAdminProjectDomainName()).toString(); } @Override @@ -299,7 +314,8 @@ public class CloudIdentity { .append(getMemberRole(), castOther.getMemberRole()) .append(getTenantMetadata(), castOther.getTenantMetadata()) .append(getIdentityServerType(), castOther.getIdentityServerType()) - .append(getIdentityAuthenticationType(), castOther.getIdentityAuthenticationType()).isEquals(); + .append(getIdentityAuthenticationType(), castOther.getIdentityAuthenticationType()) + .append(getAdminProjectDomainName(), castOther.getAdminProjectDomainName()).isEquals(); } @Override @@ -307,6 +323,7 @@ public class CloudIdentity { return new HashCodeBuilder(1, 31).append(getId()).append(getIdentityUrl()).append(getMsoId()) .append(getMsoPass()).append(getProjectDomainName()).append(getUserDomainName()) .append(getAdminTenant()).append(getMemberRole()).append(getTenantMetadata()) - .append(getIdentityServerType()).append(getIdentityAuthenticationType()).toHashCode(); + .append(getIdentityServerType()).append(getIdentityAuthenticationType()) + .append(getAdminProjectDomainName()).toHashCode(); } } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index ef90dd6984..91cfb00911 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -47,6 +47,7 @@ import org.onap.so.db.catalog.beans.HomingInstance; import org.onap.so.db.catalog.beans.InstanceGroup; import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; import org.onap.so.db.catalog.beans.NetworkRecipe; +import org.onap.so.db.catalog.beans.NetworkResource; import org.onap.so.db.catalog.beans.NetworkResourceCustomization; import org.onap.so.db.catalog.beans.OrchestrationAction; import org.onap.so.db.catalog.beans.OrchestrationStatus; @@ -98,6 +99,7 @@ public class CatalogDbClient { private static final String RAINY_DAY_HANDLER_MACRO = "/rainy_day_handler_macro"; private static final String NORTHBOUND_REQUEST_REF_LOOKUP = "/northbound_request_ref_lookup"; private static final String NETWORK_RESOURCE_CUSTOMIZATION = "/networkResourceCustomization"; + private static final String NETWORK_RESOURCE = "/networkResource"; private static final String COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION = "/collectionResourceInstanceGroupCustomization"; private static final String VNFC_INSTANCE_GROUP_CUSTOMIZATION = "/vnfcInstanceGroupCustomization"; @@ -223,6 +225,7 @@ public class CatalogDbClient { private String vnfResourceURI; private String networkCollectionResourceCustomizationURI; private String networkResourceCustomizationURI; + private String networkResourceURI; private String collectionNetworkResourceCustomizationURI; private String instanceGroupURI; private String cloudifyManagerURI; @@ -375,6 +378,7 @@ public class CatalogDbClient { networkCollectionResourceCustomizationURI = endpoint + NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION + URI_SEPARATOR; networkResourceCustomizationURI = endpoint + NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR; + networkResourceURI = endpoint + NETWORK_RESOURCE + SEARCH; collectionNetworkResourceCustomizationURI = endpoint + COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR; instanceGroupURI = endpoint + INSTANCE_GROUP + URI_SEPARATOR; @@ -607,6 +611,25 @@ public class CatalogDbClient { return networkResourceCustomization; } + public NetworkResource getNetworkResourceByModelName(String networkType) { + if (Strings.isNullOrEmpty(networkType)) { + throw new EntityNotFoundException("networkType passed as Null or Empty String"); + } + try { + HttpEntity<?> entity = getHttpEntity(); + return restTemplate.exchange( + UriBuilder.fromUri(networkResourceURI + "/findFirstByModelNameOrderByModelVersionDesc") + .queryParam("modelName", networkType).build(), + HttpMethod.GET, entity, NetworkResource.class).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find NetworkResource By networkType " + networkType); + } + throw e; + } + } + + public BuildingBlockDetail getBuildingBlockDetail(String buildingBlockName) { BuildingBlockDetail buildingBlockDetail = diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/NetworkResourceRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/NetworkResourceRepository.java index 42d107c1ff..30f3df7110 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/NetworkResourceRepository.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/NetworkResourceRepository.java @@ -23,6 +23,7 @@ package org.onap.so.db.catalog.data.repository; import org.onap.so.db.catalog.beans.NetworkResource; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; @@ -38,7 +39,7 @@ public interface NetworkResourceRepository extends JpaRepository<NetworkResource */ @Query(value = "SELECT * FROM network_resource WHERE MODEL_NAME = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true) - NetworkResource findFirstByModelNameOrderByModelVersionDesc(String modelName); + NetworkResource findFirstByModelNameOrderByModelVersionDesc(@Param("modelName") String modelName); NetworkResource findResourceByModelUUID(String modelUUID); |