Skip to content

Commit 9549849

Browse files
Merge pull request #78 from gjs29/master
Allow user config when creating a Solr cluster
2 parents 24075ee + 4f72326 commit 9549849

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

examples/retrieve_and_rank_lifecycle.v1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async.series([
2121
},
2222

2323
function createCluster(done) {
24-
retrieve.createCluster({}, function getId(err, res) {
24+
retrieve.createCluster({cluster_name: 'example_cluster', cluster_size: '1'}, function getId(err, res) {
2525
if (err) {
2626
return console.log('Error creating Solr cluster: ' + JSON.stringify(err));
2727
}

services/retrieve_and_rank/v1.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,22 @@ RetrieveAndRank.prototype.deleteClusters = function(params, callback) {
6262
* Creates a Solr cluster.
6363
*
6464
* @param params An Object representing the parameters for this service call.
65-
* This request currently does not require any parameters.
65+
* Optional params
66+
* - cluster_name: name to use for identifying the cluster in responses
67+
* - cluster_size: size of the cluster to create
6668
*
6769
* @param callback The callback.
6870
*/
6971
RetrieveAndRank.prototype.createCluster = function(params, callback) {
70-
return sendRequest('POST', solrClustersPath(), this._options, callback);
72+
// Avoid modifying the global options by making a deep copy
73+
var createOptions = JSON.parse(JSON.stringify(this._options));
74+
createOptions.body = JSON.stringify(params || {});
75+
if (createOptions.headers === undefined) {
76+
createOptions.headers = {};
77+
}
78+
createOptions.headers['Content-Type'] = 'application/json';
79+
80+
return sendRequest('POST', solrClustersPath(), createOptions, callback);
7181
};
7282

7383
/**

services/search/v1.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,22 @@ Search.prototype.deleteClusters = function(params, callback) {
6464
* Creates a Solr cluster.
6565
*
6666
* @param params An Object representing the parameters for this service call.
67-
* This request currently does not require any parameters.
67+
* Optional params
68+
* - cluster_name: name to use for identifying the cluster in responses
69+
* - cluster_size: size of the cluster to create
6870
*
6971
* @param callback The callback.
7072
*/
7173
Search.prototype.createCluster = function(params, callback) {
72-
return sendRequest('POST', solrClustersPath(), this._options, callback);
74+
// Avoid modifying the global options by making a deep copy
75+
var createOptions = JSON.parse(JSON.stringify(this._options));
76+
createOptions.body = JSON.stringify(params || {});
77+
if (createOptions.headers === undefined) {
78+
createOptions.headers = {};
79+
}
80+
createOptions.headers['Content-Type'] = 'application/json';
81+
82+
return sendRequest('POST', solrClustersPath(), createOptions, callback);
7383
};
7484

7585
/**

test/test.retrieve_and_rank.v1.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,27 @@ describe('retrieve_and_rank', function() {
9595
});
9696
});
9797

98-
it('can create a Solr cluster', function(done) {
98+
it('can create a Solr cluster without specified config', function(done) {
9999
search.createCluster({}, function(error, data) {
100100
assert.equal(data, createResponse);
101101
done();
102102
});
103103
});
104104

105+
it('sets headers and body of request when creating a Solr cluster based on params', function(done) {
106+
var createParams = {
107+
cluster_size: '2',
108+
cluster_name: 'the_cluster',
109+
some_other_option: 'some_other_value'
110+
};
111+
112+
var response = search.createCluster(createParams, function(error, data) {});
113+
114+
assert.equal(response.headers['Content-Type'], 'application/json');
115+
assert.deepEqual(JSON.parse(response.body), createParams);
116+
done();
117+
});
118+
105119
it('can poll a Solr cluster', function(done) {
106120
search.pollCluster({clusterId: clusterId}, function(error, data) {
107121
assert.equal(data, pollResponse);

test/test.search.v1.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,27 @@ describe('search', function() {
9595
});
9696
});
9797

98-
it('can create a Solr cluster', function(done) {
98+
it('can create a Solr cluster without specified config', function(done) {
9999
search.createCluster({}, function(error, data) {
100100
assert.equal(data, createResponse);
101101
done();
102102
});
103103
});
104104

105+
it('sets headers and body of request when creating a Solr cluster based on params', function(done) {
106+
var createParams = {
107+
cluster_size: '2',
108+
cluster_name: 'the_cluster',
109+
some_other_option: 'some_other_value'
110+
};
111+
112+
var response = search.createCluster(createParams, function(error, data) {});
113+
114+
assert.equal(response.headers['Content-Type'], 'application/json');
115+
assert.deepEqual(JSON.parse(response.body), createParams);
116+
done();
117+
});
118+
105119
it('can poll a Solr cluster', function(done) {
106120
search.pollCluster({clusterId: clusterId}, function(error, data) {
107121
assert.equal(data, pollResponse);

0 commit comments

Comments
 (0)