Search in sources :

Example 96 with FlowIdentifier

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

the class SdxUpgradeRecoveryServiceTest method testValidateWithDataAndSuccessfulBackupShouldStartRecoveryFlow.

@Test
public void testValidateWithDataAndSuccessfulBackupShouldStartRecoveryFlow() {
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    String reason = "There is no successful backup taken yet for data lake cluster with runtime 7.2.2.";
    RecoveryValidationV4Response recoveryV4Response = new RecoveryValidationV4Response(reason, RecoveryStatus.RECOVERABLE);
    request.setType(SdxRecoveryType.RECOVER_WITH_DATA);
    datalakeDRProto.DatalakeBackupInfo datalakeBackupInfo = datalakeDRProto.DatalakeBackupInfo.newBuilder().setRuntimeVersion(RUNTIME).setOverallState("SUCCESSFUL").build();
    when(cluster.getRuntime()).thenReturn(RUNTIME);
    when(stackV4Endpoint.getClusterRecoverableByNameInternal(WORKSPACE_ID, CLUSTER_NAME, USER_CRN)).thenReturn(recoveryV4Response);
    when(datalakeDrClient.getLastSuccessfulBackup(CLUSTER_NAME, USER_CRN, Optional.of(RUNTIME))).thenReturn(datalakeBackupInfo);
    when(sdxReactorFlowManager.triggerDatalakeRuntimeRecoveryFlow(cluster, SdxRecoveryType.RECOVER_WITH_DATA)).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    SdxRecoverableResponse sdxRecoverableResponse = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateRecovery(cluster, request));
    assertEquals(reason, sdxRecoverableResponse.getReason());
    SdxRecoveryResponse response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerRecovery(cluster, request));
    assertEquals(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"), response.getFlowIdentifier());
}
Also used : RecoveryValidationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryValidationV4Response) SdxRecoverableResponse(com.sequenceiq.sdx.api.model.SdxRecoverableResponse) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) com.cloudera.thunderhead.service.datalakedr.datalakeDRProto(com.cloudera.thunderhead.service.datalakedr.datalakeDRProto) SdxRecoveryResponse(com.sequenceiq.sdx.api.model.SdxRecoveryResponse) Test(org.junit.jupiter.api.Test)

Example 97 with FlowIdentifier

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

the class CertRotationServiceTest method testFlowTrigger.

@Test
public void testFlowTrigger() {
    SdxCluster cluster = new SdxCluster();
    cluster.setId(1L);
    cluster.setClusterName("testclustername");
    CertificatesRotationV4Request request = new CertificatesRotationV4Request();
    ArgumentCaptor<SdxStartCertRotationEvent> eventArgumentCaptor = ArgumentCaptor.forClass(SdxStartCertRotationEvent.class);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, "pollid");
    when(flowManager.triggerCertRotation(eventArgumentCaptor.capture(), anyString())).thenReturn(flowIdentifier);
    FlowIdentifier result = ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.rotateAutoTlsCertificates(cluster, request));
    assertEquals(flowIdentifier, result);
    SdxStartCertRotationEvent event = eventArgumentCaptor.getValue();
    assertEquals(request, event.getRequest());
    assertEquals(1L, event.getResourceId());
    assertEquals(TEST_USER_CRN, event.getUserId());
}
Also used : SdxStartCertRotationEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 98 with FlowIdentifier

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

the class CloudbreakFlowServiceTest method testSaveFlowIdWhenFlowTypeIsFlow.

@Test
public void testSaveFlowIdWhenFlowTypeIsFlow() {
    SdxCluster cluster = new SdxCluster();
    cluster.setLastCbFlowChainId(FLOW_CHAIN_ID);
    cluster.setInitiatorUserCrn(USER_CRN);
    cluster.setClusterName(CLUSTER_NAME);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, FLOW_ID);
    underTest.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
    verify(sdxClusterRepository).save(clusterCaptor.capture());
    assertEquals(FLOW_ID, 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 99 with FlowIdentifier

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

the class CloudbreakFlowServiceTest method testSaveFlowChainIdWhenFlowTypeIsFlowChain.

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

Example 100 with FlowIdentifier

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

the class LoadBalancerPollerServiceTest method testPollingSingleFailure.

@Test
public void testPollingSingleFailure() {
    List<FlowIdentifier> flowIdentifiers = setupFlowIdentifiers(3);
    Iterator<FlowIdentifier> iterator = flowIdentifiers.iterator();
    FlowIdentifier failFlowId = iterator.next();
    String successFlowId1 = iterator.next().getPollableId();
    String successFlowId2 = iterator.next().getPollableId();
    String expectedError = "Data Lake or Data Hub update flows failed: " + List.of(failFlowId);
    setupDatalakeResponse();
    setupDatahubResponse();
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(stackService.updateLoadBalancer(eq(Set.of(DL_NAME, DH_NAME1, DH_NAME2)))).thenReturn(flowIdentifiers);
    when(flowEndpoint.hasFlowRunningByFlowId(anyString())).thenReturn(setupFinishedFlowCheckResponse());
    when(flowEndpoint.getFlowLogsByFlowId(failFlowId.getPollableId())).thenReturn(List.of(setupFailFlowLogResponse()));
    when(flowEndpoint.getFlowLogsByFlowId(successFlowId1)).thenReturn(List.of(setupSuccessFlowLogResponse()));
    when(flowEndpoint.getFlowLogsByFlowId(successFlowId2)).thenReturn(List.of(setupSuccessFlowLogResponse()));
    UpdateFailedException exception = assertThrows(UpdateFailedException.class, () -> underTest.updateStackWithLoadBalancer(ENV_ID, ENV_CRN, ENV_NAME, PublicEndpointAccessGateway.ENABLED));
    verify(flowEndpoint, times(3)).hasFlowRunningByFlowId(anyString());
    verify(flowEndpoint, times(3)).getFlowLogsByFlowId(anyString());
    assertEquals(expectedError, exception.getMessage());
}
Also used : FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UpdateFailedException(com.sequenceiq.environment.exception.UpdateFailedException) Test(org.junit.jupiter.api.Test)

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