Search in sources :

Example 1 with CmDiagnosticsParameters

use of com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters in project cloudbreak by hortonworks.

the class CmDiagnosticsCleanupHandler method accept.

@Override
public void accept(Event<CmDiagnosticsCollectionEvent> event) {
    CmDiagnosticsCollectionEvent data = event.getData();
    Long resourceId = data.getResourceId();
    String resourceCrn = data.getResourceCrn();
    CmDiagnosticsParameters parameters = data.getParameters();
    Map<String, Object> parameterMap = parameters.toMap();
    try {
        LOGGER.debug("CM based diagnostics cleanup started. resourceCrn: '{}', parameters: '{}'", resourceCrn, parameterMap);
        if (DiagnosticsDestination.SUPPORT.equals(parameters.getDestination())) {
            LOGGER.debug("CM based diagnostics uses SUPPORT destination, no support specific cleanup step yet.");
        } else {
            cmDiagnosticsFlowService.cleanup(resourceId, parameterMap, new HashSet<>());
        }
        CmDiagnosticsCollectionEvent diagnosticsCollectionEvent = CmDiagnosticsCollectionEvent.builder().withResourceCrn(resourceCrn).withResourceId(resourceId).withSelector(FINISH_CM_DIAGNOSTICS_COLLECTION_EVENT.selector()).withParameters(parameters).build();
        eventSender().sendEvent(diagnosticsCollectionEvent, event.getHeaders());
    } catch (Exception e) {
        LOGGER.debug("CM based diagnostics cleanup failed. resourceCrn: '{}', parameters: '{}'.", resourceCrn, parameterMap, e);
        CmDiagnosticsCollectionFailureEvent failureEvent = new CmDiagnosticsCollectionFailureEvent(resourceId, e, resourceCrn, parameters);
        eventBus.notify(failureEvent.selector(), new Event<>(event.getHeaders(), failureEvent));
    }
}
Also used : CmDiagnosticsCollectionFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionFailureEvent) CmDiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent) Event(reactor.bus.Event) CmDiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent) CmDiagnosticsParameters(com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters) CmDiagnosticsCollectionFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionFailureEvent)

Example 2 with CmDiagnosticsParameters

use of com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters in project cloudbreak by hortonworks.

the class CmDiagnosticsInitHandler method accept.

@Override
public void accept(Event<CmDiagnosticsCollectionEvent> event) {
    CmDiagnosticsCollectionEvent data = event.getData();
    Long resourceId = data.getResourceId();
    String resourceCrn = data.getResourceCrn();
    CmDiagnosticsParameters parameters = data.getParameters();
    Map<String, Object> parameterMap = parameters.toMap();
    try {
        LOGGER.debug("CM based diagnostics collection initialization started. resourceCrn: '{}', parameters: '{}'", resourceCrn, parameterMap);
        if (DiagnosticsDestination.SUPPORT.equals(parameters.getDestination())) {
            LOGGER.debug("CM based diagnostics uses SUPPORT destination, no support specific init step yet.");
        } else {
            cmDiagnosticsFlowService.init(resourceId, parameterMap, new HashSet<>());
        }
        CmDiagnosticsCollectionEvent diagnosticsCollectionEvent = CmDiagnosticsCollectionEvent.builder().withResourceCrn(resourceCrn).withResourceId(resourceId).withSelector(START_CM_DIAGNOSTICS_COLLECTION_EVENT.selector()).withParameters(parameters).build();
        eventSender().sendEvent(diagnosticsCollectionEvent, event.getHeaders());
    } catch (Exception e) {
        LOGGER.debug("CM based diagnostics collection initialization failed. resourceCrn: '{}', parameters: '{}'.", resourceCrn, parameterMap, e);
        CmDiagnosticsCollectionFailureEvent failureEvent = new CmDiagnosticsCollectionFailureEvent(resourceId, e, resourceCrn, parameters);
        eventBus.notify(failureEvent.selector(), new Event<>(event.getHeaders(), failureEvent));
    }
}
Also used : CmDiagnosticsCollectionFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionFailureEvent) CmDiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent) Event(reactor.bus.Event) CmDiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent) CmDiagnosticsParameters(com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters) CmDiagnosticsCollectionFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionFailureEvent)

Example 3 with CmDiagnosticsParameters

use of com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters 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)

Example 4 with CmDiagnosticsParameters

use of com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters in project cloudbreak by hortonworks.

the class CmDiagnosticsDataToParameterConverter method convert.

public CmDiagnosticsParameters convert(BaseCmDiagnosticsCollectionRequest request, Telemetry telemetry, String clusterName, String region) {
    Logging logging = telemetry.getLogging();
    CmDiagnosticsParameters.CmDiagnosticsParametersBuilder builder = CmDiagnosticsParameters.builder();
    if (logging.getS3() != null) {
        S3Config s3Config = s3ConfigGenerator.generateStorageConfig(logging.getStorageLocation());
        builder.withS3Bucket(s3Config.getBucket());
        builder.withS3Location(Paths.get(s3Config.getFolderPrefix(), DIAGNOSTICS_SUFFIX_PATH).toString());
        builder.withS3Region(region);
    } else if (logging.getAdlsGen2() != null) {
        AdlsGen2Config adlsGen2Config = adlsGen2ConfigGenerator.generateStorageConfig(logging.getStorageLocation());
        builder.withAdlsv2StorageAccount(adlsGen2Config.getAccount());
        builder.withAdlsv2StorageContainer(adlsGen2Config.getFileSystem());
        builder.withAdlsv2StorageLocation(Paths.get(adlsGen2Config.getFolderPrefix(), DIAGNOSTICS_SUFFIX_PATH).toString());
    } else if (logging.getGcs() != null) {
        GcsConfig gcsConfig = gcsConfigGenerator.generateStorageConfig(logging.getStorageLocation());
        builder.withGcsBucket(gcsConfig.getBucket());
        builder.withGcsLocation(Paths.get(gcsConfig.getFolderPrefix(), DIAGNOSTICS_SUFFIX_PATH).toString());
    }
    builder.withComments(request.getComments()).withDestination(request.getDestination()).withClusterName(clusterName).withStartTime(request.getStartTime()).withEndTime(request.getEndTime()).withTicketNumber(request.getTicket()).withRoles(request.getRoles()).withBundleSizeBytes(request.getBundleSizeBytes()).withEnableMonitorMetricsCollection(request.getEnableMonitorMetricsCollection()).withUpdatePackage(request.getUpdatePackage()).withSkipValidation(request.getSkipValidation());
    return builder.build();
}
Also used : Logging(com.sequenceiq.common.api.telemetry.model.Logging) S3Config(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.S3Config) AdlsGen2Config(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.AdlsGen2Config) GcsConfig(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.GcsConfig) CmDiagnosticsParameters(com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters)

Example 5 with CmDiagnosticsParameters

use of com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters in project cloudbreak by hortonworks.

the class CmDiagnosticsCollectionHandler method accept.

@Override
public void accept(Event<CmDiagnosticsCollectionEvent> event) {
    CmDiagnosticsCollectionEvent data = event.getData();
    Long resourceId = data.getResourceId();
    String resourceCrn = data.getResourceCrn();
    CmDiagnosticsParameters parameters = data.getParameters();
    Map<String, Object> parameterMap = parameters.toMap();
    try {
        LOGGER.debug("CM based diagnostics collection started. resourceCrn: '{}', parameters: '{}'", resourceCrn, parameterMap);
        clusterDiagnosticsService.collectDiagnostics(resourceId, parameters);
        CmDiagnosticsCollectionEvent diagnosticsCollectionEvent = CmDiagnosticsCollectionEvent.builder().withResourceCrn(resourceCrn).withResourceId(resourceId).withSelector(START_CM_DIAGNOSTICS_UPLOAD_EVENT.selector()).withParameters(parameters).build();
        eventSender().sendEvent(diagnosticsCollectionEvent, event.getHeaders());
    } catch (Exception e) {
        LOGGER.debug("CM based diagnostics collection failed. resourceCrn: '{}', parameters: '{}'.", resourceCrn, parameterMap, e);
        CmDiagnosticsCollectionFailureEvent failureEvent = new CmDiagnosticsCollectionFailureEvent(resourceId, e, resourceCrn, parameters);
        eventBus.notify(failureEvent.selector(), new Event<>(event.getHeaders(), failureEvent));
    }
}
Also used : CmDiagnosticsCollectionFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionFailureEvent) CmDiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent) Event(reactor.bus.Event) CmDiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent) CmDiagnosticsParameters(com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters) CmDiagnosticsCollectionFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionFailureEvent)

Aggregations

CmDiagnosticsParameters (com.sequenceiq.common.model.diagnostics.CmDiagnosticsParameters)7 CmDiagnosticsCollectionEvent (com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionEvent)6 CmDiagnosticsCollectionFailureEvent (com.sequenceiq.cloudbreak.core.flow2.cmdiagnostics.event.CmDiagnosticsCollectionFailureEvent)4 Event (reactor.bus.Event)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 AdlsGen2Config (com.sequenceiq.cloudbreak.telemetry.fluent.cloud.AdlsGen2Config)1 GcsConfig (com.sequenceiq.cloudbreak.telemetry.fluent.cloud.GcsConfig)1 S3Config (com.sequenceiq.cloudbreak.telemetry.fluent.cloud.S3Config)1 Logging (com.sequenceiq.common.api.telemetry.model.Logging)1 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)1 CommonContext (com.sequenceiq.flow.core.CommonContext)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1 Promise (reactor.rx.Promise)1