Search in sources :

Example 51 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class ClouderaManagerClientActions method checkCmServicesStartedSuccessfully.

public DistroXTestDto checkCmServicesStartedSuccessfully(DistroXTestDto testDto, String user, String password) {
    String serverIp = testDto.getResponse().getCluster().getServerIp();
    ApiClient apiClient = getCmApiClientWithTimeoutDisabledDirect(serverIp, testDto.getName(), V_43, user, password);
    // CHECKSTYLE:OFF
    HostsResourceApi hostsResourceApi = new HostsResourceApi(apiClient);
    // CHECKSTYLE:ON
    try {
        Set<String> masterHostnames = testDto.getResponse().getInstanceGroups().stream().filter(ig -> "master".equals(ig.getName())).flatMap(ig -> ig.getMetadata().stream()).map(InstanceMetaDataV4Response::getDiscoveryFQDN).collect(Collectors.toSet());
        List<ApiHost> apiHosts = hostsResourceApi.readHosts(null, null, "FULL_WITH_HEALTH_CHECK_EXPLANATION").getItems();
        Set<String> servicesNotStarted = apiHosts.stream().filter(apiHost -> masterHostnames.contains(apiHost.getHostname())).flatMap(apiHost -> collectNotStartedServicesOnHost(apiHost).stream()).filter(serviceName -> REQUIRED_SERVICES.contains(serviceName)).collect(Collectors.toSet());
        if (!servicesNotStarted.isEmpty()) {
            LOGGER.error("There are not started required services: {}", servicesNotStarted);
            throw new TestFailException(String.format("There are not started required services: %s", servicesNotStarted));
        }
    } catch (ApiException e) {
        LOGGER.error("Exception when calling HostsResourceApi#readHosts. Response: {}", e.getResponseBody(), e);
        String message = format("Exception when calling HostsResourceApi#readHosts at %s. Response: %s", apiClient.getBasePath(), e.getResponseBody());
        throw new TestFailException(message, e);
    } catch (Exception e) {
        LOGGER.error("Can't read host statuses at: '{}'!", apiClient.getBasePath());
        throw new TestFailException("Can't read host statuses at: " + apiClient.getBasePath(), e);
    }
    return testDto;
}
Also used : Logger(org.slf4j.Logger) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) Log(com.sequenceiq.it.cloudbreak.log.Log) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ApiException(com.cloudera.api.swagger.client.ApiException) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Value(org.springframework.beans.factory.annotation.Value) RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) List(java.util.List) Component(org.springframework.stereotype.Component) ClouderaManagerClient(com.sequenceiq.it.cloudbreak.util.clouderamanager.client.ClouderaManagerClient) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiHost(com.cloudera.api.swagger.model.ApiHost) ListUtils.emptyIfNull(org.apache.commons.collections4.ListUtils.emptyIfNull) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiException(com.cloudera.api.swagger.client.ApiException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiHost(com.cloudera.api.swagger.model.ApiHost) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 52 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class ClouderaManagerClientActions method checkCmHdfsDatanodeRoleConfigGroups.

public DistroXTestDto checkCmHdfsDatanodeRoleConfigGroups(DistroXTestDto testDto, String user, String password, Set<String> mountPoints) {
    String serverIp = testDto.getResponse().getCluster().getServerIp();
    ApiClient apiClient = getCmApiClientWithTimeoutDisabled(serverIp, testDto.getName(), V_43, user, password);
    // CHECKSTYLE:OFF
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = new RoleConfigGroupsResourceApi(apiClient);
    // CHECKSTYLE:ON
    try {
        ApiConfigList hdfsConfigs = roleConfigGroupsResourceApi.readConfig(testDto.getName(), "hdfs-DATANODE-BASE", "hdfs", "summary");
        hdfsConfigs.getItems().forEach(config -> {
            String hdfsConfigName = config.getName();
            String mappingsFromHdfsConfig = config.getValue();
            if ("dfs_data_dir_list".equalsIgnoreCase(hdfsConfigName)) {
                if (mountPoints.stream().anyMatch(mappingsFromHdfsConfig::startsWith)) {
                    LOGGER.error("{} contains ephemeral volume mapping '{}'!", hdfsConfigName, mappingsFromHdfsConfig);
                    throw new TestFailException(String.format("%s contains ephemeral volume mapping '%s'!", hdfsConfigName, mappingsFromHdfsConfig));
                } else {
                    Log.log(LOGGER, format(" '%s' does not contain the ephemeral mapping '%s', as expected. ", hdfsConfigName, mappingsFromHdfsConfig));
                }
            }
        });
        if (hdfsConfigs.getItems().isEmpty()) {
            LOGGER.error("Datanode mappings are NOT exist!");
            throw new TestFailException("Datanode mappings are NOT exist!");
        }
    } catch (ApiException e) {
        LOGGER.error("Exception when calling RoleConfigGroupsResourceApi#readConfig. Response: {}", e.getResponseBody(), e);
        String message = format("Exception when calling RoleConfigGroupsResourceApi#readConfig at %s. Response: %s", apiClient.getBasePath(), e.getResponseBody());
        throw new TestFailException(message, e);
    } catch (Exception e) {
        LOGGER.error("Can't read config at: '{}'!", apiClient.getBasePath());
        throw new TestFailException("Can't read config at: " + apiClient.getBasePath(), e);
    }
    return testDto;
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiException(com.cloudera.api.swagger.client.ApiException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 53 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class GcpClientActions method deleteHostGroupInstances.

public void deleteHostGroupInstances(List<String> instanceIds) {
    LOGGER.info("Deleting instances: '{}'", String.join(", ", instanceIds));
    Compute compute = buildCompute();
    for (String instanceId : instanceIds) {
        try {
            Operation deleteOperationResponse = compute.instances().delete(getProjectId(), gcpProperties.getAvailabilityZone(), instanceId).execute();
            Log.log(LOGGER, format(" Gcp instance [%s] state is [%s] with message: %s", instanceId, deleteOperationResponse.getStatus(), deleteOperationResponse.getStatusMessage()));
            try {
                waitForComplete(compute, deleteOperationResponse, getProjectId(), TIMEOUT);
            } catch (Exception e) {
                String defaultErrorMessageForInstanceDeletion = getDefaultErrorMessageForInstanceDeletion(instanceId, deleteOperationResponse);
                LOGGER.error(defaultErrorMessageForInstanceDeletion, e);
                throw new TestFailException(defaultErrorMessageForInstanceDeletion, e);
            }
            if (deleteOperationResponse.getStatus().equals("DONE")) {
                Log.log(LOGGER, format(" Gcp Instance: %s state is DELETED ", instanceId));
            } else {
                String defaultErrorMessageForInstanceDeletion = getDefaultErrorMessageForInstanceDeletion(instanceId, deleteOperationResponse);
                LOGGER.error(defaultErrorMessageForInstanceDeletion);
                throw new TestFailException(defaultErrorMessageForInstanceDeletion);
            }
        } catch (GoogleJsonResponseException e) {
            if (!e.getMessage().contains("Not Found")) {
                handleGeneralInstanceDeletionError(instanceId, e);
            } else {
                LOGGER.info(String.format("Gcp instance [%s] is not found, thus it is deleted.", instanceId));
            }
        } catch (IOException e) {
            handleGeneralInstanceDeletionError(instanceId, e);
        }
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Compute(com.google.api.services.compute.Compute) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Operation(com.google.api.services.compute.model.Operation) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) IOException(java.io.IOException)

Example 54 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class GcpClientActions method stopHostGroupInstances.

public void stopHostGroupInstances(List<String> instanceIds) {
    LOGGER.info("Stopping instances: '{}'", String.join(", ", instanceIds));
    Compute compute = buildCompute();
    for (String instanceId : instanceIds) {
        try {
            Operation stopInstanceResponse = compute.instances().stop(getProjectId(), gcpProperties.getAvailabilityZone(), instanceId).execute();
            Log.log(LOGGER, format(" Gcp instance [%s] state is [%s] with message: %s", instanceId, stopInstanceResponse.getStatus(), stopInstanceResponse.getStatusMessage()));
            waitForComplete(compute, stopInstanceResponse, getProjectId(), TIMEOUT);
            if (stopInstanceResponse.getStatus().equals("DONE")) {
                Log.log(LOGGER, format(" Gcp Instance: %s state is STOPPED ", instanceId));
            } else {
                LOGGER.error("Gcp Instance: {} stop has not been successful. So the actual state is: {} with message: {}", instanceId, stopInstanceResponse.getStatus(), stopInstanceResponse.getStatusMessage());
                throw new TestFailException(" Gcp Instance: " + instanceId + " stop has not been successful, because of the actual state is: " + stopInstanceResponse.getStatus() + " with message: " + stopInstanceResponse.getStatusMessage());
            }
        } catch (Exception e) {
            LOGGER.warn(String.format("Failed to get the details of the instance from Gcp with instance id: '%s'", instanceId), e);
        }
    }
}
Also used : Compute(com.google.api.services.compute.Compute) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Operation(com.google.api.services.compute.model.Operation) URISyntaxException(java.net.URISyntaxException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) IOException(java.io.IOException)

Example 55 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class GcpClientActions method deleteNonVersionedBucket.

public void deleteNonVersionedBucket(String baseLocation) {
    LOGGER.info("Delete bucket from base location: '{}'", baseLocation);
    Storage storage = buildStorage();
    try {
        Storage.Buckets.Delete operation = storage.buckets().delete(baseLocation);
        operation.execute();
    } catch (IOException ioException) {
        String msg = String.format("Failed to delete bucket from base location '%s'", baseLocation);
        LOGGER.error(msg, ioException);
        throw new TestFailException(msg, ioException);
    }
}
Also used : Storage(com.google.api.services.storage.Storage) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) IOException(java.io.IOException)

Aggregations

TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)101 List (java.util.List)15 Inject (javax.inject.Inject)14 Map (java.util.Map)13 Description (com.sequenceiq.it.cloudbreak.context.Description)12 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Test (org.testng.annotations.Test)12 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 Log (com.sequenceiq.it.cloudbreak.log.Log)9 String.format (java.lang.String.format)9 Collectors (java.util.stream.Collectors)9 FreeIpaTestDto (com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto)8 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)8 IOException (java.io.IOException)8 URISyntaxException (java.net.URISyntaxException)8 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8