Commit c9f7fcbc authored by Siva Rama Krishna's avatar Siva Rama Krishna

Initial Commit

parent ee67b0a2
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
\ No newline at end of file
variables:
RELEASE_NAME: "SERVICE_NAME"
SERVICE_PORT: 1099
REGISTRY_URL: 751503455312.dkr.ecr.us-west-2.amazonaws.com/pgnonprod
stages:
- Build
- Test
- ReleaseCleanup
- ReleaseDeploy
Build:
stage: Build
script:
- mvn clean install
- $(aws ecr get-login --no-include-email --region us-west-2)
- docker build -t 751503455312.dkr.ecr.us-west-2.amazonaws.com/pgnonprod:$CI_PIPELINE_ID .
- docker push 751503455312.dkr.ecr.us-west-2.amazonaws.com/pgnonprod:$CI_PIPELINE_ID
ReleaseCleanup:
stage: ReleaseCleanup
script:
- echo `pwd`
- cd ./helm && /sbin/helm delete --purge $RELEASE_NAME && exit 0
allow_failure: true
ReleaseDeploy:
stage: ReleaseDeploy
script:
- echo `pwd`
- sed -i s/#BUILD_ID#/$CI_PIPELINE_ID/g ./helm/service/values.yaml
- sed -i s/#SERVICE_PORT#/$SERVICE_PORT/g ./helm/service/values.yaml
- cd ./helm && /sbin/helm install service --name $RELEASE_NAME
\ No newline at end of file
FROM openjdk:8-jre-alpine
ADD /target/demo-0.0.1-SNAPSHOT.jar //
ENTRYPOINT ["java", "-jar", "/demo-0.0.1-SNAPSHOT.jar"]
# java8_springboot-2.0.5-api-template-3.0
Spring Boot with MySQL
\ No newline at end of file
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: SERVICE_NAME
version: 0.1.0
\ No newline at end of file
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range $.Values.ingress.paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "SERVICE_NAME.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ include "SERVICE_NAME.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "SERVICE_NAME.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "SERVICE_NAME.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
\ No newline at end of file
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "SERVICE_NAME.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "SERVICE_NAME.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "SERVICE_NAME.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "SERVICE_NAME.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
helm.sh/chart: {{ include "SERVICE_NAME.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.internalport }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
\ No newline at end of file
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "SERVICE_NAME.fullname" . -}}
{{- $ingressPaths := .Values.ingress.paths -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
helm.sh/chart: {{ include "SERVICE_NAME.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . | quote }}
http:
paths:
{{- range $ingressPaths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}
{{- end }}
\ No newline at end of file
apiVersion: v1
kind: Service
metadata:
name: {{ include "SERVICE_NAME.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
helm.sh/chart: {{ include "SERVICE_NAME.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
\ No newline at end of file
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "SERVICE_NAME.fullname" . }}-test-connection"
labels:
app.kubernetes.io/name: {{ include "SERVICE_NAME.name" . }}
helm.sh/chart: {{ include "SERVICE_NAME.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "SERVICE_NAME.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
\ No newline at end of file
# Default values for SERVICE_NAME.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: 751503455312.dkr.ecr.us-west-2.amazonaws.com/pgnonprod
tag: #BUILD_ID#
pullPolicy: IfNotPresent
nameOverride: ""
fullnameOverride: ""
service:
type: NodePort
port: 80
internalport: #SERVICE_PORT#
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
#kubernetes.io/tls-acme: "true"
paths:
path: /SERVICE_NAME
hosts:
# - afe6ec7ed3f3711e9b98006759708723-313212737.us-west-2.elb.amazonaws.com
- pgtest.altimetrik.com
tls:
- secretName: custom-tls-cert
hosts:
- pgtest.altimetrik.com
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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.0.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.altimetrik</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>articles</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Swagger based Dependencies -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.20</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
{
"description" : "Maven structured base project with CICD integrated",
"default_interface" : "API"
}
\ No newline at end of file
# Spring properties
spring:
application:
name: article # Service registers under this name
freemarker:
enabled: false # Ignore Eureka dashboard FreeMarker templates
# HTTP Server
server:
port: 1099 # HTTP (Tomcat) port
undertow:
accesslog:
enabled: true
# Logging configurations
logging:
level:
root: INFO
com.memorynotfound: DEBUG
org.springframework.web: INFO
org.springframework.security: INFO
org.hibernate.SQL: WARN
article:
fileName : validator.json
\ No newline at end of file
......@@ -3,21 +3,26 @@
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>
<groupId>com.altimetrik.ee</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot with MySQL</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.altimetrik</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>articles</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<swagger.annotations.version>1.5.20</swagger.annotations.version>
<swagger.version>2.8.0</swagger.version>
</properties>
<dependencies>
......@@ -25,12 +30,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......@@ -40,35 +39,38 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Swagger based Dependencies -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.20</version>
<version>${swagger.annotations.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<version>${swagger.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
<version>${swagger.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency> -->
</dependencies>
<build>
......@@ -79,6 +81,4 @@
</plugin>
</plugins>
</build>
</project>
package com.altimetrik;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
@EnableAsync
public class Application {
public static void main(String[] args) {
System.out.println("App started...miami demo - day 2 Welcome to Articles Publishing Service.");
SpringApplication.run(Application.class, args);
}
}
package com.altimetrik.controllers;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/hello")
public class Hello {
@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.ALL_VALUE)
public ResponseEntity<String> getUserDetailByGitlabEmailId() {
return new ResponseEntity<>("Wecome to Playground...Java-007", HttpStatus.OK);
}
}
package com.altimetrik.ee.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.altimetrik.ee.demo.service.ComponentDetailsService;
@EnableAsync
@EnableScheduling
@SpringBootApplication(scanBasePackages = { "com.altimetrik" })
@PropertySource("classpath:db-config.properties")
public class Application {
private static ConfigurableApplicationContext context;
public static void main(String[] args) {
context = SpringApplication.run(Application.class, args);
context.getBean(ComponentDetailsService.class)
.createComponentDetails(context.getEnvironment().getProperty("spring.application.name"));
}
}
package com.altimetrik.ee.demo.bean;
public class ComponentDetailsBean {
private String componentName;
private String componentIdentifier;
public ComponentDetailsBean() {
super();
}
public ComponentDetailsBean(String componentName, String componentIdentifier) {
super();
this.componentName = componentName;
this.componentIdentifier = componentIdentifier;
}
public String getComponentName() {
return componentName;
}
public void setComponentName(String componentName) {
this.componentName = componentName;
}
public String getComponentIdentifier() {
return componentIdentifier;
}
public void setComponentIdentifier(String componentIdentifier) {
this.componentIdentifier = componentIdentifier;
}
@Override
public String toString() {
return "ComponentDetailsBean [componentName=" + componentName + ", componentIdentifier=" + componentIdentifier
+ "]";
}
}
package com.altimetrik.ee.demo.bean;
import java.util.List;
public class PairedComponentDetailsBean extends ComponentDetailsBean {
private List<ComponentDetailsBean> pairedComponentDetails;
public PairedComponentDetailsBean() {
super();
}
public PairedComponentDetailsBean(final String componentName, final String componentIdentifier) {
super(componentName, componentIdentifier);
}
public PairedComponentDetailsBean(final String componentName, final String componentIdentifier,
final List<ComponentDetailsBean> pairedComponentDetails) {
super(componentName, componentIdentifier);
this.pairedComponentDetails = pairedComponentDetails;
}
public PairedComponentDetailsBean(final ComponentDetailsBean componentDetails,
final List<ComponentDetailsBean> pairedComponentDetails) {
super(componentDetails.getComponentName(), componentDetails.getComponentIdentifier());
this.pairedComponentDetails = pairedComponentDetails;
}
public List<ComponentDetailsBean> getPairedComponentDetails() {
return pairedComponentDetails;
}
public void setPairedComponentDetails(List<ComponentDetailsBean> pairedComponentDetails) {
this.pairedComponentDetails = pairedComponentDetails;
}
}
/**
* Copyright (C) Altimetrik 2018. All rights reserved.
*
* This software is the confidential and proprietary information
* of Altimetrik. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms and conditions
* entered into with Altimetrik.
*/
package com.altimetrik.config;
import static springfox.documentation.builders.PathSelectors.regex;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
*
* @author MMelavanki
*
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
// Production closes swagger
private boolean enableSwagger=true;
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("com.altimetrik.controllers")).paths(regex("/.*")).build()
.enable(enableSwagger).apiInfo(metaData());
}
private ApiInfo metaData() {
return new ApiInfo("Playground Application", "Playground API Services", "2.0",
"https://www.altimetrik.com/privacy-policy/", new Contact("Playground", "https://playground.altimetrik.com", "pg-mgr1@altimetrik.com"),
"Apache License Version 2.0", "https://www.apache.org/licenses/LICENSE-2.0", Collections.emptyList());
}
}
package com.altimetrik.ee.demo.config;
import static springfox.documentation.builders.PathSelectors.regex;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.altimetrik.ee.demo.controller")).paths(regex("/.*"))
.build().enable(true).apiInfo(metaData());
}
private ApiInfo metaData() {
return new ApiInfo("Demo Application", "Demo API Services", "2.0", "https://www.altimetrik.com/privacy-policy/",
new Contact("Playground", "https://playground.altimetrik.com", "pg-mgr1@altimetrik.com"),
"Apache License Version 2.0", "https://www.apache.org/licenses/LICENSE-2.0", Collections.emptyList());
}
}
package com.altimetrik.controllers;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/")
public class Default {
@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.ALL_VALUE)
public ResponseEntity<String> getUserDetailByGitlabEmailId() {
return new ResponseEntity<>("Wecome to Playground...Java-007", HttpStatus.OK);
}
}
package com.altimetrik.ee.demo.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/")
public class Default {
@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.ALL_VALUE)
public ResponseEntity<String> getUserDetailByGitlabEmailId() {
return new ResponseEntity<>("Wecome to Playground Engineering Environment", HttpStatus.OK);
}
}
package com.altimetrik.ee.demo.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.altimetrik.ee.demo.bean.PairedComponentDetailsBean;
import com.altimetrik.ee.demo.service.ComponentDetailsService;
import io.swagger.annotations.ApiOperation;
@RestController
@RequestMapping(value = "/service")
public class ServiceController {
protected static Logger logger = LoggerFactory.getLogger(ServiceController.class.getName());
@Value("${spring.application.name}")
private String applicationName;
@Autowired
private ComponentDetailsService componentDetailsService;
@GetMapping(value = "/")
@ApiOperation(value = "Get service name and identifier", notes = "Get service details and its corresponding values for all paired services", response = PairedComponentDetailsBean.class)
public PairedComponentDetailsBean findAll() {
return componentDetailsService.findAll(this.applicationName);
}
}
package com.altimetrik.ee.demo.entity;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
@Entity
@Table(name = "component_details")
public class ComponentDetailsEntity {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "component_name")
private String componentName;
@Column(name = "component_identifier")
private String componentIdentifier;
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_date", nullable = false, updatable = false)
private Date createdDate;
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "updated_date")
private Date updatedDate;
public ComponentDetailsEntity() {
super();
}
public ComponentDetailsEntity(String componentName, String componentIdentifier) {
super();
this.componentName = componentName;
this.componentIdentifier = componentIdentifier;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getComponentName() {
return componentName;
}
public void setComponentName(String componentName) {
this.componentName = componentName;
}
public String getComponentIdentifier() {
return componentIdentifier;
}
public void setComponentIdentifier(String componentIdentifier) {
this.componentIdentifier = componentIdentifier;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((componentIdentifier == null) ? 0 : componentIdentifier.hashCode());
result = prime * result + ((componentName == null) ? 0 : componentName.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ComponentDetailsEntity other = (ComponentDetailsEntity) obj;
if (componentIdentifier == null) {
if (other.componentIdentifier != null)
return false;
} else if (!componentIdentifier.equals(other.componentIdentifier))
return false;
if (componentName == null) {
if (other.componentName != null)
return false;
} else if (!componentName.equals(other.componentName))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public String toString() {
return "ComponentDetailsEntity [id=" + id + ", componentName=" + componentName + ", componentIdentifier="
+ componentIdentifier + "]";
}
}
package com.altimetrik.ee.demo.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.altimetrik.ee.demo.bean.ComponentDetailsBean;
import com.altimetrik.ee.demo.entity.ComponentDetailsEntity;
@Repository
public interface ComponentDetailsRepository extends JpaRepository<ComponentDetailsEntity, Long> {
<S extends ComponentDetailsEntity> S save(final S componentDetails);
<S extends ComponentDetailsEntity> List<S> save(final Iterable<S> componentDetails);
ComponentDetailsEntity findByComponentName(final String componentName);
ComponentDetailsEntity findByComponentIdentifier(final String componentIdentifier);
@Query("SELECT new com.altimetrik.ee.demo.bean.ComponentDetailsBean(c.componentName,c.componentIdentifier) FROM ComponentDetailsEntity c WHERE c.componentName = (:componentName)")
ComponentDetailsBean getByComponentName(@Param("componentName") final String componentName);
@Query("SELECT new com.altimetrik.ee.demo.bean.ComponentDetailsBean(c.componentName,c.componentIdentifier) FROM ComponentDetailsEntity c WHERE c.componentName != (:componentName)")
List<ComponentDetailsBean> getByComponentNameNotIn(@Param("componentName") final String componentName);
}
package com.altimetrik.ee.demo.service;
import org.springframework.stereotype.Service;
import com.altimetrik.ee.demo.bean.PairedComponentDetailsBean;
@Service
public interface ComponentDetailsService {
boolean createComponentDetails(final String applicationName);
PairedComponentDetailsBean findAll(final String applicationName);
}
package com.altimetrik.ee.demo.service.impl;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import com.altimetrik.ee.demo.bean.PairedComponentDetailsBean;
import com.altimetrik.ee.demo.entity.ComponentDetailsEntity;
import com.altimetrik.ee.demo.repository.ComponentDetailsRepository;
import com.altimetrik.ee.demo.service.ComponentDetailsService;
@Service
public class ComponentDetailsServiceImpl implements ComponentDetailsService {
protected static Logger logger = LoggerFactory.getLogger(ComponentDetailsServiceImpl.class.getName());
@Value("${spring.application.name}")
private String applicationName;
@Autowired
private ComponentDetailsRepository componentDetailsRepository;
@Override
public PairedComponentDetailsBean findAll(final String applicationName) {
final PairedComponentDetailsBean pairedComponentDetails = new PairedComponentDetailsBean(
this.componentDetailsRepository.getByComponentName(applicationName),
this.componentDetailsRepository.getByComponentNameNotIn(applicationName));
return pairedComponentDetails;
}
@Override
public boolean createComponentDetails(final String applicationName) {
if (this.componentDetailsRepository.findByComponentName(applicationName) == null) {
this.componentDetailsRepository
.save(new ComponentDetailsEntity(applicationName, UUID.randomUUID().toString()));
}
return true;
}
@Scheduled(cron = "${cron.component.identifier.reg-ex}")
public void regenerateComponentIdentifier() {
final ComponentDetailsEntity componentDetails = this.componentDetailsRepository
.findByComponentName(this.applicationName);
componentDetails.setComponentIdentifier(UUID.randomUUID().toString());
this.componentDetailsRepository.save(componentDetails);
}
}
# Spring properties
spring:
application:
name: article # Service registers under this name
freemarker:
enabled: false # Ignore Eureka dashboard FreeMarker templates
# HTTP Server
server:
port: 1099 # HTTP (Tomcat) port
undertow:
accesslog:
enabled: true
# Logging configurations
logging:
level:
root: INFO
com.memorynotfound: DEBUG
org.springframework.web: INFO
org.springframework.security: INFO
org.hibernate.SQL: WARN
article:
fileName : validator.json
\ No newline at end of file
# Spring properties
spring:
application:
name: demo # Service registers under this name
cron:
component:
identifier:
reg-ex: 0/5 * * * * ?
# HTTP Server
server:
# port: 8090 # HTTP (Tomcat) port
undertow:
accesslog:
enabled: true
# Logging configurations
logging:
level:
root: INFO
com.memorynotfound: DEBUG
org.springframework.web: INFO
org.springframework.security: INFO
org.hibernate.SQL: WARN
# Spring Boot automatically creates a JPA EntityManagerFactory using Hibernate
# but we need to override some defaults:
spring.jpa.hibernate.ddl-auto: create
spring.jpa.hibernate.show_sql= true
spring.jpa.hibernate.naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.hibernate.naming.physical-strategy= org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.open-in-view = true
# Spring performance optimization
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.properties.javax.persistence.query.timeout= 60000
spring.jpa.properties.hibernate.query.plan_cache_max_soft_references= 1024
spring.jpa.properties.hibernate.query.plan_cache_max_strong_references= 64
spring.jpa.properties.hibernate.query.plan_cache_max_size= 1024
spring.jpa.properties.hibernate.query.plan_parameter_metadata_max_size= 32
spring.jpa.show-sql: true
# Connection properties
spring.datasource.url= jdbc:mysql://db:3306/ee_demo?autoReconnect=true&useSSL=false
spring.datasource.username= demouser
spring.datasource.password= password
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle= true
spring.datasource.validationQuery= SELECT 1
spring.datasource.driver-class-name= com.mysql.jdbc.Driver
package com.altimetrik;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ArticlesApplicationTests {
@Test
public void contextLoads() {
}
}
package com.altimetrik.ee.demo.tests;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests {
@Test
public void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment