Search in sources :

Example 56 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class GcpMetadataCollector method collect.

@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
    List<CloudVmMetaDataStatus> instanceMetaData = new ArrayList<>();
    Map<String, CloudResource> instanceNameMap = groupByInstanceName(resources);
    Map<Long, CloudResource> privateIdMap = groupByPrivateId(resources);
    for (CloudInstance cloudInstance : vms) {
        String instanceId = cloudInstance.getInstanceId();
        CloudResource cloudResource;
        cloudResource = instanceId != null ? instanceNameMap.get(instanceId) : privateIdMap.get(cloudInstance.getTemplate().getPrivateId());
        CloudVmMetaDataStatus cloudVmMetaDataStatus = getCloudVmMetaDataStatus(authenticatedContext, cloudResource, cloudInstance);
        instanceMetaData.add(cloudVmMetaDataStatus);
    }
    return instanceMetaData;
}
Also used : CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 57 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class GcpFirewallInResourceBuilder method update.

@Override
public CloudResourceStatus update(GcpContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) {
    String projectId = context.getProjectId();
    Compute compute = context.getCompute();
    String resourceName = resource.getName();
    try {
        Firewall fireWall = compute.firewalls().get(projectId, resourceName).execute();
        List<String> sourceRanges = getSourceRanges(security);
        fireWall.setSourceRanges(sourceRanges);
        Operation operation = compute.firewalls().update(projectId, resourceName, fireWall).execute();
        CloudResource cloudResource = createOperationAwareCloudResource(resource, operation);
        return checkResources(context, auth, Collections.singletonList(cloudResource)).get(0);
    } catch (IOException e) {
        throw new GcpResourceException("Failed to update resource!", GCP_FIREWALL_IN, resourceName, e);
    }
}
Also used : Compute(com.google.api.services.compute.Compute) GcpResourceException(com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException) Operation(com.google.api.services.compute.model.Operation) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) IOException(java.io.IOException) Firewall(com.google.api.services.compute.model.Firewall)

Example 58 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class ComputeResourceService method stopStart.

private List<CloudVmInstanceStatus> stopStart(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, Iterable<CloudInstance> instances) {
    List<CloudVmInstanceStatus> results = new ArrayList<>();
    Collection<Future<ResourceRequestResult<List<CloudVmInstanceStatus>>>> futures = new ArrayList<>();
    Platform platform = auth.getCloudContext().getPlatform();
    List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
    if (!context.isBuild()) {
        Collections.reverse(builders);
    }
    for (ComputeResourceBuilder builder : builders) {
        List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
        for (CloudResource cloudResource : resourceList) {
            CloudInstance instance = getCloudInstance(cloudResource, instances);
            if (instance != null) {
                ResourceStopStartThread thread = createThread(ResourceStopStartThread.NAME, context, auth, cloudResource, instance, builder);
                Future<ResourceRequestResult<List<CloudVmInstanceStatus>>> future = resourceBuilderExecutor.submit(thread);
                futures.add(future);
                if (isRequestFull(futures.size(), context)) {
                    results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
                }
            } else {
                break;
            }
        }
    }
    results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
    return results;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 59 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class ComputeResourceService method deleteResources.

public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, boolean cancellable) {
    List<CloudResourceStatus> results = new ArrayList<>();
    Collection<Future<ResourceRequestResult<List<CloudResourceStatus>>>> futures = new ArrayList<>();
    Platform platform = auth.getCloudContext().getPlatform();
    List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
    int numberOfBuilders = builders.size();
    for (int i = numberOfBuilders - 1; i >= 0; i--) {
        ComputeResourceBuilder builder = builders.get(i);
        List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
        for (CloudResource cloudResource : resourceList) {
            ResourceDeleteThread thread = createThread(ResourceDeleteThread.NAME, context, auth, cloudResource, builder, cancellable);
            Future<ResourceRequestResult<List<CloudResourceStatus>>> future = resourceBuilderExecutor.submit(thread);
            futures.add(future);
            if (isRequestFull(futures.size(), context)) {
                results.addAll(flatList(waitForRequests(futures).get(FutureResult.SUCCESS)));
            }
        }
        // wait for builder type to finish before starting the next one
        results.addAll(flatList(waitForRequests(futures).get(FutureResult.SUCCESS)));
    }
    return results;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) ArrayList(java.util.ArrayList) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 60 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class ResourceCreateThread method call.

@Override
public ResourceRequestResult<List<CloudResourceStatus>> call() {
    List<CloudResourceStatus> results = new ArrayList<>();
    Collection<CloudResource> buildableResources = new ArrayList<>();
    try {
        for (ComputeResourceBuilder builder : resourceBuilders.compute(auth.getCloudContext().getPlatform())) {
            LOGGER.info("Building {} resources of {} instance group", builder.resourceType(), group.getName());
            List<CloudResource> cloudResources = builder.create(context, privateId, auth, group, image);
            if (!cloudResources.isEmpty()) {
                buildableResources.addAll(cloudResources);
                createResource(auth, cloudResources);
                PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
                if (pollGroup != null && CANCELLED.equals(pollGroup)) {
                    throw new CancellationException(format("Building of %s has been cancelled", cloudResources));
                }
                List<CloudResource> resources = builder.build(context, privateId, auth, group, image, cloudResources, tags);
                updateResource(auth, resources);
                context.addComputeResources(privateId, resources);
                PollTask<List<CloudResourceStatus>> task = resourcePollTaskFactory.newPollResourceTask(builder, auth, resources, context, true);
                List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                for (CloudResourceStatus resourceStatus : pollerResult) {
                    resourceStatus.setPrivateId(privateId);
                }
                results.addAll(pollerResult);
            }
        }
    } catch (CancellationException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("", e);
        results.clear();
        for (CloudResource buildableResource : buildableResources) {
            results.add(new CloudResourceStatus(buildableResource, ResourceStatus.FAILED, e.getMessage(), privateId));
        }
        return new ResourceRequestResult<>(FutureResult.FAILED, results);
    }
    return new ResourceRequestResult<>(FutureResult.SUCCESS, results);
}
Also used : ArrayList(java.util.ArrayList) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)79 ArrayList (java.util.ArrayList)33 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)29 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)20 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)17 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)16 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)13 List (java.util.List)11 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)8 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 Location (com.sequenceiq.cloudbreak.cloud.model.Location)8 Group (com.sequenceiq.cloudbreak.cloud.model.Group)7 Operation (com.google.api.services.compute.model.Operation)6 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)6 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)6 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)6 Map (java.util.Map)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5