Search in sources :

Example 1 with UserDataUpdateOnProviderRequest

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

use of com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest 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)

Aggregations

UserDataUpdateFailed (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed)2 UserDataUpdateOnProviderRequest (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderRequest)2 UserDataUpdateOnProviderResult (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateOnProviderResult)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 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 UserDataUpdateRequest (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest)1 UserDataUpdateSuccess (com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateSuccess)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