diff --git a/README.md b/README.md index d9cc1b9..dd5d0c4 100644 --- a/README.md +++ b/README.md @@ -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. + + diff --git a/build-deploy-ks8.sh b/build-deploy-ks8.sh deleted file mode 100755 index 51f5523..0000000 --- a/build-deploy-ks8.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# eval $(minikube docker-env) -# Jib google docker build with minikube -./mvnw com.google.cloud.tools:jib-maven-plugin:dockerBuild -Dimage=reservation-service:v0.1.0-alpha - -# Build deployment and service -kubectl apply -f ./k8s \ No newline at end of file diff --git a/kustomize/base/application.yaml b/kustomize/base/application.yaml new file mode 100644 index 0000000..453642e --- /dev/null +++ b/kustomize/base/application.yaml @@ -0,0 +1,4 @@ +logging: + level: + org: + springframework: INFO \ No newline at end of file diff --git a/k8s/deployment.yaml b/kustomize/base/deployment.yaml similarity index 81% rename from k8s/deployment.yaml rename to kustomize/base/deployment.yaml index 10dbcab..9ebb11f 100644 --- a/k8s/deployment.yaml +++ b/kustomize/base/deployment.yaml @@ -2,6 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: reservation-service-deployment + namespace: reservation-develop labels: app: reservation-service spec: @@ -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: @@ -38,4 +42,9 @@ spec: # preStop: # exec: # command: ["sh", "-c", "sleep 10"] + + volumes: + - name: config-volume + configMap: + name: reservation-service-config \ No newline at end of file diff --git a/kustomize/base/kafka-local.yaml b/kustomize/base/kafka-local.yaml new file mode 100644 index 0000000..726655d --- /dev/null +++ b/kustomize/base/kafka-local.yaml @@ -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 \ No newline at end of file diff --git a/kustomize/base/kustomization.yaml b/kustomize/base/kustomization.yaml new file mode 100644 index 0000000..2bb9c46 --- /dev/null +++ b/kustomize/base/kustomization.yaml @@ -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 \ No newline at end of file diff --git a/kustomize/base/namespace.yaml b/kustomize/base/namespace.yaml new file mode 100644 index 0000000..29128fd --- /dev/null +++ b/kustomize/base/namespace.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: reservation-develop \ No newline at end of file diff --git a/k8s/service.yaml b/kustomize/base/service.yaml similarity index 86% rename from k8s/service.yaml rename to kustomize/base/service.yaml index a4508ba..8e323ff 100644 --- a/k8s/service.yaml +++ b/kustomize/base/service.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Service metadata: name: reservation-service-kuservice + namespace: reservation-develop spec: type: LoadBalancer selector: diff --git a/kustomize/qa/kustomization.yaml b/kustomize/qa/kustomization.yaml new file mode 100644 index 0000000..3e84fb0 --- /dev/null +++ b/kustomize/qa/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- ../base + +patchesStrategicMerge: +- update-replicas.yaml \ No newline at end of file diff --git a/kustomize/qa/update-replicas.yaml b/kustomize/qa/update-replicas.yaml new file mode 100644 index 0000000..4fd3004 --- /dev/null +++ b/kustomize/qa/update-replicas.yaml @@ -0,0 +1,6 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: reservation-service-deployment +spec: + replicas: 2 \ No newline at end of file diff --git a/skaffold.yaml b/skaffold.yaml index c44ee5a..35c3075 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -8,6 +8,6 @@ build: jib: project: com.ubluetech:reservation-service manifests: - rawYaml: - - k8s/deployment.yaml - - k8s/service.yaml + kustomize: + paths: + - kustomize/base