Search in sources :

Example 1 with UserDataUpdateFailed

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

the class UpdateUserDataOnProviderHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<UserDataUpdateOnProviderRequest> event) {
    UserDataUpdateOnProviderRequest request = event.getData();
    try {
        LOGGER.info("Updating userData on cloud provider side...");
        CloudConnector<?> connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
        CloudStack stack = request.getCloudStack();
        connector.resources().updateUserData(auth, stack, request.getCloudResources(), request.getUserData());
        return new UserDataUpdateOnProviderResult(request.getResourceId());
    } catch (Exception e) {
        LOGGER.error("Updating user data on provider side has failed", e);
        return new UserDataUpdateFailed(UPDATE_USERDATA_FAILED_EVENT.event(), request.getResourceId(), e);
    }
}
Also used : UserDataUpdateOnProviderRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest) UserDataUpdateFailed(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) UserDataUpdateOnProviderResult(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderResult)

Example 2 with UserDataUpdateFailed

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

the class UserDataUpdateActions method updateUserData.

@Bean(name = "UPDATE_USERDATA_STATE")
public AbstractUserDataUpdateAction<?> updateUserData() {
    return new AbstractUserDataUpdateAction<>(UserDataUpdateRequest.class) {

        @Override
        protected void doExecute(StackContext context, UserDataUpdateRequest payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Recreate userdata for new freeipa instances");
            setOperationId(variables, payload.getOperationId());
            setChainedAction(variables, payload.isChained());
            setFinalChain(variables, payload.isFinal());
            sendEvent(context, new UserDataUpdateRequest(context.getStack().getId(), payload.getOldTunnel()));
        }

        @Override
        protected Object getFailurePayload(UserDataUpdateRequest payload, Optional<StackContext> flowContext, Exception ex) {
            return new UserDataUpdateFailed(payload.getResourceId(), ex);
        }
    };
}
Also used : Optional(java.util.Optional) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) UserDataUpdateRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest) UserDataUpdateFailed(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 with UserDataUpdateFailed

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

use of com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed 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)4 UserDataUpdateRequest (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest)3 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)2 UserDataUpdateOnProviderRequest (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest)2 UserDataUpdateOnProviderResult (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderResult)2 UserDataUpdateSuccess (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Bean (org.springframework.context.annotation.Bean)2 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)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 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 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)1