Search in sources :

Example 11 with StackV1Endpoint

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

the class CloudbreakUtil method waitForStatuses.

private static WaitResult waitForStatuses(CloudbreakClient cloudbreakClient, String stackId, Map<String, String> desiredStatuses) {
    WaitResult waitResult = WaitResult.SUCCESSFUL;
    Map<String, String> currentStatuses = new HashMap<>();
    int retryCount = 0;
    do {
        LOGGER.info("Waiting for status(es) {}, stack id: {}, current status(es) {} ...", desiredStatuses, stackId, currentStatuses);
        sleep();
        StackV1Endpoint stackV1Endpoint = cloudbreakClient.stackV1Endpoint();
        try {
            Map<String, Object> statusResult = stackV1Endpoint.status(Long.valueOf(stackId));
            for (String statusPath : desiredStatuses.keySet()) {
                currentStatuses.put(statusPath, (String) statusResult.get(statusPath));
            }
        } catch (RuntimeException ignore) {
            continue;
        }
        retryCount++;
    } while (!checkStatuses(currentStatuses, desiredStatuses) && !checkFailedStatuses(currentStatuses) && retryCount < MAX_RETRY);
    LOGGER.info("Status(es) {} for {} are in desired status(es) {}", desiredStatuses.keySet(), stackId, currentStatuses.values());
    if (currentStatuses.values().stream().anyMatch(cs -> cs.contains("FAILED")) || checkNotExpectedDelete(currentStatuses, desiredStatuses)) {
        waitResult = WaitResult.FAILED;
    }
    if (retryCount == MAX_RETRY) {
        waitResult = WaitResult.TIMEOUT;
    }
    return waitResult;
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) Arrays(java.util.Arrays) HostMetadataResponse(com.sequenceiq.cloudbreak.api.model.HostMetadataResponse) HostGroupResponse(com.sequenceiq.cloudbreak.api.model.HostGroupResponse) LoggerFactory(org.slf4j.LoggerFactory) AutoscaleClusterHistoryResponse(com.sequenceiq.periscope.api.model.AutoscaleClusterHistoryResponse) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) HashMap(java.util.HashMap) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) AutoscaleClient(com.sequenceiq.periscope.client.AutoscaleClient) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) Status(com.sequenceiq.cloudbreak.api.model.Status) StackEndpoint(com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint) Assert(org.testng.Assert) Map(java.util.Map) FALSE(java.lang.Boolean.FALSE) Logger(org.slf4j.Logger) HistoryEndpoint(com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint) Collection(java.util.Collection) Set(java.util.Set) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) Family(javax.ws.rs.core.Response.Status.Family) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) Entry(java.util.Map.Entry) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) EventEndpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StringUtils(org.springframework.util.StringUtils) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HashMap(java.util.HashMap) 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)

Example 12 with StackV1Endpoint

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

the class ClusterCreationTest method testClusterCreation.

@Test
@Parameters({ "clusterName", "emailNeeded", "enableSecurity", "kerberosMasterKey", "kerberosAdmin", "kerberosPassword", "runRecipesOnHosts", "checkAmbari", "withRDSConfig", "autoRecoveryMode", "withFs" })
public void testClusterCreation(@Optional("it-cluster") String clusterName, @Optional("false") boolean emailNeeded, @Optional("false") boolean enableSecurity, @Optional String kerberosMasterKey, @Optional String kerberosAdmin, @Optional String kerberosPassword, @Optional("") String runRecipesOnHosts, @Optional("true") boolean checkAmbari, @Optional("false") boolean withRDSConfig, @Optional("false") boolean autoRecoveryMode, @Optional("false") boolean withFs) throws Exception {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    String stackIdStr = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    Integer stackId = Integer.valueOf(stackIdStr);
    Integer blueprintId = Integer.valueOf(itContext.getContextParam(CloudbreakITContextConstants.BLUEPRINT_ID));
    List<HostGroup> hostgroups = itContext.getContextParam(CloudbreakITContextConstants.HOSTGROUP_ID, List.class);
    Set<HostGroupRequest> hostGroupJsons1 = convertHostGroups(hostgroups, runRecipesOnHosts, autoRecoveryMode);
    String ambariUser = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID);
    String ambariPassword = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID);
    String ambariPort = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PORT_ID);
    // WHEN
    ClusterRequest clusterRequest = new ClusterRequest();
    clusterRequest.setName(clusterName);
    clusterRequest.setDescription("Cluster for integration test");
    clusterRequest.setEnableSecurity(enableSecurity);
    clusterRequest.setPassword(ambariPassword);
    clusterRequest.setUserName(ambariUser);
    clusterRequest.setBlueprintId(Long.valueOf(blueprintId));
    clusterRequest.setHostGroups(hostGroupJsons1);
    if (withRDSConfig) {
        clusterRequest = setRDSConfiguration(itContext, clusterRequest);
    }
    if (withFs) {
        clusterRequest = setFileSystem(itContext, clusterRequest);
    }
    if (enableSecurity) {
        KerberosRequest kerberosRequest = new KerberosRequest();
        kerberosRequest.setAdmin(kerberosAdmin);
        kerberosRequest.setPassword(kerberosPassword);
        kerberosRequest.setMasterKey(kerberosMasterKey);
        clusterRequest.setKerberos(kerberosRequest);
    }
    ClusterV1Endpoint clusterV1Endpoint = getCloudbreakClient().clusterEndpoint();
    Long clusterId = clusterV1Endpoint.post(Long.valueOf(stackId), clusterRequest).getId();
    // THEN
    Assert.assertNotNull(clusterId);
    CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackIdStr, "AVAILABLE");
    CloudbreakUtil.checkClusterAvailability(getCloudbreakClient().stackV1Endpoint(), ambariPort, stackIdStr, ambariUser, ambariPassword, checkAmbari);
    if (Boolean.TRUE.equals(withRDSConfig)) {
        checkRDSConfigWithCluster(itContext, clusterName);
    }
}
Also used : IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) ClusterV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.ClusterV1Endpoint) ClusterRequest(com.sequenceiq.cloudbreak.api.model.ClusterRequest) HostGroupRequest(com.sequenceiq.cloudbreak.api.model.HostGroupRequest) KerberosRequest(com.sequenceiq.cloudbreak.api.model.KerberosRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 13 with StackV1Endpoint

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

the class FilesystemTest method testFileSystem.

@Test
@Parameters({ "filesystemType", "filesystemName", "folderPrefix", "wasbContainerName", "sshCommand", "sshUser", "sshChecker" })
public void testFileSystem(String filesystemType, String filesystemName, String folderPrefix, @Optional("it-container") String wasbContainerName, String sshCommand, @Optional("cloudbreak") String sshUser, String sshChecker) throws IOException {
    // GIVEN
    Assert.assertEquals(new File(defaultPrivateKeyFile).exists(), true, "Private cert file not found: " + defaultPrivateKeyFile);
    fsParams.put("filesystemType", filesystemType);
    fsParams.put("filesystemName", filesystemName);
    fsParams.put("folderPrefix", folderPrefix);
    fsParams.put("wasbContainerName", wasbContainerName);
    IntegrationTestContext itContext = getItContext();
    String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    StackV1Endpoint stackV1Endpoint = itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint();
    String masterIp = CloudbreakUtil.getAmbariIp(stackV1Endpoint, stackId, itContext);
    Map<String, String> cloudProviderParams = itContext.getContextParam(CloudbreakITContextConstants.CLOUDPROVIDER_PARAMETERS, Map.class);
    sshCommand = ResourceUtil.readStringFromResource(applicationContext, sshCommand.replaceAll("\n", ""));
    if ("WASB".equals(filesystemType)) {
        FilesystemUtil.createWasbContainer(cloudProviderParams, filesystemName, wasbContainerName);
    }
    // WHEN
    boolean sshResult = SshUtil.executeCommand(masterIp, defaultPrivateKeyFile, sshCommand, sshUser, SshUtil.getSshCheckMap(sshChecker));
    // THEN
    Assert.assertTrue(sshResult, "Ssh command executing was not successful");
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) File(java.io.File) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 14 with StackV1Endpoint

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

the class AwsCheckSpotInstance method checkSpotInstance.

@Parameters({ "region", "hostGroupToCheck", "scalingAdjustment" })
@Test
public void checkSpotInstance(Regions region, String hostGroupToCheck, @Optional Integer scalingAdjustment) {
    // GIVEN
    Integer spotInstanceCount = 0;
    IntegrationTestContext itContext = getItContext();
    String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    StackV1Endpoint stackV1Endpoint = getCloudbreakClient().stackV1Endpoint();
    StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
    List<InstanceGroupResponse> instanceGroups = stackResponse.getInstanceGroups();
    Collection<String> instanceIdList = new ArrayList<>();
    List<String> hostGroupList = Arrays.asList(hostGroupToCheck.split(","));
    for (InstanceGroupResponse instanceGroup : instanceGroups) {
        if (hostGroupList.contains(instanceGroup.getGroup())) {
            Set<InstanceMetaDataJson> instanceMetaData = instanceGroup.getMetadata();
            for (InstanceMetaDataJson metaData : instanceMetaData) {
                instanceIdList.add(metaData.getInstanceId());
            }
        }
    }
    // WHEN
    AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
    DescribeSpotInstanceRequestsResult describeSpotInstanceRequestsResult = ec2.describeSpotInstanceRequests();
    List<SpotInstanceRequest> spotInstanceRequests = describeSpotInstanceRequestsResult.getSpotInstanceRequests();
    // THEN
    Assert.assertFalse(spotInstanceRequests.isEmpty());
    Collection<String> spotInstanceIdList = new ArrayList<>();
    for (SpotInstanceRequest request : spotInstanceRequests) {
        spotInstanceIdList.add(request.getInstanceId());
    }
    for (String id : instanceIdList) {
        Assert.assertTrue(spotInstanceIdList.contains(id));
        if (spotInstanceIdList.contains(id)) {
            spotInstanceCount += 1;
        }
    }
    if (scalingAdjustment != null) {
        Assert.assertNotNull(itContext.getContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, List.class));
        Integer instanceCountPrev = 0;
        for (String hostGroup : hostGroupList) {
            List<Map<String, Integer>> instanceList = itContext.getContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, List.class);
            Assert.assertTrue(instanceList.size() >= 2);
            instanceCountPrev += instanceList.get(instanceList.size() - 2).get(hostGroup);
        }
        Assert.assertEquals(Integer.valueOf(instanceCountPrev + scalingAdjustment), spotInstanceCount);
    }
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) ArrayList(java.util.ArrayList) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) SpotInstanceRequest(com.amazonaws.services.ec2.model.SpotInstanceRequest) DescribeSpotInstanceRequestsResult(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult) ArrayList(java.util.ArrayList) List(java.util.List) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 15 with StackV1Endpoint

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

the class CloudbreakUtil method waitForHostStatusStack.

public static WaitResult waitForHostStatusStack(StackEndpoint stackV1Endpoint, String stackId, String hostGroup, String desiredStatus) {
    WaitResult waitResult = WaitResult.SUCCESSFUL;
    Boolean found = FALSE;
    int retryCount = 0;
    do {
        LOGGER.info("Waiting for host status {} in hostgroup {} ...", desiredStatus, hostGroup);
        sleep();
        StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
        Set<HostGroupResponse> hostGroupResponse = stackResponse.getCluster().getHostGroups();
        for (HostGroupResponse hr : hostGroupResponse) {
            if (hr.getName().equals(hostGroup)) {
                Set<HostMetadataResponse> hostMetadataResponses = hr.getMetadata();
                for (HostMetadataResponse hmr : hostMetadataResponses) {
                    if (hmr.getState().equals(desiredStatus)) {
                        found = Boolean.TRUE;
                    }
                }
            }
        }
        retryCount++;
    } while (!found && (retryCount < MAX_RETRY));
    if (retryCount == MAX_RETRY) {
        waitResult = WaitResult.TIMEOUT;
    }
    return waitResult;
}
Also used : HostMetadataResponse(com.sequenceiq.cloudbreak.api.model.HostMetadataResponse) HostGroupResponse(com.sequenceiq.cloudbreak.api.model.HostGroupResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) 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