Search in sources :

Example 31 with AuthenticatedContext

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

the class GcpCredentialConnectorTest method testPassingVerifyPermissionCheck.

/**
 * Test that if the credential authentication has passed, the returned
 * CredentialStatus is VERIFIED.
 *
 * @throws IOException this exception could thrown by the credential
 *                     checker method.
 */
@Test
public void testPassingVerifyPermissionCheck() throws IOException {
    final AuthenticatedContext authContext = createAuthContext();
    when(contextBuilder.contextInit(authContext.getCloudContext(), authContext, null, null, false)).thenReturn(context);
    when(context.getProjectId()).thenReturn("some id");
    when(context.getServiceAccountId()).thenReturn("some service id");
    final CloudCredentialStatus status = underTest.verify(authContext);
    Assert.assertNotNull("The returned CloudCredentialStatus instance is null!", status);
    Assert.assertEquals("Invalid credential status has specified!", CredentialStatus.VERIFIED, status.getStatus());
}
Also used : AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Test(org.junit.Test)

Example 32 with AuthenticatedContext

use of com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext 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)

Example 33 with AuthenticatedContext

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

the class GetTlsInfoHandler method accept.

@Override
public void accept(Event<GetTlsInfoRequest> getTlsInfoRequestEvent) {
    LOGGER.info("Received event: {}", getTlsInfoRequestEvent);
    GetTlsInfoRequest<?> tlsInfoRequest = getTlsInfoRequestEvent.getData();
    try {
        CloudContext cloudContext = tlsInfoRequest.getCloudContext();
        CloudCredential cloudCredential = tlsInfoRequest.getCloudCredential();
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        CloudStack cloudStack = tlsInfoRequest.getCloudStack();
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
        TlsInfo tlsInfo = connector.resources().getTlsInfo(ac, cloudStack);
        GetTlsInfoResult getTlsInfoResult = new GetTlsInfoResult(tlsInfoRequest, tlsInfo);
        tlsInfoRequest.getResult().onNext(getTlsInfoResult);
        eventBus.notify(getTlsInfoResult.selector(), new Event<>(getTlsInfoRequestEvent.getHeaders(), getTlsInfoResult));
        LOGGER.info("GetTlsInfoHandler finished.");
    } catch (RuntimeException e) {
        String errorMsg = "Failed to get Tls info from cloud connector!";
        LOGGER.error(errorMsg, e);
        GetTlsInfoResult failure = new GetTlsInfoResult(errorMsg, e, tlsInfoRequest);
        tlsInfoRequest.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(getTlsInfoRequestEvent.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Example 34 with AuthenticatedContext

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

the class StopStackHandler method accept.

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

Example 35 with AuthenticatedContext

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

the class UpscaleStackHandler method accept.

@Override
public void accept(Event<UpscaleStackRequest> upscaleStackRequestEvent) {
    LOGGER.info("Received event: {}", upscaleStackRequestEvent);
    UpscaleStackRequest request = upscaleStackRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().upscale(ac, request.getCloudStack(), request.getResourceList());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        UpscaleStackResult result = ResourcesStatePollerResults.transformToUpscaleStackResult(statePollerResult, request);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(upscaleStackRequestEvent.getHeaders(), result));
        LOGGER.info("Upscale successfully finished for {}", cloudContext);
    } catch (Exception e) {
        UpscaleStackResult result = new UpscaleStackResult(e.getMessage(), e, request);
        request.getResult().onNext(result);
        eventBus.notify(CloudPlatformResult.failureSelector(UpscaleStackResult.class), new Event<>(upscaleStackRequestEvent.getHeaders(), result));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) UpscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) UpscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Aggregations

AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)52 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)34 Test (org.junit.Test)26 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)20 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)19 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)18 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)17 Location (com.sequenceiq.cloudbreak.cloud.model.Location)17 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)15 Vpc (com.amazonaws.services.ec2.model.Vpc)15 Group (com.sequenceiq.cloudbreak.cloud.model.Group)15 Network (com.sequenceiq.cloudbreak.cloud.model.Network)15 HashMap (java.util.HashMap)15 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)14 ArrayList (java.util.ArrayList)11 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)10 Event (reactor.bus.Event)10 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)8 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)8