Search in sources :

Example 66 with TestFailException

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

the class CloudbreakInstanceWaitObject method fetchData.

@Override
public void fetchData() {
    try {
        instanceGroups = testContext.getMicroserviceClient(CloudbreakClient.class).getDefaultClient().distroXV1Endpoint().getByName(name, Set.of()).getInstanceGroups();
        instanceResourceType = "Data Hub";
    } catch (NotFoundException e) {
        LOGGER.info("SDX '{}' instance groups are present for validation.", name);
        instanceGroups = testContext.getSdxClient().getDefaultClient().sdxEndpoint().getDetail(name, Set.of()).getStackV4Response().getInstanceGroups();
    } catch (Exception e) {
        LOGGER.error("Instance groups cannot be determined, because of: {}", e.getMessage(), e);
        throw new TestFailException("Instance groups cannot be determined", e);
    }
}
Also used : CloudbreakClient(com.sequenceiq.it.cloudbreak.CloudbreakClient) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) NotFoundException(javax.ws.rs.NotFoundException) NotFoundException(javax.ws.rs.NotFoundException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 67 with TestFailException

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

the class SshEnaDriverCheckActions method getInstanceMetadata.

private InstanceMetaDataV4Response getInstanceMetadata(String name, CloudbreakClient cloudbreakClient, String group) {
    InstanceMetaDataV4Response instanceMetaDataResponse = cloudbreakClient.getDefaultClient().distroXV1Endpoint().getByName(name, Collections.emptySet()).getInstanceGroups().stream().filter(ig -> group.equals(ig.getName())).findFirst().orElseThrow(() -> new TestFailException("Cannot find " + group + " for " + name)).getMetadata().stream().findFirst().orElseThrow(() -> new TestFailException("Cannot find metadata in " + group + " for " + name));
    LOGGER.info("The selected Instance Group [{}] and the available Private IP [{}] and Public IP [{}]]", group, instanceMetaDataResponse.getPrivateIp(), instanceMetaDataResponse.getPublicIp());
    return instanceMetaDataResponse;
}
Also used : InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 68 with TestFailException

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

the class SshJClientActions method checkMeteringStatus.

public DistroXTestDto checkMeteringStatus(DistroXTestDto testDto, List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames) {
    String meteringStatusCommand = "sudo cdp-doctor metering status --format json";
    Map<String, Pair<Integer, String>> meteringStatusReportByIp = getInstanceGroupIps(instanceGroups, hostGroupNames, false).stream().collect(Collectors.toMap(ip -> ip, ip -> executeSshCommand(ip, meteringStatusCommand)));
    for (Entry<String, Pair<Integer, String>> meteringStatusReport : meteringStatusReportByIp.entrySet()) {
        List<Integer> heartbeatEventCounts = new Json(meteringStatusReport.getValue().getValue()).getMap().entrySet().stream().filter(status -> String.valueOf(status.getKey()).contains("heartbeatEventCount")).map(Entry::getValue).collect(Collectors.toList()).stream().map(countObject -> (Integer) countObject).collect(Collectors.toList());
        LOGGER.info(format("heartbeatEventCounts: %s", heartbeatEventCounts));
        Log.log(LOGGER, format(" Found '%s' Metering Heartbeat Events at '%s' instance. ", heartbeatEventCounts, meteringStatusReport.getKey()));
        if (CollectionUtils.isEmpty(heartbeatEventCounts) || heartbeatEventCounts.contains(0)) {
            LOGGER.error("Metering Heartbeat Events does NOT generated on '{}' instance!", meteringStatusReport.getKey());
            throw new TestFailException(format("Metering Heartbeat Events does NOT generated on '%s' instance!", meteringStatusReport.getKey()));
        }
    }
    for (Entry<String, Pair<Integer, String>> meteringStatusReport : meteringStatusReportByIp.entrySet()) {
        List<String> heartbeatStatusesNotOk = new Json(meteringStatusReport.getValue().getValue()).getMap().entrySet().stream().filter(status -> String.valueOf(status.getValue()).contains("NOK")).map(Entry::getKey).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(heartbeatStatusesNotOk)) {
            heartbeatStatusesNotOk.forEach(event -> {
                if (StringUtils.containsIgnoreCase(event, "databusReachable")) {
                    Log.log(LOGGER, format(" Found 'databusReachable' status is not OK at '%s' instance. However this is acceptable!", meteringStatusReport.getKey()));
                    LOGGER.warn("Found 'databusReachable' status is not OK at '{}' instance. However this is acceptable!", meteringStatusReport.getKey());
                } else {
                    Log.log(LOGGER, format(" Found '%s' not OK at '%s' instance. ", event, meteringStatusReport.getKey()));
                    LOGGER.error("There is 'Not OK' Metering Heartbeat status {} is present on '{}' instance!", event, meteringStatusReport.getKey());
                    throw new TestFailException(format("There is 'Not OK' Metering Heartbeat status %s is present on '%s' instance!", event, meteringStatusReport.getKey()));
                }
            });
        }
    }
    return testDto;
}
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) 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 69 with TestFailException

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

the class SshJClientActions method executeSshCommand.

private Pair<Integer, String> executeSshCommand(String instanceIp, String user, String password, String privateKeyFilePath, String command) {
    try (SSHClient sshClient = createSshClient(instanceIp, user, password, privateKeyFilePath)) {
        Pair<Integer, String> cmdOut = execute(sshClient, command);
        Log.log(LOGGER, " 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);
        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) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 70 with TestFailException

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

the class SshJClientActions method executefileListCommand.

private long executefileListCommand(String instanceIP, String user, String password, String fileListCommand) {
    AtomicLong quantity = new AtomicLong(0);
    try {
        Pair<Integer, String> cmdOut = executeSshCommand(instanceIP, user, password, fileListCommand);
        Log.log(LOGGER, " Command exit status '%s' and result '%s'. ", cmdOut.getKey(), cmdOut.getValue());
        List<String> cmdOutputValues = Stream.of(cmdOut.getValue().split("[\\r\\n\\t]")).filter(Objects::nonNull).collect(Collectors.toList());
        boolean fileFound = cmdOutputValues.stream().anyMatch(outputValue -> outputValue.strip().startsWith("/"));
        String foundFilePath = cmdOutputValues.stream().filter(outputValue -> outputValue.strip().startsWith("/")).findFirst().orElse(null);
        Log.log(LOGGER, format(" The file is present '%s' at '%s' path. ", fileFound, foundFilePath));
        quantity.set(cmdOutputValues.stream().filter(outputValue -> outputValue.strip().startsWith("/")).count());
    } catch (Exception e) {
        LOGGER.error("SSH fail on '{}' host while running command: [{}]", instanceIP, fileListCommand);
        throw new TestFailException(format(" SSH fail on '%s' host while running command: [%s]! ", instanceIP, fileListCommand), e);
    }
    return quantity.get();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

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