use of com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent in project cloudbreak by hortonworks.
the class CmDiagnosticsUploadHandler 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 upload started. resourceCrn: '{}', parameters: '{}'", resourceCrn, parameterMap);
if (DiagnosticsDestination.SUPPORT.equals(parameters.getDestination())) {
LOGGER.debug("CM based diagnostics uses SUPPORT destination, no support specific upload step yet.");
} else {
cmDiagnosticsFlowService.upload(resourceId, parameterMap, new HashSet<>());
}
CmDiagnosticsCollectionEvent diagnosticsCollectionEvent = CmDiagnosticsCollectionEvent.builder().withResourceCrn(resourceCrn).withResourceId(resourceId).withSelector(START_CM_DIAGNOSTICS_CLEANUP_EVENT.selector()).withParameters(parameters).build();
eventSender().sendEvent(diagnosticsCollectionEvent, event.getHeaders());
} catch (Exception e) {
LOGGER.debug("CM based diagnostics upload failed. resourceCrn: '{}', parameters: '{}'.", resourceCrn, parameterMap, e);
CmDiagnosticsCollectionFailureEvent failureEvent = new CmDiagnosticsCollectionFailureEvent(resourceId, e, resourceCrn, parameters);
eventBus.notify(failureEvent.selector(), new Event<>(event.getHeaders(), failureEvent));
}
}
use of com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent in project cloudbreak by hortonworks.
the class DiagnosticsCollectionActions method diagnosticsUploadAction.
@Bean(name = "DIAGNOSTICS_UPLOAD_STATE")
public Action<?, ?> diagnosticsUploadAction() {
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_UPLOAD_STATE. resourceCrn: '{}'", resourceCrn);
fireUploadEvent(resourceId, payload);
DiagnosticsCollectionEvent event = DiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(payload.getResourceCrn()).withSelector(DiagnosticsCollectionHandlerSelectors.UPLOAD_DIAGNOSTICS_EVENT.selector()).withParameters(payload.getParameters()).withHosts(payload.getHosts()).withHostGroups(payload.getHostGroups()).withExcludeHosts(payload.getExcludeHosts()).build();
sendEvent(context, event);
}
private void fireUploadEvent(Long resourceId, DiagnosticsCollectionEvent payload) {
DiagnosticParameters 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:
if (StringUtils.isNotBlank(parameters.getIssue())) {
message = String.format("Diagnostics have been sent to support. " + "Case number: '%s' Description: '%s'", parameters.getIssue(), parameters.getDescription());
} else {
message = String.format("Diagnostics have been sent to support. " + "A ticket will be created for the diagnostics. Description: '%s'", parameters.getDescription());
}
break;
default:
message = "Location for logs on each node: " + LOCAL_LOG_PATH;
break;
}
cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_IN_PROGRESS.name(), ResourceEvent.STACK_DIAGNOSTICS_UPLOAD_RUNNING, List.of(message));
}
private String getStorageLocation(DiagnosticParameters parameters) {
String storageLocation;
CloudStorageDiagnosticsParameters csDiagnosticsParams = parameters.getCloudStorageDiagnosticsParameters();
if (csDiagnosticsParams instanceof AwsDiagnosticParameters) {
AwsDiagnosticParameters awsParameters = (AwsDiagnosticParameters) csDiagnosticsParams;
storageLocation = "s3://" + Paths.get(awsParameters.getS3Bucket(), awsParameters.getS3Location()).toString();
} else if (csDiagnosticsParams instanceof AzureDiagnosticParameters) {
AzureDiagnosticParameters azureParameters = (AzureDiagnosticParameters) csDiagnosticsParams;
storageLocation = "abfs://" + Paths.get(azureParameters.getAdlsv2StorageContainer(), azureParameters.getAdlsv2StorageLocation()).toString();
} else {
GcsDiagnosticsParameters gcsParameters = (GcsDiagnosticsParameters) csDiagnosticsParams;
storageLocation = "gcs://" + Paths.get(gcsParameters.getBucket(), gcsParameters.getGcsLocation()).toString();
}
return storageLocation;
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent in project cloudbreak by hortonworks.
the class DiagnosticsCollectionActions method diagnosticsEnsureMachineUserAction.
@Bean(name = "DIAGNOSTICS_ENSURE_MACHINE_USER_STATE")
public Action<?, ?> diagnosticsEnsureMachineUserAction() {
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_CREATE_MACHINE_USER_STATE. resourceCrn: '{}'", resourceCrn);
cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_IN_PROGRESS.name(), ResourceEvent.STACK_DIAGNOSTICS_ENSURE_MACHINE_USER);
DiagnosticsCollectionEvent event = DiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(payload.getResourceCrn()).withSelector(DiagnosticsCollectionHandlerSelectors.ENSURE_MACHINE_USER_EVENT.selector()).withParameters(payload.getParameters()).withHosts(payload.getHosts()).withHostGroups(payload.getHostGroups()).withExcludeHosts(payload.getExcludeHosts()).build();
sendEvent(context, event);
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent in project cloudbreak by hortonworks.
the class DiagnosticsCollectionActions method diagnosticsSaltPillarUpdateAction.
@Bean(name = "DIAGNOSTICS_SALT_PILLAR_UPDATE_STATE")
public Action<?, ?> diagnosticsSaltPillarUpdateAction() {
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_SALT_PILLAR_UPDATE_STATE. resourceCrn: '{}'", resourceCrn);
cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_IN_PROGRESS.name(), ResourceEvent.STACK_DIAGNOSTICS_SALT_PILLAR_UPDATE_RUNNING);
DiagnosticsCollectionEvent event = DiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(resourceCrn).withSelector(DiagnosticsCollectionHandlerSelectors.SALT_PILLAR_UPDATE_DIAGNOSTICS_EVENT.selector()).withParameters(payload.getParameters()).withHosts(payload.getHosts()).withHostGroups(payload.getHostGroups()).withExcludeHosts(payload.getExcludeHosts()).build();
sendEvent(context, event);
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent in project cloudbreak by hortonworks.
the class DiagnosticsCollectionActions method diagnosticsSaltStateUpdateAction.
@Bean(name = "DIAGNOSTICS_SALT_STATE_UPDATE_STATE")
public Action<?, ?> diagnosticsSaltStateUpdateAction() {
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 SALT_STATE_UPDATE_DIAGNOSTICS_EVENT. resourceCrn: '{}'", resourceCrn);
cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_IN_PROGRESS.name(), ResourceEvent.STACK_DIAGNOSTICS_SALT_STATE_UPDATE_RUNNING);
DiagnosticsCollectionEvent event = DiagnosticsCollectionEvent.builder().withResourceId(resourceId).withResourceCrn(resourceCrn).withSelector(DiagnosticsCollectionHandlerSelectors.SALT_STATE_UPDATE_DIAGNOSTICS_EVENT.selector()).withParameters(payload.getParameters()).withHosts(payload.getHosts()).withHostGroups(payload.getHostGroups()).withExcludeHosts(payload.getExcludeHosts()).build();
sendEvent(context, event);
}
};
}
Aggregations