Search in sources :

Example 1 with HubIntegrationException

use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-docker-inspector by blackducksoftware.

the class DockerClientManager method pullImage.

public String pullImage(final String imageName, final String tagName) throws HubIntegrationException {
    logger.info(String.format("Pulling image %s:%s", imageName, tagName));
    final DockerClient dockerClient = hubDockerClient.getDockerClient();
    final Image alreadyPulledImage = getLocalImage(dockerClient, imageName, tagName);
    if (alreadyPulledImage == null) {
        // Only pull if we dont already have it
        final PullImageCmd pull = dockerClient.pullImageCmd(imageName).withTag(tagName);
        try {
            pull.exec(new PullImageResultCallback()).awaitSuccess();
        } catch (final NotFoundException e) {
            final String msg = String.format("Pull failed: Image %s:%s not found. Please check the image name/tag", imageName, tagName);
            logger.error(msg);
            throw new HubIntegrationException(msg, e);
        }
        final Image justPulledImage = getLocalImage(dockerClient, imageName, tagName);
        if (justPulledImage == null) {
            final String msg = String.format("Pulled image %s:%s not found in image list.", imageName, tagName);
            logger.error(msg);
            throw new HubIntegrationException(msg);
        }
        return justPulledImage.getId();
    } else {
        logger.info("Image already pulled");
        return alreadyPulledImage.getId();
    }
}
Also used : DockerClient(com.github.dockerjava.api.DockerClient) PullImageCmd(com.github.dockerjava.api.command.PullImageCmd) PullImageResultCallback(com.github.dockerjava.core.command.PullImageResultCallback) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) Image(com.github.dockerjava.api.model.Image) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Example 2 with HubIntegrationException

use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-alert by blackducksoftware.

the class VulnerabilityCache method getEvents.

@Override
public Collection<NotificationEvent> getEvents() throws HubIntegrationException {
    final Collection<NotificationEvent> vulnerabilities = super.getEvents();
    // need to group the vulnerabilities by severity which can be gathered by the vulnerability API.
    final Collection<NotificationEvent> result = new LinkedList<>();
    for (final NotificationEvent event : vulnerabilities) {
        List<NotificationEvent> vulnerabilityEvents;
        try {
            vulnerabilityEvents = createVulnerabilityEvents(event);
        } catch (final IntegrationException e) {
            throw new HubIntegrationException(e);
        }
        for (final NotificationEvent vulnerability : vulnerabilityEvents) {
            result.add(vulnerability);
        }
    }
    return this.addUserInformation(result);
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) LinkedList(java.util.LinkedList) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Example 3 with HubIntegrationException

use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-docker-inspector by blackducksoftware.

the class DockerClientManager method getDockerEngineVersion.

public String getDockerEngineVersion() {
    logger.info("Requesting version string from Docker engine");
    try {
        final DockerClient dockerClient = hubDockerClient.getDockerClient();
        final Info dockerInfo = dockerClient.infoCmd().exec();
        final String engineVersion = dockerInfo.getServerVersion();
        logger.debug(String.format("Docker Engine (Server) Version: %s", engineVersion));
        if (engineVersion == null) {
            return "Unknown";
        } else {
            return engineVersion;
        }
    } catch (final HubIntegrationException e) {
        return "Unknown";
    }
}
Also used : DockerClient(com.github.dockerjava.api.DockerClient) Info(com.github.dockerjava.api.model.Info) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Example 4 with HubIntegrationException

use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-docker-inspector by blackducksoftware.

the class DockerClientManager method getTarFileFromDockerImageById.

public File getTarFileFromDockerImageById(final String imageId) throws HubIntegrationException, IOException {
    final File imageTarDirectory = new File(new File(programPaths.getHubDockerWorkingDirPath()), "tarDirectory");
    final DockerClient dockerClient = hubDockerClient.getDockerClient();
    final InspectImageCmd inspectImageCmd = dockerClient.inspectImageCmd(imageId);
    final InspectImageResponse imageDetails = inspectImageCmd.exec();
    final List<String> repoTags = imageDetails.getRepoTags();
    if (repoTags.size() == 0) {
        throw new HubIntegrationException(String.format("Unable to get image name:tag for image ID %s", imageId));
    }
    final ImageNameResolver resolver = new ImageNameResolver(repoTags.get(0));
    final String imageName = resolver.getNewImageRepo().get();
    final String tagName = resolver.getNewImageTag().get();
    logger.info(String.format("Converted image ID %s to image name:tag %s:%s", imageId, imageName, tagName));
    final File imageTarFile = saveImageToDir(imageTarDirectory, Names.getImageTarFilename(imageName, tagName), imageName, tagName);
    return imageTarFile;
}
Also used : InspectImageCmd(com.github.dockerjava.api.command.InspectImageCmd) DockerClient(com.github.dockerjava.api.DockerClient) ImageNameResolver(com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver) InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) File(java.io.File) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Example 5 with HubIntegrationException

use of com.blackducksoftware.integration.hub.exception.HubIntegrationException in project hub-docker-inspector by blackducksoftware.

the class HubClient method testHubConnection.

public void testHubConnection() throws HubIntegrationException {
    // ArgsWithSpacesTest tests this in output
    logger.trace(String.format("Hub username: %s", getHubUsername()));
    if (!config.isUploadBdio()) {
        logger.debug("Upload of BDIO not enabled; skipping verification of Hub connection");
        return;
    }
    RestConnection restConnection;
    try {
        restConnection = createRestConnection();
        restConnection.connect();
    } catch (final IntegrationException e) {
        final String msg = String.format("Error connecting to Hub: %s", e.getMessage());
        throw new HubIntegrationException(msg);
    }
    logger.info("Successful connection to the Hub.");
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException)

Aggregations

HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)6 DockerClient (com.github.dockerjava.api.DockerClient)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 File (java.io.File)2 ImageNameResolver (com.blackducksoftware.integration.hub.imageinspector.name.ImageNameResolver)1 ResultFile (com.blackducksoftware.integration.hub.imageinspector.result.ResultFile)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)1 InspectImageCmd (com.github.dockerjava.api.command.InspectImageCmd)1 InspectImageResponse (com.github.dockerjava.api.command.InspectImageResponse)1 PullImageCmd (com.github.dockerjava.api.command.PullImageCmd)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 Image (com.github.dockerjava.api.model.Image)1 Info (com.github.dockerjava.api.model.Info)1 PullImageResultCallback (com.github.dockerjava.core.command.PullImageResultCallback)1 LinkedList (java.util.LinkedList)1