-
Notifications
You must be signed in to change notification settings - Fork 77
Add 2.0 API pollers routes #133
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
| // Copyright 2016, EMC Inc. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| var injector = require('../../../index').injector; | ||
| var controller = injector.get('Http.Services.Swagger').controller; | ||
| var pollers = injector.get('Http.Services.Api.Pollers'); | ||
|
|
||
|
|
||
| /** | ||
| * @api {get} /api/2.0/pollers/library GET /library | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription get list of possible pollers services | ||
| * @apiName pollers-library-get | ||
| * @apiGroup pollers | ||
| * @apiSuccess {json} pollers list of the available library pollers. | ||
| */ | ||
| var pollersLibGet = controller(function() { | ||
| return pollers.getPollerLib(); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {get} /api/2.0/pollers/library/:identifier GET /library/:identifier | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription get a single poller | ||
| * @apiName pollers-library-service-get | ||
| * @apiGroup pollers | ||
| * @apiParam {String} identifier String representation of the ObjectId | ||
| * @apiParamExample {String} Identifier-Example: | ||
| * "ipmi" | ||
| * @apiSuccess {json} poller the specfied poller library | ||
| * @apiError NotFound There is no poller in the library with <code>identifier</code> | ||
| * @apiErrorExample Error-Response: | ||
| * HTTP/1.1 404 Not Found | ||
| * { | ||
| * "error": "Not Found" | ||
| * } | ||
| */ | ||
| var pollersLibByIdGet = controller(function(req, res) { | ||
| return pollers.getPollerLibById(req.swagger.params.identifier.value); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {get} /api/2.0/pollers GET / | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription get a list of all pollers | ||
| * @apiName pollers-get | ||
| * @apiGroup pollers | ||
| * @apiSuccess {json} pollers list of pollers or an empty object if there are none. | ||
| */ | ||
| var pollersGet = controller(function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.getPollers(req.query); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {get} /api/2.0/pollers/:identifier GET /:identifier | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription Get specifics of the specified poller. | ||
| * @apiName poller-get | ||
| * @apiGroup pollers | ||
| * @apiParam {String} identifier String representation of the ObjectId | ||
| * @apiSuccess {json} poller the poller with the <code>id</code> | ||
| * @apiError identifierNotFound The <code>identifier</code> could not be found. | ||
| * @apiErrorExample Error-Response: | ||
| * HTTP/1.1 404 Not Found | ||
| * { | ||
| * "error": "Not Found" | ||
| * } | ||
| */ | ||
| var pollersIdGet = controller(function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.getPollersById(req.swagger.params.identifier.value); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {post} /api/2.0/pollers POST / | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription create a poller | ||
| * @apiName pollers-create | ||
| * @apiGroup pollers | ||
| * @apiError E_VALIDATION invalid Attributes. | ||
| * @apiErrorExample E_VALIDATION: | ||
| * { | ||
| * "error": "E_VALIDATION", | ||
| * "status": 400, | ||
| * "summary": "1 attributes are invalid", | ||
| * "model": "workitems", | ||
| * "invalidAttributes": { | ||
| * "pollInterval": [ | ||
| * { | ||
| * "rule": "integer", | ||
| * "message": | ||
| * "`undefined` should be a integer (instead of \"null\", which is a object)" | ||
| * }, | ||
| * { | ||
| * "rule": "required", | ||
| * "message": "\"required\" validation rule failed for input: null" | ||
| * } | ||
| * ] | ||
| * } | ||
| * } | ||
| */ | ||
| var pollersPost = controller({success: 201}, function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.postPollers(req.body); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {patch} /api/2.0/pollers/:identifier PATCH /:identifier | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription update a poller | ||
| * @apiName pollers-update | ||
| * @apiGroup pollers | ||
| * @apiParam {String} identifier String representation of the ObjectId | ||
| * @apiSuccess {json} poller the patched poller with the <code>id</code> | ||
| * @apiError NotFound The <code>identifier</code> could not be found. | ||
| * @apiErrorExample Error-Response: | ||
| * HTTP/1.1 404 Not Found | ||
| * { | ||
| * "error": "Not Found" | ||
| * } | ||
| */ | ||
| var pollersPatch = controller(function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.patchPollersById(req.swagger.params.identifier.value, req.body); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {patch} /api/2.0/pollers/:identifier PATCH /:identifier | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription update a poller | ||
| * @apiName pollers-update | ||
| * @apiGroup pollers | ||
| * @apiParam {String} identifier String representation of the ObjectId | ||
| * @apiSuccess {json} poller the patched poller with the <code>id</code> | ||
| * @apiError NotFound The <code>identifier</code> could not be found. | ||
| * @apiErrorExample Error-Response: | ||
| * HTTP/1.1 404 Not Found | ||
| * { | ||
| * "error": "Not Found" | ||
| * } | ||
| */ | ||
| var pollersPausePatch = controller(function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.patchPollersByIdPause(req.swagger.params.identifier.value); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {patch} /api/2.0/pollers/:identifier/resume PATCH /:identifier/resume | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription resume a paused poller | ||
| * @apiName pollers-resume | ||
| * @apiGroup pollers | ||
| * @apiParam {String} identifier String representation of the ObjectId | ||
| * @apiSuccess {json} poller the unpaused poller with the <code>id</code> | ||
| * @apiError NotFound The <code>identifier</code> could not be found. | ||
| * @apiErrorExample Error-Response: | ||
| * HTTP/1.1 404 Not Found | ||
| * { | ||
| * "error": "Not Found" | ||
| * } | ||
| */ | ||
| var pollersResumePatch = controller(function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.patchPollersByIdResume(req.swagger.params.identifier.value); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {delete} /api/2.0/pollers/:identifier DELETE /:id | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription Delete all pollers of specified device. | ||
| * @apiName poller-delete | ||
| * @apiGroup pollers | ||
| * @apiParam {String} identifier String representation of the ObjectId | ||
| * @apiSuccess {nothing} nothing it doesn't return anything if Successful | ||
| * @apiError NotFound The <code>identifier</code> could not be found. | ||
| * @apiErrorExample Error-Response: | ||
| * HTTP/1.1 404 Not Found | ||
| * { | ||
| * "error": "Not Found" | ||
| * } | ||
| */ | ||
| var pollersDelete = controller({success: 204}, function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.deletePollersById(req.swagger.params.identifier.value); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {get} /api/2.0/pollers/:identifier/data GET /:identifier/data | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription Get data for the specific poller. | ||
| * @apiName poller-get-data | ||
| * @apiGroup pollers | ||
| * @apiParam {String} identifier (ip address or NodeId) for the data from a poller | ||
| * @apiError NotFound1 The <code>identifier</code> could not be found. | ||
| * @apiError NotFound2 There is no data for the poller with the <code>identifier</code>. | ||
| * @apiErrorExample Error-Response: | ||
| * HTTP/1.1 404 Not Found | ||
| * { | ||
| * "error": "Not Found" | ||
| * } | ||
| */ | ||
| var pollersDataGet = controller(function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.getPollersByIdData(req.swagger.params.identifier.value); | ||
| }); | ||
|
|
||
| /** | ||
| * @api {get} /api/2.0/pollers/:identifier/data/current GET /:identifier/data/current | ||
| * @apiVersion 2.0.0 | ||
| * @apiDescription Get only the most recent data entry for the specific poller. | ||
| * @apiName poller-get-data-current | ||
| * @apiGroup pollers | ||
| * @apiParam {String} identifier (ip address or NodeId) for the data from a poller | ||
| * @apiError NotFound1 The <code>identifier</code> could not be found. | ||
| * @apiError NotFound2 There is no data for the poller with the <code>identifier</code>. | ||
| * @apiErrorExample Error-Response: | ||
| * HTTP/1.1 404 Not Found | ||
| * { | ||
| * "error": "Not Found" | ||
| * } | ||
| */ | ||
| var pollersCurrentDataGet = controller(function(req, res) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'res' is defined but never used. |
||
| return pollers.getPollersByIdDataCurrent(req.swagger.params.identifier.value); | ||
| }); | ||
|
|
||
|
|
||
| module.exports = { | ||
| pollersLibGet: pollersLibGet, | ||
| pollersLibByIdGet: pollersLibByIdGet, | ||
| pollersGet: pollersGet, | ||
| pollersIdGet: pollersIdGet, | ||
| pollersPost: pollersPost, | ||
| pollersPatch: pollersPatch, | ||
| pollersDelete: pollersDelete, | ||
| pollersDataGet: pollersDataGet, | ||
| pollersCurrentDataGet: pollersCurrentDataGet, | ||
| pollersPausePatch: pollersPausePatch, | ||
| pollersResumePatch: pollersResumePatch | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 'use strict'; | ||
|
|
||
| var injector = require('../../../index').injector; | ||
| var serializer = injector.get('Http.Services.Swagger').serializer; | ||
| var deserializer = injector.get('Http.Services.Swagger').deserializer; | ||
|
|
||
| var pollersSerializer = serializer('Serializables.V2.Pollers'); | ||
| var pollersDeserializer = deserializer('Serializables.V2.Pollers'); | ||
|
|
||
| module.exports = { | ||
| pollersLibGet: pollersSerializer, | ||
| pollersLibByIdGet: pollersSerializer, | ||
| pollersGet: pollersSerializer, | ||
| pollersIdGet: pollersSerializer, | ||
| pollersPost: pollersDeserializer, | ||
| pollersPatch: pollersDeserializer, | ||
| pollersDelete: pollersDeserializer, | ||
| pollersDataGet: pollersSerializer, | ||
| pollersCurrentDataGet: pollersSerializer, | ||
| pollersPausePatch: pollersSerializer, | ||
| pollersResumePatch: pollersSerializer | ||
| }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright 2015, EMC, Inc. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. created on 2015 or 2016 ? |
||
|
|
||
| 'use strict'; | ||
|
|
||
| var di = require('di'); | ||
|
|
||
| module.exports = PollersFactory; | ||
|
|
||
| di.annotate(PollersFactory, new di.Provide('Serializables.V2.Pollers')); | ||
| di.annotate(PollersFactory, | ||
| new di.Inject( | ||
| 'Serializable', | ||
| 'Services.Waterline', | ||
| 'Constants', | ||
| '_' | ||
| ) | ||
| ); | ||
|
|
||
| function PollersFactory (Serializable, waterline, Constants, _) { | ||
| function Pollers (defaults) { | ||
| Serializable.call( | ||
| this, | ||
| Pollers.schema, | ||
| defaults | ||
| ); | ||
| } | ||
|
|
||
| Pollers.schema = { | ||
| id: 'Serializables.V2.Pollers', | ||
| type: 'object', | ||
| properties: { | ||
| config: { | ||
| type: 'object' | ||
| }, | ||
| type: { | ||
| type: 'string' | ||
| }, | ||
| pollInterval: { | ||
| type: 'integer' | ||
| }, | ||
| paused: { | ||
| type: 'boolean' | ||
| } | ||
| }, | ||
| required: [ 'config', 'type', 'pollInterval' ] | ||
| }; | ||
|
|
||
| Serializable.register(PollersFactory, Pollers); | ||
|
|
||
| var pollerWorkItems = { | ||
| ipmi: Constants.WorkItems.Pollers.IPMI, | ||
| snmp: Constants.WorkItems.Pollers.SNMP | ||
| }; | ||
|
|
||
| Pollers.prototype.deserialize = function(target) { | ||
| var poller = target; | ||
| if (poller) { | ||
| if (poller.type) { | ||
| poller.name = pollerWorkItems[poller.type]; | ||
| } | ||
| poller = _.pick(poller, 'name', 'node', 'config', 'pollInterval', 'paused'); | ||
| this.defaults(target); | ||
| } | ||
| return this; | ||
| }; | ||
|
|
||
| Pollers.prototype.serialize = function(target) { | ||
| var poller = target; | ||
| if (poller) { | ||
| poller.type = _.findKey(pollerWorkItems, function(workItem) { | ||
| return workItem === poller.name; | ||
| }); | ||
| delete poller.name; | ||
| } | ||
| return waterline.workitems.deserialize(poller); | ||
| }; | ||
|
|
||
| return Pollers; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'res' is defined but never used.