Search in sources :

Example 6 with StackResponse

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

the class MockInstanceTerminationUnknownTest method testInstanceTermination.

@Test
public void testInstanceTermination() throws Exception {
    // GIVEN
    // WHEN
    Long stackId = Long.parseLong(getItContext().getContextParam(CloudbreakITContextConstants.STACK_ID));
    StackResponse stackResponse = getStackResponse(stackId);
    // THEN
    String hostGroupName = "compute";
    int before = getInstanceMetaData(stackResponse, hostGroupName).size();
    String instanceId = getInstanceId(stackResponse, hostGroupName);
    getCloudbreakClient().stackV2Endpoint().deleteInstance(stackResponse.getId(), instanceId);
    Map<String, String> desiredStatuses = new HashMap<>();
    desiredStatuses.put("status", "AVAILABLE");
    desiredStatuses.put("clusterStatus", "AVAILABLE");
    CloudbreakUtil.waitAndCheckStatuses(getCloudbreakClient(), stackId.toString(), desiredStatuses);
    int after = getInstanceMetaData(getStackResponse(stackId), hostGroupName).size();
    Assert.assertEquals(after, before - 1);
    stackResponse = getStackResponse(stackId);
    Assert.assertTrue(getInstanceMetaData(stackResponse, hostGroupName).stream().noneMatch(a -> a.getDiscoveryFQDN().equals(instanceId)));
}
Also used : AfterClass(org.testng.annotations.AfterClass) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakITContextConstants(com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants) MockServer(com.sequenceiq.it.cloudbreak.v2.mock.MockServer) InstanceGroupV2Request(com.sequenceiq.cloudbreak.api.model.v2.InstanceGroupV2Request) Optional(org.testng.annotations.Optional) Assert(org.testng.Assert) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) CloudbreakUtil(com.sequenceiq.it.cloudbreak.CloudbreakUtil) CloudbreakV2Constants(com.sequenceiq.it.cloudbreak.v2.CloudbreakV2Constants) Collections(java.util.Collections) HashMap(java.util.HashMap) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 7 with StackResponse

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

the class TagsTest method testTagTest.

@Test
@Parameters("tags")
public void testTagTest(String tags) throws Exception {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    Map<String, String> cloudProviderParams = itContext.getContextParam(CloudbreakITContextConstants.CLOUDPROVIDER_PARAMETERS, Map.class);
    StackV1Endpoint stackV1Endpoint = itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint();
    StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
    Map<String, String> userDefinedTagsStack = TagsUtil.checkTagsStack(stackResponse);
    Map<String, String> tagsToCheckMap = TagsUtil.getTagsToCheck(tags);
    // WHEN: The cluster was created with user-defined tags
    // THEN
    TagsUtil.checkTags(tagsToCheckMap, userDefinedTagsStack);
    List<String> instanceIdList = TagsUtil.getInstancesList(stackResponse);
    TagsUtil.checkTagsWithProvider(stackResponse.getName(), cloudProviderParams, applicationContext, instanceIdList, tagsToCheckMap);
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 8 with StackResponse

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

the class AutoRecoveryTest method testAutoRecovery.

@Test
@Parameters({ "hostGroup", "removedInstanceCount" })
public void testAutoRecovery(String hostGroup, @Optional("0") Integer removedInstanceCount) {
    // GIVEN
    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.waitForEvent(getCloudbreakClient(), stackResponse.getName(), "RECOVERY", "autorecovery requested", RecoveryUtil.getCurentTimeStamp());
    if (waitResult == WaitResult.TIMEOUT) {
        Assert.fail("Timeout happened when waiting for the desired host state");
    }
    // WHEN: Cloudbreak automatically starts the recover
    // 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) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 9 with StackResponse

use of com.sequenceiq.cloudbreak.api.model.StackResponse 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 10 with StackResponse

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

the class ScalingUtil method checkStackScaled.

public static void checkStackScaled(StackEndpoint stackV1Endpoint, String stackId, int expectedNodeCount) {
    StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
    checkStackScaled(expectedNodeCount, stackResponse);
}
Also used : StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse)

Aggregations

StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)32 Test (org.testng.annotations.Test)10 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)9 Parameters (org.testng.annotations.Parameters)9 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)8 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)7 Map (java.util.Map)7 CredentialResponse (com.sequenceiq.cloudbreak.api.model.CredentialResponse)6 ImageJson (com.sequenceiq.cloudbreak.api.model.ImageJson)6 OrchestratorResponse (com.sequenceiq.cloudbreak.api.model.OrchestratorResponse)6 StackAuthenticationResponse (com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse)6 HashMap (java.util.HashMap)6 CloudbreakDetailsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakDetailsJson)5 ClusterResponse (com.sequenceiq.cloudbreak.api.model.ClusterResponse)5 FailurePolicyResponse (com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse)5 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)5 InstanceMetaDataJson (com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)5 NetworkResponse (com.sequenceiq.cloudbreak.api.model.NetworkResponse)5 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)5 Test (org.junit.Test)5