Search in sources :

Example 1 with Payload

use of org.openstack4j.model.common.Payload 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)

Example 2 with Payload

use of org.openstack4j.model.common.Payload 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 3 with Payload

use of org.openstack4j.model.common.Payload 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 Payload

use of org.openstack4j.model.common.Payload in project camel by apache.

the class AbstractOpenstackProducer method createPayload.

protected Payload createPayload(Message msg) {
    //if payload object is send directly
    Payload payload = msg.getBody(Payload.class);
    if (ObjectHelper.isNotEmpty(payload)) {
        return payload;
    }
    Object messageBody = msg.getBody();
    if (messageBody instanceof URL) {
        payload = Payloads.create((URL) messageBody);
    }
    if (messageBody instanceof File) {
        payload = Payloads.create((File) messageBody);
    }
    if (messageBody instanceof InputStream) {
        payload = Payloads.create((InputStream) messageBody);
    }
    if (payload == null) {
        throw new IllegalArgumentException("You have to set payload. It can be InputStream, File or URL class");
    }
    return payload;
}
Also used : InputStream(java.io.InputStream) Payload(org.openstack4j.model.common.Payload) File(java.io.File) URL(java.net.URL)

Example 5 with Payload

use of org.openstack4j.model.common.Payload in project camel by apache.

the class ObjectProducer method doCreate.

private void doCreate(Exchange exchange) {
    final Message msg = exchange.getIn();
    final Payload payload = createPayload(msg);
    final String containerName = msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class);
    final String objectName = msg.getHeader(SwiftConstants.OBJECT_NAME, String.class);
    ObjectHelper.notEmpty(containerName, "Container name");
    ObjectHelper.notEmpty(objectName, "Object name");
    final String etag = os.objectStorage().objects().put(containerName, objectName, payload);
    msg.setBody(etag);
}
Also used : Message(org.apache.camel.Message) Payload(org.openstack4j.model.common.Payload)

Aggregations

Payload (org.openstack4j.model.common.Payload)8 Image (org.openstack4j.model.image.Image)5 Test (org.junit.Test)4 File (java.io.File)3 Message (org.apache.camel.Message)3 Matchers.anyString (org.mockito.Matchers.anyString)3 GlanceImage (org.openstack4j.openstack.image.domain.GlanceImage)3 InputStream (java.io.InputStream)2 FileInputStream (java.io.FileInputStream)1 URL (java.net.URL)1