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