Search in sources :

Example 56 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxCreateRazNotRequestedAndMultiAzRequested.

@ParameterizedTest(name = "{0}")
@MethodSource("razCloudPlatformDataProvider")
void testSdxCreateRazNotRequestedAndMultiAzRequested(String testCaseName, CloudPlatform cloudPlatform, boolean multiAz) throws IOException, TransactionExecutionException {
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.1.0/aws/light_duty.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    when(sdxReactorFlowManager.triggerSdxCreation(any())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest("7.1.0", LIGHT_DUTY);
    withCloudStorage(sdxClusterRequest);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    when(clock.getCurrentTimeMillis()).thenReturn(1L);
    mockEnvironmentCall(sdxClusterRequest, cloudPlatform, null);
    sdxClusterRequest.setEnableRangerRaz(false);
    sdxClusterRequest.setEnableMultiAz(multiAz);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    SdxCluster createdSdxCluster = result.getLeft();
    assertEquals(id, createdSdxCluster.getId());
    ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
    verify(sdxClusterRepository, times(1)).save(captor.capture());
    SdxCluster capturedSdx = captor.getValue();
    assertFalse(capturedSdx.isRangerRazEnabled());
    assertEquals(multiAz, capturedSdx.isEnableMultiAz());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 57 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxServiceTest method testCreateNOTInternalSdxClusterFromLightDutyTemplateShouldTriggerSdxCreationFlow.

@Test
void testCreateNOTInternalSdxClusterFromLightDutyTemplateShouldTriggerSdxCreationFlow() throws IOException, TransactionExecutionException {
    CrnTestUtil.mockCrnGenerator(regionAwareCrnGenerator);
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.1.0/aws/light_duty.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, LIGHT_DUTY);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    withCloudStorage(sdxClusterRequest);
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    when(clock.getCurrentTimeMillis()).thenReturn(1L);
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AZURE, null);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    SdxCluster createdSdxCluster = result.getLeft();
    assertEquals(id, createdSdxCluster.getId());
    ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
    verify(sdxClusterRepository, times(1)).save(captor.capture());
    SdxCluster capturedSdx = captor.getValue();
    assertEquals("tagecske", capturedSdx.getTags().getValue("mytag"));
    assertEquals(CLUSTER_NAME, capturedSdx.getClusterName());
    assertEquals(LIGHT_DUTY, capturedSdx.getClusterShape());
    assertEquals("envir", capturedSdx.getEnvName());
    assertEquals("hortonworks", capturedSdx.getAccountId());
    assertEquals(USER_CRN, capturedSdx.getInitiatorUserCrn());
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.REQUESTED, "Datalake requested", createdSdxCluster);
    assertEquals(1L, capturedSdx.getCreated());
    assertFalse(capturedSdx.isCreateDatabase());
    assertTrue(createdSdxCluster.getCrn().matches("crn:cdp:datalake:us-west-1:hortonworks:datalake:.*"));
    StackV4Request stackV4Request = JsonUtil.readValue(capturedSdx.getStackRequest(), StackV4Request.class);
    assertEquals(2L, stackV4Request.getInstanceGroups().size());
    InstanceGroupV4Request core = getGroup(stackV4Request, CORE);
    assertEquals(1L, core.getSecurityGroup().getSecurityRules().size());
    assertEquals("0.0.0.0/0", core.getSecurityGroup().getSecurityRules().get(0).getSubnet());
    assertEquals("22", core.getSecurityGroup().getSecurityRules().get(0).getPorts().get(0));
    InstanceGroupV4Request gateway = getGroup(stackV4Request, GATEWAY);
    assertEquals(2L, gateway.getSecurityGroup().getSecurityRules().size());
    assertEquals("0.0.0.0/0", gateway.getSecurityGroup().getSecurityRules().get(0).getSubnet());
    assertEquals("443", gateway.getSecurityGroup().getSecurityRules().get(0).getPorts().get(0));
    assertEquals("0.0.0.0/0", gateway.getSecurityGroup().getSecurityRules().get(1).getSubnet());
    assertEquals("22", gateway.getSecurityGroup().getSecurityRules().get(1).getPorts().get(0));
    verify(sdxReactorFlowManager).triggerSdxCreation(createdSdxCluster);
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 58 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class CertRotationServiceTest method testStartCertRotation.

@Test
public void testStartCertRotation() {
    CertificatesRotationV4Request request = new CertificatesRotationV4Request();
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setClusterName("testclustername");
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(sdxService.getById(1L)).thenReturn(sdxCluster);
    CertificatesRotationV4Response response = new CertificatesRotationV4Response();
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, "pollid");
    response.setFlowIdentifier(flowIdentifier);
    when(stackV4Endpoint.rotateAutoTlsCertificates(0L, sdxCluster.getClusterName(), TEST_USER_CRN, request)).thenReturn(response);
    ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.startCertRotation(1L, request));
    verify(cloudbreakFlowService).saveLastCloudbreakFlowChainId(sdxCluster, flowIdentifier);
    verify(sdxStatusService).setStatusForDatalakeAndNotify(DatalakeStatusEnum.CERT_ROTATION_IN_PROGRESS, "Datalake cert rotation in progress", sdxCluster);
}
Also used : CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) CertificatesRotationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CertificatesRotationV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 59 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class CloudbreakFlowServiceTest method testResetCbFlowInfoWhenNotTriggeredFlow.

@Test
public void testResetCbFlowInfoWhenNotTriggeredFlow() {
    SdxCluster cluster = new SdxCluster();
    cluster.setLastCbFlowChainId(FLOW_CHAIN_ID);
    cluster.setInitiatorUserCrn(USER_CRN);
    cluster.setClusterName(CLUSTER_NAME);
    FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
    underTest.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
    verify(sdxClusterRepository).save(clusterCaptor.capture());
    assertNull(clusterCaptor.getValue().getLastCbFlowId());
    assertNull(clusterCaptor.getValue().getLastCbFlowChainId());
}
Also used : SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 60 with FlowIdentifier

use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.

the class SdxDiagnosticsCollectionHandlerTest method initEvent.

private Event<SdxDiagnosticsWaitRequest> initEvent() {
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, "pollableId");
    SdxDiagnosticsWaitRequest request = new SdxDiagnosticsWaitRequest(1L, "userId", Map.of(), flowIdentifier);
    return new Event<>(new Event.Headers(), request);
}
Also used : SdxDiagnosticsSuccessEvent(com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsSuccessEvent) SdxDiagnosticsFailedEvent(com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsFailedEvent) Event(reactor.bus.Event) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxDiagnosticsWaitRequest(com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsWaitRequest)

Aggregations

FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)150 Test (org.junit.jupiter.api.Test)55 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)15 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)14 SdxClusterDetailResponse (com.sequenceiq.sdx.api.model.SdxClusterDetailResponse)14 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)10 Supplier (java.util.function.Supplier)10 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)9 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)7 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)7 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)7 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)7 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)7