Search in sources :

Example 1 with Optional

use of org.testng.annotations.Optional in project cloudbreak by hortonworks.

the class IpPoolSelectionTest method testIpPoolSelection.

@Test
@Parameters({ "credentialName", "region", "availabilityZone", "poolName" })
public void testIpPoolSelection(@Optional("") String credentialName, @Optional("") String region, @Optional("") String availabilityZone, String poolName) {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    credentialName = StringUtils.hasText(credentialName) ? credentialName : itContext.getContextParam(CloudbreakV2Constants.CREDENTIAL_NAME);
    region = StringUtils.hasText(region) ? region : itContext.getContextParam(CloudbreakV2Constants.REGION);
    availabilityZone = StringUtils.hasText(availabilityZone) ? availabilityZone : itContext.getContextParam(CloudbreakV2Constants.AVAILABILTYZONE);
    PlatformResourceRequestJson resourceRequestJson = new PlatformResourceRequestJson();
    resourceRequestJson.setCredentialName(credentialName);
    resourceRequestJson.setRegion(region);
    resourceRequestJson.setAvailabilityZone(availabilityZone);
    // WHEN
    PlatformIpPoolsResponse response = getCloudbreakClient().connectorV1Endpoint().getIpPoolsCredentialId(resourceRequestJson);
    // THEN
    Set<IpPoolJson> ipPools = response.getIppools().get(availabilityZone);
    Assert.assertNotNull(ipPools, "ippools cannot be null for " + region);
    java.util.Optional<IpPoolJson> selected = ipPools.stream().filter(rk -> rk.getName().equals(poolName)).findFirst();
    Assert.assertTrue(selected.isPresent(), "the ippool list doesn't contain [" + poolName + ']');
    getItContext().putContextParam(CloudbreakV2Constants.OPENSTACK_FLOATING_POOL, selected.get().getId());
}
Also used : Optional(org.testng.annotations.Optional) PlatformResourceRequestJson(com.sequenceiq.cloudbreak.api.model.PlatformResourceRequestJson) Assert(org.testng.Assert) PlatformIpPoolsResponse(com.sequenceiq.cloudbreak.api.model.PlatformIpPoolsResponse) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Parameters(org.testng.annotations.Parameters) Set(java.util.Set) Test(org.testng.annotations.Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) IpPoolJson(com.sequenceiq.cloudbreak.api.model.IpPoolJson) StringUtils(org.springframework.util.StringUtils) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) PlatformIpPoolsResponse(com.sequenceiq.cloudbreak.api.model.PlatformIpPoolsResponse) IpPoolJson(com.sequenceiq.cloudbreak.api.model.IpPoolJson) PlatformResourceRequestJson(com.sequenceiq.cloudbreak.api.model.PlatformResourceRequestJson) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 2 with Optional

use of org.testng.annotations.Optional in project cloudbreak by hortonworks.

the class MockScalingTest method configMockServer.

@BeforeClass
@Parameters({ "mockPort", "sshPort", "desiredCount", "hostGroup" })
public void configMockServer(@Optional("9443") int mockPort, @Optional("2020") int sshPort, int desiredCount, String hostGroup) {
    IntegrationTestContext itContext = getItContext();
    String clusterName = itContext.getContextParam(CloudbreakV2Constants.STACK_NAME);
    StackResponse response = getCloudbreakClient().stackV2Endpoint().getPrivate(clusterName, null);
    java.util.Optional<InstanceGroupResponse> igg = response.getInstanceGroups().stream().filter(ig -> ig.getGroup().equals(hostGroup)).findFirst();
    Map<String, CloudVmInstanceStatus> instanceMap = itContext.getContextParam(CloudbreakITContextConstants.MOCK_INSTANCE_MAP, Map.class);
    ScalingMock scalingMock = (ScalingMock) applicationContext.getBean(ScalingMock.NAME, mockPort, sshPort, instanceMap);
    scalingMock.addSPIEndpoints();
    scalingMock.addMockEndpoints();
    scalingMock.addAmbariMappings(clusterName);
    itContext.putContextParam(CloudbreakV2Constants.MOCK_SERVER, scalingMock);
    igg.ifPresent(ig -> {
        int scalingAdjustment = desiredCount - ig.getNodeCount();
        if (scalingAdjustment > 0) {
            scalingMock.addInstance(scalingAdjustment);
        }
    });
}
Also used : AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Test(org.testng.annotations.Test) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakITContextConstants(com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants) Optional(org.testng.annotations.Optional) ScalingUtil(com.sequenceiq.it.cloudbreak.scaling.ScalingUtil) Assert(org.testng.Assert) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) StackV2Request(com.sequenceiq.cloudbreak.api.model.v2.StackV2Request) CloudbreakV2Constants(com.sequenceiq.it.cloudbreak.v2.CloudbreakV2Constants) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) StackScalingV2Test(com.sequenceiq.it.cloudbreak.v2.StackScalingV2Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) BeforeClass(org.testng.annotations.BeforeClass) Parameters(org.testng.annotations.Parameters)

Example 3 with Optional

use of org.testng.annotations.Optional in project cloudbreak by hortonworks.

the class ExistingSshKeySelectionTest method testSshKeySelection.

@Test
@Parameters({ "credentialName", "region", "availabilityZone", "selectedKeyName" })
public void testSshKeySelection(@Optional("") String credentialName, @Optional("") String region, @Optional("") String availabilityZone, String selectedKeyName) {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    credentialName = StringUtils.hasText(credentialName) ? credentialName : itContext.getContextParam(CloudbreakV2Constants.CREDENTIAL_NAME);
    region = StringUtils.hasText(region) ? region : itContext.getContextParam(CloudbreakV2Constants.REGION);
    availabilityZone = StringUtils.hasText(availabilityZone) ? availabilityZone : itContext.getContextParam(CloudbreakV2Constants.AVAILABILTYZONE);
    PlatformResourceRequestJson resourceRequestJson = new PlatformResourceRequestJson();
    resourceRequestJson.setCredentialName(credentialName);
    resourceRequestJson.setRegion(region);
    resourceRequestJson.setAvailabilityZone(availabilityZone);
    // WHEN
    PlatformSshKeysResponse response = getCloudbreakClient().connectorV1Endpoint().getCloudSshKeys(resourceRequestJson);
    // THEN
    Set<PlatformSshKeyResponse> regionKeys = response.getSshKeys().get(region);
    Assert.assertNotNull(regionKeys, "keys cannot be null for " + region);
    java.util.Optional<PlatformSshKeyResponse> selected = regionKeys.stream().filter(rk -> rk.getName().equals(selectedKeyName)).findFirst();
    Assert.assertTrue(selected.isPresent(), "the sshkey list doesn't contain [" + selectedKeyName + ']');
    getItContext().putContextParam(CloudbreakV2Constants.SSH_PUBLICKEY_ID, selected.get().getName());
}
Also used : Optional(org.testng.annotations.Optional) PlatformResourceRequestJson(com.sequenceiq.cloudbreak.api.model.PlatformResourceRequestJson) Assert(org.testng.Assert) PlatformSshKeysResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Parameters(org.testng.annotations.Parameters) Set(java.util.Set) PlatformSshKeyResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeyResponse) Test(org.testng.annotations.Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) StringUtils(org.springframework.util.StringUtils) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) PlatformSshKeysResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse) PlatformResourceRequestJson(com.sequenceiq.cloudbreak.api.model.PlatformResourceRequestJson) PlatformSshKeyResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeyResponse) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)3 Assert (org.testng.Assert)3 Optional (org.testng.annotations.Optional)3 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 PlatformResourceRequestJson (com.sequenceiq.cloudbreak.api.model.PlatformResourceRequestJson)2 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)2 Set (java.util.Set)2 StringUtils (org.springframework.util.StringUtils)2 InstanceGroupResponse (com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse)1 IpPoolJson (com.sequenceiq.cloudbreak.api.model.IpPoolJson)1 PlatformIpPoolsResponse (com.sequenceiq.cloudbreak.api.model.PlatformIpPoolsResponse)1 PlatformSshKeyResponse (com.sequenceiq.cloudbreak.api.model.PlatformSshKeyResponse)1 PlatformSshKeysResponse (com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse)1 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)1 StackV2Request (com.sequenceiq.cloudbreak.api.model.v2.StackV2Request)1 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)1 CloudbreakITContextConstants (com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants)1 ScalingUtil (com.sequenceiq.it.cloudbreak.scaling.ScalingUtil)1 CloudbreakV2Constants (com.sequenceiq.it.cloudbreak.v2.CloudbreakV2Constants)1