Skip to content

Commit

Permalink
Merge pull request #9 from Nasruddin/feature/elastic-search
Browse files Browse the repository at this point in the history
Cleaning up
  • Loading branch information
Nasruddin committed Apr 14, 2022
2 parents 126db5b + 4392b1b commit 6859098
Show file tree
Hide file tree
Showing 29 changed files with 414 additions and 56 deletions.
4 changes: 3 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

31 changes: 31 additions & 0 deletions api-gateway-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#stage 1
#Start with a base image containing Java runtime
FROM openjdk:11-slim as build

# Add Maintainer Info
LABEL maintainer="Nasruddin <[email protected]>"

# The application's jar file
ARG JAR_FILE

# Add the application's jar to the container
COPY ${JAR_FILE} app.jar

#unpackage jar file
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf /app.jar)

#stage 2
#Same Java runtime
FROM openjdk:11-slim

#Add volume pointing to /tmp
VOLUME /tmp

#Copy unpackaged application to new container
ARG DEPENDENCY=/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app

#execute the application
ENTRYPOINT ["java","-cp","app:app/lib/*","com.javatab.gatewayservice.ApiGatewayServiceApplication"]
2 changes: 1 addition & 1 deletion api-gateway-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.javatab</groupId>
<artifactId>api-gateway-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.0</version>
<name>api-gateway-service</name>
<description>Gateway Service using spring cloud gateway</description>
<properties>
Expand Down
3 changes: 2 additions & 1 deletion auth-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ spring:
# max-attempts: 3

datasource:
url: jdbc:postgresql://localhost:5432/testdb
url: jdbc:postgresql://postgres_container1:5432/testdb
username: postgres
password: 123
driver-class-name: org.postgresql.Driver
jpa:
properties:
hibernate:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ management:
include: "*"

eureka:
instance:
prefer-ip-address: true
client:
service-url:
default-zone: http://discoveryservice:8761/eureka/
defaultZone: ${EUREKA_SERVER:http://localhost:8761/eureka}
fetch-registry: true
register-with-eureka: true
30 changes: 30 additions & 0 deletions docker/docker-compose-elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.8"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.0
container_name: elasticsearch
environment:
- node.name=elasticsearch
- discovery.type=single-node
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
# volumes:
# - esdata1:/usr/share/elasticsearch/data
ports:
- "9300:9300"
- "9200:9200"
networks:
- backend

networks:
backend:
driver: bridge

#volumes:
# esdata1:
# driver: local
21 changes: 4 additions & 17 deletions docker/docker-compose-kafka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,22 @@ services:
ports:
- "2181:2181"
networks:
backend:
aliases:
- "zookeeper"
- backend
kafkaserver:
image: wurstmeister/kafka:latest
ports:
- "9092:9092"
environment:
- KAFKA_ADVERTISED_HOST_NAME=192.168.1.8
- KAFKA_ADVERTISED_HOST_NAME=kafka
- KAFKA_ADVERTISED_PORT=9092
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_CREATE_TOPICS=users:1:1,students:1:1,userCreatedOutput:1:1
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
depends_on:
- zookeeper
networks:
backend:
aliases:
- "kafka"
- backend

networks:
backend:
driver: bridge
# redisserver:
# image: redis:alpine
# ports:
# - 6379:6379
# networks:
# backend:
# aliases:
# - "redis"
driver: bridge
8 changes: 7 additions & 1 deletion docker/docker-compose-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ services:
- "5432:5432"
volumes:
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
networks:
- backend
volumes:
database-data: # named volumes can be managed easier using docker-compose
database-data: # named volumes can be managed easier using docker-compose

networks:
backend:
driver: bridge
4 changes: 1 addition & 3 deletions docker/docker-compose-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ services:
ports:
- "6379:6379"
networks:
backend:
aliases:
- "redis"
- backend

networks:
backend:
Expand Down
20 changes: 7 additions & 13 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ services:
ports:
- "8761:8761"
networks:
backend:
aliases:
- "discoveryservice"
- backend
#healthcheck:
# test: [ "CMD", "curl", "-f", "http://discoveryservice:8761/eureka/" ]
# interval: 30s
Expand All @@ -22,9 +20,10 @@ services:
ports:
- "8071:8071"
networks:
backend:
aliases:
- "configserver"
- backend
environment:
- JAVA_OPTS=
-DEUREKA_SERVER=http://discoveryservice:8761/eureka
auth-service:
depends_on:
- discoveryservice
Expand All @@ -34,9 +33,7 @@ services:
ports:
- "9100:9100"
networks:
backend:
aliases:
- "authservice"
- backend
apigatewayservice:
depends_on:
- discoveryservice
Expand All @@ -54,10 +51,7 @@ services:
ports:
- "8200:8200"
networks:
backend:
aliases:
- "course-service"

- backend
networks:
backend:
driver: bridge
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
<module>course-service</module>
<module>api-gateway-service</module>
<module>auth-service</module>
<module>student-service</module>
<module>search-engine</module>
</modules>
</project>
31 changes: 31 additions & 0 deletions search-engine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#stage 1
#Start with a base image containing Java runtime
FROM openjdk:11-slim as build

# Add Maintainer Info
LABEL maintainer="Nasruddin <[email protected]>"

# The application's jar file
ARG JAR_FILE

# Add the application's jar to the container
COPY ${JAR_FILE} app.jar

#unpackage jar file
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf /app.jar)

#stage 2
#Same Java runtime
FROM openjdk:11-slim

#Add volume pointing to /tmp
VOLUME /tmp

#Copy unpackaged application to new container
ARG DEPENDENCY=/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app

#execute the application
ENTRYPOINT ["java","-cp","app:app/lib/*","com.javatab.searchengine.SearchEngineApplication"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.javatab.searchengine;

import com.javatab.searchengine.domain.Student;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;

@Repository
public interface StudentRepository extends ReactiveCrudRepository<Student, String> {
Flux<Student> findStudentByUsername(String username);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.javatab.searchengine.api;

import com.javatab.searchengine.StudentRepository;
import com.javatab.searchengine.domain.Student;
import com.javatab.searchengine.service.StudentService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.util.function.Supplier;

@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class SearchApi {

private final StudentService studentService;
private final StudentRepository studentRepository;

@PostMapping("/create-index")
public Mono<Student> createStudentIndex(@RequestBody Student student) throws IOException {
return studentRepository.save(student);
}

@GetMapping("/id/{userid}")
public Mono<Student> getUserById(@PathVariable("userid") String id) throws IOException {
return studentRepository.findById(id);
}

@GetMapping("/username/{username}")
public Flux<Student> getUserByUsername(@PathVariable("username") String username) throws IOException {
return studentRepository.findStudentByUsername(username);
}
}
Loading

0 comments on commit 6859098

Please sign in to comment.