Search in sources :

Example 6 with StackV4Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint in project cloudbreak by hortonworks.

the class ProvisionerServiceTest method waitCloudbreakClusterDeletionStackRetryFailedTest.

@Test
void waitCloudbreakClusterDeletionStackRetryFailedTest() {
    long clusterId = CLUSTER_ID.incrementAndGet();
    SdxCluster sdxCluster = generateValidSdxCluster(clusterId);
    sdxCluster.setClusterName("sdxcluster1");
    when(sdxService.getById(clusterId)).thenReturn(sdxCluster);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:datahub:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    StackV4Response firstStackV4Response = new StackV4Response();
    firstStackV4Response.setStatus(Status.DELETE_FAILED);
    ClusterV4Response firstClusterResponse = new ClusterV4Response();
    firstClusterResponse.setStatus(Status.DELETE_IN_PROGRESS);
    firstStackV4Response.setCluster(firstClusterResponse);
    StackV4Response secondStackV4Response = new StackV4Response();
    secondStackV4Response.setStatus(Status.DELETE_FAILED);
    ClusterV4Response secondClusterResponse = new ClusterV4Response();
    secondClusterResponse.setStatus(Status.DELETE_COMPLETED);
    secondStackV4Response.setCluster(secondClusterResponse);
    when(stackV4Endpoint.get(anyLong(), eq(sdxCluster.getClusterName()), anySet(), anyString())).thenReturn(firstStackV4Response).thenReturn(secondStackV4Response).thenThrow(new NotFoundException());
    PollingConfig pollingConfig = new PollingConfig(10, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
    underTest.waitCloudbreakClusterDeletion(clusterId, pollingConfig);
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.STACK_DELETED, "Datalake stack deleted", sdxCluster);
    verify(stackV4Endpoint, times(3)).get(anyLong(), eq(sdxCluster.getClusterName()), anySet(), anyString());
}
Also used : ClusterV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 7 with StackV4Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint in project cloudbreak by hortonworks.

the class ProvisionerServiceTest method startStackDeletionStackNotFound.

@Test
void startStackDeletionStackNotFound() {
    long clusterId = CLUSTER_ID.incrementAndGet();
    SdxCluster sdxCluster = generateValidSdxCluster(clusterId);
    when(sdxService.getById(clusterId)).thenReturn(sdxCluster);
    StackV4Response stackV4Response = new StackV4Response();
    stackV4Response.setStatus(Status.CREATE_FAILED);
    doThrow(new NotFoundException()).when(stackV4Endpoint).deleteInternal(anyLong(), eq(sdxCluster.getClusterName()), eq(Boolean.FALSE), nullable(String.class));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:datahub:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    underTest.startStackDeletion(clusterId, false);
    verify(stackV4Endpoint).deleteInternal(eq(0L), eq(null), eq(false), nullable(String.class));
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) NotFoundException(javax.ws.rs.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 8 with StackV4Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint in project cloudbreak by hortonworks.

the class ProvisionerServiceTest method waitCloudbreakClusterDeletionClusterRetryFailedTest.

@Test
void waitCloudbreakClusterDeletionClusterRetryFailedTest() {
    long clusterId = CLUSTER_ID.incrementAndGet();
    SdxCluster sdxCluster = generateValidSdxCluster(clusterId);
    sdxCluster.setClusterName("sdxcluster1");
    when(sdxService.getById(clusterId)).thenReturn(sdxCluster);
    StackV4Response firstStackV4Response = new StackV4Response();
    firstStackV4Response.setStatus(Status.DELETE_IN_PROGRESS);
    ClusterV4Response firstClusterResponse = new ClusterV4Response();
    firstClusterResponse.setStatus(Status.DELETE_IN_PROGRESS);
    firstClusterResponse.setStatusReason("delete failed");
    firstStackV4Response.setCluster(firstClusterResponse);
    StackV4Response secondStackV4Response = new StackV4Response();
    secondStackV4Response.setStatus(Status.DELETE_FAILED);
    ClusterV4Response secondClusterResponse = new ClusterV4Response();
    secondClusterResponse.setStatus(Status.DELETE_IN_PROGRESS);
    secondClusterResponse.setStatusReason("delete failed");
    secondStackV4Response.setCluster(secondClusterResponse);
    StackV4Response thirdStackV4Response = new StackV4Response();
    thirdStackV4Response.setStatus(Status.DELETE_FAILED);
    ClusterV4Response thirdClusterResponse = new ClusterV4Response();
    thirdClusterResponse.setStatus(Status.DELETE_FAILED);
    thirdClusterResponse.setStatusReason("delete failed");
    thirdStackV4Response.setCluster(thirdClusterResponse);
    when(stackV4Endpoint.get(anyLong(), eq(sdxCluster.getClusterName()), anySet(), anyString())).thenReturn(firstStackV4Response).thenReturn(secondStackV4Response).thenReturn(thirdStackV4Response);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:datahub:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    PollingConfig pollingConfig = new PollingConfig(10, TimeUnit.MILLISECONDS, 500, TimeUnit.MILLISECONDS);
    Assertions.assertThrows(UserBreakException.class, () -> underTest.waitCloudbreakClusterDeletion(clusterId, pollingConfig), "Data lake deletion failed 'sdxcluster1', delete failed");
    verify(stackV4Endpoint, times(5)).get(anyLong(), eq(sdxCluster.getClusterName()), anySet(), anyString());
}
Also used : ClusterV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Test(org.junit.jupiter.api.Test)

Example 9 with StackV4Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint in project cloudbreak by hortonworks.

the class SdxRecoveryServiceTest method triggerCloudbreakRecovery.

@Test
public void triggerCloudbreakRecovery() {
    Long clusterId = cluster.getId();
    doNothing().when(cloudbreakFlowService).saveLastCloudbreakFlowChainId(any(), any());
    FlowIdentifier flowId = new FlowIdentifier(FlowType.FLOW, "FLOW_ID_1");
    RecoveryV4Response recoveryV4Response = new RecoveryV4Response(flowId);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(sdxService.getById(clusterId)).thenReturn(cluster);
    when(ThreadBasedUserCrnProvider.doAsInternalActor("crn:cdp:iam:us-west-1:cloudera:user:__internal__actor__", () -> stackV4Endpoint.recoverClusterByNameInternal(0L, cluster.getClusterName(), ThreadBasedUserCrnProvider.getUserCrn()))).thenReturn(recoveryV4Response);
    ThreadBasedUserCrnProvider.doAsInternalActor("crn:cdp:iam:us-west-1:cloudera:user:__internal__actor__", () -> underTest.recoverCluster(clusterId));
    verify(stackV4Endpoint).recoverClusterByNameInternal(eq(0L), eq(CLUSTER_NAME), nullable(String.class));
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.RECOVERY_IN_PROGRESS, DATALAKE_RECOVERY_REQUESTED, "Recovering datalake stack", cluster);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) RecoveryV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response) Test(org.junit.jupiter.api.Test)

Example 10 with StackV4Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint in project cloudbreak by hortonworks.

the class ProvisionerServiceTest method startStackDeletionButClientError.

@Test
void startStackDeletionButClientError() {
    long clusterId = CLUSTER_ID.incrementAndGet();
    SdxCluster sdxCluster = generateValidSdxCluster(clusterId);
    when(sdxService.getById(clusterId)).thenReturn(sdxCluster);
    StackV4Response stackV4Response = new StackV4Response();
    stackV4Response.setStatus(Status.CREATE_FAILED);
    WebApplicationException webApplicationException = new WebApplicationException();
    doThrow(webApplicationException).when(stackV4Endpoint).deleteInternal(anyLong(), eq(sdxCluster.getClusterName()), eq(Boolean.FALSE), nullable(String.class));
    when(webApplicationExceptionMessageExtractor.getErrorMessage(webApplicationException)).thenReturn("web-error");
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:datahub:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    RuntimeException actual = Assertions.assertThrows(RuntimeException.class, () -> underTest.startStackDeletion(clusterId, false));
    Assertions.assertEquals("Cannot delete cluster, error happened during the operation: web-error", actual.getMessage());
    verify(stackV4Endpoint).deleteInternal(eq(0L), eq(null), eq(false), nullable(String.class));
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)7 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)3 ClusterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response)2 NotFoundException (javax.ws.rs.NotFoundException)2 StackV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint)1 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 GeneratedBlueprintV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.GeneratedBlueprintV4Response)1 StackStatusV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)1 StackViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)1 AttachRecipeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.AttachRecipeV4Response)1 RecoveryV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recovery.RecoveryV4Response)1 StackCcmUpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.StackCcmUpgradeV4Response)1 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)1 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)1 EnvironmentView (com.sequenceiq.environment.environment.domain.EnvironmentView)1 PollingConfig (com.sequenceiq.environment.util.PollingConfig)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1