org.springframework.statemachine.action.Action Java Examples

The following examples show how to use org.springframework.statemachine.action.Action. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FreeIpaCleanupActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "REMOVE_ROLES_STATE")
public Action<?, ?> removeRolesAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveUsersResponse.class) {
        @Override
        protected void doExecute(FreeIpaContext context, RemoveUsersResponse payload, Map<Object, Object> variables) {
            if (shouldSkipState(payload, variables) || payload.getRoles() == null || payload.getRoles().isEmpty()) {
                LOGGER.info("Roles is empty, skipping removing roles");
                RemoveRolesResponse response =
                        new RemoveRolesResponse(payload, Collections.emptySet(), Collections.emptyMap());
                sendEvent(context, response);
            } else {
                RemoveRolesRequest request = new RemoveRolesRequest(payload, context.getStack());
                sendEvent(context, request);
            }
        }
    };
}
 
Example #2
Source File: EnvDeleteActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "IDBROKER_MAPPINGS_DELETE_STARTED_STATE")
public Action<?, ?> idbmmsDeleteAction() {
    return new AbstractEnvDeleteAction<>(EnvDeleteEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService
                    .updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.IDBROKER_MAPPINGS_DELETE_IN_PROGRESS,
                            ResourceEvent.ENVIRONMENT_IDBROKER_MAPPINGS_DELETION_STARTED, EnvDeleteState.IDBROKER_MAPPINGS_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder()
                    .withEnvironmentDto(envDto)
                    .withForceDelete(payload.isForceDelete())
                    .withId(payload.getResourceId())
                    .build();
            sendEvent(context, DELETE_IDBROKER_MAPPINGS_EVENT.selector(), environmentDeletionDto);
        }
    };
}
 
Example #3
Source File: FreeIpaDownscaleActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "DOWNSCALE_CLUSTERPROXY_REGISTRATION_STATE")
public Action<?, ?> downscaleClusterProxyRegistrationAction() {
    return new AbstractDownscaleAction<>(StackEvent.class) {
        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) throws Exception {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating cluster proxy registration.");
            List<String> repairInstanceIds = getInstanceIds(variables);
            List<String> instanceIdsToRegister = stack.getNotDeletedInstanceMetaDataList().stream()
                    .map(InstanceMetaData::getInstanceId)
                    .filter(instanceId -> !repairInstanceIds.contains(instanceId))
                    .collect(Collectors.toList());
            ClusterProxyUpdateRegistrationRequest request = new ClusterProxyUpdateRegistrationRequest(stack.getId(), instanceIdsToRegister);
            sendEvent(context, request.selector(), request);
        }
    };
}
 
Example #4
Source File: FreeIpaDownscaleActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "DOWNSCALE_FINISHED_STATE")
public Action<?, ?> downscaleFinsihedAction() {
    return new AbstractDownscaleAction<>(StackEvent.class) {
        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getDownscaleCompleteStatus(variables), "Downscale complete");
            if (!isRepair(variables)) {
                SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
                successDetails.getAdditionalDetails().put("Hosts", getDownscaleHosts(variables));
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            }
            sendEvent(context, DOWNSCALE_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
 
Example #5
Source File: FreeIpaUpscaleActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "UPSCALE_STARTING_STATE")
public Action<?, ?> startingAction() {
    return new AbstractUpscaleAction<>(UpscaleEvent.class) {
        @Override
        protected void doExecute(StackContext context, UpscaleEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            String operationId = payload.getOperationId();
            setOperationId(variables, operationId);
            setInstanceCountByGroup(variables, payload.getInstanceCountByGroup());
            setRepair(variables, payload.isRepair());
            LOGGER.info("Starting upscale {}", payload);
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Starting upscale");
            sendEvent(context, UPSCALE_STARTING_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
 
Example #6
Source File: FreeIpaUpscaleActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "UPSCALE_SAVE_METADATA_STATE")
public Action<?, ?> saveMetadataAction() {
    return new AbstractUpscaleAction<>(CollectMetadataResult.class) {

        @Override
        protected void doExecute(StackContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Saving metadata");
            List<String> instanceIds = payload.getResults().stream()
                    .map(CloudVmMetaDataStatus::getCloudVmInstanceStatus)
                    .map(CloudVmInstanceStatus::getCloudInstance)
                    .map(CloudInstance::getInstanceId)
                    .collect(Collectors.toList());
            setInstanceIds(variables, instanceIds);
            metadataSetupService.saveInstanceMetaData(stack, payload.getResults(),
                    com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.CREATED);
            sendEvent(context, UPSCALE_SAVE_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
 
Example #7
Source File: EnvDeleteActionsTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private void testDeleteActionHappyPath(Supplier<Action<?, ?>> deleteAction,
        String selector,
        EnvironmentStatus environmentStatus,
        ResourceEvent eventStarted) {

    Action<?, ?> action = configureAction(deleteAction);

    EnvironmentDto environmentDto = mock(EnvironmentDto.class);
    when(environmentStatusUpdateService.updateEnvironmentStatusAndNotify(any(), any(), any(), any(), any())).thenReturn(environmentDto);

    action.execute(stateContext);

    verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture());
    verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture());
    verify(environmentStatusUpdateService).updateEnvironmentStatusAndNotify(any(), any(), eq(environmentStatus), eq(eventStarted), any());
}
 
Example #8
Source File: EnvCreationActionsTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private void testFailure(Supplier<Action<?, ?>> creationAction) {
    Action<?, ?> action = configureAction(creationAction);

    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenThrow(new UnsupportedOperationException(MESSAGE));
    when(failureEvent.event()).thenReturn(FAILURE_EVENT);

    action.execute(stateContext);

    verify(environmentService, never()).save(any(Environment.class));
    verify(environmentService, never()).getEnvironmentDto(any(Environment.class));
    verify(environmentResponseConverter, never()).dtoToSimpleResponse(any(EnvironmentDto.class));
    verify(notificationService, never()).send(any(ResourceEvent.class), any(SimpleEnvironmentResponse.class), anyString());
    verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture());
    verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture());

    verifyFailureEvent();
}
 
Example #9
Source File: FreeIpaUpscaleActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "UPSCALE_UPDATE_METADATA_STATE")
public Action<?, ?> updateMetadataAction() {
    return new AbstractUpscaleAction<>(PostInstallFreeIpaSuccess.class) {
        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(StackContext context, PostInstallFreeIpaSuccess payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Upscale update metadata");
            if (!isRepair(variables)) {
                int nodeCount = getInstanceCountByGroup(variables);
                for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
                    instanceGroup.setNodeCount(nodeCount);
                    instanceGroupService.save(instanceGroup);
                }
            }
            sendEvent(context, UPSCALE_UPDATE_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
 
Example #10
Source File: ExternalDatabaseCreationActionsTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
void externalDatabaseCreationFinishedAction() {
    CreateExternalDatabaseResult createExternalDatabaseResultPayload =
            new CreateExternalDatabaseResult(STACK_ID, EXTERNAL_DATABASE_WAIT_SUCCESS_EVENT.event(), STACK_NAME, STACK_CRN);
    when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(createExternalDatabaseResultPayload);
    Action<?, ?> action = configureAction(underTest::externalDatabaseCreationFinishedAction);
    action.execute(stateContext);

    verifyNoMoreInteractions(stackUpdaterService);
    verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture());
    verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture());
    verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_SUCCESSFUL, STACK);
    assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_CREATION_FINISHED_EVENT");
    Object capturedPayload = payloadArgumentCaptor.getValue();
    assertThat(capturedPayload).isInstanceOf(StackEvent.class);
    StackEvent stackEvent = (StackEvent) capturedPayload;
    assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID);
}
 
Example #11
Source File: EnvDeleteActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "PREREQUISITES_DELETE_STARTED_STATE")
public Action<?, ?> prerequisitesDeleteAction() {
    return new AbstractEnvDeleteAction<>(EnvDeleteEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService
                    .updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.PREREQUISITES_DELETE_IN_PROGRESS,
                            ResourceEvent.ENVIRONMENT_PREREQUISITES_DELETION_STARTED, EnvDeleteState.PREREQUISITES_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder()
                    .withEnvironmentDto(envDto)
                    .withForceDelete(payload.isForceDelete())
                    .withId(payload.getResourceId())
                    .build();
            sendEvent(context, DELETE_PREREQUISITES_EVENT.selector(), environmentDeletionDto);
        }
    };
}
 
Example #12
Source File: FreeIpaCleanupActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "REVOKE_CERTS_STATE")
public Action<?, ?> revokeCertsAction() {
    return new AbstractFreeIpaCleanupAction<>(CleanupEvent.class) {
        @Override
        protected void doExecute(FreeIpaContext context, CleanupEvent payload, Map<Object, Object> variables) {
            if (shouldSkipState(payload, variables) || payload.getHosts() == null || payload.getHosts().isEmpty()) {
                LOGGER.info("Host is empty, skipping revoking certificates");
                RevokeCertsResponse response =
                        new RevokeCertsResponse(payload, Collections.emptySet(), Collections.emptyMap());
                sendEvent(context, response);
            } else {
                RevokeCertsRequest request = new RevokeCertsRequest(payload, context.getStack());
                sendEvent(context, request);
            }
        }
    };
}
 
Example #13
Source File: FreeIpaCleanupActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "REMOVE_DNS_ENTRIES_STATE")
public Action<?, ?> removeDnsEntriesAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveHostsResponse.class) {
        @Override
        protected void doExecute(FreeIpaContext context, RemoveHostsResponse payload, Map<Object, Object> variables) {
            if (shouldSkipState(payload, variables)
                    || (payload.getHosts() == null || payload.getHosts().isEmpty()) && (payload.getIps() == null || payload.getIps().isEmpty())) {
                LOGGER.info("Host is empty, skipping removing hosts");
                RemoveDnsResponse response =
                        new RemoveDnsResponse(payload, Collections.emptySet(), Collections.emptyMap());
                sendEvent(context, response);
            } else {
                RemoveDnsRequest request = new RemoveDnsRequest(payload);
                sendEvent(context, request);
            }
        }
    };
}
 
Example #14
Source File: FreeIpaCleanupActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "REMOVE_VAULT_ENTRIES_STATE")
public Action<?, ?> removeVaultEntriesAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveDnsResponse.class) {
        @Override
        protected void doExecute(FreeIpaContext context, RemoveDnsResponse payload, Map<Object, Object> variables) {
            if (shouldSkipState(payload, variables) || payload.getHosts() == null || payload.getHosts().isEmpty()) {
                LOGGER.info("Host is empty, skipping removing vault entries");
                RemoveVaultEntriesResponse response =
                        new RemoveVaultEntriesResponse(payload, Collections.emptySet(), Collections.emptyMap());
                sendEvent(context, response);
            } else {
                RemoveVaultEntriesRequest request = new RemoveVaultEntriesRequest(payload, context.getStack());
                sendEvent(context, request);
            }
        }
    };
}
 
Example #15
Source File: FreeIpaCleanupActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "REMOVE_USERS_STATE")
public Action<?, ?> removeUsersAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveVaultEntriesResponse.class) {
        @Override
        protected void doExecute(FreeIpaContext context, RemoveVaultEntriesResponse payload, Map<Object, Object> variables) {
            if (shouldSkipState(payload, variables) || payload.getUsers() == null || payload.getUsers().isEmpty()) {
                LOGGER.info("User is empty, skipping removing users");
                RemoveUsersResponse response =
                        new RemoveUsersResponse(payload, Collections.emptySet(), Collections.emptyMap());
                sendEvent(context, response);
            } else {
                RemoveUsersRequest request = new RemoveUsersRequest(payload, context.getStack());
                sendEvent(context, request);
            }
        }
    };
}
 
Example #16
Source File: FreeIpaUpscaleActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "UPSCALE_FINISHED_STATE")
public Action<?, ?> upscaleFinsihedAction() {
    return new AbstractUpscaleAction<>(StackEvent.class) {
        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getUpscaleCompleteStatus(variables), "Upscale complete");
            if (!isRepair(variables)) {
                SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
                successDetails.getAdditionalDetails().put("Hosts", getUpscaleHosts(variables));
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            }
            sendEvent(context, UPSCALE_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
 
Example #17
Source File: FreeIpaCleanupActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "CLEANUP_FINISHED_STATE")
public Action<?, ?> cleanupFinishedAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveRolesResponse.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(FreeIpaContext context, RemoveRolesResponse payload, Map<Object, Object> variables) {
            CleanupEvent cleanupEvent = new CleanupEvent(FreeIpaCleanupEvent.CLEANUP_FINISHED_EVENT.event(), payload.getResourceId(), payload.getUsers(),
                    payload.getHosts(), payload.getRoles(), payload.getIps(), payload.getStatesToSkip(), payload.getAccountId(), payload.getOperationId(),
                    payload.getClusterName(), payload.getEnvironmentCrn());
            SuccessDetails successDetails = new SuccessDetails(payload.getEnvironmentCrn());
            successDetails.getAdditionalDetails().put("Hosts", payload.getHosts() == null ? List.of() : new ArrayList<>(payload.getHosts()));
            successDetails.getAdditionalDetails().put("Users", payload.getUsers() == null ? List.of() : new ArrayList<>(payload.getUsers()));
            successDetails.getAdditionalDetails().put("Roles", payload.getRoles() == null ? List.of() : new ArrayList<>(payload.getRoles()));
            successDetails.getAdditionalDetails().put("IPs", payload.getIps() == null ? List.of() : new ArrayList<>(payload.getIps()));
            operationService.completeOperation(payload.getAccountId(), payload.getOperationId(), List.of(successDetails), Collections.emptyList());
            LOGGER.info("Cleanup successfully finished with: " + successDetails);
            sendEvent(context, cleanupEvent);
        }
    };
}
 
Example #18
Source File: EnvCreationActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "ENVIRONMENT_INITIALIZATION_STATE")
public Action<?, ?> environmentInitAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("ENVIRONMENT_INITIALIZATION_STATE");
                environment.setStatus(EnvironmentStatus.ENVIRONMENT_INITIALIZATION_IN_PROGRESS);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto);
                notificationService.send(ResourceEvent.ENVIRONMENT_INITIALIZATION_STARTED, simpleResponse, context.getFlowTriggerUserCrn());
                sendEvent(context, INITIALIZE_ENVIRONMENT_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(
                        payload.getResourceId(),
                        payload.getResourceName(),
                        null,
                        payload.getResourceCrn());
                notificationService.send(ResourceEvent.ENVIRONMENT_INITIALIZATION_FAILED, payload, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to validate environment creation request! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
 
Example #19
Source File: EnvCreationActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "ENVIRONMENT_CREATION_VALIDATION_STATE")
public Action<?, ?> environmentValidationAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("ENVIRONMENT_CREATION_VALIDATION_STATE");
                environment.setStatus(EnvironmentStatus.ENVIRONMENT_VALIDATION_IN_PROGRESS);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto);
                notificationService.send(ResourceEvent.ENVIRONMENT_VALIDATION_STARTED, simpleResponse, context.getFlowTriggerUserCrn());
                sendEvent(context, VALIDATE_ENVIRONMENT_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(
                        payload.getResourceId(),
                        payload.getResourceName(),
                        null,
                        payload.getResourceCrn());
                notificationService.send(ResourceEvent.ENVIRONMENT_VALIDATION_FAILED, payload, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to validate environment creation request! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
 
Example #20
Source File: EnvCreationActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "PREREQUISITES_CREATION_STATE")
public Action<?, ?> resourceGroupCreateAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("PREREQUISITES_CREATION_STATE");
                environment.setStatus(EnvironmentStatus.PREREQUISITES_CREATE_IN_PROGRESS);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto);
                notificationService.send(ResourceEvent.ENVIRONMENT_PREREQUISITES_CREATE_STARTED, simpleResponse, context.getFlowTriggerUserCrn());
                sendEvent(context, CREATE_PREREQUISITES_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(
                        payload.getResourceId(),
                        payload.getResourceName(),
                        null,
                        payload.getResourceCrn());
                notificationService.send(ResourceEvent.ENVIRONMENT_PREREQUISITES_CREATE_FAILED, payload, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create prerequisites in environment! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
 
Example #21
Source File: EnvCreationActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "NETWORK_CREATION_STARTED_STATE")
public Action<?, ?> networkCreationAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("NETWORK_CREATION_STARTED_STATE");
                environment.setStatus(EnvironmentStatus.NETWORK_CREATION_IN_PROGRESS);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto);
                notificationService.send(ResourceEvent.ENVIRONMENT_NETWORK_CREATION_STARTED, simpleResponse, context.getFlowTriggerUserCrn());
                sendEvent(context, CREATE_NETWORK_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(
                        payload.getResourceId(),
                        payload.getResourceName(),
                        null,
                        payload.getResourceCrn());
                notificationService.send(ResourceEvent.ENVIRONMENT_NETWORK_CREATION_FAILED, payload, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create network for environment! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
 
Example #22
Source File: EnvCreationActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "PUBLICKEY_CREATION_STARTED_STATE")
public Action<?, ?> publickeyCreationAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("PUBLICKEY_CREATION_STARTED_STATE");
                environment.setStatus(EnvironmentStatus.PUBLICKEY_CREATE_IN_PROGRESS);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto);
                notificationService.send(ResourceEvent.ENVIRONMENT_PUBLICKEY_CREATION_STARTED, simpleResponse, context.getFlowTriggerUserCrn());
                sendEvent(context, CREATE_PUBLICKEY_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(
                        payload.getResourceId(),
                        payload.getResourceName(),
                        null,
                        payload.getResourceCrn());
                notificationService.send(ResourceEvent.ENVIRONMENT_PUBLICKEY_CREATION_FAILED, payload, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create public key for environment! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
 
Example #23
Source File: EnvCreationActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "FREEIPA_CREATION_STARTED_STATE")
public Action<?, ?> freeipaCreationAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("FREEIPA_CREATION_STARTED_STATE");
                environment.setStatus(EnvironmentStatus.FREEIPA_CREATION_IN_PROGRESS);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto);
                notificationService.send(ResourceEvent.ENVIRONMENT_FREEIPA_CREATION_STARTED, simpleResponse, context.getFlowTriggerUserCrn());
                sendEvent(context, CREATE_FREEIPA_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(
                        payload.getResourceId(),
                        payload.getResourceName(),
                        null,
                        payload.getResourceCrn());
                notificationService.send(ResourceEvent.ENVIRONMENT_FREEIPA_CREATION_FAILED, payload, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create freeipa for environment! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
 
Example #24
Source File: EnvCreationActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "ENV_CREATION_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService
                    .findEnvironmentById(payload.getResourceId())
                    .ifPresentOrElse(environment -> {
                        environment.setStatusReason(null);
                        environment.setStatus(EnvironmentStatus.AVAILABLE);
                        Environment result = environmentService.save(environment);
                        environmentJobService.schedule(result);
                        EnvironmentDto environmentDto = environmentService.getEnvironmentDto(result);
                        SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto);
                        metricService.incrementMetricCounter(MetricType.ENV_CREATION_FINISHED, environmentDto);
                        notificationService.send(ResourceEvent.ENVIRONMENT_CREATION_FINISHED, simpleResponse, context.getFlowTriggerUserCrn());
                    }, () -> LOGGER.error("Cannot finish the creation of env, because the environment does not exist: {}. "
                            + "But the flow will continue, how can this happen?", payload.getResourceId()));
            LOGGER.info("Flow entered into ENV_CREATION_FINISHED_STATE");
            sendEvent(context, FINALIZE_ENV_CREATION_EVENT.event(), payload);
        }
    };
}
 
Example #25
Source File: EnvCreationActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "ENV_CREATION_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationFailureEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvCreationFailureEvent payload, Map<Object, Object> variables) {
            Exception exception = payload.getException();
            LOGGER.warn("Failed to create environment", exception);
            environmentService
                    .findEnvironmentById(payload.getResourceId())
                    .ifPresentOrElse(environment -> {
                        environment.setStatusReason(exception.getMessage());
                        environment.setStatus(EnvironmentStatus.CREATE_FAILED);
                        environmentService.save(environment);
                        EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                        SimpleEnvironmentResponse simpleResponse = environmentResponseConverter.dtoToSimpleResponse(environmentDto);
                        metricService.incrementMetricCounter(MetricType.ENV_CREATION_FAILED, environmentDto, exception);
                        notificationService.send(ResourceEvent.ENVIRONMENT_CREATION_FAILED, simpleResponse, context.getFlowTriggerUserCrn());
                    }, () -> LOGGER.error("Cannot finish the creation of env, because the environment does not exist: {}. "
                            + "But the flow will continue, how can this happen?", payload.getResourceId()));
            LOGGER.info("Flow entered into ENV_CREATION_FAILED_STATE");
            sendEvent(context, HANDLED_FAILED_ENV_CREATION_EVENT.event(), payload);
        }
    };
}
 
Example #26
Source File: EnvClustersDeleteActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "DATAHUB_CLUSTERS_DELETE_STARTED_STATE")
public Action<?, ?> datahubClustersDeleteAction() {
    return new AbstractEnvClustersDeleteAction<>(EnvDeleteEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.DATAHUB_CLUSTERS_DELETE_IN_PROGRESS;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_DATAHUB_CLUSTERS_DELETION_STARTED;
            EnvClustersDeleteState envClustersDeleteState = EnvClustersDeleteState.DATAHUB_CLUSTERS_DELETE_STARTED_STATE;
            String logDeleteState = "Data Hub clusters";

            EnvironmentDeletionDto envDto = commonUpdateEnvironmentAndNotify(context, payload, environmentStatus, resourceEvent,
                    envClustersDeleteState, logDeleteState);
            sendEvent(context, DELETE_DATAHUB_CLUSTERS_EVENT.selector(), envDto);
        }
    };
}
 
Example #27
Source File: EnvClustersDeleteActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "DATALAKE_CLUSTERS_DELETE_STARTED_STATE")
public Action<?, ?> datalakeClustersDeleteAction() {
    return new AbstractEnvClustersDeleteAction<>(EnvDeleteEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.DATALAKE_CLUSTERS_DELETE_IN_PROGRESS;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_DATALAKE_CLUSTERS_DELETION_STARTED;
            EnvClustersDeleteState envClustersDeleteState = EnvClustersDeleteState.DATALAKE_CLUSTERS_DELETE_STARTED_STATE;
            String logDeleteState = "Data Lake clustesr";

            EnvironmentDeletionDto envDto = commonUpdateEnvironmentAndNotify(context, payload, environmentStatus, resourceEvent,
                    envClustersDeleteState, logDeleteState);
            sendEvent(context, DELETE_DATALAKE_CLUSTERS_EVENT.selector(), envDto);
        }
    };
}
 
Example #28
Source File: EnvDeleteActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "FREEIPA_DELETE_STARTED_STATE")
public Action<?, ?> freeipaDeleteAction() {
    return new AbstractEnvDeleteAction<>(EnvDeleteEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService
                    .updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.FREEIPA_DELETE_IN_PROGRESS,
                            ResourceEvent.ENVIRONMENT_FREEIPA_DELETION_STARTED, EnvDeleteState.FREEIPA_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder()
                    .withEnvironmentDto(envDto)
                    .withForceDelete(payload.isForceDelete())
                    .withId(payload.getResourceId())
                    .build();
            sendEvent(context, DELETE_FREEIPA_EVENT.selector(), environmentDeletionDto);
        }
    };
}
 
Example #29
Source File: EnvDeleteActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "RDBMS_DELETE_STARTED_STATE")
public Action<?, ?> rdbmsDeleteAction() {
    return new AbstractEnvDeleteAction<>(EnvDeleteEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService
                    .updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.RDBMS_DELETE_IN_PROGRESS,
                            ResourceEvent.ENVIRONMENT_DATABASE_DELETION_STARTED, EnvDeleteState.RDBMS_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder()
                    .withEnvironmentDto(envDto)
                    .withForceDelete(payload.isForceDelete())
                    .withId(payload.getResourceId())
                    .build();
            sendEvent(context, DELETE_RDBMS_EVENT.selector(), environmentDeletionDto);
        }
    };
}
 
Example #30
Source File: EnvDeleteActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Bean(name = "NETWORK_DELETE_STARTED_STATE")
public Action<?, ?> networkDeleteAction() {
    return new AbstractEnvDeleteAction<>(EnvDeleteEvent.class) {
        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService
                    .updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.NETWORK_DELETE_IN_PROGRESS,
                            ResourceEvent.ENVIRONMENT_NETWORK_DELETION_STARTED, EnvDeleteState.NETWORK_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder()
                    .withEnvironmentDto(envDto)
                    .withForceDelete(payload.isForceDelete())
                    .withId(payload.getResourceId())
                    .build();
            sendEvent(context, DELETE_NETWORK_EVENT.selector(), environmentDeletionDto);
        }
    };
}