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;
}
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);
}
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);
}
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()));
}
}
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();
}
Aggregations