summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xms/blueprintsprocessor/parent/pom.xml3
-rw-r--r--ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java12
-rw-r--r--ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java10
-rw-r--r--ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java43
-rw-r--r--ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java (renamed from ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/DistributionStatusMessage.java)24
-rw-r--r--ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java65
-rw-r--r--ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java16
-rwxr-xr-xms/sdclistener/parent/pom.xml1
8 files changed, 124 insertions, 50 deletions
diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml
index 31101e65a..e2824048e 100755
--- a/ms/blueprintsprocessor/parent/pom.xml
+++ b/ms/blueprintsprocessor/parent/pom.xml
@@ -40,7 +40,6 @@
<jsch.version>0.1.55</jsch.version>
<protobuff.java.utils.version>3.6.1</protobuff.java.utils.version>
<eelf.version>1.0.0</eelf.version>
- <sli.version>0.4.2-SNAPSHOT</sli.version>
<guava.version>27.0.1-jre</guava.version>
<jython.version>2.7.1</jython.version>
<springfox.swagger2.version>2.9.2</springfox.swagger2.version>
@@ -248,7 +247,7 @@
<dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
<artifactId>sli-provider</artifactId>
- <version>${sli.version}</version>
+ <version>${ccsdk.sli.core.version}</version>
<exclusions>
<exclusion>
<groupId>commons-lang</groupId>
diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java
index 67db02e77..d5f156e55 100644
--- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java
+++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java
@@ -24,6 +24,7 @@ import java.util.Objects;
import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
import org.onap.ccsdk.cds.sdclistener.service.ListenerService;
import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus;
+import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType;
import org.onap.ccsdk.cds.sdclistener.util.FileUtil;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.consumer.INotificationCallback;
@@ -80,7 +81,9 @@ public class SdcListenerNotificationCallback implements INotificationCallback {
*/
private void downloadCsarArtifacts(IArtifactInfo info, IDistributionClient distributionClient) {
final String url = info.getArtifactURL();
+ sdcListenerDto.setArtifactUrl(url);
final String id = info.getArtifactUUID();
+ final String distributionId = sdcListenerDto.getDistributionId();
if (Objects.equals(info.getArtifactType(), SdcListenerConfiguration.TOSCA_CSAR)) {
LOGGER.info("Trying to download the artifact from : {} and UUID is {} ", url, id);
@@ -89,12 +92,15 @@ public class SdcListenerNotificationCallback implements INotificationCallback {
IDistributionClientDownloadResult result = distributionClient.download(info);
if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) {
- String errorMessage = String.format("Failed to download the artifact from : %s due to %s ", url,
+ final String errorMessage = String.format("Failed to download the artifact from : %s due to %s ", url,
result.getDistributionActionResult());
- listenerStatus.sendResponseStatusBackToSDC(sdcListenerDto.getDistributionId(),
- DistributionStatusEnum.COMPONENT_DONE_ERROR, errorMessage);
+ listenerStatus
+ .sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, errorMessage,
+ url, NotificationType.DOWNLOAD);
LOGGER.error(errorMessage);
} else {
+ listenerStatus.sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_OK, null, url,
+ NotificationType.DOWNLOAD);
LOGGER.info("Trying to write CSAR artifact to file with URL {} and UUID {}", url, id);
processCsarArtifact(result);
}
diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java
index c7c3d4829..a59022c3f 100644
--- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java
+++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java
@@ -34,6 +34,8 @@ public class SdcListenerDto {
@Value("${listenerservice.config.grpcPort}")
private int grpcPort;
+ private String artifactUrl;
+
@Autowired
private SdcListenerAuthClientInterceptor sdcListenerAuthClientInterceptor;
@@ -67,4 +69,12 @@ public class SdcListenerDto {
public ManagedChannel getManagedChannelForGrpc() {
return managedChannel;
}
+
+ public String getArtifactUrl() {
+ return artifactUrl;
+ }
+
+ public void setArtifactUrl(String artifactUrl) {
+ this.artifactUrl = artifactUrl;
+ }
}
diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java
index d1aac9704..c78505377 100644
--- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java
+++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java
@@ -15,6 +15,8 @@
*/
package org.onap.ccsdk.cds.sdclistener.service;
+import static java.lang.String.format;
+import static org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType.SDC_LISTENER_COMPONENT;
import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_ERROR;
import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK;
import com.google.protobuf.ByteString;
@@ -80,7 +82,8 @@ public class ListenerServiceImpl implements ListenerService {
@Override
public void extractBluePrint(String csarArchivePath, String cbaArchivePath) {
int validPathCount = 0;
- final String distributionId = sdcListenerDto.getDistributionId();
+ final String distributionId = getDistributionId();
+ final String artifactUrl = getArtifactUrl();
Path cbaStorageDir = getStorageDirectory(cbaArchivePath);
try (ZipFile zipFile = new ZipFile(csarArchivePath)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
@@ -96,15 +99,17 @@ public class ListenerServiceImpl implements ListenerService {
}
if (validPathCount == 0) {
- final String errorMessage = String
- .format("The CBA Archive doesn't exist as per this given regex %s", CBA_ZIP_PATH);
- listenerStatus.sendResponseStatusBackToSDC(distributionId, COMPONENT_DONE_ERROR, errorMessage);
- LOGGER.error(errorMessage);
+ LOGGER
+ .info("CBA archive doesn't exist in the CSAR Package or it doesn't exist as per the given path {}",
+ CBA_ZIP_PATH);
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_OK, null,
+ artifactUrl, SDC_LISTENER_COMPONENT);
}
} catch (Exception e) {
- final String errorMessage = String.format("Failed to extract blueprint %s", e.getMessage());
- listenerStatus.sendResponseStatusBackToSDC(distributionId, COMPONENT_DONE_ERROR, errorMessage);
+ final String errorMessage = format("Failed to extract blueprint %s", e.getMessage());
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage,
+ artifactUrl, SDC_LISTENER_COMPONENT);
LOGGER.error(errorMessage);
}
}
@@ -177,7 +182,8 @@ public class ListenerServiceImpl implements ListenerService {
}
private void prepareRequestForCdsBackend(List<File> files, ManagedChannel managedChannel, String path) {
- final String distributionId = sdcListenerDto.getDistributionId();
+ final String distributionId = getDistributionId();
+ final String artifactUrl = getArtifactUrl();
files.forEach(zipFile -> {
try {
@@ -187,18 +193,21 @@ public class ListenerServiceImpl implements ListenerService {
final Status responseStatus = bluePrintProcesssorHandler.sendRequest(request, managedChannel);
if (responseStatus.getCode() != SUCCESS_CODE) {
- final String errorMessage = String.format("Failed to store the CBA archive into CDS DB due to %s",
+ final String errorMessage = format("Failed to store the CBA archive into CDS DB due to %s",
responseStatus.getErrorMessage());
- listenerStatus.sendResponseStatusBackToSDC(distributionId, COMPONENT_DONE_ERROR, errorMessage);
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl,
+ SDC_LISTENER_COMPONENT);
LOGGER.error(errorMessage);
} else {
LOGGER.info(responseStatus.getMessage());
- listenerStatus.sendResponseStatusBackToSDC(distributionId, COMPONENT_DONE_OK, null);
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_OK, null, artifactUrl,
+ SDC_LISTENER_COMPONENT);
}
} catch (Exception e) {
- final String errorMessage = String.format("Failure due to %s", e.getMessage());
- listenerStatus.sendResponseStatusBackToSDC(distributionId, COMPONENT_DONE_ERROR, errorMessage);
+ final String errorMessage = format("Failure due to %s", e.getMessage());
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl,
+ SDC_LISTENER_COMPONENT);
LOGGER.error(errorMessage);
} finally {
FileUtil.deleteFile(zipFile, path);
@@ -214,4 +223,12 @@ public class ListenerServiceImpl implements ListenerService {
.setFileChunk(fileChunk)
.build();
}
+
+ private String getDistributionId() {
+ return sdcListenerDto.getDistributionId();
+ }
+
+ private String getArtifactUrl() {
+ return sdcListenerDto.getArtifactUrl();
+ }
}
diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/DistributionStatusMessage.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java
index 60463762b..7a959692a 100644
--- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/DistributionStatusMessage.java
+++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java
@@ -15,10 +15,11 @@
*/
package org.onap.ccsdk.cds.sdclistener.status;
-import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
+import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+import org.onap.sdc.api.consumer.IDistributionStatusMessage;
import org.onap.sdc.utils.DistributionStatusEnum;
-public class DistributionStatusMessage implements IFinalDistrStatusMessage {
+public class ComponentStatusMessage implements IComponentDoneStatusMessage, IDistributionStatusMessage {
public String componentName;
@@ -28,17 +29,16 @@ public class DistributionStatusMessage implements IFinalDistrStatusMessage {
public DistributionStatusEnum status;
+ public long timeStamp;
+
+ public String artifactUrl;
+
@Override
public String getDistributionID() {
return distributionID;
}
@Override
- public long getTimestamp() {
- return 0;
- }
-
- @Override
public DistributionStatusEnum getStatus() {
return status;
}
@@ -52,4 +52,14 @@ public class DistributionStatusMessage implements IFinalDistrStatusMessage {
public String getComponentName() {
return componentName;
}
+
+ @Override
+ public String getArtifactURL() {
+ return artifactUrl;
+ }
+
+ @Override
+ public long getTimestamp() {
+ return timeStamp;
+ }
}
diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java
index ff64c0d0c..446fdc068 100644
--- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java
+++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java
@@ -20,7 +20,8 @@ import java.util.Objects;
import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
import org.onap.ccsdk.cds.sdclistener.util.BuilderUtil;
import org.onap.sdc.api.IDistributionClient;
-import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
+import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+import org.onap.sdc.api.consumer.IDistributionStatusMessage;
import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.utils.DistributionStatusEnum;
import org.slf4j.Logger;
@@ -45,32 +46,62 @@ public class SdcListenerStatus {
@Autowired
private SdcListenerDto sdcListenerDto;
+ public enum NotificationType {
+ DOWNLOAD, SDC_LISTENER_COMPONENT;
+ }
+
/**
- * Send the response back to SDC.
- *
+ * Send the component status back to SDC.
* @param distributionID SDC Distribution ID
* @param status Distribution status
- * @param errorReason Reason of failure
+ * @param errorReason Reason of failure if present
+ * @param url Artifact URL
+ * @param type - NotificationType(Download or Component)
*/
- public void sendResponseStatusBackToSDC(String distributionID, DistributionStatusEnum status, String errorReason) {
-
+ public void sendResponseBackToSdc(String distributionID, DistributionStatusEnum status, String errorReason,
+ String url, NotificationType type) {
final IDistributionClient distributionClient = sdcListenerDto.getDistributionClient();
- IFinalDistrStatusMessage finalDistribution = new BuilderUtil<>(new DistributionStatusMessage())
- .build(builder -> {
- builder.distributionID = distributionID;
- builder.status = status;
- builder.consumerID = consumerId;
- builder.componentName = COMPONENT_NAME;
- }).create();
+ switch (type) {
+ case SDC_LISTENER_COMPONENT:
+ IComponentDoneStatusMessage componentStatusMessage = buildStatusMessage(distributionID, status, url,
+ COMPONENT_NAME);
- if (errorReason == null) {
- checkResponseStatusFromSdc(distributionClient.sendFinalDistrStatus(finalDistribution));
- } else {
- checkResponseStatusFromSdc(distributionClient.sendFinalDistrStatus(finalDistribution, errorReason));
+ if (errorReason == null) {
+ checkResponseStatusFromSdc(distributionClient.sendComponentDoneStatus(componentStatusMessage));
+ } else {
+ checkResponseStatusFromSdc(
+ distributionClient.sendComponentDoneStatus(componentStatusMessage, errorReason));
+ }
+ break;
+
+ case DOWNLOAD:
+ IDistributionStatusMessage downloadStatusMessage = buildStatusMessage(distributionID, status, url,
+ null);
+
+ if (errorReason == null) {
+ checkResponseStatusFromSdc(distributionClient.sendDownloadStatus(downloadStatusMessage));
+ } else {
+ checkResponseStatusFromSdc(
+ distributionClient.sendDownloadStatus(downloadStatusMessage, errorReason));
+ }
+ default:
+ break;
}
}
+ private ComponentStatusMessage buildStatusMessage(String distributionId, DistributionStatusEnum status, String url,
+ String componentName) {
+ return new BuilderUtil<>(new ComponentStatusMessage()).build(builder -> {
+ builder.distributionID = distributionId;
+ builder.status = status;
+ builder.consumerID = consumerId;
+ builder.componentName = componentName;
+ builder.timeStamp = System.currentTimeMillis();
+ builder.artifactUrl = url;
+ }).create();
+ }
+
private void checkResponseStatusFromSdc(IDistributionClientResult result) {
if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) {
LOGGER.error("SDC failed to receive the response from cds-sdc listener due to {}",
diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java
index aed4b8b30..ecb753892 100644
--- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java
+++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java
@@ -16,13 +16,14 @@
package org.onap.ccsdk.cds.sdclistener.service;
import static junit.framework.TestCase.assertTrue;
+import static org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType.SDC_LISTENER_COMPONENT;
import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_ERROR;
+import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import mockit.Mock;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
@@ -31,18 +32,16 @@ import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.internal.junit.JUnitRule;
import org.mockito.junit.MockitoJUnit;
-import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.MockitoRule;
import org.onap.ccsdk.cds.sdclistener.SdcListenerConfiguration;
import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor;
import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
import org.onap.ccsdk.cds.sdclistener.handler.BluePrintProcesssorHandler;
import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus;
+import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.onap.sdc.impl.mock.DistributionClientResultStubImpl;
-import org.onap.sdc.utils.DistributionStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
@@ -62,6 +61,7 @@ public class ListenerServiceImplTest {
private static final String ZIP_FILE = ".zip";
private static final String CSAR_FILE = ".csar";
private static final String DISTRIBUTION_ID = "1";
+ private static final String URL = "/sdc/v1/artifact";
private String csarArchivePath;
@@ -94,7 +94,7 @@ public class ListenerServiceImplTest {
// Act
listenerService.extractBluePrint(CSAR_SAMPLE, tempDirectoryPath.toString());
- // Verify
+ // Verify.
String result = checkFileExists(tempDirectoryPath);
assertTrue(result.contains(ZIP_FILE));
}
@@ -105,14 +105,16 @@ public class ListenerServiceImplTest {
final String errorMessage = String
.format("The CBA Archive doesn't exist as per this given regex %s", CBA_ZIP_PATH);
Mockito.when(listenerDto.getDistributionId()).thenReturn(DISTRIBUTION_ID);
+ Mockito.when(listenerDto.getArtifactUrl()).thenReturn(URL);
Mockito.doCallRealMethod().when(status)
- .sendResponseStatusBackToSDC(DISTRIBUTION_ID, COMPONENT_DONE_ERROR, errorMessage);
+ .sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, SDC_LISTENER_COMPONENT);
// Act
listenerService.extractBluePrint(WRONG_CSAR_SAMPLE, tempDirectoryPath.toString());
// Verify
- Mockito.verify(status).sendResponseStatusBackToSDC(DISTRIBUTION_ID, COMPONENT_DONE_ERROR, errorMessage);
+ Mockito.verify(status)
+ .sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, SDC_LISTENER_COMPONENT);
}
@Test
diff --git a/ms/sdclistener/parent/pom.xml b/ms/sdclistener/parent/pom.xml
index e99bf472d..714dc7e88 100755
--- a/ms/sdclistener/parent/pom.xml
+++ b/ms/sdclistener/parent/pom.xml
@@ -34,7 +34,6 @@
<grpc.version>1.18.0</grpc.version>
<protobuff.java.utils.version>3.6.1</protobuff.java.utils.version>
<eelf.version>1.0.0</eelf.version>
- <sli.version>0.4.2-SNAPSHOT</sli.version>
<guava.version>27.0.1-jre</guava.version>
<onap.logger.slf4j>1.2.2</onap.logger.slf4j>
<powermock.version>1.7.4</powermock.version>