Search in sources :

Example 6 with BdioFileContent

use of com.synopsys.integration.blackduck.bdio2.model.BdioFileContent in project blackduck-common by blackducksoftware.

the class Bdio2UploadJob method attemptJob.

@Override
public void attemptJob() throws IntegrationException {
    Response headerResponse = bdio2Uploader.start(header, editor);
    complete = true;
    try {
        throwIfResponseUnsuccessful(headerResponse);
        uploadUrl = new HttpUrl(headerResponse.getHeaderValue("location"));
        logger.debug(String.format("Starting upload to %s", uploadUrl.string()));
        for (BdioFileContent content : bdioEntries) {
            Response chunkResponse = bdio2Uploader.append(uploadUrl, count, content, editor);
            throwIfResponseUnsuccessful(chunkResponse);
        }
        throwIfResponseUnsuccessful(bdio2Uploader.finish(uploadUrl, count, editor));
    } catch (RetriableBdioUploadException e) {
        complete = false;
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 7 with BdioFileContent

use of com.synopsys.integration.blackduck.bdio2.model.BdioFileContent in project blackduck-common by blackducksoftware.

the class Bdio2ContentExtractor method readEntryContent.

private BdioFileContent readEntryContent(ZipFile zipFile, ZipEntry entry) throws IntegrationException {
    String entryContent;
    byte[] buffer = new byte[4096];
    try (InputStream zipInputStream = zipFile.getInputStream(entry);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream)) {
        int length;
        while ((length = zipInputStream.read(buffer)) > 0) {
            bufferedOutputStream.write(buffer, 0, length);
        }
        bufferedOutputStream.flush();
        entryContent = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
    } catch (IOException ex) {
        throw new IntegrationException(String.format("Error reading entry %s", entry.getName()), ex);
    }
    return new BdioFileContent(entry.getName(), entryContent);
}
Also used : BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) IntegrationException(com.synopsys.integration.exception.IntegrationException) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 8 with BdioFileContent

use of com.synopsys.integration.blackduck.bdio2.model.BdioFileContent in project blackduck-common by blackducksoftware.

the class Bdio2FileUploadService method uploadFiles.

private Bdio2UploadResult uploadFiles(List<BdioFileContent> bdioFiles, @Nullable NameVersion nameVersion, long timeout) throws IntegrationException, InterruptedException {
    if (bdioFiles.isEmpty()) {
        throw new IllegalArgumentException("BDIO files cannot be empty.");
    }
    BdioFileContent header = bdioFiles.stream().filter(content -> content.getFileName().equals(FILE_NAME_BDIO_HEADER_JSONLD)).findFirst().orElseThrow(() -> new BlackDuckIntegrationException("Cannot find BDIO header file" + FILE_NAME_BDIO_HEADER_JSONLD + "."));
    List<BdioFileContent> remainingFiles = bdioFiles.stream().filter(content -> !content.getFileName().equals(FILE_NAME_BDIO_HEADER_JSONLD)).collect(Collectors.toList());
    int count = remainingFiles.size();
    logger.debug("BDIO upload file count = " + count);
    BlackDuckRequestBuilderEditor editor = noOp -> {
    };
    if (nameVersion != null) {
        editor = builder -> builder.addHeader(Bdio2StreamUploader.PROJECT_NAME_HEADER, nameVersion.getName()).addHeader(Bdio2StreamUploader.VERSION_NAME_HEADER, nameVersion.getVersion());
    }
    ResilientJobConfig jobConfig = new ResilientJobConfig(logger, timeout, System.currentTimeMillis(), BD_WAIT_AND_RETRY_INTERVAL);
    Bdio2UploadJob bdio2UploadJob = new Bdio2UploadJob(bdio2Uploader, header, remainingFiles, editor, count);
    ResilientJobExecutor jobExecutor = new ResilientJobExecutor(jobConfig);
    return jobExecutor.executeJob(bdio2UploadJob);
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) DataService(com.synopsys.integration.blackduck.service.DataService) ResilientJobExecutor(com.synopsys.integration.wait.ResilientJobExecutor) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig) Collectors(java.util.stream.Collectors) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) Nullable(org.jetbrains.annotations.Nullable) Bdio2ContentExtractor(com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor) NameVersion(com.synopsys.integration.util.NameVersion) List(java.util.List) BlackDuckRequestBuilderEditor(com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor) BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckRequestBuilderEditor(com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor) BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) ResilientJobExecutor(com.synopsys.integration.wait.ResilientJobExecutor) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig)

Aggregations

BdioFileContent (com.synopsys.integration.blackduck.bdio2.model.BdioFileContent)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)3 NameVersion (com.synopsys.integration.util.NameVersion)3 IOException (java.io.IOException)3 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 Bdio2ContentExtractor (com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 DataService (com.synopsys.integration.blackduck.service.DataService)2 BlackDuckRequestBuilderEditor (com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor)2 IntLogger (com.synopsys.integration.log.IntLogger)2 File (java.io.File)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Nullable (org.jetbrains.annotations.Nullable)2 Bdio2StreamUploader (com.synopsys.integration.blackduck.bdio2.Bdio2StreamUploader)1 RapidCompareMode (com.synopsys.integration.detect.configuration.enumeration.RapidCompareMode)1 DetectZipUtil (com.synopsys.integration.detect.util.DetectZipUtil)1