diff --git a/lib/services/serviceManagement/hdinsightservice.js b/lib/services/serviceManagement/hdinsightservice.js index ec84c8904b..5ddcd908bc 100644 --- a/lib/services/serviceManagement/hdinsightservice.js +++ b/lib/services/serviceManagement/hdinsightservice.js @@ -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 @@ -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'); @@ -309,7 +416,7 @@ HDInsightService.prototype.listClusters = function (callback) { cloudServices.push (cloudService[i]); } - responseObject.response.body.CloudServices.CloudService = cloudServices; + responseObject.response.body = transformResponse(cloudServices); } } diff --git a/lib/util/util.js b/lib/util/util.js index 52655be66c..16cc42ccde 100644 --- a/lib/util/util.js +++ b/lib/util/util.js @@ -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; }; diff --git a/test/services/HDInsight/hdinsight-createCluster-unit-tests.js b/test/services/HDInsight/hdinsight-createCluster-unit-tests.js index b142b1ab82..6d4c3c2a7f 100644 --- a/test/services/HDInsight/hdinsight-createCluster-unit-tests.js +++ b/test/services/HDInsight/hdinsight-createCluster-unit-tests.js @@ -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 = {}; diff --git a/test/services/HDInsight/hdinsight-listClusters-unit-tests.js b/test/services/HDInsight/hdinsight-listClusters-unit-tests.js index aed05f43f8..6e5d89631b 100644 --- a/test/services/HDInsight/hdinsight-listClusters-unit-tests.js +++ b/test/services/HDInsight/hdinsight-listClusters-unit-tests.js @@ -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); }); }); @@ -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); - }); - }); - }); diff --git a/test/services/HDInsight/namespace-tests.js b/test/services/HDInsight/namespace-tests.js index 525156a13b..d34c6ae226 100644 --- a/test/services/HDInsight/namespace-tests.js +++ b/test/services/HDInsight/namespace-tests.js @@ -17,7 +17,7 @@ var azureUtil = require('../../../lib/util/util.js'); // Test includes -var assert = require('assert'); +var should = require('should'); describe('HDInsight Namespace Test', function() { @@ -25,27 +25,32 @@ describe('HDInsight Namespace Test', function() { 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(); }); diff --git a/test/testlist.txt b/test/testlist.txt index b265ab70a2..fb2b0e3de0 100644 --- a/test/testlist.txt +++ b/test/testlist.txt @@ -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