-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit de2e980
Showing
89 changed files
with
3,629 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*.DS_Store | ||
build/ | ||
target/ | ||
bin/ | ||
dependency-reduced-pom.xml | ||
.classpath | ||
.project | ||
.settings/ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
*.idea | ||
*.log | ||
Thumbs.db |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
ARG MVN_VERSION=3.6.3 | ||
ARG JDK_VERSION=11 | ||
|
||
FROM maven:${MVN_VERSION}-jdk-${JDK_VERSION}-slim as build | ||
|
||
WORKDIR /build | ||
COPY pom.xml . | ||
# creates a layer with all of the Manven dependencies, first time it takes a while consequent call are very fast | ||
RUN mvn dependency:go-offline | ||
|
||
COPY ./pom.xml /tmp/ | ||
COPY ./src /tmp/src/ | ||
WORKDIR /tmp/ | ||
RUN mvn clean package | ||
|
||
WORKDIR /application | ||
COPY target/*.jar application.jar | ||
RUN java -Djarmode=layertools -jar application.jar extract | ||
|
||
FROM gcr.io/distroless/java:${JDK_VERSION} | ||
|
||
USER nonroot:nonroot | ||
WORKDIR application | ||
|
||
COPY --from=build --chown=nonroot:nonroot /application/dependencies/ ./ | ||
COPY --from=build --chown=nonroot:nonroot /application/snapshot-dependencies/ ./ | ||
COPY --from=build --chown=nonroot:nonroot /application/resources/ ./ | ||
COPY --from=build --chown=nonroot:nonroot /application/application/ ./ | ||
|
||
EXPOSE 8080 | ||
|
||
ENV _JAVA_OPTIONS "-XX:MinRAMPercentage=60.0 -XX:MaxRAMPercentage=90.0 \ | ||
-Djava.security.egd=file:/dev/./urandom \ | ||
-Djava.awt.headless=true -Dfile.encoding=UTF-8 \ | ||
-Dspring.output.ansi.enabled=ALWAYS \ | ||
-Dspring.profiles.active=default" | ||
|
||
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.3.0.M2</version> | ||
</parent> | ||
<artifactId>department-service</artifactId> | ||
<groupId>vmware.services</groupId> | ||
<version>1.1</version> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>Hoxton.SR2</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-kubernetes-all</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-openfeign</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-mongodb</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger2</artifactId> | ||
<version>2.9.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-sleuth</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spring-milestones</id> | ||
<name>Spring Milestones</name> | ||
<url>https://repo.spring.io/milestone</url> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>spring-milestones</id> | ||
<name>Spring Milestones</name> | ||
<url>https://repo.spring.io/milestone</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<layout>LAYERED_JAR</layout> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Class-Path: | ||
|
42 changes: 42 additions & 0 deletions
42
department-service/src/main/java/vmware/services/department/DepartmentApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package vmware.services.department; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; | ||
import org.springframework.cloud.netflix.ribbon.RibbonClients; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; | ||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
import vmware.services.department.config.RibbonConfiguration; | ||
|
||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
@EnableFeignClients | ||
@EnableMongoRepositories | ||
@EnableSwagger2 | ||
@AutoConfigureAfter(RibbonAutoConfiguration.class) | ||
@RibbonClients(defaultConfiguration = RibbonConfiguration.class) | ||
public class DepartmentApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DepartmentApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public Docket swaggerApi() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.select() | ||
.apis(RequestHandlerSelectors.basePackage("vmware.services.department.controller")) | ||
.paths(PathSelectors.any()) | ||
.build() | ||
.apiInfo(new ApiInfoBuilder().version("1.0").title("Department API").description("Documentation Department API v1.0").build()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
department-service/src/main/java/vmware/services/department/client/EmployeeClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package vmware.services.department.client; | ||
|
||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import vmware.services.department.model.Employee; | ||
|
||
import java.util.List; | ||
|
||
@FeignClient(name = "employee") | ||
public interface EmployeeClient { | ||
|
||
@GetMapping("/department/{departmentId}") | ||
List<Employee> findByDepartment(@PathVariable("departmentId") String departmentId); | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
department-service/src/main/java/vmware/services/department/config/RibbonConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package vmware.services.department.config; | ||
|
||
import com.netflix.client.config.IClientConfig; | ||
import com.netflix.loadbalancer.Server; | ||
import com.netflix.loadbalancer.ServerList; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.cloud.client.discovery.DiscoveryClient; | ||
import org.springframework.cloud.netflix.ribbon.StaticServerList; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
public class RibbonConfiguration { | ||
|
||
@Autowired | ||
private DiscoveryClient discoveryClient; | ||
|
||
private String serviceId = "client"; | ||
protected static final String VALUE_NOT_SET = "__not__set__"; | ||
protected static final String DEFAULT_NAMESPACE = "ribbon"; | ||
|
||
public RibbonConfiguration() { | ||
} | ||
|
||
public RibbonConfiguration(String serviceId) { | ||
this.serviceId = serviceId; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public ServerList<?> ribbonServerList(IClientConfig config) { | ||
|
||
Server[] servers = discoveryClient.getInstances(config.getClientName()).stream() | ||
.map(i -> new Server(i.getHost(), i.getPort())) | ||
.toArray(Server[]::new); | ||
|
||
return new StaticServerList(servers); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...ent-service/src/main/java/vmware/services/department/controller/DepartmentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package vmware.services.department.controller; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
import vmware.services.department.client.EmployeeClient; | ||
import vmware.services.department.model.Department; | ||
import vmware.services.department.model.Employee; | ||
import vmware.services.department.repository.DepartmentRepository; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
public class DepartmentController { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DepartmentController.class); | ||
|
||
@Autowired | ||
DepartmentRepository repository; | ||
@Autowired | ||
EmployeeClient employeeClient; | ||
|
||
@GetMapping("/feign") | ||
public List<Employee> listRest() { | ||
return employeeClient.findByDepartment("1"); | ||
} | ||
|
||
@PostMapping("/") | ||
public Department add(@RequestBody Department department) { | ||
LOGGER.info("Department add: {}", department); | ||
return repository.save(department); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public Department findById(@PathVariable("id") String id) { | ||
LOGGER.info("Department find: id={}", id); | ||
return repository.findById(id).get(); | ||
} | ||
|
||
@GetMapping("/") | ||
public Iterable<Department> findAll() { | ||
LOGGER.info("Department find"); | ||
return repository.findAll(); | ||
} | ||
|
||
@GetMapping("/organization/{organizationId}") | ||
public List<Department> findByOrganization(@PathVariable("organizationId") Long organizationId) { | ||
LOGGER.info("Department find: organizationId={}", organizationId); | ||
return repository.findByOrganizationId(organizationId); | ||
} | ||
|
||
@GetMapping("/organization/{organizationId}/with-employees") | ||
public List<Department> findByOrganizationWithEmployees(@PathVariable("organizationId") Long organizationId) { | ||
LOGGER.info("Department find: organizationId={}", organizationId); | ||
List<Department> departments = repository.findByOrganizationId(organizationId); | ||
departments.forEach(d -> d.setEmployees(employeeClient.findByDepartment(d.getId()))); | ||
return departments; | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
department-service/src/main/java/vmware/services/department/model/Department.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package vmware.services.department.model; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.annotation.Transient; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Document(collection = "department") | ||
public class Department { | ||
|
||
@Id | ||
private String id; | ||
private Long organizationId; | ||
private String name; | ||
@Transient | ||
private List<Employee> employees = new ArrayList<>(); | ||
|
||
public Department() { | ||
|
||
} | ||
|
||
public Department(Long organizationId, String name) { | ||
super(); | ||
this.organizationId = organizationId; | ||
this.name = name; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getOrganizationId() { | ||
return organizationId; | ||
} | ||
|
||
public void setOrganizationId(Long organizationId) { | ||
this.organizationId = organizationId; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public List<Employee> getEmployees() { | ||
return employees; | ||
} | ||
|
||
public void setEmployees(List<Employee> employees) { | ||
this.employees = employees; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Department [id=" + id + ", organizationId=" + organizationId + ", name=" + name + "]"; | ||
} | ||
|
||
} |
Oops, something went wrong.