Search in sources :

Example 6 with CloudVmMetaDataStatus

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;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Instance(com.google.api.services.compute.model.Instance) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Compute(com.google.api.services.compute.Compute) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) IOException(java.io.IOException) AccessConfig(com.google.api.services.compute.model.AccessConfig)

Example 7 with 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;
}
Also used : Server(org.openstack4j.model.compute.Server) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 8 with CloudVmMetaDataStatus

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));
    }
}
Also used : CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)

Example 9 with CloudVmMetaDataStatus

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;
}
Also used : CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with CloudVmMetaDataStatus

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);
}
Also used : CloudVmInstanceStatuses(com.sequenceiq.it.spark.spi.CloudVmInstanceStatuses) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) TypeToken(com.google.common.reflect.TypeToken) CloudMetaDataStatuses(com.sequenceiq.it.spark.spi.CloudMetaDataStatuses) Service(spark.Service) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Gson(com.google.gson.Gson)

Aggregations

CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)43 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)20 ArrayList (java.util.ArrayList)18 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)13 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)12 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)10 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)9 Service (spark.Service)8 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Map (java.util.Map)7 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)6 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)6 Instance (com.amazonaws.services.ec2.model.Instance)6 Reservation (com.amazonaws.services.ec2.model.Reservation)6 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 AmbariClusterResponse (com.sequenceiq.it.spark.ambari.AmbariClusterResponse)6 EmptyAmbariResponse (com.sequenceiq.it.spark.ambari.EmptyAmbariResponse)6 CreateTagsRequest (com.amazonaws.services.ec2.model.CreateTagsRequest)5 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)5