Search in sources :

Example 1 with TelemetryOrchestrator

use of com.sequenceiq.cloudbreak.orchestrator.host.TelemetryOrchestrator 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 2 with TelemetryOrchestrator

use of com.sequenceiq.cloudbreak.orchestrator.host.TelemetryOrchestrator 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)

Aggregations

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 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 FeatureSetting (com.sequenceiq.common.api.type.FeatureSetting)2 AwsDiagnosticParameters (com.sequenceiq.common.model.diagnostics.AwsDiagnosticParameters)2