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