95 lines
2.8 KiB
Bash
95 lines
2.8 KiB
Bash
#!/bin/bash
|
|||
|
|
# Phase 6.6: Create kmsvc (Kafka Message Service) Topics
|
||
|
|
# Topics:
|
||
|
|
# - poimen-memory-dlq (extraction + webhook + agent failures)
|
||
|
|
# - poimen-memory-metric-dlq (metrics persistence failures)
|
||
|
|
#
|
||
|
|
# Prerequisites:
|
||
|
|
# 1. kubectl access to cluster (SQS namespace)
|
||
|
|
# 2. management-service running and accessible
|
||
|
|
#
|
||
|
|
# Usage:
|
||
|
|
# ./create-kmsvc-topics.sh (auto port-forward)
|
||
|
|
# ./create-kmsvc-topics.sh manual (assumes port-forward exists)
|
||
|
|
|
||
|
|
set -e
|
||
|
|
|
||
|
|
NAMESPACE=${NAMESPACE:-sqs}
|
||
|
|
SERVICE=${SERVICE:-management-service}
|
||
|
|
PORT=${PORT:-8080}
|
||
|
|
MANUAL_PORTFORWARD=${1:-auto}
|
||
|
|
|
||
|
|
# Colors
|
||
|
|
RED='\033[0;31m'
|
||
|
|
GREEN='\033[0;32m'
|
||
|
|
YELLOW='\033[1;33m'
|
||
|
|
NC='\033[0m' # No Color
|
||
|
|
|
||
|
|
echo -e "${YELLOW}========================================${NC}"
|
||
|
|
echo -e "${YELLOW}Creating kmsvc Topics for Poimen Memory${NC}"
|
||
|
|
echo -e "${YELLOW}========================================${NC}"
|
||
|
|
|
||
|
|
# Setup port-forward if needed
|
||
|
|
if [ "$MANUAL_PORTFORWARD" != "manual" ]; then
|
||
|
|
echo -e "${YELLOW}Setting up port-forward to $SERVICE...${NC}"
|
||
|
|
|
||
|
|
# Kill existing port-forward if running
|
||
|
|
pkill -f "kubectl.*port-forward.*$SERVICE" || true
|
||
|
|
sleep 1
|
||
|
|
|
||
|
|
# Start port-forward in background
|
||
|
|
kubectl -n $NAMESPACE port-forward svc/$SERVICE $PORT:8080 &
|
||
|
|
PORTFORWARD_PID=$!
|
||
|
|
trap "kill $PORTFORWARD_PID" EXIT
|
||
|
|
|
||
|
|
sleep 3
|
||
|
|
echo -e "${GREEN}Port-forward started (PID: $PORTFORWARD_PID)${NC}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
ENDPOINT="http://localhost:$PORT/v1/queues"
|
||
|
|
|
||
|
|
# Helper function to create topic
|
||
|
|
create_topic() {
|
||
|
|
local topic_name=$1
|
||
|
|
local description=$2
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo -e "${YELLOW}Creating topic: ${topic_name}${NC}"
|
||
|
|
echo "Description: ${description}"
|
||
|
|
|
||
|
|
# Try to create (SQS-style API)
|
||
|
|
response=$(curl -s -X POST "$ENDPOINT" \
|
||
|
|
-H "Content-Type: application/json" \
|
||
|
|
-d "{
|
||
|
|
\"name\": \"${topic_name}\",
|
||
|
|
\"fifoQueue\": false,
|
||
|
|
\"visibilityTimeoutSeconds\": 300,
|
||
|
|
\"messageRetentionPeriodSeconds\": 1209600
|
||
|
|
}")
|
||
|
|
|
||
|
|
if echo "$response" | grep -q '"name"'; then
|
||
|
|
echo -e "${GREEN}✓ Created: ${topic_name}${NC}"
|
||
|
|
echo "Response: $response"
|
||
|
|
elif echo "$response" | grep -q 'already exists'; then
|
||
|
|
echo -e "${YELLOW}⚠ Already exists: ${topic_name}${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${RED}✗ Failed to create: ${topic_name}${NC}"
|
||
|
|
echo "Response: $response"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
# Create topics
|
||
|
|
create_topic "poimen-memory-dlq" "DLQ for extraction, webhook, and agent failures"
|
||
|
|
create_topic "poimen-memory-metric-dlq" "DLQ for metrics persistence failures"
|
||
|
|
|
||
|
|
# List all queues
|
||
|
|
echo ""
|
||
|
|
echo -e "${YELLOW}Listing all queues:${NC}"
|
||
|
|
curl -s "$ENDPOINT" | jq '.' || curl -s "$ENDPOINT"
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo -e "${GREEN}========================================${NC}"
|
||
|
|
echo -e "${GREEN}Topic creation complete!${NC}"
|
||
|
|
echo -e "${GREEN}========================================${NC}"
|