Search in sources :

Example 1 with ClusterRepairRequest

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

the class ManualRecoveryTest method testManualRecovery.

@Test
@Parameters({ "hostGroup", "removeOnly", "removedInstanceCount" })
public void testManualRecovery(String hostGroup, @Optional("False") Boolean removeOnly, @Optional("0") Integer removedInstanceCount) {
    // GIVEN
    if (removeOnly) {
        Assert.assertNotEquals(removedInstanceCount, 0);
    }
    IntegrationTestContext itContext = getItContext();
    String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    String ambariUser = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID);
    String ambariPassword = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID);
    String ambariPort = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PORT_ID);
    Map<String, String> cloudProviderParams = itContext.getContextParam(CloudbreakITContextConstants.CLOUDPROVIDER_PARAMETERS, Map.class);
    StackV1Endpoint stackV1Endpoint = getCloudbreakClient().stackV1Endpoint();
    StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
    String instanceToDelete = RecoveryUtil.getInstanceId(stackResponse, hostGroup);
    Assert.assertNotNull(instanceToDelete);
    RecoveryUtil.deleteInstance(cloudProviderParams, instanceToDelete);
    Integer expectedNodeCountAmbari = ScalingUtil.getNodeCountAmbari(stackV1Endpoint, ambariPort, stackId, ambariUser, ambariPassword, itContext) - removedInstanceCount;
    WaitResult waitResult = CloudbreakUtil.waitForHostStatusStack(stackV1Endpoint, stackId, hostGroup, "UNHEALTHY");
    if (waitResult == WaitResult.TIMEOUT) {
        Assert.fail("Timeout happened when waiting for the desired host state");
    }
    // WHEN
    List<String> hostgroupList = Arrays.asList(hostGroup.split(","));
    ClusterRepairRequest clusterRepairRequest = new ClusterRepairRequest();
    clusterRepairRequest.setHostGroups(hostgroupList);
    clusterRepairRequest.setRemoveOnly(removeOnly);
    getCloudbreakClient().clusterEndpoint().repairCluster(Long.valueOf(stackId), clusterRepairRequest);
    // THEN
    Map<String, String> desiredStatuses = new HashMap<>();
    desiredStatuses.put("status", "AVAILABLE");
    desiredStatuses.put("clusterStatus", "AVAILABLE");
    CloudbreakUtil.waitAndCheckStatuses(getCloudbreakClient(), stackId, desiredStatuses);
    Integer actualNodeCountAmbari = ScalingUtil.getNodeCountAmbari(stackV1Endpoint, ambariPort, stackId, ambariUser, ambariPassword, itContext);
    Assert.assertEquals(expectedNodeCountAmbari, actualNodeCountAmbari);
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) HashMap(java.util.HashMap) WaitResult(com.sequenceiq.it.cloudbreak.WaitResult) ClusterRepairRequest(com.sequenceiq.cloudbreak.api.model.ClusterRepairRequest) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)1 ClusterRepairRequest (com.sequenceiq.cloudbreak.api.model.ClusterRepairRequest)1 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)1 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)1 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)1 WaitResult (com.sequenceiq.it.cloudbreak.WaitResult)1 HashMap (java.util.HashMap)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1