Search in sources :

Example 26 with BlackDuckIntegrationException

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);
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 27 with BlackDuckIntegrationException

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);
    }
}
Also used : BlackDuckResponse(com.synopsys.integration.blackduck.api.core.BlackDuckResponse) Response(com.synopsys.integration.rest.response.Response) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse)

Example 28 with BlackDuckIntegrationException

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

Example 29 with BlackDuckIntegrationException

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()));
}
Also used : Container(com.github.dockerjava.api.model.Container) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

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