use of com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest in project cloudbreak by hortonworks.
the class StackImageUpdateActions method setImageAction.
@Bean(name = "SET_IMAGE_STATE")
public AbstractStackImageUpdateAction<?> setImageAction() {
return new AbstractStackImageUpdateAction<>(StackEvent.class) {
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
Collection<Resource> resources = getResourceService().getAllByStackId(context.getStack().getId());
List<CloudResource> cloudResources = resources.stream().map(resource -> getResourceToCloudResourceConverter().convert(resource)).collect(Collectors.toList());
UpdateImageRequest<Selectable> request = new UpdateImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, cloudResources);
sendEvent(context, request);
}
};
}
use of com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest in project cloudbreak by hortonworks.
the class ImageChangeActions method setImageOnProvider.
@Bean(name = "SET_IMAGE_ON_PROVIDER_STATE")
public AbstractImageChangeAction<?> setImageOnProvider() {
return new AbstractImageChangeAction<>(StackEvent.class) {
@Inject
private ResourceService resourceService;
@Inject
private ResourceToCloudResourceConverter cloudResourceConverter;
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) throws Exception {
CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
Collection<Resource> resources = resourceService.findAllByStackId(context.getStack().getId());
List<CloudResource> cloudResources = resources.stream().map(resource -> cloudResourceConverter.convert(resource)).collect(Collectors.toList());
UpdateImageRequest<Selectable> request = new UpdateImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, cloudResources);
sendEvent(context, request);
}
@Override
protected Object getFailurePayload(StackEvent payload, Optional<StackContext> flowContext, Exception ex) {
LOGGER.error("[SET_IMAGE_ON_PROVIDER_STATE] failed", ex);
return new StackFailureEvent(IMAGE_CHANGE_FAILED_EVENT.event(), payload.getResourceId(), ex);
}
};
}
use of com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest 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