Repository: mesos Updated Branches: refs/heads/master a21d41f13 -> c5f49f629
Added layerid information to ManifestResponse. Review: https://reviews.apache.org/r/38443 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f640188d Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f640188d Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f640188d Branch: refs/heads/master Commit: f640188d2116e7b141a92a52166101fffdaefb82 Parents: a21d41f Author: Jojy Varghese <[email protected]> Authored: Wed Oct 14 08:59:28 2015 +0800 Committer: Timothy Chen <[email protected]> Committed: Wed Oct 14 08:59:28 2015 +0800 ---------------------------------------------------------------------- .../provisioner/docker/registry_client.cpp | 70 +++++++++++++++++++- .../provisioner/docker/registry_client.hpp | 3 +- .../containerizer/provisioner_docker_tests.cpp | 38 +++++++++++ 3 files changed, 108 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/f640188d/src/slave/containerizer/provisioner/docker/registry_client.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/provisioner/docker/registry_client.cpp b/src/slave/containerizer/provisioner/docker/registry_client.cpp index 4931ae8..c6db213 100644 --- a/src/slave/containerizer/provisioner/docker/registry_client.cpp +++ b/src/slave/containerizer/provisioner/docker/registry_client.cpp @@ -288,6 +288,7 @@ Future<Response> RegistryClientProcess::doHttpGet( foreach (const JSON::Value& error, errorObjects.get().values) { Result<JSON::String> message = error.as<JSON::Object>().find<JSON::String>("message"); + if (message.isError()) { return Failure("Failed to parse bad request error message: " + message.error()); @@ -302,6 +303,7 @@ Future<Response> RegistryClientProcess::doHttpGet( out << ", " << message.get().value; } } + return Failure("Received Bad request, errors: [" + out.str() + "]"); } @@ -471,18 +473,82 @@ Future<ManifestResponse> RegistryClientProcess::getManifest( return Error("Failed to find \"fsLayers\" in manifest response"); } + Result<JSON::Array> historyArray = + responseJSON.get().find<JSON::Array>("history"); + + if (historyArray.isNone()) { + return Error("Failed to find \"history\" in manifest response"); + } + + if (historyArray.get().values.size() != fsLayers.get().values.size()) { + return Error( + "\"history\" and \"fsLayers\" array count mismatch" + "in manifest response"); + } + vector<FileSystemLayerInfo> fsLayerInfoList; + size_t index = 0; + foreach (const JSON::Value& layer, fsLayers.get().values) { + if (!layer.is<JSON::Object>()) { + return Error( + "Failed to parse layer as a JSON object for index: " + + stringify(index)); + } + const JSON::Object& layerInfoJSON = layer.as<JSON::Object>(); - Result<JSON::String> blobSumInfo = + + // Get blobsum for layer. + const Result<JSON::String> blobSumInfo = layerInfoJSON.find<JSON::String>("blobSum"); if (blobSumInfo.isNone()) { return Error("Failed to find \"blobSum\" in manifest response"); } + // Get history for layer. + if (!historyArray.get().values[index].is<JSON::Object>()) { + return Error( + "Failed to parse history as a JSON object for index: " + + stringify(index)); + } + const JSON::Object& historyObj = + historyArray.get().values[index].as<JSON::Object>(); + + // Get layer id. + const Result<JSON::String> v1CompatibilityJSON = + historyObj.find<JSON::String>("v1Compatibility"); + + if (!v1CompatibilityJSON.isSome()) { + return Error( + "Failed to obtain layer v1 compability json in manifest for layer: " + + stringify(index)); + } + + Try<JSON::Object> v1CompatibilityObj = + JSON::parse<JSON::Object>(v1CompatibilityJSON.get().value); + + if (!v1CompatibilityObj.isSome()) { + return Error( + "Failed to parse v1 compability json in manifest for layer: " + + stringify(index)); + } + + const Result<JSON::String> id = + v1CompatibilityObj.get().find<JSON::String>("id"); + + if (!id.isSome()) { + return Error( + "Failed to find \"id\" in manifest for layer: " + stringify(index)); + } + fsLayerInfoList.emplace_back( - FileSystemLayerInfo{blobSumInfo.get().value}); + FileSystemLayerInfo{ + blobSumInfo.get().value, + id.get().value, + }); + + index++; } return ManifestResponse { http://git-wip-us.apache.org/repos/asf/mesos/blob/f640188d/src/slave/containerizer/provisioner/docker/registry_client.hpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/provisioner/docker/registry_client.hpp b/src/slave/containerizer/provisioner/docker/registry_client.hpp index fdb68b6..c4f19c3 100644 --- a/src/slave/containerizer/provisioner/docker/registry_client.hpp +++ b/src/slave/containerizer/provisioner/docker/registry_client.hpp @@ -50,7 +50,8 @@ public: struct FileSystemLayerInfo { // TODO(jojy): This string includes the checksum type also now. Need to // separate this into checksum method and checksum. - std::string checksumInfo; + const std::string checksumInfo; + const std::string layerId; }; /** http://git-wip-us.apache.org/repos/asf/mesos/blob/f640188d/src/tests/containerizer/provisioner_docker_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/provisioner_docker_tests.cpp b/src/tests/containerizer/provisioner_docker_tests.cpp index d895eb9..9c3c45a 100644 --- a/src/tests/containerizer/provisioner_docker_tests.cpp +++ b/src/tests/containerizer/provisioner_docker_tests.cpp @@ -490,6 +490,32 @@ TEST_F(RegistryClientTest, SimpleGetManifest) \"sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4\" \ } \ ], \ + \"history\": [ \ + { \ + \"v1Compatibility\": \ + \"{\\\"id\\\": \ + \\\"1ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\\\", \ + \\\"parent\\\": \ + \\\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\\\" \ + }\" \ + }, \ + { \ + \"v1Compatibility\": \ + \"{\\\"id\\\": \ + \\\"2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\\\", \ + \\\"parent\\\": \ + \\\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\\\" \ + }\" \ + }, \ + { \ + \"v1Compatibility\": \ + \"{\\\"id\\\": \ + \\\"3ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea\\\", \ + \\\"parent\\\": \ + \\\"cf2616975b4a3cba083ca99bc3f0bf25f5f528c3c52be1596b30f60b0b1c37ff\\\" \ + }\" \ + } \ + ], \ \"signatures\": [ \ { \ \"header\": { \ @@ -526,6 +552,18 @@ TEST_F(RegistryClientTest, SimpleGetManifest) AWAIT_ASSERT_READY(Socket(socket.get()).send(manifestHttpResponse)); AWAIT_ASSERT_READY(manifestResponseFuture); + + ASSERT_EQ( + manifestResponseFuture.get().fsLayerInfoList[0].layerId, + "1ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea"); + + ASSERT_EQ( + manifestResponseFuture.get().fsLayerInfoList[1].layerId, + "2ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea"); + + ASSERT_EQ( + manifestResponseFuture.get().fsLayerInfoList[2].layerId, + "3ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea"); }
