Search in sources :

Example 36 with Image

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.image.v2.Image in project openstack4j by ContainX.

the class ImageServiceImpl method update.

/**
 * {@inheritDoc}
 */
@Override
public Image update(Image image) {
    checkNotNull(image);
    ObjectMapper objectMapper = new ObjectMapper();
    Image origImage = get(image.getId());
    ObjectNode origJson;
    ObjectNode newJson;
    try {
        String oImg = objectMapper.writeValueAsString(origImage);
        origJson = (ObjectNode) objectMapper.readTree(oImg);
        String img = objectMapper.writeValueAsString(image);
        newJson = (ObjectNode) objectMapper.readTree(img);
        JsonNode jsonDiff = JsonDiff.asJson(origJson, newJson);
        GlanceImageUpdate giu = new GlanceImageUpdate(jsonDiff);
        return update(image.getId(), giu);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GlanceImageUpdate(org.openstack4j.openstack.image.v2.domain.GlanceImageUpdate) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) GlanceImage(org.openstack4j.openstack.image.v2.domain.GlanceImage) CachedImage(org.openstack4j.model.image.v2.CachedImage) Image(org.openstack4j.model.image.v2.Image) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 37 with Image

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.image.v2.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ImageIT method setupBeforeEach.

@BeforeEach
public void setupBeforeEach() throws ClientException {
    clientlibs = "core.wcm.components.image.v3";
    imageTests = new ImageTests();
    imageTests.setup(adminClient, contextPath, label, Commons.rtImage_v3, rootPage, defaultPageTemplate, clientlibs, new Image());
}
Also used : ImageTests(com.adobe.cq.wcm.core.components.it.seljup.tests.image.ImageTests) Image(com.adobe.cq.wcm.core.components.it.seljup.util.components.image.v2.Image) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with Image

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.image.v2.Image 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 39 with Image

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.image.v2.Image 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)

Example 40 with Image

use of com.adobe.cq.wcm.core.components.it.seljup.util.components.image.v2.Image in project spring-cloud-gcp by spring-cloud.

the class CloudVisionTemplate method analyzeImage.

/**
 * Analyze an image and extract the features of the image specified by
 * {@code featureTypes}.
 * <p>A feature describes the kind of Cloud Vision analysis one wishes to perform on an
 * image, such as text detection, image labelling, facial detection, etc. A full list of
 * feature types can be found in {@link Feature.Type}.
 * @param imageResource the image one wishes to analyze. The Cloud Vision APIs support
 *     image formats described here: https://cloud.google.com/vision/docs/supported-files
 * @param imageContext the image context used to customize the Vision API request
 * @param featureTypes the types of image analysis to perform on the image
 * @return the results of image analyses
 * @throws CloudVisionException if the image could not be read or if a malformed response
 *     is received from the Cloud Vision APIs
 */
public AnnotateImageResponse analyzeImage(Resource imageResource, ImageContext imageContext, Feature.Type... featureTypes) {
    ByteString imgBytes;
    try {
        imgBytes = ByteString.readFrom(imageResource.getInputStream());
    } catch (IOException ex) {
        throw new CloudVisionException("Failed to read image bytes from provided resource.", ex);
    }
    Image image = Image.newBuilder().setContent(imgBytes).build();
    List<Feature> featureList = Arrays.stream(featureTypes).map((featureType) -> Feature.newBuilder().setType(featureType).build()).collect(Collectors.toList());
    BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder().addRequests(AnnotateImageRequest.newBuilder().addAllFeatures(featureList).setImageContext(imageContext).setImage(image)).build();
    BatchAnnotateImagesResponse batchResponse = this.imageAnnotatorClient.batchAnnotateImages(request);
    List<AnnotateImageResponse> annotateImageResponses = batchResponse.getResponsesList();
    if (!annotateImageResponses.isEmpty()) {
        return annotateImageResponses.get(0);
    } else {
        throw new CloudVisionException("Failed to receive valid response Vision APIs; empty response received.");
    }
}
Also used : Arrays(java.util.Arrays) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) Type(com.google.cloud.vision.v1.Feature.Type) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Feature(com.google.cloud.vision.v1.Feature) ByteString(com.google.protobuf.ByteString) List(java.util.List) Image(com.google.cloud.vision.v1.Image) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) ImageContext(com.google.cloud.vision.v1.ImageContext) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse) BatchAnnotateImagesRequest(com.google.cloud.vision.v1.BatchAnnotateImagesRequest) Code(com.google.rpc.Code) Resource(org.springframework.core.io.Resource) Assert(org.springframework.util.Assert) BatchAnnotateImagesRequest(com.google.cloud.vision.v1.BatchAnnotateImagesRequest) ByteString(com.google.protobuf.ByteString) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) IOException(java.io.IOException) Image(com.google.cloud.vision.v1.Image) Feature(com.google.cloud.vision.v1.Feature) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Aggregations

AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)29 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)29 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)29 Feature (com.google.cloud.vision.v1.Feature)29 Image (com.google.cloud.vision.v1.Image)29 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)28 ArrayList (java.util.ArrayList)27 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)25 ByteString (com.google.protobuf.ByteString)18 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)16 ImageSource (com.google.cloud.vision.v1.ImageSource)15 FileInputStream (java.io.FileInputStream)14 WebPage (com.google.cloud.vision.v1.WebDetection.WebPage)8 Block (com.google.cloud.vision.v1.Block)6 ColorInfo (com.google.cloud.vision.v1.ColorInfo)6 CropHint (com.google.cloud.vision.v1.CropHint)6 CropHintsAnnotation (com.google.cloud.vision.v1.CropHintsAnnotation)6 DominantColorsAnnotation (com.google.cloud.vision.v1.DominantColorsAnnotation)6 FaceAnnotation (com.google.cloud.vision.v1.FaceAnnotation)6 LocationInfo (com.google.cloud.vision.v1.LocationInfo)6