summaryrefslogtreecommitdiffstats
path: root/asdc-controller/src
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2019-04-29 12:40:42 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-29 12:40:42 +0000
commitf0559cfb0674061d05859a90be4b6462897be951 (patch)
tree6037bf091d07d64781ba2fde0d256f328fcf8d0a /asdc-controller/src
parenta992190b495d69cbd06ef83fb980cb586e1ba909 (diff)
parent47ace9d3fa552b3c19c8894d039841fe7ce91958 (diff)
Merge "repeat distribution transaction error" into dublin
Diffstat (limited to 'asdc-controller/src')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java92
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java29
-rw-r--r--asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java38
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;
@@ -92,6 +94,9 @@ public class ASDCController {
private WatchdogDistributionStatusRepository wdsRepo;
@Autowired
+ protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository;
+
+ @Autowired
private ASDCConfiguration asdcConfig;
@Autowired
@@ -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;
@@ -242,6 +243,9 @@ public class ToscaResourceInstaller {
protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
@Autowired
+ protected ToscaCsarRepository toscaCsarRepo;
+
+ @Autowired
protected PnfResourceRepository pnfResourceRepository;
@Autowired
@@ -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<ToscaCsar> 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
@@ -117,6 +122,37 @@ public class ToscaResourceInstallerTest extends BaseTest {
}
@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<ToscaCsar> 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");
notificationData.setServiceVersion("123456");