Skip to content

Commit

Permalink
Merge ae68ccf into 3b4a92e
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaricChan committed Dec 20, 2017
2 parents 3b4a92e + ae68ccf commit 7f487aa
Show file tree
Hide file tree
Showing 17 changed files with 611 additions and 16 deletions.
4 changes: 1 addition & 3 deletions lib/jobs/dell-wsman-RAID.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ function DellWsmanRAIDFactory(

DellWsmanRAIDJob.prototype._handleSyncResponse = function(response) {
var self = this;
var json = JSON.parse(response.body);
logger.info('Status from SCP Microservice for RAID operation: ' + json["status"]);
if (json["status"] === "OK") {
if (response.body.status === "OK") {
if(self.options.removeXmlFile){
if(self.dell.shareFolder.shareType === 0){
var nfsClient = new NfsClient(
Expand Down
162 changes: 162 additions & 0 deletions lib/jobs/dell-wsman-add-hotspare-updatexml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.

'use strict';

var di = require('di'),
xmldom = require('xmldom').DOMParser;

module.exports = WsmanAddHotspareUpdateXmlFactory;

di.annotate(WsmanAddHotspareUpdateXmlFactory, new di.Provide('Job.Dell.Wsman.Add.Hotspare.UpdateXml'));
di.annotate(WsmanAddHotspareUpdateXmlFactory, new di.Inject(
'Job.Base',
'Logger',
'Assert',
'Util',
'Services.Configuration',
'Errors',
'JobUtils.Smb2Client',
'JobUtils.NfsClient',
'Promise',
'_'
));

function WsmanAddHotspareUpdateXmlFactory(
BaseJob,
Logger,
assert,
util,
configuration,
errors,
Smb2Client,
NfsClient,
Promise,
_
) {
var logger = Logger.initialize(WsmanAddHotspareUpdateXmlFactory);

function WsmanAddHotspareUpdateXmlJob(options, context, taskId) {
WsmanAddHotspareUpdateXmlJob.super_.call(this, logger, options, context, taskId);
}

util.inherits(WsmanAddHotspareUpdateXmlJob, BaseJob);

WsmanAddHotspareUpdateXmlJob.prototype._run = function() {
var self = this;
if(!self.options.driveId) {
throw new errors.NotFoundError('The driveId should not be empty.');
}
self.dell = configuration.get('dell');
if(!self.dell || !self.dell.shareFolder) {
throw new errors.NotFoundError('Share folder is not defined in smiConfig.json');
}
return self.updateXmlForRaid();
};

WsmanAddHotspareUpdateXmlJob.prototype.updateXmlForRaid = function() {
var self = this;
var fileName = self.context.graphId + '.xml';
var client;
return Promise.try(function() {
if(self.dell.shareFolder.shareType === 0) {
client = new NfsClient(
self.dell.shareFolder.address,
self.dell.shareFolder.shareName,
self.context.mountDir
);
} else if(self.dell.shareFolder.shareType === 2) {
client = new Smb2Client(
self.dell.shareFolder.address,
self.dell.shareFolder.shareName,
self.dell.shareFolder.username,
self.dell.shareFolder.password
);
} else {
throw new Error('Invalid shareType in smiConfig.json. The shareType should be 0 or 2.');
}
return client.readFile(fileName);
})
.then(function(data) {
return self.updateXml(data);
})
.then(function(doc) {
return client.writeFile(fileName, doc);
})
.then(function() {
self._done();
})
.catch(function(err) {
logger.error('An error occurred while updating component xml.', { error: err });
self._done(err);
});
};

WsmanAddHotspareUpdateXmlJob.prototype.updateXml = function(data) {
var self = this;
var xmlFile = String.fromCharCode.apply(null, new Uint16Array(data));
var doc = new xmldom().parseFromString(xmlFile, 'application/xml');
if(self.options.hotspareType === 'dhs') {
self.UpdateVolumeElement(doc);
} else {
self.UpdateDiskElement(doc);
}
return doc;
};

/*
* Dedicated hotspare should be added into corresponding volume
*/
WsmanAddHotspareUpdateXmlJob.prototype.UpdateVolumeElement = function(doc) {
var self = this;
if(!self.options.volumeId) {
throw new errors.NotFoundError('The volumeId should not be empty.');
}
var components = doc.getElementsByTagName('Component');
_.forEach(components, function(component) {
var volumeFQDD = component.getAttribute('FQDD');
if(volumeFQDD === self.options.volumeId) {
var newNode = doc.createElement('Attribute');
newNode.setAttribute('Name', 'RAIDdedicatedSpare');
newNode.textContent = self.options.driveId;
component.appendChild(newNode);
var breakLineChild = doc.createTextNode('\n');
component.appendChild(breakLineChild);
return false;
}
});
return doc;
};

/*
* Update hotspare status of specified drive
*/
WsmanAddHotspareUpdateXmlJob.prototype.UpdateDiskElement = function(doc) {
var self = this;
var components = doc.getElementsByTagName('Component');
_.forEach(components, function(component) {
var diskFQDD = component.getAttribute('FQDD');
if(diskFQDD === self.options.driveId) {
var newDriveNode = doc.createElement('Component');
newDriveNode.setAttribute('FQDD', diskFQDD);
var statusChild = doc.createElement('Attribute');
statusChild.setAttribute('Name', 'RAIDHotSpareStatus');
statusChild.textContent = 'Global';
var stateChild = doc.createElement('Attribute');
stateChild.setAttribute('Name', 'RAIDPDState');
stateChild.textContent = 'Ready';
var breakLineChild = doc.createTextNode('\n');
newDriveNode.appendChild(breakLineChild);
newDriveNode.appendChild(statusChild);
breakLineChild = doc.createTextNode('\n');
newDriveNode.appendChild(breakLineChild);
newDriveNode.appendChild(stateChild);
breakLineChild = doc.createTextNode('\n');
newDriveNode.appendChild(breakLineChild);
doc.replaceChild(newDriveNode, component);
return false;
}
});
};

return WsmanAddHotspareUpdateXmlJob;
}
12 changes: 6 additions & 6 deletions lib/jobs/dell-wsman-getXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ function WsmanGetComponentFactory(
};

WsmanGetComponentJob.prototype._handleSyncResponse = function(response) {
var json = JSON.parse(response.body);
logger.info('Status from SCP Microservice for getXml: ' + json["status"]);
if (json["status"] === "OK") {
if (response.body.status === "OK") {
return response;
} else {
throw new Error("Failed to getXml from smi service.");
Expand All @@ -97,12 +95,14 @@ function WsmanGetComponentFactory(
}
var self = this;
var componentNames = "";
if(self.options.volumeId !== undefined && self.options.volumeId !== ""){
if(self.options.volumeId !== undefined && self.options.volumeId !== "") {
componentNames = self.options.volumeId.split(':')[1];
}else if(self.options.drives !== undefined){
} else if(self.options.drives !== undefined) {
var drive = self.options.drives.split(',')[0];
componentNames = drive.slice(drive.lastIndexOf(':')+1, drive.length);
}else{
} else if(self.options.driveId) {
componentNames = self.options.driveId.split(':')[2];
} else {
throw new Error('Drives or volumeId isn\'t defined.');
}
var data = {
Expand Down
12 changes: 12 additions & 0 deletions lib/task-data/base-tasks/dell-wsman-add-hotspare-updatexml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.

'use strict';

module.exports = {
friendlyName: "Dell Wsman Add Hotspare UpdateXml Base Task",
injectableName: "Task.Base.Dell.Wsman.Add.Hotspare.UpdateXml",
runJob: 'Job.Dell.Wsman.Add.Hotspare.UpdateXml',
requiredOptions: [],
requiredProperties: {},
properties: {}
};
23 changes: 23 additions & 0 deletions lib/task-data/schemas/dell-wsman-add-hotspare-getxml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"copyright": "Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.",
"definitions": {
"driveId": {
"description": "Specify drive id to be added as hot spare",
"type": "string"
},
"shutdownType": {
"description": "Specify the type of system shutdown: Graceful(0), Forced(1), default value is 0",
"type": "integer",
"enum": [0, 1]
}
},
"properties": {
"driveId": {
"$ref": "#/definitions/driveId"
},
"shutdownType": {
"$ref": "#/definitions/shutdownType"
}
},
"required": ["driveId"]
}
30 changes: 30 additions & 0 deletions lib/task-data/schemas/dell-wsman-add-hotspare-updatexml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"copyright": "Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.",
"definitions": {
"volumeId": {
"description": "Specify volume id for adding hot spare",
"type": "string"
},
"driveId": {
"description": "Specify drive id to be added as hot spare",
"type": "string"
},
"hotspareType": {
"description": "Specify hotspare type for the drive",
"type": "string",
"enum": ["ghs", "dhs"]
}
},
"properties": {
"volumeId": {
"$ref": "#/definitions/volumeId"
},
"driveId": {
"$ref": "#/definitions/driveId"
},
"hotspareType": {
"$ref": "#/definitions/hotspareType"
}
},
"required": ["driveId", "hotspareType"]
}
2 changes: 1 addition & 1 deletion lib/task-data/schemas/dell-wsman-add-volume-updateXml.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"raidLevel": {
"description": "Specify raidLevel for adding volume. default value: 0",
"type": "integer",
"enum": [0,1,5,6,10,50]
"enum": [0,1,5,10,50]
},
"stripeSize": {
"description": "Specify stripeSize for adding volume, default value: 128",
Expand Down
14 changes: 14 additions & 0 deletions lib/task-data/tasks/dell-wsman-add-hotspare-getxml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.

'use strict';

module.exports = {
friendlyName: "Dell Wsman GetXml for Add Hotspare",
injectableName: "Task.Dell.Wsman.Add.Hotspare.GetXml",
implementsTask: "Task.Base.Dell.Wsman.GetXml",
optionsSchema: 'dell-wsman-add-hotspare-getxml.json',
options: {
shutdownType: 0
},
properties: {}
};
12 changes: 12 additions & 0 deletions lib/task-data/tasks/dell-wsman-add-hotspare-updatexml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.

'use strict';

module.exports = {
friendlyName: "Dell Wsman UpdateXml for Add Hotspare",
injectableName: "Task.Dell.Wsman.Add.Hotspare.UpdateXml",
implementsTask: "Task.Base.Dell.Wsman.Add.Hotspare.UpdateXml",
optionsSchema: 'dell-wsman-add-hotspare-updatexml.json',
options: {},
properties: {}
};
16 changes: 12 additions & 4 deletions spec/lib/jobs/dell-wsman-RAID-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ describe('Dell Wsman RAID Job', function(){
describe('handleSyncResponse function cases', function(){
it('Should delete cifs file succesfully', function(){
var response = {
"body": '{"status":"OK"}'
"body": {
"status": "OK"
}
};
job.options.removeXmlFile = true;
job.dell = {
Expand All @@ -109,7 +111,9 @@ describe('Dell Wsman RAID Job', function(){

it('Should delete nfs file and umount directory successfully', function(){
var response = {
"body": '{"status":"OK"}'
"body": {
"status": "OK"
}
};
job.options.removeXmlFile = true;
job.dell = {
Expand All @@ -125,15 +129,19 @@ describe('Dell Wsman RAID Job', function(){

it('Should not delete file', function(){
var response = {
"body": '{"status":"OK"}'
"body": {
"status": "OK"
}
};
job.options.removeXmlFile = false;
expect(job._handleSyncResponse(response)).to.equal(response);
});

it('Should throw an error: Failed to do RAID operation', function(){
var response = {
"body": '{"status":"fail"}'
"body": {
"status": "fail"
}
};
expect(function(){
job._handleSyncResponse(response);
Expand Down
Loading

0 comments on commit 7f487aa

Please sign in to comment.