From 9e43ae5645f1fe360a07d4687e5a5b5602dbfcee Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Sun, 21 Apr 2019 20:28:38 -0400 Subject: Configuration object status to Inventoried Set initial OrchestrationStatus of Configuration object to Inventoried After Assign call, we need to set the configuration orchestration status to Assigned Change-Id: I4abaeb18d1d220b2bdd03269b3b5a2aba478bf64 Issue-ID: SO-1796 Signed-off-by: Benjamin, Max (mb388a) --- .../bpmn/servicedecomposition/tasks/ExtractPojosForBB.java | 2 +- .../so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java | 10 ++++++++++ .../so/client/orchestration/AAIConfigurationResources.java | 2 +- .../so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java | 12 ++++++++++++ .../client/orchestration/AAIConfigurationResourcesTest.java | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExtractPojosForBB.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExtractPojosForBB.java index 4332a6cf4e..86bbead9a4 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExtractPojosForBB.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExtractPojosForBB.java @@ -47,7 +47,7 @@ public class ExtractPojosForBB { return extractByKey(execution, key, execution.getLookupMap().get(key)); } - public T extractByKey(BuildingBlockExecution execution, ResourceKey key, String value) + protected T extractByKey(BuildingBlockExecution execution, ResourceKey key, String value) throws BBObjectNotFoundException { Optional result = Optional.empty(); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java index 3304d1b113..01bdc09419 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java @@ -481,6 +481,16 @@ public class AAIUpdateTasks { } } + public void updateOrchestrationStatusAssignFabricConfiguration(BuildingBlockExecution execution) { + try { + Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID); + aaiConfigurationResources.updateOrchestrationStatusConfiguration(configuration, + OrchestrationStatus.ASSIGNED); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + public void updateOrchestrationStatusActivateFabricConfiguration(BuildingBlockExecution execution) { try { Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java index 746f136e96..1453e40653 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java @@ -49,7 +49,7 @@ public class AAIConfigurationResources { public void createConfiguration(Configuration configuration) { AAIResourceUri configurationURI = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configuration.getConfigurationId()); - configuration.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + configuration.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); org.onap.aai.domain.yang.Configuration aaiConfiguration = aaiObjectMapper.mapConfiguration(configuration); injectionHelper.getAaiClient().create(configurationURI, aaiConfiguration); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index 7109ac8826..905f244278 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -665,6 +665,18 @@ public class AAIUpdateTasksTest extends BaseTaskTest { OrchestrationStatus.ACTIVE); } + @Test + public void updateOrchestrationStatusAssignedFabricConfigurationTest() throws Exception { + gBBInput = execution.getGeneralBuildingBlock(); + doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, + OrchestrationStatus.ASSIGNED); + + aaiUpdateTasks.updateOrchestrationStatusAssignFabricConfiguration(execution); + + verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, + OrchestrationStatus.ASSIGNED); + } + @Test public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception { execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java index 2e1a40dd22..be58ccb046 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java @@ -98,7 +98,7 @@ public class AAIConfigurationResourcesTest extends TestDataSetup { aaiConfigurationResources.createConfiguration(configuration); - assertEquals(OrchestrationStatus.ASSIGNED, configuration.getOrchestrationStatus()); + assertEquals(OrchestrationStatus.INVENTORIED, configuration.getOrchestrationStatus()); verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Configuration.class)); } -- cgit 1.2.3-korg From 9be7e16cf43270645a3307aa77b3ffeaf70006cf Mon Sep 17 00:00:00 2001 From: "Bonkur, Venkat (vb8416)" Date: Wed, 24 Apr 2019 16:43:15 -0400 Subject: Add SO update config file -application.yaml file Added to Dublin branch- update the catalog-db-adapter -application.yaml file Remove the below line for flyway so that repeatable scripts are run. repeatableSqlMigrationPrefix: RATT Issue-ID: SO-1804 Signed-off-by: Bonkur, Venkat (vb8416) Change-Id: I54bd6d178d9f4c6854421f099bf393599d46d58f --- adapters/mso-catalog-db-adapter/src/main/resources/application.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml index 07b000875e..b1528a0897 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml +++ b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml @@ -28,7 +28,6 @@ spring: password: ${DB_ADMIN_PASSWORD} outOfOrder: true validateOnMigrate: false - repeatableSqlMigrationPrefix: RATT jpa: show-sql: true hibernate: @@ -53,4 +52,4 @@ management: prometheus: enabled: true # Whether exporting of metrics to Prometheus is enabled. step: 1m # Step size (i.e. reporting frequency) to use. - \ No newline at end of file + -- cgit 1.2.3-korg From 97063f90cfa7b9bfc591ee6dba1a5ffa68e00643 Mon Sep 17 00:00:00 2001 From: Eric Multanen Date: Fri, 26 Apr 2019 17:51:39 -0700 Subject: Fix multicloud query of non-existant stack Fix handling of Not Found status for multicloud plugin query of a workload. Change-Id: Ie33b8728bf71fbcf0eaaa6496520351404928a36 Issue-ID: SO-1821 Signed-off-by: Eric Multanen --- .../src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java | 2 +- .../src/main/java/org/onap/so/openstack/mappers/StackInfoMapper.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index 7bf68fff78..4b68ddb674 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -340,7 +340,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { workloadStack = JSON_MAPPER.treeToValue(node.at("/stacks/0"), Stack.class); } else { workloadStack = new Stack(); - workloadStack.setStackStatus(HeatStatus.NOTFOUND.toString()); + workloadStack.setStackStatus("NOT_FOUND"); } } catch (Exception e) { logger.debug("Multicloud Get Exception mapping /stack/0: {} ", node.toString(), e); diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/StackInfoMapper.java b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/StackInfoMapper.java index 8efa48ce79..d830e706f7 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/StackInfoMapper.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/StackInfoMapper.java @@ -95,5 +95,6 @@ public class StackInfoMapper { heatStatusMap.put("UPDATE_IN_PROGRESS", HeatStatus.UPDATING); heatStatusMap.put("UPDATE_FAILED", HeatStatus.FAILED); heatStatusMap.put("UPDATE_COMPLETE", HeatStatus.UPDATED); + heatStatusMap.put("NOT_FOUND", HeatStatus.NOTFOUND); } } -- cgit 1.2.3-korg From cd2687fbd989f2ca23fd82dcb7c70afb401bdd13 Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Fri, 26 Apr 2019 21:25:55 -0400 Subject: Do not need to retry on inventory exception Do not need to retry on inventory exception due to vservers/linterfaces missing. Change-Id: I8e1e1d89ebd35e2b84a65e5e6db3e1db3f976982 Issue-ID: SO-1812 Signed-off-by: Benjamin, Max (mb388a) --- .../inventory/create/CreateInventoryTask.java | 12 ++++++++++-- .../inventory/create/CreateInventoryTaskTest.java | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java index 2bddd439a5..4958bbc7f2 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -48,6 +48,7 @@ public class CreateInventoryTask { protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) { setupMDC(externalTask); boolean success = true; + boolean inventoryException = false; String auditInventoryString = externalTask.getVariable("auditInventoryResult"); AAIObjectAuditList auditInventory = null; try { @@ -61,6 +62,10 @@ public class CreateInventoryTask { logger.info("Executing External Task Create Inventory, Retry Number: {} \n {}", auditInventory, externalTask.getRetries()); createInventory.createInventory(auditInventory); + } catch (InventoryException e) { + logger.error("Error during inventory of stack", e); + success = false; + inventoryException = true; } catch (Exception e) { logger.error("Error during inventory of stack", e); success = false; @@ -68,6 +73,9 @@ public class CreateInventoryTask { if (success) { externalTaskService.complete(externalTask); logger.debug("The External Task Id: {} Successful", externalTask.getId()); + } else if (inventoryException) { + logger.debug("The External Task Id: {} Failed, Retry not needed", externalTask.getId()); + externalTaskService.handleBpmnError(externalTask, "AAIInventoryFailure"); } else { if (externalTask.getRetries() == null) { logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}", diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java index 03622db655..c358d3f34c 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java @@ -10,12 +10,19 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.so.adapters.audit.AAIObjectAudit; +import org.onap.so.adapters.audit.AAIObjectAuditList; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import com.fasterxml.jackson.core.JsonProcessingException; public class CreateInventoryTaskTest { @Mock ExternalTask externalTask; + @Mock + CreateAAIInventory createAAIInventory; + @Mock ExternalTaskService externalTaskService; @@ -33,4 +40,17 @@ public class CreateInventoryTaskTest { inventoryTask.executeExternalTask(externalTask, externalTaskService); Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); } + + @Test + public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException { + AAIObjectAuditList object = new AAIObjectAuditList(); + AAIObjectAudit e = new AAIObjectAudit(); + e.setDoesObjectExist(true); + object.getAuditList().add(e); + GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); + doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult"); + Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any()); + inventoryTask.executeExternalTask(externalTask, externalTaskService); + Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); + } } -- cgit 1.2.3-korg From 47ace9d3fa552b3c19c8894d039841fe7ce91958 Mon Sep 17 00:00:00 2001 From: "Parthasarathy, Ramesh" Date: Sat, 27 Apr 2019 11:08:55 -0400 Subject: repeat distribution transaction error implemented existence of tosca csar first before processing the notification implemented changes to verify if a csar already exists with tosca_csar table before processing the distribution. Updated code to set the SO component status when the csarIsAlreadyDeployed. Change-Id: I777ec603cb2f2f004adaa84e07196a961cebd646 Issue-ID: SO-1808 Signed-off-by: Benjamin, Max (mb388a) --- .../org/onap/so/asdc/client/ASDCController.java | 92 +++++++++++++++++----- .../installer/heat/ToscaResourceInstaller.java | 29 +++++++ .../installer/heat/ToscaResourceInstallerTest.java | 38 ++++++++- 3 files changed, 137 insertions(+), 22 deletions(-) diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java index 9b838c4d98..9597158cb6 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java @@ -62,7 +62,9 @@ import org.onap.so.asdc.installer.heat.ToscaResourceInstaller; import org.onap.so.asdc.tenantIsolation.DistributionStatus; import org.onap.so.asdc.tenantIsolation.WatchdogDistribution; import org.onap.so.asdc.util.ASDCNotificationLogging; +import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; import org.onap.so.db.request.beans.WatchdogDistributionStatus; +import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository; import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; @@ -91,6 +93,9 @@ public class ASDCController { @Autowired private WatchdogDistributionStatusRepository wdsRepo; + @Autowired + protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository; + @Autowired private ASDCConfiguration asdcConfig; @@ -104,6 +109,8 @@ public class ASDCController { private static final String UUID_PARAM = "(UUID:"; + protected static final String MSO = "SO"; + @Autowired private WatchdogDistribution wd; @@ -268,6 +275,52 @@ public class ASDCController { } } + protected void notifyErrorToAsdc(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure, + DistributionStatusEnum deployStatus, VfResourceStructure resourceStructure, String errorMessage) { + // do csar lever first + this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deployStatus, errorMessage); + // at resource level + for (IResourceInstance resource : iNotif.getResources()) { + resourceStructure = new VfResourceStructure(iNotif, resource); + errorMessage = String.format("Resource with UUID: %s already exists", resource.getResourceUUID()); + this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deployStatus, + errorMessage); + } + } + + protected boolean isCsarAlreadyDeployed(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) { + VfResourceStructure resourceStructure = null; + String errorMessage = ""; + boolean csarAlreadyDeployed = false; + DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK; + WatchdogComponentDistributionStatus wdStatus = + new WatchdogComponentDistributionStatus(iNotif.getDistributionID(), MSO); + try { + csarAlreadyDeployed = toscaInstaller.isCsarAlreadyDeployed(toscaResourceStructure); + if (csarAlreadyDeployed) { + deployStatus = DistributionStatusEnum.ALREADY_DEPLOYED; + resourceStructure = new VfResourceStructure(iNotif, null); + errorMessage = String.format("Csar with UUID: %s already exists", + toscaResourceStructure.getToscaArtifact().getArtifactUUID()); + wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name()); + watchdogCDStatusRepository.saveAndFlush(wdStatus); + logger.error(errorMessage); + } + } catch (ArtifactInstallerException e) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + resourceStructure = new VfResourceStructure(iNotif, null); + errorMessage = e.getMessage(); + wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name()); + watchdogCDStatusRepository.saveAndFlush(wdStatus); + logger.warn("Tosca Checksums don't match, Tosca validation check failed", e); + } + + if (deployStatus != DistributionStatusEnum.DEPLOY_OK) { + notifyErrorToAsdc(iNotif, toscaResourceStructure, deployStatus, resourceStructure, errorMessage); + } + + return csarAlreadyDeployed; + } protected IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact, String distributionId) throws ASDCDownloadException { @@ -376,23 +429,14 @@ public class ASDCController { } protected void sendCsarDeployNotification(INotificationData iNotif, ResourceStructure resourceStructure, - ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) { + ToscaResourceStructure toscaResourceStructure, DistributionStatusEnum statusEnum, String errorReason) { IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact(); - if (deploySuccessful) { - - this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(), - asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(), - DistributionStatusEnum.DEPLOY_OK, errorReason, System.currentTimeMillis()); - - } else { - - this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(), - asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(), - DistributionStatusEnum.DEPLOY_ERROR, errorReason, System.currentTimeMillis()); + this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(), asdcConfig.getConsumerID(), + resourceStructure.getNotification().getDistributionID(), statusEnum, errorReason, + System.currentTimeMillis()); - } } protected void deployResourceStructure(ResourceStructure resourceStructure, @@ -657,7 +701,7 @@ public class ASDCController { String msoConfigPath = getMsoConfigPath(); boolean hasVFResource = false; ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath); - boolean deploySuccessful = true; + DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK; String errorMessage = null; boolean serviceDeployed = false; @@ -667,16 +711,21 @@ public class ASDCController { String filePath = msoConfigPath + "/ASDC/" + iArtifact.getArtifactVersion() + "/" + iArtifact.getArtifactName(); File csarFile = new File(filePath); - String csarFilePath = csarFile.getAbsolutePath(); + + + if (isCsarAlreadyDeployed(iNotif, toscaResourceStructure)) { + return; + } for (IResourceInstance resource : iNotif.getResources()) { String resourceType = resource.getResourceType(); - String category = resource.getCategory(); + logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID()); - if ("VF".equals(resourceType)) { + if ("VF".equals(resourceType) && resource.getArtifacts() != null + && !resource.getArtifacts().isEmpty()) { resourceStructure = new VfResourceStructure(iNotif, resource); } else if ("PNF".equals(resourceType)) { resourceStructure = new PnfResourceStructure(iNotif, resource); @@ -694,7 +743,8 @@ public class ASDCController { logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: " + resourceStructure.getResourceInstance().getResourceUUID()); - if ("VF".equals(resourceType)) { + if ("VF".equals(resourceType) && resource.getArtifacts() != null + && !resource.getArtifacts().isEmpty()) { hasVFResource = true; for (IArtifactInfo artifact : resource.getArtifacts()) { IDistributionClientDownloadResult resultArtifact = @@ -730,7 +780,7 @@ public class ASDCController { } } catch (ArtifactInstallerException e) { - deploySuccessful = false; + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; errorMessage = e.getMessage(); logger.error("Exception occurred", e); } @@ -743,12 +793,12 @@ public class ASDCController { try { this.deployResourceStructure(resourceStructure, toscaResourceStructure); } catch (ArtifactInstallerException e) { - deploySuccessful = false; + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; errorMessage = e.getMessage(); logger.error("Exception occurred", e); } } - this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deploySuccessful, + this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deployStatus, errorMessage); } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 23c31f3298..85943edda8 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -121,6 +121,7 @@ import org.onap.so.db.catalog.data.repository.PnfResourceRepository; import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository; import org.onap.so.db.catalog.data.repository.ServiceRepository; import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository; +import org.onap.so.db.catalog.data.repository.ToscaCsarRepository; import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository; import org.onap.so.db.catalog.data.repository.VFModuleRepository; import org.onap.so.db.catalog.data.repository.VnfResourceRepository; @@ -241,6 +242,9 @@ public class ToscaResourceInstaller { @Autowired protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository; + @Autowired + protected ToscaCsarRepository toscaCsarRepo; + @Autowired protected PnfResourceRepository pnfResourceRepository; @@ -252,6 +256,31 @@ public class ToscaResourceInstaller { protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class); + public boolean isCsarAlreadyDeployed(ToscaResourceStructure toscaResourceStructure) + throws ArtifactInstallerException { + boolean deployed = false; + if (toscaResourceStructure == null) { + return deployed; + } + + IArtifactInfo inputToscaCsar = toscaResourceStructure.getToscaArtifact(); + String checkSum = inputToscaCsar.getArtifactChecksum(); + String artifactUuid = inputToscaCsar.getArtifactUUID(); + + Optional toscaCsarObj = toscaCsarRepo.findById(artifactUuid); + if (toscaCsarObj.isPresent()) { + ToscaCsar toscaCsar = toscaCsarObj.get(); + if (!toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) { + String errorMessage = + String.format("Csar with UUID: %s already exists.Their checksums don't match", artifactUuid); + throw new ArtifactInstallerException(errorMessage); + } else if (toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) { + deployed = true; + } + } + return deployed; + } + public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed) throws ArtifactInstallerException { boolean status = false; diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java index ce70a252c9..dd107f7775 100644 --- a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java +++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java @@ -24,12 +24,14 @@ import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; import org.hibernate.exception.LockAcquisitionException; @@ -39,6 +41,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.IResourceInstance; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl; @@ -58,15 +61,17 @@ import org.onap.so.db.catalog.beans.ConfigurationResource; import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; +import org.onap.so.db.catalog.beans.ToscaCsar; import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository; import org.onap.so.db.catalog.data.repository.AllottedResourceRepository; import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository; import org.onap.so.db.catalog.data.repository.ServiceRepository; +import org.onap.so.db.catalog.data.repository.ToscaCsarRepository; import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.util.ReflectionTestUtils; - +import java.util.Optional; public class ToscaResourceInstallerTest extends BaseTest { @Autowired @@ -116,6 +121,37 @@ public class ToscaResourceInstallerTest extends BaseTest { statusData = new JsonStatusData(); } + @Test + public void isCsarAlreadyDeployedTest() throws ArtifactInstallerException { + IArtifactInfo inputCsar = mock(IArtifactInfo.class); + String artifactUuid = "0122c05e-e13a-4c63-b5d2-475ccf13aa74"; + String checkSum = "MGUzNjJjMzk3OTBkYzExYzQ0MDg2ZDc2M2E2ZjZiZmY="; + + doReturn(checkSum).when(inputCsar).getArtifactChecksum(); + doReturn(artifactUuid).when(inputCsar).getArtifactUUID(); + + doReturn(inputCsar).when(toscaResourceStructure).getToscaArtifact(); + + ToscaCsar toscaCsar = mock(ToscaCsar.class); + + Optional returnValue = Optional.of(toscaCsar); + + ToscaCsarRepository toscaCsarRepo = spy(ToscaCsarRepository.class); + + + doReturn(artifactUuid).when(toscaCsar).getArtifactUUID(); + doReturn(checkSum).when(toscaCsar).getArtifactChecksum(); + doReturn(returnValue).when(toscaCsarRepo).findById(artifactUuid); + + ReflectionTestUtils.setField(toscaInstaller, "toscaCsarRepo", toscaCsarRepo); + + boolean isCsarDeployed = toscaInstaller.isCsarAlreadyDeployed(toscaResourceStructure); + assertTrue(isCsarDeployed); + verify(toscaCsarRepo, times(1)).findById(artifactUuid); + verify(toscaResourceStructure, times(1)).getToscaArtifact(); + verify(toscaCsar, times(2)).getArtifactChecksum(); + } + @Test public void isResourceAlreadyDeployedTest() throws Exception { notificationData.setServiceName("serviceName"); -- cgit 1.2.3-korg From 54b6e6ac185b55d89248cd3c55b1d7766ecaf294 Mon Sep 17 00:00:00 2001 From: "Merkel, Jeff" Date: Mon, 29 Apr 2019 10:48:13 -0400 Subject: Check to make sure Heat records do not exist. - Replaced index assert statements with stream(). - Updated the UT to retrieve from the service object for the assert statements. - Added check to make sure Heat records don't already exist. Change-Id: Ife02303e7b3f5c7d132fb9c1baebaa3787a18494 Issue-ID: SO-1818 Signed-off-by: Benjamin, Max (mb388a) --- .../installer/heat/ToscaResourceInstaller.java | 146 ++++++++++++--------- .../data/repository/HeatFilesRepository.java | 30 +++++ 2 files changed, 117 insertions(+), 59 deletions(-) create mode 100644 mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/HeatFilesRepository.java diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 85943edda8..4e97b5f290 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -112,6 +112,8 @@ import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomization import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository; import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository; import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository; +import org.onap.so.db.catalog.data.repository.HeatEnvironmentRepository; +import org.onap.so.db.catalog.data.repository.HeatFilesRepository; import org.onap.so.db.catalog.data.repository.HeatTemplateRepository; import org.onap.so.db.catalog.data.repository.InstanceGroupRepository; import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository; @@ -226,6 +228,12 @@ public class ToscaResourceInstaller { @Autowired protected HeatTemplateRepository heatRepo; + @Autowired + protected HeatEnvironmentRepository heatEnvRepo; + + @Autowired + protected HeatFilesRepository heatFilesRepo; + @Autowired protected NetworkResourceCustomizationRepository networkCustomizationRepo; @@ -1137,77 +1145,95 @@ public class ToscaResourceInstaller { protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure, ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) { - HeatTemplate heatTemplate = new HeatTemplate(); - List typeList = new ArrayList<>(); - typeList.add(ASDCConfiguration.HEAT_NESTED); - typeList.add(ASDCConfiguration.HEAT_ARTIFACT); - heatTemplate.setTemplateBody( - verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); - heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + HeatTemplate existingHeatTemplate = + heatRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) { - heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout()); - } else { - heatTemplate.setTimeoutMinutes(240); - } + if (existingHeatTemplate == null) { + HeatTemplate heatTemplate = new HeatTemplate(); + List typeList = new ArrayList<>(); + typeList.add(ASDCConfiguration.HEAT_NESTED); + typeList.add(ASDCConfiguration.HEAT_ARTIFACT); - heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatTemplate.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatTemplate.setTemplateBody( + verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); + heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); - } else { - heatTemplate.setArtifactChecksum(MANUAL_RECORD); - } + if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) { + heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout()); + } else { + heatTemplate.setTimeoutMinutes(240); + } + + heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatTemplate.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatTemplate.setArtifactChecksum(MANUAL_RECORD); + } - Set heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(), - vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - heatTemplate.setParameters(heatParam); - vfModuleArtifact.setHeatTemplate(heatTemplate); + Set heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(), + vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatTemplate.setParameters(heatParam); + vfModuleArtifact.setHeatTemplate(heatTemplate); + } } protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure, VfModuleArtifact vfModuleArtifact) { - HeatEnvironment heatEnvironment = new HeatEnvironment(); - heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - List typeList = new ArrayList<>(); - typeList.add(ASDCConfiguration.HEAT); - typeList.add(ASDCConfiguration.HEAT_VOL); - heatEnvironment.setEnvironment( - verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); - heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatEnvironment.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); - } else { - heatEnvironment.setArtifactChecksum(MANUAL_RECORD); + + HeatEnvironment existingHeatEnvironment = + heatEnvRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (existingHeatEnvironment == null) { + HeatEnvironment heatEnvironment = new HeatEnvironment(); + heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + List typeList = new ArrayList<>(); + typeList.add(ASDCConfiguration.HEAT); + typeList.add(ASDCConfiguration.HEAT_VOL); + heatEnvironment.setEnvironment( + verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); + heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatEnvironment.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatEnvironment.setArtifactChecksum(MANUAL_RECORD); + } + vfModuleArtifact.setHeatEnvironment(heatEnvironment); } - vfModuleArtifact.setHeatEnvironment(heatEnvironment); } protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure, VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) { - HeatFiles heatFile = new HeatFiles(); - heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatFile.setFileBody(vfModuleArtifact.getResult()); - heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - heatFile.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); - } else { - heatFile.setArtifactChecksum(MANUAL_RECORD); + HeatFiles existingHeatFiles = + heatFilesRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (existingHeatFiles == null) { + HeatFiles heatFile = new HeatFiles(); + heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatFile.setFileBody(vfModuleArtifact.getResult()); + heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + heatFile.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatFile.setArtifactChecksum(MANUAL_RECORD); + } + vfModuleArtifact.setHeatFiles(heatFile); + } - vfModuleArtifact.setHeatFiles(heatFile); } protected Service createService(ToscaResourceStructure toscaResourceStructure, @@ -2153,10 +2179,12 @@ public class ToscaResourceInstaller { vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment()); vfModuleArtifact.incrementDeployedInDB(); } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) { - if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) { - vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment()); - } else { - vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment()); + if (vfModuleArtifact.getHeatEnvironment() != null) { + if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) { + vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment()); + } else { + vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment()); + } } vfModuleArtifact.incrementDeployedInDB(); } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) { diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/HeatFilesRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/HeatFilesRepository.java new file mode 100644 index 0000000000..acefb75b5a --- /dev/null +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/HeatFilesRepository.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog.data.repository; + +import org.onap.so.db.catalog.beans.HeatFiles; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource(collectionResourceRel = "heatFiles", path = "heatFiles") +public interface HeatFilesRepository extends JpaRepository { + HeatFiles findByArtifactUuid(String artifactUUID); +} -- cgit 1.2.3-korg