APPController for ADAPT VH

parent 53dd4905
...@@ -122,6 +122,3 @@ local.properties ...@@ -122,6 +122,3 @@ local.properties
.cache-main .cache-main
.scala_dependencies .scala_dependencies
.worksheet .worksheet
#Windows specific
*~
# DECIDE Application Controller Library # DECIDE Application Controller
The Application Controller Library provides a consistent way for handling the AppDescription and History json files to every project that has to operate on these files. The Application Controller Library provides a consistent way for handling the AppDescription and History json files to every project that has to operate on these files.
...@@ -6,7 +6,6 @@ The Application Controller Library provides a consistent way for handling the Ap ...@@ -6,7 +6,6 @@ The Application Controller Library provides a consistent way for handling the Ap
1. [Features](#features) 1. [Features](#features)
1. [Installation](#installation) 1. [Installation](#installation)
1. [Getting started](#getting-started) 1. [Getting started](#getting-started)
1. [Validation Exception Handling](#validation-exception-handling)
1. [The Model](#the-model) 1. [The Model](#the-model)
1. [The Interface](#the-interface) 1. [The Interface](#the-interface)
1. [License](#license) 1. [License](#license)
...@@ -21,14 +20,14 @@ The Application Controller Library provides a consistent way for handling the Ap ...@@ -21,14 +20,14 @@ The Application Controller Library provides a consistent way for handling the Ap
The project is available via Git repository. If you have access, do the following steps: The project is available via Git repository. If you have access, do the following steps:
```bash ```shell
$> git clone https://gitlab.fokus.fraunhofer.de/DECIDE/app-controller.git $> git clone https://gitlab.fokus.fraunhofer.de/DECIDE/app-controller.git
$> cd app-controller $> cd app-controller
``` ```
The project uses Maven as build tool. After build you will find the jar and a fat jar in the target directory. To build use the follwoing command: The project uses Maven as build tool. After build you will find the jar and a fat jar in the target directory. To build use the follwoing command:
```bash ```shell
$> mvn clean package $> mvn clean package
``` ```
...@@ -57,15 +56,15 @@ A small example on getting the `AppDescription` and saving it using the `AppMana ...@@ -57,15 +56,15 @@ A small example on getting the `AppDescription` and saving it using the `AppMana
```java ```java
AppManager appManager = AppManager.open(String gitRef, String username, String password, Path localPath); AppManager appManager = AppManager.open(String gitRef, String username, String password, Path localPath);
// get the Appdescription //get the Appdescription
AppDescription appDescription = appManager.getAppDescription(); AppDescription appDescription = appManager.getAppDescription();
// do something with the AppDescription //do something with the AppDescription
//then save
// then save
appManager.writeAndSync(appDescription, "Added new Microservices"); appManager.writeAndSync(appDescription, "Added new Microservices");
// close the AppManager //close the AppManager
appManager.close(); appManager.close();
``` ```
...@@ -78,33 +77,12 @@ try (AppManager appManager = AppManager.open("https://git.ref/", "username", "pa ...@@ -78,33 +77,12 @@ try (AppManager appManager = AppManager.open("https://git.ref/", "username", "pa
AppDescription appDescription = appManager.getAppDescription(); AppDescription appDescription = appManager.getAppDescription();
//work on the AppDescription & save it with AppManager //work on the AppDescription & save it with AppManager
appManager.writeAndSync(appDescription, "Added NFRs"); appManager.writeAndSync(appDescription, "Added NFRs");
} catch (AppManagerException | IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
``` ```
For further examples please take a look at the test cases. For further examples please take a look at the test cases.
## Validation Exception Handling
A `DECIDEValidationException` is usually a wrapper for the underlying validation library validation errors. The AppController utilizes the JSON Schema Validator from everit-org. You can easily access the original `ValidationException` if you need more details beyond the main message.
```java
try {
AppDescription appDescription = appManager.getAppDescription();
} catch (DECIDEValidationException e) {
ValidationException original = (ValidationException)e.getCause();
// get a list of all sub messages
List<String> messages = original.getAllMessages();
// get all sub exceptions. Each one is again a ValidationException
List<ValidationException> original.getCausingExceptions();
// getting a fancy pretty printed json structure containing all sub errors
String json = original.getJSON().toString(4);
} catch (IOEXception e) {
}
```
Please note that `DECIDEValidationException` is also a subclass of `AppManagerException`.
## The Model ## The Model
......
<?xml version="1.0" encoding="UTF-8"?> <?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0"
<modelVersion>4.0.0</modelVersion> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>eu.DECIDEh2020</groupId> <modelVersion>4.0.0</modelVersion>
<artifactId>app-controller</artifactId>
<version>0.0.15-SNAPSHOT</version> <groupId>eu.DECIDEh2020</groupId>
<artifactId>app-controller</artifactId>
<distributionManagement> <version>0.0.12</version>
<repository> <repositories>
<id>paca-releases</id> <repository>
<name>Paca Releases Repo</name> <id>jgit-repository</id>
<url>https://paca.fokus.fraunhofer.de/repository/maven-releases/</url> <url>https://repo.eclipse.org/content/groups/releases/</url>
</repository> </repository>
<snapshotRepository> <repository>
<id>paca-snaptshots</id> <id>jitpack.io</id>
<url>https://paca.fokus.fraunhofer.de/repository/maven-snapshots/</url> <url>https://jitpack.io</url>
</snapshotRepository> </repository>
</distributionManagement> </repositories>
<dependencies>
<scm> <dependency>
<connection>scm:git:https://${GITLAB_USER_LDAP}:${GITLAB_USER_PASSWORD}@gitlab.fokus.fraunhofer.de/${CI_PROJECT_PATH}</connection> <groupId>org.eclipse.jgit</groupId>
<url>https://${GITLAB_USER_LDAP}:${GITLAB_USER_PASSWORD}@gitlab.fokus.fraunhofer.de/${CI_PROJECT_PATH}</url> <artifactId>org.eclipse.jgit</artifactId>
<developerConnection>scm:git:https://${GITLAB_USER_LDAP}:${GITLAB_USER_PASSWORD}@gitlab.fokus.fraunhofer.de/${CI_PROJECT_PATH}</developerConnection> <version>4.11.0.201803080745-r</version>
<tag>HEAD</tag> </dependency>
</scm> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<repositories> <artifactId>jackson-core</artifactId>
<repository> <version>2.9.5</version>
<id>jgit-repository</id> </dependency>
<url>https://repo.eclipse.org/content/groups/releases/</url> <dependency>
</repository> <groupId>com.fasterxml.jackson.core</groupId>
<repository> <artifactId>jackson-annotations</artifactId>
<id>jitpack.io</id> <version>2.9.5</version>
<url>https://jitpack.io</url> </dependency>
</repository> <dependency>
</repositories> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<dependencies> <version>2.9.5</version>
<dependency> </dependency>
<groupId>org.eclipse.jgit</groupId> <dependency>
<artifactId>org.eclipse.jgit</artifactId> <groupId>ch.qos.logback</groupId>
<version>5.1.1.201809181055-r</version> <artifactId>logback-classic</artifactId>
</dependency> <version>1.2.3</version>
<dependency> </dependency>
<groupId>com.fasterxml.jackson.core</groupId> <dependency>
<artifactId>jackson-core</artifactId> <groupId>com.github.everit-org.json-schema</groupId>
<version>2.9.5</version> <artifactId>org.everit.json.schema</artifactId>
</dependency> <version>1.9.1</version>
<dependency> </dependency>
<groupId>com.fasterxml.jackson.core</groupId> <dependency>
<artifactId>jackson-annotations</artifactId> <groupId>org.testng</groupId>
<version>2.9.5</version> <artifactId>testng</artifactId>
</dependency> <version>6.14.3</version>
<dependency> <scope>test</scope>
<groupId>com.fasterxml.jackson.core</groupId> </dependency>
<artifactId>jackson-databind</artifactId> </dependencies>
<version>2.9.5</version>
</dependency> <build>
<dependency> <plugins>
<groupId>ch.qos.logback</groupId> <plugin>
<artifactId>logback-classic</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>1.2.3</version> <version>3.7.0</version>
</dependency> <configuration>
<dependency> <source>1.8</source>
<groupId>com.github.everit-org.json-schema</groupId> <target>1.8</target>
<artifactId>org.everit.json.schema</artifactId> </configuration>
<version>1.9.1</version> </plugin>
</dependency> <plugin>
<dependency> <groupId>org.apache.maven.plugins</groupId>
<groupId>org.testng</groupId> <artifactId>maven-shade-plugin</artifactId>
<artifactId>testng</artifactId> <version>3.1.1</version>
<version>6.14.3</version> <executions>
<scope>test</scope> <execution>
</dependency> <phase>package</phase>
</dependencies> <goals>
<goal>shade</goal>
<build> </goals>
<plugins> <configuration>
<plugin> <filters>
<groupId>org.apache.maven.plugins</groupId> <filter>
<artifactId>maven-release-plugin</artifactId> <artifact>*:*</artifact>
<version>2.5.3</version> <excludes>
<configuration> <exclude>META-INF/*.SF</exclude>
<tagNameFormat>v@{project.version}</tagNameFormat> <exclude>META-INF/*.DSA</exclude>
</configuration> <exclude>META-INF/*.RSA</exclude>
</plugin> </excludes>
<plugin> </filter>
<artifactId>maven-compiler-plugin</artifactId> </filters>
<version>3.7.0</version> <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
<configuration> </configuration>
<source>1.8</source> </execution>
<target>1.8</target> </executions>
</configuration> </plugin>
</plugin> </plugins>
<plugin> </build>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> </project>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
...@@ -3,6 +3,7 @@ package eu.DECIDEh2020.appManager; ...@@ -3,6 +3,7 @@ package eu.DECIDEh2020.appManager;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collections;
import java.util.UUID; import java.util.UUID;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
...@@ -54,7 +55,7 @@ public class AppDescriptionFactory { ...@@ -54,7 +55,7 @@ public class AppDescriptionFactory {
appDescription.setVersion("0.2.2-alpha"); appDescription.setVersion("0.2.2-alpha");
appDescription.setHighTechnologicalRisk(false); appDescription.setHighTechnologicalRisk(false);
appDescription.getMicroservices().add(createMicroservice("Default")); appDescription.setMicroservices(Collections.singletonList(createMicroservice("Default")));
return appDescription; return appDescription;
} }
...@@ -64,7 +65,7 @@ public class AppDescriptionFactory { ...@@ -64,7 +65,7 @@ public class AppDescriptionFactory {
microservice.setId(UUID.randomUUID().toString()); microservice.setId(UUID.randomUUID().toString());
microservice.setName(name); microservice.setName(name);
microservice.getEndpoints().add("http://mircroservice1.com/service"); microservice.setEndpoints(Collections.singletonList("http://mircroservice1.com/service"));
return microservice; return microservice;
} }
......
...@@ -72,9 +72,4 @@ public class AppDescriptionHelper { ...@@ -72,9 +72,4 @@ public class AppDescriptionHelper {
} }
public String getMicroserviceName(String id) {
Microservice microservice = appDescription.getMicroservices().stream().filter(m -> m.getId().equalsIgnoreCase(id)).findFirst().orElse(null);
return microservice != null ? microservice.getName() : null;
}
} }
...@@ -166,10 +166,6 @@ public class AppManager implements Closeable { ...@@ -166,10 +166,6 @@ public class AppManager implements Closeable {
} }
} }
public void reset() {
gitHandler.resetAll();
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
try { try {
......
...@@ -52,7 +52,7 @@ public class AppDescription { ...@@ -52,7 +52,7 @@ public class AppDescription {
private Monitoring monitoring; private Monitoring monitoring;
private String applicationInstanceId; private String appInstanceId;
private Map<String, JsonNode> additionalProperties = new HashMap<>(); private Map<String, JsonNode> additionalProperties = new HashMap<>();
...@@ -176,12 +176,12 @@ public class AppDescription { ...@@ -176,12 +176,12 @@ public class AppDescription {
this.recommendedPatterns = recommendedPatterns; this.recommendedPatterns = recommendedPatterns;
} }
public String getApplicationInstanceId() { public String getAppInstanceId() {
return applicationInstanceId; return appInstanceId;
} }
public void setApplicationInstanceId(String applicationInstanceId) { public void setAppInstanceId(String appInstanceId) {
this.applicationInstanceId = applicationInstanceId; this.appInstanceId = appInstanceId;
} }
@JsonAnyGetter @JsonAnyGetter
......
...@@ -12,26 +12,16 @@ import java.util.Map; ...@@ -12,26 +12,16 @@ import java.util.Map;
@JsonInclude(Include.NON_EMPTY) @JsonInclude(Include.NON_EMPTY)
public class AvailabilityNfr extends Nfr { public class AvailabilityNfr extends Nfr {
private String abstractValue; private double quantitativeAvailability;
private Double value;
private String unit; private String unit;
public String getAbstractValue() { public double getQuantitativeAvailability() {
return abstractValue; return quantitativeAvailability;
}
public void setAbstractValue(String abstractValue) {
this.abstractValue = abstractValue;
}
public Double getValue() {
return value;
} }
public void setValue(double value) { public void setQuantitativeAvailability(double quantitativeAvailability) {
this.value = value; this.quantitativeAvailability = quantitativeAvailability;
} }
public String getUnit() { public String getUnit() {
......
...@@ -13,12 +13,13 @@ import java.util.Map; ...@@ -13,12 +13,13 @@ import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Container { public class Container {
private String id;
private String name; private String name;
private String imageName; private String imageName;
private String imageTag; private String imageTag;
private String dockerPrivateRegistryIp; private String dockerPrivateRegistryIp;
private Integer dockerPrivateRegistryPort; private int dockerPrivateRegistryPort;
private String hostname; private String hostname;
private String restart; private String restart;
...@@ -30,23 +31,31 @@ public class Container { ...@@ -30,23 +31,31 @@ public class Container {
private List<String> networks = new ArrayList<>(); private List<String> networks = new ArrayList<>();
private List<VolumeMapping> volumeMapping = new ArrayList<>(); private Map<String, String> volumeMapping = new HashMap<>();
private List<String> environment = new ArrayList<>(); private List<String> environment = new ArrayList<>();
private String consulKvProviderNodeName; private String consulKvProviderNodeName;
private Integer addConsulService; private boolean addConsulService;
private Integer consulServicePort; private int consulServicePort;
private Integer addConsulTraefikRules; private boolean addConsulTraefikRules;
private List<PortMapping> portMapping = new ArrayList<>(); private Map<Integer, Integer> portMapping = new HashMap<>();
private List<Endpoint> endpoints = new ArrayList<>(); private Endpoint endpoints;
private Map<String, JsonNode> additionalProperties = new HashMap<>(); private Map<String, JsonNode> additionalProperties = new HashMap<>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() { public String getName() {
return name; return name;
} }
...@@ -79,11 +88,11 @@ public class Container { ...@@ -79,11 +88,11 @@ public class Container {
this.dockerPrivateRegistryIp = dockerPrivateRegistryIp; this.dockerPrivateRegistryIp = dockerPrivateRegistryIp;
} }
public Integer getDockerPrivateRegistryPort() { public int getDockerPrivateRegistryPort() {
return dockerPrivateRegistryPort; return dockerPrivateRegistryPort;
} }
public void setDockerPrivateRegistryPort(Integer dockerPrivateRegistryPort) { public void setDockerPrivateRegistryPort(int dockerPrivateRegistryPort) {
this.dockerPrivateRegistryPort = dockerPrivateRegistryPort; this.dockerPrivateRegistryPort = dockerPrivateRegistryPort;
} }
...@@ -135,11 +144,11 @@ public class Container { ...@@ -135,11 +144,11 @@ public class Container {
this.networks = networks; this.networks = networks;
} }
public List<VolumeMapping> getVolumeMapping() { public Map<String, String> getVolumeMapping() {
return volumeMapping; return volumeMapping;
} }
public void setVolumeMapping(List<VolumeMapping> volumeMapping) { public void setVolumeMapping(Map<String, String> volumeMapping) {
this.volumeMapping = volumeMapping; this.volumeMapping = volumeMapping;
} }
...@@ -159,44 +168,36 @@ public class Container { ...@@ -159,44 +168,36 @@ public class Container {
this.consulKvProviderNodeName = consulKvProviderNodeName; this.consulKvProviderNodeName = consulKvProviderNodeName;
} }
public Integer getAddConsulService() { public boolean isAddConsulService() {
return addConsulService; return addConsulService;
} }
public void setAddConsulService(Integer addConsulService) { public void setAddConsulService(boolean addConsulService) {
this.addConsulService = addConsulService; this.addConsulService = addConsulService;
} }
public List<PortMapping> getPortMapping() { public boolean isAddConsulTraefikRules() {
return portMapping; return addConsulTraefikRules;
}
public void setPortMapping(List<PortMapping> portMapping) {
this.portMapping = portMapping;
}
public List<Endpoint> getEndpoints() {
return endpoints;
} }
public void setEndpoints(List<Endpoint> endpoints) { public void setAddConsulTraefikRules(boolean addConsulTraefikRules) {
this.endpoints = endpoints; this.addConsulTraefikRules = addConsulTraefikRules;
} }
public Integer getConsulServicePort() { public Map<Integer, Integer> getPortMapping() {
return consulServicePort; return portMapping;
} }
public void setConsulServicePort(Integer consulServicePort) { public void setPortMapping(Map<Integer, Integer> portMapping) {
this.consulServicePort = consulServicePort; this.portMapping = portMapping;
} }
public void setAddConsulTraefikRules(Integer addConsulTraefikRules) { public Endpoint getEndpoints() {
this.addConsulTraefikRules = addConsulTraefikRules; return endpoints;
} }
public Integer getAddConsulTraefikRules() { public void setEndpoints(Endpoint endpoints) {
return addConsulTraefikRules; this.endpoints = endpoints;
} }
@JsonAnyGetter @JsonAnyGetter
......
...@@ -6,26 +6,16 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; ...@@ -6,26 +6,16 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_EMPTY) @JsonInclude(Include.NON_EMPTY)
public class CostNfr extends Nfr { public class CostNfr extends Nfr {
private String abstractValue; private double quantitativeCost;
private Double value;
private String unit; private String unit;
public String getAbstractValue() { public double getQuantitativeCost() {
return abstractValue; return quantitativeCost;
}
public void setAbstractValue(String abstractValue) {
this.abstractValue = abstractValue;
} }
public Double getValue() { public void setQuantitativeCost(double quantitativeCost) {
return value; this.quantitativeCost = quantitativeCost;
}
public void setValue(Double value) {
this.value = value;
} }
public String getUnit() { public String getUnit() {
...@@ -35,5 +25,4 @@ public class CostNfr extends Nfr { ...@@ -35,5 +25,4 @@ public class CostNfr extends Nfr {
public void setUnit(String unit) { public void setUnit(String unit) {
this.unit = unit; this.unit = unit;
}