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());
}
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));
}
}
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));
}
}
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));
}
}
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));
}
}
Aggregations