Search in sources :

Example 56 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class GcpDiskResourceBuilder method create.

@Override
public List<CloudResource> create(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image) {
    CloudContext cloudContext = auth.getCloudContext();
    String resourceName = getResourceNameService().resourceName(resourceType(), cloudContext.getName(), group.getName(), privateId);
    return Collections.singletonList(createNamedResource(resourceType(), resourceName));
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext)

Example 57 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class GcpInstanceResourceBuilder method create.

@Override
public List<CloudResource> create(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image) {
    CloudContext cloudContext = auth.getCloudContext();
    String resourceName = getResourceNameService().resourceName(resourceType(), cloudContext.getName(), group.getName(), privateId);
    return Collections.singletonList(createNamedResource(resourceType(), resourceName));
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext)

Example 58 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AbstractGcpResourceBuilder method checkResources.

protected List<CloudResourceStatus> checkResources(ResourceType type, GcpContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
    List<CloudResourceStatus> result = new ArrayList<>();
    for (CloudResource resource : resources) {
        LOGGER.info("Check {} resource: {}", type, resource);
        try {
            Operation operation = check(context, resource);
            boolean finished = operation == null || GcpStackUtil.isOperationFinished(operation);
            ResourceStatus successStatus = context.isBuild() ? ResourceStatus.CREATED : ResourceStatus.DELETED;
            result.add(new CloudResourceStatus(resource, finished ? successStatus : ResourceStatus.IN_PROGRESS));
            if (finished) {
                if (successStatus == ResourceStatus.CREATED) {
                    LOGGER.info("Creation of {} was successful", resource);
                } else {
                    LOGGER.info("Deletion of {} was successful", resource);
                }
            }
        } catch (Exception e) {
            CloudContext cloudContext = auth.getCloudContext();
            throw new GcpResourceException("Error during status check", type, cloudContext.getName(), cloudContext.getId(), resource.getName(), e);
        }
    }
    return result;
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Operation(com.google.api.services.compute.model.Operation) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException)

Example 59 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class GcpInstanceConnector method check.

@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> statuses = new ArrayList<>();
    CloudCredential credential = ac.getCloudCredential();
    CloudContext cloudContext = ac.getCloudContext();
    Compute compute = GcpStackUtil.buildCompute(credential);
    for (CloudInstance instance : vms) {
        InstanceStatus status = InstanceStatus.UNKNOWN;
        try {
            Instance executeInstance = getInstance(cloudContext, credential, compute, instance.getInstanceId());
            if ("RUNNING".equals(executeInstance.getStatus())) {
                status = InstanceStatus.STARTED;
            } else if ("TERMINATED".equals(executeInstance.getStatus())) {
                status = InstanceStatus.STOPPED;
            }
        } catch (GoogleJsonResponseException e) {
            if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                status = InstanceStatus.TERMINATED;
            } else {
                LOGGER.warn(String.format("Instance %s is not reachable", instance), e);
            }
        } catch (IOException e) {
            LOGGER.warn(String.format("Instance %s is not reachable", instance), e);
        }
        statuses.add(new CloudVmInstanceStatus(instance, status));
    }
    return statuses;
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Instance(com.google.api.services.compute.model.Instance) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Compute(com.google.api.services.compute.Compute) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) IOException(java.io.IOException)

Example 60 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class GetSSHFingerprintsHandler method accept.

@Override
public void accept(Event<GetSSHFingerprintsRequest> getSSHFingerprintsRequestEvent) {
    LOGGER.info("Received event: {}", getSSHFingerprintsRequestEvent);
    GetSSHFingerprintsRequest fingerprintsRequest = getSSHFingerprintsRequestEvent.getData();
    try {
        CloudContext cloudContext = fingerprintsRequest.getCloudContext();
        CloudInstance cloudInstance = fingerprintsRequest.getCloudInstance();
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, fingerprintsRequest.getCloudCredential());
        GetSSHFingerprintsResult fingerprintsResult;
        try {
            String initialConsoleOutput = connector.instances().getConsoleOutput(ac, cloudInstance);
            InstanceConsoleOutputResult consoleOutputResult = new InstanceConsoleOutputResult(cloudContext, cloudInstance, initialConsoleOutput);
            PollTask<InstanceConsoleOutputResult> outputPollerTask = statusCheckFactory.newPollConsoleOutputTask(connector.instances(), ac, cloudInstance);
            if (!outputPollerTask.completed(consoleOutputResult)) {
                consoleOutputResult = syncPollingScheduler.schedule(outputPollerTask);
            }
            Set<String> sshFingerprints = FingerprintParserUtil.parseFingerprints(consoleOutputResult.getConsoleOutput());
            if (sshFingerprints.isEmpty()) {
                throw new RuntimeException("Failed to get SSH fingerprints from the specified VM instance.");
            } else {
                fingerprintsResult = new GetSSHFingerprintsResult(fingerprintsRequest, sshFingerprints);
            }
        } catch (CloudOperationNotSupportedException ignored) {
            fingerprintsResult = new GetSSHFingerprintsResult(fingerprintsRequest, new HashSet<>());
        }
        fingerprintsRequest.getResult().onNext(fingerprintsResult);
        eventBus.notify(fingerprintsResult.selector(), new Event<>(getSSHFingerprintsRequestEvent.getHeaders(), fingerprintsResult));
        LOGGER.info("GetSSHFingerprintsHandler finished");
    } catch (Exception e) {
        GetSSHFingerprintsResult failure = new GetSSHFingerprintsResult("Failed to get ssh fingerprints!", e, fingerprintsRequest);
        fingerprintsRequest.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(getSSHFingerprintsRequestEvent.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceConsoleOutputResult(com.sequenceiq.cloudbreak.cloud.event.instance.InstanceConsoleOutputResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudOperationNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.CloudOperationNotSupportedException) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) CloudOperationNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.CloudOperationNotSupportedException) Event(reactor.bus.Event)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)100 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)43 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)34 Test (org.junit.Test)34 Group (com.sequenceiq.cloudbreak.cloud.model.Group)33 HashMap (java.util.HashMap)33 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)32 Location (com.sequenceiq.cloudbreak.cloud.model.Location)31 Network (com.sequenceiq.cloudbreak.cloud.model.Network)31 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)31 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)25 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)19 Matchers.containsString (org.hamcrest.Matchers.containsString)18 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)16 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)15 ArrayList (java.util.ArrayList)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14