use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance 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));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class ParameterGenerator method createCloudStack.
public CloudStack createCloudStack() {
List<Group> groups = new ArrayList<>();
String name = "master";
List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
Security security = new Security(rules, null);
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
Subnet subnet = new Subnet("10.0.0.0/24");
Network network = new Network(subnet);
network.putParameter("publicNetId", "028ffc0c-63c5-4ca0-802a-3ac753eaf76c");
return new CloudStack(groups, network, image, new HashMap<>(), new HashMap<>(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class UnhealthyInstancesFinalizer method finalizeUnhealthyInstances.
public Set<String> finalizeUnhealthyInstances(Stack stack, Iterable<InstanceMetaData> candidateUnhealthyInstances) {
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());
List<CloudInstance> cloudInstances = cloudInstanceConverter.convert(candidateUnhealthyInstances);
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses(cloudCredential, cloudContext, cloudInstances);
Map<String, CloudVmInstanceStatus> cloudVmInstanceStatusesById = new HashMap<>();
cloudVmInstanceStatuses.forEach(c -> cloudVmInstanceStatusesById.put(c.getCloudInstance().getInstanceId(), c));
Set<String> unhealthyInstances = new HashSet<>();
for (InstanceMetaData i : candidateUnhealthyInstances) {
CloudVmInstanceStatus instanceStatus = cloudVmInstanceStatusesById.get(i.getInstanceId());
if ((instanceStatus == null) || (instanceStatus.getStatus().equals(InstanceStatus.TERMINATED))) {
unhealthyInstances.add(i.getInstanceId());
}
}
return unhealthyInstances;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class StackCreationActions method getTlsInfoAction.
@Bean(name = "GET_TLS_INFO_STATE")
public Action<?, ?> getTlsInfoAction() {
return new AbstractStackCreationAction<GetTlsInfoResult>(GetTlsInfoResult.class) {
@Override
protected void doExecute(StackContext context, GetTlsInfoResult payload, Map<Object, Object> variables) {
Stack stack = stackCreationService.saveTlsInfo(context, payload.getTlsInfo());
StackContext newContext = new StackContext(context.getFlowId(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
sendEvent(newContext);
}
@Override
protected Selectable createRequest(StackContext context) {
InstanceMetaData gatewayMetaData = context.getStack().getPrimaryGatewayInstance();
CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData);
return new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
}
};
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class StackDownscaleActions method stackDownscaleAction.
@Bean(name = "DOWNSCALE_STATE")
public Action<?, ?> stackDownscaleAction() {
return new AbstractStackDownscaleAction<DownscaleStackCollectResourcesResult>(DownscaleStackCollectResourcesResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, DownscaleStackCollectResourcesResult payload, Map<Object, Object> variables) {
Selectable request = new DownscaleStackRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), (List<CloudResource>) variables.get(RESOURCES), (List<CloudInstance>) variables.get(INSTANCES), payload.getResourcesToScale());
sendEvent(context.getFlowId(), request);
}
};
}
Aggregations