import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.List;
-import java.util.Optional;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public void saveBluePrintToCdsDatabase(Path cbaArchivePath, ManagedChannel channel) {
List<File> zipFiles = FileUtil.getFilesFromDisk(cbaArchivePath);
if (!zipFiles.isEmpty()) {
- zipFiles.forEach(file -> FileUtil.deleteFile(file, cbaArchivePath.toString()));
prepareRequestForCdsBackend(zipFiles, channel, cbaArchivePath.toString());
- } else {
- LOGGER.error("Could not able to read CBA archives from this location {}", cbaArchivePath);
}
}
files.forEach(zipFile -> {
try {
- final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile);
+ final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile, path);
// Send request to CDS Backend.
final Status responseStatus = bluePrintProcesssorHandler.sendRequest(request, managedChannel);
listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl,
SDC_LISTENER_COMPONENT);
LOGGER.error(errorMessage);
- } finally {
- FileUtil.deleteFile(zipFile, path);
}
});
}
- private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file) throws IOException {
+ private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file, String path) throws IOException {
byte[] bytes = FileUtils.readFileToByteArray(file);
FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build();
-
+ FileUtil.deleteFile(file, path);
return BluePrintUploadInput.newBuilder()
.setFileChunk(fileChunk)
.build();
import static junit.framework.TestCase.assertTrue;
import static org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType.SDC_LISTENER_COMPONENT;
-import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_ERROR;
import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK;
import java.io.File;
import java.io.IOException;
import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
import org.onap.ccsdk.cds.sdclistener.handler.BluePrintProcesssorHandler;
import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus;
-import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.onap.sdc.impl.mock.DistributionClientResultStubImpl;
import org.springframework.beans.factory.annotation.Autowired;
@Test
public void extractBluePrintFailure() {
// Arrange
- final String errorMessage = String
- .format("The CBA Archive doesn't exist as per this given regex %s", CBA_ZIP_PATH);
Mockito.when(listenerDto.getDistributionId()).thenReturn(DISTRIBUTION_ID);
Mockito.when(listenerDto.getArtifactUrl()).thenReturn(URL);
Mockito.doCallRealMethod().when(status)