use of com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext in project cloudbreak by hortonworks.
the class RemoveInstanceHandler method accept.
@Override
public void accept(Event<RemoveInstanceRequest> removeInstanceRequestEvent) {
RemoveInstanceRequest request = removeInstanceRequestEvent.getData();
RemoveInstanceResult result;
try {
CloudContext cloudContext = request.getCloudContext();
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
List<CloudResourceStatus> resourceStatus = connector.resources().downscale(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances(), Collections.emptyMap());
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);
}
LOGGER.info("Instance remove successfully finished for {}", cloudContext);
result = new RemoveInstanceResult(new DownscaleStackResult(request, ResourceLists.transform(statePollerResult.getResults())), request);
} catch (Exception e) {
LOGGER.error("Failed to handle RemoveInstanceRequest.", e);
result = new RemoveInstanceResult(e.getMessage(), e, request);
}
eventBus.notify(result.selector(), new Event<>(removeInstanceRequestEvent.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext in project cloudbreak by hortonworks.
the class InstanceStateQuery method getCloudVmInstanceStatuses.
public List<CloudVmInstanceStatus> getCloudVmInstanceStatuses(CloudCredential cloudCredential, CloudContext cloudContext, List<CloudInstance> instances) {
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, cloudCredential);
return connector.instances().check(auth, instances);
}
use of com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext 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());
}
use of com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext in project cloudbreak by hortonworks.
the class GcpCredentialConnectorTest method testForFailedStatusBecauseMissingCompute.
/**
* Testing the GcpContext checking mechanism. If the inner created
* GcpContext does not contains a valid Compute instance then a FAILED
* status should come back.
*/
@Test
public void testForFailedStatusBecauseMissingCompute() {
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");
when(context.getCompute()).thenReturn(null);
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());
}
use of com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext in project cloudbreak by hortonworks.
the class GcpCredentialConnectorTest method testForNullExceptionOnVerifyPermissionCheck.
/**
* Test that if some exception terminates the credential check operation,
* or the checked credential is not valid. If that so, than the expected
* CredentialStatus should be FAILED.
*
* @throws IOException this exception could thrown by the credential
* checker method.
*/
@Test
public void testForNullExceptionOnVerifyPermissionCheck() throws IOException {
final AuthenticatedContext authContext = createAuthContext();
final String expectionReasonMessage = "exception message";
when(contextBuilder.contextInit(authContext.getCloudContext(), authContext, null, null, false)).thenReturn(context);
when(context.getProjectId()).thenReturn("some id");
when(context.getServiceAccountId()).thenReturn("some service id");
when(context.getCompute().regions().list(anyString()).executeUsingHead()).thenThrow(new BadRequestException(expectionReasonMessage));
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());
Assert.assertTrue("Not the specified exception has come with the status", status.getException() instanceof BadRequestException);
Assert.assertEquals("Not the expected exception message has come with the status", expectionReasonMessage, status.getException().getMessage());
}
Aggregations