Skip to content

Commit

Permalink
Merge pull request #53 from shikshalokam/master
Browse files Browse the repository at this point in the history
remove ES
  • Loading branch information
aks30 authored Oct 19, 2021
2 parents f7eb9d6 + 24e8eed commit 41dae04
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 469 deletions.
5 changes: 0 additions & 5 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ INCOMPLETE_SURVEY_SUBMISSION_TOPIC = "dev.sl.incomplete.survey.raw"
KAFKA_GROUP_ID = "survey" // Kafka consumer group for ML Survey Service
IMPROVEMENT_PROJECT_SUBMISSION_TOPIC = "dev.sl.improvement.project.submission" // Kafka topic name for pushing project submission related data

# Elastic search configurations
ELASTICSEARCH_COMMUNICATIONS_ON_OFF = "ON" // Elastic search enable/disable flag E.g. ON/OFF
ELASTICSEARCH_HOST_URL = "http://127.0.0.1:9200" // Elastic search host url
ELASTIC_SEARCH_SNIFF_ON_START = true/false // Flag to obtain ES Nodes list at the time of connection e.g. true/false
ELASTICSEARCH_ENTITIES_INDEX = "entities" // Elastic search index name for storing entity data

# ML Core Service
ML_CORE_SERVICE_URL = "http://ml-core-service:3000" // ML Core Service URL
Expand Down
68 changes: 34 additions & 34 deletions config/db/elasticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@


//dependencies
const { Client : esClient } = require('@elastic/elasticsearch');

/**
* Elastic search connection.
* @function
* @name connect
* @return {Object} elastic search client
*/

var connect = function () {

const elasticSearchClient = new esClient({
node : process.env.ELASTICSEARCH_HOST_URL,
maxRetries : 5,
requestTimeout : 60000,
sniffOnStart : process.env.ELASTIC_SEARCH_SNIFF_ON_START
});

elasticSearchClient.ping({
}, function (error) {
if (error) {
console.log('Elasticsearch cluster is down!');
} else {
console.log('Elasticsearch connection established.');
}
});

return {
client : elasticSearchClient
};

};

module.exports = connect;
// const { Client : esClient } = require('@elastic/elasticsearch');

// /**
// * Elastic search connection.
// * @function
// * @name connect
// * @return {Object} elastic search client
// */

// var connect = function () {

// const elasticSearchClient = new esClient({
// node : process.env.ELASTICSEARCH_HOST_URL,
// maxRetries : 5,
// requestTimeout : 60000,
// sniffOnStart : process.env.ELASTIC_SEARCH_SNIFF_ON_START
// });

// elasticSearchClient.ping({
// }, function (error) {
// if (error) {
// console.log('Elasticsearch cluster is down!');
// } else {
// console.log('Elasticsearch connection established.');
// }
// });

// return {
// client : elasticSearchClient
// };

// };

// module.exports = connect;
8 changes: 4 additions & 4 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ let db_connect = function() {
* @name elasticsearch_connect
*/

let elasticsearch_connect = function () {
global.elasticsearch = require("./db/elasticSearch")();
};
// let elasticsearch_connect = function () {
// global.elasticsearch = require("./db/elasticSearch")();
// };

/**
* Kafka connection information.
Expand All @@ -49,6 +49,6 @@ const configuration = {

db_connect();
kafka_connect();
elasticsearch_connect();
// elasticsearch_connect();

module.exports = configuration;
32 changes: 16 additions & 16 deletions envVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ let enviromentVariables = {
"message" : "OFF/TOPIC_NAME",
"optional" : false
},
"ELASTICSEARCH_COMMUNICATIONS_ON_OFF" : {
"message" : "Enable/Disable elastic search communications",
"optional" : false
},
"ELASTICSEARCH_HOST_URL" : {
"message" : "Required elastic search host",
"optional" : false
},
"ELASTICSEARCH_ENTITIES_INDEX" : {
"message" : "Required entities index",
"optional" : false
},
// "ELASTICSEARCH_COMMUNICATIONS_ON_OFF" : {
// "message" : "Enable/Disable elastic search communications",
// "optional" : false
// },
// "ELASTICSEARCH_HOST_URL" : {
// "message" : "Required elastic search host",
// "optional" : false
// },
// "ELASTICSEARCH_ENTITIES_INDEX" : {
// "message" : "Required entities index",
// "optional" : false
// },
"ML_CORE_SERVICE_URL" : {
"message" : "Required core service url",
"optional" : false
Expand All @@ -82,10 +82,10 @@ let enviromentVariables = {
"message" : "Required keycloak public key path",
"optional" : false
},
"ELASTIC_SEARCH_SNIFF_ON_START" : {
"message" : "Elastic search sniff on start",
"optional" : false
},
// "ELASTIC_SEARCH_SNIFF_ON_START" : {
// "message" : "Elastic search sniff on start",
// "optional" : false
// },
"DISABLE_LEARNER_SERVICE_ON_OFF": {
"message" : "Disable learner service on/off",
"default": "ON"
Expand Down
206 changes: 103 additions & 103 deletions generics/helpers/elasticSearch.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
/**
* name : elasticSearch.js
* author : Aman Jung Karki
* created-date : 11-Jun-2020
* Description : elastic search common functionality
*/

/**
* Get user data
* @function
* @name get
* @param {String} id - a unique document id
* @param {String} index - elastic search index
* @param {String} type - elastic search type
* @returns {Object} Get user data.
*/

var get = function (
id = "",
index = "",
type = ""
) {

return new Promise(async function (resolve, reject) {
try {

if (id == "") {
throw new Error("ID is required");
}

if (index == "") {
throw new Error("Index is required");
}

const result = await elasticsearch.client.get({
id: id,
index: index
}, {
ignore: [httpStatusCode["not_found"].status],
maxRetries: 3
});

return resolve(result);

} catch (error) {
return reject(error);
}
})
};

/**
* Create or update based on user data.
* @function
* @name createOrUpdate
* @param {String} id - a unique document id
* @param {String} index - elastic search index
* @param {String} data - requested data
* @returns {Object} created or updated user data.
*/

var createOrUpdate = function (
id = "",
index = "",
data = ""
) {

return new Promise(async function (resolve, reject) {
try {

if (id == "") {
throw new Error("ID is required");
}

if (index == "") {
throw new Error("Index is required");
}

if (Object.keys(data).length == 0) {
throw new Error("Data is required");
}

let result =
await elasticsearch.client.update({
id : id,
index : index,
body : {
doc : data ,
doc_as_upsert : true
}
});

return resolve(result);

} catch (error) {
return reject(error);
}
})
};

module.exports = {
get : get,
createOrUpdate : createOrUpdate
};
// /**
// * name : elasticSearch.js
// * author : Aman Jung Karki
// * created-date : 11-Jun-2020
// * Description : elastic search common functionality
// */

// /**
// * Get user data
// * @function
// * @name get
// * @param {String} id - a unique document id
// * @param {String} index - elastic search index
// * @param {String} type - elastic search type
// * @returns {Object} Get user data.
// */

// var get = function (
// id = "",
// index = "",
// type = ""
// ) {

// return new Promise(async function (resolve, reject) {
// try {

// if (id == "") {
// throw new Error("ID is required");
// }

// if (index == "") {
// throw new Error("Index is required");
// }

// const result = await elasticsearch.client.get({
// id: id,
// index: index
// }, {
// ignore: [httpStatusCode["not_found"].status],
// maxRetries: 3
// });

// return resolve(result);

// } catch (error) {
// return reject(error);
// }
// })
// };

// *
// * Create or update based on user data.
// * @function
// * @name createOrUpdate
// * @param {String} id - a unique document id
// * @param {String} index - elastic search index
// * @param {String} data - requested data
// * @returns {Object} created or updated user data.


// var createOrUpdate = function (
// id = "",
// index = "",
// data = ""
// ) {

// return new Promise(async function (resolve, reject) {
// try {

// if (id == "") {
// throw new Error("ID is required");
// }

// if (index == "") {
// throw new Error("Index is required");
// }

// if (Object.keys(data).length == 0) {
// throw new Error("Data is required");
// }

// let result =
// await elasticsearch.client.update({
// id : id,
// index : index,
// body : {
// doc : data ,
// doc_as_upsert : true
// }
// });

// return resolve(result);

// } catch (error) {
// return reject(error);
// }
// })
// };

// module.exports = {
// get : get,
// createOrUpdate : createOrUpdate
// };
32 changes: 0 additions & 32 deletions healthCheck/elastic-search.js
Original file line number Diff line number Diff line change
@@ -1,32 +0,0 @@
/**
* name : elastic-search.js.
* author : Aman Karki.
* created-date : 02-Feb-2021.
* Description : Elastic Search health check.
*/

// Dependencies

const { Client : esClient } = require('@elastic/elasticsearch');

function health_check() {
return new Promise( async (resolve,reject) => {

const elasticSearchClient = new esClient({
node: process.env.ELASTICSEARCH_HOST_URL
});

elasticSearchClient.ping({
}, function (error) {
if (error) {
return resolve(false);
} else {
return resolve(true);
}
});
})
}

module.exports = {
health_check : health_check
}
Loading

0 comments on commit 41dae04

Please sign in to comment.