diff --git a/src/database/.gitignore b/src/database/.gitignore deleted file mode 100644 index 549e00a2a96fa9d7c5dbc9859664a78d980158c2..0000000000000000000000000000000000000000 --- a/src/database/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/src/database/.mvn/wrapper/maven-wrapper.jar b/src/database/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index cb28b0e37c7d206feb564310fdeec0927af4123a..0000000000000000000000000000000000000000 Binary files a/src/database/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/src/database/.mvn/wrapper/maven-wrapper.properties b/src/database/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index e70e7bc8d68e955b549770fd646db8b1851c5577..0000000000000000000000000000000000000000 --- a/src/database/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,2 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/src/database/mvnw b/src/database/mvnw deleted file mode 100755 index 66df2854281f4cb6869e4830dd1a7abd1e946c18..0000000000000000000000000000000000000000 --- a/src/database/mvnw +++ /dev/null @@ -1,308 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.2.0 -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /usr/local/etc/mavenrc ] ; then - . /usr/local/etc/mavenrc - fi - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "$(uname)" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME - else - JAVA_HOME="/Library/Java/Home"; export JAVA_HOME - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=$(java-config --jre-home) - fi -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --unix "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --unix "$CLASSPATH") -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && - JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="$(which javac)" - if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=$(which readlink) - if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then - if $darwin ; then - javaHome="$(dirname "\"$javaExecutable\"")" - javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" - else - javaExecutable="$(readlink -f "\"$javaExecutable\"")" - fi - javaHome="$(dirname "\"$javaExecutable\"")" - javaHome=$(expr "$javaHome" : '\(.*\)/bin') - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=$(cd "$wdir/.." || exit 1; pwd) - fi - # end of workaround - done - printf '%s' "$(cd "$basedir" || exit 1; pwd)" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - # Remove \r in case we run on Windows within Git Bash - # and check out the repository with auto CRLF management - # enabled. Otherwise, we may read lines that are delimited with - # \r\n and produce $'-Xarg\r' rather than -Xarg due to word - # splitting rules. - tr -s '\r\n' ' ' < "$1" - fi -} - -log() { - if [ "$MVNW_VERBOSE" = true ]; then - printf '%s\n' "$1" - fi -} - -BASE_DIR=$(find_maven_basedir "$(dirname "$0")") -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR -log "$MAVEN_PROJECTBASEDIR" - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" -if [ -r "$wrapperJarPath" ]; then - log "Found $wrapperJarPath" -else - log "Couldn't find $wrapperJarPath, downloading it ..." - - if [ -n "$MVNW_REPOURL" ]; then - wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - else - wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - fi - while IFS="=" read -r key value; do - # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) - safeValue=$(echo "$value" | tr -d '\r') - case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; - esac - done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" - log "Downloading from: $wrapperUrl" - - if $cygwin; then - wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") - fi - - if command -v wget > /dev/null; then - log "Found wget ... using wget" - [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" - else - wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - log "Found curl ... using curl" - [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" - else - curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" - fi - else - log "Falling back to using Java to download" - javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" - javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaSource=$(cygpath --path --windows "$javaSource") - javaClass=$(cygpath --path --windows "$javaClass") - fi - if [ -e "$javaSource" ]; then - if [ ! -e "$javaClass" ]; then - log " - Compiling MavenWrapperDownloader.java ..." - ("$JAVA_HOME/bin/javac" "$javaSource") - fi - if [ -e "$javaClass" ]; then - log " - Running MavenWrapperDownloader.java ..." - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -# If specified, validate the SHA-256 sum of the Maven wrapper jar file -wrapperSha256Sum="" -while IFS="=" read -r key value; do - case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; - esac -done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" -if [ -n "$wrapperSha256Sum" ]; then - wrapperSha256Result=false - if command -v sha256sum > /dev/null; then - if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then - wrapperSha256Result=true - fi - elif command -v shasum > /dev/null; then - if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then - wrapperSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." - echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." - exit 1 - fi - if [ $wrapperSha256Result = false ]; then - echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 - echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 - echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 - exit 1 - fi -fi - -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --windows "$CLASSPATH") - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -# shellcheck disable=SC2086 # safe args -exec "$JAVACMD" \ - $MAVEN_OPTS \ - $MAVEN_DEBUG_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/src/database/mvnw.cmd b/src/database/mvnw.cmd deleted file mode 100644 index 95ba6f54ac526de46248af840bab26f33f946b93..0000000000000000000000000000000000000000 --- a/src/database/mvnw.cmd +++ /dev/null @@ -1,205 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% diff --git a/src/database/pom.xml b/src/database/pom.xml deleted file mode 100644 index 8621101dc4051ef84a81e5b9f622f69f400ed964..0000000000000000000000000000000000000000 --- a/src/database/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ -<?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>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-parent</artifactId> - <version>3.2.5</version> - <relativePath/> <!-- lookup parent from repository --> - </parent> - <groupId>com.l2sm</groupId> - <artifactId>database</artifactId> - <version>0.0.1-SNAPSHOT</version> - <name>database</name> - <description>Database manager</description> - <properties> - <java.version>17</java.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-rest</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-validation</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - - - <dependency> - <groupId>com.mysql</groupId> - <artifactId>mysql-connector-j</artifactId> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.security</groupId> - <artifactId>spring-security-test</artifactId> - <scope>test</scope> - </dependency> - <!-- Java Persistence API --> -<dependency> - <groupId>javax.persistence</groupId> - <artifactId>javax.persistence-api</artifactId> - <version>2.2</version> -</dependency> - -<!-- Hibernate Core for JPA implementation --> -<dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - <version>5.6.9.Final</version> <!-- Ensure you use a compatible version --> -</dependency> - - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/database/src/main/java/com/l2sm/database/DatabaseApplication.java b/src/database/src/main/java/com/l2sm/database/DatabaseApplication.java deleted file mode 100644 index a085297a3ff93aa3a664804e3953dc7804586b5f..0000000000000000000000000000000000000000 --- a/src/database/src/main/java/com/l2sm/database/DatabaseApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.l2sm.database; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DatabaseApplication { - - public static void main(String[] args) { - SpringApplication.run(DatabaseApplication.class, args); - } - -} diff --git a/src/database/src/main/java/com/l2sm/database/entity/Interface.java b/src/database/src/main/java/com/l2sm/database/entity/Interface.java deleted file mode 100644 index b9a4e940cf0c90e02c5f9add5379071b95daf789..0000000000000000000000000000000000000000 --- a/src/database/src/main/java/com/l2sm/database/entity/Interface.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.l2sm.database.entity; - -import javax.persistence.*; - - -@Entity -@Table(name = "interfaces") -public class Interface { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - @Column(name = "name", length = 255) - private String name; - - @Column(name = "pod", length = 255) - private String pod; - - @ManyToOne - @JoinColumn(name = "switch_id") - private Switch switchEntity; - - @ManyToOne - @JoinColumn(name = "ned_id") - private Ned ned; - - @ManyToOne - @JoinColumn(name = "network_id") - private Network network; - - @ManyToOne - @JoinColumn(name = "link_id") - private Link link; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPod() { - return pod; - } - - public void setPod(String pod) { - this.pod = pod; - } - - public Switch getSwitchEntity() { - return switchEntity; - } - - public void setSwitchEntity(Switch switchEntity) { - this.switchEntity = switchEntity; - } - - public Ned getNed() { - return ned; - } - - public void setNed(Ned ned) { - this.ned = ned; - } - - public Network getNetwork() { - return network; - } - - public void setNetwork(Network network) { - this.network = network; - } - - public Link getLink() { - return link; - } - - public void setLink(Link link) { - this.link = link; - } -// Getters and setters -} diff --git a/src/database/src/main/java/com/l2sm/database/entity/Link.java b/src/database/src/main/java/com/l2sm/database/entity/Link.java deleted file mode 100644 index 639b6131dc5257d968e89dfc4ebbb9bc98af07f0..0000000000000000000000000000000000000000 --- a/src/database/src/main/java/com/l2sm/database/entity/Link.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.l2sm.database.entity; - -import javax.persistence.*; -import java.util.Set; - -@Entity -@Table(name = "link") -public class Link { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - @Column(name = "link_name", nullable = false, length = 255) - private String linkName; - - @ManyToOne - @JoinColumn(name = "end_A") - private Switch endA; - - @ManyToOne - @JoinColumn(name = "end_B") - private Switch endB; - - @ManyToMany - Set<Path> linkedPaths; - // Getters and setters - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getLinkName() { - return linkName; - } - - public void setLinkName(String linkName) { - this.linkName = linkName; - } - - public Switch getEndA() { - return endA; - } - - public void setEndA(Switch endA) { - this.endA = endA; - } - - public Switch getEndB() { - return endB; - } - - public void setEndB(Switch endB) { - this.endB = endB; - } - - public Set<Path> getLinkedPaths() { - return linkedPaths; - } - - public void setLinkedPaths(Set<Path> linkedPaths) { - this.linkedPaths = linkedPaths; - } -} diff --git a/src/database/src/main/java/com/l2sm/database/entity/Ned.java b/src/database/src/main/java/com/l2sm/database/entity/Ned.java deleted file mode 100644 index e913fa24279bfc834ba09e36f7e0f636952f538b..0000000000000000000000000000000000000000 --- a/src/database/src/main/java/com/l2sm/database/entity/Ned.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.l2sm.database.entity; - -import javax.persistence.*; - -@Entity -@Table(name = "neds") -public class Ned { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - @Column(name = "node_name", nullable = false, length = 255) - private String nodeName; - - @Column(name = "provider", nullable = false, length = 255) - private String provider; - - @Column(name = "openflowId", columnDefinition = "TEXT") - private String openflowId; - - @Column(name = "ip", length = 15) - private String ip; - - // Getters and setters - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getNodeName() { - return nodeName; - } - - public void setNodeName(String nodeName) { - this.nodeName = nodeName; - } - - public String getProvider() { - return provider; - } - - public void setProvider(String provider) { - this.provider = provider; - } - - public String getOpenflowId() { - return openflowId; - } - - public void setOpenflowId(String openflowId) { - this.openflowId = openflowId; - } - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } -} diff --git a/src/database/src/main/java/com/l2sm/database/entity/Network.java b/src/database/src/main/java/com/l2sm/database/entity/Network.java deleted file mode 100644 index 5b2f9c0479a29119a196162f1caf93f9766ba8a0..0000000000000000000000000000000000000000 --- a/src/database/src/main/java/com/l2sm/database/entity/Network.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.l2sm.database.entity; - -import javax.persistence.*; - - - -@Entity -@Table(name = "networks") -public class Network { - - public enum NetworkType { - VNET, VLINK - } - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - @Column(name = "name", nullable = false, length = 255) - private String name; - - @Column(name = "type", nullable = false) - @Enumerated(EnumType.STRING) - private NetworkType type; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public NetworkType getType() { - return type; - } - - public void setType(NetworkType type) { - this.type = type; - } -// Getters and setters -} diff --git a/src/database/src/main/java/com/l2sm/database/entity/Path.java b/src/database/src/main/java/com/l2sm/database/entity/Path.java deleted file mode 100644 index ed4687dfe4ae191cc1e21f7be2d542c11e446015..0000000000000000000000000000000000000000 --- a/src/database/src/main/java/com/l2sm/database/entity/Path.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.l2sm.database.entity; - -import javax.persistence.*; -import java.util.Set; - -@Entity -@Table(name = "path") -public class Path { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - @Column(name = "name", length = 255) - private String name; - - @ManyToMany - Set<Link> linkedLinks; - - - - // Getters and setters - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Set<Link> getLinkedLinks() { - return linkedLinks; - } - - public void setLinkedLinks(Set<Link> linkedLinks) { - this.linkedLinks = linkedLinks; - } -} diff --git a/src/database/src/main/java/com/l2sm/database/entity/Switch.java b/src/database/src/main/java/com/l2sm/database/entity/Switch.java deleted file mode 100644 index 421398aefd6aa9c61c350376987a45b70d42b937..0000000000000000000000000000000000000000 --- a/src/database/src/main/java/com/l2sm/database/entity/Switch.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.l2sm.database.entity; - -import javax.persistence.*; - -@Entity -@Table(name = "switches") -public class Switch { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - @Column(name = "node_name", nullable = false, length = 255) - private String nodeName; - - @Column(name = "openflowId", columnDefinition = "TEXT") - private String openflowId; - - @Column(name = "ip", length = 15) - private String ip; - - // Getters and setters -} diff --git a/src/database/src/main/resources/application.properties b/src/database/src/main/resources/application.properties deleted file mode 100644 index 04dec8bed6feb632d3280c5bf17afc6db2bb5cbd..0000000000000000000000000000000000000000 --- a/src/database/src/main/resources/application.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.application.name=database -spring.datasource.url=jdbc:mysql://10.152.183.132:3306/l2sm?useSSL=false&serverTimezone=UTC -spring.datasource.username=l2sm -spring.datasource.password=l2sm - -# JPA / Hibernate properties -spring.jpa.hibernate.ddl-auto=create -spring.jpa.show-sql=true -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect \ No newline at end of file diff --git a/src/database/src/test/java/com/l2sm/database/DatabaseApplicationTests.java b/src/database/src/test/java/com/l2sm/database/DatabaseApplicationTests.java deleted file mode 100644 index bc1b85732a298c4e663c685b646c73df9374e7fd..0000000000000000000000000000000000000000 --- a/src/database/src/test/java/com/l2sm/database/DatabaseApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.l2sm.database; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class DatabaseApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/operator/__pycache__/l2sm-operator.cpython-310.pyc b/src/operator/__pycache__/l2sm-operator.cpython-310.pyc deleted file mode 100644 index 425353d977bdddd56ae32e227334418d45b11174..0000000000000000000000000000000000000000 Binary files a/src/operator/__pycache__/l2sm-operator.cpython-310.pyc and /dev/null differ diff --git a/src/operator/__pycache__/l2sm-operator.cpython-38.pyc b/src/operator/__pycache__/l2sm-operator.cpython-38.pyc deleted file mode 100644 index c0ada9265a3f6bf8bbabba5f8522ad5407b5d496..0000000000000000000000000000000000000000 Binary files a/src/operator/__pycache__/l2sm-operator.cpython-38.pyc and /dev/null differ diff --git a/src/operator/l2sm-operator.py b/src/operator/l2sm-operator.py deleted file mode 100644 index 49308a91f63e977e2057207b2335842cae03dd51..0000000000000000000000000000000000000000 --- a/src/operator/l2sm-operator.py +++ /dev/null @@ -1,496 +0,0 @@ -import kopf -import os -import sys -import json -import subprocess -import secrets -import kubernetes -from subprocess import CalledProcessError -from random import randrange -from kubernetes import client, config -from kubernetes.client import CustomObjectsApi -import pymysql -import random -import time -import requests -import re -import sys -from requests.auth import HTTPBasicAuth - -database_ip = os.environ['DATABASE_IP'] -database_username = os.environ['MYSQL_USER'] -database_password = os.environ['MYSQL_PASSWORD'] -database_name = os.environ['MYSQL_DATABASE'] - -base_controller_url = 'http://' + os.environ['CONTROLLER_IP'] + ':8181' + '/onos' - -print(base_controller_url) -print(database_ip) - -def begin_session_controller(base_controller_url,username,password): - - # Create a session with basic authentication - auth = HTTPBasicAuth(username, password) - - session = requests.Session() - session.auth = auth - - #Check if connection is possible - response = session.get(base_controller_url + '/vnets/api/status') - if response.status_code == 200: - # Successful request - print("Initialized session between operator and controller.") - return session - else: - print("Could not initialize session with l2sm-controller") - sys.exit() - - - -session = begin_session_controller(base_controller_url,"karaf","karaf") - -def get_openflow_id(node_name): - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - try: - with connection.cursor() as cursor: - switch_query = "SELECT id, openflowId, ip FROM switches WHERE node_name = %s" - cursor.execute(switch_query, (node_name,)) - switch_record = cursor.fetchone() - - print(switch_record) - if switch_record is not None: - switchId = switch_record['openflowId'] - - if switchId is not None: - return switchId # If openflowId is already set, return it - - # If openflowId is not set, make a request to get the information from the API - response = session.get(base_controller_url + '/v1/devices') - devices = response.json().get('devices', []) - - for device in devices: - if 'id' in device and 'annotations' in device and 'managementAddress' in device['annotations']: - if device['annotations']['managementAddress'] == switch_record['ip']: - openflowId = device['id'] - switchId = openflowId - - # Save the openflowId in the database - updateQuery = "UPDATE switches SET openflowId = %s WHERE id = %s" - cursor.execute(updateQuery, (openflowId, switch_record['id'])) - connection.commit() - - return switchId # Return the openflowId - connection.commit() - finally: - connection.close() - - return None # Return None if no matching device is found - -#POPULATE DATABASE ENTRIES WHEN A NEW L2SM SWITCH IS CREATED (A NEW NODE APPEARS) -@kopf.on.create('pods.v1', labels={'l2sm-component': 'l2sm-switch'}) -def build_db(body, logger, annotations, **kwargs): - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - if 'spec' in body and 'nodeName' in body['spec']: - try: - with connection.cursor() as cursor: - # Step 1: Check if the switch already exists - select_switch_sql = "SELECT id FROM switches WHERE node_name = %s;" - cursor.execute(select_switch_sql, body['spec']['nodeName']) - result = cursor.fetchone() - - if result: - # Switch exists, so update it (if needed) - switch_id = result['id'] - # Example update (modify as needed) - # update_switch_sql = "UPDATE switches SET openflowId = %s, IP = %s WHERE id = %s;" - # cursor.execute(update_switch_sql, (newOpenflowId, newIP, switch_id)) - else: - # Step 2: Insert a switch since it doesn't exist - insert_switch_sql = "INSERT INTO switches (node_name, openflowId, IP) VALUES (%s, NULL, NULL);" - cursor.execute(insert_switch_sql, body['spec']['nodeName']) - switch_id = cursor.lastrowid - # Step 3: Insert interfaces - for i in range(1, 11): - interface_name = f"veth{i}" - # Consider adding a check here to see if the interface already exists for the switch - insert_interface_sql = "INSERT INTO interfaces (name, switch_id) VALUES (%s, %s);" - cursor.execute(insert_interface_sql, (interface_name, switch_id)) - - # Commit the changes - connection.commit() - finally: - connection.close() - logger.info(f"Node {body['spec']['nodeName']} has been registered in the operator") - else: - raise kopf.TemporaryError("The Pod is not yet ready", delay=5) - -@kopf.on.field('pods.v1', labels={'l2sm-component': 'l2sm-switch'}, field='status.podIP') -def update_db(body, logger, annotations, **kwargs): - if 'status' in body and 'podIP' in body['status']: - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - try: - with connection.cursor() as cursor: - updateQuery = "UPDATE switches SET ip = '%s', OpenFlowId = NULL WHERE node_name = '%s'" % (body['status']['podIP'], body['spec']['nodeName']) - cursor.execute(updateQuery) - connection.commit() - finally: - connection.close() - logger.info(f"Updated switch ip") - - -#UPDATE DATABASE WHEN NETWORK IS CREATED, I.E: IS A MULTUS CRD WITH OUR L2SM INTERFACE PRESENT IN ITS CONFIG -#@kopf.on.create('NetworkAttachmentDefinition', field="spec.config['device']", value='l2sm-vNet') -@kopf.on.create('l2sm.l2sm.k8s.local', 'v1', 'l2networks') -def create_vn(spec, name, namespace, logger, **kwargs): - - # Database connection setup - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - try: - # Start database transaction - with connection.cursor() as cursor: - sql = "INSERT INTO networks (name, type) VALUES (%s, %s) ON DUPLICATE KEY UPDATE name = VALUES(name), type = VALUES(type)" - cursor.execute(sql, (name.strip(), spec['type'])) - connection.commit() - - except Exception as e: - # Roll back the database transaction in case of any error - connection.rollback() - logger.error(f"An error occurred: {e}. Rolled back the database transaction.") - finally: - # Ensure the database connection is closed - connection.close() - - - -@kopf.on.create('pods.v1', annotations={'l2sm/networks': kopf.PRESENT}) -def pod_vn(body, name, namespace, logger, annotations, **kwargs): - """Assign Pod to a network if a specific annotation is present.""" - - #time.sleep(random.uniform(0,0.8)) # Avoid database overlap by introducing a random sleep time - - l2networks = extract_l2networks(annotations) - - - if not l2networks: - logger.info("No Multus networks specified. Exiting.") - return - - existing_networks = get_existing_networks(namespace) - # Need to extract just the names from l2networks for comparison - target_networks_info = filter_target_networks([net['name'] for net in l2networks], existing_networks) - if not target_networks_info: - logger.info("No target networks found. Letting Multus handle the network assignment.") - return - - # Update `target_networks` to include IP information if available - target_networks = [net for net in l2networks if net['name'] in target_networks_info] - - - api = CustomObjectsApi() - # Assign pods to each of the target networks, this part remains unchanged - for network in target_networks: - update_network(network['name'], name, namespace, api) - - if 'spec' in body and 'nodeName' in body['spec']: - node_name = body['spec']['nodeName'] - # free_interfaces = get_free_interfaces(node_name) - v1 = client.CoreV1Api() - - pod = v1.read_namespaced_pod(name, namespace) - multus_annotations = pod.metadata.annotations if pod.metadata.annotations else {} - free_interfaces = extract_multus_networks(multus_annotations) - if len(free_interfaces) != len(target_networks): - raise kopf.PermanentError(f"Node {node_name} has no free interfaces left") - - openflow_id = get_openflow_id(node_name) - # Now pass the full network info including IPs if present - update_network_assignments(name, namespace, node_name, free_interfaces, target_networks, logger, openflow_id) - else: - raise kopf.TemporaryError("The Pod is not yet ready", delay=1) - -def update_network(l2sm_network_name,pod_name,namespace,api): - l2sm_network = api.get_namespaced_custom_object( - group="l2sm.l2sm.k8s.local", - version="v1", - namespace=namespace, - plural="l2networks", - name=l2sm_network_name, - ) - connected_pods = l2sm_network.get('status', {}).get('connectedPods', []) - if pod_name not in connected_pods: - connected_pods.append(pod_name) - patch = {'status': {'connectedPods': connected_pods}} - # Apply the patch to the L2SMNetwork - - api.patch_namespaced_custom_object( - group="l2sm.l2sm.k8s.local", - version="v1", - namespace=namespace, - plural="l2networks", - name=l2sm_network_name, - body=patch - ) - print(f"Updated L2SMNetwork {l2sm_network_name} with connected Pod {pod_name}") - -def remove_from_network(l2sm_network_name,pod_name,namespace,api): - l2sm_network = api.get_namespaced_custom_object( - group="l2sm.l2sm.k8s.local", - version="v1", - namespace=namespace, - plural="l2networks", - name=l2sm_network_name, - ) - connected_pods = l2sm_network.get('status', {}).get('connectedPods', []) - if pod_name in connected_pods: - connected_pods.remove(pod_name) - patch = {'status': {'connectedPods': connected_pods}} - # Apply the patch to the L2SMNetwork - - api.patch_namespaced_custom_object( - group="l2sm.l2sm.k8s.local", - version="v1", - namespace=namespace, - plural="l2networks", - name=l2sm_network_name, - body=patch - ) - print(f"Updated L2SMNetwork {l2sm_network_name} with disconnected Pod {pod_name}") - - - - -def extract_l2networks(annotations): - """Extract and return l2sm networks from annotations.""" - annotation = annotations.get('l2sm/networks') - if annotation.startswith('['): # New JSON format - try: - networks = json.loads(annotation) - return [{ 'name': net['name'], 'ips': net.get('ips', []) } for net in networks] - except json.JSONDecodeError: - raise ValueError("Failed to decode JSON from annotations") - else: # Original string format - return [{'name': network.strip(), 'ips': []} for network in annotation.split(",")] - -def extract_multus_networks(annotations): - """Extract and return Multus networks from annotations.""" - annotation = annotations.get('k8s.v1.cni.cncf.io/networks') - if annotation.startswith('['): # New JSON format - try: - networks = json.loads(annotation) - return [{ 'name': net['name'], 'ips': net.get('ips', []) } for net in networks] - except json.JSONDecodeError: - raise ValueError("Failed to decode JSON from annotations") - else: # Original string format - return [{'name': network.strip(), 'ips': []} for network in annotation.split(",")] - - -def get_existing_networks(namespace): - """Return existing networks in the namespace.""" - api = client.CustomObjectsApi() - networks = api.list_namespaced_custom_object('l2sm.l2sm.k8s.local', 'v1', namespace, 'l2networks').get('items') - return [network['metadata']['name'] for network in networks if "vnet" in network['spec']['type']] - -def filter_target_networks(l2networks, existing_networks): - """Filter and return networks that are both requested and exist.""" - return [network for network in l2networks if network in existing_networks] - -def get_free_interfaces(node_name): - """Query the database for free interfaces on a node.""" - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - try: - with connection.cursor() as cursor: - sql = """ - SELECT i.id, i.name - FROM interfaces i - JOIN switches s ON i.switch_id = s.id - WHERE i.network_id IS NULL AND s.node_name = %s; - """ - cursor.execute(sql, (node_name.strip(),)) - free_interfaces = cursor.fetchall() - print(free_interfaces) - finally: - connection.close() - return free_interfaces - -def update_pod_annotation(pod_name, namespace, networks_info): - """Update the Pod's annotation with assigned networks and optional IPs.""" - v1 = client.CoreV1Api() - pod = v1.read_namespaced_pod(pod_name, namespace) - pod_annotations = pod.metadata.annotations or {} - # Format the annotations based on whether IPs are provided - formatted_networks = [] - for network_info in networks_info: - if not network_info.get('ips'): - network_info['ips'] = [generate_random_ipv6_fe80()] # Ensure this is a list - formatted_networks.append(json.dumps(network_info)) # Convert dict to a JSON string - - pod_annotations['k8s.v1.cni.cncf.io/networks'] = '[' + ', '.join(formatted_networks) + ']' - print(pod_annotations) - v1.patch_namespaced_pod(pod_name, namespace, {'metadata': {'annotations': pod_annotations}}) - v1.delete_namespaced_pod(pod_name, namespace) - - - -def update_network_assignments(pod_name, namespace, node_name, free_interfaces, target_networks, logger, openflow_id): - """Update the network assignments in the database and controller.""" - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - try: - assigned_interfaces = [] - with connection.cursor() as cursor: - for i, interface in enumerate(free_interfaces[:len(target_networks)]): - if openflow_id: - port_number = extract_port_number(interface['name']) - - post_network_assignment(openflow_id, port_number, target_networks[i]['name']) - connection.commit() - finally: - connection.close() - logger.info(f"Pod {pod_name} attached to networks {', '.join(network['name'] for network in target_networks)}") - -# Assuming these functions are implemented as per original logic -def update_interface_assignment(cursor, interface_id, network_name, pod_name, node_name): - """Update a single interface's network assignment in the database.""" - # First, find the network_id from the network name - cursor.execute("SELECT id FROM networks WHERE name = %s", (network_name,)) - network = cursor.fetchone() - if network is None: - raise ValueError(f"Network {network_name} does not exist") - network_id = network['id'] - - # Update the interface with the network_id and pod name - sql = """ - UPDATE interfaces - SET pod = %s, network_id = %s - WHERE id = %s; - """ - cursor.execute(sql, (pod_name, network_id, interface_id)) - -def extract_port_number(interface_name): - """Extract and return the port number from an interface name.""" - return int(re.search(r'\d+$', interface_name).group()) - -def post_network_assignment(openflow_id, port_number, network_name): - """Post network assignment to the controller.""" - payload = { - "networkId": network_name, - "networkEndpoints": [f"{openflow_id}/{port_number}"] - } - response = session.post(f"{base_controller_url}/vnets/api/port", json=payload) - if response.status_code != 204: - raise Exception(f"Network assignment failed with status code: {response.status_code}") - - - -#UPDATE DATABASE WHEN POD IS DELETED -@kopf.on.delete('pods.v1', annotations={'l2sm/networks': kopf.PRESENT}) -def dpod_vn(body, name, namespace, logger, annotations, **kwargs): - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - try: - with connection.cursor() as cursor: - sql = "UPDATE interfaces SET network_id = NULL, pod = NULL WHERE pod = '%s'" % (name) - cursor.execute(sql) - - connection.commit() - l2networks = extract_l2networks(annotations) - if not l2networks: - logger.info("No Multus networks specified. Exiting.") - return - - existing_networks = get_existing_networks(namespace) - # Need to extract just the names from l2networks for comparison - target_networks_info = filter_target_networks([net['name'] for net in l2networks], existing_networks) - if not target_networks_info: - logger.info("No target networks found. Letting Multus handle the network assignment.") - return - - # Update `target_networks` to include IP information if available - target_networks = [net for net in l2networks if net['name'] in target_networks_info] - - api = CustomObjectsApi() - # Assign pods to each of the target networks - for network in target_networks: - update_network(network['name'], name, namespace, api) - finally: - connection.close() - logger.info(f"Pod {name} removed") - -#UPDATE DATABASE WHEN NETWORK IS DELETED -@kopf.on.delete('l2sm.l2sm.k8s.local', 'v1', 'l2networks') -def delete_vn(spec, name, logger, **kwargs): - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - try: - with connection.cursor() as cursor: - # First, set network_id to NULL in interfaces for the network being deleted - update_interfaces_sql = """ - UPDATE interfaces - SET network_id = NULL - WHERE network_id = (SELECT id FROM networks WHERE name = %s AND type = %s); - """ - cursor.execute(update_interfaces_sql, (name,spec['type'])) - - # Then, delete the network from networks table - delete_network_sql = "DELETE FROM networks WHERE name = %s AND type = %s;" - cursor.execute(delete_network_sql, (name,spec['type'])) - - - - - connection.commit() - finally: - connection.close() - logger.info(f"Network {name} removed") - -#DELETE DATABASE ENTRIES WHEN A NEW L2SM SWITCH IS DELETED (A NEW NODE GETS OUT OF THE CLUSTER) -@kopf.on.delete('pods.v1', labels={'l2sm-component': 'l2sm-switch'}) -def remove_node(body, logger, annotations, **kwargs): - connection = pymysql.connect(host=database_ip, - user=database_username, - password=database_password, - database=database_name, - cursorclass=pymysql.cursors.DictCursor) - try: - with connection.cursor() as cursor: - sql = """ - DELETE FROM interfaces - WHERE switch_id = (SELECT id FROM switches WHERE node_name = %s); - """ - switchSql = "DELETE FROM switches WHERE node_name = %s;" - cursor.execute(sql,body['spec']['nodeName']) - cursor.execute(switchSql,body['spec']['nodeName']) - connection.commit() - finally: - connection.close() - logger.info(f"Node {body['spec']['nodeName']} has been deleted from the cluster") - diff --git a/src/operator/requirements.txt b/src/operator/requirements.txt deleted file mode 100644 index 5749c3bef47b797ae98bca0f1b352a0d5b2b9413..0000000000000000000000000000000000000000 --- a/src/operator/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -kopf==1.37.0 -kubernetes==28.1.0 -PyMySQL==1.1.0 -requests==2.25.1