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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations