-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>
/*
- * 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;
/*
- * 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;
@Value("${listenerservice.config.isUseHttpsWithDmaap}")
private boolean isUseHttpsWithDmaap;
-
@Override
public String getAsdcAddress() {
return asdcAddress;
/*
- * 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;
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;
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);
}
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);
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());
}
}
/*
- * 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;
/*
- * 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;
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);
}
"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();
}
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());
/*
- * 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;
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;
+ }
}
/*
- * 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 {
/*
- * 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;
/*
- * 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;
* 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.
/*
- * 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;
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;
@Autowired
private CdsSdcListenerAuthClientInterceptor cdsSdcListenerAuthClientInterceptor;
+ @Autowired
+ private CdsSdcListenerStatus listenerStatus;
+
+ @Autowired
+ private CdsSdcListenerDto cdsSdcListenerDto;
+
@Value("${listenerservice.config.grpcAddress}")
private String grpcAddress;
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
storeBluePrint(zipFile, cbaArchiveName, cbaStorageDir, entry);
}
}
+
} catch (Exception e) {
- LOGGER.error("Failed to extract blueprint", e);
+ LOGGER.error("Failed to extract blueprint {}", e);
}
}
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
// 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);
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();
.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();
- }
}
--- /dev/null
+/*
+ * 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");
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
user: vid
password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
pollingInterval: 15
- pollingTimeout: 15
+ pollingTimeout: 60
relevantArtifactTypes: TOSCA_CSAR
consumerGroup: cds-id-local
environmentName: AUTO
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==
/*
- * 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;
@Injectable CdsSdcListenerNotificationCallback notification,
@Injectable CdsSdcListenerDto cdsSdcListenerDto) throws CdsSdcListenerException {
- // Arrange
+ //Arrange
new MockUp<DistributionClientFactory>() {
@Mock
public IDistributionClient createDistributionClient() {
/*
- * 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;
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");
/*
- * 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;
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})
/*
- * 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 {
.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";
+ }
+ }
}