Search in sources :

Example 1 with GetPlatformTemplateResult

use of com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method getTemplate.

public String getTemplate(Stack stack) {
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    GetPlatformTemplateRequest getPlatformTemplateRequest = new GetPlatformTemplateRequest(cloudContext, cloudCredential);
    eventBus.notify(getPlatformTemplateRequest.selector(), eventFactory.createEvent(getPlatformTemplateRequest));
    try {
        GetPlatformTemplateResult res = getPlatformTemplateRequest.await();
        LOGGER.info("Get template result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to get template", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return res.getTemplate();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting template: " + cloudContext, e);
        throw new OperationException(e);
    }
}
Also used : GetPlatformTemplateResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest)

Example 2 with GetPlatformTemplateResult

use of com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult in project cloudbreak by hortonworks.

the class TemplateHandler method accept.

@Override
public void accept(Event<GetPlatformTemplateRequest> platformTemplateRequestEvent) {
    LOGGER.info("Received event: {}", platformTemplateRequestEvent);
    GetPlatformTemplateRequest request = platformTemplateRequestEvent.getData();
    String template = null;
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        if (connector != null) {
            template = connector.resources().getStackTemplate();
        }
    } catch (TemplatingDoesNotSupportedException ignored) {
    }
    GetPlatformTemplateResult getPlatformTemplateResult = new GetPlatformTemplateResult(request, template);
    request.getResult().onNext(getPlatformTemplateResult);
    LOGGER.info("Get template finished.");
}
Also used : GetPlatformTemplateResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) TemplatingDoesNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.TemplatingDoesNotSupportedException) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest)

Aggregations

GetPlatformTemplateRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest)2 GetPlatformTemplateResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 TemplatingDoesNotSupportedException (com.sequenceiq.cloudbreak.cloud.exception.TemplatingDoesNotSupportedException)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)1