You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/11/15 08:13:36 UTC

[12/15] mesos git commit: Changed failure response of LAUNCH containers API.

Changed failure response of LAUNCH containers API.

By default, the HTTP handlers in libprocess will translate failures
(of returned Futures) into '500 Internal Server Error'.  This commit
only changes the `LAUNCH_NESTED_CONTAINER` and `LAUNCH_CONTAINER` APIs
to return '400 Bad Request' instead when the container launch fails,
as it is more likely for the failure to be a user-input error.

Review: https://reviews.apache.org/r/63058


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/89258c04
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/89258c04
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/89258c04

Branch: refs/heads/master
Commit: 89258c04497af293b9b3aeac2e83a73d6b1141fb
Parents: fd4b9af
Author: Joseph Wu <jo...@apache.org>
Authored: Mon Oct 16 10:44:01 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Tue Nov 14 17:16:21 2017 -0800

----------------------------------------------------------------------
 src/slave/http.cpp                      |  5 ++++
 src/tests/agent_container_api_tests.cpp | 37 ++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/89258c04/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index e4fa4df..ff6d21d 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -2554,6 +2554,11 @@ Future<Response> Http::_launchContainer(
         return BadRequest("The provided ContainerInfo is not supported");
       }
       return OK();
+    })
+    .repair([](const Future<Response>& launch) {
+      // NOTE: Failures are automatically translated into 500 Internal Server
+      // Errors, but a launch failure is likely due to user input.
+      return BadRequest(launch.failure());
     });
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/89258c04/src/tests/agent_container_api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/agent_container_api_tests.cpp b/src/tests/agent_container_api_tests.cpp
index 6b9bace..531ec73 100644
--- a/src/tests/agent_container_api_tests.cpp
+++ b/src/tests/agent_container_api_tests.cpp
@@ -623,6 +623,43 @@ TEST_P_TEMP_DISABLED_ON_WINDOWS(AgentContainerAPITest, NestedContainerNotFound)
 }
 
 
+// This test runs tries to launch a nested container that fails upon
+// launch (rather than validation) and expects a 400 Bad Request in response.
+TEST_P_TEMP_DISABLED_ON_WINDOWS(
+    AgentContainerAPITest, NestedContainerFailLaunch)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+
+  slave::Flags slaveFlags = CreateSlaveFlags();
+  slaveFlags.launcher = std::get<1>(std::get<3>(GetParam()));
+  slaveFlags.isolation = std::get<0>(std::get<3>(GetParam()));
+
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
+  ASSERT_SOME(slave);
+
+  Try<v1::ContainerID> parentContainerId =
+    launchParentContainer(master.get()->pid, slave.get()->pid);
+
+  ASSERT_SOME(parentContainerId);
+
+  // Launch a nested container that needs to fetch a URI that
+  // doesn't exist. The launch should therefore fail.
+  v1::ContainerID containerId;
+  containerId.set_value(UUID::random().toString());
+  containerId.mutable_parent()->CopyFrom(parentContainerId.get());
+
+  mesos::v1::CommandInfo commandInfo;
+  commandInfo.add_uris()->set_value("This file doesn't exist");
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(
+      http::BadRequest().status,
+      launchNestedContainer(slave.get()->pid, containerId, commandInfo));
+}
+
+
 // This test attempts to give invalid ContainerInfo when launching a
 // nested container. The invalid nested container LAUNCH call is expected
 // to give a 400 Bad Request, but the parent container should be otherwise