Search in sources :

Example 21 with CloudInstance

use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.

the class MockInstanceConnector method stop.

@Override
public List<CloudVmInstanceStatus> stop(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
    for (CloudInstance instance : vms) {
        CloudVmInstanceStatus instanceStatus = new CloudVmInstanceStatus(instance, InstanceStatus.STOPPED);
        cloudVmInstanceStatuses.add(instanceStatus);
    }
    return cloudVmInstanceStatuses;
}
Also used : CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 22 with CloudInstance

use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.

the class MockInstanceConnector method check.

@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext authenticatedContext, List<CloudInstance> vms) {
    try {
        MockCredentialView mockCredentialView = mockCredentialViewFactory.createCredetialView(authenticatedContext.getCloudCredential());
        LOGGER.info("collect instance statuses from mock spi, server address: " + mockCredentialView.getMockEndpoint());
        CloudVmInstanceStatus[] cloudVmInstanceStatusArray = Unirest.post(mockCredentialView.getMockEndpoint() + "/spi/cloud_instance_statuses").asObject(CloudVmInstanceStatus[].class).getBody();
        LOGGER.info("collected instance statuses: " + Arrays.toString(cloudVmInstanceStatusArray));
        List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
        for (CloudInstance instance : vms) {
            Optional<CloudVmInstanceStatus> vmInstanceStatusFromApi = Arrays.stream(cloudVmInstanceStatusArray).filter(instanceStatus -> instanceStatus.getCloudInstance().getTemplate().getPrivateId().equals(instance.getTemplate().getPrivateId())).findFirst();
            InstanceStatus instanceStatus = InstanceStatus.TERMINATED;
            if (vmInstanceStatusFromApi.isPresent()) {
                instanceStatus = vmInstanceStatusFromApi.get().getStatus();
            }
            CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(instance, instanceStatus);
            cloudVmInstanceStatuses.add(cloudVmInstanceStatus);
        }
        return cloudVmInstanceStatuses;
    } catch (UnirestException e) {
        throw new RuntimeException("can't convert to object", e);
    }
}
Also used : InstanceConnector(com.sequenceiq.cloudbreak.cloud.InstanceConnector) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) LoggerFactory(org.slf4j.LoggerFactory) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) List(java.util.List) Unirest(com.mashape.unirest.http.Unirest) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) UnirestException(com.mashape.unirest.http.exceptions.UnirestException)

Example 23 with CloudInstance

use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.

the class MockInstanceConnector method start.

@Override
public List<CloudVmInstanceStatus> start(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
    for (CloudInstance instance : vms) {
        CloudVmInstanceStatus instanceStatus = new CloudVmInstanceStatus(instance, InstanceStatus.CREATED);
        cloudVmInstanceStatuses.add(instanceStatus);
    }
    return cloudVmInstanceStatuses;
}
Also used : CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 24 with CloudInstance

use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.

the class StackUpscaleActions method finishExtendMetadata.

@Bean(name = "EXTEND_METADATA_FINISHED_STATE")
public Action<?, ?> finishExtendMetadata() {
    return new AbstractStackUpscaleAction<CollectMetadataResult>(CollectMetadataResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
            Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), context.getInstanceGroupName(), payload);
            variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
            InstanceGroup ig = instanceGroupRepository.findOneByGroupNameInStack(payload.getStackId(), context.getInstanceGroupName());
            if (InstanceGroupType.GATEWAY == ig.getInstanceGroupType()) {
                InstanceMetaData gatewayMetaData = context.getStack().getPrimaryGatewayInstance();
                CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData);
                Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
                sendEvent(context.getFlowId(), sshFingerPrintReq);
            } else {
                BootstrapNewNodesEvent bootstrapPayload = new BootstrapNewNodesEvent(context.getStack().getId(), upscaleCandidateAddresses);
                sendEvent(context.getFlowId(), StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
            }
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) Map(java.util.Map) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Bean(org.springframework.context.annotation.Bean)

Example 25 with CloudInstance

use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance 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

CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)75 ArrayList (java.util.ArrayList)41 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)32 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)25 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)20 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)17 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)16 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)12 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)10 Group (com.sequenceiq.cloudbreak.cloud.model.Group)10 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)10 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)9 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)7 Instance (com.amazonaws.services.ec2.model.Instance)7