Search in sources :

Example 1 with UpdateImageResult

use of com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageResult in project cloudbreak by hortonworks.

the class UpdateImageHandler method accept.

@Override
public void accept(Event<UpdateImageRequest> event) {
    LOGGER.debug("Received event: {}", event);
    UpdateImageRequest<UpdateImageResult> request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector<?> connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        CloudStack stack = request.getCloudStack();
        List<CloudResource> cloudResources = request.getCloudResources();
        cloudResources.stream().filter(resource -> resource.getType().getCommonResourceType() == CommonResourceType.TEMPLATE).forEach(resource -> resource.putParameter(CloudResource.IMAGE, stack.getImage().getImageName()));
        connector.resources().update(auth, stack, cloudResources);
        UpdateImageResult result = new UpdateImageResult(request.getResourceId());
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
        LOGGER.debug("Update image finished for {}", cloudContext);
    } catch (Exception e) {
        UpdateImageResult failure = new UpdateImageResult(e.getMessage(), e, request.getResourceId());
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
    }
}
Also used : UpdateImageResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageResult) Logger(org.slf4j.Logger) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CommonResourceType(com.sequenceiq.common.api.type.CommonResourceType) LoggerFactory(org.slf4j.LoggerFactory) EventBus(reactor.bus.EventBus) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) Inject(javax.inject.Inject) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Component(org.springframework.stereotype.Component) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Event(reactor.bus.Event) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) UpdateImageResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageResult) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Aggregations

CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 UpdateImageRequest (com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest)1 UpdateImageResult (com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageResult)1 CloudPlatformConnectors (com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 CommonResourceType (com.sequenceiq.common.api.type.CommonResourceType)1 List (java.util.List)1 Inject (javax.inject.Inject)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Component (org.springframework.stereotype.Component)1 Event (reactor.bus.Event)1 EventBus (reactor.bus.EventBus)1