public static CubeControlException failedDestroy(String cubeId, Throwable cause) { return new CubeControlException(cubeId, "Could not destroy " + cubeId, cause); }
@Override public void start() throws CubeControlException { try { resource = client.create(resource); portBindings.serviceStarted(); this.state = State.STARTED; } catch (Exception e) { this.state = State.START_FAILED; throw CubeControlException.failedStart(getId(), e); } }
@Override public void stop() throws CubeControlException { try { if (configuration.isNamespaceCleanupEnabled()) { client.destroy(resource); } else { logger.info("Ignoring cleanup for service " + resource.getMetadata().getName()); } this.state = State.STOPPED; } catch (Exception e) { this.state = State.STOP_FAILED; throw CubeControlException.failedStop(getId(), e); } }
@Override public void create() throws CubeControlException { if (state == State.BEFORE_CREATE || state == State.DESTROYED) { try { lifecycle.fire(new BeforeCreate(id)); log.fine(String.format("Creating container with name %s and configuration %s.", id, configuration)); long currentTime = System.currentTimeMillis(); executor.createContainer(id, configuration); this.startingTimeInMillis = System.currentTimeMillis() - currentTime; log.fine(String.format("Created container with id %s.", id)); state = State.CREATED; lifecycle.fire(new AfterCreate(id)); } catch (Exception e) { state = State.CREATE_FAILED; throw CubeControlException.failedCreate(id, e); } } }
@Override public void destroy() throws CubeControlException { if (state != State.STOPPED) { return; } try { lifecycle.fire(new BeforeDestroy(id)); List<Exception> exceptions = client.clean(holder); if (exceptions.size() > 0) { throw exceptions.get(0); } this.state = State.DESTROYED; lifecycle.fire(new AfterDestroy(id)); } catch (Exception e) { this.state = State.DESTROY_FAILED; throw CubeControlException.failedDestroy(getId(), e); } }
@Override public void start() throws CubeControlException { if (state == State.STARTED || state == State.PRE_RUNNING) { return; } try { lifecycle.fire(new BeforeStart(id)); long currentTime = System.currentTimeMillis(); executor.startContainer(id, configuration); long partialDuration = System.currentTimeMillis() - currentTime; this.startingTimeInMillis = this.startingTimeInMillis + partialDuration; state = State.STARTED; portBindings.containerStarted(); if (!AwaitStrategyFactory.create(executor, this, configuration).await()) { throw new IllegalArgumentException(String.format("Cannot connect to %s container", id)); } lifecycle.fire(new AfterStart(id)); } catch (Exception e) { state = State.START_FAILED; throw CubeControlException.failedStart(id, e); } }
@Override public void stop() throws CubeControlException { if (state == State.STOPPED || state == State.PRE_RUNNING || state == State.DESTROYED) { return; } try { lifecycle.fire(new BeforeStop(id)); long currentTime = System.currentTimeMillis(); try { if (configuration.isKillContainer()) { executor.killContainer(id); } else { executor.stopContainer(id); } } catch (NotFoundException e) { } catch (NotModifiedException e) { } this.stoppingTimeInMillis = System.currentTimeMillis() - currentTime; state = State.STOPPED; lifecycle.fire(new AfterStop(id)); } catch (Exception e) { state = State.STOP_FAILED; throw CubeControlException.failedStop(id, e); } }
@Override public void create() throws CubeControlException { if (state == State.BEFORE_CREATE || state == State.DESTROYED) { try { lifecycle.fire(new BeforeCreate(id)); log.fine(String.format("Creating container with name %s and configuration %s.", id, configuration)); long currentTime = System.currentTimeMillis(); executor.createContainer(id, configuration); this.startingTimeInMillis = System.currentTimeMillis() - currentTime; log.fine(String.format("Created container with id %s.", id)); state = State.CREATED; lifecycle.fire(new AfterCreate(id)); } catch (Exception e) { state = State.CREATE_FAILED; throw CubeControlException.failedCreate(id, e); } } }
@Override public void destroy() throws CubeControlException { if (state != State.STOPPED) { return; } try { lifecycle.fire(new BeforeDestroy(id)); long currentTime = System.currentTimeMillis(); try { executor.removeContainer(id, configuration.getRemoveVolumes()); } catch (NotFoundException e) { } catch (NotModifiedException e) { } long partialDuration = System.currentTimeMillis() - currentTime; this.stoppingTimeInMillis = this.stoppingTimeInMillis + partialDuration; state = State.DESTROYED; lifecycle.fire(new AfterDestroy(id)); } catch (Exception e) { state = State.DESTROY_FAILED; throw CubeControlException.failedDestroy(id, e); } }
@Override public void start() throws CubeControlException { if (state == State.STARTED || state == State.PRE_RUNNING) { return; } try { lifecycle.fire(new BeforeStart(id)); long currentTime = System.currentTimeMillis(); executor.startContainer(id, configuration); long partialDuration = System.currentTimeMillis() - currentTime; this.startingTimeInMillis = this.startingTimeInMillis + partialDuration; state = State.STARTED; portBindings.containerStarted(); if (!AwaitStrategyFactory.create(executor, this, configuration).await()) { throw new IllegalArgumentException(String.format("Cannot connect to %s container", id)); } lifecycle.fire(new AfterStart(id)); } catch (Exception e) { state = State.START_FAILED; throw CubeControlException.failedStart(id, e); } }
@Override public void stop() throws CubeControlException { if (state == State.STOPPED || state == State.PRE_RUNNING || state == State.DESTROYED) { return; } try { lifecycle.fire(new BeforeStop(id)); long currentTime = System.currentTimeMillis(); try { if (configuration.isKillContainer()) { executor.killContainer(id); } else { executor.stopContainer(id); } } catch (NotFoundException e) { } catch (NotModifiedException e) { } this.stoppingTimeInMillis = System.currentTimeMillis() - currentTime; state = State.STOPPED; lifecycle.fire(new AfterStop(id)); } catch (Exception e) { state = State.STOP_FAILED; throw CubeControlException.failedStop(id, e); } }
@Override public void create() throws CubeControlException { try { lifecycle.fire(new BeforeCreate(id)); holder = client.build(template); this.state = State.CREATED; lifecycle.fire(new AfterCreate(id)); } catch (Exception e) { this.state = State.CREATE_FAILED; throw CubeControlException.failedCreate(getId(), e); } }
@Override public void destroy() throws CubeControlException { if (state != State.STOPPED) { return; } try { lifecycle.fire(new BeforeDestroy(id)); long currentTime = System.currentTimeMillis(); try { executor.removeContainer(id, configuration.getRemoveVolumes()); } catch (NotFoundException e) { } catch (NotModifiedException e) { } long partialDuration = System.currentTimeMillis() - currentTime; this.stoppingTimeInMillis = this.stoppingTimeInMillis + partialDuration; state = State.DESTROYED; lifecycle.fire(new AfterDestroy(id)); } catch (Exception e) { state = State.DESTROY_FAILED; throw CubeControlException.failedDestroy(id, e); } }
public static CubeControlException failedStart(String cubeId, Throwable cause) { return new CubeControlException(cubeId, "Could not start " + cubeId, cause); }
@Override public void start() throws CubeControlException { try { lifecycle.fire(new BeforeStart(id)); holder.setPod(client.createAndWait(holder.getPod())); this.state = State.STARTED; try { portBindings.podStarted(); } catch (Exception e) { try { destroyPod(holder.getPod()); } catch (Exception e1) { } throw e; } lifecycle.fire(new AfterStart(id)); // Add the routes to JVM's name service. ArqCubeNameService.setRoutes(client.getClientExt().routes().list(), this.configuration.getRouterHost()); } catch (Exception e) { this.state = State.START_FAILED; throw CubeControlException.failedStart(getId(), e); } }
@Override public void stop() throws CubeControlException { if (state == State.STOPPED || state == State.PRE_RUNNING || state == State.DESTROYED) { return; } try { lifecycle.fire(new BeforeStop(id)); destroyPod(holder.getPod()); try { portBindings.podStopped(); } catch (Exception e) { // this shouldn't prevent normal shutdown behavior } this.state = State.STOPPED; lifecycle.fire(new AfterStop(id)); } catch (Exception e) { this.state = State.STOP_FAILED; throw CubeControlException.failedStop(getId(), e); } }
public static CubeControlException failedCreate(String cubeId, Throwable cause) { return new CubeControlException(cubeId, "Could not create " + cubeId, cause); }
public static CubeControlException failedStart(String cubeId, Throwable cause) { return new CubeControlException(cubeId, "Could not start " + cubeId, cause); }
public static CubeControlException failedDestroy(String cubeId, Throwable cause) { return new CubeControlException(cubeId, "Could not destroy " + cubeId, cause); }
public static CubeControlException failedCreate(String cubeId, Throwable cause) { return new CubeControlException(cubeId, "Could not create " + cubeId, cause); }