Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Kafka config #17

Merged
merged 9 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 143 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,143 @@
# reservation-service
# Reservation-Service
Bootstrap Skaffold configuration
Run the following command to generate a skaffold.yaml config file:
skaffold init

### Use skaffold dev
Run the following command to begin using Skaffold for continuous development
skaffold dev

### Provide external IP
minikube tunnel

### Kafka
#### Create a topic and recovery
kubectl exec -it kafka-0 -- bash

#### Create a topic named reservation with three partitions and a replication factor of 3.
kafka-topics --create --topic reservation --partitions 2 --replication-factor 2 --bootstrap-server kafka-0.kafka-headless.kafka.svc.cluster.local:9092

#### Verify the topic partitions are replicated across all three brokers:
kafka-topics --describe --topic reservation --bootstrap-server kafka-0.kafka-headless.kafka.svc.cluster.local:9092

### Debugging With Skaffold


## EventStorming Proccess
### Schema

### Topic
1. reservation

### Unstructured Exploration
1. ReservationRequestedEvent
Triggered by the customer submitting a reservation request.
2. AvailabilityConfirmed
Emitted by the system after validating the request and confirming availability.
1. ReservationCreatedEvent
Signals that a new reservation has been successfully created.
2. ReservationCanceledEvent
Indicates that a reservation has been cancelled.
3. ReservationModifiedEvent
Notifies that changes have been made to an existing reservation.
4. ReservationCheckedInEvent
Signals that a booked service or resource usage has started.
5. ReservationCheckedOutEvent
Indicates that a booked service or resource usage has ended.
6. AddedToWaitlistEvent
Notifies that a customer has been added to a waitlist for a service/resource.
7. PromotionAppliedEvent
Signals the successful application of a promotion or discount to a reservation.
8. ReservationExpiredEvent
Signals that a reservation request has expired due to inactivity.
9. OverreservationProcessedEvent
Signals that the system has handled the situation of overreservation by managing excess reservations.
10. ReservationConfirmationSentEvent
Indicates that a confirmation notification has been sent to the customer after a successful reservation.
11. PaymentAuthorizedEvent (Policy Event Trigger)
Signals successful authorization of payment associated with a reservation.
12. PaymentCompletedEvent
Indicates the successful completion of a payment transaction for a reservation.
13. PaymentFailedEvent
Signals that a payment transaction for a reservation has failed.

### Timelines
Happy Path Workflow:
1. Reservation Creation
- Customer submits a reservation request.
- System validates the request and confirms availability.
- Reservation is successfully created.
- Confirmation is sent to the customer.
- Payment authorization is requested.
- Payment is successfully authorized.
- Payment completion is confirmed.
- Reservation is finalized.
2. Reservation Modification
- Customer requests a modification to an existing reservation.
- System validates the modification and confirms availability.
- Reservation is successfully updated.
- Confirmation of modification is sent to the customer.
- Payment authorization may be requested for additional charges.
- Payment, if required, is successfully authorized and completed.
- Updated reservation details are finalized.
3. Reservation Cancellation
- Customer requests cancellation of a reservation.
- System confirms cancellation.
- Reservation is successfully cancelled.
- Confirmation of cancellation is sent to the customer.
- Any applicable refunds are processed.
4. Check-In and Check-Out
- Customer checks in for a booked service/resource.
- System confirms check-in.
- Customer uses the service/resource.
- Customer checks out.
- System confirms check-out.


Alternative Path Workflow
1. Reservation Creation Failure
- Customer submits a reservation request.
- System validates the request but finds no availability.
- System notifies the customer of unavailability.
- Optionally, customer may be added to a waitlist.
2. Reservation Modification Failure
- Customer requests a modification to an existing reservation.
- System validates the modification but finds conflicts.
- System notifies the customer of the conflict and suggests alternatives.
3. Reservation Cancellation Failure
- Customer requests cancellation of a reservation.
- System encounters an error in cancellation.
- System notifies the customer of the failure and suggests contacting support.
4. Payment Failure
- Customer submits a reservation request.
- System validates the request and confirms availability.
- Payment authorization fails.
- System notifies the customer of the payment failure and suggests alternative payment methods.
5. Overreservation Handling
- Customer submits a reservation request.
- System validates the request and detects potential overreservation.
- System notifies the customer of the situation and suggests alternative reservation times or accommodations.

### Commands
1. CreateReservationCommand
Initiates the process of creating a new reservation.
2. SendReservationConfirmationCommand
Sends a confirmation notification to the customer after a successful reservation.
3. CancelReservationCommand
Requests the cancellation of an existing reservation.
4. ModifyReservationCommand
Initiates changes to an existing reservation, such as altering the time, duration, or details of the reservation.
5. CheckinCommand
Indicates the beginning of a booked service or resource usage.
6. CheckoutCommand
Indicates the end of a booked service or resource usage.
7. AddToWaitlistCommand
Adds a customer to a waitlist for a service/resource that is currently unavailable.
8. ApplyPromotionCommand
Applies a promotion or discount to a reservation.
9. ExpireReservationCommand
Marks a reservation request as expired due to inactivity or lack of confirmation.
10. ProcessOverreservationCommand
Handles the situation of overreservation by managing the excess reservations.


8 changes: 0 additions & 8 deletions build-deploy-ks8.sh

This file was deleted.

4 changes: 4 additions & 0 deletions kustomize/base/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
logging:
level:
org:
springframework: INFO
9 changes: 9 additions & 0 deletions k8s/deployment.yaml → kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: reservation-service-deployment
namespace: reservation-develop
labels:
app: reservation-service
spec:
Expand All @@ -18,6 +19,9 @@ spec:
containers:
- name: reservation-service
image: reservation-service:v0.1.0-alpha
volumeMounts:
- name: config-volume
mountPath: /workspace/config
imagePullPolicy: Never # SHOULD NOT DO IT ON PRODUCTION the kubelet does not try fetching the image. If the image is somehow already present locally
resources:
limits:
Expand All @@ -38,4 +42,9 @@ spec:
# preStop:
# exec:
# command: ["sh", "-c", "sleep 10"]

volumes:
- name: config-volume
configMap:
name: reservation-service-config

118 changes: 118 additions & 0 deletions kustomize/base/kafka-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: kafka
namespace: reservation-develop
---
apiVersion: v1
kind: Service
metadata:
labels:
app: kafka
name: kafka-headless
namespace: reservation-develop
spec:
clusterIP: None
clusterIPs:
- None
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: tcp-kafka-int
port: 9092
protocol: TCP
targetPort: tcp-kafka-int
- name: tcp-kafka-ctrl
port: 29093
protocol: TCP
targetPort: tcp-kafka-ctrl
selector:
app: kafka
sessionAffinity: None
type: ClusterIP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: kafka
name: kafka
namespace: reservation-develop
spec:
podManagementPolicy: Parallel
replicas: 2
revisionHistoryLimit: 10
selector:
matchLabels:
app: kafka # has to match .spec.template.metadata.labels
serviceName: kafka-headless
template:
metadata:
labels:
app: kafka # has to match .spec.selector.matchLabels
spec:
serviceAccountName: kafka
containers:
- command:
- sh
- -exc
- |
export CLUSTER_ID="6PMpHYL9QkeyXRj9Nrp4KA" && \
export KAFKA_NODE_ID=${HOSTNAME##*-}
export KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://${POD_NAME}.kafka-headless.reservation-develop.svc.cluster.local:9092
export KAFKA_CONTROLLER_QUORUM_VOTERS="0@kafka-0.kafka-headless.reservation-develop.svc.cluster.local:29093,1@kafka-1.kafka-headless.reservation-develop.svc.cluster.local:29093"

exec /etc/confluent/docker/run
env:
- name: KAFKA_CONTROLLER_LISTENER_NAMES
value: "CONTROLLER"
- name: KAFKA_LISTENERS
value: PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:29093
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
name: kafka
image: docker.io/confluentinc/confluent-local:7.5.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9092
name: tcp-kafka-int
protocol: TCP
- containerPort: 29093
name: tcp-kafka-ctrl
protocol: TCP
resources:
limits:
cpu: "1"
memory: 1400Mi
requests:
cpu: 250m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
# readOnlyRootFilesystem: true
runAsGroup: 1000
runAsUser: 1000
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /etc/kafka
name: config
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext:
fsGroup: 1000
terminationGracePeriodSeconds: 30
volumes:
- emptyDir: {}
name: config
updateStrategy:
type: RollingUpdate
14 changes: 14 additions & 0 deletions kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- namespace.yaml
- kafka-local.yaml
- service.yaml
- deployment.yaml

configMapGenerator:
- name: reservation-service-config
namespace: reservation-develop
files:
- application.yaml
5 changes: 5 additions & 0 deletions kustomize/base/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: reservation-develop
1 change: 1 addition & 0 deletions k8s/service.yaml → kustomize/base/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: reservation-service-kuservice
namespace: reservation-develop
spec:
type: LoadBalancer
selector:
Expand Down
8 changes: 8 additions & 0 deletions kustomize/qa/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../base

patchesStrategicMerge:
- update-replicas.yaml
6 changes: 6 additions & 0 deletions kustomize/qa/update-replicas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: reservation-service-deployment
spec:
replicas: 2
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down Expand Up @@ -93,6 +92,10 @@
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
6 changes: 3 additions & 3 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ build:
jib:
project: com.ubluetech:reservation-service
manifests:
rawYaml:
- k8s/deployment.yaml
- k8s/service.yaml
kustomize:
paths:
- kustomize/base
Loading
Loading