Search in sources :

Example 1 with AwsDiagnosticParameters

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

the class DiagnosticCloudStorageConverter method loggingToS3.

public AwsDiagnosticParameters loggingToS3(Logging logging, String region) {
    AwsDiagnosticParameters.AwsDiagnosticParametersBuilder awsBuilder = AwsDiagnosticParameters.builder();
    S3Config s3Config = s3ConfigGenerator.generateStorageConfig(logging.getStorageLocation());
    return awsBuilder.withS3Bucket(s3Config.getBucket()).withS3Location(Paths.get(s3Config.getFolderPrefix(), DIAGNOSTICS_SUFFIX_PATH).toString()).withS3Region(region).build();
}
Also used : AwsDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters) S3Config(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.S3Config)

Example 2 with AwsDiagnosticParameters

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

the class CloudStorageValidationServiceTest method testValidationWithFailingIdbrokerAndRandomHost.

@Test
void testValidationWithFailingIdbrokerAndRandomHost() throws CloudbreakOrchestratorException {
    Stack stack = getStack();
    when(stackService.getByIdWithClusterInTransaction(STACK_ID)).thenReturn(stack);
    when(entitlementService.cloudStorageValidationOnVmEnabled(anyString())).thenReturn(true);
    DetailedEnvironmentResponse environment = getEnvironment();
    when(environmentClientService.getByCrn(ENV_CRN)).thenReturn(environment);
    List<GatewayConfig> gatewayConfigs = getGatewayConfigs();
    when(gatewayConfigService.getAllGatewayConfigs(stack)).thenReturn(gatewayConfigs);
    Set<Node> nodes = getNodes();
    when(stackUtil.collectNodes(stack)).thenReturn(nodes);
    when(diagnosticCloudStorageConverter.loggingResponseToCloudStorageDiagnosticsParameters(environment.getTelemetry().getLogging(), REGION)).thenReturn(new AwsDiagnosticParameters());
    doThrow(new CloudbreakOrchestratorFailedException("failed")).when(telemetryOrchestrator).validateCloudStorage(anyList(), anySet(), any(), anyMap(), any());
    assertThrows(CloudbreakOrchestratorFailedException.class, () -> underTest.validateCloudStorage(STACK_ID), "If provisioning was done using the UI, then verify the log's instance profile and logs location base when provisioning");
    ArgumentCaptor<Set<String>> targetHostnamesCaptor = ArgumentCaptor.forClass(Set.class);
    verify(telemetryOrchestrator, times(2)).validateCloudStorage(anyList(), anySet(), targetHostnamesCaptor.capture(), anyMap(), any());
    verify(eventService, times(1)).fireCloudbreakEvent(anyLong(), anyString(), any());
    List<Set<String>> capturedTargetHostnames = targetHostnamesCaptor.getAllValues();
    List<String> idbrokerTargets = capturedTargetHostnames.stream().flatMap(Collection::stream).filter(s -> s.equals(IDBROKER_HOSTNAME)).collect(Collectors.toList());
    List<String> nonIdbrokerTargets = capturedTargetHostnames.stream().flatMap(Collection::stream).filter(s -> !s.equals(IDBROKER_HOSTNAME)).collect(Collectors.toList());
    assertEquals(1, idbrokerTargets.size());
    assertEquals(1, nonIdbrokerTargets.size());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) Mock(org.mockito.Mock) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) TelemetryOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.TelemetryOrchestrator) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) FeaturesResponse(com.sequenceiq.common.api.telemetry.response.FeaturesResponse) ArgumentCaptor(org.mockito.ArgumentCaptor) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AwsDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) InjectMocks(org.mockito.InjectMocks) LoggingResponse(com.sequenceiq.common.api.telemetry.response.LoggingResponse) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Collection(java.util.Collection) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Set(java.util.Set) S3CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters) Mockito.times(org.mockito.Mockito.times) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) FeatureSetting(com.sequenceiq.common.api.type.FeatureSetting) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) DiagnosticCloudStorageConverter(com.sequenceiq.cloudbreak.telemetry.converter.DiagnosticCloudStorageConverter) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) Set(java.util.Set) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AwsDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Collection(java.util.Collection) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 3 with AwsDiagnosticParameters

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

the class CloudStorageValidationServiceTest method testValidationWithIdbrokerAndRandomHost.

@Test
void testValidationWithIdbrokerAndRandomHost() throws CloudbreakOrchestratorException {
    Stack stack = getStack();
    when(stackService.getByIdWithClusterInTransaction(STACK_ID)).thenReturn(stack);
    when(entitlementService.cloudStorageValidationOnVmEnabled(anyString())).thenReturn(true);
    DetailedEnvironmentResponse environment = getEnvironment();
    when(environmentClientService.getByCrn(ENV_CRN)).thenReturn(environment);
    List<GatewayConfig> gatewayConfigs = getGatewayConfigs();
    when(gatewayConfigService.getAllGatewayConfigs(stack)).thenReturn(gatewayConfigs);
    Set<Node> nodes = getNodes();
    when(stackUtil.collectNodes(stack)).thenReturn(nodes);
    when(diagnosticCloudStorageConverter.loggingResponseToCloudStorageDiagnosticsParameters(environment.getTelemetry().getLogging(), REGION)).thenReturn(new AwsDiagnosticParameters());
    underTest.validateCloudStorage(STACK_ID);
    ArgumentCaptor<Set<String>> targetHostnamesCaptor = ArgumentCaptor.forClass(Set.class);
    verify(telemetryOrchestrator, times(2)).validateCloudStorage(anyList(), anySet(), targetHostnamesCaptor.capture(), anyMap(), any());
    List<Set<String>> capturedTargetHostnames = targetHostnamesCaptor.getAllValues();
    List<String> idbrokerTargets = capturedTargetHostnames.stream().flatMap(Collection::stream).filter(s -> s.equals(IDBROKER_HOSTNAME)).collect(Collectors.toList());
    List<String> nonIdbrokerTargets = capturedTargetHostnames.stream().flatMap(Collection::stream).filter(s -> !s.equals(IDBROKER_HOSTNAME)).collect(Collectors.toList());
    assertEquals(1, idbrokerTargets.size());
    assertEquals(1, nonIdbrokerTargets.size());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) Mock(org.mockito.Mock) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) TelemetryOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.TelemetryOrchestrator) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) FeaturesResponse(com.sequenceiq.common.api.telemetry.response.FeaturesResponse) ArgumentCaptor(org.mockito.ArgumentCaptor) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AwsDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) InjectMocks(org.mockito.InjectMocks) LoggingResponse(com.sequenceiq.common.api.telemetry.response.LoggingResponse) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Collection(java.util.Collection) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Set(java.util.Set) S3CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters) Mockito.times(org.mockito.Mockito.times) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) FeatureSetting(com.sequenceiq.common.api.type.FeatureSetting) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) DiagnosticCloudStorageConverter(com.sequenceiq.cloudbreak.telemetry.converter.DiagnosticCloudStorageConverter) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) Set(java.util.Set) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AwsDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Collection(java.util.Collection) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Example 4 with AwsDiagnosticParameters

use of com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters 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;
        }
    };
}
Also used : AwsDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters) CloudStorageDiagnosticsParameters(com.sequenceiq.common.model.diagnostics.CloudStorageDiagnosticsParameters) 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) AzureDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AzureDiagnosticParameters) GcsDiagnosticsParameters(com.sequenceiq.common.model.diagnostics.GcsDiagnosticsParameters) DiagnosticsCollectionEvent(com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 5 with AwsDiagnosticParameters

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

the class DiagnosticCloudStorageConverter method loggingResponseToS3.

public AwsDiagnosticParameters loggingResponseToS3(LoggingResponse logging, String region) {
    AwsDiagnosticParameters.AwsDiagnosticParametersBuilder awsBuilder = AwsDiagnosticParameters.builder();
    S3Config s3Config = s3ConfigGenerator.generateStorageConfig(logging.getStorageLocation());
    return awsBuilder.withS3Bucket(s3Config.getBucket()).withS3Location(Paths.get(s3Config.getFolderPrefix(), DIAGNOSTICS_SUFFIX_PATH).toString()).withS3Region(region).build();
}
Also used : AwsDiagnosticParameters(com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters) S3Config(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.S3Config)

Aggregations

AwsDiagnosticParameters (com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters)5 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)2 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)2 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)2 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)2 TelemetryOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.TelemetryOrchestrator)2 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 GatewayConfigService (com.sequenceiq.cloudbreak.service.GatewayConfigService)2 EnvironmentClientService (com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService)2 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)2 CloudbreakEventService (com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService)2 DiagnosticCloudStorageConverter (com.sequenceiq.cloudbreak.telemetry.converter.DiagnosticCloudStorageConverter)2 S3Config (com.sequenceiq.cloudbreak.telemetry.fluent.cloud.S3Config)2 StackUtil (com.sequenceiq.cloudbreak.util.StackUtil)2 S3CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters)2 FeaturesResponse (com.sequenceiq.common.api.telemetry.response.FeaturesResponse)2 LoggingResponse (com.sequenceiq.common.api.telemetry.response.LoggingResponse)2 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)2