Search in sources :

Example 6 with CloudCredentialStatus

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

the class OpenStackCredentialConnector method verify.

@Override
public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext) {
    CloudCredential credential = authenticatedContext.getCloudCredential();
    String smartSenseId = smartSenseIdGenerator.getSmartSenseId();
    if (StringUtils.isNoneEmpty(smartSenseId)) {
        credential.putParameter(SMART_SENSE_ID, smartSenseId);
    }
    return new CloudCredentialStatus(credential, CredentialStatus.VERIFIED);
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Example 7 with CloudCredentialStatus

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

the class TerminateStackHandler method accept.

@Override
public void accept(Event<TerminateStackRequest> terminateStackRequestEvent) {
    LOGGER.info("Received event: {}", terminateStackRequestEvent);
    TerminateStackRequest request = terminateStackRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().terminate(ac, request.getCloudStack(), request.getCloudResources());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        TerminateStackResult result;
        if (!resources.isEmpty()) {
            PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, false);
            ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(request.getCloudContext(), resourceStatus);
            if (!task.completed(statePollerResult)) {
                statePollerResult = syncPollingScheduler.schedule(task);
            }
            if (!statePollerResult.getStatus().equals(ResourceStatus.DELETED)) {
                throw new CloudConnectorException("Stack could not be terminated, Resource(s) could not be deleted on the provider side.");
            } else {
                result = new TerminateStackResult(request);
            }
        } else {
            result = new TerminateStackResult(request);
        }
        CloudCredentialStatus credentialStatus = connector.credentials().delete(ac);
        if (CredentialStatus.FAILED == credentialStatus.getStatus()) {
            if (credentialStatus.getException() != null) {
                throw new CloudConnectorException(credentialStatus.getException());
            }
            throw new CloudConnectorException(credentialStatus.getStatusReason());
        }
        request.getResult().onNext(result);
        LOGGER.info("TerminateStackHandler finished");
        eventBus.notify(result.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), result));
    } catch (Exception e) {
        LOGGER.error("Failed to handle TerminateStackRequest", e);
        TerminateStackResult terminateStackResult = new TerminateStackResult("Stack termination failed.", e, request);
        request.getResult().onNext(terminateStackResult);
        eventBus.notify(terminateStackResult.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), terminateStackResult));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) TerminateStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackResult) TerminateStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Example 8 with CloudCredentialStatus

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

the class TestApplicationContext method cloudConnectors.

@Bean
public CloudConnector cloudConnectors() throws Exception {
    CloudResource resource = new Builder().type(ResourceType.HEAT_STACK).name("ref").build();
    when(cloudConnector.authentication()).thenReturn(authenticator);
    when(cloudConnector.credentials()).thenReturn(credentialConnector);
    when(credentialConnector.create(any(AuthenticatedContext.class))).thenReturn(new CloudCredentialStatus(null, CredentialStatus.CREATED));
    when(credentialConnector.delete(any(AuthenticatedContext.class))).thenReturn(new CloudCredentialStatus(null, CredentialStatus.DELETED));
    when(authenticator.authenticate(any(), any())).thenReturn(g.createAuthenticatedContext());
    when(cloudConnector.platform()).thenReturn(Platform.platform("TESTCONNECTOR"));
    when(cloudConnector.variant()).thenReturn(Variant.variant("TESTVARIANT"));
    when(cloudConnector.resources()).thenReturn(resourceConnector);
    when(cloudConnector.instances()).thenReturn(instanceConnector);
    when(cloudConnector.metadata()).thenReturn(collector);
    when(resourceConnector.launch(any(), any(), any(), any(), anyLong())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.CREATED)));
    when(resourceConnector.terminate(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.DELETED)));
    when(resourceConnector.update(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(resourceConnector.upscale(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(resourceConnector.downscale(any(), any(), any(), anyList(), anyMap())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(instanceConnector.check(any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STARTED)));
    CloudVmInstanceStatus collectInstanceStatus = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS);
    when(collector.collect(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmMetaDataStatus(collectInstanceStatus, new CloudInstanceMetaData("privateIp", "publicIp", "hypervisor"))));
    when(instanceConnector.start(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STARTED)));
    when(instanceConnector.stop(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STOPPED)));
    when(instanceConnector.getConsoleOutput(any(), eq(cloudInstance))).thenReturn(g.getSshFingerprint() + "    RSA/n-----END SSH HOST KEY FINGERPRINTS-----");
    when(instanceConnector.getConsoleOutput(any(), eq(cloudInstanceBad))).thenReturn("XYZ    RSA/n-----END SSH HOST KEY FINGERPRINTS-----");
    return cloudConnector;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Bean(org.springframework.context.annotation.Bean)

Example 9 with CloudCredentialStatus

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

the class GcpCredentialConnectorTest method testForFailedStatusBecauseMissingServiceAccId.

/**
 * Testing the GcpContext checking mechanism. If the inner created
 * GcpContext does not contains a valid service account id then a FAILED
 * status should come back.
 */
@Test
public void testForFailedStatusBecauseMissingServiceAccId() {
    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(null);
    when(context.getCompute()).thenReturn(createDummyCompute());
    final CloudCredentialStatus status = underTest.verify(authContext);
    Assert.assertNotNull("The returned CloudCredentialStatus instance is null!", status);
    Assert.assertEquals("Invalid credential status has specified!", CredentialStatus.FAILED, status.getStatus());
}
Also used : AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Test(org.junit.Test)

Example 10 with CloudCredentialStatus

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

the class GcpCredentialConnectorTest method testDeletePositive.

/**
 * Test that if the delete function has called with a proper
 * AuthenticationContext, then the returning CredentialStatus
 * should be DELETED.
 */
@Test
public void testDeletePositive() {
    final CloudCredentialStatus status = underTest.delete(createAuthContext());
    Assert.assertNotNull("The returned CloudCredentialStatus instance is null!", status);
    Assert.assertEquals("Invalid credential status has specified!", CredentialStatus.DELETED, status.getStatus());
}
Also used : CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Test(org.junit.Test)

Aggregations

CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 Test (org.junit.Test)7 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)3 AmazonClientException (com.amazonaws.AmazonClientException)2 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)2 Event (reactor.bus.Event)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)1 TokenResponseException (com.google.api.client.auth.oauth2.TokenResponseException)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CredentialVerificationException (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationException)1 CredentialVerificationRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest)1 CredentialVerificationResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult)1