コード例 #1
0
 private List<Container> findContainers(Id id, boolean allContainers) {
   final List<Container> matchingContainers = new ArrayList<>();
   for (Container container : docker.listContainersCmd().withShowAll(allContainers).exec()) {
     boolean imageNameMatches = container.getImage().equals(repo.imageName(id));
     String[] containerNames = container.getNames();
     if (containerNames == null) {
       // Every container should have a name, but this is not the case
       // on Circle CI. Containers with no name are broken residues of
       // building the image and therefore will be ignored.
       continue;
     }
     boolean containerNameMatches = asList(containerNames).contains(containerName(id));
     if (imageNameMatches || containerNameMatches) {
       matchingContainers.add(container);
     }
   }
   return matchingContainers;
 }
コード例 #2
0
  private void stop(final Id id) {
    if (id == null) {
      throw new IllegalArgumentException("id is null");
    }

    logger.info("Stopping " + id);

    for (Container container : findRunningContainers(id)) {
      logger.info("Stopping container " + Arrays.toString(container.getNames()));
      try {
        docker.stopContainerCmd(container.getId()).withTimeout(1).exec();
      } catch (DockerException e) {
        throw new OrchestrationException(e);
      }
    }
    for (Plugin plugin : plugins) {
      plugin.stopped(id, conf(id));
    }
  }