forked from hpchud/vccjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadtargets.js
More file actions
59 lines (52 loc) · 2.15 KB
/
loadtargets.js
File metadata and controls
59 lines (52 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Load targets init8js module.
* @module loadtargets
*/
var os = require("os");
var fs = require("fs");
var promise = require("deferred");
var yaml = require('yamljs');
var path = require('path');
var vccutil = require("./vccutil.js");
var logger = require("./log.js");
// This is an init8js module, it runs in-process with the init in order to
// register our cluster targets, so it must follow the service module pattern
module.exports = {
/**
* The path to search for the services-*.yml file
* @type {String}
*/
servicePath: '/etc/vcc',
/**
* Load the targets from the services-*.yml file into the service manager
* @param {Object} service - The service object (provided by service manager)
* @param {Object} config - The configuration object (provided by service manager)
* @param {Object} targets - The targets object (provided by service manager)
* @param {Function} f_register_services - The function exposed by the service manager to register targets
* @returns {Promise}
*/
LoadTargets: function (service, config, targets, f_register_services) {
var deferred = promise();
var servicefile = path.join(module.exports.servicePath, "services-"+config.cluster.service+".yml");
// make sure service targets definition file exists
fs.stat(servicefile, function(err, stat) {
if(err) {
if(err.code == 'ENOENT') {
// no service file
logger.error('There is no service definition for '+config.cluster.service);
logger.error('Please create '+servicefile);
} else {
// something went wrong
logger.error('unhandled error hook stat', servicefile);
}
deferred.reject(err);
} else {
// parse the yaml file and register the targets
logger.debug("Registering service provider targets for "+config.cluster.service);
f_register_services(yaml.load(servicefile));
deferred.resolve();
}
});
return deferred.promise();
}
}