Search in sources :

Example 1 with Volume

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

the class VolumeProducer method doGet.

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

Example 2 with Volume

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

the class VolumeProducer method doCreate.

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

Example 3 with Volume

use of org.openstack4j.model.storage.block.Volume in project openstack4j by ContainX.

the class VolumeTests method getVolumeV2.

@SuppressWarnings("unchecked")
@Test
@SkipTest(connector = ".*", issue = 395, description = "Volume attribute not recognized when using cinder v2 api")
public void getVolumeV2() throws Exception {
    // Check get volume
    respondWith("/storage/v2/volume.json");
    Volume volume = osv3().blockStorage().volumes().get("8a9287b7-4f4d-4213-8d75-63470f19f27c");
    RecordedRequest getRequest = server.takeRequest();
    assertTrue(getRequest.getPath().matches("/v[12]/\\p{XDigit}*/volumes/8a9287b7-4f4d-4213-8d75-63470f19f27c"));
    assertEquals(volume.getId(), "8a9287b7-4f4d-4213-8d75-63470f19f27c");
    assertEquals(volume.getName(), "vol-test");
    assertEquals(volume.getDescription(), "a description");
    assertNotNull(volume.getCreated());
    assertEquals(volume.getZone(), "nova");
    assertEquals(volume.getSize(), 100);
    assertEquals(volume.getStatus(), Volume.Status.IN_USE);
    assertEquals(volume.getSnapshotId(), "22222222-2222-2222-2222-222222222222");
    assertEquals(volume.getSourceVolid(), "11111111-1111-1111-1111-111111111111");
    assertEquals(volume.getVolumeType(), "Gold");
    assertNotNull(volume.getMetaData());
    Map<String, String> metadata = volume.getMetaData();
    assertEquals(metadata.get("readonly"), "False");
    assertEquals(metadata.get("attached_mode"), "rw");
    assertNotNull(volume.getAttachments());
    List<VolumeAttachment> attachments = (List<VolumeAttachment>) volume.getAttachments();
    assertEquals(attachments.get(0).getDevice(), "/dev/vdd");
    assertEquals(attachments.get(0).getHostname(), "myhost");
    assertEquals(attachments.get(0).getId(), "8a9287b7-4f4d-4213-8d75-63470f19f27c");
    assertEquals(attachments.get(0).getServerId(), "eaa6a54d-35c1-40ce-831d-bb61f991e1a9");
    assertEquals(attachments.get(0).getVolumeId(), "8a9287b7-4f4d-4213-8d75-63470f19f27c");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) VolumeAttachment(org.openstack4j.model.storage.block.VolumeAttachment) Volume(org.openstack4j.model.storage.block.Volume) List(java.util.List) AbstractTest(org.openstack4j.api.AbstractTest) SkipTest(org.openstack4j.api.SkipTest) Test(org.testng.annotations.Test) SkipTest(org.openstack4j.api.SkipTest)

Example 4 with Volume

use of org.openstack4j.model.storage.block.Volume in project cloudbreak by hortonworks.

the class OpenStackAttachedDiskResourceBuilder method build.

@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
    List<CloudResource> resources = new ArrayList<>();
    List<CloudResource> syncedResources = Collections.synchronizedList(resources);
    Collection<Future<Void>> futures = new ArrayList<>();
    for (CloudResource cloudResource : buildableResource) {
        Future<Void> submit = intermediateBuilderExecutor.submit(() -> {
            CinderVolumeView volumeView = cloudResource.getParameter(VOLUME_VIEW, CinderVolumeView.class);
            Volume osVolume = Builders.volume().name(cloudResource.getName()).size(volumeView.getSize()).build();
            try {
                OSClient<?> osClient = createOSClient(auth);
                osVolume = osClient.blockStorage().volumes().create(osVolume);
                CloudResource newRes = createPersistedResource(cloudResource, group.getName(), osVolume.getId());
                newRes.putParameter(OpenStackConstants.VOLUME_MOUNT_POINT, volumeView.getDevice());
                syncedResources.add(newRes);
            } catch (OS4JException ex) {
                throw new OpenStackResourceException("Volume creation failed", resourceType(), cloudResource.getName(), ex);
            }
            return null;
        });
        futures.add(submit);
    }
    for (Future<Void> future : futures) {
        future.get();
    }
    return resources;
}
Also used : CinderVolumeView(com.sequenceiq.cloudbreak.cloud.openstack.view.CinderVolumeView) Volume(org.openstack4j.model.storage.block.Volume) OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) OS4JException(org.openstack4j.api.exceptions.OS4JException)

Example 5 with Volume

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

the class VolumeProducer method messageToVolume.

private Volume messageToVolume(Message message) {
    Volume volume = message.getBody(Volume.class);
    if (volume == null) {
        Map headers = message.getHeaders();
        VolumeBuilder builder = Builders.volume();
        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.SIZE)) {
            builder.size(message.getHeader(CinderConstants.SIZE, Integer.class));
        }
        if (headers.containsKey(CinderConstants.VOLUME_TYPE)) {
            builder.volumeType(message.getHeader(CinderConstants.VOLUME_TYPE, String.class));
        }
        if (headers.containsKey(CinderConstants.IMAGE_REF)) {
            builder.imageRef(message.getHeader(CinderConstants.IMAGE_REF, String.class));
        }
        if (headers.containsKey(CinderConstants.SNAPSHOT_ID)) {
            builder.snapshot(message.getHeader(CinderConstants.SNAPSHOT_ID, String.class));
        }
        if (headers.containsKey(CinderConstants.IS_BOOTABLE)) {
            builder.bootable(message.getHeader(CinderConstants.IS_BOOTABLE, Boolean.class));
        }
        volume = builder.build();
    }
    return volume;
}
Also used : Volume(org.openstack4j.model.storage.block.Volume) VolumeBuilder(org.openstack4j.model.storage.block.builder.VolumeBuilder) Map(java.util.Map)

Aggregations

Volume (org.openstack4j.model.storage.block.Volume)8 Message (org.apache.camel.Message)3 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)2 List (java.util.List)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 AbstractTest (org.openstack4j.api.AbstractTest)2 SkipTest (org.openstack4j.api.SkipTest)2 VolumeAttachment (org.openstack4j.model.storage.block.VolumeAttachment)2 Test (org.testng.annotations.Test)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CinderVolumeView (com.sequenceiq.cloudbreak.cloud.openstack.view.CinderVolumeView)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1 OS4JException (org.openstack4j.api.exceptions.OS4JException)1 ActionResponse (org.openstack4j.model.common.ActionResponse)1 Status (org.openstack4j.model.storage.block.Volume.Status)1 VolumeBuilder (org.openstack4j.model.storage.block.builder.VolumeBuilder)1