Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
*.sublime*
84 changes: 84 additions & 0 deletions api/apps.js
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions api/artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function createMethods (makeRequest) {
return {
// /v2/artifacts todo
// /v2/artifacts/{path} todo
}
}
24 changes: 24 additions & 0 deletions api/deployments.js
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions api/events.js
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions api/groups.js
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions api/info.js
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions api/leader.js
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions api/misc.js
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions api/queue.js
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions api/tasks.js
Original file line number Diff line number Diff line change
@@ -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
Loading