Ejemplo n.º 1
0
void process_lines(vector<string> & lines)
{

    const int nlines = lines.size();  // number of lines
    const int n = nlines - 1; // number of input data
    if (nlines < 2) {
        cout << "number of lines is wrong" << endl;
        exit(EXIT_FAILURE);
    }


    Loader loader; // frontend
    Docker docker; // backend

    for (int i = 0; i < n; ++i) {
        string input = lines[i + 1];
        //cout << input << endl;

        loader.load(input);
        loader.check();

#if 1
        vector<string> tokens = loader.get_tokens();
        for (unsigned int i = 0; i < tokens.size() - 1; ++i)
            cout << tokens[i] << ",";
        cout << tokens[tokens.size() - 1];
#endif
        cout << endl;


        loader.build_complex(docker.complex);
        docker.run();
    }
}
Ejemplo n.º 2
0
Try<Docker*> Docker::create(
    const string& path,
    const string& socket,
    bool validate)
{
  if (!strings::startsWith(socket, "/")) {
    return Error("Invalid Docker socket path: " + socket);
  }

  Docker* docker = new Docker(path, socket);
  if (!validate) {
    return docker;
  }

#ifdef __linux__
  // Make sure that cgroups are mounted, and at least the 'cpu'
  // subsystem is attached.
  Result<string> hierarchy = cgroups::hierarchy("cpu");

  if (hierarchy.isNone()) {
    delete docker;
    return Error("Failed to find a mounted cgroups hierarchy "
                 "for the 'cpu' subsystem; you probably need "
                 "to mount cgroups manually");
  }
#endif // __linux__

  Try<Nothing> validateVersion = docker->validateVersion(Version(1, 0, 0));
  if (validateVersion.isError()) {
    delete docker;
    return Error(validateVersion.error());
  }

  return docker;
}
Ejemplo n.º 3
0
Try<Docker*> Docker::create(const string& path, bool validate)
{
  Docker* docker = new Docker(path);
  if (!validate) {
    return docker;
  }

#ifdef __linux__
  // Make sure that cgroups are mounted, and at least the 'cpu'
  // subsystem is attached.
  Result<string> hierarchy = cgroups::hierarchy("cpu");

  if (hierarchy.isNone()) {
    delete docker;
    return Error("Failed to find a mounted cgroups hierarchy "
                 "for the 'cpu' subsystem; you probably need "
                 "to mount cgroups manually");
  }
#endif // __linux__

  // Validate the version (and that we can use Docker at all).
  Future<Version> version = docker->version();

  if (!version.await(DOCKER_VERSION_WAIT_TIMEOUT)) {
    delete docker;
    return Error("Timed out getting docker version");
  }

  if (version.isFailed()) {
    delete docker;
    return Error("Failed to get docker version: " + version.failure());
  }

  if (version.get() < Version(1, 0, 0)) {
    delete docker;
    return Error("Insufficient version of Docker. Please upgrade to >= 1.0.0");
  }

  return docker;
}
Ejemplo n.º 4
0
// This test tests the functionality of the  docker's interfaces.
TEST(DockerTest, ROOT_DOCKER_interface)
{
  string containerName = "mesos-docker-test";
  Resources resources = Resources::parse("cpus:1;mem:512").get();
  Docker docker = Docker::create(tests::flags.docker, false).get();

  // Cleaning up the container first if it exists.
  Future<Nothing> status = docker.rm(containerName, true);
  ASSERT_TRUE(status.await(Seconds(10)));

  // Verify that we do not see the container.
  Future<list<Docker::Container> > containers = docker.ps(true, containerName);
  AWAIT_READY(containers);
  foreach (const Docker::Container& container, containers.get()) {
    EXPECT_NE("/" + containerName, container.name);
  }

  Try<string> directory = environment->mkdtemp();
  CHECK_SOME(directory) << "Failed to create temporary directory";

  ContainerInfo containerInfo;
  containerInfo.set_type(ContainerInfo::DOCKER);

  ContainerInfo::DockerInfo dockerInfo;
  dockerInfo.set_image("busybox");
  containerInfo.mutable_docker()->CopyFrom(dockerInfo);

  CommandInfo commandInfo;
  commandInfo.set_value("sleep 120");

  // Start the container.
  status = docker.run(
      containerInfo,
      commandInfo,
      containerName,
      directory.get(),
      "/mnt/mesos/sandbox",
      resources);

  AWAIT_READY(status);

  // Should be able to see the container now.
  containers = docker.ps();
  AWAIT_READY(containers);
  bool found = false;
  foreach (const Docker::Container& container, containers.get()) {
    if ("/" + containerName == container.name) {
      found = true;
      break;
    }
  }
  EXPECT_TRUE(found);

  Future<Docker::Container> container = docker.inspect(containerName);
  AWAIT_READY(container);

  // Test some fields of the container.
  EXPECT_NE("", container.get().id);
  EXPECT_EQ("/" + containerName, container.get().name);
  EXPECT_SOME(container.get().pid);

  // Kill the container.
  status = docker.kill(containerName);
  AWAIT_READY(status);

  // Now, the container should not appear in the result of ps().
  // But it should appear in the result of ps(true).
  containers = docker.ps();
  AWAIT_READY(containers);
  foreach (const Docker::Container& container, containers.get()) {
    EXPECT_NE("/" + containerName, container.name);
  }

  containers = docker.ps(true, containerName);
  AWAIT_READY(containers);
  found = false;
  foreach (const Docker::Container& container, containers.get()) {
    if ("/" + containerName == container.name) {
      found = true;
      break;
    }
  }
  EXPECT_TRUE(found);

  // Check the container's info, both id and name should remain the
  // same since we haven't removed it, but the pid should be none
  // since it's not running.
  container = docker.inspect(containerName);
  AWAIT_READY(container);

  EXPECT_NE("", container.get().id);
  EXPECT_EQ("/" + containerName, container.get().name);
  EXPECT_NONE(container.get().pid);

  // Remove the container.
  status = docker.rm(containerName);
  AWAIT_READY(status);

  // Should not be able to inspect the container.
  container = docker.inspect(containerName);
  AWAIT_FAILED(container);

  // Also, now we should not be able to see the container by invoking
  // ps(true).
  containers = docker.ps(true, containerName);
  AWAIT_READY(containers);
  foreach (const Docker::Container& container, containers.get()) {
    EXPECT_NE("/" + containerName, container.name);
  }

  // Start the container again, this time we will do a "rm -f"
  // directly, instead of killing and rm.
  status = docker.run(
      containerInfo,
      commandInfo,
      containerName,
      directory.get(),
      "/mnt/mesos/sandbox",
      resources);

  AWAIT_READY(status);

  // Verify that the container is there.
  containers = docker.ps();
  AWAIT_READY(containers);
  found = false;
  foreach (const Docker::Container& container, containers.get()) {
    if ("/" + containerName == container.name) {
      found = true;
      break;
    }
  }
  EXPECT_TRUE(found);

  // Then do a "rm -f".
  status = docker.rm(containerName, true);
  AWAIT_READY(status);

  // Verify that the container is totally removed, that is we can't
  // find it by ps() or ps(true).
  containers = docker.ps();
  AWAIT_READY(containers);
  foreach (const Docker::Container& container, containers.get()) {
    EXPECT_NE("/" + containerName, container.name);
  }
  containers = docker.ps(true, containerName);
  AWAIT_READY(containers);
  foreach (const Docker::Container& container, containers.get()) {
    EXPECT_NE("/" + containerName, container.name);
  }
}