Search in sources :

Example 1 with UpdateImageRequest

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);
        }
    };
}
Also used : CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Resource(com.sequenceiq.cloudbreak.domain.Resource) STACK_IMAGE_UPDATE_FAILED(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_IMAGE_UPDATE_FAILED) LoggerFactory(org.slf4j.LoggerFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Inject(javax.inject.Inject) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) Map(java.util.Map) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) STACK_IMAGE_UPDATE_FINISHED(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_IMAGE_UPDATE_FINISHED) STACK_IMAGE_UPDATE_STARTED(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_IMAGE_UPDATE_STARTED) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) STACK_IMAGE_UPDATE_FINISHED_EVENT(com.sequenceiq.cloudbreak.core.flow2.stack.image.update.StackImageUpdateEvent.STACK_IMAGE_UPDATE_FINISHED_EVENT) Logger(org.slf4j.Logger) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Collection(java.util.Collection) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) EventStatus(com.sequenceiq.cloudbreak.cloud.event.model.EventStatus) Collectors(java.util.stream.Collectors) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudPlatformResult(com.sequenceiq.cloudbreak.cloud.event.CloudPlatformResult) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) List(java.util.List) OperationException(com.sequenceiq.cloudbreak.service.OperationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Bean(org.springframework.context.annotation.Bean) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with UpdateImageRequest

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);
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) ImageService(com.sequenceiq.freeipa.service.image.ImageService) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) LoggerFactory(org.slf4j.LoggerFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) IMAGE_CHANGE_FAILED_EVENT(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvents.IMAGE_CHANGE_FAILED_EVENT) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) IMAGE_CHANGE_FINISHED_EVENT(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvents.IMAGE_CHANGE_FINISHED_EVENT) PayloadConverter(com.sequenceiq.flow.core.PayloadConverter) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) Logger(org.slf4j.Logger) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Collection(java.util.Collection) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudPlatformResult(com.sequenceiq.cloudbreak.cloud.event.CloudPlatformResult) List(java.util.List) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 with UpdateImageRequest

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

UpdateImageRequest (com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 List (java.util.List)3 Inject (javax.inject.Inject)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 CloudPlatformResult (com.sequenceiq.cloudbreak.cloud.event.CloudPlatformResult)2 PrepareImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Bean (org.springframework.context.annotation.Bean)2 Configuration (org.springframework.context.annotation.Configuration)2 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)1 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1