use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.
the class TagService method createTag.
public TagView createTag(ProjectView projectView, TagView tag) throws IntegrationException {
if (!projectView.hasLink(ProjectView.TAGS_LINK)) {
throw new BlackDuckIntegrationException(String.format("The supplied projectView does not have the link (%s) to create a tag.", ProjectView.TAGS_LINK));
}
HttpUrl tagsLink = projectView.getFirstLink(ProjectView.TAGS_LINK);
HttpUrl tagLink = blackDuckApiClient.post(tagsLink, tag);
return blackDuckApiClient.getResponse(tagLink, TagView.class);
}
use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-common by blackducksoftware.
the class BlackDuckResponsesTransformer method getInternalMatchingResponse.
private <T extends BlackDuckResponse> BlackDuckPageResponse<T> getInternalMatchingResponse(BlackDuckRequest<T, UrlMultipleResponses<T>> requestMultiple, int maxToReturn, Predicate<T> predicate) throws IntegrationException {
List<T> allResponses = new LinkedList<>();
int totalCount = 0;
int limit = getLimit(requestMultiple);
int offset = getOffset(requestMultiple);
try (Response initialResponse = blackDuckHttpClient.execute(requestMultiple)) {
blackDuckHttpClient.throwExceptionForError(initialResponse);
String initialJsonResponse = initialResponse.getContentString();
BlackDuckPageResponse<T> blackDuckPageResponse = blackDuckJsonTransformer.getResponses(initialJsonResponse, requestMultiple.getResponseClass());
allResponses.addAll(this.matchPredicate(blackDuckPageResponse, predicate));
totalCount = blackDuckPageResponse.getTotalCount();
int totalItemsToRetrieve = Math.min(totalCount, maxToReturn);
while (allResponses.size() < totalItemsToRetrieve && offset < totalCount) {
offset = offset + limit;
requestMultiple = nextPage(requestMultiple, offset);
try (Response response = blackDuckHttpClient.execute(requestMultiple)) {
blackDuckHttpClient.throwExceptionForError(response);
String jsonResponse = response.getContentString();
blackDuckPageResponse = blackDuckJsonTransformer.getResponses(jsonResponse, requestMultiple.getResponseClass());
allResponses.addAll(this.matchPredicate(blackDuckPageResponse, predicate));
} catch (IOException e) {
throw new BlackDuckIntegrationException(e);
}
}
allResponses = onlyReturnMaxRequested(maxToReturn, allResponses);
return new BlackDuckPageResponse<>(totalCount, allResponses);
} catch (IOException e) {
throw new BlackDuckIntegrationException(e.getMessage(), e);
}
}
use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException 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);
}
use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-docker-inspector by blackducksoftware.
the class DockerClientManager method getRunningContainerByAppName.
public Container getRunningContainerByAppName(String targetAppName, ImageInspectorOsEnum targetInspectorOs) throws IntegrationException {
List<Container> containers = dockerClient.listContainersCmd().withShowAll(true).exec();
for (Container container : containers) {
logger.debug(String.format("Checking container %s to see if it has labels app = %s, os = %s", container.getNames()[0], targetAppName, targetInspectorOs.name()));
String containerAppName = container.getLabels().get(CONTAINER_APPNAME_LABEL_KEY);
String containerOsName = container.getLabels().get(CONTAINER_OS_LABEL_KEY);
logger.debug(String.format("Comparing app name %s to %s, os name %s to %s", targetAppName, containerAppName, targetInspectorOs.name(), containerOsName));
if (targetAppName.equals(containerAppName) && targetInspectorOs.name().equalsIgnoreCase(containerOsName)) {
logger.debug("\tIt's a match");
return container;
}
}
throw new BlackDuckIntegrationException(String.format("No running container found with app = %s, os = %s", targetAppName, targetInspectorOs.name()));
}
Aggregations