Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from tistocks/tistocks_HDInsight_2
Browse files Browse the repository at this point in the history
Tistocks hd insight 2
  • Loading branch information
tistocks committed Jun 10, 2013
2 parents 9657428 + 95e86a3 commit 2f22c92
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 78 deletions.
111 changes: 109 additions & 2 deletions lib/services/serviceManagement/hdinsightservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,113 @@ HDInsightService.prototype.convertCreationObject = function (clusterCreationObje
return payload;
};

function transformResponse (cloudService) {
if (!_.isArray(cloudService)) {
cloudService = [ cloudService ];
}
var clusters = [];
for (var i = 0; i < cloudService.length; i++) {
if (cloudService[i].Name &&
cloudService[i].Name.indexOf('hdinsight') === 0) {
if (cloudService[i].Resources && cloudService[i].Resources.Resource) {
if (!_.isArray(cloudService[i].Resources.Resource)) {
cloudService[i].Resources.Resource = [ cloudService[i].Resources.Resource ];
}

var resource = cloudService[i].Resources.Resource;
for (var j = 0; j < resource.length; j++) {
if (resource[j].ResourceProviderNamespace == 'hdinsight') {
var cluster = {
Name : resource[j].Name,
Location : cloudService[i].GeoRegion,
State : resource[j].SubState,
Error : 'None'
};
if (resource[j].OutputItems) {
if (!_.isArray(resource[j].OutputItems.OutputItem)) {
resource[j].OutputItems.OutputItem = [resource[j].OutputItems.OutputItem];
}
for (var k = 0; k < resource[j].OutputItems.OutputItem.length; k++) {
var outputItem = resource[j].OutputItems.OutputItem[k];
if (outputItem.Key == 'CreatedDate') {
cluster.CreatedDate = outputItem.Value;
}
if (outputItem.Key == 'NodesCount') {
cluster.Nodes = outputItem.Value;
}
if (outputItem.Key == 'ConnectionURL') {
cluster.ConnectionURL = outputItem.Value;
}
if (outputItem.Key == 'ClusterUsername') {
cluster.Username = outputItem.Value;
}
}
}
if (resource[j].OperationStatus && resource[j].OperationStatus.Error) {
cluster.Error = resource[j].OperationStatus.Error.Message;
}
else if (cluster.State == 'Error') {
cluster.Error = 'The request failed. Please contact support for more information.';
}
clusters.push(cluster);
}
}
}
}
}

var response = {
clusters : clusters
};
return response;
}

HDInsightService.prototype.registerLocation = function(location, callback) {
return this.manageLocation('put', location, callback);
};

HDInsightService.prototype.unregisterLocation = function(location, callback) {
return this.manageLocation('del', location, callback);
};

HDInsightService.prototype.validateLocation = function(location, callback) {
return this.manageLocation('get', location, callback);
};

HDInsightService.prototype.manageLocation = function(method, location, callback) {
var regionCloudServiceName = azureUtil.getNameSpace(this.subscriptionId, 'hdinsight' , location);
var path = '/' + this.subscriptionId + '/cloudservices/' + regionCloudServiceName;
var webResource;
var content = null;
if (method == 'del') {
webResource = WebResource.del(path);
}
else if (method == 'get') {
webResource = WebResource.get(path);
}
else {
webResource = WebResource.put(path);
content = {
CloudService : {
'$' : { xmlns : 'http://schemas.microsoft.com/windowsazure' },
Label : 'HdInsight CloudService',
Description : 'HdInsight clusters for subscription ' + this.subscriptionId,
GeoRegion : location
}
};
content = js2xml.serialize(content);
}
webResource.withHeader('x-ms-version', '2011-08-18');
webResource.withHeader('accept', 'application/xml');
this.performRequest(webResource, content, null, function (responseObject, next) {
var finalCallback = function (returnObject) {
callback(returnObject.error, returnObject.response);
};

next(responseObject, finalCallback);
});
};

/**
*
* Deletes an HDInsight Cluster
Expand Down Expand Up @@ -249,7 +356,7 @@ HDInsightService.prototype.createCluster = function (clusterCreationObject, call
// Convert the simply form "clusterCreationObject" into the complex form "payload" needed by the server REST call.
Validate.isValidHDInsightCreationObject(clusterCreationObject);
var payload = this.convertCreationObject(clusterCreationObject);
var regionCloudServiceName = azureUtil.getNameSpace(this.subscriptionId, 'hdinsight' , 'East US');
var regionCloudServiceName = azureUtil.getNameSpace(this.subscriptionId, 'hdinsight' , clusterCreationObject.location);
var path = '/' + this.subscriptionId + '/cloudservices/' + regionCloudServiceName + '/resources/hdinsight/containers/' + payload.Resource.IntrinsicSettings.ClusterContainer.DnsName;
var webResource = WebResource.put(path);
webResource.withHeader('x-ms-version', '2011-08-18');
Expand Down Expand Up @@ -309,7 +416,7 @@ HDInsightService.prototype.listClusters = function (callback) {
cloudServices.push (cloudService[i]);
}

responseObject.response.body.CloudServices.CloudService = cloudServices;
responseObject.response.body = transformResponse(cloudServices);
}

}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function base32NoPaddingEncode (data) {
* @return {Bool} True if the value is an integer number; false otherwise.
*/
exports.getNameSpace = function (subscriptionId, prefix, location) {
location = location.replace(' ', '-');
location = location.replace(/ /g, '-');
var hash = crypto.createHash('sha256').update(new Buffer(subscriptionId, 'utf-8')).digest('hex');
return prefix + base32NoPaddingEncode(new Buffer(hash, 'hex')) + '-' + location;
};
Expand Down
27 changes: 27 additions & 0 deletions test/services/HDInsight/hdinsight-createCluster-unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@ describe('HDInsight createCluster (under unit test)', function() {
});
});

it('should pass the correct locate to getNameSpace', function(done) {
performRequestStubUtil.StubAuthenticationFailed('http://test');
var clusterCreationObject = {
name : 'test',
location : 'Botamazu',
defaultStorageAccountName : 'test',
defaultStorageAccountKey : 'KEY',
defaultStorageContainer : 'deploy1',
user : 'user',
password : 'password',
nodes : 4,
};
should.exist(azureUtil);
should.exist(azureUtil.getNameSpace);
var originalFunction = azureUtil.getNameSpace;
should.exist(azureUtil);
var actualLocation = 'unspecified';
azureUtil.getNameSpace = function(subscriptionId, prefix, location) {
actualLocation = location;
}
hdInsight.createCluster(clusterCreationObject, function(err, response) {
azureUtil.getNameSpace = originalFunction;
actualLocation.should.be.eql(clusterCreationObject.location);
done(null);
});
});

it('should validate the name field of the clusterCreationObject is not undefined', function() {
performRequestStubUtil.StubAuthenticationFailed('http://test');
var clusterCreationObject = {};
Expand Down
33 changes: 11 additions & 22 deletions test/services/HDInsight/hdinsight-listClusters-unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ describe('HDInsight listClusters (under unit test)', function() {
performRequestStubUtil.StubProcessRequestWithSuccess('http://test.com', singleResult);
hdInsight.listClusters(function (err, response) {
should.not.exist(err);
should.exist(response.body.CloudServices.CloudService);
_.isArray(response.body.CloudServices.CloudService).should.be.eql(true);
response.body.CloudServices.CloudService.length.should.be.eql(1);
should.exist(response.body.CloudServices.CloudService[0].Resources.Resource);
_.isArray(response.body.CloudServices.CloudService).should.be.eql(true);
response.body.CloudServices.CloudService.length.should.be.eql(1);
should.exist(response.body.clusters);
_.isArray(response.body.clusters).should.be.eql(true);
response.body.clusters.length.should.be.eql(1);
should.exist(response.body.clusters[0]);
response.body.clusters[0].Name.should.be.eql('tsthdx00hdxcibld02');
done(err);
});
});
Expand All @@ -141,26 +140,16 @@ describe('HDInsight listClusters (under unit test)', function() {
});
});

it('should remove CloudServices not related to HDInsight', function (done) {
it('should remove CloudServices and resources not related to HDInsight', function (done) {
performRequestStubUtil.StubProcessRequestWithSuccess('http://test.com', goodResult);
hdInsight.listClusters(function (err, response) {
should.not.exist(err);
should.exist(response.body.CloudServices.CloudService);
response.body.CloudServices.CloudService.length.should.eql(1);
response.body.CloudServices.CloudService[0].Name.should.eql('hdinsightHRIEVKWCABCRT3AK64SGDGFJDR7EM64QV4T5UXU23MU6ZPCWG5NQ-East-US-2');
should.exist(response.body.clusters);
_.isArray(response.body.clusters).should.be.eql(true);
response.body.clusters.length.should.be.eql(1);
should.exist(response.body.clusters[0]);
response.body.clusters[0].Name.should.be.eql('tsthdx00hdxcibld02');
done(err);
});
});

it('should remove resources not representing a cluster', function (done) {
performRequestStubUtil.StubProcessRequestWithSuccess('http://test.com', goodResult);
hdInsight.listClusters(function (err, response) {
should.not.exist(err);
should.exist(response.body.CloudServices.CloudService);
response.body.CloudServices.CloudService[0].Resources.Resource.length.should.eql(1);
response.body.CloudServices.CloudService[0].Resources.Resource[0].Name.should.eql('tsthdx00hdxcibld02');
done(err);
});
});

});
17 changes: 11 additions & 6 deletions test/services/HDInsight/namespace-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,40 @@
var azureUtil = require('../../../lib/util/util.js');

// Test includes
var assert = require('assert');
var should = require('should');

describe('HDInsight Namespace Test', function() {

it('GetNameSpace should properly create namespaces', function (done) {
var subscriptionId = '0bf0b5da-dc38-4795-8595-3170ffefec48';
var expected = 'hdinsightC2D4FSA77HSYSQLRU4V73NKI3YH2OYHQXACMRGPECIHSH7FXTUAQ-East-US';
var result = azureUtil.getNameSpace(subscriptionId, 'hdinsight', 'East US');
assert.equal(expected, result);
result.should.be.eql(expected);

subscriptionId = 'c72f7fde-36ec-4cdf-93bf-43f90fe5373a';
expected = 'hdinsightGTUVH76U5MNNGTJEFMKSGQMQO7AFBW52LMZPQ22R6UUXVWBDRBVA-East-US';
result = azureUtil.getNameSpace(subscriptionId, 'hdinsight', 'East US');
assert.equal(expected, result);
result.should.be.eql(expected);

subscriptionId = '04066490-336b-4732-adfa-90ba5422cc84';
expected = 'hdinsightXVS5S5SBDTTR7OJ4IOKGRTFM2M3P33KWPGP5SPYDJZYUMY73KOIQ-East-US';
result = azureUtil.getNameSpace(subscriptionId, 'hdinsight', 'East US');
assert.equal(expected, result);
result.should.be.eql(expected);

subscriptionId = '3cfbb7fc-1347-4eff-bf07-2e1f43084b00';
expected = 'hdinsightVXFY2XGLQTT5PCJCDRKJXWE2W2PQZOJK3NLO4QSNHEKS32E6RM5A-East-US';
result = azureUtil.getNameSpace(subscriptionId, 'hdinsight', 'East US');
assert.equal(expected, result);
result.should.be.eql(expected);

subscriptionId = 'ee3733c1-5ebd-4a20-95ce-17dba36a071a';
expected = 'hdinsightLDBRGOYTMVIJZ2ZAJZZTFFJD7N3MNFCJGONZO53VLK2V5GIEU2SQ-East-US';
result = azureUtil.getNameSpace(subscriptionId, 'hdinsight', 'East US');
assert.equal(expected, result);
result.should.be.eql(expected);

subscriptionId = 'ee3733c1-5ebd-4a20-95ce-17dba36a071a';
expected = 'hdinsightLDBRGOYTMVIJZ2ZAJZZTFFJD7N3MNFCJGONZO53VLK2V5GIEU2SQ-East-US-2';
result = azureUtil.getNameSpace(subscriptionId, 'hdinsight', 'East US 2');
result.should.be.eql(expected);

done();
});
Expand Down
94 changes: 47 additions & 47 deletions test/testlist.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
serviceruntime/roleenvironment-tests.js
serviceruntime/runtimeversionmanager-tests.js
serviceruntime/runtimeversionprotocolclient-tests.js
services/blob/internal/sharedaccesssignature-tests.js
services/blob/internal/sharedkey-tests.js
services/blob/internal/sharedkeylite-tests.js
services/blob/blobservice-tests.js
services/blob/blobservice-gb-tests.js
services/blob/filters-tests.js
services/core/connectionstringparser-tests.js
services/core/serviceclient-tests.js
services/core/exponentialretrypolicyfilter-tests.js
services/core/linearretrypolicyfilter-tests.js
services/core/servicesettings-tests.js
services/core/servicebussettings-tests.js
services/core/servicemanagementsettings-tests.js
services/core/storageservicesettings-tests.js
services/queue/queueservice-tests.js
services/serviceBus/internal/wraptokenmanager-tests.js
services/serviceBus/apnsservice-tests.js
services/serviceBus/apnsservice-registrations-tests.js
services/serviceBus/servicebusservice-tests.js
services/serviceBus/notificationhubs-tests.js
services/serviceBus/wnsservice-tests.js
services/serviceBus/wnsservice-registrations-tests.js
services/serviceBus/wrapservice-tests.js
services/serviceManagement/affinitygroup-tests.js
services/serviceManagement/servicebusmanagementservice-tests.js
services/serviceManagement/servicemanagementservice-tests.js
services/serviceManagement/sqlmanagementservice-tests.js
services/table/internal/sharedkeytable-tests.js
services/table/internal/sharedkeylitetable-tests.js
services/table/batchserviceclient-tests.js
services/table/tabledatatype-tests.js
services/table/tablequery-tests.js
services/table/tableservice-batch-tests.js
services/table/tableservice-tablequery-tests.js
services/table/tableservice-tests.js
services/table/tableservice-gb-tests.js
services/sqlAzure/sqlservice-tests.js
util/date-tests.js
util/edmtype-tests.js
util/iso8061date-tests.js
util/odatahandler-tests.js
util/util-tests.js
util/validate-tests.js
azure-tests.js
# serviceruntime/roleenvironment-tests.js
# serviceruntime/runtimeversionmanager-tests.js
# serviceruntime/runtimeversionprotocolclient-tests.js
# services/blob/internal/sharedaccesssignature-tests.js
# services/blob/internal/sharedkey-tests.js
# services/blob/internal/sharedkeylite-tests.js
# services/blob/blobservice-tests.js
# services/blob/blobservice-gb-tests.js
# services/blob/filters-tests.js
# services/core/connectionstringparser-tests.js
# services/core/serviceclient-tests.js
# services/core/exponentialretrypolicyfilter-tests.js
# services/core/linearretrypolicyfilter-tests.js
# services/core/servicesettings-tests.js
# services/core/servicebussettings-tests.js
# services/core/servicemanagementsettings-tests.js
# services/core/storageservicesettings-tests.js
# services/queue/queueservice-tests.js
# services/serviceBus/internal/wraptokenmanager-tests.js
# services/serviceBus/apnsservice-tests.js
# services/serviceBus/apnsservice-registrations-tests.js
# services/serviceBus/servicebusservice-tests.js
# services/serviceBus/notificationhubs-tests.js
# services/serviceBus/wnsservice-tests.js
# services/serviceBus/wnsservice-registrations-tests.js
# services/serviceBus/wrapservice-tests.js
# services/serviceManagement/affinitygroup-tests.js
# services/serviceManagement/servicebusmanagementservice-tests.js
# services/serviceManagement/servicemanagementservice-tests.js
# services/serviceManagement/sqlmanagementservice-tests.js
# services/table/internal/sharedkeytable-tests.js
# services/table/internal/sharedkeylitetable-tests.js
# services/table/batchserviceclient-tests.js
# services/table/tabledatatype-tests.js
# services/table/tablequery-tests.js
# services/table/tableservice-batch-tests.js
# services/table/tableservice-tablequery-tests.js
# services/table/tableservice-tests.js
# services/table/tableservice-gb-tests.js
# services/sqlAzure/sqlservice-tests.js
# util/date-tests.js
# util/edmtype-tests.js
# util/iso8061date-tests.js
# util/odatahandler-tests.js
# util/util-tests.js
# util/validate-tests.js
# azure-tests.js
services/HDInsight/hdinsight-listClusters-unit-tests.js
services/HDInsight/hdinsight-createCluster-unit-tests.js
services/HDInsight/hdinsight-deleteCluster-unit-tests.js
Expand Down

0 comments on commit 2f22c92

Please sign in to comment.