Search in sources :

Example 1 with GetSSHFingerprintsResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult in project cloudbreak by hortonworks.

the class GetSSHFingerprintsComponentTest method testGetSSHFingerprintsWithBadFingerprint.

@Test
public void testGetSSHFingerprintsWithBadFingerprint() {
    GetSSHFingerprintsResult result = sendCloudRequest(getBadRequest());
    assertEquals(EventStatus.FAILED, result.getStatus());
    assertNull(result.getSshFingerprints());
}
Also used : GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) Test(org.junit.Test)

Example 2 with GetSSHFingerprintsResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult in project cloudbreak by hortonworks.

the class GetSSHFingerprintsComponentTest method testGetSSHFingerprints.

@Test
public void testGetSSHFingerprints() {
    GetSSHFingerprintsResult result = sendCloudRequest();
    assertEquals(EventStatus.OK, result.getStatus());
    assertTrue(result.getSshFingerprints().contains(g().getSshFingerprint()));
}
Also used : GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) Test(org.junit.Test)

Example 3 with GetSSHFingerprintsResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult in project cloudbreak by hortonworks.

the class StackCreationActions method tlsSetupAction.

@Bean(name = "TLS_SETUP_STATE")
public Action<?, ?> tlsSetupAction() {
    return new AbstractStackCreationAction<GetSSHFingerprintsResult>(GetSSHFingerprintsResult.class) {

        @Override
        protected void doExecute(StackContext context, GetSSHFingerprintsResult payload, Map<Object, Object> variables) throws Exception {
            stackCreationService.setupTls(context);
            StackWithFingerprintsEvent fingerprintsEvent = new StackWithFingerprintsEvent(payload.getStackId(), payload.getSshFingerprints());
            sendEvent(context.getFlowId(), StackCreationEvent.TLS_SETUP_FINISHED_EVENT.event(), fingerprintsEvent);
        }
    };
}
Also used : StackWithFingerprintsEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.StackWithFingerprintsEvent) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) Map(java.util.Map) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) Bean(org.springframework.context.annotation.Bean)

Example 4 with GetSSHFingerprintsResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult 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

GetSSHFingerprintsResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult)4 Test (org.junit.Test)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 GetSSHFingerprintsRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest)1 InstanceConsoleOutputResult (com.sequenceiq.cloudbreak.cloud.event.instance.InstanceConsoleOutputResult)1 CloudOperationNotSupportedException (com.sequenceiq.cloudbreak.cloud.exception.CloudOperationNotSupportedException)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)1 StackWithFingerprintsEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.StackWithFingerprintsEvent)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1