Search in sources :

Example 1 with Image

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

the class GlanceProducer method doUpload.

private void doUpload(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String imageId = msg.getHeader(OpenstackConstants.ID, String.class);
    ObjectHelper.notEmpty(imageId, "Image ID");
    final Image in = messageHeadersToImage(msg, false);
    final Payload payload = createPayload(msg);
    final Image out = os.images().upload(imageId, payload, in);
    msg.setBody(out);
}
Also used : Message(org.apache.camel.Message) Payload(org.openstack4j.model.common.Payload) Image(org.openstack4j.model.image.Image)

Example 2 with Image

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

the class GlanceProducer method doUpdate.

private void doUpdate(Exchange exchange) {
    final Message msg = exchange.getIn();
    final Image in = messageToImage(msg);
    final Image out = os.images().update(in);
    msg.setBody(out);
}
Also used : Message(org.apache.camel.Message) Image(org.openstack4j.model.image.Image)

Example 3 with Image

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

the class GlanceProducer method doCreate.

private void doCreate(Exchange exchange) {
    final Message msg = exchange.getIn();
    final Image in = messageHeadersToImage(msg, true);
    final Payload payload = createPayload(msg);
    final Image out = os.images().create(in, payload);
    msg.setBody(out);
}
Also used : Message(org.apache.camel.Message) Payload(org.openstack4j.model.common.Payload) Image(org.openstack4j.model.image.Image)

Example 4 with Image

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

the class GlanceProducer method doGet.

private void doGet(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String imageId = msg.getHeader(OpenstackConstants.ID, String.class);
    ObjectHelper.notEmpty(imageId, "ImageID");
    final Image out = os.images().get(imageId);
    msg.setBody(out);
}
Also used : Message(org.apache.camel.Message) Image(org.openstack4j.model.image.Image)

Example 5 with Image

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

the class GlanceProducerTest method uploadWithUpdatingTest.

@Test
public void uploadWithUpdatingTest() throws Exception {
    final String newName = "newName";
    dummyImage.setName(newName);
    when(osImage.getName()).thenReturn(newName);
    msg.setHeader(OpenstackConstants.OPERATION, GlanceConstants.UPLOAD);
    final String id = "id";
    msg.setHeader(OpenstackConstants.ID, id);
    msg.setHeader(OpenstackConstants.NAME, dummyImage.getName());
    msg.setHeader(GlanceConstants.OWNER, dummyImage.getOwner());
    msg.setHeader(GlanceConstants.MIN_DISK, dummyImage.getMinDisk());
    msg.setHeader(GlanceConstants.MIN_RAM, dummyImage.getMinRam());
    msg.setHeader(GlanceConstants.CHECKSUM, dummyImage.getChecksum());
    msg.setHeader(GlanceConstants.DISK_FORMAT, dummyImage.getDiskFormat());
    msg.setHeader(GlanceConstants.CONTAINER_FORMAT, dummyImage.getContainerFormat());
    final File file = File.createTempFile("image", ".iso");
    msg.setBody(file);
    producer.process(exchange);
    ArgumentCaptor<Payload> payloadCaptor = ArgumentCaptor.forClass(Payload.class);
    ArgumentCaptor<String> imageIdCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<org.openstack4j.model.image.Image> imageCaptor = ArgumentCaptor.forClass(org.openstack4j.model.image.Image.class);
    verify(imageService).upload(imageIdCaptor.capture(), payloadCaptor.capture(), imageCaptor.capture());
    assertEquals(id, imageIdCaptor.getValue());
    assertEquals(file, payloadCaptor.getValue().getRaw());
    assertEquals(newName, imageCaptor.getValue().getName());
    final Image result = msg.getBody(Image.class);
    assertNotNull(result.getId());
    assertEqualsImages(dummyImage, result);
}
Also used : Payload(org.openstack4j.model.common.Payload) Matchers.anyString(org.mockito.Matchers.anyString) GlanceImage(org.openstack4j.openstack.image.domain.GlanceImage) Image(org.openstack4j.model.image.Image) File(java.io.File) Test(org.junit.Test)

Aggregations

Image (org.openstack4j.model.image.Image)11 Test (org.junit.Test)6 GlanceImage (org.openstack4j.openstack.image.domain.GlanceImage)6 Message (org.apache.camel.Message)5 Payload (org.openstack4j.model.common.Payload)5 File (java.io.File)2 Matchers.anyString (org.mockito.Matchers.anyString)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 Producer (org.apache.camel.Producer)1 VolumeProducer (org.apache.camel.component.openstack.cinder.producer.VolumeProducer)1 GlanceEndpoint (org.apache.camel.component.openstack.glance.GlanceEndpoint)1 GlanceProducer (org.apache.camel.component.openstack.glance.GlanceProducer)1 ProjectProducer (org.apache.camel.component.openstack.keystone.producer.ProjectProducer)1 NetworkProducer (org.apache.camel.component.openstack.neutron.producer.NetworkProducer)1 KeypairProducer (org.apache.camel.component.openstack.nova.producer.KeypairProducer)1 ContainerProducer (org.apache.camel.component.openstack.swift.producer.ContainerProducer)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1