Search in sources :

Example 1 with UserDataUpdateSuccess

use of com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess 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 2 with UserDataUpdateSuccess

use of com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess in project cloudbreak by hortonworks.

the class UpdateUserDataHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<UserDataUpdateRequest> event) {
    UserDataUpdateRequest request = event.getData();
    try {
        LOGGER.info("Updating userData in the stack's current used image entity...");
        switch(request.getOldTunnel()) {
            case CCM:
                LOGGER.debug("Regenerating user data from request payload.");
                userDataService.regenerateUserData(request.getResourceId());
                break;
            case CCMV2:
                LOGGER.debug("Updating Jumpgate flag only.");
                userDataService.updateJumpgateFlagOnly(request.getResourceId());
                break;
            default:
                throw new IllegalStateException(String.format("Upgrade from %s is not implemented", request.getOldTunnel()));
        }
        return new UserDataUpdateSuccess(request.getResourceId());
    } catch (Exception e) {
        LOGGER.error("Updating user data in the stack's image entity has failed", e);
        return new UserDataUpdateFailed(UPDATE_USERDATA_FAILED_EVENT.event(), request.getResourceId(), e);
    }
}
Also used : UserDataUpdateRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest) UserDataUpdateSuccess(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess) UserDataUpdateFailed(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed)

Aggregations

UserDataUpdateFailed (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed)2 UserDataUpdateRequest (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest)2 UserDataUpdateSuccess (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 ResourceToCloudResourceConverter (com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter)1 Resource (com.sequenceiq.freeipa.entity.Resource)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)1 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)1 UpdateUserDataEvents (com.sequenceiq.freeipa.flow.stack.update.UpdateUserDataEvents)1 UPDATE_USERDATA_FAILED_EVENT (com.sequenceiq.freeipa.flow.stack.update.UpdateUserDataEvents.UPDATE_USERDATA_FAILED_EVENT)1 UserDataUpdateOnProviderRequest (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest)1 UserDataUpdateOnProviderResult (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderResult)1 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)1 ResourceService (com.sequenceiq.freeipa.service.resource.ResourceService)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1