Search in sources :

Example 6 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class ScannerZipInstaller method installOrUpdateScanner.

/**
 * The Black Duck Signature Scanner will be download if it has not
 * previously been downloaded or if it has been updated on the server. The
 * absolute path to the install location will be returned if it was
 * downloaded or found successfully, otherwise an Optional.empty will be
 * returned and the log will contain details concerning the failure.
 */
@Override
public File installOrUpdateScanner() throws BlackDuckIntegrationException {
    if (installDirectory.exists()) {
        try {
            ScanPaths scanPaths = scanPathsUtility.searchForScanPaths(installDirectory);
            if (!scanPaths.isManagedByLibrary()) {
                return installDirectory;
            }
        } catch (BlackDuckIntegrationException ignored) {
        // a valid scanPaths could not be found so we will need to attempt an install
        }
    }
    File scannerExpansionDirectory = new File(installDirectory, ScannerZipInstaller.BLACK_DUCK_SIGNATURE_SCANNER_INSTALL_DIRECTORY);
    scannerExpansionDirectory.mkdirs();
    File versionFile = new File(scannerExpansionDirectory, ScannerZipInstaller.VERSION_FILENAME);
    HttpUrl downloadUrl = getDownloadUrl();
    try {
        String connectedBlackDuckVersion = StringUtils.trim(blackDuckRegistrationService.getBlackDuckServerData().getVersion());
        if (!versionFile.exists()) {
            logger.info("No version file exists, assuming this is new installation and the signature scanner should be downloaded.");
            downloadSignatureScanner(scannerExpansionDirectory, downloadUrl);
            // Version file creation should happen after successful download
            logger.debug("The version file has not been created yet so creating it now.");
            FileUtils.writeStringToFile(versionFile, connectedBlackDuckVersion, Charset.defaultCharset());
            return installDirectory;
        }
        // A version file exists, so we have to compare to determine if a download should occur.
        String localScannerVersion = FileUtils.readFileToString(versionFile, Charset.defaultCharset());
        logger.debug(String.format("Locally installed signature scanner version: %s", localScannerVersion));
        if (!connectedBlackDuckVersion.equals(localScannerVersion)) {
            logger.info(String.format("The signature scanner should be downloaded. Locally installed signature scanner is %s, but the connected Black Duck version is %s", localScannerVersion, connectedBlackDuckVersion));
            downloadSignatureScanner(scannerExpansionDirectory, downloadUrl);
            FileUtils.writeStringToFile(versionFile, connectedBlackDuckVersion, Charset.defaultCharset());
        } else {
            logger.debug("The Black Duck Signature Scanner version matches the connected Black Duck version - skipping download.");
        }
    } catch (Exception e) {
        throw new BlackDuckIntegrationException("The Black Duck Signature Scanner could not be downloaded successfully: " + e.getMessage(), e);
    }
    logger.info("The Black Duck Signature Scanner downloaded/found successfully: " + installDirectory.getAbsolutePath());
    return installDirectory;
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) File(java.io.File) HttpUrl(com.synopsys.integration.rest.HttpUrl) IntegrationException(com.synopsys.integration.exception.IntegrationException) ArchiveException(org.apache.commons.compress.archivers.ArchiveException) IOException(java.io.IOException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 7 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class UploadBatchRunner method uploadTargets.

private UploadBatchOutput uploadTargets(UploadBatch uploadBatch) throws BlackDuckIntegrationException {
    List<UploadOutput> uploadOutputs = new ArrayList<>();
    try {
        List<UploadCallable> callables = createCallables(uploadBatch);
        List<Future<UploadOutput>> submitted = new ArrayList<>();
        for (UploadCallable callable : callables) {
            submitted.add(executorService.submit(callable));
        }
        for (Future<UploadOutput> future : submitted) {
            UploadOutput uploadOutput = future.get();
            uploadOutputs.add(uploadOutput);
        }
    } catch (Exception e) {
        throw new BlackDuckIntegrationException(String.format("Encountered a problem uploading a file: %s", e.getMessage()), e);
    }
    return new UploadBatchOutput(uploadOutputs);
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 8 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class BinaryScanBatchRunner method uploadFiles.

private BinaryScanBatchOutput uploadFiles(BinaryScanBatch binaryScanBatch) throws BlackDuckIntegrationException {
    List<BinaryScanOutput> uploadOutputs = new ArrayList<>();
    try {
        List<BinaryScanCallable> callables = createCallables(binaryScanBatch);
        List<Future<BinaryScanOutput>> submitted = new ArrayList<>();
        for (BinaryScanCallable callable : callables) {
            submitted.add(executorService.submit(callable));
        }
        for (Future<BinaryScanOutput> future : submitted) {
            BinaryScanOutput uploadOutput = future.get();
            uploadOutputs.add(uploadOutput);
        }
    } catch (Exception e) {
        throw new BlackDuckIntegrationException(String.format("Encountered a problem uploading a binary file: %s", e.getMessage()), e);
    }
    return new BinaryScanBatchOutput(uploadOutputs);
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 9 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.

the class BinaryScanUploadServiceTestIT method testCodeLocationFromBinaryScanUploadWhenNotConfigured.

@Test
public void testCodeLocationFromBinaryScanUploadWhenNotConfigured() throws Exception {
    BlackDuckServices blackDuckServices = new BlackDuckServices(intHttpClientTestHelper);
    BinaryScanData binaryScanData = createBinaryScanData(blackDuckServices, createTestBinaryScan());
    BinaryScanUploadService binaryScanUploadService = blackDuckServices.blackDuckServicesFactory.createBinaryScanUploadService();
    BinaryScanBatchOutput binaryScanBatchOutput = binaryScanUploadService.uploadBinaryScanAndWait(binaryScanData.binaryScan, 15 * 60);
    BufferedIntLogger logger = new BufferedIntLogger();
    try {
        binaryScanBatchOutput.throwExceptionForError(logger);
    } catch (Exception e) {
        assertTrue(e instanceof BlackDuckIntegrationException);
        assertTrue(e.getMessage().startsWith("Error when uploading binary scan"));
        assertTrue(logger.getOutputString(LogLevel.ERROR).contains(e.getMessage()));
    }
}
Also used : BlackDuckServices(com.synopsys.integration.blackduck.comprehensive.BlackDuckServices) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) Test(org.junit.jupiter.api.Test)

Example 10 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-docker-inspector by blackducksoftware.

the class DockerClientManager method pullImage.

private String pullImage(String imageName, String tagName, PullImageCmd pull) throws IntegrationException, InterruptedException {
    try {
        pull.exec(new PullImageResultCallback()).awaitCompletion();
    } catch (NotFoundException e) {
        throw new BlackDuckIntegrationException(String.format("Pull failed: Image %s:%s not found. Please check the image name/tag. Error: %s", imageName, tagName, e.getMessage()), e);
    }
    Optional<Image> justPulledImage = getLocalImage(dockerClient, imageName, tagName);
    if (!justPulledImage.isPresent()) {
        String msg = String.format("Pulled image %s:%s not found in image list.", imageName, tagName);
        logger.error(msg);
        throw new BlackDuckIntegrationException(msg);
    }
    return justPulledImage.get().getId();
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) PullImageResultCallback(com.github.dockerjava.api.command.PullImageResultCallback) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) Image(com.github.dockerjava.api.model.Image)

Aggregations

BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)29 File (java.io.File)8 HttpUrl (com.synopsys.integration.rest.HttpUrl)7 ArrayList (java.util.ArrayList)7 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 IOException (java.io.IOException)6 Future (java.util.concurrent.Future)5 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)3 UploadOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadOutput)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 ProjectVersionReportView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionReportView)2 BdioFileContent (com.synopsys.integration.blackduck.bdio2.model.BdioFileContent)2 Bdio2ContentExtractor (com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)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