package com.sequenceiq.it.cloudbreak.scaling; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import org.testng.annotations.Test; import com.sequenceiq.cloudbreak.api.endpoint.StackEndpoint; import com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson; import com.sequenceiq.cloudbreak.api.model.UpdateClusterJson; import com.sequenceiq.cloudbreak.client.CloudbreakClient; import com.sequenceiq.it.IntegrationTestContext; import com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest; import com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants; import com.sequenceiq.it.cloudbreak.CloudbreakUtil; public class ClusterScalingTest extends AbstractCloudbreakIntegrationTest { private static final Logger LOGGER = LoggerFactory.getLogger(ClusterScalingTest.class); @BeforeMethod public void setContextParameters() { Assert.assertNotNull(getItContext().getContextParam(CloudbreakITContextConstants.STACK_ID), "Stack id is mandatory."); } @Test @Parameters({ "instanceGroup", "scalingAdjustment" }) public void testClusterScaling(@Optional("slave_1") String instanceGroup, int scalingAdjustment) throws Exception { // GIVEN IntegrationTestContext itContext = getItContext(); String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID); int stackIntId = Integer.valueOf(stackId); StackEndpoint stackEndpoint = itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackEndpoint(); String ambariUser = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID); String ambariPassword = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID); String ambariPort = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PORT_ID); int expectedNodeCount = ScalingUtil.getNodeCountAmbari(stackEndpoint, ambariPort, stackId, ambariUser, ambariPassword, itContext) + scalingAdjustment; // WHEN UpdateClusterJson updateClusterJson = new UpdateClusterJson(); HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson(); hostGroupAdjustmentJson.setHostGroup(instanceGroup); hostGroupAdjustmentJson.setWithStackUpdate(false); hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment); updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson); CloudbreakUtil.checkResponse("ScalingCluster", getCloudbreakClient().clusterEndpoint().put((long) stackIntId, updateClusterJson)); CloudbreakUtil.waitAndCheckClusterStatus(getCloudbreakClient(), stackId, "AVAILABLE"); // THEN ScalingUtil.checkClusterScaled(stackEndpoint, ambariPort, stackId, ambariUser, ambariPassword, expectedNodeCount, itContext); } }