* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onap.ccsdk.cds.sdclistener;
-import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS;
-import java.io.File;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
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;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Objects;
+
+import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS;
+
@ConfigurationProperties("listenerservice")
@Component
@ComponentScan("org.onap.ccsdk.cds.cdssdclistener.dto")
private void processNotification(INotificationData notificationData) {
final IDistributionClient distributionClient = sdcListenerDto.getDistributionClient();
notificationData.getServiceArtifacts()
- .forEach(artifactInfo -> downloadCsarArtifacts(artifactInfo, distributionClient));
+ .forEach(artifactInfo -> downloadCsarArtifacts(artifactInfo, distributionClient));
}
/**
* Download the TOSCA CSAR artifact and process it.
*
- * @param info - Artifact information
+ * @param info - Artifact information
* @param distributionClient - SDC distribution client
*/
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);
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,
- result.getDistributionActionResult());
- listenerStatus.sendResponseStatusBackToSDC(sdcListenerDto.getDistributionId(),
- DistributionStatusEnum.COMPONENT_DONE_ERROR, errorMessage);
+ final String errorMessage = String.format("Failed to download the artifact from : %s due to %s ", url,
+ result.getDistributionActionResult());
+ 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);
}
}
}
- public void processCsarArtifact(IDistributionClientDownloadResult result) {
+ private void processCsarArtifact(IDistributionClientDownloadResult result) {
Path cbaArchivePath = Paths.get(pathToStoreArchives, "cba-archive");
Path csarArchivePath = Paths.get(pathToStoreArchives, "csar-archive");
// Extract and store the CSAR archive into local disk.
- listenerService.extractCsarAndStore(result, csarArchivePath.toString());
+ listenerService.extractCsarAndStore(result, csarArchivePath);
- Optional<List<File>> csarFiles = FileUtil.getFilesFromDisk(csarArchivePath);
+ 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();
+ if (!csarFiles.isEmpty()) {
+ final String archivePath = cbaArchivePath.toString();
- 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);
- }
+ //Extract CBA archive from CSAR package and store it into local disk
+ csarFiles.forEach(file -> listenerService.extractBluePrint(file.getAbsolutePath(), archivePath));
+ csarFiles.forEach(file -> FileUtil.deleteFile(file, csarArchivePath.toString()));
+ } else {
+ LOGGER.error("Could not able to read CSAR files from this location {}", csarArchivePath);
}
listenerService.saveBluePrintToCdsDatabase(cbaArchivePath, sdcListenerDto.getManagedChannelForGrpc());
}
+
}