Search in sources :

Example 31 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class StartStackHandler method accept.

@Override
public void accept(Event<StartInstancesRequest> event) {
    LOGGER.info("Received event: {}", event);
    StartInstancesRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext authenticatedContext = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudInstance> instances = request.getCloudInstances();
        List<CloudVmInstanceStatus> instanceStatuses = connector.instances().start(authenticatedContext, request.getResources(), instances);
        PollTask<InstancesStatusResult> task = statusCheckFactory.newPollInstanceStateTask(authenticatedContext, instances, Sets.newHashSet(InstanceStatus.STARTED, InstanceStatus.FAILED));
        InstancesStatusResult statusResult = new InstancesStatusResult(cloudContext, instanceStatuses);
        if (!task.completed(statusResult)) {
            statusResult = syncPollingScheduler.schedule(task);
        }
        StartInstancesResult result = new StartInstancesResult(request, cloudContext, statusResult);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    } catch (Exception e) {
        StartInstancesResult failure = new StartInstancesResult("Failed to start stack", e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) InstancesStatusResult(com.sequenceiq.cloudbreak.cloud.event.instance.InstancesStatusResult) StartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult) Event(reactor.bus.Event)

Example 32 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class GroupResourceService method buildResources.

public List<CloudResourceStatus> buildResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<Group> groups, Network network, Security security) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    List<CloudResourceStatus> results = new ArrayList<>();
    for (GroupResourceBuilder builder : resourceBuilders.group(cloudContext.getPlatform())) {
        PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
        if (pollGroup != null && CANCELLED.equals(pollGroup)) {
            break;
        }
        for (Group group : getOrderedCopy(groups)) {
            try {
                CloudResource buildableResource = builder.create(context, auth, group, network);
                createResource(auth, buildableResource);
                CloudResource resource = builder.build(context, auth, group, network, group.getSecurity(), buildableResource);
                updateResource(auth, resource);
                PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(resource), context, true);
                List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                context.addGroupResources(group.getName(), Collections.singletonList(resource));
                results.addAll(pollerResult);
            } catch (ResourceNotNeededException e) {
                LOGGER.warn("Skipping resource creation: {}", e.getMessage());
            }
        }
    }
    return results;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GroupResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.GroupResourceBuilder) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ResourceNotNeededException(com.sequenceiq.cloudbreak.cloud.template.ResourceNotNeededException)

Example 33 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class NetworkResourceService method deleteResources.

public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, Network network, boolean cancellable) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    List<CloudResourceStatus> results = new ArrayList<>();
    List<NetworkResourceBuilder> builderChain = resourceBuilders.network(cloudContext.getPlatform());
    for (int i = builderChain.size() - 1; i >= 0; i--) {
        NetworkResourceBuilder builder = builderChain.get(i);
        List<CloudResource> specificResources = getResources(resources, builder.resourceType());
        for (CloudResource resource : specificResources) {
            if (resource.getStatus() == CommonStatus.CREATED) {
                CloudResource deletedResource = builder.delete(context, auth, resource, network);
                if (deletedResource != null) {
                    PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(deletedResource), context, cancellable);
                    List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                    results.addAll(pollerResult);
                }
            }
            resourceNotifier.notifyDeletion(resource, cloudContext);
        }
    }
    return results;
}
Also used : NetworkResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 34 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class NetworkResourceService method update.

public List<CloudResourceStatus> update(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security, Iterable<CloudResource> networkResources) throws Exception {
    List<CloudResourceStatus> results = new ArrayList<>();
    CloudContext cloudContext = auth.getCloudContext();
    for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
        CloudResource resource = getResources(networkResources, builder.resourceType()).get(0);
        CloudResourceStatus status = builder.update(context, auth, network, security, resource);
        if (status != null) {
            PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(status.getCloudResource()), context, true);
            List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
            results.addAll(pollerResult);
        }
    }
    return results;
}
Also used : NetworkResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 35 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class ProvisionSetupHandler method accept.

@Override
public void accept(Event<SetupRequest> event) {
    LOGGER.info("Received event: {}", event);
    SetupRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    SetupResult result;
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        CloudStack cloudStack = request.getCloudStack();
        connector.setup().prerequisites(auth, cloudStack, resourceNotifier);
        result = new SetupResult(request);
        LOGGER.info("Provision setup finished for {}", cloudContext);
    } catch (RuntimeException e) {
        result = new SetupResult(e, request);
    }
    request.getResult().onNext(result);
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : SetupResult(com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) SetupRequest(com.sequenceiq.cloudbreak.cloud.event.setup.SetupRequest)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)100 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)43 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)34 Test (org.junit.Test)34 Group (com.sequenceiq.cloudbreak.cloud.model.Group)33 HashMap (java.util.HashMap)33 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)32 Location (com.sequenceiq.cloudbreak.cloud.model.Location)31 Network (com.sequenceiq.cloudbreak.cloud.model.Network)31 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)31 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)25 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)19 Matchers.containsString (org.hamcrest.Matchers.containsString)18 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)16 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)15 ArrayList (java.util.ArrayList)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14