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;
}
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);
}
}
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);
}
};
}
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);
}
};
}
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);
}
Aggregations