diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3627a85 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,27 @@ +name: Continuous Integration +on: + push: + branches: + - '**' +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: adopt + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Check phase 1 + run: ./gradlew build -PhomeworkStage=1 + - name: Check phase 2 + run: ./gradlew build -PhomeworkStage=2 + - name: Check phase 3 + run: ./gradlew build -PhomeworkStage=3 + - name: Check phase 4 + run: ./gradlew build -PhomeworkStage=4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba31cb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*._trace +.idea/ +.gradle/ +build/ +**/src/gen/ diff --git a/README.md b/README.md deleted file mode 100644 index 4fa2390..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# ASE Labs - -Practice material for the Automated Software Engineering (VIMIAC20) course. diff --git a/VersionControl.md b/VersionControl.md deleted file mode 100644 index d39c07d..0000000 --- a/VersionControl.md +++ /dev/null @@ -1 +0,0 @@ -Todo \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..346abcd --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,18 @@ +import org.gradle.accessors.dm.LibrariesForLibs + +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() + gradlePluginPortal() +} + +val libs = the() + +dependencies { + // https://github.com/gradle/gradle/issues/15383 + implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) + implementation(libs.python.gradle.plugin) +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..b5a0fab --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,7 @@ +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/buildSrc/src/main/kotlin/hu/bme/mit/ase/gradle/conventions/generator.gradle.kts b/buildSrc/src/main/kotlin/hu/bme/mit/ase/gradle/conventions/generator.gradle.kts new file mode 100644 index 0000000..5df94ba --- /dev/null +++ b/buildSrc/src/main/kotlin/hu/bme/mit/ase/gradle/conventions/generator.gradle.kts @@ -0,0 +1,60 @@ +package hu.bme.mit.ase.gradle.conventions + +import com.pswidersk.gradle.python.VenvTask +import org.gradle.api.tasks.Sync +import org.gradle.kotlin.dsl.getValue +import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.registering + +plugins { + id("hu.bme.mit.ase.gradle.conventions.jvm") + id("com.pswidersk.python-plugin") +} + +val srcGenJava = "src/gen/java" + +sourceSets.main { + java.srcDir(srcGenJava) +} + +val installPythonPackages by tasks.registering(VenvTask::class) { + venvExec = "pip3" + + args = listOf( + "install", + "jinja2", + ) +} + +val syncGeneratorScripts by tasks.registering(Sync::class) { + from(rootProject.layout.projectDirectory.dir("python-scripts")) + into(project.layout.buildDirectory.dir("python-scripts")) +} + +val syncModels by tasks.registering(Sync::class) { + from(rootProject.layout.projectDirectory.dir("models")) + into(project.layout.buildDirectory.dir("models")) +} + +val syncTemplates by tasks.registering(Sync::class) { + from(rootProject.layout.projectDirectory.dir("jinja-templates")) + into(project.layout.buildDirectory.dir("jinja-templates")) +} + +val generate by tasks.registering(VenvTask::class) { + inputs.files(syncGeneratorScripts.get().outputs) + inputs.files(syncModels.get().outputs) + inputs.files(syncTemplates.get().outputs) + + dependsOn(installPythonPackages) + + outputs.dir(srcGenJava) +} + +tasks.compileJava { + inputs.files(generate.get().outputs) +} + +tasks.clean { + delete(srcGenJava) +} diff --git a/buildSrc/src/main/kotlin/hu/bme/mit/ase/gradle/conventions/jvm.gradle.kts b/buildSrc/src/main/kotlin/hu/bme/mit/ase/gradle/conventions/jvm.gradle.kts new file mode 100644 index 0000000..0e43a54 --- /dev/null +++ b/buildSrc/src/main/kotlin/hu/bme/mit/ase/gradle/conventions/jvm.gradle.kts @@ -0,0 +1,37 @@ +package hu.bme.mit.ase.gradle.conventions + +import org.gradle.accessors.dm.LibrariesForLibs + +plugins { + `java-library` + `java-test-fixtures` + java +} + +val libs = the() + +repositories { + mavenCentral() +} + +java.toolchain { + languageVersion.set(JavaLanguageVersion.of(21)) +} + +tasks { + test { + useJUnitPlatform() + testLogging.showStandardStreams = true + } +} + +dependencies { + implementation(libs.slf4j.api) + + runtimeOnly(libs.slf4j.log4j.impl) + + testImplementation(libs.junit.jupiter.core) + testImplementation(libs.junit.jupiter.params) + + testRuntimeOnly(libs.junit.jupiter.engine) +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..1b06dbd --- /dev/null +++ b/gradle.properties @@ -0,0 +1,6 @@ +org.gradle.daemon=true +org.gradle.jvmargs=-Xmx2048M +org.gradle.parallel=true + +# Change the stage here to execute additional tests! +homeworkStage=0 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..6760dfd --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,16 @@ +# This file was generated by the Gradle 'init' task. +# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format + +[versions] +slf4j = "1.7.25" +log4j = "2.23.1" +jUnit = "5.10.0" +python-gradle-plugin = "2.7.3" + +[libraries] +slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" } +slf4j-log4j-impl = { group = "org.apache.logging.log4j", name = "log4j-slf4j-impl", version.ref = "log4j" } +junit-jupiter-core = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "jUnit" } +junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "jUnit" } +junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "jUnit" } +python-gradle-plugin = { group = "com.pswidersk", name = "python-gradle-plugin", version.ref = "python-gradle-plugin" } diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..fcb6fca --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed 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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +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 + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem 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, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/materials/hw-1-stage1.png b/materials/hw-1-stage1.png deleted file mode 100644 index 46badd4..0000000 Binary files a/materials/hw-1-stage1.png and /dev/null differ diff --git a/materials/hw-1-stage2.png b/materials/hw-1-stage2.png deleted file mode 100644 index 0b32877..0000000 Binary files a/materials/hw-1-stage2.png and /dev/null differ diff --git a/materials/hw-1-stage3.png b/materials/hw-1-stage3.png deleted file mode 100644 index bfc60df..0000000 Binary files a/materials/hw-1-stage3.png and /dev/null differ diff --git a/materials/hw-1-stage4.png b/materials/hw-1-stage4.png deleted file mode 100644 index d9e42e7..0000000 Binary files a/materials/hw-1-stage4.png and /dev/null differ diff --git a/materials/hw-1-stage5.png b/materials/hw-1-stage5.png deleted file mode 100644 index 34a9574..0000000 Binary files a/materials/hw-1-stage5.png and /dev/null differ diff --git a/materials/hw-simple-instance.png b/materials/hw-simple-instance.png deleted file mode 100644 index 3499151..0000000 Binary files a/materials/hw-simple-instance.png and /dev/null differ diff --git a/materials/readme.md b/materials/readme.md deleted file mode 100644 index c27ea06..0000000 --- a/materials/readme.md +++ /dev/null @@ -1 +0,0 @@ -This folder contains some materials used by documents. diff --git a/models/computer-types.json b/models/computer-types.json new file mode 100644 index 0000000..7718b37 --- /dev/null +++ b/models/computer-types.json @@ -0,0 +1,54 @@ +{ + "computer_types": [ + { + "name": "RaspberryPi3", + "os": "RaspberryPiOS", + "description": "Entry-level computer for lightweight tasks", + "resources": { + "memory": "1GB", + "cpu": "4-core ARM Cortex-A53", + "storage": "16GB" + } + }, + { + "name": "RaspberryPi4", + "os": "RaspberryPiOS", + "description": "Improved model with enhanced performance", + "resources": { + "memory": "4GB", + "cpu": "4-core ARM Cortex-A72", + "storage": "32GB" + } + }, + { + "name": "PC", + "os": "UbuntuLinux", + "description": "Standard desktop computer for general-purpose use", + "resources": { + "memory": "16GB", + "cpu": "8-core Intel i7", + "storage": "512GB" + } + }, + { + "name": "Laptop", + "os": "Windows10", + "description": "Portable computer for professional and personal use", + "resources": { + "memory": "8GB", + "cpu": "4-core Intel i5", + "storage": "256GB" + } + }, + { + "name": "Server", + "os": "CentOS", + "description": "High-performance server for enterprise applications", + "resources": { + "memory": "64GB", + "cpu": "16-core AMD EPYC", + "storage": "2TB" + } + } + ] +} diff --git a/models/deployments.json b/models/deployments.json new file mode 100644 index 0000000..1e20f8a --- /dev/null +++ b/models/deployments.json @@ -0,0 +1,155 @@ +{ + "deployments": [ + { + "name": "HomeSecuritySystem", + "computers": [ + { + "name": "camera_node_1", + "type": "RaspberryPi4", + "software": [ + "YoloV8", + "OpenCV" + ], + "ip": "192.168.1.10" + }, + { + "name": "central_server", + "type": "Server", + "software": [ + "OpenHAB", + "YoloV10", + "OpenCV" + ], + "ip": "192.168.1.20" + } + ], + "connections": [ + { + "source": "camera_node_1", + "target": "central_server" + } + ] + }, + { + "name": "IndustrialAutomation", + "computers": [ + { + "name": "control_unit", + "type": "PC", + "software": [ + "OpenHAB", + "OpenCV" + ], + "ip": "10.0.0.5" + }, + { + "name": "sensor_node_1", + "type": "RaspberryPi3", + "software": [ + "YoloV8" + ], + "ip": "10.0.0.6" + }, + { + "name": "sensor_node_2", + "type": "RaspberryPi3", + "software": [ + "YoloV8" + ], + "ip": "10.0.0.7" + }, + { + "name": "data_processing_server", + "type": "Server", + "software": [ + "YoloV10", + "OpenCV" + ], + "ip": "10.0.0.20" + } + ], + "connections": [ + { + "source": "sensor_node_1", + "target": "data_processing_server" + }, + { + "source": "sensor_node_2", + "target": "data_processing_server" + }, + { + "source": "data_processing_server", + "target": "control_unit" + } + ] + }, + { + "name": "SmartCityTrafficManagement", + "computers": [ + { + "name": "central_hub", + "type": "Server", + "software": [ + "OpenHAB", + "YoloV10", + "OpenCV" + ], + "ip": "192.168.100.1" + }, + { + "name": "traffic_camera_1", + "type": "RaspberryPi4", + "software": [ + "YoloV8", + "OpenCV" + ], + "ip": "192.168.100.2" + }, + { + "name": "traffic_camera_2", + "type": "RaspberryPi4", + "software": [ + "YoloV8", + "OpenCV" + ], + "ip": "192.168.100.3" + }, + { + "name": "data_analytics_node", + "type": "PC", + "software": [ + "YoloV10", + "OpenCV" + ], + "ip": "192.168.100.4" + }, + { + "name": "monitoring_laptop", + "type": "Laptop", + "software": [ + "OpenHAB" + ], + "ip": "192.168.100.5" + } + ], + "connections": [ + { + "source": "traffic_camera_1", + "target": "central_hub" + }, + { + "source": "traffic_camera_2", + "target": "central_hub" + }, + { + "source": "central_hub", + "target": "data_analytics_node" + }, + { + "source": "data_analytics_node", + "target": "monitoring_laptop" + } + ] + } + ] +} diff --git a/models/software-types.json b/models/software-types.json new file mode 100644 index 0000000..6a35171 --- /dev/null +++ b/models/software-types.json @@ -0,0 +1,31 @@ +{ + "software_types": [ + { + "name": "MQTTBroker", + "description": "Object detection framework version 8" + }, + { + "name": "YoloV8", + "description": "Object detection framework version 8" + }, + { + "name": "OpenCV", + "description": "Open-source computer vision library" + }, + { + "name": "YoloV10", + "description": "Object detection framework version 10 with improved accuracy", + "dependencies": [ + "OpenCV" + ] + }, + { + "name": "OpenHAB", + "description": "Open-source home automation software", + "dependencies": [ + "OpenCV", + "MQTTBroker" + ] + } + ] +} diff --git a/python-scripts/generate-computer-types.py b/python-scripts/generate-computer-types.py new file mode 100644 index 0000000..86c212f --- /dev/null +++ b/python-scripts/generate-computer-types.py @@ -0,0 +1,28 @@ +import argparse +import jinja2 +import json +from pathlib import Path + +# Set up parser +parser = argparse.ArgumentParser(description='Generate the Software Types.') +parser.add_argument('input_model', type=str, help='Path to the input JSON model file.') +parser.add_argument('template_file', type=str, help='Path to the template file.') +parser.add_argument('output_directory', type=str, help='Path to the output directory.') + +args = parser.parse_args() + +# Create output directory +output_directory = Path(args.output_directory) +output_directory.mkdir(exist_ok=True, parents=True) + +# Load the domain model +with open(args.input_model, 'r') as file: + model = json.load(file) + +# Generate code using template +template_loader = jinja2.FileSystemLoader(searchpath="./") +template_env = jinja2.Environment(loader=template_loader) +template = template_env.get_template(args.template_file) + +for computer_type in model["computer_types"]: + template.stream(computer_type).dump(str(output_directory / f"{computer_type["name"]}.java")) diff --git a/python-scripts/generate-deployments.py b/python-scripts/generate-deployments.py new file mode 100644 index 0000000..3804b4d --- /dev/null +++ b/python-scripts/generate-deployments.py @@ -0,0 +1,28 @@ +import argparse +import jinja2 +import json +from pathlib import Path + +# Set up parser +parser = argparse.ArgumentParser(description='Generate the Software Types.') +parser.add_argument('input_model', type=str, help='Path to the input JSON model file.') +parser.add_argument('template_file', type=str, help='Path to the template file.') +parser.add_argument('output_directory', type=str, help='Path to the output directory.') + +args = parser.parse_args() + +# Create output directory +output_directory = Path(args.output_directory) +output_directory.mkdir(exist_ok=True, parents=True) + +# Load the domain model +with open(args.input_model, 'r') as file: + model = json.load(file) + +# Generate code using template +template_loader = jinja2.FileSystemLoader(searchpath="./") +template_env = jinja2.Environment(loader=template_loader) +template = template_env.get_template(args.template_file) + +for deployment in model["deployments"]: + template.stream(deployment).dump(str(output_directory / f"{deployment["name"]}.java")) diff --git a/python-scripts/generate-software-repository.py b/python-scripts/generate-software-repository.py new file mode 100644 index 0000000..a2f294c --- /dev/null +++ b/python-scripts/generate-software-repository.py @@ -0,0 +1,27 @@ +import argparse +import jinja2 +import json +from pathlib import Path + +# Set up parser +parser = argparse.ArgumentParser(description='Generate the Software Types.') +parser.add_argument('input_model', type=str, help='Path to the input JSON model file.') +parser.add_argument('template_file', type=str, help='Path to the template file.') +parser.add_argument('output_file', type=str, help='Path to the output directory.') + +args = parser.parse_args() + +# Create output directory +output_file = Path(args.output_file) +output_file.parent.mkdir(exist_ok=True, parents=True) + +# Load the domain model +with open(args.input_model, 'r') as file: + model = json.load(file) + +# Generate code using template +template_loader = jinja2.FileSystemLoader(searchpath="./") +template_env = jinja2.Environment(loader=template_loader) +template = template_env.get_template(args.template_file) + +template.stream(model).dump(str(output_file)) diff --git a/python-scripts/generate-software-types.py b/python-scripts/generate-software-types.py new file mode 100644 index 0000000..1b599d0 --- /dev/null +++ b/python-scripts/generate-software-types.py @@ -0,0 +1,28 @@ +import argparse +import jinja2 +import json +from pathlib import Path + +# Set up parser +parser = argparse.ArgumentParser(description='Generate the Software Types.') +parser.add_argument('input_model', type=str, help='Path to the input JSON model file.') +parser.add_argument('template_file', type=str, help='Path to the template file.') +parser.add_argument('output_directory', type=str, help='Path to the output directory.') + +args = parser.parse_args() + +# Create output directory +output_directory = Path(args.output_directory) +output_directory.mkdir(exist_ok=True, parents=True) + +# Load the domain model +with open(args.input_model, 'r') as file: + model = json.load(file) + +# Generate code using template +template_loader = jinja2.FileSystemLoader(searchpath="./") +template_env = jinja2.Environment(loader=template_loader) +template = template_env.get_template(args.template_file) + +for software_type in model["software_types"]: + template.stream(software_type).dump(str(output_directory / f"{software_type["name"]}.java")) diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..7e11d43 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,32 @@ +rootProject.name = "ASE Homework 3" + +val homeworkStage: String by settings +val stage = homeworkStage.toInt() + +if (stage >= 1) { + include( + "computer-types", + ) +} + +if (stage >= 2) { + include( + "software-types", + ) +} + +if (stage >= 3) { + include( + "software-repository", + ) +} + +if (stage >= 4) { + include( + "deployments", + ) +} + +rootProject.children.forEach { project -> + project.projectDir = file("subprojects/${project.name}") +} diff --git a/subprojects/computer-types/build.gradle.kts b/subprojects/computer-types/build.gradle.kts new file mode 100644 index 0000000..5ab3dbe --- /dev/null +++ b/subprojects/computer-types/build.gradle.kts @@ -0,0 +1,14 @@ +import com.pswidersk.gradle.python.VenvTask + +plugins { + id("hu.bme.mit.ase.gradle.conventions.generator") +} + +val generate by tasks.getting(VenvTask::class) { + args = listOf( + "build/python-scripts/generate-computer-types.py", + "build/models/computer-types.json", + "build/jinja-templates/computer-type.java.j2", + "src/gen/java/hu/bme/mit/ase/cps/types/computers", + ) +} diff --git a/subprojects/computer-types/src/main/java/hu/bme/mit/ase/cps/types/computers/Computer.java b/subprojects/computer-types/src/main/java/hu/bme/mit/ase/cps/types/computers/Computer.java new file mode 100644 index 0000000..c6097bd --- /dev/null +++ b/subprojects/computer-types/src/main/java/hu/bme/mit/ase/cps/types/computers/Computer.java @@ -0,0 +1,27 @@ +package hu.bme.mit.ase.cps.types.computers; + +public abstract class Computer { + + private final String name; + private final String ip; + + Computer(String name, String ip) { + this.name = name; + this.ip = ip; + } + + public String getName() { + return name; + } + + public String getIp() { + return ip; + } + + abstract String getOs(); + + abstract String getDescription(); + + abstract ComputerResources getResources(); + +} diff --git a/subprojects/computer-types/src/main/java/hu/bme/mit/ase/cps/types/computers/ComputerResources.java b/subprojects/computer-types/src/main/java/hu/bme/mit/ase/cps/types/computers/ComputerResources.java new file mode 100644 index 0000000..0d0edd6 --- /dev/null +++ b/subprojects/computer-types/src/main/java/hu/bme/mit/ase/cps/types/computers/ComputerResources.java @@ -0,0 +1,26 @@ +package hu.bme.mit.ase.cps.types.computers; + +public class ComputerResources { + + private final String memory; + private final String cpu; + private final String storage; + + public ComputerResources(String memory, String cpu, String storage) { + this.memory = memory; + this.cpu = cpu; + this.storage = storage; + } + + public String getMemory() { + return memory; + } + + public String getCpu() { + return cpu; + } + + public String getStorage() { + return storage; + } +} diff --git a/subprojects/deployments/build.gradle.kts b/subprojects/deployments/build.gradle.kts new file mode 100644 index 0000000..c1a7957 --- /dev/null +++ b/subprojects/deployments/build.gradle.kts @@ -0,0 +1,19 @@ +import com.pswidersk.gradle.python.VenvTask + +plugins { + id("hu.bme.mit.ase.gradle.conventions.generator") +} + +dependencies { + implementation(project(":computer-types")) + implementation(project(":software-repository")) +} + +val generate by tasks.getting(VenvTask::class) { + args = listOf( + "build/python-scripts/generate-deployments.py", + "build/models/deployments.json", + "build/jinja-templates/deployment.java.j2", + "src/gen/java/hu/bme/mit/ase/cps/deployments", + ) +} diff --git a/subprojects/deployments/src/main/java/hu/bme/mit/ase/cps/deployments/CPS.java b/subprojects/deployments/src/main/java/hu/bme/mit/ase/cps/deployments/CPS.java new file mode 100644 index 0000000..525e834 --- /dev/null +++ b/subprojects/deployments/src/main/java/hu/bme/mit/ase/cps/deployments/CPS.java @@ -0,0 +1,16 @@ +package hu.bme.mit.ase.cps.deployments; + +import hu.bme.mit.ase.cps.types.computers.Computer; +import hu.bme.mit.ase.cps.types.software.Software; + +public abstract class CPS { + + public abstract void installSoftware(Computer computer, String software); + + public abstract void deployComputer(Computer computer); + + public abstract void connectComputers(Computer source, Computer target); + + public abstract boolean checkReachability(Computer source, Computer target); + +} diff --git a/subprojects/deployments/src/main/java/hu/bme/mit/ase/cps/deployments/Deployment.java b/subprojects/deployments/src/main/java/hu/bme/mit/ase/cps/deployments/Deployment.java new file mode 100644 index 0000000..7a8544e --- /dev/null +++ b/subprojects/deployments/src/main/java/hu/bme/mit/ase/cps/deployments/Deployment.java @@ -0,0 +1,11 @@ +package hu.bme.mit.ase.cps.deployments; + +public abstract class Deployment { + + abstract String getName(); + + abstract void deployComputers(CPS system); + + abstract boolean checkDeployment(CPS system); + +} diff --git a/subprojects/software-repository/build.gradle.kts b/subprojects/software-repository/build.gradle.kts new file mode 100644 index 0000000..2772641 --- /dev/null +++ b/subprojects/software-repository/build.gradle.kts @@ -0,0 +1,18 @@ +import com.pswidersk.gradle.python.VenvTask + +plugins { + id("hu.bme.mit.ase.gradle.conventions.generator") +} + +dependencies { + api(project(":software-types")) +} + +val generate by tasks.getting(VenvTask::class) { + args = listOf( + "build/python-scripts/generate-software-repository.py", + "build/models/software-types.json", + "build/jinja-templates/software-repository.java.j2", + "src/gen/java/hu/bme/mit/ase/cps/types/software/SoftwareRepository.java", + ) +} diff --git a/subprojects/software-repository/src/main/java/hu/bme/mit/ase/cps/types/software/Repository.java b/subprojects/software-repository/src/main/java/hu/bme/mit/ase/cps/types/software/Repository.java new file mode 100644 index 0000000..1840eff --- /dev/null +++ b/subprojects/software-repository/src/main/java/hu/bme/mit/ase/cps/types/software/Repository.java @@ -0,0 +1,20 @@ +package hu.bme.mit.ase.cps.types.software; + +import java.util.ArrayList; +import java.util.List; + +public abstract class Repository { + + private final List registeredSoftware = new ArrayList<>(); + + void registerSoftware(Software software) { + registeredSoftware.add(software); + } + + public List getRegisteredSoftware() { + return registeredSoftware; + } + + public abstract void registerRepository(); + +} diff --git a/subprojects/software-repository/src/test/java/hu/bme/mit/ase/cps/types/software/SoftareTest.java b/subprojects/software-repository/src/test/java/hu/bme/mit/ase/cps/types/software/SoftareTest.java new file mode 100644 index 0000000..8731d67 --- /dev/null +++ b/subprojects/software-repository/src/test/java/hu/bme/mit/ase/cps/types/software/SoftareTest.java @@ -0,0 +1,12 @@ +package hu.bme.mit.ase.cps.types.software; + +import org.junit.jupiter.api.Test; + +public class SoftareTest { + + @Test + public void asdf() { + + } + +} diff --git a/subprojects/software-types/build.gradle.kts b/subprojects/software-types/build.gradle.kts new file mode 100644 index 0000000..dbabbfd --- /dev/null +++ b/subprojects/software-types/build.gradle.kts @@ -0,0 +1,14 @@ +import com.pswidersk.gradle.python.VenvTask + +plugins { + id("hu.bme.mit.ase.gradle.conventions.generator") +} + +val generate by tasks.getting(VenvTask::class) { + args = listOf( + "build/python-scripts/generate-software-types.py", + "build/models/software-types.json", + "build/jinja-templates/software-type.java.j2", + "src/gen/java/hu/bme/mit/ase/cps/types/software", + ) +} diff --git a/subprojects/software-types/src/main/java/hu/bme/mit/ase/cps/types/software/Software.java b/subprojects/software-types/src/main/java/hu/bme/mit/ase/cps/types/software/Software.java new file mode 100644 index 0000000..a3ff94c --- /dev/null +++ b/subprojects/software-types/src/main/java/hu/bme/mit/ase/cps/types/software/Software.java @@ -0,0 +1,15 @@ +package hu.bme.mit.ase.cps.types.software; + +import java.util.List; + +public abstract class Software { + + abstract String getName(); + + abstract String getDescription(); + + abstract int getPort(); + + abstract List getDependencies(); + +} diff --git a/subprojects/software-types/src/test/java/hu/bme/mit/ase/cps/types/software/SoftareTest.java b/subprojects/software-types/src/test/java/hu/bme/mit/ase/cps/types/software/SoftareTest.java new file mode 100644 index 0000000..8731d67 --- /dev/null +++ b/subprojects/software-types/src/test/java/hu/bme/mit/ase/cps/types/software/SoftareTest.java @@ -0,0 +1,12 @@ +package hu.bme.mit.ase.cps.types.software; + +import org.junit.jupiter.api.Test; + +public class SoftareTest { + + @Test + public void asdf() { + + } + +}