Search in sources :

Example 1 with ImageStatus

use of org.openstack4j.model.image.v2.Image.ImageStatus in project cloudbreak by hortonworks.

the class OpenStackImageVerifier method getStatus.

public ImageStatus getStatus(OSClient<?> osClient, String name) {
    ImageStatus imageStatus;
    List<? extends Image> images = osClient.imagesV2().list(Collections.singletonMap("name", name));
    if (images == null || images.isEmpty()) {
        imageStatus = null;
        LOGGER.error("OpenStack image: {} not found", name);
        List<? extends Image> allImages = osClient.imagesV2().list();
        if (allImages != null) {
            for (Image image : allImages) {
                LOGGER.info("Available images: {}, entry: {}", image.getName(), image);
            }
        }
        LOGGER.warn("OpenStack image: {} not found", name);
    } else if (images.size() > 1) {
        for (Image image : images) {
            LOGGER.info("Multiple images found: {}, entry: {}", image.getName(), image);
        }
        List<String> imageIds = images.stream().map(Image::getId).collect(Collectors.toList());
        throw new CloudConnectorException(String.format("Multiple OpenStack images found with ids: %s, image name: %s", String.join(", ", imageIds), name));
    } else {
        LOGGER.info("OpenStack Image found: {}, entry: {}", name, images);
        imageStatus = images.get(0).getStatus();
    }
    return imageStatus;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ImageStatus(org.openstack4j.model.image.v2.Image.ImageStatus) List(java.util.List) Image(org.openstack4j.model.image.v2.Image)

Example 2 with ImageStatus

use of org.openstack4j.model.image.v2.Image.ImageStatus in project cloudbreak by hortonworks.

the class OpenStackSetup method checkImageStatus.

@Override
public ImageStatusResult checkImageStatus(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
    String imageName = image.getImageName();
    OSClient osClient = openStackClient.createOSClient(authenticatedContext);
    Image.ImageStatus imageStatus = openStackImageVerifier.getStatus(osClient, imageName);
    ImageStatusResult imageStatusResult;
    switch(imageStatus) {
        case ACTIVE:
            imageStatusResult = new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
            break;
        case QUEUED:
        case SAVING:
            imageStatusResult = new ImageStatusResult(ImageStatus.IN_PROGRESS, ImageStatusResult.HALF);
            break;
        default:
            imageStatusResult = new ImageStatusResult(ImageStatus.CREATE_FAILED, ImageStatusResult.COMPLETED);
            break;
    }
    LOGGER.info("OpenStack image result. name: {}, imageStatus: {}, imageStatusResult: {}", imageName, imageStatus, imageStatusResult);
    return imageStatusResult;
}
Also used : OSClient(org.openstack4j.api.OSClient) Image(org.openstack4j.model.image.v2.Image) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Aggregations

Image (org.openstack4j.model.image.v2.Image)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 ImageStatusResult (com.sequenceiq.cloudbreak.common.type.ImageStatusResult)1 List (java.util.List)1 OSClient (org.openstack4j.api.OSClient)1 ImageStatus (org.openstack4j.model.image.v2.Image.ImageStatus)1