Skip to content

Commit

Permalink
further ES integration
Browse files Browse the repository at this point in the history
  • Loading branch information
sharepointoscar committed Jan 22, 2020
1 parent 9d12c3b commit 0631843
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ENV MONGODB_URI=${MONGO_URI}

ENV ENABLE_ELASTICSEARCH=${ENABLE_ELASTICSEARCH}
ENV DISABLE_SAILS_SEED=${DISABLE_SAILS_SEED}
ENV ELASTICSEARCH_URL=${ELASTICSEARCH_URL}

#RUN npm install -g grunt-cli
#RUN npm install -g bower

Expand Down
8 changes: 5 additions & 3 deletions api/hooks/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ module.exports = function(sails){

if(err){sails.log(JSON.stringify(err,null,2));}

sails.log(JSON.stringify(response,null,2));

//if the car-api index does not exist create it
if(!response){

sails.log('************ INDEX CAR-API DOES NOT EXIST, SO CREATING ********************* ');
client.indices.create(config, function(err,response){

if(err){sails.log(JSON.stringify(err,null,2));
}
else{


sails.log('************ CREATED INDEX CAR-API NOT EXISTED ********************* ');
sails.log(JSON.stringify(response,null,2));
}

Expand Down
4 changes: 2 additions & 2 deletions api/models/Car.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ module.exports = {
afterCreate: function (car, callback){

sails.log("NEW CAR: "+JSON.stringify(car,null,2));
sails.log("IS ELASTIC ENABLEDED: "+ process.env.ENABLE_ELASTICSEARCH);
if(process.env.ENABLE_ELASTICSEARCH == true){
sails.log("IS ELASTIC ENABLED NOW: "+ process.env.ENABLE_ELASTICSEARCH);
if(process.env.ENABLE_ELASTICSEARCH == "true"){
var DSLQuery ={
index: 'car-api',
type: 'car',
Expand Down
8 changes: 3 additions & 5 deletions config/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,15 @@ module.exports.connections = {
adapter: 'elasticsearch',
hosts: [process.env.ELASTICSEARCH_URL],
keepAlive: true,
sniffOnStart: true,
maxRetries: 10,
sniffOnStart: false,
maxRetries: 20,
deadTimeout: 40000,
sniffOnConnectionFault: true,
index:'car-api',
apiVersion: '6.0'
},
productionElasticsearch: {
adapter: 'elasticsearch',
hosts: [process.env.BONSAI_URL],
keepAlive: true,
keepAlive: false,
sniffOnStart: true,
maxRetries: 10,
deadTimeout: 40000,
Expand Down
5 changes: 3 additions & 2 deletions config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ module.exports = {
},

/***************************************************************************
* Set the port in the developm ent environment to 443 *
* Set the port in the development environment *
***************************************************************************/

port: process.env.PORT,
environment: 'development',


hookTimeout: 60000
};


1 change: 0 additions & 1 deletion config/seeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
module.exports.seeds = {

disable: true,
_hookTimeout: 700000,
person: {
overwrite: true,
data: [{
Expand Down
39 changes: 35 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
build:
context: .
dockerfile: Dockerfile
image: sharepointoscar/cars-api:v3
image: sharepointoscar/cars-api:v4
ports:
- '1337:1337'
environment:
Expand All @@ -13,9 +13,12 @@ services:
- MONGODB_HOST=database
- MONGODB_PORT=27017
- MONGODB_URI=mongodb://mongoadmin:password01@database:27017/cars_api?authSource=admin
- ENABLE_ELASTICSEARCH=false
- DISABLE_SAILS_SEED=false
- DISABLE_GRAPHQL=false
- MONGODB_USERNAME=mongoadmin
- MONGODB_PASSWORD=password01
- ENABLE_ELASTICSEARCH=true
- ELASTICSEARCH_URL=localhost:9200
- DISABLE_SAILS_SEED=true
- DISABLE_GRAPHQL=true
depends_on:
- database
links:
Expand All @@ -30,3 +33,31 @@ services:
- 27017:27017
volumes:
- /Users/omedina/Documents:/var/lib/mongodb

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.6
environment:
- cluster.name=oscar-search
- bootstrap.memory_lock=true
- transport.host=localhost
- transport.tcp.port=9300
- http.port=9200
- http.host=0.0.0.0
- cluster.routing.allocation.disk.threshold_enabled=false
- cluster.routing.allocation.disk.watermark.low=2gb
- cluster.routing.allocation.disk.watermark.high=1gb
- cluster.routing.allocation.disk.watermark.flood_stage=512mb
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"

ulimits:
memlock:
soft: -1
hard: -1
ports:
- "9200:9200"
kibana:
image: docker.elastic.co/kibana/kibana:6.8.6
environment:
- opendistro_security.multitenancy.enabled=false
ports:
- "5601:5601"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"scripts": {
"debug": "node debug app.js",
"start": "ENV=development PORT=1337 ENABLE_ELASTICSEARCH=true DISABLE_SAILS_SEED=false DISABLE_GRAPHQL=true node app.js"
"start": "ENV=development PORT=1337 ENABLE_ELASTICSEARCH=true DISABLE_SAILS_SEED=true DISABLE_GRAPHQL=true node app.js"
},
"main": "app.js",
"repository": {
Expand Down

0 comments on commit 0631843

Please sign in to comment.