use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.
the class GetVirtualMachineRecommendationsHandler method accept.
@Override
public void accept(Event<GetVirtualMachineRecommendtaionRequest> gVMRRE) {
LOGGER.info("Received GetVirtualMachineRecommendtaionRequest event: {}", gVMRRE);
GetVirtualMachineRecommendtaionRequest request = gVMRRE.getData();
String cloudPlatform = request.getCloudPlatform();
try {
CloudConnector connector = cloudPlatformConnectors.getDefault(Platform.platform(cloudPlatform));
VmRecommendations recommendations = connector.parameters().recommendedVms();
GetVirtualMachineRecommendationResponse gVMRResponse = new GetVirtualMachineRecommendationResponse(request, recommendations);
request.getResult().onNext(gVMRResponse);
LOGGER.info("Query platform machine recommendations finished.");
} catch (RuntimeException e) {
LOGGER.warn("Could not get virtual machine recommendations for platform: " + cloudPlatform, e);
request.getResult().onNext(new GetVirtualMachineRecommendationResponse(e.getMessage(), e, request));
}
}
use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.
the class InteractiveLoginHandler method accept.
@Override
public void accept(Event<InteractiveLoginRequest> interactiveLoginRequestEvent) {
LOGGER.info("Received event: {}", interactiveLoginRequestEvent);
InteractiveLoginRequest request = interactiveLoginRequestEvent.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector connector = cloudPlatformConnectors.getDefault(cloudContext.getPlatform());
Map<String, String> parameters = connector.credentials().interactiveLogin(cloudContext, request.getExtendedCloudCredential(), credentialNotifier);
InteractiveLoginResult interactiveLoginResult = new InteractiveLoginResult(request, parameters);
request.getResult().onNext(interactiveLoginResult);
LOGGER.info("Interactive login request successfully processed");
} catch (RuntimeException e) {
request.getResult().onNext(new InteractiveLoginResult(e.getMessage(), e, request));
}
}
use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.
the class CloudPlatformConnectorsTest method getOpenstackNative.
@Test
public void getOpenstackNative() {
CloudConnector conn = c.get(platform("MULTIWITHDEFAULT"), variant("TWO"));
assertEquals("TWO", conn.variant().value());
}
use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.
the class CloudPlatformConnectorsTest method getWithNullVariant.
@Test
public void getWithNullVariant() {
CloudConnector conn = c.get(platform("MULTIWITHDEFAULT"), variant(null));
// should fall back to default
assertEquals("ONE", conn.variant().value());
}
use of com.sequenceiq.cloudbreak.cloud.CloudConnector 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));
}
}
Aggregations