Search in sources :

Example 6 with StackV1Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint 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)

Example 7 with StackV1Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint in project cloudbreak by hortonworks.

the class ScalingUtil method putInstanceCountToContext.

public static void putInstanceCountToContext(IntegrationTestContext itContext, String stackId) {
    Collection<Map<String, Integer>> tmpInstanceCount = new ArrayList<>();
    StackV1Endpoint stackV1Endpoint = itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint();
    StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
    if (itContext.getContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, List.class) != null) {
        tmpInstanceCount = itContext.getContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, List.class);
        tmpInstanceCount.add(getNodeCountByHostgroup(stackResponse));
    } else {
        tmpInstanceCount.add(getNodeCountByHostgroup(stackResponse));
    }
    itContext.putContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, tmpInstanceCount);
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse)

Example 8 with StackV1Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint in project cloudbreak by hortonworks.

the class AutoScalingPrometheusTest method testAutoscaling.

@Test
@Parameters({ "cooldown", "clusterMinSize", "clusterMaxSize", "policyName", "operator", "alertRuleName", "period", "threshold", "hostGroup", "scalingAdjustment" })
public void testAutoscaling(int cooldown, int clusterMinSize, int clusterMaxSize, String policyName, String operator, String alertRuleName, int period, Double threshold, String hostGroup, int scalingAdjustment) {
    // GIVEN
    itContext = getItContext();
    String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    StackV1Endpoint stackV1Endpoint = itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint();
    String ambariUser = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID);
    String ambariPassword = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID);
    String ambariPort = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PORT_ID);
    autoscaleClient = itContext.getContextParam(CloudbreakITContextConstants.AUTOSCALE_CLIENT, AutoscaleClient.class);
    Long clusterId = AutoscalingUtil.getPeriscopeClusterId(autoscaleClient, stackId);
    long currentTime = RecoveryUtil.getCurentTimeStamp();
    int expectedNodeCountStack = ScalingUtil.getNodeCountStack(stackV1Endpoint, stackId) + scalingAdjustment;
    int expectedNodeCountCluster = ScalingUtil.getNodeCountAmbari(stackV1Endpoint, ambariPort, stackId, ambariUser, ambariPassword, itContext) + scalingAdjustment;
    // WHEN
    AutoscalingUtil.configureAutoScaling(autoscaleClient, clusterId, cooldown, clusterMinSize, clusterMaxSize);
    AutoscalingUtil.switchAutoscaling(autoscaleClient, clusterId, true);
    AutoscalingUtil.createPrometheusAlert(autoscaleClient, clusterId, policyName, operator, alertRuleName, period, threshold);
    Long alertId = AutoscalingUtil.getAlertId(autoscaleClient, clusterId, policyName);
    AutoscalingUtil.setAlertsToContext(itContext, clusterId, alertId);
    AutoscalingUtil.createPolicy(autoscaleClient, policyName, clusterId, alertId, hostGroup, scalingAdjustment);
    // THEN
    AutoscalingUtil.checkHistory(autoscaleClient, clusterId, currentTime);
    AutoscalingUtil.checkScaling(itContext, getCloudbreakClient(), scalingAdjustment, stackId, expectedNodeCountStack, expectedNodeCountCluster);
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) AutoscaleClient(com.sequenceiq.periscope.client.AutoscaleClient) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 9 with StackV1Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint in project cloudbreak by hortonworks.

the class AutoscalingUtil method checkScaling.

static void checkScaling(IntegrationTestContext itContext, CloudbreakClient cloudbreakClient, int scalingAdjustment, String stackId, int expectedNodeCountStack, int expectedNodeCountCluster) {
    String ambariUser = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID);
    String ambariPassword = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID);
    String ambariPort = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PORT_ID);
    StackV1Endpoint stackV1Endpoint = itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint();
    if (scalingAdjustment < 0) {
        CloudbreakUtil.waitAndCheckClusterStatus(cloudbreakClient, stackId, "AVAILABLE");
        CloudbreakUtil.waitAndCheckStackStatus(cloudbreakClient, stackId, "AVAILABLE");
    } else {
        CloudbreakUtil.waitAndCheckStackStatus(cloudbreakClient, stackId, "AVAILABLE");
        CloudbreakUtil.waitAndCheckClusterStatus(cloudbreakClient, stackId, "AVAILABLE");
    }
    ScalingUtil.checkStackScaled(stackV1Endpoint, stackId, expectedNodeCountStack);
    ScalingUtil.checkClusterScaled(stackV1Endpoint, ambariPort, stackId, ambariUser, ambariPassword, expectedNodeCountCluster, itContext);
    ScalingUtil.putInstanceCountToContext(itContext, stackId);
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient)

Example 10 with StackV1Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint in project cloudbreak by hortonworks.

the class CloudbreakUtil method getFailedStatusReason.

public static String getFailedStatusReason(CloudbreakClient cloudbreakClient, String stackId, Map<String, String> desiredStatuses, Collection<WaitResult> desiredWaitResult) {
    for (int i = 0; i < 3; i++) {
        WaitResult waitResult = waitForStatuses(cloudbreakClient, stackId, desiredStatuses);
        if (!desiredWaitResult.contains(waitResult)) {
            Assert.fail("Expected status is failed, actual: " + waitResult);
        } else {
            StackV1Endpoint stackV1Endpoint = cloudbreakClient.stackV1Endpoint();
            stackV1Endpoint.status(Long.valueOf(stackId));
            return stackV1Endpoint.status(Long.valueOf(stackId)).get("statusReason").toString();
        }
    }
    return "";
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) StackEndpoint(com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint) HistoryEndpoint(com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint) EventEndpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)

Aggregations

StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)16 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)14 Parameters (org.testng.annotations.Parameters)14 Test (org.testng.annotations.Test)14 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)11 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)11 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)8 HashMap (java.util.HashMap)4 StackEndpoint (com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint)3 ClusterV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.ClusterV1Endpoint)3 EventEndpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)3 ClusterRequest (com.sequenceiq.cloudbreak.api.model.ClusterRequest)3 HostGroupRequest (com.sequenceiq.cloudbreak.api.model.HostGroupRequest)3 InstanceGroupResponse (com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse)3 KerberosRequest (com.sequenceiq.cloudbreak.api.model.KerberosRequest)3 HistoryEndpoint (com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)2