Search in sources :

Example 26 with CloudInstance

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

the class StartStackHandler method accept.

@Override
public void accept(Event<StartInstancesRequest> event) {
    LOGGER.info("Received event: {}", event);
    StartInstancesRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext authenticatedContext = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudInstance> instances = request.getCloudInstances();
        List<CloudVmInstanceStatus> instanceStatuses = connector.instances().start(authenticatedContext, request.getResources(), instances);
        PollTask<InstancesStatusResult> task = statusCheckFactory.newPollInstanceStateTask(authenticatedContext, instances, Sets.newHashSet(InstanceStatus.STARTED, InstanceStatus.FAILED));
        InstancesStatusResult statusResult = new InstancesStatusResult(cloudContext, instanceStatuses);
        if (!task.completed(statusResult)) {
            statusResult = syncPollingScheduler.schedule(task);
        }
        StartInstancesResult result = new StartInstancesResult(request, cloudContext, statusResult);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    } catch (Exception e) {
        StartInstancesResult failure = new StartInstancesResult("Failed to start stack", e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) InstancesStatusResult(com.sequenceiq.cloudbreak.cloud.event.instance.InstancesStatusResult) StartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult) Event(reactor.bus.Event)

Example 27 with CloudInstance

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

the class ParameterGenerator method createCloudStack.

public CloudStack createCloudStack() {
    List<Group> groups = new ArrayList<>();
    String name = "master";
    List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
    InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    Security security = new Security(rules, null);
    groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
    Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
    Subnet subnet = new Subnet("10.0.0.0/24");
    Network network = new Network(subnet);
    network.putParameter("publicNetId", "028ffc0c-63c5-4ca0-802a-3ac753eaf76c");
    return new CloudStack(groups, network, image, new HashMap<>(), new HashMap<>(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 28 with CloudInstance

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

the class UnhealthyInstancesFinalizer method finalizeUnhealthyInstances.

public Set<String> finalizeUnhealthyInstances(Stack stack, Iterable<InstanceMetaData> candidateUnhealthyInstances) {
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    List<CloudInstance> cloudInstances = cloudInstanceConverter.convert(candidateUnhealthyInstances);
    List<CloudVmInstanceStatus> cloudVmInstanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses(cloudCredential, cloudContext, cloudInstances);
    Map<String, CloudVmInstanceStatus> cloudVmInstanceStatusesById = new HashMap<>();
    cloudVmInstanceStatuses.forEach(c -> cloudVmInstanceStatusesById.put(c.getCloudInstance().getInstanceId(), c));
    Set<String> unhealthyInstances = new HashSet<>();
    for (InstanceMetaData i : candidateUnhealthyInstances) {
        CloudVmInstanceStatus instanceStatus = cloudVmInstanceStatusesById.get(i.getInstanceId());
        if ((instanceStatus == null) || (instanceStatus.getStatus().equals(InstanceStatus.TERMINATED))) {
            unhealthyInstances.add(i.getInstanceId());
        }
    }
    return unhealthyInstances;
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Location(com.sequenceiq.cloudbreak.cloud.model.Location) HashSet(java.util.HashSet)

Example 29 with CloudInstance

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

the class StackCreationActions method getTlsInfoAction.

@Bean(name = "GET_TLS_INFO_STATE")
public Action<?, ?> getTlsInfoAction() {
    return new AbstractStackCreationAction<GetTlsInfoResult>(GetTlsInfoResult.class) {

        @Override
        protected void doExecute(StackContext context, GetTlsInfoResult payload, Map<Object, Object> variables) {
            Stack stack = stackCreationService.saveTlsInfo(context, payload.getTlsInfo());
            StackContext newContext = new StackContext(context.getFlowId(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            sendEvent(newContext);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            InstanceMetaData gatewayMetaData = context.getStack().getPrimaryGatewayInstance();
            CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData);
            return new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) Bean(org.springframework.context.annotation.Bean)

Example 30 with CloudInstance

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

the class StackDownscaleActions method stackDownscaleAction.

@Bean(name = "DOWNSCALE_STATE")
public Action<?, ?> stackDownscaleAction() {
    return new AbstractStackDownscaleAction<DownscaleStackCollectResourcesResult>(DownscaleStackCollectResourcesResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, DownscaleStackCollectResourcesResult payload, Map<Object, Object> variables) {
            Selectable request = new DownscaleStackRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), (List<CloudResource>) variables.get(RESOURCES), (List<CloudInstance>) variables.get(INSTANCES), payload.getResourcesToScale());
            sendEvent(context.getFlowId(), request);
        }
    };
}
Also used : Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) DownscaleStackCollectResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

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