diff --git a/.gitignore b/.gitignore index 3c3629e..fc5952d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +*.sublime* diff --git a/api/apps.js b/api/apps.js new file mode 100644 index 0000000..1fed6bf --- /dev/null +++ b/api/apps.js @@ -0,0 +1,84 @@ +'use strict' + +class MarathonApiAppEndpoints { + constructor (ctx) { // accepts a parent context + this.parent = ctx + this.baseURL = ctx.baseURL + this.baseURL.pathname = `${ctx.basePath}/apps` + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + async getList (query = {}) { + const params = new URLSearchParams(Object.entries(query)) + const { data } = await this.client.get('', { params }) + return data + } + + async create (data) { + const { data: result } = await this.client.post('', data) + return result + } + + async getOne (appId, query = {}) { + const params = new URLSearchParams(Object.entries(query)) + const path = encodeURIComponent(appId) + const { data } = await this.client.get(path, { params }) + return data + } + + async update (appId, data, force) { + const params = new URLSearchParams([['force', !!force]]) + const path = encodeURIComponent(appId) + const { data: result } = await this.client.put(path, data, { params }) + return result + } + + async destroy (appId, force) { + const params = new URLSearchParams([['force', !!force]]) + const path = encodeURIComponent(appId) + const { data } = await this.client.delete(path, undefined, { params }) + return data + } + + async restart (appId, force) { + const params = new URLSearchParams([['force', !!force]]) + const path = `${encodeURIComponent(appId)}/restart` + const { data } = await this.client.post(path, undefined, { params }) + return data + } + + async getTasks (appId) { + const path = `${encodeURIComponent(appId)}/tasks` + const { data } = await this.client.get(`${path}/tasks`) + return data + } + + async killTasks (appId, query = {}) { + const params = new URLSearchParams(Object.entries(query)) + const path = `${encodeURIComponent(appId)}/tasks` + const { data } = await this.client.delete(path, undefined, { params }) + return data + } + + async killTask (appId, taskId, scale) { + const params = new URLSearchParams([['scale', !!scale]]) + const path = `${encodeURIComponent(appId)}/tasks/${taskId}` + const { data } = await this.client.delete(path, undefined, { params }) + return data + } + + async getVersions (appId) { + const path = `${encodeURIComponent(appId)}/versions` + const { data } = await this.client.get(path) + return data + } + + async getVersion (appId, versionId) { + const path = `${encodeURIComponent(appId)}/versions/${versionId}` + const { data } = await this.client.get(path) + return data + } +} + +module.exports = MarathonApiAppEndpoints diff --git a/api/artifacts.js b/api/artifacts.js new file mode 100644 index 0000000..07c254d --- /dev/null +++ b/api/artifacts.js @@ -0,0 +1,6 @@ +module.exports = function createMethods (makeRequest) { + return { + // /v2/artifacts todo + // /v2/artifacts/{path} todo + } +} diff --git a/api/deployments.js b/api/deployments.js new file mode 100644 index 0000000..33ef6cc --- /dev/null +++ b/api/deployments.js @@ -0,0 +1,24 @@ +'use strict' + +class MarathonApiDeploymentEndpoints { + constructor (ctx) { // accepts a parent context + this.parent = ctx + this.baseURL = ctx.baseURL + this.baseURL.pathname = `${ctx.basePath}/deployments` + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + async getList () { + const { data } = await this.client.get() + return data + } + + async destroy (deploymentId, force) { + const params = new URLSearchParams([['force', force]]) + const { data } = await this.client.delete(deploymentId, { params }) + return data + } +} + +module.exports = MarathonApiDeploymentEndpoints diff --git a/api/events.js b/api/events.js new file mode 100644 index 0000000..4073069 --- /dev/null +++ b/api/events.js @@ -0,0 +1,32 @@ +'use strict' + +var EventSource = require('eventsource') + +class MarathonEventSource { + constructor (ctx) { // accepts a parent context + this.basePath = ctx.basePath + this.baseURL = ctx.baseURL + this.baseURL.pathname = this.path + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + get path () { return `${this.basePath}/events` } + + // the constructor url should contain credentials and the api basepath '/v2' + createEventSource (opts = {}) { + this.baseURL.pathname = this.path // make sure we have a good path + const { eventType } = opts + if (eventType) { + if (typeof eventType === 'string') { + this.baseURL.searchParams.set('event_type', eventType) + } else if (eventType instanceof Array) { // array + for (const type of eventType) { this.baseURL.searchParams.append('event_type', type) } + } // ignore anything that isn't a string or array + } + this.es = new EventSource(`${this.baseURL}`) + return this.es + } +} + +module.exports = MarathonEventSource diff --git a/api/groups.js b/api/groups.js new file mode 100644 index 0000000..7fb654f --- /dev/null +++ b/api/groups.js @@ -0,0 +1,40 @@ +'use strict' + +class MarathonApiGroupEndpoints { + constructor (ctx) { // accepts a parent context + this.parent = ctx + this.baseURL = ctx.baseURL + this.baseURL.pathname = `${ctx.basePath}/groups` + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + async getList () { + const { data } = await this.client.get() + return data + } + + async create (data) { + const { data: result } = await this.client.post('', { json: data }) + return result + } + + async getOne (groupId) { + const { data } = await this.client.get(groupId) + return data + } + + async update (groupId, data, force) { + const params = new URLSearchParams([['force', force]]) + const { data: result } = await this.client.put(groupId, { json: data }, { params }) + return result + } + + async destroy (groupId, force) { + const params = new URLSearchParams([['force', force]]) + const { data } = await this.client.delete(groupId, undefined, { params }) + return data + } +} + +module.exports = MarathonApiGroupEndpoints diff --git a/api/info.js b/api/info.js new file mode 100644 index 0000000..a55c51a --- /dev/null +++ b/api/info.js @@ -0,0 +1,18 @@ +'use strict' + +class MarathonApiInfoEndpoints { + constructor (ctx) { // accepts a parent context + this.parent = ctx + this.baseURL = ctx.baseURL + this.baseURL.pathname = `${ctx.basePath}/info` + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + async get (timeout = 1000) { + const { data } = await this.client.get('', { timeout }) + return data + } +} + +module.exports = MarathonApiInfoEndpoints diff --git a/api/leader.js b/api/leader.js new file mode 100644 index 0000000..951db6e --- /dev/null +++ b/api/leader.js @@ -0,0 +1,23 @@ +'use strict' + +class MarathonApiLeaderEndpoints { + constructor (ctx) { // accepts a parent context + this.parent = ctx + this.baseURL = ctx.baseURL + this.baseURL.pathname = `${ctx.basePath}/leader` + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + async get () { + const { data } = await this.client.get() + return data + } + + async abdicate () { + const { data } = await this.client.delete() + return data + } +} + +module.exports = MarathonApiLeaderEndpoints diff --git a/api/misc.js b/api/misc.js new file mode 100644 index 0000000..9de791f --- /dev/null +++ b/api/misc.js @@ -0,0 +1,25 @@ +'use strict' + +class MarathonApiMiscEndpoints { + constructor (ctx) { // accepts a parent context + this.parent = ctx + this.baseURL = ctx.baseURL + this.baseURL.pathname = '/' // these endpoints don't get the version prefix + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + async ping (timeout = 300) { + this.timeToken = '/ping' + const { data } = await this.client.get('ping', { timeout }) + return data + } + + async metrics () { + this.timeToken = '/metrics' + const { data } = await this.client.get('metrics') + return data + } +} + +module.exports = MarathonApiMiscEndpoints diff --git a/api/queue.js b/api/queue.js new file mode 100644 index 0000000..1e2a283 --- /dev/null +++ b/api/queue.js @@ -0,0 +1,23 @@ +'use strict' + +class MarathonApiQueueEndpoints { + constructor (ctx) { // accepts a parent context + this.parent = ctx + this.baseURL = ctx.baseURL + this.baseURL.pathname = `${ctx.basePath}/queue` + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + async get () { + const { data } = await this.client.get() + return data + } + + async resetDelay (appId) { + const { data } = await this.client.delete(`${appId}/delay`) + return data + } +} + +module.exports = MarathonApiQueueEndpoints diff --git a/api/tasks.js b/api/tasks.js new file mode 100644 index 0000000..956f6e6 --- /dev/null +++ b/api/tasks.js @@ -0,0 +1,24 @@ +'use strict' + +class MarathonApiTaskEndpoints { + constructor (ctx) { // accepts a parent context + this.parent = ctx + this.baseURL = ctx.baseURL + this.baseURL.pathname = `${ctx.basePath}/tasks` + this.client = ctx.http + this.client.defaults.baseURL = this.baseURL.toString() + } + + async getList () { + const { data } = await this.client.get() + return data + } + + async kill (data, scale, wipe) { + const params = new URLSearchParams(Object.entries({ scale, wipe })) + const { data: result } = await this.client.post('delete', { json: data }, { params }) + return result + } +} + +module.exports = MarathonApiTaskEndpoints diff --git a/index.js b/index.js index 734afe8..cc8e377 100644 --- a/index.js +++ b/index.js @@ -1 +1,86 @@ -module.exports = require('./lib/marathon'); \ No newline at end of file +'use strict' + +const axios = require('axios') + +const MARATHON_API_VERSION = 'v2' +// http api endpoints +const MarathonApiAppEndpoints = require('./api/apps') +const MarathonApiDeploymentEndpoints = require('./api/deployments') +const MarathonApiGroupEndpoints = require('./api/groups') +const MarathonApiTaskEndpoints = require('./api/tasks') +const MarathonApiInfoEndpoints = require('./api/info') +const MarathonApiQueueEndpoints = require('./api/queue') +const MarathonApiMiscEndpoints = require('./api/misc') +const MarathonApiLeaderEndpoints = require('./api/leader') + +// EventSource +const MarathonEventSource = require('./api/events') + +// not yet implemented so no need to require here +// var artifacts = require('./artifacts') + +// helper functions +const { omit } = require('./lib/nodash') + +const contentType = 'application/json' + +// configure axios defaults +axios.defaults.headers.common.Accept = contentType +axios.defaults.headers.post['Content-Type'] = contentType +axios.defaults.headers.put['Content-Type'] = contentType +axios.defaults.headers.delete['Content-Type'] = contentType +/** + * https://mesosphere.github.io/marathon/docs/rest-api.html + */ +class MarathonApi { + get basePath () { return `/${MARATHON_API_VERSION}` } + + get http () { // returns an http client + const client = axios.create({ + ...this.defaults, + baseURL: this.baseURL.toString() + }) + if (this.logTime) { + client.interceptors.request.use(async config => this.timeTracker(config)) + client.interceptors.response.use(async res => this.timeTracker(res)) + } + return client + } + + constructor (baseURL, opts = {}) { + this.logTime = opts.logTime + this.defaults = omit(opts, 'logTime') // setup options without the logTime + + this.baseURL = new URL(`${baseURL}`) // if it's already a url object create a new copy + this.baseURL.pathname = this.basePath + + // initialize the api endpoints + this.app = new MarathonApiAppEndpoints(this) + this.apps = this.app // alias for app + this.deployments = new MarathonApiDeploymentEndpoints(this) + this.events = new MarathonEventSource(this) + this.groups = new MarathonApiGroupEndpoints(this) + this.tasks = new MarathonApiTaskEndpoints(this) + this.info = new MarathonApiInfoEndpoints(this) + this.queue = new MarathonApiQueueEndpoints(this) + this.misc = new MarathonApiMiscEndpoints(this) + this.leader = new MarathonApiLeaderEndpoints(this) + this.timers = {} // key/object pairing of timer tokens + } + + async timeTracker (c) { + if (this.logTime && !c.status) { + const { pathname } = new URL(c.baseURL) + if (!(pathname in this.timers)) { + this.timers[pathname] = `Marathon Request Timer: ${pathname}` + } + console.time(this.timers[pathname]) + } else if (this.logTime && c?.status) { + const { request: { path } } = c + console.timeEnd(this.timers[path]) + } + return c + } +} + +module.exports = MarathonApi diff --git a/lib/apps.js b/lib/apps.js deleted file mode 100644 index a941a9f..0000000 --- a/lib/apps.js +++ /dev/null @@ -1,51 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/apps - getList: function getList(query) { - return makeRequest('GET', '/apps')(query); - }, - create: function create(body) { - return makeRequest('POST', '/apps')(null, body); - }, - - // /v2/apps/{app_id} - getOne: function getOne(appId, query) { - return makeRequest('GET', '/apps/' + appId)(query); - }, - update: function update(appId, body, force) { - return makeRequest('PUT', '/apps/' + appId)({force: force}, body); - }, - destroy: function destroy(appId, force) { - return makeRequest('DELETE', '/apps/' + appId)({force: force}); - }, - - // /v2/apps/{app_id}/restart - restart: function restart(appId, force) { - return makeRequest('POST', '/apps/' + appId + '/restart')({force: force}); - }, - - // /v2/apps/{app_id}/tasks - getTasks: function getTasks(appId) { - return makeRequest('GET', '/apps/' + appId + '/tasks')(); - }, - - killTasks: function killTasks(appId, parameters) { - return makeRequest('DELETE', '/apps/' + appId + '/tasks')(parameters); - }, - - // /v2/apps/{app_id}/tasks/{task_id} - killTask: function killTask(appId, taskId, scale) { - return makeRequest('DELETE', '/apps/' + appId + '/tasks/' + taskId)({scale: scale}); - }, - - // /v2/apps/{app_id}/versions - getVersions: function getVersions(appId) { - return makeRequest('GET', '/apps/' + appId + '/versions')(); - }, - - // /v2/apps/{app_id}/versions/{version} - getVersion: function getVersion(appId, versionId) { - return makeRequest('GET', '/apps/' + appId + '/versions/' + versionId)(); - } - }; -}; diff --git a/lib/artifacts.js b/lib/artifacts.js deleted file mode 100644 index 447aeb2..0000000 --- a/lib/artifacts.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/artifacts todo - // /v2/artifacts/{path} todo - }; -}; diff --git a/lib/deployments.js b/lib/deployments.js deleted file mode 100644 index bf3de2b..0000000 --- a/lib/deployments.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/deployments - getList: function getList() { - return makeRequest('GET', '/deployments')(); - }, - // /v2/deployments/{deployment_id} - destroy: function destroy(deploymentId, force) { - return makeRequest('DELETE', '/deployments/' + deploymentId)({force: force}); - } - }; -}; diff --git a/lib/events.js b/lib/events.js deleted file mode 100644 index 57a8f65..0000000 --- a/lib/events.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -var util = require('util'); -var EventSource = require('eventsource'); -var nodeUrl = require('url'); -var _ = require('lodash'); - -module.exports = function createMethods(makeRequest, url) { - return { - // /v2/events - attach: util.deprecate(function attach() { - return makeRequest('GET', '/events', {headers: {Accept: 'text/event-stream'}}, true)(); - }, '"events.attach()" is deprecated in favor of "events.createEventSource()"'), - - createEventSource: function createEventSource(opts) { - opts = opts || {}; - - url.query = url.query || {}; - - var eventType = opts.eventType; - if (eventType) { - if (!_.isString(eventType) && !_.isArray(eventType)) { - throw new Error('"eventType" should be a string or an array'); - } - - url.query.event_type = eventType; - } - return new EventSource(nodeUrl.format(url), opts); - } - }; -}; diff --git a/lib/groups.js b/lib/groups.js deleted file mode 100644 index a9de320..0000000 --- a/lib/groups.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/groups - getList: function getList() { - return makeRequest('GET', '/groups')(); - }, - create: function create(body) { - return makeRequest('POST', '/groups')(null, body); - }, - // /v2/groups/{group_id} - getOne: function getOne(groupId) { - return makeRequest('GET', '/groups/' + groupId)(); - }, - update: function update(groupId, body, force) { - return makeRequest('PUT', '/groups/' + groupId)({force: force}, body); - }, - destroy: function destroy(groupId, force) { - return makeRequest('DELETE', '/groups/' + groupId)({force: force}); - } - }; -}; diff --git a/lib/info.js b/lib/info.js deleted file mode 100644 index 5ae80d5..0000000 --- a/lib/info.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/info - get: function get() { - return makeRequest('GET', '/info')(); - } - }; -}; diff --git a/lib/leader.js b/lib/leader.js deleted file mode 100644 index 9df2fb6..0000000 --- a/lib/leader.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/leader - get: function get() { - return makeRequest('GET', '/leader')(); - }, - abdicate: function abdicate() { - return makeRequest('DELETE', '/leader')(); - } - }; -}; diff --git a/lib/marathon.js b/lib/marathon.js deleted file mode 100644 index e2ff921..0000000 --- a/lib/marathon.js +++ /dev/null @@ -1,111 +0,0 @@ -'use strict'; - -var rp = require('request-promise'); -var request = require('request'); -var Promise = require('bluebird'); -var _ = require('lodash'); -var nodeUrl = require('url'); -var nodePath = require('path'); - -var API_VERSION = 'v2'; -var PATHS_WITHOUT_PREFIX = ['/ping', '/metrics']; - -var apps = require('./apps'); -var deployments = require('./deployments'); -var groups = require('./groups'); -var tasks = require('./tasks'); -var artifacts = require('./artifacts'); -var events = require('./events'); -var subscriptions = require('./subscriptions'); -var info = require('./info'); -var leader = require('./leader'); -var queue = require('./queue'); -var misc = require('./misc'); - -/** - * https://mesosphere.github.io/marathon/docs/rest-api.html - */ -function Marathon(baseUrl, opts) { - opts = opts || {}; - - var baseOptions = { - json: true - }; - - _.assign(baseOptions, _.omit(opts, 'logTime')); - - function getRequestUrl(path) { - if (PATHS_WITHOUT_PREFIX.indexOf(path) < 0) { - path = nodePath.join('/', API_VERSION, path); - } - - var result = nodeUrl.parse(baseUrl); - result.pathname = nodePath.join(result.pathname, path); - return result; - } - - function makeRequest(method, path, addOptions, requestStream) { - return function closure(query, body) { - var requestOptions = _.cloneDeep(baseOptions); - - requestOptions.method = method; - requestOptions.qs = query; - requestOptions.url = nodeUrl.format(getRequestUrl(path)); - - if (addOptions) { - requestOptions = _.extend(requestOptions, addOptions); - } - - requestOptions.body = body; - - var consoleTimeToken = 'Request to Marathon ' + path; - - if (opts.logTime) { - console.time(consoleTimeToken); - } - - function logTime() { - if (opts.logTime) { - console.timeEnd(consoleTimeToken); - } - } - - if (requestStream) { - return new Promise(function createPromise(resolve, reject) { - request[method.toLowerCase()](requestOptions) - .on('error', function onError(err) { - return reject(err); - }) - .on('response', function onResponse(readableStream) { - readableStream.on('end', function onEnd() { - logTime(); - }); - return resolve(readableStream); - }); - }); - } - - return rp(requestOptions).finally(logTime); - }; - } - - var client = { - app: apps(makeRequest), - deployments: deployments(makeRequest), - groups: groups(makeRequest), - tasks: tasks(makeRequest), - artifacts: artifacts(makeRequest), - events: events(makeRequest, getRequestUrl('/events')), - subscriptions: subscriptions(makeRequest), - info: info(makeRequest), - leader: leader(makeRequest), - queue: queue(makeRequest), - misc: misc(makeRequest) - }; - - client.apps = client.app; - - return client; -} - -module.exports = Marathon; diff --git a/lib/misc.js b/lib/misc.js deleted file mode 100644 index 944cd57..0000000 --- a/lib/misc.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /ping - ping: function ping(addOptions) { - return makeRequest('GET', '/ping', addOptions)(); - } - }; -}; diff --git a/lib/nodash.js b/lib/nodash.js new file mode 100644 index 0000000..8b7bcbd --- /dev/null +++ b/lib/nodash.js @@ -0,0 +1,132 @@ +// disabled so we can use `with` in the template function +// for now until a better solution presents itself +// 'use strict' + +// const AsyncFunction = (async () => {}).constructor + +const omit = function (obj, ...keys) { + const keysToRemove = new Set(keys.flat()) // flatten the props, and convert to a Set + + return Object.fromEntries( // convert the entries back to object + Object.entries(obj) // convert the object to entries + .filter(([k]) => !keysToRemove.has(k)) // remove entries with keys that exist in the Set + ) +} + +// maps an object similarly to lodash.map function +const mapObject = function (obj, fun) { + if (!fun) fun = (...opts) => opts + return Object.entries(obj).map(v => fun(...v)) +} + +const isObject = obj => (obj !== null && typeof obj === 'object') + +// determine whether or not an object is empty +const emptyObj = obj => Object.keys(obj).length === 0 + +const isEqual = (o1, o2) => { // deep object comparison + if (isObject(o1) && isObject(o2)) { + const k1 = Object.keys(o1) + const k2 = Object.keys(o2) + const keq = difference(k1, k2) + if (keq.length) return false // key difference, easy + for (const k of k1) { + const v1 = k1[k] + const v2 = k2[k] + const deep = (isObject(v1) && isObject(v2)) + if ((deep && !isEqual(v1, v2)) || (!deep && v1 !== v2)) return false + } + return true + } + return (o1 === o2) // basic comparison +} + +const pick = (obj, ...keys) => { + const result = {} + for (const key of keys) { + result[key] = obj[key] + } + return result +} + +const difference = (a, b) => a.filter(x => !b.includes(x)) + +const union = (...arrays) => [...new Set([...arrays.flat()])] + +const unionBy = (...input) => { + const output = [] + const x = input.pop() + for (const a of input) { + for (const i of a) { + if (i?.[x]) { + const f = output.find(y => y?.[x] === i?.[x]) + if (!f) output.push(i) + } + } + } + return output +} + +const debounce = function (fn, delay) { + let timer = null + return function () { + clearTimeout(timer) + timer = setTimeout(() => fn.apply(this, arguments), delay) + } +} + +const throttle = function (fn, threshold, scope) { + threshold || (threshold = 250) + scope || (scope = this) + let last + let deferTimer + let result + return async function Throttled () { + const now = +new Date() + if (last && now < last + threshold) { + clearTimeout(deferTimer) + deferTimer = setTimeout(async () => { + last = now + result = await fn.apply(scope, arguments) + }, threshold) + } else { + last = now + result = await fn.apply(scope, arguments) + } + return result + } +} + +const partition = function (col, fn) { + return [...col].reduce((acc, value, key) => { + acc[fn(value, key) ? 0 : 1].push(value) + return acc + }, [[], []]) +} + +// returns a function with some of it's arguments filled out +const partial = (fn, ...params) => (...more) => fn(...params, ...more) + +// probably not suitable for anything with unsanitized user input +const template = (t) => function (params = {}) { + with (params) { + return eval(`\`${t}\``) + } +} + +module.exports = { + isObject, + isEqual, + emptyObj, + debounce, + difference, + mapObject, + omit, + partial, + partition, + pick, + template, + throttle, + union, + unionBy +} diff --git a/lib/queue.js b/lib/queue.js deleted file mode 100644 index df33001..0000000 --- a/lib/queue.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/queue - get: function get() { - return makeRequest('GET', '/queue')(); - }, - // /v2/queue/{app_id}/delay - resetDelay: function resetDelay(appId) { - return makeRequest('DELETE', '/queue/' + appId + '/delay')(); - } - }; -}; diff --git a/lib/subscriptions.js b/lib/subscriptions.js deleted file mode 100644 index d61da71..0000000 --- a/lib/subscriptions.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/eventSubscriptions - getList: makeRequest('GET', '/eventSubscriptions'), - create: function create(callbackUrl) { - return makeRequest('POST', '/eventSubscriptions')({callbackUrl: callbackUrl}); - }, - delete: function deleteSubscription(callbackUrl) { - return makeRequest('DELETE', '/eventSubscriptions')({callbackUrl: callbackUrl}); - } - }; -}; diff --git a/lib/tasks.js b/lib/tasks.js deleted file mode 100644 index 19a8461..0000000 --- a/lib/tasks.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function createMethods(makeRequest) { - return { - // /v2/tasks - getList: function getList() { - return makeRequest('GET', '/tasks')(); - }, - // /v2/tasks/delete - kill: function kill(body, scale, wipe) { - return makeRequest('POST', '/tasks/delete')({scale: scale, wipe: wipe}, body); - } - }; -}; diff --git a/package.json b/package.json index 361fdab..e9b0f87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "marathon-node", - "version": "1.1.0", + "version": "2.0.1", "description": "Node.js client library for Mesos Marathon's REST API", "main": "index.js", "scripts": { @@ -11,20 +11,17 @@ }, "repository": { "type": "git", - "url": "https://github.com/elasticio/marathon-node.git" + "url": "https://github.com/AppliedTrust/marathon-node.git" }, - "author": "elastic.io", + "author": "AppliedTrust", "license": "ISC", "bugs": { - "url": "https://github.com/elasticio/marathon-node/issues" + "url": "https://github.com/AppliedTrust/marathon-node/issues" }, - "homepage": "https://github.com/elasticio/marathon-node", + "homepage": "https://github.com/AppliedTrust/marathon-node", "dependencies": { - "bluebird": "^3.4.7", - "eventsource": "^1.0.4", - "lodash": "^4.0.0", - "request": "2.75.x", - "request-promise": "^3.0.0" + "axios": "^1.3.4", + "eventsource": "^2.0.2" }, "devDependencies": { "chai": "^3.5.0", diff --git a/postpublish.js b/postpublish.js index c966663..4a1076b 100755 --- a/postpublish.js +++ b/postpublish.js @@ -1,24 +1,24 @@ #! /usr/bin/env node -'use strict'; +'use strict' -var execSync = require('child_process').execSync; -var version = require('./package.json').version; +var { execSync } = require('child_process') +var { version } = require('./package.json') if (!version) { - console.error('Can not determine current version'); - process.exit(0); + console.error('Can not determine current version') + process.exit(0) } -var tag = 'v' + version; +var tag = 'v' + version try { - // if grep not found anything, it's exit code isn't zero, so execSync raises an Error - execSync('git tag | grep "' + tag + '"'); - // it seems tag is found, do nothing - process.exit(0); + // if grep not found anything, it's exit code isn't zero, so execSync raises an Error + execSync('git tag | grep "' + tag + '"') + // it seems tag is found, do nothing + process.exit(0) } catch (e) { - // grep found nothing, so le'ts create new tag - console.info('creating a new tag: ', tag); - execSync('git tag ' + tag); - console.info('pushing tag to origin: ', tag); - execSync('git push origin ' + tag); + // grep found nothing, so le'ts create new tag + console.info('creating a new tag: ', tag) + execSync('git tag ' + tag) + console.info('pushing tag to origin: ', tag) + execSync('git push origin ' + tag) }