Search in sources :

Example 1 with TestFrameworkException

use of io.pravega.test.system.framework.TestFrameworkException in project pravega by pravega.

the class BookkeeperService method start.

@Override
public void start(final boolean wait) {
    deleteApp("/pravega/bookkeeper");
    log.info("Starting Bookkeeper Service: {}", getID());
    try {
        marathonClient.createApp(createBookieApp());
        if (wait) {
            waitUntilServiceRunning().get(5, TimeUnit.MINUTES);
        }
    } catch (MarathonException e) {
        handleMarathonException(e);
    } catch (InterruptedException | ExecutionException | TimeoutException ex) {
        throw new TestFrameworkException(InternalError, "Exception while " + "starting Bookkeeper Service", ex);
    }
}
Also used : TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) MarathonException(mesosphere.marathon.client.MarathonException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with TestFrameworkException

use of io.pravega.test.system.framework.TestFrameworkException in project pravega by pravega.

the class MarathonBasedService method isRunning.

@Override
public boolean isRunning() {
    try {
        GetAppResponse app = marathonClient.getApp(this.id);
        log.debug("App Details: {}", app);
        // and the state of application is healthy.
        if ((app.getApp().getTasksRunning().intValue() == app.getApp().getInstances().intValue()) && app.getApp().getTasksRunning().intValue() == app.getApp().getTasksHealthy().intValue()) {
            log.info("App {} is running", this.id);
            return true;
        } else {
            log.info("App {} is not running", this.id);
            return false;
        }
    } catch (MarathonException ex) {
        if (ex.getStatus() == NOT_FOUND.getStatusCode()) {
            log.info("App is not running : {}", this.id);
            return false;
        }
        throw new TestFrameworkException(RequestFailed, "Marathon Exception while fetching service details", ex);
    }
}
Also used : GetAppResponse(mesosphere.marathon.client.model.v2.GetAppResponse) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) MarathonException(mesosphere.marathon.client.MarathonException)

Example 3 with TestFrameworkException

use of io.pravega.test.system.framework.TestFrameworkException in project pravega by pravega.

the class MarathonBasedService method deleteApp.

void deleteApp(final String appID) {
    try {
        Result result = marathonClient.deleteApp(appID);
        log.info("App: {} deleted, Deployment id is: {}", appID, result.getDeploymentId());
        waitUntilDeploymentPresent(result.getDeploymentId()).get();
    } catch (MarathonException e) {
        if (e.getStatus() == NOT_FOUND.getStatusCode()) {
            log.debug("Application does not exist");
        } else {
            throw new TestFrameworkException(RequestFailed, "Marathon Exception while deleting service", e);
        }
    } catch (InterruptedException | ExecutionException e) {
        throw new TestFrameworkException(InternalError, "Exception during deleteApp", e);
    }
}
Also used : TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) MarathonException(mesosphere.marathon.client.MarathonException) ExecutionException(java.util.concurrent.ExecutionException) Result(mesosphere.marathon.client.model.v2.Result)

Example 4 with TestFrameworkException

use of io.pravega.test.system.framework.TestFrameworkException in project pravega by pravega.

the class K8sClient method downloadLogs.

/**
 * Download logs of the specified pod.
 *
 * @param fromPod Pod logs to be copied.
 * @param toFile Destination file of the logs.
 * @return A Future which completes once the download operation completes.
 */
public CompletableFuture<Void> downloadLogs(final V1Pod fromPod, final String toFile) {
    final AtomicInteger retryCount = new AtomicInteger(0);
    return Retry.withExpBackoff(LOG_DOWNLOAD_INIT_DELAY_MS, 10, LOG_DOWNLOAD_RETRY_COUNT, RETRY_MAX_DELAY_MS).retryingOn(TestFrameworkException.class).throwingOn(RuntimeException.class).runInExecutor(() -> {
        final String podName = fromPod.getMetadata().getName();
        log.debug("Download logs from pod {}", podName);
        try {
            @Cleanup InputStream logStream = logUtility.streamNamespacedPodLog(fromPod);
            // On every retry this method attempts to download the complete pod logs from from K8s api-server. Due to the
            // amount of logs for a pod and the K8s cluster configuration it can so happen that the K8s api-server can
            // return truncated logs. Hence, every retry attempt does not overwrite the previously downloaded logs for
            // the pod.
            String logFile = toFile + "-" + retryCount.incrementAndGet() + ".log";
            Files.copy(logStream, Paths.get(logFile));
            log.info("Logs downloaded from pod {} to {}", podName, logFile);
        } catch (ApiException | IOException e) {
            log.warn("Retryable error while downloading logs from pod {}. Error message: {} ", podName, e.getMessage());
            throw new TestFrameworkException(TestFrameworkException.Type.RequestFailed, "Error while downloading logs");
        }
    }, executor);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) InputStream(java.io.InputStream) IOException(java.io.IOException) Cleanup(lombok.Cleanup) ApiException(io.kubernetes.client.openapi.ApiException)

Example 5 with TestFrameworkException

use of io.pravega.test.system.framework.TestFrameworkException in project pravega by pravega.

the class SingleJUnitTestRunner method runMethod.

public void runMethod() {
    Method m = null;
    try {
        m = this.testClass.getDeclaredMethod(this.methodName);
        Statement statement = methodBlock(new FrameworkMethod(m) {

            @Override
            public Object invokeExplosively(final Object target, final Object... params) throws Throwable {
                try {
                    Object result = super.invokeExplosively(target, params);
                    log.info("Test " + methodName + " completed without error.");
                    return result;
                } catch (Throwable t) {
                    log.error("Test " + methodName + " failed with exception. ", t);
                    throw t;
                }
            }
        });
        statement.evaluate();
    } catch (Throwable ex) {
        throw new TestFrameworkException(TestFrameworkException.Type.InternalError, "Exception while running test" + " method: " + this.methodName, ex);
    }
}
Also used : TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Aggregations

TestFrameworkException (io.pravega.test.system.framework.TestFrameworkException)16 MarathonException (mesosphere.marathon.client.MarathonException)7 DockerException (com.spotify.docker.client.exceptions.DockerException)6 Service (com.spotify.docker.client.messages.swarm.Service)5 ExecutionException (java.util.concurrent.ExecutionException)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 TimeoutException (java.util.concurrent.TimeoutException)4 IOException (java.io.IOException)2 ServiceCreateResponse (com.spotify.docker.client.messages.ServiceCreateResponse)1 EndpointSpec (com.spotify.docker.client.messages.swarm.EndpointSpec)1 TaskSpec (com.spotify.docker.client.messages.swarm.TaskSpec)1 ApiClient (io.kubernetes.client.openapi.ApiClient)1 ApiException (io.kubernetes.client.openapi.ApiException)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Cleanup (lombok.Cleanup)1 App (mesosphere.marathon.client.model.v2.App)1 GetAppResponse (mesosphere.marathon.client.model.v2.GetAppResponse)1 Result (mesosphere.marathon.client.model.v2.Result)1