Search in sources :

Example 1 with ImageBuilder

use of org.openstack4j.model.image.builder.ImageBuilder in project openstack4j by ContainX.

the class ImageFromHeadersFunction method apply.

@Override
@Nullable
public Image apply(HttpResponse from) {
    ImageBuilder builder = GlanceImage.builder().id(from.header(ID.asHeader())).name(from.header(NAME.asHeader())).checksum(from.header(CHECKSUM.asHeader())).minDisk(asLong(from.header(MIN_DISK.asHeader()))).minRam(asLong(from.header(MIN_RAM.asHeader()))).isPublic(asBoolean(from.header(IS_PUBLIC.asHeader()))).owner(from.header(OWNER.asHeader())).containerFormat(ContainerFormat.value(from.header(CONTAINER_FORMAT.asHeader()))).diskFormat(DiskFormat.value(from.header(DISK_FORMAT.asHeader())));
    GlanceImage image = (GlanceImage) builder.build();
    image.location(from.header("Location")).isDeleted(asBoolean(from.header(DELETED.asHeader()))).isProtected(asBoolean(from.header(PROTECTED.asHeader()))).createdAt(asDate(from.header(CREATED_AT.asHeader()))).updatedAt(asDate(from.header(UPDATED_AT.asHeader()))).deletedAt(asDate(from.header(DELETED_AT.asHeader()))).size(asLong(from.header(SIZE.asHeader()))).status(Status.value(from.header(STATUS.asHeader())));
    Map<String, String> properties = null;
    String property = PROPERTY.asHeader() + "-";
    for (String k : from.headers().keySet()) {
        if (k.indexOf(property) > -1) {
            if (properties == null)
                properties = Maps.newHashMap();
            properties.put(k.substring(property.length()).toLowerCase(), from.headers().get(k));
        }
    }
    image.properties(properties);
    return image;
}
Also used : GlanceImage(org.openstack4j.openstack.image.domain.GlanceImage) ImageBuilder(org.openstack4j.model.image.builder.ImageBuilder) Nullable(javax.annotation.Nullable)

Example 2 with ImageBuilder

use of org.openstack4j.model.image.builder.ImageBuilder in project camel by apache.

the class GlanceProducer method messageHeadersToImage.

private Image messageHeadersToImage(Message message, boolean required) {
    ImageBuilder imageBuilder = null;
    if (required && ObjectHelper.isEmpty(message.getHeader(OpenstackConstants.NAME, String.class))) {
        throw new IllegalArgumentException("Image Name must be specified and not empty");
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(OpenstackConstants.NAME, String.class))) {
        imageBuilder = getImageBuilder(imageBuilder).name(message.getHeader(OpenstackConstants.NAME, String.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(GlanceConstants.DISK_FORMAT, DiskFormat.class))) {
        imageBuilder = getImageBuilder(imageBuilder).diskFormat(message.getHeader(GlanceConstants.DISK_FORMAT, DiskFormat.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(GlanceConstants.CONTAINER_FORMAT, ContainerFormat.class))) {
        imageBuilder = getImageBuilder(imageBuilder).containerFormat(message.getHeader(GlanceConstants.CONTAINER_FORMAT, ContainerFormat.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(GlanceConstants.SIZE, Long.class))) {
        imageBuilder = getImageBuilder(imageBuilder).size(message.getHeader(GlanceConstants.SIZE, Long.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(GlanceConstants.CHECKSUM))) {
        imageBuilder = getImageBuilder(imageBuilder).checksum(message.getHeader(GlanceConstants.CHECKSUM, String.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(GlanceConstants.MIN_DISK))) {
        imageBuilder = getImageBuilder(imageBuilder).minDisk(message.getHeader(GlanceConstants.MIN_DISK, Long.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(GlanceConstants.MIN_RAM))) {
        imageBuilder = getImageBuilder(imageBuilder).minRam(message.getHeader(GlanceConstants.MIN_RAM, Long.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(GlanceConstants.OWNER))) {
        imageBuilder = getImageBuilder(imageBuilder).owner(message.getHeader(GlanceConstants.OWNER, String.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(GlanceConstants.IS_PUBLIC))) {
        imageBuilder = getImageBuilder(imageBuilder).isPublic(message.getHeader(GlanceConstants.IS_PUBLIC, Boolean.class));
    }
    if (ObjectHelper.isNotEmpty(message.getHeader(OpenstackConstants.PROPERTIES))) {
        imageBuilder = getImageBuilder(imageBuilder).properties(message.getHeader(OpenstackConstants.PROPERTIES, Map.class));
    }
    if (!required && imageBuilder == null) {
        return null;
    }
    ObjectHelper.notNull(imageBuilder, "Image");
    return imageBuilder.build();
}
Also used : ImageBuilder(org.openstack4j.model.image.builder.ImageBuilder) ContainerFormat(org.openstack4j.model.image.ContainerFormat) DiskFormat(org.openstack4j.model.image.DiskFormat)

Aggregations

ImageBuilder (org.openstack4j.model.image.builder.ImageBuilder)2 Nullable (javax.annotation.Nullable)1 ContainerFormat (org.openstack4j.model.image.ContainerFormat)1 DiskFormat (org.openstack4j.model.image.DiskFormat)1 GlanceImage (org.openstack4j.openstack.image.domain.GlanceImage)1