Search in sources :

Example 26 with TestFailException

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

the class SshJClientActions method checkAzureTemporalDisksMounted.

public void checkAzureTemporalDisksMounted(List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames, String mountDir) {
    Map<String, Pair<Integer, String>> deviceMountPointMappingsByIp = getDeviceMountPointMappingsByIp(instanceGroups, hostGroupNames, mountDir);
    deviceMountPointMappingsByIp.forEach((ip, outPair) -> {
        if (StringUtils.isBlank(outPair.getValue()) || outPair.getKey() != 0) {
            LOGGER.error("No mount point found '{}' on node with IP {}!", mountDir, ip);
            throw new TestFailException(format("No mount point found '%s' on node with IP %s!", mountDir, ip));
        } else if (!StringUtils.containsIgnoreCase(outPair.getValue(), mountDir)) {
            LOGGER.error("Device incorrectly mounted to '{}' on node with IP {}!", mountDir, ip);
            throw new TestFailException(format("Device incorrectly mounted to '%s' on node with IP %s!", mountDir, ip));
        }
    });
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Pair(org.apache.commons.lang3.tuple.Pair)

Example 27 with TestFailException

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

the class SshJClientActions method checkAwsEphemeralDisksMounted.

public void checkAwsEphemeralDisksMounted(List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames, String mountDirPrefix) {
    Map<String, Pair<Integer, String>> deviceMountPointMappingsByIp = getDeviceMountPointMappingsByIp(instanceGroups, hostGroupNames, "hadoopfs");
    Map<String, Pair<Integer, String>> deviceDiskTypeMappingsByIp = getDeviceDiskTypeMappingsByIp(instanceGroups, hostGroupNames);
    for (Entry<String, Pair<Integer, String>> node : deviceDiskTypeMappingsByIp.entrySet()) {
        Map<String, String> ephemeralDisks = new Json(node.getValue().getValue()).getMap().entrySet().stream().filter(e -> String.valueOf(e.getValue()).contains("Amazon EC2 NVMe Instance Storage")).collect(Collectors.toMap(Entry::getKey, x -> String.valueOf(x.getValue())));
        if (ephemeralDisks.isEmpty()) {
            LOGGER.error("Instance store volume missing from node with IP {}!", node.getKey());
            throw new TestFailException(format("Instance store volume missing from node with IP %s!", node.getKey()));
        }
        if (deviceMountPointMappingsByIp.get(node.getKey()) == null) {
            LOGGER.error("No device mount point mappings found for node with IP {}!", node.getKey());
            throw new TestFailException(format("No device mount point mappings found for node with IP %s!", node.getKey()));
        }
        Map<String, String> mountPoints = new Json(deviceMountPointMappingsByIp.get(node.getKey()).getValue()).getMap().entrySet().stream().collect(Collectors.toMap(Entry::getKey, x -> String.valueOf(x.getValue())));
        for (String device : ephemeralDisks.keySet()) {
            String mountPoint = mountPoints.get(device);
            if (mountPoint == null) {
                LOGGER.error("No mount point found for ephemeral device {} on node with IP {}!", device, node.getKey());
                throw new TestFailException(format("No mount point found for device %s on node with IP %s!", device, node.getKey()));
            } else if (!mountPoint.contains(mountDirPrefix)) {
                LOGGER.error("Ephemeral device {} incorrectly mounted to {} on node with IP {}!", device, mountPoint, node.getKey());
                throw new TestFailException(format("Ephemeral device %s incorrectly mounted to %s on node with IP %s!", device, mountPoint, node.getKey()));
            }
        }
    }
}
Also used : FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) SshJClient(com.sequenceiq.it.cloudbreak.util.ssh.client.SshJClient) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Logger(org.slf4j.Logger) Collection(java.util.Collection) Log(com.sequenceiq.it.cloudbreak.log.Log) Set(java.util.Set) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) AbstractSdxTestDto(com.sequenceiq.it.cloudbreak.dto.AbstractSdxTestDto) SSHClient(net.schmizz.sshj.SSHClient) Entry(java.util.Map.Entry) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Json(com.sequenceiq.cloudbreak.common.json.Json) Pair(org.apache.commons.lang3.tuple.Pair)

Example 28 with TestFailException

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

the class SshJClient method createSshClient.

protected SSHClient createSshClient(String host, String user, String password, String privateKeyFilePath) throws IOException {
    SSHClient client = new SSHClient();
    client.addHostKeyVerifier(new PromiscuousVerifier());
    client.connect(host, 22);
    client.setConnectTimeout(120000);
    if (StringUtils.isBlank(user) && StringUtils.isBlank(privateKeyFilePath)) {
        LOGGER.info("Creating SSH client on '{}' host with 'cloudbreak' user and defaultPrivateKeyFile from application.yml.", host);
        client.authPublickey("cloudbreak", defaultPrivateKeyFilePath);
        Log.log(LOGGER, format(" SSH client has been authenticated with 'cloudbreak' user and key file: [%s] at [%s] host. ", client.isAuthenticated(), client.getRemoteHostname()));
    } else if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(privateKeyFilePath)) {
        LOGGER.info("Creating SSH client on '{}' host with user: '{}' and key file: '{}'.", host, user, privateKeyFilePath);
        client.authPublickey(user, privateKeyFilePath);
        Log.log(LOGGER, format(" SSH client has been authenticated with user (%s) and key file: [%s] at [%s] host. ", user, client.isAuthenticated(), client.getRemoteHostname()));
    } else if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password)) {
        LOGGER.info("Creating SSH client on '{}' host with user: '{}' and password: '{}'.", host, user, password);
        client.authPassword(user, password);
        Log.log(LOGGER, format(" SSH client has been authenticated with user (%s) and password: [%s] at [%s] host. ", user, client.isAuthenticated(), client.getRemoteHostname()));
    } else {
        LOGGER.error("Creating SSH client is not possible, because of host: '{}', user: '{}', password: '{}' and privateKey: '{}' are missing!", host, user, password, privateKeyFilePath);
        throw new TestFailException(String.format("Creating SSH client is not possible, because of host: '%s', user: '%s', password: '%s'" + " and privateKey: '%s' are missing!", host, user, password, privateKeyFilePath));
    }
    return client;
}
Also used : PromiscuousVerifier(net.schmizz.sshj.transport.verification.PromiscuousVerifier) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) SSHClient(net.schmizz.sshj.SSHClient)

Example 29 with TestFailException

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

the class SshJClient method executeCommand.

protected Pair<Integer, String> executeCommand(String instanceIP, String command) {
    try (SSHClient sshClient = createSshClient(instanceIP, null, null, null)) {
        Pair<Integer, String> cmdOut = execute(sshClient, command);
        Log.log(LOGGER, format("Command exit status [%s] and result [%s].", cmdOut.getKey(), cmdOut.getValue()));
        return cmdOut;
    } catch (Exception e) {
        LOGGER.error("SSH fail on [{}] while executing command [{}]. {}", instanceIP, command, e.getMessage());
        throw new TestFailException(" SSH fail on [" + instanceIP + "] while executing command [" + command + "].", e);
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) SSHClient(net.schmizz.sshj.SSHClient) ConnectionException(net.schmizz.sshj.connection.ConnectionException) TransportException(net.schmizz.sshj.transport.TransportException) IOException(java.io.IOException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 30 with TestFailException

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

the class ClouderaManagerClientActions method checkCmKnoxIDBrokerRoleConfigGroups.

public SdxInternalTestDto checkCmKnoxIDBrokerRoleConfigGroups(SdxInternalTestDto testDto, String user, String password) {
    String serverFqdn = testDto.getResponse().getStackV4Response().getCluster().getServerFqdn();
    ApiClient apiClient = getCmApiClient(serverFqdn, testDto.getName(), V_43, user, password);
    // CHECKSTYLE:OFF
    RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = new RoleConfigGroupsResourceApi(apiClient);
    // CHECKSTYLE:ON
    try {
        ApiConfigList knoxConfigs = roleConfigGroupsResourceApi.readConfig(testDto.getName(), "knox-IDBROKER-BASE", "knox", "full");
        knoxConfigs.getItems().stream().forEach(knoxConfig -> {
            String knoxConfigName = knoxConfig.getName();
            String mappingsFromKnoxConfig = knoxConfig.getValue();
            if (String.join("_", "idbroker", cloudProvider, "group", "mapping").equalsIgnoreCase(knoxConfigName)) {
                if (!mappingsFromKnoxConfig.contains("_c_cm_admins_")) {
                    LOGGER.error("{} does not contains the expected 'CM Admins' mapping!", knoxConfigName);
                    throw new TestFailException(String.format("%s does not contains the expected 'CM Admins' mapping!", knoxConfigName));
                } else {
                    Log.log(LOGGER, format(" '%s' contains the expected '%s' mapping. ", knoxConfigName, mappingsFromKnoxConfig));
                }
            } else if (String.join("_", "idbroker", cloudProvider, "user", "mapping").equalsIgnoreCase(knoxConfigName)) {
                if (!mappingsFromKnoxConfig.contains("hive")) {
                    LOGGER.error("{} does not contains the expected 'Hive' mapping!", knoxConfigName);
                    throw new TestFailException(String.format("%s does not contains the expected 'Hive' mapping!", knoxConfigName));
                } else {
                    Log.log(LOGGER, format(" '%s' contains the expected ['%s'] mappings. ", knoxConfigName, mappingsFromKnoxConfig));
                }
            }
        });
        if (knoxConfigs.getItems().isEmpty()) {
            LOGGER.error("IDBroker mappings are NOT exist!");
            throw new TestFailException("IDBroker 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 get users' list at: '{}'!", apiClient.getBasePath());
        throw new TestFailException("Can't get users' list 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)

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