@Test public void removeContainer() throws Exception { String testContainer = manager.startContainer(busyboxImageName, Constants.CONTAINER_TYPE_SYSTEM, null, sleepCommand); assertNotNull(testContainer); services.add(testContainer); manager.removeContainer(testContainer); assertContainerIsNotRunning("Removed container", testContainer); services.remove(testContainer); }
@Override public void removeContainer(String serviceName) { try { Integer exitCode = getContainerExitCode(serviceName); if (DEPLOY_ENV.equals(DEPLOY_ENV_DEVELOP)) { LOGGER.info( "Will not remove container {}. " + "Development mode is enabled.", serviceName); } else if (DEPLOY_ENV.equals(DEPLOY_ENV_TESTING) && (exitCode == null || exitCode != 0)) { LOGGER.info( "Will not remove container {}. " + "ExitCode: {} != 0 and testing mode is enabled.", serviceName, exitCode); } else { LOGGER.info("Removing container {}. ", serviceName); dockerClient.removeService(serviceName); Waiting.waitFor(() -> { try { dockerClient.inspectService(serviceName); return false; } catch (ServiceNotFoundException e) { return true; } }, DOCKER_POLL_INTERVAL); } } catch (TaskNotFoundException | ServiceNotFoundException e) { LOGGER.error("Couldn't remove container {} because it doesn't exist", serviceName); } catch (Exception e) { LOGGER.error("Couldn't remove container {}.", serviceName, e); } }
ContainerManagerImpl implements ContainerManager { @Override public void removeContainer(String serviceName) { try { Integer exitCode = getContainerExitCode(serviceName); if (DEPLOY_ENV.equals(DEPLOY_ENV_DEVELOP)) { LOGGER.info( "Will not remove container {}. " + "Development mode is enabled.", serviceName); } else if (DEPLOY_ENV.equals(DEPLOY_ENV_TESTING) && (exitCode == null || exitCode != 0)) { LOGGER.info( "Will not remove container {}. " + "ExitCode: {} != 0 and testing mode is enabled.", serviceName, exitCode); } else { LOGGER.info("Removing container {}. ", serviceName); dockerClient.removeService(serviceName); Waiting.waitFor(() -> { try { dockerClient.inspectService(serviceName); return false; } catch (ServiceNotFoundException e) { return true; } }, DOCKER_POLL_INTERVAL); } } catch (TaskNotFoundException | ServiceNotFoundException e) { LOGGER.error("Couldn't remove container {} because it doesn't exist", serviceName); } catch (Exception e) { LOGGER.error("Couldn't remove container {}.", serviceName, e); } } }
ContainerManagerImpl implements ContainerManager { @Override public void removeContainer(String serviceName) { try { Integer exitCode = getContainerExitCode(serviceName); if (DEPLOY_ENV.equals(DEPLOY_ENV_DEVELOP)) { LOGGER.info( "Will not remove container {}. " + "Development mode is enabled.", serviceName); } else if (DEPLOY_ENV.equals(DEPLOY_ENV_TESTING) && (exitCode == null || exitCode != 0)) { LOGGER.info( "Will not remove container {}. " + "ExitCode: {} != 0 and testing mode is enabled.", serviceName, exitCode); } else { LOGGER.info("Removing container {}. ", serviceName); dockerClient.removeService(serviceName); Waiting.waitFor(() -> { try { dockerClient.inspectService(serviceName); return false; } catch (ServiceNotFoundException e) { return true; } }, DOCKER_POLL_INTERVAL); } } catch (TaskNotFoundException | ServiceNotFoundException e) { LOGGER.error("Couldn't remove container {} because it doesn't exist", serviceName); } catch (Exception e) { LOGGER.error("Couldn't remove container {}.", serviceName, e); } } ContainerManagerImpl(); }
ContainerManagerImpl implements ContainerManager { @Override public void removeContainer(String serviceName) { try { Integer exitCode = getContainerExitCode(serviceName); if (DEPLOY_ENV.equals(DEPLOY_ENV_DEVELOP)) { LOGGER.info( "Will not remove container {}. " + "Development mode is enabled.", serviceName); } else if (DEPLOY_ENV.equals(DEPLOY_ENV_TESTING) && (exitCode == null || exitCode != 0)) { LOGGER.info( "Will not remove container {}. " + "ExitCode: {} != 0 and testing mode is enabled.", serviceName, exitCode); } else { LOGGER.info("Removing container {}. ", serviceName); dockerClient.removeService(serviceName); Waiting.waitFor(() -> { try { dockerClient.inspectService(serviceName); return false; } catch (ServiceNotFoundException e) { return true; } }, DOCKER_POLL_INTERVAL); } } catch (TaskNotFoundException | ServiceNotFoundException e) { LOGGER.error("Couldn't remove container {} because it doesn't exist", serviceName); } catch (Exception e) { LOGGER.error("Couldn't remove container {}.", serviceName, e); } } ContainerManagerImpl(); void pullImage(String imageName); @Deprecated String startContainer(String imageName); @Deprecated String startContainer(String imageName, String[] command); String startContainer(String imageName, String type, String parent); @Override String startContainer(String imageName, String containerType, String parentId, String[] command); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
            String[] command); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
    String[] netAliases, String[] command); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
            String[] command, boolean pullImage); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
            String[] netAliases, String[] command, boolean pullImage); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
            String[] netAliases, String[] command, String experimentId); @Override void removeContainer(String serviceName); @Deprecated @Override void stopContainer(String containerId); @Deprecated @Override void stopParentAndChildren(String parentId); @Override void removeParentAndChildren(String parent); @Override Service getContainerInfo(String serviceName); @Override List<Service> getContainers(Service.Criteria criteria); @Override Integer getContainerExitCode(String serviceName); @Deprecated @Override String getContainerId(String name); @Deprecated @Override String getContainerName(String containerId); @Override void addContainerObserver(ContainerStateObserver containerObserver); static boolean containsVersionTag(String imageName); @Override ContainerStats getStats(String containerId); }
ContainerManagerImpl implements ContainerManager { @Override public void removeContainer(String serviceName) { try { Integer exitCode = getContainerExitCode(serviceName); if (DEPLOY_ENV.equals(DEPLOY_ENV_DEVELOP)) { LOGGER.info( "Will not remove container {}. " + "Development mode is enabled.", serviceName); } else if (DEPLOY_ENV.equals(DEPLOY_ENV_TESTING) && (exitCode == null || exitCode != 0)) { LOGGER.info( "Will not remove container {}. " + "ExitCode: {} != 0 and testing mode is enabled.", serviceName, exitCode); } else { LOGGER.info("Removing container {}. ", serviceName); dockerClient.removeService(serviceName); Waiting.waitFor(() -> { try { dockerClient.inspectService(serviceName); return false; } catch (ServiceNotFoundException e) { return true; } }, DOCKER_POLL_INTERVAL); } } catch (TaskNotFoundException | ServiceNotFoundException e) { LOGGER.error("Couldn't remove container {} because it doesn't exist", serviceName); } catch (Exception e) { LOGGER.error("Couldn't remove container {}.", serviceName, e); } } ContainerManagerImpl(); void pullImage(String imageName); @Deprecated String startContainer(String imageName); @Deprecated String startContainer(String imageName, String[] command); String startContainer(String imageName, String type, String parent); @Override String startContainer(String imageName, String containerType, String parentId, String[] command); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
            String[] command); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
    String[] netAliases, String[] command); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
            String[] command, boolean pullImage); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
            String[] netAliases, String[] command, boolean pullImage); @Override String startContainer(String imageName, String containerType, String parentId, String[] env,
            String[] netAliases, String[] command, String experimentId); @Override void removeContainer(String serviceName); @Deprecated @Override void stopContainer(String containerId); @Deprecated @Override void stopParentAndChildren(String parentId); @Override void removeParentAndChildren(String parent); @Override Service getContainerInfo(String serviceName); @Override List<Service> getContainers(Service.Criteria criteria); @Override Integer getContainerExitCode(String serviceName); @Deprecated @Override String getContainerId(String name); @Deprecated @Override String getContainerName(String containerId); @Override void addContainerObserver(ContainerStateObserver containerObserver); static boolean containsVersionTag(String imageName); @Override ContainerStats getStats(String containerId); static final String DEPLOY_ENV_KEY; static final String DOCKER_AUTOPULL_ENV_KEY; static final String LOGGING_GELF_ADDRESS_KEY; static final String USER_NAME_KEY; static final String USER_EMAIL_KEY; static final String USER_PASSWORD_KEY; static final String REGISTRY_URL_KEY; static final String HOBBIT_DOCKER_NETWORK; static final String LOGGING_TAG; static final Set<String> NEW_TASKS_STATES; static final Set<String> UNFINISHED_TASK_STATES; }