use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class DistroXTestDtoBase method withPreferredSubnetsForInstanceNetworkIfMultiAzEnabledOrJustFirst.
public DistroXTestDtoBase<T> withPreferredSubnetsForInstanceNetworkIfMultiAzEnabledOrJustFirst() {
if (StringUtils.isEmpty(getRequest().getEnvironmentName())) {
throw new TestFailException("Cannot fetch the preferred subnet without env name, please add it");
}
try {
EnvironmentClient envClient = getTestContext().getMicroserviceClient(EnvironmentClient.class);
DetailedEnvironmentResponse envResponse = envClient.getDefaultClient().environmentV1Endpoint().getByName(getRequest().getEnvironmentName());
InstanceGroupNetworkV1Request instanceGroupNetworkV1Request = new InstanceGroupNetworkV1Request();
InstanceGroupAwsNetworkV1Parameters awsNetworkV1Parameters = new InstanceGroupAwsNetworkV1Parameters();
if ("AWS_NATIVE".equals(getRequest().getVariant())) {
awsNetworkV1Parameters.setSubnetIds(new ArrayList<>(envResponse.getNetwork().getPreferedSubnetIds()));
} else {
envResponse.getNetwork().getPreferedSubnetIds().stream().filter(s -> !s.equals(envResponse.getNetwork().getPreferedSubnetId())).findFirst().ifPresent(s -> awsNetworkV1Parameters.setSubnetIds(List.of(s)));
}
instanceGroupNetworkV1Request.setAws(awsNetworkV1Parameters);
getRequest().getInstanceGroups().forEach(s -> s.setNetwork(instanceGroupNetworkV1Request));
} catch (Exception e) {
String message = "Cannot fetch preferred subnets from " + getRequest().getEnvironmentName();
throw new TestFailException(message, e);
}
return this;
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class DefaultResponseConfigure method thenReturn.
public T thenReturn(R retValue, String message, int statusCode, int times, String clss) {
if (!parameters.isEmpty()) {
throw new TestFailException("Mock thenReturn will not take into account url parameters.");
}
String crn = testDto.getCrn();
if (crn != null) {
pathVariable("mockUuid", crn);
}
String retType = clss;
if (retType == null && retValue != null) {
retType = retValue.getClass().getName();
}
MockResponse body = new MockResponse(retValue, message, getMethod().getHttpMethod().name(), getPath(), times, statusCode, retType);
executeQuery.executeConfigure(pathVariables(), body);
return testDto;
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class DefaultResponseConfigure method verify.
public T verify() {
String callsJson;
if (crnless) {
callsJson = executeQuery.execute("/tests/calls", w -> w.queryParam("path", pathReplaced(path)), r -> r.readEntity(String.class));
} else {
callsJson = executeQuery.execute("/tests/calls/" + testDto.getCrn(), w -> w.queryParam("path", pathReplaced(path)), r -> r.readEntity(String.class));
}
Call[] calls;
try {
calls = new ObjectMapper().readValue(callsJson, Call[].class);
} catch (JsonProcessingException e) {
throw new TestFailException("Cannot deserialize calls: " + e.getMessage(), e);
}
if (calls == null) {
calls = new Call[0];
}
List<Call> collect = Arrays.stream(calls).filter(this::isPathMatched).filter(call -> call.getMethod().equalsIgnoreCase(method.toString())).filter(call -> parameterCheck(call.getParameters())).collect(Collectors.toList());
VerificationContext verificationContext = new VerificationContext(collect);
verifications.forEach(v -> {
v.handle(path, method, verificationContext);
});
List<String> errors = verificationContext.getErrors();
if (!errors.isEmpty()) {
throw new TestFailException("URL verification failed: " + System.lineSeparator() + String.join(System.lineSeparator(), errors));
}
return testDto;
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class DistroxStopStartScaleDurationAssertions method doAssertion.
@Override
public DistroXTestDto doAssertion(TestContext testContext, DistroXTestDto testDto, CloudbreakClient client) throws Exception {
String startMessage = scalingUp ? "Scaling up (via instance start) for host group" : "Scaling down (via instance stop) for host group";
String stopMessage = scalingUp ? "Scaled up (via instance start) host group" : "Scaled down (via instance stop) host group";
StructuredEventContainer structuredEventContainer = client.getDefaultClient().eventV4Endpoint().structured(testDto.getName(), testContext.getActingUserCrn().getAccountId());
List<StructuredNotificationEvent> structuredNotificationEvents = structuredEventContainer.getNotification();
long startTime = getTimestampForEvent(structuredNotificationEvents, startMessage);
long endTime = getTimestampForEvent(structuredNotificationEvents, stopMessage);
long actualDuration = endTime - startTime;
LOGGER.info(String.format("[%s] event duration '%s' minutes.", startMessage, TimeUnit.MILLISECONDS.toMinutes(actualDuration)));
String message = String.format("Distrox last scale have been took (%d) more than the expected %d minutes!", TimeUnit.MILLISECONDS.toMinutes(actualDuration), expectedDuration);
if (actualDuration > TimeUnit.MINUTES.toMillis(expectedDuration)) {
LOGGER.error(message);
throw new TestFailException(message);
}
return testDto;
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class DistroxStopStartScaleDurationAssertions method getTimestampForEvent.
private long getTimestampForEvent(List<StructuredNotificationEvent> structuredNotificationEvents, String message) {
OperationDetails latestEvent = structuredNotificationEvents.stream().filter(events -> StringUtils.containsIgnoreCase(events.getNotificationDetails().getNotification(), message)).map(StructuredEvent::getOperation).max(Comparator.comparing(OperationDetails::getTimestamp)).orElseThrow(() -> new TestFailException(String.format("Cannot find Structured Event for '%s' message!", message)));
long latestEventTimestamp = latestEvent.getTimestamp();
LOGGER.info(String.format("[%s] event time '%s'.", message, LocalDateTime.ofInstant(Instant.ofEpochMilli(latestEventTimestamp), ZoneId.systemDefault())));
return latestEventTimestamp;
}
Aggregations