Compare commits
8 Commits
saga-rollb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd0f9fc4fd | ||
|
|
03ee20230b | ||
|
|
776e44a444 | ||
|
|
72ee30e19e | ||
|
|
4f17340a9b | ||
|
|
dce8398a6a | ||
|
|
9eb405da62 | ||
|
|
4138076baf |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -32,7 +32,6 @@ dependency-reduced-pom.xml
|
||||
dump.rdb
|
||||
interpolated*.xml
|
||||
lib/
|
||||
library/
|
||||
manifest.yml
|
||||
overridedb.*
|
||||
settings.xml
|
||||
@@ -43,4 +42,4 @@ secrets.yml
|
||||
.gradletasknamecache
|
||||
.sts4-cache
|
||||
node_modules
|
||||
.dist/
|
||||
.dist/
|
||||
@@ -1,55 +0,0 @@
|
||||
# Maven
|
||||
# Build your Java project and run tests with Apache Maven.
|
||||
# Add steps that analyze code, save build artifacts, deploy, and more:
|
||||
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
|
||||
|
||||
trigger:
|
||||
- master
|
||||
|
||||
variables:
|
||||
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
|
||||
MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
|
||||
|
||||
pool:
|
||||
vmImage: 'ubuntu-latest'
|
||||
|
||||
steps:
|
||||
- task: Cache@2
|
||||
inputs:
|
||||
key: 'maven | "$(Agent.OS)" | **/pom.xml'
|
||||
restoreKeys: |
|
||||
maven | "$(Agent.OS)"
|
||||
maven
|
||||
path: $(MAVEN_CACHE_FOLDER)
|
||||
displayName: Cache Maven local repo
|
||||
- task: Maven@3
|
||||
inputs:
|
||||
mavenPomFile: 'pom.xml'
|
||||
options: '-Dmaven.test.skip=true -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
|
||||
publishJUnitResults: false
|
||||
javaHomeOption: 'JDKVersion'
|
||||
mavenVersionOption: 'Default'
|
||||
mavenAuthenticateFeed: false
|
||||
effectivePomSkip: false
|
||||
sonarQubeRunAnalysis: false
|
||||
- task: CopyFiles@2
|
||||
inputs:
|
||||
SourceFolder: '$(system.defaultworkingdirectory)'
|
||||
Contents: |
|
||||
**/*.jar
|
||||
Dockerfile
|
||||
kubernetes/*
|
||||
TargetFolder: '$(build.artifactstagingdirectory)'
|
||||
|
||||
- task: PublishPipelineArtifact@1
|
||||
inputs:
|
||||
targetPath: '$(build.artifactstagingdirectory)'
|
||||
artifact: 'target'
|
||||
publishLocation: 'pipeline'
|
||||
|
||||
- task: Docker@2
|
||||
inputs:
|
||||
containerRegistry: 'myEventstormingRegistry'
|
||||
repository: 'order'
|
||||
command: 'buildAndPush'
|
||||
Dockerfile: '**/Dockerfile'
|
||||
@@ -37,7 +37,7 @@ stages:
|
||||
pool:
|
||||
vmImage: $(vmImageName)
|
||||
steps:
|
||||
- task: Cache@2
|
||||
- task: CacheBeta@1
|
||||
inputs:
|
||||
key: 'maven | "$(Agent.OS)" | **/pom.xml'
|
||||
restoreKeys: |
|
||||
@@ -53,19 +53,6 @@ stages:
|
||||
jdkVersionOption: '1.8'
|
||||
jdkArchitectureOption: 'x64'
|
||||
goals: 'package'
|
||||
- task: CopyFiles@2
|
||||
inputs:
|
||||
SourceFolder: '$(system.defaultworkingdirectory)'
|
||||
Contents: |
|
||||
**/*.jar
|
||||
Dockerfile
|
||||
kubernetes/*
|
||||
TargetFolder: '$(build.artifactstagingdirectory)'
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
|
||||
ArtifactName: 'artifact'
|
||||
publishLocation: 'Container'
|
||||
- task: Docker@2
|
||||
inputs:
|
||||
containerRegistry: $(containerRegistryDockerConnection)
|
||||
|
||||
99
buildspec.yml
Normal file
99
buildspec.yml
Normal file
@@ -0,0 +1,99 @@
|
||||
version: 0.2
|
||||
|
||||
env:
|
||||
variables:
|
||||
_PROJECT_NAME: "orders"
|
||||
|
||||
phases:
|
||||
install:
|
||||
runtime-versions:
|
||||
java: openjdk8
|
||||
docker: 18
|
||||
commands:
|
||||
- echo install kubectl
|
||||
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
|
||||
- chmod +x ./kubectl
|
||||
- mv ./kubectl /usr/local/bin/kubectl
|
||||
pre_build:
|
||||
commands:
|
||||
- echo Logging in to Amazon ECR...
|
||||
- echo $_PROJECT_NAME
|
||||
- echo $AWS_ACCOUNT_ID
|
||||
- echo $AWS_DEFAULT_REGION
|
||||
- echo $CODEBUILD_RESOLVED_SOURCE_VERSION
|
||||
- echo start command
|
||||
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
|
||||
build:
|
||||
commands:
|
||||
- echo Build started on `date`
|
||||
- echo Building the Docker image...
|
||||
- mvn package -Dmaven.test.skip=true
|
||||
- docker build -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$_PROJECT_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION .
|
||||
post_build:
|
||||
commands:
|
||||
- echo Pushing the Docker image...
|
||||
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$_PROJECT_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION
|
||||
- echo connect kubectl
|
||||
- kubectl config set-cluster k8s --server="$KUBE_URL" --insecure-skip-tls-verify=true
|
||||
- kubectl config set-credentials admin --token="$KUBE_TOKEN"
|
||||
- kubectl config set-context default --cluster=k8s --user=admin
|
||||
- kubectl config use-context default
|
||||
- |
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: $_PROJECT_NAME
|
||||
labels:
|
||||
app: $_PROJECT_NAME
|
||||
spec:
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
selector:
|
||||
app: $_PROJECT_NAME
|
||||
EOF
|
||||
- |
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: $_PROJECT_NAME
|
||||
labels:
|
||||
app: $_PROJECT_NAME
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: $_PROJECT_NAME
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: $_PROJECT_NAME
|
||||
spec:
|
||||
containers:
|
||||
- name: $_PROJECT_NAME
|
||||
image: $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$_PROJECT_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /actuator/health
|
||||
port: 8080
|
||||
initialDelaySeconds: 10
|
||||
timeoutSeconds: 2
|
||||
periodSeconds: 5
|
||||
failureThreshold: 10
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /actuator/health
|
||||
port: 8080
|
||||
initialDelaySeconds: 120
|
||||
timeoutSeconds: 2
|
||||
periodSeconds: 5
|
||||
failureThreshold: 5
|
||||
EOF
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- '/root/.m2/**/*'
|
||||
@@ -102,7 +102,7 @@ options:
|
||||
env:
|
||||
# # location/name of GKE cluster (used by all kubectl commands)
|
||||
- CLOUDSDK_COMPUTE_ZONE=asia-northeast1-a
|
||||
- CLOUDSDK_CONTAINER_CLUSTER=standard-cluster-1
|
||||
- CLOUDSDK_CONTAINER_CLUSTER=cluster-1
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Order {
|
||||
|
||||
if("true".equalsIgnoreCase(env.getProperty("checkStock"))){
|
||||
// 1. 주문에 대한 상품 조회 - API
|
||||
String productUrl = env.getProperty("productUrl") + "/product/" + productId;
|
||||
String productUrl = env.getProperty("api.url.product") + "/product/" + productId;
|
||||
|
||||
ResponseEntity<String> productEntity = restTemplate.getForEntity(productUrl, String.class);
|
||||
JsonParser parser = new JsonParser();
|
||||
@@ -49,7 +49,7 @@ public class Order {
|
||||
price = jsonObject.get("price").getAsInt();
|
||||
productName = jsonObject.get("name").getAsString();
|
||||
if( jsonObject.get("stock").getAsInt() < getQuantity()){
|
||||
// throw new OrderException("No Available stock!");
|
||||
throw new OrderException("No Available stock!");
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class Order {
|
||||
price = product.getPrice();
|
||||
productName = product.getName();
|
||||
if( product.getStock() < getQuantity()){
|
||||
// throw new OrderException("No Available stock!");
|
||||
throw new OrderException("No Available stock!");
|
||||
}
|
||||
}
|
||||
this.setPrice(price);
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.example.template;
|
||||
|
||||
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.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@RestController
|
||||
public class OrderController {
|
||||
|
||||
private static final String RESPONSE_STRING_FORMAT = "order => %s\n";
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Value("${delivery.api.url:http://delivery:8080}")
|
||||
private String remoteURL;
|
||||
|
||||
@PostMapping("/order")
|
||||
ResponseEntity<String> fakeOrder(@RequestBody String data) {
|
||||
try {
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(remoteURL + "/startDelivery", data, String.class);
|
||||
String response = responseEntity.getBody();
|
||||
|
||||
logger.info(String.format(RESPONSE_STRING_FORMAT, response.trim()));
|
||||
|
||||
return ResponseEntity.ok(String.format(RESPONSE_STRING_FORMAT, response.trim()));
|
||||
} catch (Exception ex) {
|
||||
logger.warn("Exception trying to get the response from order service.", ex);
|
||||
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
|
||||
.body(String.format(RESPONSE_STRING_FORMAT, ex.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,16 @@
|
||||
package com.example.template;
|
||||
|
||||
import com.example.template.config.kafka.KafkaProcessor;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class OrderService {
|
||||
public class PolicyHandler {
|
||||
|
||||
@Autowired
|
||||
private ProductRepository productRepository;
|
||||
@Autowired
|
||||
private OrderRepository orderRepository;
|
||||
|
||||
/**
|
||||
* 상품 변경이 발생할때마다, 상품정보를 저장해 놓음
|
||||
@@ -43,19 +32,4 @@ public class OrderService {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@StreamListener(KafkaProcessor.INPUT)
|
||||
public void onProductOutOfStock(@Payload ProductOutOfStock productOutOfStock) {
|
||||
try {
|
||||
if (productOutOfStock.isMe()) {
|
||||
System.out.println("##### listener : " + productOutOfStock.toJson());
|
||||
Optional<Order> orderOptional = orderRepository.findById(productOutOfStock.getOrderId());
|
||||
Order order = orderOptional.get();
|
||||
order.setState("OrderCancelled");
|
||||
orderRepository.save(order);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.example.template;
|
||||
|
||||
public class ProductOutOfStock extends AbstractEvent {
|
||||
|
||||
private String stateMessage = "재고량 바닥";
|
||||
private Long productId;
|
||||
private Long orderId;
|
||||
|
||||
public String getStateMessage() {
|
||||
return stateMessage;
|
||||
}
|
||||
|
||||
public void setStateMessage(String stateMessage) {
|
||||
this.stateMessage = stateMessage;
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Long productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public Long getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(Long orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
}
|
||||
@@ -32,16 +32,23 @@ spring:
|
||||
hibernate:
|
||||
show_sql: true
|
||||
format_sql: true
|
||||
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
hibernate:
|
||||
SQL: DEBUG
|
||||
type:
|
||||
descriptor:
|
||||
sql:
|
||||
BasicBinder: TRACE
|
||||
#logging:
|
||||
# level:
|
||||
# org.hibernate.type: trace
|
||||
# org.springframework.cloud: debug
|
||||
|
||||
productUrl: http://localhost:8085
|
||||
delivery:
|
||||
api:
|
||||
url: http://localhost:8082
|
||||
api:
|
||||
url:
|
||||
product: http://localhost:8085
|
||||
|
||||
server:
|
||||
port: 8081
|
||||
@@ -74,5 +81,6 @@ spring:
|
||||
event-out:
|
||||
destination: eventTopicDocker
|
||||
contentType: application/json
|
||||
|
||||
productUrl: http://products:8080
|
||||
api:
|
||||
url:
|
||||
product: http://products:8080
|
||||
|
||||
Reference in New Issue
Block a user