use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.
the class CloudbreakUtil method waitForStatuses.
private static WaitResult waitForStatuses(CloudbreakClient cloudbreakClient, Long workspaceId, String stackName, Map<String, String> desiredStatuses, String accountId) {
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, stackName, currentStatuses);
sleep();
StackV4Endpoint stackV4Endpoint = cloudbreakClient.stackV4Endpoint();
try {
StackStatusV4Response statusResult = stackV4Endpoint.getStatusByName(workspaceId, stackName, accountId);
for (String statusPath : desiredStatuses.keySet()) {
currentStatuses.put(statusPath, statusResult.getStatus().name());
}
} 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(), stackName, 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;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status 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;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.
the class AwsSdxSpotInstanceTest method testSdxOnSpotInstances.
@Test(dataProvider = TEST_CONTEXT)
@Description(given = "there is a running cloudbreak ", when = "creating an SDX with 100% spot percentage ", then = "SDX is started on spot instances, or fails with insufficient spot capacity")
public void testSdxOnSpotInstances(TestContext testContext) {
String sdx = resourcePropertyProvider().getName();
SdxDatabaseRequest database = new SdxDatabaseRequest();
database.setCreate(false);
testContext.given(SdxTestDto.class).withCloudStorage().withExternalDatabase(database).withSpotPercentage(100).when(sdxTestClient.create(), key(sdx)).then((tc, testDto, client) -> {
testDto.await(STACK_CREATED, key(sdx));
Map<String, Exception> exceptionMap = testContext.getExceptionMap();
if (!exceptionMap.isEmpty()) {
String key = testDto.getAwaitExceptionKey(STACK_CREATED);
if (exceptionMap.containsKey(key)) {
LOGGER.info("Awaiting STACK_CREATED failed, clearing exception to check status reason", exceptionMap.get(key));
exceptionMap.remove(key);
}
}
return testDto;
}).when(sdxTestClient.describe()).then(assertSpotInstances()).validate();
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status in project cloudbreak by hortonworks.
the class MockStackResponseGenerator method getMockStackV4Response.
public static StackV4Response getMockStackV4Response(String clusterCrn, String hostGroup, String fqdnBase, int currentHostGroupCount, boolean withUnhealthyInstances) {
List<InstanceGroupV4Response> instanceGroupV4Responses = new ArrayList<>();
InstanceMetaDataV4Response master1 = new InstanceMetaDataV4Response();
master1.setDiscoveryFQDN("master1");
master1.setInstanceId("test_instanceid" + "master1");
instanceGroupV4Responses.add(instanceGroup("master", awsTemplate(), Set.of(master1)));
InstanceMetaDataV4Response worker1 = new InstanceMetaDataV4Response();
worker1.setDiscoveryFQDN("worker1");
worker1.setInstanceId("test_instanceid" + "worker1");
InstanceMetaDataV4Response worker2 = new InstanceMetaDataV4Response();
worker2.setDiscoveryFQDN("worker2");
worker2.setInstanceId("test_instanceid" + "worker2");
instanceGroupV4Responses.add(instanceGroup("worker", awsTemplate(), Set.of(worker1, worker2)));
Set fqdnToInstanceIds = new HashSet();
if (!withUnhealthyInstances) {
for (int i = 1; i <= currentHostGroupCount; i++) {
InstanceMetaDataV4Response metadata1 = new InstanceMetaDataV4Response();
metadata1.setDiscoveryFQDN(fqdnBase + i);
metadata1.setInstanceId("test_instanceid_" + hostGroup + i);
metadata1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
fqdnToInstanceIds.add(metadata1);
}
} else {
// Add nodes with InstanceStatuses STOPPED and SERVICES_UNHEALTHY
List<InstanceStatus> unhealthyStatuses = List.of(InstanceStatus.STOPPED, InstanceStatus.SERVICES_UNHEALTHY);
for (InstanceStatus status : unhealthyStatuses) {
InstanceMetaDataV4Response metadataResponse = new InstanceMetaDataV4Response();
metadataResponse.setDiscoveryFQDN(fqdnBase + unhealthyStatuses.indexOf(status));
metadataResponse.setInstanceId("test_instanceid_" + hostGroup + unhealthyStatuses.indexOf(status));
metadataResponse.setInstanceStatus(status);
fqdnToInstanceIds.add(metadataResponse);
}
// Add remaining healthy instances
for (int i = unhealthyStatuses.size(); i < currentHostGroupCount; ++i) {
InstanceMetaDataV4Response metadataResponse = new InstanceMetaDataV4Response();
metadataResponse.setDiscoveryFQDN(fqdnBase + i);
metadataResponse.setInstanceId("test_instanceid_" + hostGroup + i);
metadataResponse.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
fqdnToInstanceIds.add(metadataResponse);
}
}
instanceGroupV4Responses.add(instanceGroup(hostGroup, awsTemplate(), fqdnToInstanceIds));
StackV4Response mockReponse = new StackV4Response();
mockReponse.setCrn(clusterCrn);
mockReponse.setInstanceGroups(instanceGroupV4Responses);
mockReponse.setCloudPlatform(CloudPlatform.AWS);
return mockReponse;
}
Aggregations