Skip to content
Merged
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
233 changes: 233 additions & 0 deletions lib/api/2.0/pollers.js
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) {

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.

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) {

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.

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) {

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.

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) {

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.

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) {

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.

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) {

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.

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) {

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.

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) {

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.

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) {

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.

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) {

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.

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
};
23 changes: 23 additions & 0 deletions lib/api/serdes/pollers.js
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
};

79 changes: 79 additions & 0 deletions lib/serializables/v2/pollers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2015, EMC, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
Loading