This section describe the steps needed to create a development environment for TFS components implemented in Java. Currently, ZTP and Policy components have been developed in Java (version 11) and use the [Quarkus](https://quarkus.io/) framework, which enables kubernetes-native development.
<h3><u>Install JDK</h3></u>
To begin, make sure that you have java installed and in the correct version
```
java --version
```
### **2.1.3. Java (Maven)**
If you don't have java installed you will get an error like the following:
```
Command 'java' not found, but can be installed with:
sudo apt install default-jre # version 2:1.11-72build1, or
sudo apt install openjdk-11-jre-headless # version 11.0.14+9-0ubuntu2
sudo apt install openjdk-17-jre-headless # version 17.0.2+8-1
sudo apt install openjdk-18-jre-headless # version 18~36ea-1
sudo apt install openjdk-8-jre-headless # version 8u312-b07-0ubuntu1
```
In which case you should use the following command to install the correct version:
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu120.04.1, mixed mode, sharing)
```
<h3><u>Compiling and testing existing components</h3></u>
In the root directory of the existing Java components you will find an executable maven wrapper named `mvnw`. You could use this executable, which is already configured in pair with the components, instead of your local maven installation. So for example if you want to compile the project you would run the following:
```
./mvnw compile
```
<h3><u>VS Code Quarkus plugin</h3></u>
In case you are using [VS Code](https://code.visualstudio.com/) for development, we suggest to install the [official Quarkus extension](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-quarkus).
The extension should be able to automatically find the current open project and integrate with the above `mvnw` maven wrapper, making it easier to control the [maven lifecycle](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html).
Make sure that you open the specific component directory (i.e., `src/ztp` or `src/policy`) and not the general controller one (i.e., `src`.
<h3><u>New Java TFS component</h3></u>
**Sample Project**
If you want to create a new TFS component written in Java you could generate a new Quarkus project based on the following project:
In that way, you should have most of the libraries you would need to integrate with the rest of the TFS Components. Feel free however to add or remove libraries depending on your needs.
**Initial setup**
If you used the sample project above, you should have a project with a basic structure. However there are some steps that you should take before starting development.
First make sure that you copy the protobuff files, that are found in the root directory of the TFS SDN controller, to the `new-component/src/main/proto` directory.
Next you should create the following files:
*`new-component/.gitlab-ci.yml`
*`new-component/Dockerfile`
*`new-component/src/resources/application.yaml`
We suggest to copy the respective files from existing components (Automation and Policy) and change them according to your needs.
### **2.1.3. Java (Maven)**
**Page under construction**
### **2.1.4. Rust**
**Page under construction**
### **2.1.5. Erlang**
### **2.1.5. Erlang**
This section describes how to configure the Erlang environment to run experiments and
develop code for the ETSI TeraFlowSDN controller.
First we need to install Erlang. There is multiple way, for development we will be
using [ASDF](https://asdf-vm.com/), a tool that allows the installation of multiple
version of Erlang at the same time, and switch from one version to the other at will.
- Activate Erlang locally for TFS controller. This will create a local file
called `.tool-versions` defining which version of the tools to use when
running under the current directory:
```bash
cd tfs-ctrl/
asdf local erlang 24.3.4.2
```
Erlang projects uses a build tool called
[rebar3](https://github.com/erlang/rebar3).
It is used to manager project dependenecies, compile a project and generate
project releases.
- Install rebar3 localy from source:
```bash
cd ~
git clone https://github.com/erlang/rebar3.git
cd rebar3
asdf local erlang 24.3.4.2
./bootstrap
./rebar3 local install
```
- Update `~/.bashrc` to use rebar3 by adding this line at the end:
```bash
export PATH=$HOME/.cache/rebar3/bin:$PATH
```
- Logout and log back in.
### **2.1.6. Kotlin**
### **2.1.6. Kotlin**
<h2><u>Kotlin</h2></u>
This section describes the steps needed to establish a development environment for TFS (TeraFlowSDN) components implemented in Kotlin. Currently, the `Gateway` component stands as the sole component developed in Kotlin.
<h3><u>Install Kotlin</h3></u>
To begin, make sure that you have kotlin installed and its current version:
```
kotlin -version
```
If you don't have kotlin installed you will get an error like the following:
```
Command 'kotlin' not found, but can be installed with:
sudo snap install --classic kotlin
```
In which case you should use the following command to install the correct version:
```
sudo snap install --classic kotlin
```
Currently, the recommended version is 1.6.21, which uses Java Runtime Environment (JRE) version 11.
<h3><u>Compiling and testing existing components</h3></u>
To compile a Kotlin project using Gradle, similarly to using the Maven wrapper (mvnw) for Java projects, you can use the Gradle wrapper (gradlew) within the root directory of your Kotlin component, specifically the gateway directory.
Navigate to the gateway directory within your Kotlin project. Ensure that it contains the gradlew script along with the gradle directory.
Then, create a directory named `proto` and move all the files with extension `.proto` in this way:
```
mkdir proto
cp ../../../proto/*.proto ./proto
```
For building the application, open a terminal or command prompt, navigate to the gateway directory, and run the following command:
```
./gradlew build
```
The following program runs the gateway application:
```
./gradlew runServer
```
<h3><u>New Kotlin TFS component</h3></u>
**Sample Project**
If you want to create a new TFS component written in Kotlin you could generate a Kotlin project using `gradle`. The recommended version is 7.1. Follow the following [Gradle guide](https://linuxize.com/post/how-to-install-gradle-on-ubuntu-20-04/) for its installation. For building the prokect follow [this link](https://docs.gradle.org/current/samples/sample_building_kotlin_applications.html) instead.
From inside the new project directory, run the init task using the following command in a terminal: `gradle init`.
The output will look like this:
```
$ gradle init
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) [1..6] 4
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1
Project name (default: demo):
Source package (default: demo):
BUILD SUCCESSFUL
2 actionable tasks: 2 executed
```
**Initial setup**
The `gradle init` command generates the new project.
First, ensure the protobuf files are copied from the root directory of the TFS SDN controller. Run the following command in the directory of the new project:
```
mkdir proto
cp TFS/project/root/path/proto/*.proto ./proto/
```
The file `build.gradle.ktl` is fundamental as it manages dependencies. Adjust it for adding external libraries.
Next you should create the following files:
1.`new-component/.gitlab-ci.yml`
1.`new-component/Dockerfile`
We recommend leveraging the structures and configurations found in the files of existing components for inspiration.
**Docker Container**
This project operates with Docker containers. Ensure the production of the container version for your component. To generate the container version of the project, modify the 'new-component/Dockerfile.' Execute the following command from the project's root directory: