当前位置: 首页>>代码示例>>Java>>正文


Java Container类代码示例

本文整理汇总了Java中com.spotify.docker.client.messages.Container的典型用法代码示例。如果您正苦于以下问题:Java Container类的具体用法?Java Container怎么用?Java Container使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Container类属于com.spotify.docker.client.messages包,在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllHostContainerId

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
private static List<String> getAllHostContainerId(){
    String cacheKey = "allHostContainerIds";
    int cacheTime = 28;//28秒缓存周期,保证一次采集job只需要访问一次docker即可

    List<String> ids = (List<String>) getCache(cacheKey);
    if (ids != null){
        return ids;
    }else {
        ids = new ArrayList<>();
    }
    synchronized (LockForGetAllHostContainerId){
        try {
            List<Container> containerList = getContainers(DockerClient.ListContainersParam.allContainers());
            for (Container container : containerList) {
                ids.add(container.id());
            }
        } catch (Exception e) {
            log.error("",e);
        }
    }
    setCache(cacheKey,ids,cacheTime);
    return ids;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:24,代码来源:DockerUtil.java

示例2: cleanDocker

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
private void cleanDocker(Set<String> runningTaskIds) {
  try {
    for (Container container : dockerUtils.listContainers()) {
      for (String name : container.names()) {
        if (name.startsWith(executorConfiguration.getDockerPrefix())) {
          if (!runningTaskIds.contains(name.substring(executorConfiguration.getDockerPrefix().length()))) {
            stopContainer(container);
          }
        }
      }
    }
  } catch (Exception e) {
    LOG.error("Could not get list of Docker containers", e);
    exceptionNotifier.notify(e, Collections.<String, String>emptyMap());
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:17,代码来源:SingularityExecutorCleanup.java

示例3: stopParentAndChildren

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
@Override
public void stopParentAndChildren(String parentId) {
    // stop parent
    stopContainer(parentId);

    // find children
    try {
        List<Container> containers = dockerClient.listContainers();
        for (Container c : containers) {
            if (c != null && c.labels().get(LABEL_PARENT) != null
                    && c.labels().get(LABEL_PARENT).equals(parentId)) {
                stopParentAndChildren(c.id());
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error while stopping containers: " + e.toString());
    }
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:19,代码来源:ContainerManagerImpl.java

示例4: removeParentAndChildren

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
@Override
public void removeParentAndChildren(String parentId) {
    // stop parent
    removeContainer(parentId);

    // find children
    try {
        List<Container> containers = dockerClient.listContainers(DockerClient.ListContainersParam.allContainers());
        for (Container c : containers) {
            if (c != null && c.labels().get(LABEL_PARENT) != null
                    && c.labels().get(LABEL_PARENT).equals(parentId)) {
                removeParentAndChildren(c.id());
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error while removing containers: " + e.toString());
    }
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:19,代码来源:ContainerManagerImpl.java

示例5: setDockerClient

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
@Autowired
public void setDockerClient(DockerClientProxy dockerClientProxy) {
    try {

        dockerClientProxy.access(dockerClient -> {
            final List<Container> containers = dockerClient.listContainers(withLabel(MccyConstants.MCCY_LABEL), allContainers());

            if (containers.isEmpty()) {
                LOG.info("NO CONTAINERS currently running");
            }
            else {
                containers.forEach(c -> LOG.info("CURRENT CONTAINER: {}", c));
            }

            return null;
        });
    } catch (InterruptedException | DockerException e) {
        LOG.warn("Failed to access or list containers", e);
    }

}
 
开发者ID:moorkop,项目名称:mccy-engine,代码行数:22,代码来源:DumpCurrentStateService.java

示例6: getServiceOfferings

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
public List<DockerContainerElement> getServiceOfferings(IProgressMonitor monitor) throws CoreException {
	return new BehaviourRequest<List<DockerContainerElement>>("Getting available service options") { //$NON-NLS-1$
		@Override
		protected List<DockerContainerElement> doRun(DockerClient client, SubMonitor progress) throws CoreException {
			// return client.getServiceOfferings();
			try {
				List<Container> containers = client.listContainers();
				return DomainHelper.convert(containers);					
			}
			catch (DockerException | InterruptedException e) {
				e.printStackTrace();
			}
			return null;
		}
	}.run(monitor);
}
 
开发者ID:osswangxining,项目名称:dockerfoundry,代码行数:17,代码来源:DockerFoundryServerBehaviour.java

示例7: updateContainerState

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
void updateContainerState() {

        // TODO: Handle state properly.

        try {
            List<Container> latestRunningContainers = getContainers();

            LOGGER.info(
                String.format("Found %d running containers", latestRunningContainers.size()));

            Map<String, String> latestRunningContainerIdAndNames = getContainerIdAndNames(
                latestRunningContainers);

            if (!latestRunningContainerIdAndNames.keySet()
                .equals(this.runningContainers.keySet())) {
                LOGGER.info("Container list changed!");

                this.runningContainers = latestRunningContainerIdAndNames;

                notifyFrameworkListener();
            }
        } catch (DockerException | InterruptedException e) {
            throw new IllegalStateException("Failed to onNewConfigsFromScheduler container states", e);
        }
    }
 
开发者ID:triforkse,项目名称:logstash-mesos,代码行数:26,代码来源:DockerClient.java

示例8: trigger

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
@Input
public void trigger() {
    if (dockerClient != null) {
        try {
            final Optional<Container> container = dockerKiller.randomlyPickOneMatchingElement(dockerClient, key, value);
            if(container.isPresent()) {
                final String containerId = container.get().id();
                dockerClient.stopContainer(containerId, secondsToWaitBeforeKilling);
                killedContainer.send(containerId);
            }
        } catch (DockerException | InterruptedException e) {
            Log.error(e.getMessage());
        }
    } else {
        Log.info("No action because of null docker client");
    }
}
 
开发者ID:kevoree,项目名称:kevoree-library,代码行数:18,代码来源:DockerKiller.java

示例9: randomlyPickOneMatchingElement

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
public Optional<Container> randomlyPickOneMatchingElement(final DefaultDockerClient dockerClient, final String key, final String value) throws DockerException, InterruptedException {
    final List<Container> containers = dockerClient.listContainers();

    final List<Container> collect = new ArrayList<>();
    for (Container container : containers) {
        final ContainerInfo containerInfo = dockerClient.inspectContainer(container.id());
        boolean res;
        res = containsKeyAndValue(containerInfo.config().env(), key, value);
        if (res) {
            collect.add(container);
        }

    }
    final Optional<Container> ret;
    if (collect.isEmpty()) {
        ret = Optional.empty();
    } else {
        ret = Optional.of(collect.get(random.nextInt(collect.size())));
    }
    return ret;
}
 
开发者ID:kevoree,项目名称:kevoree-library,代码行数:22,代码来源:DockerKillerService.java

示例10: cleanDocker

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
private void cleanDocker(Set<String> runningTaskIds) {
  try {
    for (Container container : dockerUtils.listContainers()) {
      for (String name : container.names()) {
        if (name.startsWith(executorConfiguration.getDockerPrefix())) {
          if (!runningTaskIds.contains(name.substring(executorConfiguration.getDockerPrefix().length()))) {
            stopContainer(container);
          }
        }
      }
    }
  } catch (Exception e) {
    LOG.error("Could not get list of Docker containers", e);
    exceptionNotifier.notify(String.format("Error listing docker containers (%s)", e.getMessage()), e, Collections.<String, String>emptyMap());
  }
}
 
开发者ID:HubSpot,项目名称:Singularity,代码行数:17,代码来源:SingularityExecutorCleanup.java

示例11: listContainers

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
@Override
public List<String> listContainers() throws FatalDockerJSONException {
    List<String> containersId = null;
    try {
        List<Container> containers = dockerClient.listContainers(DockerClient.ListContainersParam.allContainers());
        containersId = containers.stream().map(c -> c.id()).collect(Collectors.toList());
    } catch (DockerException | InterruptedException e) {
        logger.error(e.getMessage());
    }
    return containersId;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:12,代码来源:DockerServiceImpl.java

示例12: addRules

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
@Given("^added custom flow rules")
public void addRules() throws Exception {
    Container mininetContainer = dockerClient.listContainers()
            .stream()
            .filter(container -> container.image().startsWith(MININET_CONTAINER_PREFIX))
            .findFirst().orElseThrow(() -> new IllegalStateException("Floodlight controller should be active"));

    final String[] commands = {"ovs-ofctl", "-O", "Openflow13", "add-flow", SWITCH_NAME, RULE};
    ExecCreation execCreation = dockerClient.execCreate(mininetContainer.id(), commands,
            DockerClient.ExecCreateParam.attachStdout(), DockerClient.ExecCreateParam.attachStderr());

    final LogStream output = dockerClient.execStart(execCreation.id());
    final String execOutput = output.readFully();
    assertTrue(StringUtils.isEmpty(execOutput));
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:16,代码来源:ClearTablesTest.java

示例13: getAllHostContainerProcInfos

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
/**
 * 获取主机上所有运行容器的proc信息
 * @return
 */
public static List<ContainerProcInfoToHost> getAllHostContainerProcInfos(){
    String cacheKey = "ALL_HOST_CONTAINER_PROC_INFOS";
    List<ContainerProcInfoToHost> procInfoToHosts = (List<ContainerProcInfoToHost>) getCache(cacheKey);
    if (procInfoToHosts != null){
        //返回缓存数据
        return procInfoToHosts;
    }else {
        procInfoToHosts = new ArrayList<>();
    }
    synchronized (LockForGetAllHostContainerProcInfos){
        try {
            List<Container> containers = getContainers(DockerClient.ListContainersParam.withStatusRunning());
            for (Container container : containers) {
                ContainerInfo info = getContainerInfo(container.id());
                if (info != null) {
                    String pid = String.valueOf(info.state().pid());
                    procInfoToHosts.add(new ContainerProcInfoToHost(container.id(),PROC_HOST_VOLUME + "/" + pid + "/root",pid));
                }
            }
        } catch (Exception e) {
            log.error("",e);
        }
    }
    if (!procInfoToHosts.isEmpty()) {
        //设置缓存
        setCache(cacheKey,procInfoToHosts);
    }
    return procInfoToHosts;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:34,代码来源:DockerUtil.java

示例14: removeContainer

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
private void removeContainer(Container container) {
    try {
        dockerClient.removeContainer(container.id(), DockerClient.RemoveContainerParam.forceKill(true));
    } catch (Exception e) {
        log.error("remove container failed: " + e.getMessage(), e);
    }
}
 
开发者ID:dshell-io,项目名称:dshell,代码行数:8,代码来源:LocalEngine.java

示例15: tryGetContainerId

import com.spotify.docker.client.messages.Container; //导入依赖的package包/类
private String tryGetContainerId(String functionName) throws Exception {
    final List<Container> containers = dockerClient.listContainers(
            allContainers(),
            withLabel(Constants.LABEL_DSHELL_FUNCTION, functionName)
    );

    assertTrue(containers.size() > 0);
    return containers.get(0).id();
}
 
开发者ID:dshell-io,项目名称:dshell,代码行数:10,代码来源:LocalEngineTest.java


注:本文中的com.spotify.docker.client.messages.Container类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。