Search in sources :

Example 1 with ActionTimeoutException

use of com.consol.citrus.exceptions.ActionTimeoutException in project yaks by citrusframework.

the class VerifyIntegrationAction method verifyIntegrationPod.

/**
 * Wait for given pod to be in given state.
 * @param name
 * @param phase
 * @param namespace
 * @return
 */
private Pod verifyIntegrationPod(String name, String phase, String namespace) {
    for (int i = 0; i < maxAttempts; i++) {
        Pod pod = getIntegrationPod(name, phase, namespace);
        if (pod != null) {
            LOG.info(String.format("Verified integration pod '%s' state '%s'!", name, phase));
            return pod;
        }
        LOG.warn(String.format("Waiting for integration '%s' in state '%s'- retry in %s ms", name, phase, delayBetweenAttempts));
        try {
            Thread.sleep(delayBetweenAttempts);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while waiting for integration pod state", e);
        }
    }
    throw new ActionTimeoutException((maxAttempts * delayBetweenAttempts), new CitrusRuntimeException(String.format("Failed to verify integration '%s' - " + "is not in state '%s' after %d attempts", name, phase, maxAttempts)));
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) ActionTimeoutException(com.consol.citrus.exceptions.ActionTimeoutException) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException)

Example 2 with ActionTimeoutException

use of com.consol.citrus.exceptions.ActionTimeoutException in project yaks by citrusframework.

the class VerifyCustomResourceAction method verifyResource.

/**
 * Wait for given pod to be in given state.
 * @param name
 * @param labelExpression
 * @param condition
 * @param context
 * @return
 */
private void verifyResource(String name, String labelExpression, String condition, TestContext context) {
    for (int i = 0; i < maxAttempts; i++) {
        GenericKubernetesResource resource;
        if (name != null && !name.isEmpty()) {
            resource = getResource(name, condition, context);
        } else {
            resource = getResourceFromLabel(labelExpression, condition, context);
        }
        if (resource != null) {
            LOG.info(String.format("Verified resource '%s' state '%s'!", getNameOrLabel(name, labelExpression), condition));
            return;
        }
        LOG.warn(String.format("Waiting for resource '%s' in state '%s' - retry in %s ms", getNameOrLabel(name, labelExpression), condition, delayBetweenAttempts));
        try {
            Thread.sleep(delayBetweenAttempts);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while waiting for resource condition", e);
        }
    }
    throw new ActionTimeoutException((maxAttempts * delayBetweenAttempts), new CitrusRuntimeException(String.format("Failed to verify resource '%s' - " + "is not in state '%s' after %d attempts", getNameOrLabel(name, labelExpression), condition, maxAttempts)));
}
Also used : ActionTimeoutException(com.consol.citrus.exceptions.ActionTimeoutException) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource)

Example 3 with ActionTimeoutException

use of com.consol.citrus.exceptions.ActionTimeoutException in project yaks by citrusframework.

the class VerifyIntegrationAction method verifyIntegrationLogs.

/**
 * Wait for integration pod to log given message.
 * @param pod
 * @param name
 * @param namespace
 * @param message
 */
private void verifyIntegrationLogs(Pod pod, String name, String namespace, String message) {
    for (int i = 0; i < maxAttempts; i++) {
        String log = getIntegrationPodLogs(pod, namespace);
        if (log.contains(message)) {
            LOG.info("Verified integration logs - All values OK!");
            return;
        }
        LOG.warn(String.format("Waiting for integration '%s' to log message - retry in %s ms", name, delayBetweenAttempts));
        try {
            Thread.sleep(delayBetweenAttempts);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while waiting for integration pod logs", e);
        }
    }
    throw new ActionTimeoutException((maxAttempts * delayBetweenAttempts), new CitrusRuntimeException(String.format("Failed to verify integration '%s' - " + "has not printed message '%s' after %d attempts", name, logMessage, maxAttempts)));
}
Also used : ActionTimeoutException(com.consol.citrus.exceptions.ActionTimeoutException) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException)

Example 4 with ActionTimeoutException

use of com.consol.citrus.exceptions.ActionTimeoutException in project yaks by citrusframework.

the class VerifyPodAction method verifyPodLogs.

/**
 * Wait for pod to log given message.
 * @param pod
 * @param nameOrLabel
 * @param namespace
 * @param message
 */
private void verifyPodLogs(Pod pod, String nameOrLabel, String namespace, String message) {
    for (int i = 0; i < maxAttempts; i++) {
        String log = getPodLogs(pod, namespace);
        if (log.contains(message)) {
            LOG.info("Verified pod logs - All values OK!");
            return;
        }
        LOG.warn(String.format("Waiting for pod '%s' to log message - retry in %s ms", nameOrLabel, delayBetweenAttempts));
        try {
            Thread.sleep(delayBetweenAttempts);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while waiting for pod logs", e);
        }
    }
    throw new ActionTimeoutException((maxAttempts * delayBetweenAttempts), new CitrusRuntimeException(String.format("Failed to verify pod '%s' - " + "has not printed message '%s' after %d attempts", nameOrLabel, logMessage, maxAttempts)));
}
Also used : ActionTimeoutException(com.consol.citrus.exceptions.ActionTimeoutException) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException)

Example 5 with ActionTimeoutException

use of com.consol.citrus.exceptions.ActionTimeoutException in project yaks by citrusframework.

the class VerifyPodAction method verifyPod.

/**
 * Wait for given pod to be in given state.
 * @param name
 * @param labelExpression         1
 * @param phase
 * @param namespace
 * @return
 */
private Pod verifyPod(String name, String labelExpression, String phase, String namespace) {
    for (int i = 0; i < maxAttempts; i++) {
        Pod pod;
        if (name != null && !name.isEmpty()) {
            pod = getPod(name, phase, namespace);
        } else {
            pod = getPodFromLabel(labelExpression, phase, namespace);
        }
        if (pod != null) {
            LOG.info(String.format("Verified pod '%s' state '%s'!", getNameOrLabel(name, labelExpression), phase));
            return pod;
        }
        LOG.warn(String.format("Waiting for pod '%s' in state '%s' - retry in %s ms", getNameOrLabel(name, labelExpression), phase, delayBetweenAttempts));
        try {
            Thread.sleep(delayBetweenAttempts);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while waiting for pod state", e);
        }
    }
    throw new ActionTimeoutException((maxAttempts * delayBetweenAttempts), new CitrusRuntimeException(String.format("Failed to verify pod '%s' - " + "is not in state '%s' after %d attempts", getNameOrLabel(name, labelExpression), phase, maxAttempts)));
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) ActionTimeoutException(com.consol.citrus.exceptions.ActionTimeoutException) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException)

Aggregations

ActionTimeoutException (com.consol.citrus.exceptions.ActionTimeoutException)5 CitrusRuntimeException (com.consol.citrus.exceptions.CitrusRuntimeException)5 Pod (io.fabric8.kubernetes.api.model.Pod)2 GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)1