Search in sources :

Example 41 with CloudInstance

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

the class AwsMetadataCollector method ensureInstanceTag.

private CloudInstance ensureInstanceTag(Map<String, CloudInstance> mapByInstanceId, Instance instance, String instanceId, Queue<CloudInstance> untrackedInstances, AmazonEC2 amazonEC2Client) {
    // we need to figure out whether it is already tracked or not, if it is already tracked then it has a tag
    String tag = getTag(instance);
    CloudInstance cloudInstance = mapByInstanceId.get(instanceId);
    if (cloudInstance == null) {
        if (tag == null) {
            // an untracked CloudInstance
            if (!untrackedInstances.isEmpty()) {
                cloudInstance = untrackedInstances.remove();
                cloudInstance = new CloudInstance(instanceId, cloudInstance.getTemplate(), cloudInstance.getAuthentication());
            }
        }
    }
    if (cloudInstance != null && tag == null) {
        addTag(amazonEC2Client, cloudInstance, instance);
    }
    return cloudInstance;
}
Also used : CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 42 with CloudInstance

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

the class AwsMetadataCollector method collect.

@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) {
    List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
    try {
        String region = ac.getCloudContext().getLocation().getRegion().value();
        AmazonCloudFormationClient amazonCFClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), region);
        AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), region);
        AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region);
        // contains all instances
        ListMultimap<String, CloudInstance> groupByInstanceGroup = groupByInstanceGroup(vms);
        for (String key : groupByInstanceGroup.keySet()) {
            List<CloudInstance> cloudInstances = groupByInstanceGroup.get(key);
            cloudVmMetaDataStatuses.addAll(collectGroupMetaData(ac, amazonASClient, amazonEC2Client, amazonCFClient, key, cloudInstances));
        }
        return cloudVmMetaDataStatuses;
    } catch (RuntimeException e) {
        throw new CloudConnectorException(e.getMessage(), e);
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient)

Example 43 with CloudInstance

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

the class StackCreationActions method provisioningFinishedAction.

@Bean(name = "PROVISIONING_FINISHED_STATE")
public Action<?, ?> provisioningFinishedAction() {
    return new AbstractStackCreationAction<LaunchStackResult>(LaunchStackResult.class) {

        @Override
        protected void doExecute(StackContext context, LaunchStackResult payload, Map<Object, Object> variables) {
            Stack stack = stackCreationService.provisioningFinished(context, payload, variables);
            StackContext newContext = new StackContext(context.getFlowId(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            sendEvent(newContext);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(context.getStack());
            List<CloudResource> cloudResources = cloudResourceConverter.convert(context.getStack().getResources());
            return new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
        }
    };
}
Also used : CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) Bean(org.springframework.context.annotation.Bean)

Example 44 with CloudInstance

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

the class StackDownscaleActions method stackDownscaleCollectResourcesAction.

@Bean(name = "DOWNSCALE_COLLECT_RESOURCES_STATE")
public Action<?, ?> stackDownscaleCollectResourcesAction() {
    return new AbstractStackDownscaleAction<StackDownscaleTriggerEvent>(StackDownscaleTriggerEvent.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, StackDownscaleTriggerEvent payload, Map<Object, Object> variables) {
            stackDownscaleService.startStackDownscale(context, payload);
            Stack stack = context.getStack();
            LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
            List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
            variables.put(RESOURCES, resources);
            List<CloudInstance> instances = new ArrayList<>();
            InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
            for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
                if (context.getInstanceIds().contains(metaData.getInstanceId())) {
                    CloudInstance cloudInstance = metadataConverter.convert(metaData);
                    instances.add(cloudInstance);
                }
            }
            variables.put(INSTANCES, instances);
            Selectable request = new DownscaleStackCollectResourcesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), resources, instances);
            sendEvent(context.getFlowId(), request);
        }
    };
}
Also used : DownscaleStackCollectResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 45 with CloudInstance

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

the class AbstractInstanceTerminationAction method createFlowContext.

@Override
protected InstanceTerminationContext createFlowContext(String flowId, StateContext<InstanceTerminationState, InstanceTerminationEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithLists(payload.getStackId());
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    Set<String> instanceIds = payload.getInstanceIds();
    CloudStack cloudStack = cloudStackConverter.convert(stack, instanceIds);
    List<CloudResource> cloudResources = cloudResourceConverter.convert(stack.getResources());
    List<InstanceMetaData> instanceMetaDataList = new ArrayList<>();
    List<CloudInstance> cloudInstances = new ArrayList<>();
    for (String instanceId : instanceIds) {
        InstanceMetaData instanceMetaData = instanceMetaDataRepository.findByInstanceId(stack.getId(), instanceId);
        CloudInstance cloudInstance = metadataConverter.convert(instanceMetaData);
        instanceMetaDataList.add(instanceMetaData);
        cloudInstances.add(cloudInstance);
    }
    return new InstanceTerminationContext(flowId, stack, cloudContext, cloudCredential, cloudStack, cloudResources, cloudInstances, instanceMetaDataList);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)75 ArrayList (java.util.ArrayList)41 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)32 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)25 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)20 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)17 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)16 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)12 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)10 Group (com.sequenceiq.cloudbreak.cloud.model.Group)10 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)10 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)9 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)7 Instance (com.amazonaws.services.ec2.model.Instance)7