Search in sources :

Example 21 with CloudResource

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

the class OpenStackNativeMetaDataCollector method collect.

@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
    List<InstanceTemplate> templates = Lists.transform(vms, CloudInstance::getTemplate);
    Map<String, InstanceTemplate> templateMap = Maps.uniqueIndex(templates, from -> utils.getPrivateInstanceId(from.getGroupName(), Long.toString(from.getPrivateId())));
    OSClient<?> client = openStackClient.createOSClient(authenticatedContext);
    List<CloudVmMetaDataStatus> results = new ArrayList<>();
    for (CloudResource resource : resources) {
        if (resource.getType() == ResourceType.OPENSTACK_INSTANCE) {
            String instanceUUID = resource.getReference();
            Server server = client.compute().servers().get(instanceUUID);
            if (server != null) {
                Map<String, String> metadata = server.getMetadata();
                String privateInstanceId = utils.getPrivateInstanceId(metadata);
                InstanceTemplate template = templateMap.get(privateInstanceId);
                if (template != null) {
                    CloudInstanceMetaData md = cloudInstanceMetaDataExtractor.extractMetadata(client, server, instanceUUID);
                    // TODO use here sshkey
                    CloudInstance cloudInstance = new CloudInstance(instanceUUID, template, null);
                    CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
                    results.add(new CloudVmMetaDataStatus(status, md));
                }
            }
        }
    }
    return results;
}
Also used : Server(org.openstack4j.model.compute.Server) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 22 with CloudResource

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

the class MockResourceConnector method launch.

@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier, AdjustmentType adjustmentType, Long threshold) {
    List<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>();
    for (Group group : stack.getGroups()) {
        for (int i = 0; i < group.getInstancesSize(); i++) {
            CloudResource cloudResource = new Builder().type(ResourceType.MOCK_INSTANCE).status(CommonStatus.CREATED).name("cloudinstance" + cloudResourceStatuses.size()).reference("").persistent(true).build();
            cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, CREATED));
        }
    }
    return cloudResourceStatuses;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 23 with CloudResource

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

the class StackUpscaleService method transformResults.

private Set<Resource> transformResults(Iterable<CloudResourceStatus> cloudResourceStatuses, Stack stack) {
    Set<Resource> retSet = new HashSet<>();
    for (CloudResourceStatus cloudResourceStatus : cloudResourceStatuses) {
        if (!cloudResourceStatus.isFailed()) {
            CloudResource cloudResource = cloudResourceStatus.getCloudResource();
            Resource resource = new Resource(cloudResource.getType(), cloudResource.getName(), cloudResource.getReference(), cloudResource.getStatus(), stack, null);
            retSet.add(resource);
        }
    }
    return retSet;
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) HashSet(java.util.HashSet)

Example 24 with CloudResource

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

the class StackUpscaleActions method addInstances.

@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
    return new AbstractStackUpscaleAction<StackScaleTriggerEvent>(StackScaleTriggerEvent.class) {

        @Override
        protected void prepareExecution(StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            variables.put(INSTANCEGROUPNAME, payload.getInstanceGroup());
            variables.put(ADJUSTMENT, payload.getAdjustment());
            variables.put(HOSTNAMES, payload.getHostNames());
        }

        @Override
        protected void doExecute(StackScalingFlowContext context, StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            stackUpscaleService.startAddInstances(context.getStack(), payload.getAdjustment());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackScalingFlowContext context) {
            LOGGER.debug("Assembling upscale stack event for stack: {}", context.getStack());
            InstanceGroup group = context.getStack().getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
            group.setNodeCount(group.getNodeCount() + context.getAdjustment());
            CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
            instanceMetadataService.saveInstanceRequests(context.getStack(), cloudStack.getGroups());
            List<CloudResource> resources = cloudResourceConverter.convert(context.getStack().getResources());
            return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), cloudStack, resources);
        }
    };
}
Also used : StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) UpscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Map(java.util.Map) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Bean(org.springframework.context.annotation.Bean)

Example 25 with CloudResource

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

the class TerminateStackHandler method accept.

@Override
public void accept(Event<TerminateStackRequest> terminateStackRequestEvent) {
    LOGGER.info("Received event: {}", terminateStackRequestEvent);
    TerminateStackRequest request = terminateStackRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().terminate(ac, request.getCloudStack(), request.getCloudResources());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        TerminateStackResult result;
        if (!resources.isEmpty()) {
            PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, false);
            ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(request.getCloudContext(), resourceStatus);
            if (!task.completed(statePollerResult)) {
                statePollerResult = syncPollingScheduler.schedule(task);
            }
            if (!statePollerResult.getStatus().equals(ResourceStatus.DELETED)) {
                throw new CloudConnectorException("Stack could not be terminated, Resource(s) could not be deleted on the provider side.");
            } else {
                result = new TerminateStackResult(request);
            }
        } else {
            result = new TerminateStackResult(request);
        }
        CloudCredentialStatus credentialStatus = connector.credentials().delete(ac);
        if (CredentialStatus.FAILED == credentialStatus.getStatus()) {
            if (credentialStatus.getException() != null) {
                throw new CloudConnectorException(credentialStatus.getException());
            }
            throw new CloudConnectorException(credentialStatus.getStatusReason());
        }
        request.getResult().onNext(result);
        LOGGER.info("TerminateStackHandler finished");
        eventBus.notify(result.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), result));
    } catch (Exception e) {
        LOGGER.error("Failed to handle TerminateStackRequest", e);
        TerminateStackResult terminateStackResult = new TerminateStackResult("Stack termination failed.", e, request);
        request.getResult().onNext(terminateStackResult);
        eventBus.notify(terminateStackResult.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), terminateStackResult));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) TerminateStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackResult) TerminateStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

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