| 1921 | |
| 1922 | |
| 1923 | string Http::serializeGetExecutors( |
| 1924 | const Owned<ObjectApprovers>& approvers) const |
| 1925 | { |
| 1926 | // Construct framework list with both active and completed frameworks. |
| 1927 | vector<const Framework*> frameworks; |
| 1928 | foreachvalue (Framework* f, slave->frameworks) { |
| 1929 | if (approvers->approved<VIEW_FRAMEWORK>(f->info)) { |
| 1930 | frameworks.push_back(f); |
| 1931 | } |
| 1932 | } |
| 1933 | foreachvalue (const Owned<Framework>& f, slave->completedFrameworks) { |
| 1934 | if (approvers->approved<VIEW_FRAMEWORK>(f->info)) { |
| 1935 | frameworks.push_back(f.get()); |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | // Lambda for serializing the following message: |
| 1940 | // |
| 1941 | // v1::agent::Response::GetExecutors::Executor executor; |
| 1942 | // *executor.mutable_executor_info() = executorInfo; |
| 1943 | auto serializeExecutor = [](const ExecutorInfo& e) { |
| 1944 | string output; |
| 1945 | google::protobuf::io::StringOutputStream stream(&output); |
| 1946 | google::protobuf::io::CodedOutputStream writer(&stream); |
| 1947 | |
| 1948 | WireFormatLite2::WriteMessageWithoutCachedSizes( |
| 1949 | v1::agent::Response::GetExecutors::Executor::kExecutorInfoFieldNumber, |
| 1950 | e, |
| 1951 | &writer); |
| 1952 | |
| 1953 | // While an explicit Trim() isn't necessary (since the coded |
| 1954 | // output stream is destructed before the string is returned), |
| 1955 | // it's a quite tricky bug to diagnose if Trim() is missed, so |
| 1956 | // we always do it explicitly to signal the reader about this |
| 1957 | // subtlety. |
| 1958 | writer.Trim(); |
| 1959 | |
| 1960 | return output; |
| 1961 | }; |
| 1962 | |
| 1963 | // Serialize the following message: |
| 1964 | // |
| 1965 | // v1::agent::Response::GetExecutors getExecutors; |
| 1966 | // for each executor: |
| 1967 | // *getExecutors.add_executors() = executor; |
| 1968 | // for each completed executor: |
| 1969 | // *getExecutors.add_completed_executors() = completed executor; |
| 1970 | |
| 1971 | string output; |
| 1972 | google::protobuf::io::StringOutputStream stream(&output); |
| 1973 | google::protobuf::io::CodedOutputStream writer(&stream); |
| 1974 | |
| 1975 | foreach (const Framework* framework, frameworks) { |
| 1976 | foreachvalue (Executor* executor, framework->executors) { |
| 1977 | if (approvers->approved<VIEW_EXECUTOR>(executor->info, framework->info)) { |
| 1978 | WireFormatLite::WriteBytes( |
| 1979 | v1::agent::Response::GetExecutors::kExecutorsFieldNumber, |
| 1980 | serializeExecutor(executor->info), |
nothing calls this directly
no test coverage detected