Search in sources :

Example 36 with IntegrationTestContext

use of com.sequenceiq.it.IntegrationTestContext in project cloudbreak by hortonworks.

the class MockClusterScalingTest method testScaling.

@SuppressWarnings("Duplicates")
@Test
@Parameters({ "instanceGroup", "scalingAdjustment", "mockPort" })
public void testScaling(@Optional("slave_1") String instanceGroup, @Optional("1") int scalingAdjustment, @Optional("9443") int mockPort) {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    int stackIntId = Integer.parseInt(stackId);
    // WHEN
    if (scalingAdjustment < 0) {
        UpdateClusterJson updateClusterJson = new UpdateClusterJson();
        HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
        hostGroupAdjustmentJson.setHostGroup(instanceGroup);
        hostGroupAdjustmentJson.setWithStackUpdate(false);
        hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
        CloudbreakUtil.checkResponse("DownscaleCluster", getCloudbreakClient().clusterEndpoint().put((long) stackIntId, updateClusterJson));
        CloudbreakUtil.waitAndCheckClusterStatus(getCloudbreakClient(), stackId, "AVAILABLE");
        UpdateStackJson updateStackJson = new UpdateStackJson();
        updateStackJson.setWithClusterEvent(false);
        InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
        instanceGroupAdjustmentJson.setInstanceGroup(instanceGroup);
        instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
        CloudbreakUtil.checkResponse("DownscaleStack", getCloudbreakClient().stackV1Endpoint().put((long) stackIntId, updateStackJson));
        CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackId, "AVAILABLE");
    } else {
        UpdateStackJson updateStackJson = new UpdateStackJson();
        updateStackJson.setWithClusterEvent(false);
        InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
        instanceGroupAdjustmentJson.setInstanceGroup(instanceGroup);
        instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
        CloudbreakUtil.checkResponse("UpscaleStack", getCloudbreakClient().stackV1Endpoint().put((long) stackIntId, updateStackJson));
        CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackId, "AVAILABLE");
        UpdateClusterJson updateClusterJson = new UpdateClusterJson();
        HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
        hostGroupAdjustmentJson.setHostGroup(instanceGroup);
        hostGroupAdjustmentJson.setWithStackUpdate(false);
        hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
        CloudbreakUtil.checkResponse("UpscaleCluster", getCloudbreakClient().clusterEndpoint().put((long) stackIntId, updateClusterJson));
        CloudbreakUtil.waitAndCheckClusterStatus(getCloudbreakClient(), stackId, "AVAILABLE");
    }
    // THEN
    CloudbreakUtil.checkClusterAvailability(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint(), "8080", stackId, itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID), itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID), false);
    ScalingMock scalingMock = getItContext().getContextParam(CloudbreakV2Constants.MOCK_SERVER, ScalingMock.class);
    scalingMock.verifyV1Calls(CLUSTER_NAME, scalingAdjustment, false);
}
Also used : UpdateStackJson(com.sequenceiq.cloudbreak.api.model.UpdateStackJson) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) ScalingMock(com.sequenceiq.it.cloudbreak.v2.mock.ScalingMock) UpdateClusterJson(com.sequenceiq.cloudbreak.api.model.UpdateClusterJson) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 37 with IntegrationTestContext

use of com.sequenceiq.it.IntegrationTestContext in project cloudbreak by hortonworks.

the class MockStackCreationWithSaltSuccessTest method testStackCreation.

@Test
@Parameters({ "stackName", "region", "onFailureAction", "threshold", "adjustmentType", "variant", "availabilityZone", "persistentStorage", "orchestrator", "mockPort", "sshPort", "publicKeyFile" })
public void testStackCreation(@Optional("testing1") String stackName, @Optional("europe-west1") String region, @Optional("DO_NOTHING") String onFailureAction, @Optional("4") Long threshold, @Optional("EXACT") String adjustmentType, @Optional("") String variant, @Optional String availabilityZone, @Optional String persistentStorage, @Optional("SALT") String orchestrator, @Optional("9443") int mockPort, @Optional("2020") int sshPort, @Optional("") String publicKeyFile) throws Exception {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    List<InstanceGroup> instanceGroups = itContext.getContextParam(CloudbreakITContextConstants.TEMPLATE_ID, List.class);
    List<InstanceGroupRequest> igMap = new ArrayList<>();
    for (InstanceGroup ig : instanceGroups) {
        InstanceGroupRequest instanceGroupRequest = new InstanceGroupRequest();
        instanceGroupRequest.setGroup(ig.getName());
        instanceGroupRequest.setNodeCount(ig.getNodeCount());
        instanceGroupRequest.setTemplateId(Long.valueOf(ig.getTemplateId()));
        instanceGroupRequest.setType(InstanceGroupType.valueOf(ig.getType()));
        igMap.add(instanceGroupRequest);
    }
    String credentialId = itContext.getContextParam(CloudbreakITContextConstants.CREDENTIAL_ID);
    String networkId = itContext.getContextParam(CloudbreakITContextConstants.NETWORK_ID);
    StackRequest stackRequest = new StackRequest();
    publicKeyFile = StringUtils.hasLength(publicKeyFile) ? publicKeyFile : defaultPublicKeyFile;
    String publicKey = ResourceUtil.readStringFromResource(applicationContext, publicKeyFile).replaceAll("\n", "");
    StackAuthenticationRequest stackAuthenticationRequest = new StackAuthenticationRequest();
    stackAuthenticationRequest.setPublicKey(publicKey);
    stackRequest.setStackAuthentication(stackAuthenticationRequest);
    stackRequest.setName(stackName);
    stackRequest.setCredentialId(Long.valueOf(credentialId));
    stackRequest.setRegion(region);
    stackRequest.setOnFailureAction(OnFailureAction.valueOf(onFailureAction));
    FailurePolicyRequest failurePolicyRequest = new FailurePolicyRequest();
    failurePolicyRequest.setAdjustmentType(AdjustmentType.valueOf(adjustmentType));
    failurePolicyRequest.setThreshold(threshold);
    stackRequest.setFailurePolicy(failurePolicyRequest);
    stackRequest.setNetworkId(Long.valueOf(networkId));
    stackRequest.setPlatformVariant(variant);
    stackRequest.setAvailabilityZone(availabilityZone);
    stackRequest.setInstanceGroups(igMap);
    OrchestratorRequest orchestratorRequest = new OrchestratorRequest();
    orchestratorRequest.setType(orchestrator);
    stackRequest.setOrchestrator(orchestratorRequest);
    Map<String, String> map = new HashMap<>();
    if (persistentStorage != null && !persistentStorage.isEmpty()) {
        map.put("persistentStorage", persistentStorage);
    }
    stackRequest.setParameters(map);
    // WHEN
    String stackId = getCloudbreakClient().stackV1Endpoint().postPrivate(stackRequest).getId().toString();
    // THEN
    Assert.assertNotNull(stackId);
    itContext.putCleanUpParam(CloudbreakITContextConstants.STACK_ID, stackId);
    CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackId, "AVAILABLE");
    itContext.putContextParam(CloudbreakITContextConstants.STACK_ID, stackId);
}
Also used : IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) StackAuthenticationRequest(com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest) InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StackRequest(com.sequenceiq.cloudbreak.api.model.StackRequest) InstanceGroup(com.sequenceiq.it.cloudbreak.InstanceGroup) OrchestratorRequest(com.sequenceiq.cloudbreak.api.model.OrchestratorRequest) FailurePolicyRequest(com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 38 with IntegrationTestContext

use of com.sequenceiq.it.IntegrationTestContext in project cloudbreak by hortonworks.

the class MockStackCreationWithSaltSuccessTest method configMockServer.

@BeforeClass
@Parameters({ "stackName", "mockPort", "sshPort" })
public void configMockServer(String stackName, @Optional("9443") int mockPort, @Optional("2020") int sshPort) {
    IntegrationTestContext itContext = getItContext();
    List<InstanceGroup> instanceGroups = itContext.getContextParam(CloudbreakITContextConstants.TEMPLATE_ID, List.class);
    int numberOfServers = 0;
    for (InstanceGroup ig : instanceGroups) {
        numberOfServers += ig.getNodeCount();
    }
    StackCreationMock stackCreationMock = (StackCreationMock) applicationContext.getBean(StackCreationMock.NAME, mockPort, sshPort, numberOfServers);
    stackCreationMock.addSPIEndpoints();
    stackCreationMock.mockImageCatalogResponse(itContext);
    itContext.putContextParam(CloudbreakV2Constants.MOCK_SERVER, stackCreationMock);
    itContext.putContextParam(CloudbreakITContextConstants.MOCK_INSTANCE_MAP, stackCreationMock.getInstanceMap());
}
Also used : IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) StackCreationMock(com.sequenceiq.it.cloudbreak.v2.mock.StackCreationMock) InstanceGroup(com.sequenceiq.it.cloudbreak.InstanceGroup) BeforeClass(org.testng.annotations.BeforeClass) Parameters(org.testng.annotations.Parameters)

Example 39 with IntegrationTestContext

use of com.sequenceiq.it.IntegrationTestContext in project cloudbreak by hortonworks.

the class AutoScalingPrometheusTest method setContextParameters.

@BeforeMethod
public void setContextParameters() {
    IntegrationTestContext itContext = getItContext();
    Assert.assertNotNull("Stack id is mandatory.", itContext.getContextParam(CloudbreakITContextConstants.STACK_ID));
    Assert.assertNotNull("Autoscale is mandatory.", itContext.getContextParam(CloudbreakITContextConstants.AUTOSCALE_CLIENT));
}
Also used : IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 40 with IntegrationTestContext

use of com.sequenceiq.it.IntegrationTestContext in project cloudbreak by hortonworks.

the class FilesystemConfigureTest method testFilesystemConfigure.

@Test
@Parameters({ "filesystemType", "fsName" })
public void testFilesystemConfigure(String filesystemType, String fsName) {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    Map<String, String> cloudProviderParams = itContext.getContextParam(CloudbreakITContextConstants.CLOUDPROVIDER_PARAMETERS, Map.class);
    // WHEN
    FileSystemRequest fsRequest = new FileSystemRequest();
    fsRequest.setProperties(createRequestProperties(cloudProviderParams, fsName));
    fsRequest.setType(FileSystemType.valueOf(filesystemType));
    fsRequest.setName("it-fs");
    fsRequest.setDefaultFs(false);
    // THEN
    getItContext().putContextParam(FSREQUEST, fsRequest);
}
Also used : IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) FileSystemRequest(com.sequenceiq.cloudbreak.api.model.FileSystemRequest) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)71 Parameters (org.testng.annotations.Parameters)39 Test (org.testng.annotations.Test)32 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)26 BeforeMethod (org.testng.annotations.BeforeMethod)26 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)10 InstanceGroupV2Request (com.sequenceiq.cloudbreak.api.model.v2.InstanceGroupV2Request)9 BeforeClass (org.testng.annotations.BeforeClass)9 HashMap (java.util.HashMap)8 UpdateClusterJson (com.sequenceiq.cloudbreak.api.model.UpdateClusterJson)7 UpdateStackJson (com.sequenceiq.cloudbreak.api.model.UpdateStackJson)7 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)7 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)6 ArrayList (java.util.ArrayList)6 StackV2Request (com.sequenceiq.cloudbreak.api.model.v2.StackV2Request)5 KerberosRequest (com.sequenceiq.cloudbreak.api.model.KerberosRequest)4 ClusterV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.ClusterV1Endpoint)3 ClusterRequest (com.sequenceiq.cloudbreak.api.model.ClusterRequest)3 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)3 HostGroupRequest (com.sequenceiq.cloudbreak.api.model.HostGroupRequest)3