• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RestartPolicy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: toRestartPolicy

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
private static final RestartPolicy toRestartPolicy(
    org.arquillian.cube.docker.impl.client.config.RestartPolicy restart) {
    if (restart.getName() != null) {
        String name = restart.getName();

        if ("failure".equals(name)) {
            return RestartPolicy.onFailureRestart(restart.getMaximumRetryCount());
        } else {
            if ("restart".equals(name)) {
                return RestartPolicy.alwaysRestart();
            } else {
                return RestartPolicy.noRestart();
            }
        }
    } else {
        return RestartPolicy.noRestart();
    }
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:19,代码来源:DockerClientExecutor.java


示例2: setRestartPolicy

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
private void setRestartPolicy(Instance instance, RestartPolicy restartPolicy) {
    if (restartPolicy == null || StringUtils.isEmpty(restartPolicy.getName())) {
        return;
    }

    io.cattle.platform.core.addon.RestartPolicy rp = new io.cattle.platform.core.addon.RestartPolicy();
    rp.setMaximumRetryCount(restartPolicy.getMaximumRetryCount());
    rp.setName(restartPolicy.getName());
    setField(instance, FIELD_RESTART_POLICY, rp);
}
 
开发者ID:rancher,项目名称:cattle,代码行数:11,代码来源:DockerTransformerImpl.java


示例3: verify_container_with_user

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
@Test
public void verify_container_with_user ()
		throws Exception {

	String imageName = BUSY_BOX;
	loadImageIfNeeded( imageName );
	String containerName = "/junit-container-with-user-"
			+ LocalDateTime.now().format( DateTimeFormatter.ofPattern( "MMM.d-HH.mm.ss" ) );

	CreateContainerResponse createResponse = dockerClient.createContainerCmd( imageName )
		.withName( containerName )
		.withWorkingDir( "/" )
		.withRestartPolicy( RestartPolicy.onFailureRestart( 3 ) )
		.withUser( "1001:1001" ) // uid:gid
		// .withCmd( "ls", "-l" )
		.withCmd( "id" )
		.exec();

	logger.info( "Create: {}", createResponse );

	dockerClient
		.startContainerCmd( createResponse.getId() )
		.exec();

	LogContainerTestCallback loggingCallback = new LogContainerTestCallback( false );

	dockerClient
		.logContainerCmd( createResponse.getId() )
		.withStdErr( true )
		.withStdOut( true )
		.withTailAll()
		.exec( loggingCallback );
	//
	loggingCallback.awaitCompletion( 3, TimeUnit.SECONDS );

	logger.info( "{} logs: \n {} ", containerName, loggingCallback.toString() );

	loggingCallback.close();

	assertThat( loggingCallback.toString() )
		.as( "id command output" )
		.contains( "uid=1001 gid=1001" );

	dockerClient
		.removeContainerCmd( createResponse.getId() )
		.withRemoveVolumes( true )
		.withForce( true )
		.exec();

	logger.info( "Container removed: {}", createResponse.getId() );

}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:53,代码来源:Docker_Java.java


示例4: createContainer

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
/**
	 * creates {@link Container}
	 * 
	 * @param element - {@link Element}
	 * @param host - host ip address
	 * @return id of created {@link Container}
	 * @throws Exception
	 */
	public String createContainer(Element element, String host) throws Exception {
		RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(10);

		Ports portBindings = new Ports();
		List<ExposedPort> exposedPorts = new ArrayList<>();
		if (element.getPortMappings() != null)
			element.getPortMappings().forEach(mapping -> {
				ExposedPort internal = ExposedPort.tcp(Integer.parseInt(mapping.getInside()));
				Ports.Binding external = Ports.Binding(Integer.parseInt(mapping.getOutside()));
				portBindings.bind(internal, external);
				exposedPorts.add(internal);
			});
		String[] extraHosts = { host };
		
		Map<String, String> containerLogConfig = new HashMap<String, String>();
		int logFiles = 1; 
		if (element.getLogSize() > 2)
			logFiles = (int) (element.getLogSize() / 2); 

		containerLogConfig.put("max-file", String.valueOf(logFiles));
		containerLogConfig.put("max-size", "2m");
		LogConfig containerLog = new LogConfig(LogConfig.LoggingType.DEFAULT, containerLogConfig);
		
		CreateContainerCmd cmd = dockerClient.createContainerCmd(element.getImageName())
				.withLogConfig(containerLog)
				.withCpuset("0")
				.withExposedPorts(exposedPorts.toArray(new ExposedPort[0]))
				.withPortBindings(portBindings)
				.withEnv("SELFNAME=" + element.getElementId())
				.withName(element.getElementId())
				.withRestartPolicy(restartPolicy);
//		if (element.getImageName().startsWith("iotracks/catalog:core-networking"))
//			cmd = cmd.withMemoryLimit(256 * Constants.MiB);
		if (StringUtil.isNullOrEmpty(host))
			cmd = cmd.withNetworkMode("host").withPrivileged(true);
		else
			cmd = cmd.withExtraHosts(extraHosts);
		CreateContainerResponse resp = cmd.exec();
		return resp.getId();
	}
 
开发者ID:iotracks,项目名称:iofabric,代码行数:49,代码来源:DockerUtil.java


示例5: call

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
public String call() throws Exception {
    DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null);
    
    CreateContainerCmd cfgCmd = client.createContainerCmd(imageRes);
    if (commandRes != null) {
        cfgCmd.withCmd(commandRes);
    }
    cfgCmd.withHostName(hostNameRes);
    cfgCmd.withName(containerNameRes);
    HostConfig hc = new HostConfig();
    cfgCmd.withLinks(LinkUtils.parseLinks(linksRes).getLinks());
    if (envVarsRes != null) {
        cfgCmd.withEnv(envVarsRes);
    }
    if (exposedPortsRes != null && !exposedPortsRes.isEmpty()) {
    	final ExposedPort[] ports;
        String[] exposedPortsSplitted = exposedPortsRes.split(",");
        ports = new ExposedPort[exposedPortsSplitted.length];
        for (int i = 0; i < ports.length; i++) {
            ports[i] = ExposedPort.parse(exposedPortsSplitted[i]);
        }

    	cfgCmd.withExposedPorts(ports);
    }
    if (cpuSharesRes != null) {
        cfgCmd.withCpuShares(cpuSharesRes);
    }
    if (memoryLimitRes != null) {
        cfgCmd.withMemory(memoryLimitRes);
    }
    if (dnsRes != null) {
        cfgCmd.withDns(dnsRes);
    }
    if (extraHostsRes != null) {
        cfgCmd.withExtraHosts(extraHostsRes);
    }
    if (portBindingsRes != null) {
        cfgCmd.withPortBindings(PortBindingParser.parse(portBindingsRes));
    }
    if (bindMountsRes != null) {
        cfgCmd.withBinds(BindParser.parse(bindMountsRes));
    }
    if (alwaysRestart) {
        cfgCmd.withRestartPolicy(RestartPolicy.alwaysRestart());
    }
    
    CreateContainerResponse resp = cfgCmd.withPublishAllPorts(publishAllPorts).withPrivileged(privileged).exec();
    InspectContainerResponse inspectResp = client.inspectContainerCmd(resp.getId()).exec();
    
    ObjectMapper mapper = new ObjectMapper();
    String serialized = mapper.writeValueAsString(inspectResp);
    return serialized;
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:54,代码来源:CreateContainerRemoteCallable.java


示例6: getRestartPolicy

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
@CheckForNull
RestartPolicy getRestartPolicy();
 
开发者ID:docker-java,项目名称:docker-java,代码行数:3,代码来源:CreateContainerCmd.java


示例7: getRestartPolicy

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
@Override
@JsonIgnore
public RestartPolicy getRestartPolicy() {
    return hostConfig.getRestartPolicy();
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:6,代码来源:CreateContainerCmdImpl.java


示例8: withRestartPolicy

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
@Override
public CreateContainerCmd withRestartPolicy(RestartPolicy restartPolicy) {
    checkNotNull(restartPolicy, "restartPolicy was not specified");
    this.hostConfig.withRestartPolicy(restartPolicy);
    return this;
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:7,代码来源:CreateContainerCmdImpl.java


示例9: startContainerWithRestartPolicy

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
@Test
public void startContainerWithRestartPolicy() throws DockerException {

    RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5);

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999")
            .withRestartPolicy(restartPolicy).exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(isEmptyString()));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainerResponse.getState().getRunning(), is(true));

    assertThat(inspectContainerResponse.getHostConfig().getRestartPolicy(), is(equalTo(restartPolicy)));
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:21,代码来源:StartContainerCmdIT.java


示例10: createContainerWithRestartPolicy

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
@Test
public void createContainerWithRestartPolicy() throws DockerException {

    RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5);

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
            .withRestartPolicy(restartPolicy).exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(isEmptyString()));

    InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();

    assertThat(inspectContainerResponse.getHostConfig().getRestartPolicy(), is(equalTo(restartPolicy)));
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:17,代码来源:CreateContainerCmdIT.java


示例11: withRestartPolicy

import com.github.dockerjava.api.model.RestartPolicy; //导入依赖的package包/类
/**
 * Set custom {@link RestartPolicy} for the container. Defaults to {@link RestartPolicy#noRestart()}
 */
CreateContainerCmd withRestartPolicy(RestartPolicy restartPolicy);
 
开发者ID:docker-java,项目名称:docker-java,代码行数:5,代码来源:CreateContainerCmd.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BasicLookupStrategy类代码示例发布时间:2022-05-22
下一篇:
Java Image类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap