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


Java Link类代码示例

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


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

示例1: create

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
@Override
public String create(String image, String name, String[] env, String[] linking) {
    DockerClient dockerClient = getClient();
    
    if (image == null  || image.trim().length() == 0) {
        LOGGER.error("Container's image name to create is empty");
        return null;
    }
    
    final CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(image)
            .withPublishAllPorts(true)
            .withAttachStdout(true)
            .withAttachStdin(true)
            .withAttachStdin(true)
            .withTty(true);
    if (linking != null) {
        final String linkName = linking[0];
        final String linkAlias = linking[1];
        final Link link = new Link(linkName, linkAlias);
        createContainerCmd.withLinks(link);
    }
    if (name != null && name.trim().length() > 0) createContainerCmd.withName(name);
    if (env != null && env.length > 0) createContainerCmd.withEnv(env);
    
    final CreateContainerResponse createContainerResponse = createContainerCmd.exec();
    final String id = createContainerResponse.getId();
    
    return id;
}
 
开发者ID:kiegroup,项目名称:kie-docker-ci,代码行数:30,代码来源:DockerServiceImpl.java

示例2: getBaseCommand

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
private CreateContainerCmd getBaseCommand() {
    String hostDir = MesosCluster.getClusterHostDir().getAbsolutePath();
    List<Bind> binds = new ArrayList<>();
    binds.add(Bind.parse("/var/run/docker.sock:/var/run/docker.sock:rw"));
    binds.add(Bind.parse("/sys/fs/cgroup:/sys/fs/cgroup"));
    binds.add(Bind.parse(hostDir + ":" + hostDir));
    if (getCluster().getMapAgentSandboxVolume()) {
        binds.add(Bind.parse(String.format("%s:%s:rw", hostDir + "/.minimesos/sandbox-" + getClusterId() + "/" + hostName, MESOS_AGENT_WORK_DIR + hostName + "/slaves")));
    }
    CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag())
        .withName(getName())
        .withHostName(hostName)
        .withPrivileged(true)
        .withVolumes(new Volume(MESOS_AGENT_WORK_DIR + hostName))
        .withEnv(newEnvironment()
            .withValues(getMesosAgentEnvVars())
            .withValues(getSharedEnvVars())
            .createEnvironment())
        .withPidMode("host")
        .withLinks(new Link(getZooKeeper().getContainerId(), "minimesos-zookeeper"))
        .withBinds(binds.stream().toArray(Bind[]::new));

    MesosDns mesosDns = getCluster().getMesosDns();
    if (mesosDns != null) {
        cmd.withDns(mesosDns.getIpAddress());
    }

    return cmd;
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:30,代码来源:MesosAgentContainer.java

示例3: testMasterLinkedToAgents

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
@Test
public void testMasterLinkedToAgents() throws UnirestException {
    List<MesosAgent> containers = CLUSTER.getAgents();
    for (MesosAgent container : containers) {
        InspectContainerResponse exec = DockerClientFactory.build().inspectContainerCmd(container.getContainerId()).exec();

        List<Link> links = Arrays.asList(exec.getHostConfig().getLinks());

        Assert.assertNotNull(links);
        Assert.assertEquals("link to zookeeper is expected", 1, links.size());
        Assert.assertEquals("minimesos-zookeeper", links.get(0).getAlias());
    }
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:14,代码来源:MesosClusterTest.java

示例4: parseLinks

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
public static Links parseLinks(String linksStr) throws IllegalArgumentException {
    if(linksStr == null || linksStr.equals(""))
        return new Links();
    
    String[] linksSplit = linksStr.split(LINK_SEPARATOR);
    Link[] links = new Link[linksSplit.length];
    for(int i = 0; i < linksSplit.length; i++) {
        links[i] = Link.parse(linksSplit[i]);
    }
    return new Links(links);
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:12,代码来源:LinkUtils.java

示例5: asString

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
public static String asString(Links links) {
    if (links == null || links.getLinks() == null || links.getLinks().length == 0)
        return "";
    
    StringBuilder sb = new StringBuilder();
    for(Link link : links.getLinks()) {
        sb.append(link.getName()).append(ALIAS_SEPARATOR).append(link.getAlias()).append(LINK_SEPARATOR);
    }
    sb.deleteCharAt(sb.length() - 1); //remove trailing comma, size is always non-zero
    return sb.toString();
}
 
开发者ID:jenkinsci,项目名称:docker-build-step-plugin,代码行数:12,代码来源:LinkUtils.java

示例6: createContainerWithLink

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
@Test
public void createContainerWithLink() throws DockerException {
    String containerName1 = "containerWithlink_" + dockerRule.getKind();
    String containerName2 = "container2Withlink_" + dockerRule.getKind();

    CreateContainerResponse container1 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999")
            .withName(containerName1).exec();
    LOG.info("Created container1 {}", container1.toString());
    assertThat(container1.getId(), not(isEmptyString()));

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

    InspectContainerResponse inspectContainerResponse1 = dockerRule.getClient().inspectContainerCmd(container1.getId())
            .exec();
    LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());
    assertThat(inspectContainerResponse1.getState().getRunning(), is(true));

    CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withName(containerName2)
            .withCmd("env").withLinks(new Link(containerName1, "container1Link")).exec();
    LOG.info("Created container {}", container2.toString());
    assertThat(container2.getId(), not(isEmptyString()));

    InspectContainerResponse inspectContainerResponse2 = dockerRule.getClient().inspectContainerCmd(container2.getId())
            .exec();
    assertThat(inspectContainerResponse2.getHostConfig().getLinks(), equalTo(new Link[]{new Link(containerName1,
            "container1Link")}));
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:28,代码来源:CreateContainerCmdIT.java

示例7: toLinks

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
private static final Link[] toLinks(Collection<org.arquillian.cube.docker.impl.client.config.Link> linkList) {
    Link[] links = new Link[linkList.size()];
    int i = 0;
    for (org.arquillian.cube.docker.impl.client.config.Link link : linkList) {
        links[i] = new Link(link.getName(), link.getAlias());
        i++;
    }

    return links;
}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:11,代码来源:DockerClientExecutor.java

示例8: linkDecorator

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
private CreateContainerCmd linkDecorator(CreateContainerCmd createContainerCmd) {
    Value value = instance.getDictionary().findValuesByID("link");
    if (value != null) {
        String links = value.getValue();
        if (links != null && !links.isEmpty()) {
            return createContainerCmd
                    .withLinks(Arrays
                            .stream(links.trim().split("\\s"))
                            .map(Link::parse)
                            .toArray(Link[]::new));
        }
    }
    return createContainerCmd;
}
 
开发者ID:kevoree,项目名称:kevoree-library,代码行数:15,代码来源:CreateContainer.java

示例9: willForwardDataToElasticsearchInDockerMode

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
@Test
public void willForwardDataToElasticsearchInDockerMode() throws Exception {
    final ElasticsearchContainer elasticsearchInstance = new ElasticsearchContainer(dockerClient);
    cluster.addAndStartContainer(elasticsearchInstance);

    Client elasticsearchClient = elasticsearchInstance.createClient();

    deployScheduler("logstash", elasticsearchInstance.getIpAddress() + ":9200", true, null, true);

    final String sysLogPort = "514";
    final String randomLogLine = "Hello " + RandomStringUtils.randomAlphanumeric(32);

    dockerClient.pullImageCmd("ubuntu:15.10").exec(new PullImageResultCallback()).awaitSuccess();
    final String logstashSlave = dockerClient.listContainersCmd().withSince(cluster.getAgents().get(0).getContainerId()).exec().stream().filter(container -> container.getImage().endsWith("/logstash-executor:latest")).findFirst().map(Container::getId).orElseThrow(() -> new AssertionError("Unable to find logstash container"));

    assertTrue("logstash slave is expected to be running", dockerClient.inspectContainerCmd(logstashSlave).exec().getState().isRunning());

    final CreateContainerResponse loggerContainer = dockerClient.createContainerCmd("ubuntu:15.10").withLinks(new Link(logstashSlave, "logstash")).withCmd("logger", "--server=logstash", "--port=" + sysLogPort, "--udp", "--rfc3164", randomLogLine).exec();
    dockerClient.startContainerCmd(loggerContainer.getId()).exec();

    await().atMost(5, SECONDS).pollDelay(1, SECONDS).until(() -> {
        final String finishedAt = dockerClient.inspectContainerCmd(loggerContainer.getId()).exec().getState().getFinishedAt();
        assertNotEquals("", finishedAt.trim());
        assertNotEquals("0001-01-01T00:00:00Z", finishedAt);
    });

    final int exitCode = dockerClient.inspectContainerCmd(loggerContainer.getId()).exec().getState().getExitCode();
    dockerClient.removeContainerCmd(loggerContainer.getId()).exec();
    assertEquals(0, exitCode);

    await().atMost(10, SECONDS).pollDelay(1, SECONDS).until(() -> {
        final SearchHits hits = elasticsearchClient.prepareSearch("logstash-*").setQuery(QueryBuilders.simpleQueryStringQuery("Hello")).addField("message").addField("mesos_agent_id").execute().actionGet().getHits();
        assertEquals(1, hits.totalHits());
        Map<String, SearchHitField> fields = hits.getAt(0).fields();

        String esMessage = fields.get("message").getValue();
        assertEquals(randomLogLine, esMessage.trim());

        String esMesosSlaveId = fields.get("mesos_agent_id").getValue();

        String trueSlaveId;
        try {
            trueSlaveId = cluster.getClusterStateInfo().getJSONArray("slaves").getJSONObject(0).getString("id");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        assertEquals(trueSlaveId, esMesosSlaveId.trim());
    });
}
 
开发者ID:mesos,项目名称:logstash,代码行数:50,代码来源:DeploymentSystemTest.java

示例10: willForwardDataToElasticsearchInJarMode

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
@Test
public void willForwardDataToElasticsearchInJarMode() throws Exception {
    final ElasticsearchContainer elasticsearchInstance = new ElasticsearchContainer(dockerClient);
    cluster.addAndStartContainer(elasticsearchInstance);

    Client elasticsearchClient = elasticsearchInstance.createClient();

    deployScheduler("logstash", elasticsearchInstance.getIpAddress() + ":9200", false, null, true);

    final String sysLogPort = "514";
    final String randomLogLine = "Hello " + RandomStringUtils.randomAlphanumeric(32);

    dockerClient.pullImageCmd("ubuntu:15.10").exec(new PullImageResultCallback()).awaitSuccess();
    final String logstashSlave = cluster.getAgents().get(0).getContainerId();

    assertTrue(dockerClient.inspectContainerCmd(logstashSlave).exec().getState().isRunning());

    final CreateContainerResponse loggerContainer = dockerClient.createContainerCmd("ubuntu:15.10").withLinks(new Link(logstashSlave, "logstash")).withCmd("logger", "--server=logstash", "--port=" + sysLogPort, "--udp", "--rfc3164", randomLogLine).exec();
    dockerClient.startContainerCmd(loggerContainer.getId()).exec();

    await().atMost(5, SECONDS).pollDelay(1, SECONDS).until(() -> {
        final String finishedAt = dockerClient.inspectContainerCmd(loggerContainer.getId()).exec().getState().getFinishedAt();
        assertNotEquals("", finishedAt.trim());
        assertNotEquals("0001-01-01T00:00:00Z", finishedAt);
    });


    final int exitCode = dockerClient.inspectContainerCmd(loggerContainer.getId()).exec().getState().getExitCode();
    dockerClient.removeContainerCmd(loggerContainer.getId()).exec();
    assertEquals(0, exitCode);

    await().atMost(10, SECONDS).pollDelay(1, SECONDS).until(() -> {
        final SearchHits hits = elasticsearchClient.prepareSearch("logstash-*").setQuery(QueryBuilders.simpleQueryStringQuery("Hello")).addField("message").addField("mesos_agent_id").execute().actionGet().getHits();
        assertEquals(1, hits.totalHits());
        Map<String, SearchHitField> fields = hits.getAt(0).fields();

        String esMessage = fields.get("message").getValue();
        assertEquals(randomLogLine, esMessage.trim());

        String esMesosSlaveId = fields.get("mesos_agent_id").getValue();

        String trueSlaveId;
        try {
            trueSlaveId = cluster.getClusterStateInfo().getJSONArray("slaves").getJSONObject(0).getString("id");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        assertEquals(trueSlaveId, esMesosSlaveId.trim());
    });
}
 
开发者ID:mesos,项目名称:logstash,代码行数:51,代码来源:DeploymentSystemTest.java

示例11: startContainer

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
@Override
public Container startContainer(Environment env, Container container) throws ContainerizationException {
    DockerContainer dockerContainer = (DockerContainer) container;
    try {
        ImageConfiguration imageConf = container.getImage().getConf();
        Ports portBindings = new Ports();
        if (imageConf.getPorts() != null) {
            for (PortConfiguration port : imageConf.getPorts()) {
                ExposedPort exposedPort = new ExposedPort("tcp", port.getContainerPort());
                Ports.Binding binding = new Ports.Binding(port.getHostPort());
                portBindings.bind(exposedPort, binding);
            }
        }
        /*if (dockerContainer.getVolumes() != null) {
            for (ServiceConfiguration.VolumeInfo volumeInfo : dockerContainer.getVolumeInfos()) {
                if (volumeInfo.getHostDir() != null) {
                    binds.add(volumeInfo.getHostDir() + ":" + volumeInfo.getId() + ":rw");
                } else {
                    binds.add(volumeInfo.getId());
                }
            }
        }*/
        List<Link> links = new ArrayList<Link>();
        for (LinkConfiguration link : container.getImage().getConf().getLinks()) {
            String serviceNameInCurrentEnv = getNamingStrategy().generateContainerName(env, link.getService());
            String alias = link.getAlias();
            if (alias == null) {
                alias = link.getService();
            }
            links.add(new Link(serviceNameInCurrentEnv, alias));
        }
        getDockerClient().startContainerCmd(dockerContainer.getId())
                .withLinks(links.toArray(new Link[0]))
                //.withBinds()
                .withPortBindings(portBindings)
                .withPrivileged(imageConf.isPrivileged())
                .exec();
        InspectContainerResponse containerInspectResponse = getDockerClient().inspectContainerCmd(dockerContainer.getId()).exec();
        dockerContainer.setRunning(containerInspectResponse.getState().isRunning());
        dockerContainer.fillPortMapping(containerInspectResponse);
        fillVariables(env, imageConf, dockerContainer);
        return dockerContainer;
    } catch(Exception ex) {
        throw new ContainerizationException(ex);
    }
}
 
开发者ID:ssouporg,项目名称:denv,代码行数:47,代码来源:DockerContainerManager.java

示例12: getLinks

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

示例13: getLinks

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

示例14: withLinks

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

示例15: startContainerWithLinkingDeprecated

import com.github.dockerjava.api.model.Link; //导入依赖的package包/类
@Test
public void startContainerWithLinkingDeprecated() throws DockerException {
    String container1Name = "containerWithLink1" + dockerRule.getKind();
    String container2Name = "containerWithLink2" + dockerRule.getKind();
    dockerRule.ensureContainerRemoved(container1Name);
    dockerRule.ensureContainerRemoved(container2Name);

    CreateContainerResponse container1 = dockerRule.getClient().createContainerCmd("busybox")
            .withCmd("sleep", "9999")
            .withName(container1Name)
            .exec();

    LOG.info("Created container1 {}", container1.toString());
    assertThat(container1.getId(), not(isEmptyString()));

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

    InspectContainerResponse inspectContainerResponse1 = dockerRule.getClient().inspectContainerCmd(container1.getId())
            .exec();
    LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString());

    assertThat(inspectContainerResponse1.getConfig(), is(notNullValue()));
    assertThat(inspectContainerResponse1.getId(), not(isEmptyString()));
    assertThat(inspectContainerResponse1.getId(), startsWith(container1.getId()));
    assertThat(inspectContainerResponse1.getName(), equalTo("/" + container1Name));
    assertThat(inspectContainerResponse1.getImageId(), not(isEmptyString()));
    assertThat(inspectContainerResponse1.getState(), is(notNullValue()));
    assertThat(inspectContainerResponse1.getState().getRunning(), is(true));

    if (!inspectContainerResponse1.getState().getRunning()) {
        assertThat(inspectContainerResponse1.getState().getExitCode(), is(equalTo(0)));
    }

    CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999")
            .withName(container2Name).withLinks(new Link(container1Name, container1Name + "Link")).exec();

    LOG.info("Created container2 {}", container2.toString());
    assertThat(container2.getId(), not(isEmptyString()));

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

    InspectContainerResponse inspectContainerResponse2 = dockerRule.getClient().inspectContainerCmd(container2.getId())
            .exec();
    LOG.info("Container2 Inspect: {}", inspectContainerResponse2.toString());

    assertThat(inspectContainerResponse2.getConfig(), is(notNullValue()));
    assertThat(inspectContainerResponse2.getId(), not(isEmptyString()));
    assertThat(inspectContainerResponse2.getHostConfig(), is(notNullValue()));
    assertThat(inspectContainerResponse2.getHostConfig().getLinks(), is(notNullValue()));
    assertThat(inspectContainerResponse2.getHostConfig().getLinks(), equalTo(new Link[] {new Link(container1Name,
            container1Name + "Link")}));
    assertThat(inspectContainerResponse2.getId(), startsWith(container2.getId()));
    assertThat(inspectContainerResponse2.getName(), equalTo("/" + container2Name));
    assertThat(inspectContainerResponse2.getImageId(), not(isEmptyString()));
    assertThat(inspectContainerResponse2.getState(), is(notNullValue()));
    assertThat(inspectContainerResponse2.getState().getRunning(), is(true));

}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:59,代码来源:StartContainerCmdIT.java


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