Skip to content

Commit

Permalink
Merge b3c8197 into 5fcda12
Browse files Browse the repository at this point in the history
  • Loading branch information
HQebupt committed Nov 21, 2017
2 parents 5fcda12 + b3c8197 commit 6d13f01
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 90 deletions.
112 changes: 70 additions & 42 deletions lib/jobs/ucs-catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ var di = require('di');
module.exports = UcsCatalogJobFactory;
di.annotate(UcsCatalogJobFactory, new di.Provide('Job.Ucs.Catalog'));
di.annotate(UcsCatalogJobFactory, new di.Inject(
'Job.Base',
'Job.Ucs.Base',
'Logger',
'Promise',
'Assert',
'Util',
'Services.Waterline',
'Services.Encryption',
'_',
'JobUtils.UcsTool'
'uuid'
));

function UcsCatalogJobFactory(
Expand All @@ -26,7 +26,7 @@ function UcsCatalogJobFactory(
waterline,
encryption,
_,
UcsTool
uuid
) {
var logger = Logger.initialize(UcsCatalogJobFactory);

Expand All @@ -47,7 +47,7 @@ function UcsCatalogJobFactory(
if(_.isEmpty(this.nodes)) {
this.nodes = [ this.context.target ];
}
this.ucs = new UcsTool();
this._obmsCollection = {};
this.boardChildrenToExtend = [
//"disk-collection",
"memarray-collection"
Expand All @@ -72,52 +72,82 @@ function UcsCatalogJobFactory(
});
};

/**
* @memberOf UcsCatalogJob
* @param {string} nodeId: node ID
*/
UcsCatalogJob.prototype._getObmsByNodeId = function (nodeId) {
var self = this;
var obms = self._obmsCollection[nodeId];
if (!obms) {
return waterline.obms.findByNode(nodeId, 'ucs-obm-service', true)
.then(function(obmSetting) {
if (obmSetting) {
self._obmsCollection[nodeId] = {
obmSetting: obmSetting
};
return self._obmsCollection[nodeId];
} else {
return Promise.reject(
new Error("No ucs-obm-service found for id: %s".format(nodeId)));
}
});
} else {
return Promise.resolve(self._obmsCollection[nodeId]);
}
};

/**
* @memberOf UcsCatalogJob
* @param {String} dn: distinguished name of ucs managed object
* @param {Boolean} withSelfData: boolean value to indicate if to include self data of dn
* @return {Object}: JSON data got from ucs service
*/
UcsCatalogJob.prototype._getDataByDN = function (dn, withSelfData) {
UcsCatalogJob.prototype._getCatalogByDN = function (dn, nodeId, withSelfData) {
var self = this;
var groupingPattern = /^(.*)-\d{1,2}$/;
var url = "/catalog?identifier=" + dn;
var callbackId = uuid.v4();
var url = "/catalog/async?identifier=%s&callbackId=%s"
.format(dn, callbackId);
var result = {};
return self.ucs.clientRequest(url)
.then(function(res) {
return res.body;
})
.map(function(data) {
var matched;
matched = data.rn.match(groupingPattern);

if(dn === data.dn){
if(!withSelfData) {
return;
} else {
result[data.rn] = data;
}
} else {
if(matched) {
var name = matched[1] + "-collection";
result[name] = result[name] || [];
result[name].push(data);
return self._getObmsByNodeId(nodeId)
.then(function(entity){
var settings = entity.obmSetting.config;
return self._ucsRequestAsync(url, settings, callbackId)
.then(function(res) {
return res.body;
});
})
.map(function(data) {
var matched;
matched = data.rn.match(groupingPattern);
if(dn === data.dn){
if(!withSelfData) {
return;
} else {
result[data.rn] = data;
}
} else {
result[data.rn] = data;
if(matched) {
var name = matched[1] + "-collection";
result[name] = result[name] || [];
result[name].push(data);
} else {
result[data.rn] = data;
}
}
}
})
.then(function() {
return result;
});
})
.then(function() {
return result;
});
};

/**
* @memberOf UcsCatalogJob
* @param {Object | arrayOfObject} collection: board children object data
* @return {Object}: JSON data got from ucs service
*/
UcsCatalogJob.prototype._extendBoardChildCatalog = function(collection) {
UcsCatalogJob.prototype._extendBoardChildCatalog = function(collection, nodeId) {
var self = this;
var _collection;
if (!_.isArray(collection)) {
Expand All @@ -126,7 +156,7 @@ function UcsCatalogJobFactory(
_collection = collection;
}
return Promise.map(_collection, function(item) {
return self._getDataByDN(item.dn)
return self._getCatalogByDN(item.dn, nodeId)
.then(function(result) {
item.children = result;
});
Expand All @@ -138,7 +168,7 @@ function UcsCatalogJobFactory(
* @param {Object} board: board object data
* @return {Promise}
*/
UcsCatalogJob.prototype._extendBoardCatalog = function(board) {
UcsCatalogJob.prototype._extendBoardCatalog = function(board, nodeId) {
var self = this;
var extendPromiseList = [];
var boardKeys = _.keys(board);
Expand All @@ -151,7 +181,7 @@ function UcsCatalogJobFactory(
});
_.forEach(boardChildrenToExtend, function(boardChild){
var boardChildData = board[boardChild];
extendPromiseList.push(self._extendBoardChildCatalog(boardChildData));
extendPromiseList.push(self._extendBoardChildCatalog(boardChildData, nodeId));
});
return Promise.all(extendPromiseList);
});
Expand All @@ -165,23 +195,21 @@ function UcsCatalogJobFactory(
UcsCatalogJob.prototype.catalogServers = function(nodeId) {
var self = this;
var nodeName = '';
return self.ucs.setup(nodeId)
.then(function(){
return waterline.nodes.getNodeById(nodeId);
})
return waterline.nodes.getNodeById(nodeId)
.then(function(node){
nodeName = node.name;
var isChassis = _.startsWith(_.last(nodeName.split('/')), 'chassis');
return Promise.all([
self._getDataByDN(nodeName, true),
isChassis ? new Promise.resolve() : self._getDataByDN(nodeName + '/board')
self._getCatalogByDN(nodeName, nodeId, true),
isChassis ?
new Promise.resolve() : self._getCatalogByDN(nodeName + '/board', nodeId)
])
.spread(function(nodeResult, boardResult) {
if(boardResult && nodeResult.board) {
// Get more details under rn="board" as hardware info like memory,
// disk, cpu are under rn="board"
nodeResult.board.children = boardResult;
return self._extendBoardCatalog(boardResult)
return self._extendBoardCatalog(boardResult, nodeId)
.then(function() {
return nodeResult;
});
Expand Down
17 changes: 0 additions & 17 deletions lib/utils/job-utils/ucs-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ function ucsToolFactory(
* @param data the POST/PUT/PATCH data to write to the HTTP client
*/

/**
* @function setup
* @description return new ucs tool for provided node Id.
*/
UcsTool.prototype.setup = function(nodeId) {
var self = this;
if (!nodeId) {
return Promise.resolve();
}

return waterline.obms.findByNode(nodeId, 'ucs-obm-service', true)
.then(function(obm) {
if (!obm) { throw new Errors.NotFoundError('Failed to find UCS settings'); }
self.settings = obm.config;
});
};

UcsTool.prototype.clientRequest = function(path, method, data) {
var self = this;
var setups = {};
Expand Down
Loading

0 comments on commit 6d13f01

Please sign in to comment.