Search in sources :

Example 26 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource 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 27 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource 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 28 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource 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 29 with CloudResource

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

the class RemoveInstanceHandler method accept.

@Override
public void accept(Event<RemoveInstanceRequest> removeInstanceRequestEvent) {
    RemoveInstanceRequest request = removeInstanceRequestEvent.getData();
    RemoveInstanceResult result;
    try {
        CloudContext cloudContext = request.getCloudContext();
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().downscale(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances(), Collections.emptyMap());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        LOGGER.info("Instance remove successfully finished for {}", cloudContext);
        result = new RemoveInstanceResult(new DownscaleStackResult(request, ResourceLists.transform(statePollerResult.getResults())), request);
    } catch (Exception e) {
        LOGGER.error("Failed to handle RemoveInstanceRequest.", e);
        result = new RemoveInstanceResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(removeInstanceRequestEvent.getHeaders(), result));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) RemoveInstanceResult(com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) RemoveInstanceRequest(com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 30 with CloudResource

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

the class TestApplicationContext method cloudConnectors.

@Bean
public CloudConnector cloudConnectors() throws Exception {
    CloudResource resource = new Builder().type(ResourceType.HEAT_STACK).name("ref").build();
    when(cloudConnector.authentication()).thenReturn(authenticator);
    when(cloudConnector.credentials()).thenReturn(credentialConnector);
    when(credentialConnector.create(any(AuthenticatedContext.class))).thenReturn(new CloudCredentialStatus(null, CredentialStatus.CREATED));
    when(credentialConnector.delete(any(AuthenticatedContext.class))).thenReturn(new CloudCredentialStatus(null, CredentialStatus.DELETED));
    when(authenticator.authenticate(any(), any())).thenReturn(g.createAuthenticatedContext());
    when(cloudConnector.platform()).thenReturn(Platform.platform("TESTCONNECTOR"));
    when(cloudConnector.variant()).thenReturn(Variant.variant("TESTVARIANT"));
    when(cloudConnector.resources()).thenReturn(resourceConnector);
    when(cloudConnector.instances()).thenReturn(instanceConnector);
    when(cloudConnector.metadata()).thenReturn(collector);
    when(resourceConnector.launch(any(), any(), any(), any(), anyLong())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.CREATED)));
    when(resourceConnector.terminate(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.DELETED)));
    when(resourceConnector.update(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(resourceConnector.upscale(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(resourceConnector.downscale(any(), any(), any(), anyList(), anyMap())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(instanceConnector.check(any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STARTED)));
    CloudVmInstanceStatus collectInstanceStatus = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS);
    when(collector.collect(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmMetaDataStatus(collectInstanceStatus, new CloudInstanceMetaData("privateIp", "publicIp", "hypervisor"))));
    when(instanceConnector.start(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STARTED)));
    when(instanceConnector.stop(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STOPPED)));
    when(instanceConnector.getConsoleOutput(any(), eq(cloudInstance))).thenReturn(g.getSshFingerprint() + "    RSA/n-----END SSH HOST KEY FINGERPRINTS-----");
    when(instanceConnector.getConsoleOutput(any(), eq(cloudInstanceBad))).thenReturn("XYZ    RSA/n-----END SSH HOST KEY FINGERPRINTS-----");
    return cloudConnector;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Bean(org.springframework.context.annotation.Bean)

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