adding files 2
This commit is contained in:
40
inventory-service/pom.xml
Normal file
40
inventory-service/pom.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.oracle.demo</groupId>
|
||||
<artifactId>kagent-oci-devops-demo</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>inventory-service</artifactId>
|
||||
<name>inventory-service</name>
|
||||
|
||||
<dependencies>
|
||||
<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>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.oracle.demo.inventory;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class InventoryServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(InventoryServiceApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.oracle.demo.inventory.api;
|
||||
|
||||
import com.oracle.demo.inventory.model.InventoryResponse;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/inventory")
|
||||
public class InventoryController {
|
||||
|
||||
private final Map<String, Integer> stock = new HashMap<>();
|
||||
private final boolean forceOutage;
|
||||
|
||||
public InventoryController(@Value("${demo.inventory.force-outage:false}") boolean forceOutage) {
|
||||
this.forceOutage = forceOutage;
|
||||
stock.put("LAPTOP-15", 25);
|
||||
stock.put("MOUSE-WL", 100);
|
||||
stock.put("MONITOR-27", 12);
|
||||
}
|
||||
|
||||
@GetMapping("/{sku}")
|
||||
public InventoryResponse getInventory(@PathVariable String sku, @RequestParam(defaultValue = "1") int quantity) {
|
||||
if (forceOutage) {
|
||||
return new InventoryResponse(sku, false, 0, "Inventory service is intentionally degraded for the demo.");
|
||||
}
|
||||
|
||||
int available = stock.getOrDefault(sku, 0);
|
||||
boolean reserved = available >= quantity;
|
||||
String message = reserved ? "Stock reserved." : "Insufficient stock.";
|
||||
return new InventoryResponse(sku, reserved, available, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.oracle.demo.inventory.model;
|
||||
|
||||
public record InventoryResponse(String sku, boolean reserved, int availableUnits, String message) {
|
||||
}
|
||||
|
||||
21
inventory-service/src/main/resources/application.yml
Normal file
21
inventory-service/src/main/resources/application.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
spring:
|
||||
application:
|
||||
name: inventory-service
|
||||
|
||||
server:
|
||||
port: 8081
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,metrics,prometheus
|
||||
endpoint:
|
||||
health:
|
||||
probes:
|
||||
enabled: true
|
||||
|
||||
demo:
|
||||
inventory:
|
||||
force-outage: false
|
||||
|
||||
Reference in New Issue
Block a user