Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/12/implement operator calls #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/meson/client/impl/agent/operator.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
(ns meson.client.impl.agent.operator
"v1 Operator HTTP API functions for agents."
(:require [clojure.data.json :as json]
[meson.http.core :as http]
[meson.util.core :as util])
(:import [clojure.lang Keyword]))

(def operator-path "api/v1")

(defn call
"HTTP call to the Mesos operator api."
([this ^Keyword type]
(call this type nil))
([this ^Keyword type payload]
(call this type payload http/json-content-type))
([this ^Keyword type payload content-type]
(call this type payload content-type {}))
([this ^Keyword type payload content-type opts]
(let [data {:type (util/keyword->upper type)
(util/keyword->lower type) payload}]
(http/post
this
operator-path
:body (json/write-str data)
:opts (into opts {:content-type content-type
:accept content-type})))))

(defn add-resource-provider-config [this payload]
:not-implemented)

(defn attach-container-input [this payload]
:not-implemented)

(defn attach-container-output [this payload]
:not-implemented)

(defn get-containers
([this]
:not-implemented)
([this payload]
:not-implemented))

(defn get-resource-providers [this]
:not-implemented)

(defn kill-nested-containers [this payload]
:not-implemented)

(defn launch-nested-container [this payload]
:not-implemented)

(defn launch-nested-container-session [this payload]
:not-implemented)

(defn prune-images
([this]
:not-implemented)
([this payload]
:not-implemented))

(defn remove-nested-container [this payload]
:not-implemented)

(defn remove-resource-provider-config [this payload]
:not-implemented)

(defn update-resource-provider-config [this payload]
:not-implemented)

(defn wait-nested-container [this payload]
:not-implemented)

(def behaviour
{:add-resource-provider-config add-resource-provider-config
:attach-container-input attach-container-input
:attach-container-output attach-container-output
:get-containers get-containers
:get-resource-providers get-resource-providers
:kill-nested-containers kill-nested-containers
:launch-nested-container launch-nested-container
:launch-nested-container-session launch-nested-container-session
:prune-images prune-images
:remove-nested-container remove-nested-container
:remove-resource-provider-config remove-resource-provider-config
:update-resource-provider-config update-resource-provider-config
:wait-nested-container wait-nested-container})
117 changes: 117 additions & 0 deletions src/meson/client/impl/master/operator.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
(ns meson.client.impl.master.operator
"v1 Operator HTTP API functions for masters."
(:require [clojure.data.json :as json]
[meson.http.core :as http]
[meson.util.core :as util])
(:import [clojure.lang Keyword]))

(def operator-path "api/v1")

(defn call
"HTTP call to the Mesos operator api."
([this ^Keyword type]
(call this type nil))
([this ^Keyword type payload]
(call this type payload http/json-content-type))
([this ^Keyword type payload content-type]
(call this type payload content-type {}))
([this ^Keyword type payload content-type opts]
(let [data {:type (util/keyword->upper type)
(util/keyword->lower type) payload}]
(http/post
this
operator-path
:body (json/write-str data)
:opts (into opts {:content-type content-type
:accept content-type})))))

(defn create-volumes
[this payload]
:not-implemented)

(defn deactivate-agent [this payload]
:not-implemented)

(defn destroy-volumes [this payload]
:not-implemented)

(defn drain-agent [this payload]
:not-implemented)

(defn get-agents [this]
:not-implemented)

(defn get-maintenance-schedule [this]
:not-implemented)

(defn get-maintenance-status [this]
:not-implemented)

(defn get-master [this]
:not-implemented)

(defn get-quota [this]
:not-implemented)

(defn get-roles [this]
:not-implemented)

(defn get-weights [this]
:not-implemented)

(defn grow-volume [this payload]
:not-implemented)

(defn mark-agent-gone [this payload]
:not-implemented)

(defn reactivate-agent [this payload]
:not-implemented)

(defn reserve-resources [this payload]
:not-implemented)

(defn shrink-volume [this payload]
:not-implemented)

(defn start-maintenance [this payload]
:not-implemented)

(defn stop-maintenance [this payload]
:not-implemented)

(defn unreserve-resources [this payload]
:not-implemented)

(defn update-maintenance-schedule [this payload]
:not-implemented)

(defn update-quota [this payload]
:not-implemented)

(defn update-weights [this payload]
:not-implemented)

(def behaviour
{:create-volumes create-volumes
:deactivate-agent deactivate-agent
:destroy-volumes destroy-volumes
:drain-agent drain-agent
:get-agents get-agents
:get-maintenance-schedule get-maintenance-schedule
:get-maintenance-status get-maintenance-status
:get-master get-master
:get-quota get-quota
:get-roles get-roles
:get-weights get-weights
:grow-volume grow-volume
:mark-agent-gone mark-agent-gone
:reactivate-agent reactivate-agent
:reserve-resources reserve-resources
:shrink-volume shrink-volume
:start-maintenance start-maintenance
:stop-maintenance stop-maintenance
:unreserve-resources unreserve-resources
:update-maintenance-schedule update-maintenance-schedule
:update-quota update-quota
:update-weights update-weights})
117 changes: 117 additions & 0 deletions src/meson/client/impl/operator.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
(ns meson.client.impl.operator
"v1 Operator HTTP API functions common to masters and agents."
(:require [clojure.data.json :as json]
[meson.http.core :as http]
[meson.util.core :as util])
(:import [clojure.lang Keyword]))

(def operator-path "api/v1")

(defn call
"HTTP call to the Mesos operator api."
([this ^Keyword type]
(call this type nil))
([this ^Keyword type payload]
(call this type payload http/json-content-type))
([this ^Keyword type payload content-type]
(call this type payload content-type {}))
([this ^Keyword type payload content-type opts]
(let [data {:type (util/keyword->upper type)
(util/keyword->lower type) payload}]
(http/post
this
operator-path
:body (json/write-str data)
:opts (into opts {:content-type content-type
:accept content-type})))))

(defn get-executors
"Queries about all the executors known to the master/agent."
[this]
(call this :get-executors))

(defn get-flags
"Retrieve the master/agent overall flag configuration."
[this]
(call this :get-flags))

(defn get-frameworks
"Retrieve information about all the frameworks known to the master/agent."
[this]
(call this :get-frameworks))

(defn get-health
"Retrieve health status of the master/agent."
[this]
(call this :get-health))

(defn get-logging-level
"Retrieve the master/agent logging level."
[this]
(call this :get-logging-level))

(defn get-metrics
"Snapshot of the current metrics. If the optional `timeout` is set in the call,
it will be used to determine the maximum amount of time the API will take to respond.
Some metrics may not be included if the timeout is exceeded."
([this]
(call this :get-metrics))
([this payload]
(call this :get-metrics payload)))

(defn get-operations
"List of all offer operations throughout the cluster (master API) or known to the
agent (agent API). Does not including LAUNCH or LAUNCH_GROUP, which can be retrieved
with get-tasks."
[this]
(call this :get-operations))

(defn get-state
"Retrieve overall cluster state (master API) or full state of the agent (agent API)."
[this]
(call this :get-state))

(defn get-tasks
"All tasks known to the master or agent."
[this]
(call this :get-tasks))

(defn get-version
"Retrieve master/agent version information."
[this]
(call this :get-version))

(defn list-files
"Retrieve file listing for a directory `path` in the master/agent."
[this payload]
(call this :list-files payload))

(defn read-file
"Reads data from a file on the master/agent. This call takes the `path` of the
file to be read, the `offset` to start reading, and the maximum number of
bytes to read (`length`)."
[this payload]
(call this :read-file payload))

(defn set-logging-level
"Sets logging verbosity `level` for a specified `duration`. Mesos uses glog for logging.
(https://github.com/google/glog)
The library only uses verbose logging which means nothing will be output unless the
verbosity level is set (by default it's 0, libprocess uses levels 1,2, and 3)."
[this payload]
(call this :set-logging-level payload))

(def behaviour
{:get-executors get-executors
:get-flags get-flags
:get-frameworks get-frameworks
:get-health get-health
:get-logging-level get-logging-level
:get-metrics get-metrics
:get-operations get-operations
:get-state get-state
:get-tasks get-tasks
:get-version get-version
:list-files list-files
:read-file read-file
:set-logging-level set-logging-level})
69 changes: 69 additions & 0 deletions src/meson/protocols/agent/operator.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(ns meson.protocols.agent.operator
"Mesos HTTP v1 Operator API endpoints for agents.

v1 Operator master endpoints:
https://mesos.apache.org/documentation/latest/operator-http-api/#agent-api"

(:refer-clojure :exclude [read]))

(defprotocol IAgentOperator
"v1 Operator Interface endpoints for agents.

See:
* https://mesos.apache.org/documentation/latest/operator-http-api/#agent-api"

(add-resource-provider-config [this payload]
"This call launches a Local Resource Provider on the agent with the specified ResourceProviderInfo.
* https://mesos.apache.org/documentation/latest/operator-http-api/#add_resource_provider_config")

(attach-container-input [this payload]
"This call attaches to the STDIN of the primary process of a container and streams input to it.
* https://mesos.apache.org/documentation/latest/operator-http-api/#attach_container_input")

(attach-container-output [this payload]
"This call attaches to the STDOUT and STDERR of the primary process of a container and streams
its output back to the client.
* https://mesos.apache.org/documentation/latest/operator-http-api/#attach_container_output")

(get-containers [this] [this payload]
"This call retrieves information about containers running on this agent.
* https://mesos.apache.org/documentation/latest/operator-http-api/#get_containers")

(get-resource-providers [this]
"This call retrieves information about all the resource providers known to the agent.
* https://mesos.apache.org/documentation/latest/operator-http-api/#get_resource_providers")

(kill-nested-containers [this payload]
"This call initiates the destruction of a nested container.
* https://mesos.apache.org/documentation/latest/operator-http-api/#kill_nested_container")

(launch-nested-container [this payload]
"This call launches a nested container.
* https://mesos.apache.org/documentation/latest/operator-http-api/#launch_nested_container")

(launch-nested-container-session [this payload]
"This call launches a nested container whose lifetime is tied to the lifetime of the HTTP
call establishing this connection.
* https://mesos.apache.org/documentation/latest/operator-http-api/#launch_nested_container_session")

(prune-images [this] [this payload]
"This call triggers garbage collection for container images.
* https://mesos.apache.org/documentation/latest/operator-http-api/#prune_images")

(remove-nested-container [this payload]
"This call triggers the removal of a nested container and its artifacts
(e.g., the sandbox and runtime directories).
* https://mesos.apache.org/documentation/latest/operator-http-api/#remove_nested_container")

(remove-resource-provider-config [this payload]
"This call terminates a given Local Resource Provider on the agent and prevents it from
being launched again until the config is added back.
* https://mesos.apache.org/documentation/latest/operator-http-api/#remove_resource_provider_config")

(update-resource-provider-config [this payload]
"This call updates a Local Resource Provider on the agent with the specified ResourceProviderInfo.
* https://mesos.apache.org/documentation/latest/operator-http-api/#update_resource_provider_config")

(wait-nested-container [this payload]
"This call waits for a nested container to terminate or exit.
* https://mesos.apache.org/documentation/latest/operator-http-api/#wait_nested_container"))
Loading