Search in sources :

Example 1 with VolumeSnapshot

use of org.openstack4j.model.storage.block.VolumeSnapshot in project camel by apache.

the class SnapshotProducer method doCreate.

private void doCreate(Exchange exchange) {
    final Message msg = exchange.getIn();
    final VolumeSnapshot in = messageToSnapshot(msg);
    final VolumeSnapshot out = os.blockStorage().snapshots().create(in);
    msg.setBody(out);
}
Also used : Message(org.apache.camel.Message) VolumeSnapshot(org.openstack4j.model.storage.block.VolumeSnapshot)

Example 2 with VolumeSnapshot

use of org.openstack4j.model.storage.block.VolumeSnapshot in project camel by apache.

the class SnapshotProducer method doGet.

private void doGet(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String id = msg.getHeader(OpenstackConstants.ID, msg.getHeader(CinderConstants.SNAPSHOT_ID, String.class), String.class);
    ObjectHelper.notEmpty(id, "Snapshot ID");
    final VolumeSnapshot out = os.blockStorage().snapshots().get(id);
    msg.setBody(out);
}
Also used : Message(org.apache.camel.Message) VolumeSnapshot(org.openstack4j.model.storage.block.VolumeSnapshot)

Example 3 with VolumeSnapshot

use of org.openstack4j.model.storage.block.VolumeSnapshot in project camel by apache.

the class SnapshotProducer method messageToSnapshot.

private VolumeSnapshot messageToSnapshot(Message message) {
    VolumeSnapshot volume = message.getBody(VolumeSnapshot.class);
    if (volume == null) {
        Map headers = message.getHeaders();
        VolumeSnapshotBuilder builder = Builders.volumeSnapshot();
        final String name = message.getHeader(OpenstackConstants.NAME, String.class);
        ObjectHelper.notEmpty(name, "Name");
        builder.name(name);
        if (headers.containsKey(OpenstackConstants.DESCRIPTION)) {
            builder.description(message.getHeader(OpenstackConstants.DESCRIPTION, String.class));
        }
        if (headers.containsKey(CinderConstants.VOLUME_ID)) {
            builder.volume(message.getHeader(CinderConstants.VOLUME_ID, String.class));
        }
        if (headers.containsKey(CinderConstants.FORCE)) {
            builder.force(message.getHeader(CinderConstants.FORCE, Boolean.class));
        }
        volume = builder.build();
    }
    return volume;
}
Also used : VolumeSnapshotBuilder(org.openstack4j.model.storage.block.builder.VolumeSnapshotBuilder) VolumeSnapshot(org.openstack4j.model.storage.block.VolumeSnapshot) Map(java.util.Map)

Example 4 with VolumeSnapshot

use of org.openstack4j.model.storage.block.VolumeSnapshot in project camel by apache.

the class VolumeSnapshotProducerTest method createVolumeTest.

@Test
public void createVolumeTest() throws Exception {
    when(endpoint.getOperation()).thenReturn(OpenstackConstants.CREATE);
    msg.setBody(dummyVolumeSnapshot);
    producer.process(exchange);
    final VolumeSnapshot result = msg.getBody(VolumeSnapshot.class);
    assertEqualsVolumeSnapshots(dummyVolumeSnapshot, result);
    assertNotNull(result.getId());
}
Also used : VolumeSnapshot(org.openstack4j.model.storage.block.VolumeSnapshot) Test(org.junit.Test)

Example 5 with VolumeSnapshot

use of org.openstack4j.model.storage.block.VolumeSnapshot in project camel by apache.

the class SnapshotProducer method doUpdate.

private void doUpdate(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String id = msg.getHeader(OpenstackConstants.ID, msg.getHeader(CinderConstants.SNAPSHOT_ID, String.class), String.class);
    final VolumeSnapshot vs = messageToSnapshot(msg);
    ObjectHelper.notEmpty(id, "Cinder Snapshot ID");
    final ActionResponse out = os.blockStorage().snapshots().update(id, vs.getName(), vs.getDescription());
    checkFailure(out, msg, "Update volume snapshot " + id);
}
Also used : Message(org.apache.camel.Message) VolumeSnapshot(org.openstack4j.model.storage.block.VolumeSnapshot) ActionResponse(org.openstack4j.model.common.ActionResponse)

Aggregations

VolumeSnapshot (org.openstack4j.model.storage.block.VolumeSnapshot)5 Message (org.apache.camel.Message)3 Map (java.util.Map)1 Test (org.junit.Test)1 ActionResponse (org.openstack4j.model.common.ActionResponse)1 VolumeSnapshotBuilder (org.openstack4j.model.storage.block.builder.VolumeSnapshotBuilder)1