Search in sources :

Example 11 with TestFrameworkException

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

the class K8sClient method initializeApiClient.

/**
 * Create an instance of K8 api client and initialize with the KUBERNETES config. The config used follows the below pattern.
 *      1. If $KUBECONFIG is defined, use that config file.
 *      2. If $HOME/.kube/config can be found, use that.
 *      3. If the in-cluster service account can be found, assume in cluster config.
 *      4. Default to localhost:8080 as a last resort.
 */
private ApiClient initializeApiClient() {
    ApiClient client;
    try {
        log.debug("Initialize KUBERNETES api client");
        client = Config.defaultClient();
        // this can be set to true enable http dump.
        client.setDebugging(false);
        client.setHttpClient(client.getHttpClient().newBuilder().readTimeout(DEFAULT_TIMEOUT_MINUTES, TimeUnit.MINUTES).build());
        Configuration.setDefaultApiClient(client);
        Runtime.getRuntime().addShutdownHook(new Thread(this::close));
    } catch (IOException e) {
        throw new TestFrameworkException(ConnectionFailed, "Connection to the k8 cluster failed, ensure .kube/config is configured correctly.", e);
    }
    return client;
}
Also used : TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) IOException(java.io.IOException) ApiClient(io.kubernetes.client.openapi.ApiClient)

Example 12 with TestFrameworkException

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

the class MarathonBasedService method scaleService.

@Override
public CompletableFuture<Void> scaleService(final int instanceCount) {
    Preconditions.checkArgument(instanceCount >= 0, "negative value: %s", instanceCount);
    try {
        App updatedConfig = new App();
        updatedConfig.setInstances(instanceCount);
        marathonClient.updateApp(getID(), updatedConfig, true);
        // wait until scale operation is complete.
        return waitUntilServiceRunning();
    } catch (MarathonException ex) {
        if (ex.getStatus() == CONFLICT.getStatusCode()) {
            log.error("Scaling operation failed as the application is locked by an ongoing deployment", ex);
            throw new TestFrameworkException(RequestFailed, "Scaling operation failed", ex);
        }
        handleMarathonException(ex);
    }
    return null;
}
Also used : App(mesosphere.marathon.client.model.v2.App) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) MarathonException(mesosphere.marathon.client.MarathonException)

Example 13 with TestFrameworkException

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

the class PravegaSegmentStoreService method start.

@Override
public void start(final boolean wait) {
    deleteApp("/pravega/segmentstore");
    log.info("Starting Pravega SegmentStore Service: {}", getID());
    try {
        marathonClient.createApp(createPravegaSegmentStoreApp());
        if (wait) {
            waitUntilServiceRunning().get(10, TimeUnit.MINUTES);
        }
    } catch (MarathonException e) {
        handleMarathonException(e);
    } catch (InterruptedException | ExecutionException | TimeoutException ex) {
        throw new TestFrameworkException(InternalError, "Exception while " + "starting Pravega SegmentStore 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 14 with TestFrameworkException

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

the class DockerBasedService method getReplicas.

private long getReplicas() {
    long replicas = -1;
    String serviceId = getServiceID();
    try {
        if (serviceId != null) {
            replicas = Exceptions.handleInterruptedCall(() -> dockerClient.inspectService(serviceId).spec().mode().replicated().replicas());
        }
    } catch (DockerException e) {
        throw new TestFrameworkException(TestFrameworkException.Type.RequestFailed, "Unable to get replicas", e);
    }
    return replicas;
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException)

Example 15 with TestFrameworkException

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

the class DockerBasedService method start.

public void start(final boolean wait, final ServiceSpec serviceSpec) {
    try {
        String serviceId = getServiceID();
        if (serviceId != null) {
            Service service = Exceptions.handleInterruptedCall(() -> dockerClient.inspectService(serviceId));
            Exceptions.handleInterrupted(() -> dockerClient.updateService(serviceId, service.version().index(), serviceSpec));
        } else {
            ServiceCreateResponse serviceCreateResponse = Exceptions.handleInterruptedCall(() -> dockerClient.createService(serviceSpec));
            assertNotNull("Service id is null", serviceCreateResponse.id());
        }
        if (wait) {
            Exceptions.handleInterrupted(() -> waitUntilServiceRunning().get(5, TimeUnit.MINUTES));
        }
    } catch (Exception e) {
        throw new TestFrameworkException(TestFrameworkException.Type.RequestFailed, "Unable to create service", e);
    }
}
Also used : TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.spotify.docker.client.messages.swarm.Service) ServiceCreateResponse(com.spotify.docker.client.messages.ServiceCreateResponse) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) DockerException(com.spotify.docker.client.exceptions.DockerException)

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