use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus in project cloudbreak by hortonworks.
the class GcpMetadataCollector method getCloudVmMetaDataStatus.
private CloudVmMetaDataStatus getCloudVmMetaDataStatus(AuthenticatedContext authenticatedContext, CloudResource cloudResource, CloudInstance matchedInstance) {
CloudVmMetaDataStatus cloudVmMetaDataStatus;
if (cloudResource != null) {
CloudInstance cloudInstance = new CloudInstance(cloudResource.getName(), matchedInstance.getTemplate(), matchedInstance.getAuthentication());
try {
CloudCredential credential = authenticatedContext.getCloudCredential();
CloudContext cloudContext = authenticatedContext.getCloudContext();
Compute compute = GcpStackUtil.buildCompute(credential);
Instance executeInstance = getInstance(cloudContext, credential, compute, cloudResource.getName());
String privateIp = executeInstance.getNetworkInterfaces().get(0).getNetworkIP();
String publicIp = null;
List<AccessConfig> acl = executeInstance.getNetworkInterfaces().get(0).getAccessConfigs();
if (acl != null && acl.get(0) != null) {
publicIp = executeInstance.getNetworkInterfaces().get(0).getAccessConfigs().get(0).getNatIP();
}
CloudInstanceMetaData metaData = new CloudInstanceMetaData(privateIp, publicIp);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, metaData);
} catch (IOException e) {
LOGGER.warn(String.format("Instance %s is not reachable", cloudResource.getName()), e);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.UNKNOWN);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, CloudInstanceMetaData.EMPTY_METADATA);
}
} else {
CloudVmInstanceStatus status = new CloudVmInstanceStatus(matchedInstance, InstanceStatus.TERMINATED);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, CloudInstanceMetaData.EMPTY_METADATA);
}
return cloudVmMetaDataStatus;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus 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.CloudVmMetaDataStatus in project cloudbreak by hortonworks.
the class CollectMetadataHandler method accept.
@Override
public void accept(Event<CollectMetadataRequest> collectMetadataRequestEvent) {
LOGGER.info("Received event: {}", collectMetadataRequestEvent);
CollectMetadataRequest request = collectMetadataRequestEvent.getData();
try {
CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
List<CloudVmMetaDataStatus> instanceStatuses = connector.metadata().collect(ac, request.getCloudResource(), request.getVms());
CollectMetadataResult collectMetadataResult = new CollectMetadataResult(request, instanceStatuses);
request.getResult().onNext(collectMetadataResult);
eventBus.notify(collectMetadataResult.selector(), new Event<>(collectMetadataRequestEvent.getHeaders(), collectMetadataResult));
LOGGER.info("Metadata collection successfully finished");
} catch (RuntimeException e) {
CollectMetadataResult failure = new CollectMetadataResult(e, request);
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(collectMetadataRequestEvent.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus in project cloudbreak by hortonworks.
the class StackUpscaleService method finishExtendMetadata.
@Transactional
public Set<String> finishExtendMetadata(Stack stack, String instanceGroupName, CollectMetadataResult payload) {
List<CloudVmMetaDataStatus> coreInstanceMetaData = payload.getResults();
int newinstances = metadataSetupService.saveInstanceMetaData(stack, coreInstanceMetaData, CREATED);
Set<String> upscaleCandidateAddresses = new HashSet<>();
for (CloudVmMetaDataStatus cloudVmMetaDataStatus : coreInstanceMetaData) {
upscaleCandidateAddresses.add(cloudVmMetaDataStatus.getMetaData().getPrivateIp());
}
InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stack.getId(), instanceGroupName);
int nodeCount = instanceGroup.getNodeCount() + newinstances;
if (newinstances != 0) {
instanceGroup.setNodeCount(nodeCount);
instanceGroupRepository.save(instanceGroup);
}
clusterService.updateClusterStatusByStackIdOutOfTransaction(stack.getId(), AVAILABLE);
eventService.fireCloudbreakEvent(stack.getId(), BillingStatus.BILLING_CHANGED.name(), messagesService.getMessage("stack.metadata.setup.billing.changed"));
flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_METADATA_EXTEND, AVAILABLE.name());
usageService.scaleUsagesForStack(stack.getId(), instanceGroupName, nodeCount);
return upscaleCandidateAddresses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus in project cloudbreak by hortonworks.
the class ScalingMock method addSPIEndpoints.
public void addSPIEndpoints() {
Service sparkService = getSparkService();
Map<String, CloudVmMetaDataStatus> instanceMap = getInstanceMap();
sparkService.post(MOCK_ROOT + "/cloud_metadata_statuses", new CloudMetaDataStatuses(instanceMap), gson()::toJson);
sparkService.post(MOCK_ROOT + "/cloud_instance_statuses", new CloudVmInstanceStatuses(instanceMap), gson()::toJson);
sparkService.post(MOCK_ROOT + "/terminate_instances", (request, response) -> {
List<CloudInstance> cloudInstances = new Gson().fromJson(request.body(), new TypeToken<List<CloudInstance>>() {
}.getType());
cloudInstances.forEach(cloudInstance -> terminateInstance(instanceMap, cloudInstance.getInstanceId()));
return null;
}, gson()::toJson);
}
Aggregations