diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml new file mode 100644 index 00000000..9b37a7fc --- /dev/null +++ b/.github/workflows/backend-ci.yml @@ -0,0 +1,63 @@ +name: Backend CI + +on: + push: + branches: + - main + paths: + - 'backend/**' + - '.github/workflows/backend-ci.yml' + pull_request: + branches: + - main + paths: + - 'backend/**' + workflow_dispatch: + +jobs: + lint-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.9', '3.10', '3.11'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Cache pip dependencies + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install common dependencies + run: | + cd backend/cab_common + pip install -r requirements.txt + pip install pytest pytest-cov flake8 black + + - name: Run linting + run: | + flake8 backend --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 backend --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + - name: Run tests with coverage + run: | + cd backend + pytest --cov=. --cov-report=xml --cov-report=html -v + + - name: Upload coverage reports + uses: codecov/codecov-action@v3 + with: + files: ./backend/coverage.xml + flags: unittests + name: codecov-umbrella + fail_ci_if_error: false diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 00000000..0903bc3a --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,60 @@ +name: Code Quality + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + security-scan: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + scan-type: 'fs' + scan-ref: '.' + format: 'sarif' + output: 'trivy-results.sarif' + + - name: Upload Trivy results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: 'trivy-results.sarif' + + dependency-check: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install safety + run: pip install safety + + - name: Check Python dependencies for vulnerabilities + run: | + for req_file in $(find . -name "requirements.txt"); do + echo "Checking $req_file..." + safety check --file "$req_file" || true + done + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Run npm audit + working-directory: frontend + run: npm audit --audit-level=moderate || true diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml new file mode 100644 index 00000000..be9fdd47 --- /dev/null +++ b/.github/workflows/docker-build-push.yml @@ -0,0 +1,76 @@ +name: Build and Push Docker Images + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +env: + DOCKERHUB_ORGANIZATION: irtsystemx + REGISTRY: docker.io + +jobs: + build-and-push: + runs-on: ubuntu-latest + environment: Deployment + permissions: + contents: read + packages: write + + strategy: + matrix: + include: + - service: cab-capitalization + dockerfile: backend/Capitalization-Service-Dockerfile + context: backend + - service: cab-context + dockerfile: backend/Context-Service-Dockerfile + context: backend + - service: cab-event + dockerfile: backend/Event-Service-Dockerfile + context: backend + - service: cab-historic + dockerfile: backend/Historic-Service-Dockerfile + context: backend + - service: cab-recommendation + dockerfile: backend/Recommendation-Service-Dockerfile + context: backend + - service: cab-common + dockerfile: backend/cab_common/Dockerfile + context: backend/cab_common + - service: cab-standalone-frontend + dockerfile: frontend/Dockerfile + context: frontend + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.DOCKERHUB_ORGANIZATION }}/interactiveai-${{ matrix.service }} + tags: | + type=semver,pattern={{version}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ${{ matrix.context }} + file: ${{ matrix.dockerfile }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/frontend-ci.yml b/.github/workflows/frontend-ci.yml new file mode 100644 index 00000000..6307d7d8 --- /dev/null +++ b/.github/workflows/frontend-ci.yml @@ -0,0 +1,48 @@ +name: Frontend CI + +on: + push: + branches: + - main + paths: + - 'frontend/**' + - '.github/workflows/frontend-ci.yml' + pull_request: + branches: + - main + paths: + - 'frontend/**' + workflow_dispatch: + +jobs: + build-and-test: + runs-on: ubuntu-latest + defaults: + run: + working-directory: frontend + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + cache-dependency-path: frontend/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Run linting + run: npm run lint --if-present + + - name: Build project + run: npm run build + + - name: Run tests + run: npm run test:unit --if-present + + - name: Run E2E tests + run: npm run test:e2e --if-present diff --git a/config/dev/cab-standalone/docker-compose-hub.sh b/config/dev/cab-standalone/docker-compose-hub.sh new file mode 100755 index 00000000..42b81c2e --- /dev/null +++ b/config/dev/cab-standalone/docker-compose-hub.sh @@ -0,0 +1,243 @@ +#!/bin/bash + +# Docker Compose Hub Management Script +# This script manages the InteractiveAI deployment using Docker images from DockerHub + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +COMPOSE_FILE="$SCRIPT_DIR/docker-compose-hub.yml" +IMAGE_TAG="${IMAGE_TAG:-latest}" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Helper functions +print_info() { + echo -e "${BLUE}ℹ${NC} $1" +} + +print_success() { + echo -e "${GREEN}✓${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}⚠${NC} $1" +} + +print_error() { + echo -e "${RED}✗${NC} $1" +} + +# Display usage information +show_usage() { + cat << EOF +Usage: $(basename "$0") [options] + +Commands: + up Start all services in the background + down Stop all services + logs View logs from all services + logs View logs from a specific service + ps Show running containers + status Show service status + pull Pull the latest images from DockerHub + restart Restart all services + restart Restart a specific service + exec Execute shell in a service container + build-up Pull images and start services + help Show this help message + +Options: + IMAGE_TAG= Specify image tag (default: latest) + Usage: IMAGE_TAG=v1.0.0 $(basename "$0") up + +Environment Variables: + IMAGE_TAG Docker image tag to use (default: latest) + COMPOSE_FILE Path to docker-compose file (auto-detected) + +Examples: + # Start services with default (latest) images + $(basename "$0") up + + # Start services with specific version + IMAGE_TAG=v1.0.0 $(basename "$0") up + + # View logs from a specific service + $(basename "$0") logs cab-context + + # Stop all services + $(basename "$0") down + + # Pull latest images and start + $(basename "$0") build-up + +EOF +} + +# Check if docker-compose file exists +check_compose_file() { + if [ ! -f "$COMPOSE_FILE" ]; then + print_error "Docker compose file not found: $COMPOSE_FILE" + exit 1 + fi +} + +# Start services +cmd_up() { + check_compose_file + print_info "Starting services with IMAGE_TAG=$IMAGE_TAG..." + export IMAGE_TAG + docker-compose -f "$COMPOSE_FILE" up -d + print_success "Services started successfully!" + print_info "Use '$(basename "$0") logs' to view logs" +} + +# Stop services +cmd_down() { + check_compose_file + print_info "Stopping services..." + docker-compose -f "$COMPOSE_FILE" down + print_success "Services stopped successfully!" +} + +# View logs +cmd_logs() { + check_compose_file + local service="$1" + + if [ -z "$service" ]; then + print_info "Showing logs from all services (Ctrl+C to exit)..." + docker-compose -f "$COMPOSE_FILE" logs -f + else + print_info "Showing logs from $service (Ctrl+C to exit)..." + docker-compose -f "$COMPOSE_FILE" logs -f "$service" + fi +} + +# Show container status +cmd_ps() { + check_compose_file + docker-compose -f "$COMPOSE_FILE" ps +} + +# Show service status +cmd_status() { + check_compose_file + print_info "Service status:" + echo "" + docker-compose -f "$COMPOSE_FILE" ps --services --status running | while read -r service; do + print_success "$service is running" + done + echo "" + docker-compose -f "$COMPOSE_FILE" ps --services --status exited | while read -r service; do + print_warning "$service is stopped" + done +} + +# Pull latest images +cmd_pull() { + check_compose_file + print_info "Pulling images with tag: $IMAGE_TAG..." + export IMAGE_TAG + docker-compose -f "$COMPOSE_FILE" pull + print_success "Images pulled successfully!" +} + +# Restart services +cmd_restart() { + check_compose_file + local service="$1" + + if [ -z "$service" ]; then + print_info "Restarting all services..." + docker-compose -f "$COMPOSE_FILE" restart + print_success "All services restarted!" + else + print_info "Restarting $service..." + docker-compose -f "$COMPOSE_FILE" restart "$service" + print_success "$service restarted!" + fi +} + +# Execute shell in container +cmd_exec() { + check_compose_file + local service="$1" + + if [ -z "$service" ]; then + print_error "Service name required" + echo "Usage: $(basename "$0") exec " + exit 1 + fi + + print_info "Opening shell in $service..." + docker-compose -f "$COMPOSE_FILE" exec "$service" sh +} + +# Pull and start +cmd_build_up() { + check_compose_file + print_info "Pulling images and starting services..." + cmd_pull + echo "" + cmd_up +} + +# Main script logic +main() { + local command="$1" + shift || true + + case "$command" in + up) + cmd_up "$@" + ;; + down) + cmd_down "$@" + ;; + logs) + cmd_logs "$@" + ;; + ps) + cmd_ps "$@" + ;; + status) + cmd_status "$@" + ;; + pull) + cmd_pull "$@" + ;; + restart) + cmd_restart "$@" + ;; + exec) + cmd_exec "$@" + ;; + build-up) + cmd_build_up "$@" + ;; + help|--help|-h) + show_usage + ;; + "") + print_error "No command provided" + echo "" + show_usage + exit 1 + ;; + *) + print_error "Unknown command: $command" + echo "" + show_usage + exit 1 + ;; + esac +} + +# Run main function +main "$@" diff --git a/config/dev/cab-standalone/docker-compose-hub.yml b/config/dev/cab-standalone/docker-compose-hub.yml new file mode 100644 index 00000000..87f78625 --- /dev/null +++ b/config/dev/cab-standalone/docker-compose-hub.yml @@ -0,0 +1,319 @@ +version: '3.5' +services: + cabcontext: + container_name: cab_context + image: docker.io/irtsystemx/interactiveai-cab-context:${IMAGE_TAG:-latest} + restart: unless-stopped + environment: + - DATABASE_URL=postgresql://postgres:postgres@db_postgres_context:5432/cab-context + - FLASK_APP=app:create_app('dev') + - PYTHONPATH=/code + - FLASK_ENV=development + - URL_INTROSPECT=http://frontend:80/auth/check_token + - KEYCLOAK_SERVER_URL=http://frontend:80/auth/ + - OPFAB_CLIENT_SECRET=opfab-keycloak-secret + - TZ=UTC # Set timezone to UTC + command: sh -c "./entrypoint.sh" + ports: + - 5100:5000 + depends_on: + - db_postgres_context + + cabevent: + container_name: cab_event + image: docker.io/irtsystemx/interactiveai-cab-event:${IMAGE_TAG:-latest} + restart: unless-stopped + environment: + - CARDS_PUBLICATION_SERVICE=http://cards-publication:8080 + - GATEWAY_SERVICE=http://frontend:80 + - HISTORIC_SERVICE=http://cabhistoric:5000 + - DATABASE_URL=postgresql://postgres:postgres@db_postgres_event:5432/cab-event + - FLASK_APP=app:create_app('dev') + - PYTHONPATH=/code + - FLASK_ENV=development + - URL_INTROSPECT=http://frontend:80/auth/check_token + - KEYCLOAK_SERVER_URL=http://frontend:80/auth/ + - OPFAB_CLIENT_SECRET=opfab-keycloak-secret + - TZ=UTC # Set timezone to UTC + command: sh -c "./entrypoint.sh" + ports: + - 5000:5000 + depends_on: + - db_postgres_event + + cabhistoric: + container_name: cabhistoric + image: docker.io/irtsystemx/interactiveai-cab-historic:${IMAGE_TAG:-latest} + restart: unless-stopped + environment: + - DATABASE_URL=postgresql://postgres:postgres@db_postgres_historic:5432/cab-historic + - FLASK_APP=app:create_app('dev') + - FLASK_ENV=development + - PYTHONPATH=/my_app + - URL_INTROSPECT=http://frontend:80/auth/check_token + - KEYCLOAK_SERVER_URL=http://frontend:80/auth/ + - OPFAB_CLIENT_SECRET=opfab-keycloak-secret + - TZ=UTC # Set timezone to UTC + command: sh -c "./entrypoint.sh" + ports: + - 5200:5000 + depends_on: + - db_postgres_historic + + db_postgres_context: + container_name: db_postgres_context + image: postgres:14.7 + environment: + - POSTGRES_HOST_AUTH_METHOD=trust + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=cab-context + ports: + - '5434:5432' + volumes: + - postgres_context_data:/var/lib/postgresql/data/ + + db_postgres_event: + container_name: db_postgres_event + image: postgres:14.7 + environment: + - POSTGRES_HOST_AUTH_METHOD=trust + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=cab-event + ports: + - '5436:5432' + volumes: + - postgres_event_data:/var/lib/postgresql/data/ + + db_postgres_historic: + container_name: db_postgres_historic + image: postgres:14.7 + environment: + - POSTGRES_HOST_AUTH_METHOD=trust + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=cab-historic + ports: + - '5433:5432' + volumes: + - postgres_historic_data:/var/lib/postgresql/data/ + + pgadmin: + container_name: pgadmin_container + image: dpage/pgadmin4 + environment: + PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org} + PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin} + PGADMIN_CONFIG_SERVER_MODE: 'False' + TZ: UTC # Set timezone to UTC + volumes: + - pgadmin:/var/lib/pgadmin + ports: + - '${PGADMIN_PORT:-5050}:80' + restart: unless-stopped + + frontend: + container_name: frontend + image: docker.io/irtsystemx/interactiveai-cab-standalone-frontend:${IMAGE_TAG:-latest} + restart: unless-stopped + environment: + - VITE_POWERGRID_SIMU=${VITE_POWERGRID_SIMU} + - VITE_ATM_SIMU=${VITE_ATM_SIMU} + - VITE_RAILWAY_SIMU=${VITE_RAILWAY_SIMU} + volumes: + - './ui-config:/usr/share/nginx/html/opfab' + - './nginx-cors-permissive.conf:/etc/nginx/conf.d/default.conf' + ports: + - '3200:80' + depends_on: + - cabrecommendation + - cabevent + - cabcontext + - cabhistoric + - users + - businessconfig + - cards-consultation + + cabrecommendation: + container_name: cab_recommendation + image: docker.io/irtsystemx/interactiveai-cab-recommendation:${IMAGE_TAG:-latest} + restart: unless-stopped + environment: + - GATEWAY_SERVICE=http://frontend:80 + - DATABASE_URL=postgresql://postgres:postgres@db_postgres_recommendation:5432/cab-recommendation + - FLASK_APP=app:create_app('dev') + - PYTHONPATH=/my_app + - FLASK_ENV=development + - URL_INTROSPECT=http://frontend:80/auth/check_token + - KEYCLOAK_SERVER_URL=http://frontend:80/auth/ + - OPFAB_CLIENT_SECRET=opfab-keycloak-secret + - TZ=UTC # Set timezone to UTC + command: sh -c "./entrypoint.sh" + ports: + - 5400:5000 + depends_on: + - db_postgres_recommendation + + db_postgres_recommendation: + container_name: db_postgres_recommendation + image: postgres:14.7 + environment: + - POSTGRES_HOST_AUTH_METHOD=trust + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=cab-recommendation + ports: + - '5437:5432' + volumes: + - postgres_recommendation_data:/var/lib/postgresql/data/ + + cabcapitalization: + container_name: cab_capitalization + image: docker.io/irtsystemx/interactiveai-cab-capitalization:${IMAGE_TAG:-latest} + restart: unless-stopped + environment: + - DATABASE_URL=postgresql://postgres:postgres@db_postgres_capitalization:5432/cab-capitalization + - FLASK_APP=app:create_app('dev') + - FLASK_ENV=development + - PYTHONPATH=/my_app + - URL_INTROSPECT=http://frontend:80/auth/check_token + - KEYCLOAK_SERVER_URL=http://frontend:80/auth/ + - OPFAB_CLIENT_SECRET=opfab-keycloak-secret + - TZ=UTC # Set timezone to UTC + command: sh -c "./entrypoint.sh" + ports: + - 5500:5000 + depends_on: + - db_postgres_capitalization + + db_postgres_capitalization: + container_name: db_postgres_capitalization + image: postgres:14.7 + environment: + - POSTGRES_HOST_AUTH_METHOD=trust + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=cab-capitalization + ports: + - '5438:5432' + volumes: + - postgres_capitalization_data:/var/lib/postgresql/data/ + + mongodb: + image: mongo:4.4.4-bionic + ports: + - '27017:27017' + environment: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: password + + rabbitmq: + container_name: rabbit + image: rabbitmq:3-management + hostname: rabbit + + keycloak: + image: quay.io/keycloak/keycloak:16.1.1 + command: -Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=/cab-keycloak/export -Dkeycloak.profile.feature.upload_scripts=enabled + environment: + - KEYCLOAK_USER=admin + - KEYCLOAK_PASSWORD=admin + - DB_VENDOR=H2 + volumes: + - ../cab-keycloak:/cab-keycloak + ports: + - '89:8080' + + users: + container_name: users + image: 'lfeoperatorfabric/of-users-service:3.11.0.RELEASE' + depends_on: + - mongodb + - rabbitmq + user: ${USER_ID}:${USER_GID} + ports: + - '2103:8080' + environment: + - SPRING_PROFILES_ACTIVE + - TZ=UTC # Set timezone to UTC + volumes: + - '../certificates:/certificates_to_add' + - './users-docker.yml:/config/application.yml' + - './common-docker.yml:/config/common-docker.yml' + - ${CONFIG_PATH}:/external-config + + businessconfig: + container_name: businessconfig + image: 'lfeoperatorfabric/of-businessconfig-service:3.11.0.RELEASE' + depends_on: + - mongodb + user: ${USER_ID}:${USER_GID} + ports: + - '2100:8080' + environment: + - SPRING_PROFILES_ACTIVE + - TZ=UTC # Set timezone to UTC + volumes: + - '../certificates:/certificates_to_add' + - './businessconfig-storage:/businessconfig-storage' + - './common-docker.yml:/config/common-docker.yml' + - './businessconfig-docker.yml:/config/application-docker.yml' + - ${CONFIG_PATH}:/external-config + + cards-publication: + container_name: cards-publication + image: 'lfeoperatorfabric/of-cards-publication-service:3.11.0.RELEASE' + depends_on: + - mongodb + - rabbitmq + user: ${USER_ID}:${USER_GID} + ports: + - '2102:8080' + environment: + - SPRING_PROFILES_ACTIVE + - TZ=UTC # Set timezone to UTC + volumes: + - '../certificates:/certificates_to_add' + - './common-docker.yml:/config/common-docker.yml' + - './cards-publication-docker.yml:/config/application-docker.yml' + - ${CONFIG_PATH}:/external-config + + cards-consultation: + container_name: cards-consultation + image: 'lfeoperatorfabric/of-cards-consultation-service:3.11.0.RELEASE' + depends_on: + - mongodb + - rabbitmq + user: ${USER_ID}:${USER_GID} + ports: + - '2104:8080' + environment: + - SPRING_PROFILES_ACTIVE + - TZ=UTC # Set timezone to UTC + volumes: + - '../certificates:/certificates_to_add' + - './common-docker.yml:/config/common-docker.yml' + - './cards-consultation-docker.yml:/config/application-docker.yml' + - ${CONFIG_PATH}:/external-config + + web-ui: + container_name: web-ui + image: 'lfeoperatorfabric/of-web-ui:3.11.0.RELEASE' + ports: + - '2002:80' + depends_on: + - users + - businessconfig + - cards-consultation + volumes: + - './ui-config:/usr/share/nginx/html/opfab' + - './nginx-cors-permissive.conf:/etc/nginx/conf.d/default.conf' + +volumes: + postgres_context_data: + postgres_event_data: + postgres_historic_data: + postgres_recommendation_data: + postgres_capitalization_data: + pgadmin: diff --git a/resources/bundles/deleteAllBundlesKube.sh b/resources/bundles/deleteAllBundlesKube.sh new file mode 100755 index 00000000..56219b3c --- /dev/null +++ b/resources/bundles/deleteAllBundlesKube.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +# CAB fix ":2100" to localhost url directly to allow use on kube ingress systems + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi + +echo "Will delete all bundles on $url" +# CAB Remove "admin $url" in source getToken line. +source ../getTokenKube.sh admin $url +curl -s -X DELETE "$url/businessconfig/processes/" -H "Authorization:Bearer $token" +echo "" + + + diff --git a/resources/bundles/deleteBundleKube.sh b/resources/bundles/deleteBundleKube.sh new file mode 100755 index 00000000..bdfc4cbf --- /dev/null +++ b/resources/bundles/deleteBundleKube.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +# CAB fix ":2100" to localhost url directly to allow use on kube ingress systems + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : deleteBundle bundle_name opfab_url" +else + echo "Will delete bundle $1 on $url" + source ../getTokenKube.sh admin $url + curl -s -X DELETE "$url/businessconfig/processes/$1" -H "Authorization:Bearer $token" + echo "" +fi + + diff --git a/resources/bundles/loadAllBundlesKube.sh b/resources/bundles/loadAllBundlesKube.sh new file mode 100755 index 00000000..25af235a --- /dev/null +++ b/resources/bundles/loadAllBundlesKube.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +for d in */; do +bundle=${d:0:$((${#d} - 1))} #remove last character / + ./loadBundleKube.sh $bundle $1 +done + diff --git a/resources/bundles/loadBundleKube.sh b/resources/bundles/loadBundleKube.sh new file mode 100755 index 00000000..62bfcd97 --- /dev/null +++ b/resources/bundles/loadBundleKube.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : loadBundle bundle_name opfab_url" +else + echo "Will load bundle $1 on $url" + ( + cd $1 + tar -czf $1.tar.gz ./* + mv $1.tar.gz ../ + cd .. + source ../getTokenKube.sh admin $url + curl -s -X POST "$url/businessconfig/processes" -H "accept: application/json" -H "Content-Type: multipart/form-data" -H "Authorization:Bearer $token" -F "file=@$1.tar.gz;type=application/gzip" + echo "" + rm $1.tar.gz + ) +fi + + diff --git a/resources/cabUsecasesContext/createContextUsecaseKube.sh b/resources/cabUsecasesContext/createContextUsecaseKube.sh new file mode 100755 index 00000000..0ef0385c --- /dev/null +++ b/resources/cabUsecasesContext/createContextUsecaseKube.sh @@ -0,0 +1,16 @@ +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : createContextUsecase use_case_name cab_url" +else + source ../getTokenKube.sh "admin" $url + echo "Create context usecase $1 on $url" + curl -X POST $url/cabcontext/api/v1/usecases -H "Content-type:application/json" -H "Authorization:Bearer $token" --data @$1.json -v + echo "" +fi diff --git a/resources/cabUsecasesContext/loadContextServicesUseCaseKube.sh b/resources/cabUsecasesContext/loadContextServicesUseCaseKube.sh new file mode 100755 index 00000000..aaab2934 --- /dev/null +++ b/resources/cabUsecasesContext/loadContextServicesUseCaseKube.sh @@ -0,0 +1,6 @@ +cd "$(dirname "${BASH_SOURCE[0]}")" + + ./createContextUsecaseKube.sh PowerGridContext $1 + ./createContextUsecaseKube.sh ATMContext $1 + ./createContextUsecaseKube.sh RailwayContext $1 + \ No newline at end of file diff --git a/resources/cabUsecasesEvent/createEventUsecaseKube.sh b/resources/cabUsecasesEvent/createEventUsecaseKube.sh new file mode 100755 index 00000000..acb3e8c0 --- /dev/null +++ b/resources/cabUsecasesEvent/createEventUsecaseKube.sh @@ -0,0 +1,16 @@ +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : createEventUsecase use_case_name cab_url" +else + source ../getTokenKube.sh "admin" $url/auth/token + echo "Create event usecase $1 on $url" + curl -X POST $url/cab_event/api/v1/usecases -H "Content-type:application/json" -H "Authorization:Bearer $token" --data @$1.json -v + echo "" +fi diff --git a/resources/cabUsecasesEvent/loadEventServicesUseCaseKube.sh b/resources/cabUsecasesEvent/loadEventServicesUseCaseKube.sh new file mode 100755 index 00000000..2e98f4c2 --- /dev/null +++ b/resources/cabUsecasesEvent/loadEventServicesUseCaseKube.sh @@ -0,0 +1,5 @@ +cd "$(dirname "${BASH_SOURCE[0]}")" + + ./createEventUsecaseKube.sh ATMEvent $1 + ./createEventUsecaseKube.sh PowerGridEvent $1 + ./createEventUsecaseKube.sh RailwayEvent $1 \ No newline at end of file diff --git a/resources/cabUsecasesRecommendation/createRecommendationUsecaseKube.sh b/resources/cabUsecasesRecommendation/createRecommendationUsecaseKube.sh new file mode 100755 index 00000000..0e29cd98 --- /dev/null +++ b/resources/cabUsecasesRecommendation/createRecommendationUsecaseKube.sh @@ -0,0 +1,16 @@ +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : createRecommendationUsecaseKube use_case_name cab_url" +else + source ../getTokenKube.sh "admin" $url + echo "Create recommendation usecase $1 on $url" + curl -X POST $url/cab_recommendation/api/v1/usecases -H "Content-type:application/json" -H "Authorization:Bearer $token" --data @$1.json -v + echo "" +fi diff --git a/resources/cabUsecasesRecommendation/loadRecommendationServicesUseCaseKube.sh b/resources/cabUsecasesRecommendation/loadRecommendationServicesUseCaseKube.sh new file mode 100755 index 00000000..9dfd91d1 --- /dev/null +++ b/resources/cabUsecasesRecommendation/loadRecommendationServicesUseCaseKube.sh @@ -0,0 +1,5 @@ +cd "$(dirname "${BASH_SOURCE[0]}")" +echo "Load recommendation usecases on Kube cluster##########################################" + ./createRecommendationUsecaseKube.sh PowerGridRecommendationUC $1 + ./createRecommendationUsecaseKube.sh ATMRecommendationUC $1 + ./createRecommendationUsecaseKube.sh RailwayRecommendationUC $1 \ No newline at end of file diff --git a/resources/cards/deleteCardKube.sh b/resources/cards/deleteCardKube.sh new file mode 100755 index 00000000..55c8a5ae --- /dev/null +++ b/resources/cards/deleteCardKube.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : deleteCard card_id opfab_url" +else + source ../getTokenKube.sh admin $url + curl -s -X DELETE $url/cards/$1 -H "Authorization: Bearer $token" -H "Content-type:application/json" +fi diff --git a/resources/cards/sendAckForCardKube.sh b/resources/cards/sendAckForCardKube.sh new file mode 100755 index 00000000..ca3770d6 --- /dev/null +++ b/resources/cards/sendAckForCardKube.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (c) 2022, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +url=$4 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ "$#" -lt 3 ] +then + echo "Usage : sendAckForCard user card_uid entitiesAcks opfab_url" +else + source ../getTokenKube.sh admin $url + curl -X POST $url/cards/userAcknowledgement/$2 -H "Authorization: Bearer $token" -H "Content-type:application/json" --data $3 +fi diff --git a/resources/cards/sendCardKube.sh b/resources/cards/sendCardKube.sh new file mode 100755 index 00000000..497a9220 --- /dev/null +++ b/resources/cards/sendCardKube.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Copyright (c) 2021-2022, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi + +export customEpochDate1=$3 +export customEpochDate2=$4 + + +# MacOs doesn't have date, so check for that and use gdate instead. +if [[ $OSTYPE == 'darwin'* ]] +then + if ! command -v gdate &> /dev/null + then + echo "You are running on macOs and gdate could not be found, please install with 'brew install coreutils'." + exit + fi + current_date_millis=$(gdate +%s%3N) +else + current_date_millis=$(date +%s%3N) +fi + +if [ -z $1 ] +then + echo "Usage : sendCard cardFile opfab_url" +else + source ../getTokenKube.sh "publisher_test" $url + export current_date_in_milliseconds_from_epoch=$(($current_date_millis)) + export current_date_in_milliseconds_from_epoch_plus_3minutes=$(($current_date_millis + 3*60*1000)) + export current_date_in_milliseconds_from_epoch_plus_1hours=$(($current_date_millis + 60*60*1000)) + export current_date_in_milliseconds_from_epoch_plus_2hours=$(($current_date_millis + 2*60*60*1000)) + export current_date_in_milliseconds_from_epoch_plus_4hours=$(($current_date_millis + 4*60*60*1000)) + export current_date_in_milliseconds_from_epoch_plus_8hours=$(($current_date_millis + 8*60*60*1000)) + export current_date_in_milliseconds_from_epoch_plus_12hours=$(($current_date_millis + 12*60*60*1000)) + export current_date_in_milliseconds_from_epoch_plus_24hours=$(($current_date_millis + 24*60*60*1000)) + export current_date_in_milliseconds_from_epoch_plus_48hours=$(($current_date_millis + 48*60*60*1000)) + echo "send card $1 (url: $url)" + echo $current_date_in_milliseconds_from_epoch + echo $current_date_in_milliseconds_from_epoch_plus_2hours + echo $current_date_in_milliseconds_from_epoch_plus_4hours + + # Capture the response body and status code + response=$(curl -X POST -w "%{http_code}\n%{response}" $url/cards -H "Content-type:application/json" --data "$(envsubst <$1)") + + # Extract the status code + status_code=$(echo "$response" | head -n 1) + + # Extract the response body + response_body=$(echo "$response" | tail -n 1) + + # Print the status code and response body + echo "Status Code: $status_code" + echo "Response Body: $response_body" +fi diff --git a/resources/delete6TestCardsKube.sh b/resources/delete6TestCardsKube.sh new file mode 100755 index 00000000..e934be06 --- /dev/null +++ b/resources/delete6TestCardsKube.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$1 +if [[ -z $url ]] +then + url="http://localhost" +fi +( + cd cards + ./deleteCardKube.sh defaultProcess.process1 $url + ./deleteCardKube.sh defaultProcess.process2 $url + ./deleteCardKube.sh defaultProcess.process3 $url + ./deleteCardKube.sh defaultProcess.process4 $url + ./deleteCardKube.sh defaultProcess.process5 $url + ./deleteCardKube.sh defaultProcess.process6 $url + +) diff --git a/resources/deleteAllArchivedCardsKube.sh b/resources/deleteAllArchivedCardsKube.sh new file mode 100755 index 00000000..41f1c383 --- /dev/null +++ b/resources/deleteAllArchivedCardsKube.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$1 +if [[ -z $url ]] +then + url="http://localhost" +fi +( + docker exec $(docker ps --format "{{.Names}}" | grep "mongodb") bash -c "mongo mongodb://root:password@localhost:27017/?authSource=admin --eval \"db=db.getSiblingDB('operator-fabric'); db['archivedCards'].drop();\"" +) diff --git a/resources/deleteAllCardsKube.sh b/resources/deleteAllCardsKube.sh new file mode 100755 index 00000000..3a259ee1 --- /dev/null +++ b/resources/deleteAllCardsKube.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$1 +if [[ -z $url ]] +then + url="http://localhost" +fi +( + docker exec $(docker ps --format "{{.Names}}" | grep "mongodb") bash -c "mongo mongodb://root:password@localhost:27017/?authSource=admin --eval \"db=db.getSiblingDB('operator-fabric'); db['cards'].drop();\"" +) diff --git a/resources/deleteAllDataKube.sh b/resources/deleteAllDataKube.sh new file mode 100755 index 00000000..97cdbbc7 --- /dev/null +++ b/resources/deleteAllDataKube.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +./deleteServiceData.sh cabcontext localhost +./deleteServiceData.sh cab_event localhost +./deleteServiceData.sh cabhistoric localhost +./deleteAllArchivedCards.sh +./deleteAllCards.sh +./deleteAllSettings.sh \ No newline at end of file diff --git a/resources/deleteAllSettingsKube.sh b/resources/deleteAllSettingsKube.sh new file mode 100755 index 00000000..de859ca8 --- /dev/null +++ b/resources/deleteAllSettingsKube.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$1 +if [[ -z $url ]] +then + url="http://localhost" +fi +( + docker exec $(docker ps --format "{{.Names}}" | grep "mongodb") bash -c "mongo mongodb://root:password@localhost:27017/?authSource=admin --eval \"db=db.getSiblingDB('operator-fabric'); db['user_settings'].drop();\"" +) diff --git a/resources/deleteServiceDataKube.sh b/resources/deleteServiceDataKube.sh new file mode 100755 index 00000000..d2e73746 --- /dev/null +++ b/resources/deleteServiceDataKube.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +cd "$(dirname "${BASH_SOURCE[0]}")" + +servicename=$1 +url=$2 + +if [ -z $url ]; then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi + +if [ -z $servicename ]; then + echo "Usage : deleteServiceData servicename cab_url" +else + source ./getTokenKube.sh "admin" $url + echo "Sending delete request to $url/$servicename/api/v1/delete_all_data" + curl -X DELETE $url/$servicename/api/v1/delete_all_data -H "Content-type:application/json" -H "Authorization:Bearer $token" -v + echo "" +fi diff --git a/resources/getConnectedUsersKube.sh b/resources/getConnectedUsersKube.sh new file mode 100755 index 00000000..0dcb0a5b --- /dev/null +++ b/resources/getConnectedUsersKube.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + + +url=$1 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi + +source ./getTokenKube.sh admin $url +curl $url/cards/connections -H "Authorization:Bearer $token" +echo "" diff --git a/resources/getTokenKube.sh b/resources/getTokenKube.sh new file mode 100755 index 00000000..32e2ff10 --- /dev/null +++ b/resources/getTokenKube.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# CAB # +# - In ordre to use this file in a kubernetes env, add +# ":3200/auth/token" to the default url. +# - Use url="https://cab-keycloak.irtsystemx.org" to get a token. + + +username=$1 +if [[ -z $username ]] +then + username="admin" +fi + +url=$2 +if [[ -z $url ]] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi + +echo "[KUBE]: Get token for user $username on $url" + +access_token_pattern='"access_token":"([^"]+)"' + +# CAB Add client_secret for confidential client! +response=$(curl -s -X POST $url/auth/token \ +-H "Content-Type: application/x-www-form-urlencoded" \ +-d "username="$username"&password=test&grant_type=password&client_id=opfab-client") + + +if [[ $response =~ $access_token_pattern ]] ; then + export token=${BASH_REMATCH[1]} +fi +# echo token=$token diff --git a/resources/loadTestConfKube.sh b/resources/loadTestConfKube.sh new file mode 100755 index 00000000..3f0bb6f4 --- /dev/null +++ b/resources/loadTestConfKube.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Copyright (c) 2022, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$1 +if [[ -z $url ]] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +echo "URL: $url" + +( + cd bundles + ./deleteAllBundlesKube.sh $url + ./loadAllBundlesKube.sh $url + cd ../processGroups + ./loadProcessGroupsKube.sh cabProcessGroup.json $url + #TODO Clear perimeters first? + cd ../perimeters + ./createAllPerimeterKube.sh $url + cd ../realTimeScreens + ./loadRealTimeScreensKube.sh realTimeScreens.json $url + cd ../cabUsecasesEvent + ./loadEventServicesUseCaseKube.sh $url + cd ../cabUsecasesContext + ./loadContextServicesUseCaseKube.sh $url + cd ../cabUsecasesRecommendation + ./loadRecommendationServicesUseCaseKube.sh $url +) diff --git a/resources/perimeters/addPerimeterToGroupKube.sh b/resources/perimeters/addPerimeterToGroupKube.sh new file mode 100755 index 00000000..88080937 --- /dev/null +++ b/resources/perimeters/addPerimeterToGroupKube.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$3 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] || [ -z $2 ] +then + echo "Usage : addPerimeterToGroup perimeter_id group_id opfab_url" +else + source ../getTokenKube.sh admin $url + echo "Add perimeter $1 to group $2" + response=$(curl -X PATCH $url/users/groups/$2/perimeters -w "%{http_code}\n%{response_code}" -H "Content-type:application/json" -H "Authorization:Bearer $token" --data "[\"$1\"]") + + # Extract the status code + status_code=$(echo "$response" | head -n 1) + + # Extract the response body + response_body=$(echo "$response" | tail -n 1) + + # Print the status code and response body + echo "Add permiter to group Status Code: $status_code" + echo "Add Permiter to group Response Body: $response_body" +fi diff --git a/resources/perimeters/createAllPerimeterKube.sh b/resources/perimeters/createAllPerimeterKube.sh new file mode 100755 index 00000000..bf518d7c --- /dev/null +++ b/resources/perimeters/createAllPerimeterKube.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Copyright (c) 2021-2022, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +for d in *.json; do + perimeter=${d:0:$((${#d} - 5))} #remove last 5 character + ./createPerimeterKube.sh $perimeter $1 +done + + ./addPerimeterToGroupKube.sh cabProcess Dispatcher $1 + ./addPerimeterToGroupKube.sh cabProcess Planner $1 + ./addPerimeterToGroupKube.sh cabProcess Supervisor $1 + diff --git a/resources/perimeters/createPerimeterKube.sh b/resources/perimeters/createPerimeterKube.sh new file mode 100755 index 00000000..352dc931 --- /dev/null +++ b/resources/perimeters/createPerimeterKube.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : createPerimeter perimeter_name opfab_url" +else + source ../getTokenKube.sh admin $url + echo "delete perimeter $1 on $url if existing " + curl -X DELETE $url/perimeters/$1 -H "Authorization:Bearer $token" + echo "" + echo "Create perimeter $1 on $url" + curl -X POST $url/perimeters -H "Content-type:application/json" -H "Authorization:Bearer $token" --data @$1.json + echo "" +fi diff --git a/resources/perimeters/deletePerimeterKube.sh b/resources/perimeters/deletePerimeterKube.sh new file mode 100755 index 00000000..804b4e2e --- /dev/null +++ b/resources/perimeters/deletePerimeterKube.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : deletePerimeter perimeter_name opfab_url" +else + source ../getTokenKube.sh admin $url + echo "delete perimeter $1 on $url " + curl -X DELETE $url/perimeters/$1 -H "Authorization:Bearer $token" + echo "" +fi diff --git a/resources/processGroups/loadProcessGroupsKube.sh b/resources/processGroups/loadProcessGroupsKube.sh new file mode 100755 index 00000000..12cb93d7 --- /dev/null +++ b/resources/processGroups/loadProcessGroupsKube.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : loadProcessGroups processGroups_name opfab_url" +else + echo "Will load processGroups $1 on $url" + source ../getTokenKube.sh admin $url + curl -s -X POST "$url/businessconfig/processgroups" -H "accept: application/json" -H "Content-Type: multipart/form-data" -H "Authorization:Bearer $token" -F "file=@$1" + echo "" +fi + + diff --git a/resources/realTimeScreens/loadRealTimeScreensKube.sh b/resources/realTimeScreens/loadRealTimeScreensKube.sh new file mode 100755 index 00000000..4fc81c0f --- /dev/null +++ b/resources/realTimeScreens/loadRealTimeScreensKube.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Copyright (c) 2022, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : loadRealTimeScreens file_name opfab_url" +else + echo "Will load realTimeScreens $1 on $url" + source ../getTokenKube.sh admin $url + + response=$(curl -s -X POST "$url/businessconfig/realtimescreens" -w "%{http_code}\n%{response_code}" -H "accept: application/json" -H "Content-Type: multipart/form-data" -H "Authorization:Bearer $token" -F "file=@$1") + + # Extract the status code + status_code=$(echo "$response" | head -n 1) + + # Extract the response body + response_body=$(echo "$response" | tail -n 1) + + # Print the status code and response body + echo "real time screens Status Code: $status_code" + echo "real time screens Response Body: $response_body" +fi diff --git a/resources/send6TestCardsKube.sh b/resources/send6TestCardsKube.sh new file mode 100755 index 00000000..9a088541 --- /dev/null +++ b/resources/send6TestCardsKube.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Copyright (c) 2021, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$1 +if [[ -z $url ]] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +( + cd cards + ./sendCardKube.sh rteProcess/event.json $url +) diff --git a/resources/sendMessageToSubscriptionsKube.sh b/resources/sendMessageToSubscriptionsKube.sh new file mode 100755 index 00000000..225e9117 --- /dev/null +++ b/resources/sendMessageToSubscriptionsKube.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright (c) 2022, RTE (http://www.rte-france.com) +# See AUTHORS.txt +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# SPDX-License-Identifier: MPL-2.0 +# This file is part of the OperatorFabric project. + +# This starts by moving to the directory where the script is located so the paths below still work even if the script +# is called from another folder +cd "$(dirname "${BASH_SOURCE[0]}")" + +url=$2 +if [ -z $url ] +then + url="https://demo.interactiveai.irt-systemx.fr" #urt="https://frontend.cab-dev.irtsystemx.org" +fi +if [ -z $1 ] +then + echo "Usage : sendMessageToSubscriptions message opfab_url" +else + echo "Will send $1 on $url" + source ./getTokenKube.sh admin $url/auth/token + curl -s -v -X POST "$url/messageToSubscriptions" -H "Authorization:Bearer $token" --data $1 + echo "" +fi + +