Exemplo n.º 1
0
 public static CreateDockerContainerMetadata newInstance(
     ContainerConfig containerConfig, ContainerCreateStatus status) {
   List<String> warnings = new ArrayList<String>();
   String[] warningArray = status.getWarnings();
   if (warningArray != null) {
     Collections.addAll(warnings, warningArray);
   }
   return new CreateDockerContainerMetadata(status.getId(), warnings);
 }
Exemplo n.º 2
0
 @Test
 public void testContainerCreate() throws IOException {
   String json = Resources.toString(getResource("container/create-response.json"), Charsets.UTF_8);
   MockWebServer server = new MockWebServer();
   server.enqueue(new MockResponse().setBody(json));
   server.play();
   Docker docker = createDockerForMock(server);
   ContainerConfig cfg = new ContainerConfig();
   cfg.setImage("base");
   cfg.setCmd(new String[] {"date"});
   ContainerCreateStatus containerCreateStatus = docker.containerCreate(cfg, null);
   assertNotNull(containerCreateStatus);
   assertEquals(containerCreateStatus.getId(), "e90e34656806");
 }
 public static CreateDockerContainerMetadata newInstance(
     ContainerConfig containerConfig,
     DockerCreateOptions options,
     ContainerCreateStatus status,
     String containerType) {
   List<String> warnings = new ArrayList<String>();
   String[] warningArray = status.getWarnings();
   if (warningArray != null) {
     Collections.addAll(warnings, warningArray);
   }
   CreateDockerContainerMetadata metadata =
       new CreateDockerContainerMetadata(status.getId(), warnings);
   String containerId = options.getName();
   metadata.setContainerName(containerId);
   metadata.setContainerType(containerType);
   metadata.setOverridenResolver(ZkDefs.MANUAL_IP);
   metadata.setCreateOptions(options);
   return metadata;
 }
Exemplo n.º 4
0
  protected CreateDockerContainerMetadata doCreateDockerContainer(
      CreateDockerContainerOptions options, DockerCreateContainerParameters parameters) {
    ContainerConfig containerConfig = parameters.getContainerConfig();
    Map<String, String> environmentVariables = parameters.getEnvironmentVariables();
    String containerType = parameters.getContainerType();
    String jolokiaUrl = parameters.getJolokiaUrl();
    String name = options.getName();
    String dockerHost = dockerFactory.getDockerHost();
    ContainerCreateStatus status = null;
    CreateDockerContainerMetadata metadata = null;
    try {
      status = docker.containerCreate(containerConfig, name);
      LOG.info("Got status: " + status);
      options = options.updateManualIp(dockerHost);

      metadata = newInstance(containerConfig, options, status, containerType);

      publishZooKeeperValues(options, environmentVariables);

      if (jolokiaUrl != null) {
        metadata.setJolokiaUrl(jolokiaUrl);
        startJolokiaKeepAlive(metadata);
      }
    } catch (Exception e) {
      LOG.info(
          "Failed to create container "
              + name
              + " from config "
              + containerConfig
              + ": "
              + e
              + Dockers.dockerErrorMessage(e),
          e);
      throw e;
    }
    startDockerContainer(status.getId(), options);
    return metadata;
  }