use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class OpenStackMetadataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
CloudResource resource = utils.getHeatResource(resources);
String stackName = utils.getStackName(authenticatedContext);
String heatStackId = resource.getName();
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);
Stack heatStack = client.heat().stacks().getDetails(stackName, heatStackId);
List<CloudVmMetaDataStatus> results = new ArrayList<>();
List<Map<String, Object>> outputs = heatStack.getOutputs();
for (Map<String, Object> map : outputs) {
String instanceUUID = (String) map.get("output_value");
if (!StringUtils.isEmpty(instanceUUID)) {
Server server = client.compute().servers().get(instanceUUID);
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 OpenStackResourceConnector method collectResources.
private List<CloudResource> collectResources(AuthenticatedContext authenticatedContext, PersistenceNotifier notifier, Stack heatStack, CloudStack stack, NeutronNetworkView neutronNetworkView) {
List<CloudResource> cloudResources = newArrayList();
CloudResource heatResource = new Builder().type(ResourceType.HEAT_STACK).name(heatStack.getId()).build();
try {
notifier.notifyAllocation(heatResource, authenticatedContext.getCloudContext());
} catch (RuntimeException ignored) {
// Rollback
terminate(authenticatedContext, stack, Collections.singletonList(heatResource));
}
cloudResources.add(heatResource);
if (!neutronNetworkView.isProviderNetwork()) {
if (!neutronNetworkView.isExistingNetwork()) {
CloudResource r = CloudResource.builder().type(ResourceType.OPENSTACK_NETWORK).name(OpenStackConstants.NETWORK_ID).build();
cloudResources.add(r);
}
if (!neutronNetworkView.isExistingSubnet()) {
CloudResource r = CloudResource.builder().type(ResourceType.OPENSTACK_SUBNET).name(OpenStackConstants.SUBNET_ID).build();
cloudResources.add(r);
}
}
return cloudResources;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class OpenStackResourceConnector method check.
@Override
public List<CloudResourceStatus> check(AuthenticatedContext authenticatedContext, List<CloudResource> resources) {
List<CloudResourceStatus> results = newArrayList();
OSClient<?> client = openStackClient.createOSClient(authenticatedContext);
String stackName = utils.getStackName(authenticatedContext);
List<CloudResource> osResourceList = openStackClient.getResources(stackName, authenticatedContext.getCloudCredential());
List<CloudResource> otherResources = newArrayList();
CloudResourceStatus heatStatus = null;
for (CloudResource resource : resources) {
if (resource.getType() == ResourceType.HEAT_STACK) {
heatStatus = checkByResourceType(authenticatedContext, client, stackName, osResourceList, resource);
results.add(heatStatus);
} else {
otherResources.add(resource);
}
}
if (heatStatus != null) {
for (CloudResource resource : otherResources) {
if (heatStatus.getStatus() == ResourceStatus.CREATED) {
results.add(checkByResourceType(authenticatedContext, client, stackName, osResourceList, resource));
} else {
results.add(new CloudResourceStatus(resource, ResourceStatus.CREATED));
}
}
}
return results;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class MockResourceConnector method upscale.
@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) {
List<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>();
for (CloudResource cloudResource : resources) {
CloudResourceStatus cloudResourceStatus = new CloudResourceStatus(cloudResource, CREATED);
cloudResourceStatuses.add(cloudResourceStatus);
}
int createResourceCount = 0;
for (int i = 0; i < stack.getGroups().size(); i++) {
createResourceCount += stack.getGroups().get(i).getInstancesSize();
}
createResourceCount -= resources.size();
if (createResourceCount > 0) {
for (int i = 0; i < createResourceCount; 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 DownscaleStackHandler method accept.
@Override
public void accept(Event<DownscaleStackRequest> downscaleStackRequestEvent) {
LOGGER.info("Received event: {}", downscaleStackRequestEvent);
DownscaleStackRequest request = downscaleStackRequestEvent.getData();
DownscaleStackResult result;
try {
CloudContext cloudContext = request.getCloudContext();
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
List<CloudResourceStatus> resourceStatus = connector.resources().downscale(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances(), request.getResourcesToScale());
List<CloudResource> resources = ResourceLists.transform(resourceStatus);
PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
if (!task.completed(statePollerResult)) {
statePollerResult = syncPollingScheduler.schedule(task);
}
LOGGER.info("Downscale successfully finished for {}", cloudContext);
result = new DownscaleStackResult(request, ResourceLists.transform(statePollerResult.getResults()));
} catch (Exception e) {
LOGGER.error("Failed to handle DownscaleStackRequest.", e);
result = new DownscaleStackResult(e.getMessage(), e, request);
}
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(downscaleStackRequestEvent.getHeaders(), result));
}
Aggregations