Search in sources :

Example 1 with CinderVolumeView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.CinderVolumeView 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)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)1 CinderVolumeView (com.sequenceiq.cloudbreak.cloud.openstack.view.CinderVolumeView)1 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 OS4JException (org.openstack4j.api.exceptions.OS4JException)1 Volume (org.openstack4j.model.storage.block.Volume)1