Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use elasticjs, not $http directly #718

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/app/services/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,24 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
};

this.elasticsearch_load = function(type,id) {
return $http({
url: config.elasticsearch + "/" + config.kibana_index + "/"+type+"/"+id+'?' + new Date().getTime(),
method: "GET",
transformResponse: function(response) {
return renderTemplate(angular.fromJson(response)._source.dashboard, $routeParams);
}
}).error(function(data, status) {
var successcb = function(data) {
var response = renderTemplate(angular.fromJson(data)._source.dashboard, $routeParams);
self.dash_load(response);
};
var errorcb = function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+
alertSrv.set('Error',"Could not contact Elasticsearch at "+ejs.config.server+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"Could not find "+id+". If you"+
" are using a proxy, ensure it is configured correctly",'error');
}
return false;
}).success(function(data) {
self.dash_load(data);
});
};

ejs.client.get(
"/" + config.kibana_index + "/"+type+"/"+id+'?' + new Date().getTime(),
null, successcb, errorcb);
};

this.script_load = function(file) {
Expand Down
28 changes: 14 additions & 14 deletions src/app/services/esVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function (angular, _, config) {

var module = angular.module('kibana.services');

module.service('esVersion', function($http, alertSrv) {
module.service('esVersion', function($http, alertSrv, ejsResource) {

this.versions = [];

Expand All @@ -19,19 +19,19 @@ function (angular, _, config) {
getVersions();
};

var ejs = ejsResource(config.elasticsearch);

var getVersions = function() {
var nodeInfo = $http({
url: config.elasticsearch + '/_nodes',
method: "GET"
}).error(function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"Could not reach "+config.elasticsearch+"/_nodes. If you"+
" are using a proxy, ensure it is configured correctly",'error');
}
});
var nodeInfo = ejs.client.get('/_nodes',
undefined, undefined, function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+ejs.config.server+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"Could not reach "+ejs.config.server+"/_nodes. If you"+
" are using a proxy, ensure it is configured correctly",'error');
}
});

return nodeInfo.then(function(p) {
_.each(p.data.nodes, function(v) {
Expand Down Expand Up @@ -147,4 +147,4 @@ function (angular, _, config) {

});

});
});
30 changes: 15 additions & 15 deletions src/app/services/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function (angular, _, config) {

var module = angular.module('kibana.services');

module.service('fields', function(dashboard, $rootScope, $http, alertSrv) {
module.service('fields', function(dashboard, $rootScope, $http, alertSrv, ejsResource) {
// Save a reference to this
var self = this;

Expand All @@ -32,6 +32,8 @@ function (angular, _, config) {
}
});

var ejs = ejsResource(config.elasticsearch);

var mapFields = function (m) {
var fields = [];
_.each(m, function(types) {
Expand All @@ -43,19 +45,17 @@ function (angular, _, config) {
};

this.map = function(indices) {
var request = $http({
url: config.elasticsearch + "/" + indices.join(',') + "/_mapping",
method: "GET"
}).error(function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"No index found at "+config.elasticsearch+"/" +
indices.join(',')+"/_mapping. Please create at least one index." +
"If you're using a proxy ensure it is configured correctly.",'error');
}
});
var request = ejs.client.get('/' + indices.join(',') + "/_mapping",
undefined, undefined, function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+ejs.config.server+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"No index found at "+ejs.config.server+"/" +
indices.join(',')+"/_mapping. Please create at least one index." +
"If you're using a proxy ensure it is configured correctly.",'error');
}
});

return request.then(function(p) {
var mapping = {};
Expand Down Expand Up @@ -93,4 +93,4 @@ function (angular, _, config) {

});

});
});
28 changes: 14 additions & 14 deletions src/app/services/kbnIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function (angular, _, config, moment) {

var module = angular.module('kibana.services');

module.service('kbnIndex', function($http, alertSrv) {
module.service('kbnIndex', function($http, alertSrv, ejsResource) {
// returns a promise containing an array of all indices matching the index
// pattern that exist in a given range
this.indices = function(from,to,pattern,interval) {
Expand All @@ -25,21 +25,21 @@ function (angular, _, config, moment) {
});
};

var ejs = ejsResource(config.elasticsearch);

// returns a promise containing an array of all indices in an elasticsearch
// cluster
function all_indices() {
var something = $http({
url: config.elasticsearch + "/_aliases",
method: "GET"
}).error(function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"Could not reach "+config.elasticsearch+"/_aliases. If you"+
" are using a proxy, ensure it is configured correctly",'error');
}
});
var something = ejs.client.get('/_aliases',
undefined, undefined, function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at "+ejs.config.server+
". Please ensure that Elasticsearch is reachable from your system." ,'error');
} else {
alertSrv.set('Error',"Could not reach "+ejs.config.server+"/_aliases. If you"+
" are using a proxy, ensure it is configured correctly",'error');
}
});

return something.then(function(p) {
var indices = [];
Expand Down Expand Up @@ -98,4 +98,4 @@ function (angular, _, config, moment) {
}
});

});
});