Search in sources :

Example 56 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class UserDataUpdateActions method updateUserDataOnProviderSide.

@Bean(name = "UPDATE_USERDATA_ON_PROVIDER_STATE")
public AbstractUserDataUpdateAction<?> updateUserDataOnProviderSide() {
    return new AbstractUserDataUpdateAction<>(UserDataUpdateSuccess.class) {

        @Override
        protected void doExecute(StackContext context, UserDataUpdateSuccess payload, Map<Object, Object> variables) {
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            Stack stack = context.getStack();
            String userData = stack.getImage().getUserdata();
            List<CloudResource> cloudResources = getCloudResources(stack.getId());
            return new UserDataUpdateOnProviderRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), cloudResources, userData);
        }

        @Override
        protected Object getFailurePayload(UserDataUpdateSuccess payload, Optional<StackContext> flowContext, Exception ex) {
            return new UserDataUpdateFailed(UPDATE_USERDATA_FAILED_EVENT.event(), payload.getResourceId(), ex);
        }

        private List<CloudResource> getCloudResources(Long stackId) {
            List<Resource> resources = resourceService.findAllByStackId(stackId);
            return resources.stream().map(r -> resourceToCloudResourceConverter.convert(r)).collect(Collectors.toList());
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) UserDataUpdateOnProviderRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) LoggerFactory(org.slf4j.LoggerFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) Inject(javax.inject.Inject) UserDataUpdateFailed(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) UserDataUpdateRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Set(java.util.Set) UpdateUserDataEvents(com.sequenceiq.freeipa.flow.stack.update.UpdateUserDataEvents) Collectors(java.util.stream.Collectors) UPDATE_USERDATA_FAILED_EVENT(com.sequenceiq.freeipa.flow.stack.update.UpdateUserDataEvents.UPDATE_USERDATA_FAILED_EVENT) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Configuration(org.springframework.context.annotation.Configuration) UserDataUpdateOnProviderResult(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderResult) List(java.util.List) UserDataUpdateSuccess(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) Optional(java.util.Optional) UserDataUpdateOnProviderRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) UserDataUpdateSuccess(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess) Stack(com.sequenceiq.freeipa.entity.Stack) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) UserDataUpdateFailed(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 57 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class AbstractImageChangeAction method createFlowContext.

@Override
protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<ImageChangeState, ImageChangeEvents> stateContext, P payload) {
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
    CloudCredential cloudCredential = credentialConverter.convert(credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn()));
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    return new StackContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.freeipa.entity.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)57 Map (java.util.Map)49 Bean (org.springframework.context.annotation.Bean)48 Stack (com.sequenceiq.freeipa.entity.Stack)45 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)30 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)30 FlowParameters (com.sequenceiq.flow.core.FlowParameters)11 List (java.util.List)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)9 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)9 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 Collectors (java.util.stream.Collectors)9 Inject (javax.inject.Inject)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 Flow (com.sequenceiq.flow.core.Flow)8 Configuration (org.springframework.context.annotation.Configuration)8 Action (org.springframework.statemachine.action.Action)8