Search in sources :

Example 6 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class DiagnosticsCollectionActions method diagnosticsCollectionFinishedAction.

@Bean(name = "DIAGNOSTICS_COLLECTION_FINISHED_STATE")
public Action<?, ?> diagnosticsCollectionFinishedAction() {
    return new AbstractDiagnosticsCollectionActions<>(DiagnosticsCollectionEvent.class) {

        @Override
        protected void doExecute(CommonContext context, DiagnosticsCollectionEvent payload, Map<Object, Object> variables) {
            Long resourceId = payload.getResourceId();
            String resourceCrn = payload.getResourceCrn();
            LOGGER.debug("Flow entered into DIAGNOSTICS_COLLECTION_FINISHED_STATE. resourceCrn: '{}'", resourceCrn);
            cloudbreakEventService.fireCloudbreakEvent(resourceId, AVAILABLE.name(), ResourceEvent.STACK_DIAGNOSTICS_COLLECTION_FINISHED);
            InMemoryStateStore.deleteStack(resourceId);
            DiagnosticsCollectionEvent event = DiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(payload.getResourceCrn()).withSelector(DiagnosticsCollectionStateSelectors.FINALIZE_DIAGNOSTICS_COLLECTION_EVENT.selector()).withParameters(payload.getParameters()).withHosts(payload.getHosts()).withHostGroups(payload.getHostGroups()).withExcludeHosts(payload.getExcludeHosts()).build();
            diagnosticsOperationsService.vmDiagnosticsReport(resourceCrn, payload.getParameters());
            sendEvent(context, event);
        }
    };
}
Also used : CommonContext(com.sequenceiq.flow.core.CommonContext) DiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 7 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class DiagnosticsCollectionActions method failedAction.

@Bean(name = "DIAGNOSTICS_COLLECTION_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractDiagnosticsCollectionActions<>(DiagnosticsCollectionFailureEvent.class) {

        @Override
        protected void doExecute(CommonContext context, DiagnosticsCollectionFailureEvent payload, Map<Object, Object> variables) {
            Long resourceId = payload.getResourceId();
            String resourceCrn = payload.getResourceCrn();
            LOGGER.debug("Flow entered into DIAGNOSTICS_COLLECTION_FAILED_STATE. resourceCrn: '{}'", resourceCrn);
            cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_FAILED.name(), ResourceEvent.STACK_DIAGNOSTICS_COLLECTION_FAILED, List.of(payload.getException().getMessage()));
            InMemoryStateStore.deleteStack(resourceId);
            DiagnosticParameters parameters = payload.getParameters();
            if (payload.getException() != null) {
                parameters.setStatusReason(payload.getException().getMessage());
            }
            DiagnosticsCollectionEvent event = DiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(payload.getResourceCrn()).withSelector(DiagnosticsCollectionStateSelectors.HANDLED_FAILED_DIAGNOSTICS_COLLECTION_EVENT.selector()).withParameters(payload.getParameters()).withHosts(payload.getHosts()).withHostGroups(payload.getHostGroups()).withExcludeHosts(payload.getExcludeHosts()).build();
            diagnosticsOperationsService.vmDiagnosticsReport(resourceCrn, payload.getParameters(), UsageProto.CDPVMDiagnosticsFailureType.Value.valueOf(payload.getFailureType()), payload.getException());
            sendEvent(context, event);
        }
    };
}
Also used : DiagnosticsCollectionFailureEvent(com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionFailureEvent) CommonContext(com.sequenceiq.flow.core.CommonContext) AwsDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters) DiagnosticParameters(com.sequenceiq.common.model.diagnostics.DiagnosticParameters) AzureDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AzureDiagnosticParameters) Map(java.util.Map) DiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent) Bean(org.springframework.context.annotation.Bean)

Example 8 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class DiagnosticsCollectionActions method diagnosticsInitAction.

@Bean(name = "DIAGNOSTICS_INIT_STATE")
public Action<?, ?> diagnosticsInitAction() {
    return new AbstractDiagnosticsCollectionActions<>(DiagnosticsCollectionEvent.class) {

        @Override
        protected void doExecute(CommonContext context, DiagnosticsCollectionEvent payload, Map<Object, Object> variables) {
            Long resourceId = payload.getResourceId();
            String resourceCrn = payload.getResourceCrn();
            LOGGER.debug("Flow entered into DIAGNOSTICS_INIT_STATE. resourceCrn: '{}'", resourceCrn);
            String hosts = CollectionUtils.isEmpty(payload.getHosts()) ? "[ALL]" : String.format("[%s]", String.join(",", payload.getHosts()));
            String excludedHosts = CollectionUtils.isEmpty(payload.getExcludeHosts()) ? "[NONE]" : String.format("[%s]", String.join(",", payload.getExcludeHosts()));
            String hostGroups = CollectionUtils.isEmpty(payload.getHostGroups()) ? "[ALL]" : String.format("[%s]", String.join(",", payload.getHostGroups()));
            cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_IN_PROGRESS.name(), ResourceEvent.STACK_DIAGNOSTICS_INIT_RUNNING, List.of(hosts, excludedHosts, hostGroups));
            DiagnosticsCollectionEvent event = DiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(resourceCrn).withSelector(DiagnosticsCollectionHandlerSelectors.INIT_DIAGNOSTICS_EVENT.selector()).withParameters(payload.getParameters()).withHosts(payload.getHosts()).withHostGroups(payload.getHostGroups()).withExcludeHosts(payload.getExcludeHosts()).build();
            sendEvent(context, event);
        }
    };
}
Also used : CommonContext(com.sequenceiq.flow.core.CommonContext) DiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 9 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class DiagnosticsCollectionActions method diagnosticsVmPreFlightCheckAction.

@Bean(name = "DIAGNOSTICS_VM_PREFLIGHT_CHECK_STATE")
public Action<?, ?> diagnosticsVmPreFlightCheckAction() {
    return new AbstractDiagnosticsCollectionActions<>(DiagnosticsCollectionEvent.class) {

        @Override
        protected void doExecute(CommonContext context, DiagnosticsCollectionEvent payload, Map<Object, Object> variables) {
            Long resourceId = payload.getResourceId();
            String resourceCrn = payload.getResourceCrn();
            LOGGER.debug("Flow entered into DIAGNOSTICS_VM_PREFLIGHT_CHECK_STATE. resourceCrn: '{}'", resourceCrn);
            cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_IN_PROGRESS.name(), ResourceEvent.STACK_DIAGNOSTICS_VM_PREFLIGHT_CHECK_RUNNING);
            DiagnosticsCollectionEvent event = DiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(payload.getResourceCrn()).withSelector(DiagnosticsCollectionHandlerSelectors.VM_PREFLIGHT_CHECK_DIAGNOSTICS_EVENT.selector()).withParameters(payload.getParameters()).withHosts(payload.getHosts()).withHostGroups(payload.getHostGroups()).withExcludeHosts(payload.getExcludeHosts()).build();
            sendEvent(context, event);
        }
    };
}
Also used : CommonContext(com.sequenceiq.flow.core.CommonContext) DiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 10 with CommonContext

use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.

the class CmDiagnosticsCollectionActions method diagnosticsUploadAction.

@Bean(name = "CM_DIAGNOSTICS_UPLOAD_STATE")
public Action<?, ?> diagnosticsUploadAction() {
    return new CmDiagnosticsCollectionActions.AbstractCmDiagnosticsCollectionActions<>(CmDiagnosticsCollectionEvent.class) {

        @Override
        protected void doExecute(CommonContext context, CmDiagnosticsCollectionEvent payload, Map<Object, Object> variables) {
            Long resourceId = payload.getResourceId();
            String resourceCrn = payload.getResourceCrn();
            LOGGER.debug("Flow entered into CM_DIAGNOSTICS_UPLOAD_STATE. resourceCrn: '{}'", resourceCrn);
            fireUploadEvent(resourceId, payload);
            CmDiagnosticsCollectionEvent event = CmDiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(payload.getResourceCrn()).withSelector(CmDiagnosticsCollectionHandlerSelectors.UPLOAD_CM_DIAGNOSTICS_EVENT.selector()).withParameters(payload.getParameters()).build();
            sendEvent(context, event);
        }

        private void fireUploadEvent(Long resourceId, CmDiagnosticsCollectionEvent payload) {
            CmDiagnosticsParameters parameters = payload.getParameters();
            String message;
            switch(parameters.getDestination()) {
                case CLOUD_STORAGE:
                    String storageLocation = getStorageLocation(parameters);
                    message = "Upload location: " + storageLocation;
                    break;
                case ENG:
                    message = "Engineering will receive the logs.";
                    break;
                case SUPPORT:
                    message = String.format("Diagnostics bundle sent to support. Ticket: '%s' Comments: '%s'", parameters.getTicketNumber(), parameters.getComments());
                    break;
                default:
                    message = "Location for logs on each node: " + LOCAL_LOG_PATH;
                    break;
            }
            cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_IN_PROGRESS.name(), ResourceEvent.STACK_CM_DIAGNOSTICS_UPLOAD_RUNNING, List.of(message));
        }

        private String getStorageLocation(CmDiagnosticsParameters parameters) {
            String storageLocation;
            if (StringUtils.isNotBlank(parameters.getS3Location())) {
                storageLocation = "s3://" + Paths.get(parameters.getS3Bucket(), parameters.getS3Location()).toString();
            } else if (StringUtils.isNotBlank(parameters.getAdlsv2StorageLocation())) {
                storageLocation = "abfs://" + Paths.get(parameters.getAdlsv2StorageContainer(), parameters.getAdlsv2StorageLocation()).toString();
            } else {
                storageLocation = "gs://" + Paths.get(parameters.getGcsBucket(), parameters.getGcsLocation()).toString();
            }
            return storageLocation;
        }
    };
}
Also used : CommonContext(com.sequenceiq.flow.core.CommonContext) CmDiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent) Map(java.util.Map) CmDiagnosticsParameters(com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters) Bean(org.springframework.context.annotation.Bean)

Aggregations

CommonContext (com.sequenceiq.flow.core.CommonContext)84 Map (java.util.Map)83 Bean (org.springframework.context.annotation.Bean)83 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)46 DiagnosticsCollectionEvent (com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent)13 DiagnosticsCollectionEvent (com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionEvent)13 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)12 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)12 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)12 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)11 EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)7 EnvCreationFailureEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)7 CmDiagnosticsCollectionEvent (com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent)6 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)6 ResourceCrnPayload (com.sequenceiq.cloudbreak.common.event.ResourceCrnPayload)5 Environment (com.sequenceiq.environment.environment.domain.Environment)4 EnvironmentStartDto (com.sequenceiq.environment.environment.dto.EnvironmentStartDto)4 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)4 DiagnosticParameters (com.sequenceiq.common.model.diagnostics.DiagnosticParameters)3 EnvStopEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent)3