forked from jasonfill/ColdFusion-ElasticSearch-Client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfig.cfc
More file actions
67 lines (55 loc) · 2.36 KB
/
Config.cfc
File metadata and controls
67 lines (55 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
component accessors="true" extends="Base" {
property name="ElasticSearchClient";
public function init(){
this.indicies = {app={}, hook={}};
return this;
}
public function configure(any event){
//buildSettings(arguments.event);
//buildIndicies();
}
private function buildIndicies(){
for(var i IN this.indicies){
// Create the app index...
local.IndexResponse = doRequest(endpoint=this.indicies[i].endpoint,
Resource="/#this.indicies[i].name#/_settings");
if(!local.IndexResponse.getSuccess() && local.IndexResponse.getStatusCode() == "404"){
// we need to build this index...
local.json = '{
"settings" : {
"number_of_shards" : #this.indicies[i].shards#,
"number_of_replicas" : #this.indicies[i].replicas#
}
}';
local.IndexCreateResponse = doRequest(endpoint=this.indicies[i].endpoint,
Resource="/#this.indicies[i].name#/",
Method="PUT",
Body=local.json);
if(!local.IndexCreateResponse.getSuccess()){
throw(message="There was an error creating the #this.indicies[i].name# for the #getClusterRegion()# region.",
detail = local.IndexCreateResponse.getMessage());
}
}
}
}
private void function buildSettings(any event){
var appProperties = getSettings().getAllProperties();
variables.ClusterRegion = arguments.event.getClusterRegion();
for(var i IN this.indicies){
local.settings = {};
if(structKeyExists(appProperties, "elasticsearch.region.#variables.ClusterRegion#.#i#")){
local.settings.Name = getSettings().getProperty("elasticsearch.region.#variables.ClusterRegion#.#i#");
}
if(structKeyExists(appProperties, "elasticsearch.region.#variables.ClusterRegion#.#i#.url")){
local.settings.EndPoint = getSettings().getProperty("elasticsearch.region.#variables.ClusterRegion#.#i#.url");
}
if(structKeyExists(appProperties, "elasticsearch.region.#variables.ClusterRegion#.#i#.Replicas")){
local.settings.Replicas = getSettings().getProperty("elasticsearch.region.#variables.ClusterRegion#.#i#.Replicas");
}
if(structKeyExists(appProperties, "elasticsearch.region.#variables.ClusterRegion#.#i#.Shards")){
local.settings.Shards = getSettings().getProperty("elasticsearch.region.#variables.ClusterRegion#.#i#.Shards");
}
this.indicies[i] = local.settings;
}
}
}