summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorprathamesh morde <prathamesh.morde@bell.ca>2019-04-10 23:00:24 -0400
committerprathamesh morde <prathamesh.morde@bell.ca>2019-04-11 17:53:27 -0400
commit4c53d7cce07ee64ab77d9fea73ca8ce16d13fe45 (patch)
tree01b4b65f44e48fad48bd3b39ccd74c9c8d4afeb0
parent0c0e1d2e6d5e57a99ff8551a2d7b8e9cdab7d860 (diff)
CDS-Listener should send response back to SDC
-Added notification logic so the listener will send response back to SDC. (Fail to download, Fail to upload and succesfully uploaded for this conditions now) -Some bug fixes. -Made use of correct copyright header Change-Id: Iefc108dbdd2bec048fd55630822c99ee1b13bab5 Issue-ID: CCSDK-1201 Signed-off-by: prathamesh morde <prathamesh.morde@bell.ca>
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerApplication.java17
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfiguration.java18
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerNotificationCallback.java58
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerAuthClientInterceptor.java16
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerClient.java25
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/dto/CdsSdcListenerDto.java53
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/exceptions/CdsSdcListenerException.java17
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcesssorHandler.java17
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerService.java23
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImpl.java96
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/CdsSdcListenerStatus.java83
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/DistributionStatusMessage.java55
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/BuilderUtil.java33
-rw-r--r--ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/FileUtil.java61
-rw-r--r--ms/cds-sdc-listener/application/src/main/resources/application.yml4
-rw-r--r--ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java19
-rw-r--r--ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java19
-rw-r--r--ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java18
-rw-r--r--ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java59
19 files changed, 550 insertions, 141 deletions
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerApplication.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerApplication.java
index 30f101246..6f0f65323 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerApplication.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerApplication.java
@@ -1,11 +1,18 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener;
import org.springframework.boot.SpringApplication;
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfiguration.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfiguration.java
index 242c19c1e..3dfb07eb8 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfiguration.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfiguration.java
@@ -1,11 +1,18 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener;
import java.util.List;
@@ -58,7 +65,6 @@ public class CdsSdcListenerConfiguration implements IConfiguration {
@Value("${listenerservice.config.isUseHttpsWithDmaap}")
private boolean isUseHttpsWithDmaap;
-
@Override
public String getAsdcAddress() {
return asdcAddress;
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerNotificationCallback.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerNotificationCallback.java
index e2aae9654..58c667c26 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerNotificationCallback.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerNotificationCallback.java
@@ -1,11 +1,18 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener;
import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS;
@@ -16,12 +23,15 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto;
-import org.onap.ccsdk.cds.cdssdclistener.service.ListenerServiceImpl;
+import org.onap.ccsdk.cds.cdssdclistener.service.ListenerService;
+import org.onap.ccsdk.cds.cdssdclistener.status.CdsSdcListenerStatus;
+import org.onap.ccsdk.cds.cdssdclistener.util.FileUtil;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.consumer.INotificationCallback;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
+import org.onap.sdc.utils.DistributionStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,16 +49,21 @@ public class CdsSdcListenerNotificationCallback implements INotificationCallback
private CdsSdcListenerDto cdsSdcListenerDto;
@Autowired
- private ListenerServiceImpl listenerService;
+ private ListenerService listenerService;
@Value("${listenerservice.config.archivePath}")
private String pathToStoreArchives;
+ @Autowired
+ private CdsSdcListenerStatus listenerStatus;
+
private static final Logger LOGGER = LoggerFactory.getLogger(CdsSdcListenerNotificationCallback.class);
@Override
public void activateCallback(INotificationData notificationData) {
- LOGGER.info(notificationData.getDistributionID(), "The UUID generated by SDC {}");
+ final String distributionId = notificationData.getDistributionID();
+ cdsSdcListenerDto.setDistributionId(distributionId);
+ LOGGER.info("Received service distribution from SDC with the id {}", distributionId);
processNotification(notificationData);
}
@@ -75,8 +90,11 @@ public class CdsSdcListenerNotificationCallback implements INotificationCallback
IDistributionClientDownloadResult result = distributionClient.download(info);
if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) {
- LOGGER.error("Failed to download the artifact from : {} due to {} ", url,
+ String errorMessage = String.format("Failed to download the artifact from : %s due to %s ", url,
result.getDistributionActionResult());
+ listenerStatus.sendResponseStatusBackToSDC(cdsSdcListenerDto.getDistributionId(),
+ DistributionStatusEnum.COMPONENT_DONE_ERROR, errorMessage);
+ LOGGER.error(errorMessage);
} else {
LOGGER.info("Trying to write CSAR artifact to file with URL {} and UUID {}", url, id);
processCsarArtifact(result);
@@ -88,20 +106,24 @@ public class CdsSdcListenerNotificationCallback implements INotificationCallback
Path cbaArchivePath = Paths.get(pathToStoreArchives, "cba-archive");
Path csarArchivePath = Paths.get(pathToStoreArchives, "csar-archive");
- // extract and store the CSAR archive into local disk.
+ // Extract and store the CSAR archive into local disk.
listenerService.extractCsarAndStore(result, csarArchivePath.toString());
- Optional<List<File>> csarFiles = listenerService.getFilesFromDisk(csarArchivePath);
+ Optional<List<File>> csarFiles = FileUtil.getFilesFromDisk(csarArchivePath);
if (csarFiles.isPresent()) {
+ //Extract CBA archive from CSAR package and store it into local disk.
+ List<File> files = csarFiles.get();
- //Extract CBA archive from CSAR package and and store it into CDS Database.
- csarFiles.get()
- .forEach(file -> listenerService.extractBluePrint(file.getAbsolutePath(), cbaArchivePath.toString()));
-
- listenerService.saveBluePrintToCdsDatabase(cbaArchivePath);
- } else {
- LOGGER.error("The CSAR file is not present at this location {}", csarArchivePath);
+ if (!files.isEmpty()) {
+ final String archivePath = cbaArchivePath.toString();
+ files.forEach(file -> listenerService.extractBluePrint(file.getAbsolutePath(), archivePath));
+ files.forEach(file -> FileUtil.deleteFile(file, archivePath));
+ } else {
+ LOGGER.error("The CSAR file is not present at this location {}", csarArchivePath);
+ }
}
+
+ listenerService.saveBluePrintToCdsDatabase(cbaArchivePath, cdsSdcListenerDto.getManagedChannelForGrpc());
}
}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerAuthClientInterceptor.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerAuthClientInterceptor.java
index 528fbe2f3..bae4a3754 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerAuthClientInterceptor.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerAuthClientInterceptor.java
@@ -1,9 +1,17 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
package org.onap.ccsdk.cds.cdssdclistener.client;
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerClient.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerClient.java
index 6f888dd0b..8d6aca5cd 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerClient.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/client/CdsSdcListenerClient.java
@@ -1,9 +1,17 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
package org.onap.ccsdk.cds.cdssdclistener.client;
@@ -51,10 +59,11 @@ public class CdsSdcListenerClient {
distributionClient = Optional.of(DistributionClientFactory.createDistributionClient())
.orElseThrow(() -> new CdsSdcListenerException("Could not able to create SDC Distribution client"));
+ listenerDto.setManagedChannelForGrpc();
+
listenerDto.setDistributionClient(distributionClient);
IDistributionClientResult result = distributionClient.init(configuration, notification);
-
startSdcClientBasedOnTheResult(result);
}
@@ -64,6 +73,8 @@ public class CdsSdcListenerClient {
"SDC distribution client init failed with reason:" + result.getDistributionMessageResult());
}
+ LOG.info("Initialization of the SDC distribution client is complete");
+
// Start the client.
result = this.distributionClient.start();
@@ -74,10 +85,8 @@ public class CdsSdcListenerClient {
}
private void closeSdcDistributionclient() throws CdsSdcListenerException {
-
- IDistributionClientResult status = this.distributionClient.stop();
-
LOG.info("Closing SDC distribution client");
+ IDistributionClientResult status = this.distributionClient.stop();
if (status.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
throw new CdsSdcListenerException(
"Failed to close the SDC distribution client due to : " + status.getDistributionMessageResult());
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/dto/CdsSdcListenerDto.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/dto/CdsSdcListenerDto.java
index 41039eb28..68669307e 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/dto/CdsSdcListenerDto.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/dto/CdsSdcListenerDto.java
@@ -1,19 +1,45 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
package org.onap.ccsdk.cds.cdssdclistener.dto;
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor;
import org.onap.sdc.api.IDistributionClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
+@ConfigurationProperties("listenerservice")
public class CdsSdcListenerDto {
+ @Value("${listenerservice.config.grpcAddress}")
+ private String grpcAddress;
+
+ @Value("${listenerservice.config.grpcPort}")
+ private int grpcPort;
+
+ @Autowired
+ private CdsSdcListenerAuthClientInterceptor cdsSdcListenerAuthClientInterceptor;
+
private IDistributionClient distributionClient;
+ private ManagedChannel managedChannel;
+ private String distributionId;
public IDistributionClient getDistributionClient() {
return distributionClient;
@@ -22,4 +48,23 @@ public class CdsSdcListenerDto {
public void setDistributionClient(IDistributionClient distributionClient) {
this.distributionClient = distributionClient;
}
+
+ public void setDistributionId(String id) {
+ this.distributionId = id;
+ }
+
+ public String getDistributionId() {
+ return distributionId;
+ }
+
+ public void setManagedChannelForGrpc() {
+ managedChannel = ManagedChannelBuilder.forAddress(grpcAddress, grpcPort)
+ .usePlaintext()
+ .intercept(cdsSdcListenerAuthClientInterceptor)
+ .build();
+ }
+
+ public ManagedChannel getManagedChannelForGrpc() {
+ return managedChannel;
+ }
}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/exceptions/CdsSdcListenerException.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/exceptions/CdsSdcListenerException.java
index 09ef4ed8c..eff5ef050 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/exceptions/CdsSdcListenerException.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/exceptions/CdsSdcListenerException.java
@@ -1,11 +1,18 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener.exceptions;
public class CdsSdcListenerException extends Exception {
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcesssorHandler.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcesssorHandler.java
index 6b03b6da2..b05245392 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcesssorHandler.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcesssorHandler.java
@@ -1,11 +1,18 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener.handler;
import io.grpc.ManagedChannel;
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerService.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerService.java
index 1efbe8f33..e55aeb134 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerService.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerService.java
@@ -1,13 +1,21 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener.service;
+import io.grpc.ManagedChannel;
import java.nio.file.Path;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
@@ -25,11 +33,12 @@ public interface ListenerService {
* Store the Zip file into CDS database.
*
* @param path path where zip file exists.
+ * @param managedChannel To access the blueprint processor application end point
*/
- void saveBluePrintToCdsDatabase(Path path);
+ void saveBluePrintToCdsDatabase(Path path, ManagedChannel managedChannel);
/**
- * Extract and store CSAR to file.
+ * Extract and store the csar package to local disk.
*
* @param result - IDistributionClientDownloadResult contains payload.
* @param csarArchivePath The destination path where CSAR will be stored.
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImpl.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImpl.java
index 37052082a..1cf1a1bae 100644
--- a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImpl.java
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImpl.java
@@ -1,17 +1,26 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2017-2019 AT&T, Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
package org.onap.ccsdk.cds.cdssdclistener.service;
import static java.nio.file.Files.walk;
+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;
import io.grpc.ManagedChannel;
-import io.grpc.ManagedChannelBuilder;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -31,7 +40,10 @@ import java.util.zip.ZipFile;
import org.apache.commons.io.FileUtils;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor;
+import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto;
import org.onap.ccsdk.cds.cdssdclistener.handler.BluePrintProcesssorHandler;
+import org.onap.ccsdk.cds.cdssdclistener.status.CdsSdcListenerStatus;
+import org.onap.ccsdk.cds.cdssdclistener.util.FileUtil;
import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput;
import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk;
@@ -53,6 +65,12 @@ public class ListenerServiceImpl implements ListenerService {
@Autowired
private CdsSdcListenerAuthClientInterceptor cdsSdcListenerAuthClientInterceptor;
+ @Autowired
+ private CdsSdcListenerStatus listenerStatus;
+
+ @Autowired
+ private CdsSdcListenerDto cdsSdcListenerDto;
+
@Value("${listenerservice.config.grpcAddress}")
private String grpcAddress;
@@ -61,7 +79,6 @@ public class ListenerServiceImpl implements ListenerService {
private static final String CBA_ZIP_PATH = "Artifacts/Resources/[a-zA-Z0-9-_]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_]+[.]zip";
private static final int SUCCESS_CODE = 200;
- private static final String CSAR_FILE_EXTENSION = ".csar";
private static final Logger LOGGER = LoggerFactory.getLogger(ListenerServiceImpl.class);
@Override
@@ -78,8 +95,9 @@ public class ListenerServiceImpl implements ListenerService {
storeBluePrint(zipFile, cbaArchiveName, cbaStorageDir, entry);
}
}
+
} catch (Exception e) {
- LOGGER.error("Failed to extract blueprint", e);
+ LOGGER.error("Failed to extract blueprint {}", e);
}
}
@@ -97,16 +115,16 @@ public class ListenerServiceImpl implements ListenerService {
try (InputStream inputStream = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(
targetZipFile)) {
IOUtils.copy(inputStream, out);
- LOGGER.info("Succesfully store the CBA archive {} at this location", targetZipFile);
+ LOGGER.info("Successfully store the CBA archive {} at this location", targetZipFile);
} catch (Exception e) {
LOGGER.error("Failed to put zip file into target location {}, {}", targetLocation, e);
}
}
@Override
- public void saveBluePrintToCdsDatabase(Path cbaArchivePath) {
- Optional<List<File>> zipFiles = getFilesFromDisk(cbaArchivePath);
- zipFiles.ifPresent(this::prepareRequestForCdsBackend);
+ public void saveBluePrintToCdsDatabase(Path cbaArchivePath, ManagedChannel channel) {
+ Optional<List<File>> zipFiles = FileUtil.getFilesFromDisk(cbaArchivePath);
+ zipFiles.ifPresent(files -> prepareRequestForCdsBackend(files, channel, cbaArchivePath.toString()));
}
@Override
@@ -114,9 +132,8 @@ public class ListenerServiceImpl implements ListenerService {
// Create CSAR storage directory
Path csarStorageDir = getStorageDirectory(csarArchivePath);
-
byte[] payload = result.getArtifactPayload();
- String csarFileName = result.getArtifactFilename() + CSAR_FILE_EXTENSION;
+ String csarFileName = result.getArtifactFilename();
Path targetLocation = csarStorageDir.resolve(csarFileName);
LOGGER.info("The target location for the CSAR file is {}", targetLocation);
@@ -137,49 +154,45 @@ public class ListenerServiceImpl implements ListenerService {
try {
return Files.createDirectories(fileStorageLocation);
} catch (IOException e) {
- LOGGER.error("Fail to create directory", e);
+ LOGGER.error("Fail to create directory {}, {}", e, fileStorageLocation);
}
}
return fileStorageLocation;
}
- private void prepareRequestForCdsBackend(List<File> files) {
- final ManagedChannel channel = getManagedChannel();
+ private void prepareRequestForCdsBackend(List<File> files, ManagedChannel managedChannel, String path) {
+ final String distributionId = cdsSdcListenerDto.getDistributionId();
files.forEach(zipFile -> {
try {
final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile);
// Send request to CDS Backend.
- final Status responseStatus = bluePrintProcesssorHandler.sendRequest(request, channel);
+ final Status responseStatus = bluePrintProcesssorHandler.sendRequest(request, managedChannel);
if (responseStatus.getCode() != SUCCESS_CODE) {
- LOGGER.error("Failed to store the CBA archive into CDS DB due to {}",
+ final String errorMessage = String.format("Failed to store the CBA archive into CDS DB due to %s",
responseStatus.getErrorMessage());
+ listenerStatus.sendResponseStatusBackToSDC(distributionId,
+ COMPONENT_DONE_ERROR, errorMessage);
+ LOGGER.error(errorMessage);
+
} else {
LOGGER.info(responseStatus.getMessage());
+ listenerStatus.sendResponseStatusBackToSDC(distributionId,
+ COMPONENT_DONE_OK, null);
}
} catch (Exception e) {
- LOGGER.error("Failure due to", e);
+ final String errorMessage = String.format("Failure due to %s", e.getMessage());
+ listenerStatus.sendResponseStatusBackToSDC(distributionId, COMPONENT_DONE_ERROR, errorMessage);
+ LOGGER.error("Failure due to {}", e);
} finally {
- //Delete the file from the local disk.
- boolean fileDeleted = zipFile.delete();
-
- if (!fileDeleted) {
- LOGGER.error("Could not able to delete the zip file {}", zipFile.toString());
- }
+ FileUtil.deleteFile(zipFile, path);
}
});
}
- private ManagedChannel getManagedChannel() {
- return ManagedChannelBuilder.forAddress(grpcAddress, grpcPort)
- .usePlaintext()
- .intercept(cdsSdcListenerAuthClientInterceptor)
- .build();
- }
-
private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file) throws IOException {
byte[] bytes = FileUtils.readFileToByteArray(file);
FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build();
@@ -188,23 +201,4 @@ public class ListenerServiceImpl implements ListenerService {
.setFileChunk(fileChunk)
.build();
}
-
- /**
- * Extract files from the given path
- *
- * @param path where files reside.
- * @return list of files.
- */
- public Optional<List<File>> getFilesFromDisk(Path path) {
- try (Stream<Path> fileTree = walk(path)) {
- // Get the list of files from the path
- return Optional.of(fileTree.filter(Files::isRegularFile)
- .map(Path::toFile)
- .collect(Collectors.toList()));
- } catch (IOException e) {
- LOGGER.error("Failed to find the file", e);
- }
-
- return Optional.empty();
- }
}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/CdsSdcListenerStatus.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/CdsSdcListenerStatus.java
new file mode 100644
index 000000000..60d3127f9
--- /dev/null
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/CdsSdcListenerStatus.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright © 2019 Bell Canada
+ *
+ * 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.
+ */
+package org.onap.ccsdk.cds.cdssdclistener.status;
+
+import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS;
+import java.util.Objects;
+import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto;
+import org.onap.ccsdk.cds.cdssdclistener.util.BuilderUtil;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.impl.DistributionClientImpl;
+import org.onap.sdc.utils.DistributionStatusEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.stereotype.Component;
+
+@Component
+@ConfigurationProperties("listenerservice")
+@ComponentScan("org.onap.ccsdk.cds.cdssdclistener.dto")
+public class CdsSdcListenerStatus {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CdsSdcListenerStatus.class);
+ private static final String COMPONENT_NAME = "cds";
+
+ @Value("${listenerservice.config.consumerId}")
+ private String consumerId;
+
+ @Autowired
+ private CdsSdcListenerDto cdsSdcListenerDto;
+
+ /**
+ * Send the response back to SDC.
+ *
+ * @param distributionID SDC Distribution ID
+ * @param status Distribution status
+ * @param errorReason Reason of failure
+ */
+ public void sendResponseStatusBackToSDC(String distributionID, DistributionStatusEnum status, String errorReason) {
+
+ final IDistributionClient distributionClient = cdsSdcListenerDto.getDistributionClient();
+
+ IFinalDistrStatusMessage finalDistribution = new BuilderUtil<>(new DistributionStatusMessage())
+ .build(builder -> {
+ builder.distributionID = distributionID;
+ builder.status = status;
+ builder.consumerID = consumerId;
+ builder.componentName = COMPONENT_NAME;
+ }).create();
+
+ if (errorReason == null) {
+ checkResponseStatusFromSdc(distributionClient.sendFinalDistrStatus(finalDistribution));
+ } else {
+ checkResponseStatusFromSdc(distributionClient.sendFinalDistrStatus(finalDistribution, errorReason));
+ }
+ }
+
+ 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 {}",
+ result.getDistributionMessageResult());
+ } else {
+ LOGGER.info("SDC successfully received the response");
+ }
+ }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/DistributionStatusMessage.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/DistributionStatusMessage.java
new file mode 100644
index 000000000..676c85c98
--- /dev/null
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/status/DistributionStatusMessage.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2019 Bell Canada
+ *
+ * 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.
+ */
+package org.onap.ccsdk.cds.cdssdclistener.status;
+
+import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
+import org.onap.sdc.utils.DistributionStatusEnum;
+
+public class DistributionStatusMessage implements IFinalDistrStatusMessage {
+
+ public String componentName;
+
+ public String consumerID;
+
+ public String distributionID;
+
+ public DistributionStatusEnum status;
+
+ @Override
+ public String getDistributionID() {
+ return distributionID;
+ }
+
+ @Override
+ public long getTimestamp() {
+ return 0;
+ }
+
+ @Override
+ public DistributionStatusEnum getStatus() {
+ return status;
+ }
+
+ @Override
+ public String getConsumerID() {
+ return consumerID;
+ }
+
+ @Override
+ public String getComponentName() {
+ return componentName;
+ }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/BuilderUtil.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/BuilderUtil.java
new file mode 100644
index 000000000..4df545c82
--- /dev/null
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/BuilderUtil.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE: All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+package org.onap.ccsdk.cds.cdssdclistener.util;
+
+import java.util.function.Consumer;
+
+/**
+ * A generic builder for constructing an object.
+ *
+ * @param <T> - Any object
+ */
+public class BuilderUtil<T> {
+
+ private final T object;
+
+ public BuilderUtil(T instance) {
+ this.object = instance;
+ }
+
+ public BuilderUtil<T> build(Consumer<T> consumer) {
+ consumer.accept(object);
+ return this;
+ }
+
+ public T create() {
+ return object;
+ }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/FileUtil.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/FileUtil.java
new file mode 100644
index 000000000..11f4eade1
--- /dev/null
+++ b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/cds/cdssdclistener/util/FileUtil.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE: All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+
+package org.onap.ccsdk.cds.cdssdclistener.util;
+
+import static java.nio.file.Files.walk;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class FileUtil {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
+
+ private FileUtil() {
+
+ }
+
+ /**
+ * Delete the file.
+ *
+ * @param file - Given file
+ * @param path - Given path
+ */
+ public static void deleteFile(File file, String path) {
+ boolean value = file.delete();
+ if (!value) {
+ LOGGER.error("Failed to delete the file {} at the location {}", file, path);
+ }
+ }
+
+ /**
+ * Extract files from the given path
+ *
+ * @param path where files reside.
+ * @return list of files.
+ */
+ public static Optional<List<File>> getFilesFromDisk(Path path) {
+ try (Stream<Path> fileTree = walk(path)) {
+ // Get the list of files from the path
+ return Optional.of(fileTree.filter(Files::isRegularFile)
+ .map(Path::toFile)
+ .collect(Collectors.toList()));
+ } catch (IOException e) {
+ LOGGER.error("Failed to find the file due to", e);
+ }
+ return Optional.empty();
+ }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/resources/application.yml b/ms/cds-sdc-listener/application/src/main/resources/application.yml
index 657ea9e80..cb1b54c96 100644
--- a/ms/cds-sdc-listener/application/src/main/resources/application.yml
+++ b/ms/cds-sdc-listener/application/src/main/resources/application.yml
@@ -5,7 +5,7 @@ listenerservice:
user: vid
password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
pollingInterval: 15
- pollingTimeout: 15
+ pollingTimeout: 60
relevantArtifactTypes: TOSCA_CSAR
consumerGroup: cds-id-local
environmentName: AUTO
@@ -14,7 +14,7 @@ listenerservice:
keyStorePath:
activateServerTLSAuth : false
isUseHttpsWithDmaap: false
- archivePath: opt/app/onap/cds-sdc-listener/
+ archivePath: /opt/app/onap/cds-sdc-listener/
grpcAddress: localhost
grpcPort: 9111
authHeader: Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==
diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java
index 948631462..e980c24c6 100644
--- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java
+++ b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java
@@ -1,11 +1,18 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener;
import mockit.Expectations;
@@ -38,7 +45,7 @@ public class CdsSdcListenerClientTest {
@Injectable CdsSdcListenerNotificationCallback notification,
@Injectable CdsSdcListenerDto cdsSdcListenerDto) throws CdsSdcListenerException {
- // Arrange
+ //Arrange
new MockUp<DistributionClientFactory>() {
@Mock
public IDistributionClient createDistributionClient() {
diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java
index 338b9c150..f940db2aa 100644
--- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java
+++ b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java
@@ -1,11 +1,18 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener;
import static org.junit.Assert.assertEquals;
@@ -31,7 +38,7 @@ public class CdsSdcListenerConfigurationTest {
assertEquals(listenerConfiguration.getUser(), "vid");
assertEquals(listenerConfiguration.getPassword(), "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U");
assertEquals(listenerConfiguration.getPollingInterval(), 15);
- assertEquals(listenerConfiguration.getPollingTimeout(), 15);
+ assertEquals(listenerConfiguration.getPollingTimeout(), 60);
assertEquals(listenerConfiguration.getRelevantArtifactTypes().stream().findFirst().get(), "TOSCA_CSAR");
assertEquals(listenerConfiguration.getConsumerGroup(), "cds-id-local");
assertEquals(listenerConfiguration.getEnvironmentName(), "AUTO");
diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java
index 0d38decdf..f700a7dd2 100644
--- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java
+++ b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java
@@ -1,11 +1,18 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener.handler;
import static org.junit.Assert.assertEquals;
@@ -35,7 +42,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-
@RunWith(SpringRunner.class)
@EnableConfigurationProperties({BluePrintProcesssorHandler.class, CdsSdcListenerAuthClientInterceptor.class})
@SpringBootTest(classes = {BluePrintProcessorHandlerTest.class})
diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java
index e33fbcdcc..359ee6cc4 100644
--- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java
+++ b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java
@@ -1,34 +1,48 @@
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * 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.
*/
-
package org.onap.ccsdk.cds.cdssdclistener.service;
import static junit.framework.TestCase.assertTrue;
+import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
+import org.onap.ccsdk.cds.cdssdclistener.CdsSdcListenerConfiguration;
import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor;
+import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto;
import org.onap.ccsdk.cds.cdssdclistener.handler.BluePrintProcesssorHandler;
-import org.onap.sdc.impl.mock.DistributionClientDownloadResultStubImpl;
+import org.onap.ccsdk.cds.cdssdclistener.status.CdsSdcListenerStatus;
+import org.onap.sdc.api.results.IDistributionClientDownloadResult;
+import org.onap.sdc.impl.mock.DistributionClientResultStubImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
-@EnableConfigurationProperties({ListenerServiceImpl.class, CdsSdcListenerAuthClientInterceptor.class,
- BluePrintProcesssorHandler.class})
+@EnableConfigurationProperties({CdsSdcListenerAuthClientInterceptor.class,
+ BluePrintProcesssorHandler.class, CdsSdcListenerDto.class, ListenerServiceImpl.class, CdsSdcListenerStatus.class,
+ CdsSdcListenerConfiguration.class})
@SpringBootTest(classes = {ListenerServiceImplTest.class})
public class ListenerServiceImplTest {
@@ -80,4 +94,33 @@ public class ListenerServiceImplTest {
.get()
.getName();
}
+
+ public byte[] convertFileToByteArray(File file) {
+ try {
+ return FileUtils.readFileToByteArray(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl implements
+ IDistributionClientDownloadResult {
+
+ public DistributionClientDownloadResultStubImpl() {
+ }
+
+ public byte[] getArtifactPayload() {
+ File file = Paths.get(CSAR_SAMPLE).toFile();
+ return convertFileToByteArray(file);
+ }
+
+ public String getArtifactName() {
+ return "MackArtifactName";
+ }
+
+ public String getArtifactFilename() {
+ return "MackArtifactName.csar";
+ }
+ }
}