Search in sources :

Example 1 with ChangePrimaryGatewaySelectionSuccess

use of com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionSuccess in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayActions method orchestrationAction.

@Bean(name = "CHANGE_PRIMARY_GATEWAY_METADATA_STATE")
public Action<?, ?> orchestrationAction() {
    return new AbstractChangePrimaryGatewayAction<>(ChangePrimaryGatewaySelectionSuccess.class) {

        @Inject
        private ChangePrimaryGatewayService changePrimaryGatewayService;

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, ChangePrimaryGatewaySelectionSuccess payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Changing the primary gateway metadata");
            try {
                changePrimaryGatewayService.changePrimaryGatewayMetadata(stack, payload.getFormerPrimaryGatewayInstanceId(), payload.getNewPrimaryGatewayInstanceId());
                sendEvent(context, CHANGE_PRIMARY_GATEWAY_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
            } catch (Exception e) {
                LOGGER.error("Failed to update the primary gateway metadata", e);
                sendEvent(context, CHANGE_PRIMARY_GATEWAY_METADATA_FAILED_EVENT.selector(), new ChangePrimaryGatewayFailureEvent(stack.getId(), "Updating metadata", Set.of(), Map.of(), e));
            }
        }
    };
}
Also used : ChangePrimaryGatewayService(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayService) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ChangePrimaryGatewayFailureEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayFailureEvent) ChangePrimaryGatewaySelectionSuccess(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionSuccess) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 2 with ChangePrimaryGatewaySelectionSuccess

use of com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionSuccess in project cloudbreak by hortonworks.

the class SelectionHandler method accept.

@Override
public void accept(Event<ChangePrimaryGatewaySelectionRequest> changePrimaryGatewaySelectionRequestEvent) {
    ChangePrimaryGatewaySelectionRequest request = changePrimaryGatewaySelectionRequestEvent.getData();
    Selectable result;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        Optional<String> formerPrimaryGatewayInstanceId = changePrimaryGatewayService.getPrimaryGatewayInstanceId(stack);
        String newPrimaryGatewayInstanceId = changePrimaryGatewayService.selectNewPrimaryGatewayInstanceId(stack, request.getRepairInstanceIds());
        result = new ChangePrimaryGatewaySelectionSuccess(request.getResourceId(), formerPrimaryGatewayInstanceId, newPrimaryGatewayInstanceId);
    } catch (Exception e) {
        LOGGER.error("Failed to select the new primary gateway", e);
        result = new ChangePrimaryGatewayFailureEvent(request.getResourceId(), "Selecting primary gateway", Set.of(), Map.of(), e);
    }
    eventBus.notify(result.selector(), new Event<>(changePrimaryGatewaySelectionRequestEvent.getHeaders(), result));
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ChangePrimaryGatewayFailureEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayFailureEvent) ChangePrimaryGatewaySelectionSuccess(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionSuccess) ChangePrimaryGatewaySelectionRequest(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionRequest) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)2 ChangePrimaryGatewayFailureEvent (com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayFailureEvent)2 ChangePrimaryGatewaySelectionSuccess (com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionSuccess)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 ChangePrimaryGatewayContext (com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext)1 ChangePrimaryGatewayService (com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayService)1 ChangePrimaryGatewaySelectionRequest (com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionRequest)1 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1