DefaultDockerCloudClient extends BuildServerAdapter implements DockerCloudClient { @Override public void restartInstance(@Nonnull final CloudInstance instance) { LOG.info("Restarting container:" + instance); final DockerInstance dockerInstance = (DockerInstance) instance; taskScheduler.scheduleInstanceTask(new DockerInstanceTask("Restart of container", dockerInstance, null) { @Override protected void callInternal() throws Exception { lock.runInterruptibly(() -> { checkReady(); dockerInstance.updateStartedTime(); dockerInstance.setStatus(InstanceStatus.RESTARTING); }); Optional<String> agentHolderId = dockerInstance.getAgentHolderId(); if (agentHolderId.isPresent()) { clientFacade.restartAgent(agentHolderId.get()); lock.runInterruptibly(() -> dockerInstance.setStatus(InstanceStatus.RUNNING)); } else { LOG.warn("No agent holder associated with instance " + instance + ". Ignoring restart request."); } } }); } DefaultDockerCloudClient(@Nonnull DockerCloudClientConfig clientConfig,
                             @Nonnull final List<DockerImageConfig> imageConfigs,
                             @Nonnull final DockerImageNameResolver resolver,
                             @Nonnull CloudState cloudState,
                             @Nonnull final SBuildServer buildServer); @Nonnull @Override UUID getUuid(); @Nonnull @Override DockerCloudSupport getCloudSupport(); @Override void serverStartup(); @Override boolean isInitialized(); @Nullable @Override DockerImage findImageById(@Nonnull String id); @Nullable @Override DockerInstance findInstanceByAgent(@Nonnull AgentDescription agent); @Nonnull @Override Collection<DockerImage> getImages(); @Nullable @Override CloudErrorInfo getErrorInfo(); @Override boolean canStartNewInstance(@Nonnull CloudImage image); @Nullable @Override String generateAgentName(@Nonnull AgentDescription agent); @Nonnull @Override DockerInstance startNewInstance(@Nonnull final CloudImage image, @Nonnull final CloudInstanceUserData tag); @Override void restartInstance(@Nonnull final CloudInstance instance); @Override void terminateInstance(@Nonnull final CloudInstance instance); @Override void dispose(); Optional<Instant> getLastDockerSyncTime(); @Override void notifyFailure(@Nonnull String msg, @Nullable Throwable throwable);  }
@Test public void restartInstance() { DefaultDockerCloudClient client = createClient(); DockerImage dockerImage = waitForImage(client); DockerInstance instance = client.startNewInstance(dockerImage, userData); waitForInstanceStatus(instance, InstanceStatus.RUNNING); client.restartInstance(instance); waitUntil(() -> { assertThat(instance.getErrorInfo()).isNull(); assertThat(instance.getStatus()).isIn(InstanceStatus.UNKNOWN, InstanceStatus.RESTARTING, InstanceStatus.RUNNING); return instance.getStatus() == InstanceStatus.RUNNING; }); }