Search in sources :

Example 1 with CloudbreakInstanceWaitObject

use of com.sequenceiq.it.cloudbreak.util.wait.service.instance.cloudbreak.CloudbreakInstanceWaitObject in project cloudbreak by hortonworks.

the class InstanceAwait method await.

public <E extends Enum<E>> CloudbreakTestDto await(CloudbreakTestDto entity, Map<List<String>, E> desiredStatuses, TestContext testContext, RunningParameter runningParameter, Duration pollingInterval, int maxRetry) {
    if (entity == null) {
        throw new RuntimeException("Cloudbreak key has been provided but no result in resource map!");
    }
    try {
        Log.await(LOGGER, String.format("%s for %s", entity.getName(), desiredStatuses));
        MicroserviceClient client = testContext.getMicroserviceClient(entity.getClass(), testContext.setActingUser(runningParameter).getAccessKey());
        desiredStatuses.forEach((instanceIds, instanceStatus) -> {
            InstanceWaitObject instanceWaitObject = client.waitInstancesObject(entity, testContext, instanceIds, instanceStatus);
            if (instanceWaitObject.isDeletionCheck()) {
                client.<CloudbreakInstanceWaitObject>waiterService().waitObject(new InstanceTerminationChecker<>(), instanceWaitObject, testContext, pollingInterval, maxRetry, 1);
            } else if (instanceWaitObject.isFailedCheck()) {
                client.<CloudbreakInstanceWaitObject>waiterService().waitObject(new InstanceFailedChecker<>(), instanceWaitObject, testContext, pollingInterval, maxRetry, 1);
            } else {
                if (runningParameter != null && runningParameter.getTimeoutChecker() != null) {
                    client.<CloudbreakInstanceWaitObject>waiterService().waitObject(new InstanceOperationChecker<>(), instanceWaitObject, testContext, pollingInterval, runningParameter.getTimeoutChecker(), maxRetry);
                } else {
                    client.<CloudbreakInstanceWaitObject>waiterService().waitObject(new InstanceOperationChecker<>(), instanceWaitObject, testContext, pollingInterval, maxRetry, 1);
                }
            }
        });
    } catch (Exception e) {
        if (runningParameter.isLogError()) {
            LOGGER.error("await [{}] is failed for statuses {}: {}, name: {}", entity, desiredStatuses, ResponseUtil.getErrorMessage(e), entity.getName());
            Log.await(null, String.format("[%s] is failed for statuses %s: %s, name: %s", entity, desiredStatuses, ResponseUtil.getErrorMessage(e), entity.getName()));
        }
        testContext.getExceptionMap().put("await " + entity + " for desired statuses " + desiredStatuses, e);
    }
    return entity;
}
Also used : MicroserviceClient(com.sequenceiq.it.cloudbreak.MicroserviceClient) CloudbreakInstanceWaitObject(com.sequenceiq.it.cloudbreak.util.wait.service.instance.cloudbreak.CloudbreakInstanceWaitObject) CloudbreakInstanceWaitObject(com.sequenceiq.it.cloudbreak.util.wait.service.instance.cloudbreak.CloudbreakInstanceWaitObject)

Aggregations

MicroserviceClient (com.sequenceiq.it.cloudbreak.MicroserviceClient)1 CloudbreakInstanceWaitObject (com.sequenceiq.it.cloudbreak.util.wait.service.instance.cloudbreak.CloudbreakInstanceWaitObject)1