APPController for ADAPT VH

parent 53dd4905
......@@ -122,6 +122,3 @@ local.properties
.cache-main
.scala_dependencies
.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.
......@@ -6,7 +6,6 @@ The Application Controller Library provides a consistent way for handling the Ap
1. [Features](#features)
1. [Installation](#installation)
1. [Getting started](#getting-started)
1. [Validation Exception Handling](#validation-exception-handling)
1. [The Model](#the-model)
1. [The Interface](#the-interface)
1. [License](#license)
......@@ -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:
```bash
```shell
$> git clone https://gitlab.fokus.fraunhofer.de/DECIDE/app-controller.git
$> 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:
```bash
```shell
$> mvn clean package
```
......@@ -57,15 +56,15 @@ A small example on getting the `AppDescription` and saving it using the `AppMana
```java
AppManager appManager = AppManager.open(String gitRef, String username, String password, Path localPath);
// get the Appdescription
//get the Appdescription
AppDescription appDescription = appManager.getAppDescription();
// do something with the AppDescription
//do something with the AppDescription
//then save
// then save
appManager.writeAndSync(appDescription, "Added new Microservices");
// close the AppManager
//close the AppManager
appManager.close();
```
......@@ -78,33 +77,12 @@ try (AppManager appManager = AppManager.open("https://git.ref/", "username", "pa
AppDescription appDescription = appManager.getAppDescription();
//work on the AppDescription & save it with AppManager
appManager.writeAndSync(appDescription, "Added NFRs");
} catch (AppManagerException | IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
```
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
......
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.DECIDEh2020</groupId>
<artifactId>app-controller</artifactId>
<version>0.0.15-SNAPSHOT</version>
<distributionManagement>
<repository>
<id>paca-releases</id>
<name>Paca Releases Repo</name>
<url>https://paca.fokus.fraunhofer.de/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>paca-snaptshots</id>
<url>https://paca.fokus.fraunhofer.de/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<scm>
<connection>scm:git:https://${GITLAB_USER_LDAP}:${GITLAB_USER_PASSWORD}@gitlab.fokus.fraunhofer.de/${CI_PROJECT_PATH}</connection>
<url>https://${GITLAB_USER_LDAP}:${GITLAB_USER_PASSWORD}@gitlab.fokus.fraunhofer.de/${CI_PROJECT_PATH}</url>
<developerConnection>scm:git:https://${GITLAB_USER_LDAP}:${GITLAB_USER_PASSWORD}@gitlab.fokus.fraunhofer.de/${CI_PROJECT_PATH}</developerConnection>
<tag>HEAD</tag>
</scm>
<repositories>
<repository>
<id>jgit-repository</id>
<url>https://repo.eclipse.org/content/groups/releases/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.1.1.201809181055-r</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.github.everit-org.json-schema</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<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
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.DECIDEh2020</groupId>
<artifactId>app-controller</artifactId>
<version>0.0.12</version>
<repositories>
<repository>
<id>jgit-repository</id>
<url>https://repo.eclipse.org/content/groups/releases/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.11.0.201803080745-r</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.github.everit-org.json-schema</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
......@@ -3,6 +3,7 @@ package eu.DECIDEh2020.appManager;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Collections;
import java.util.UUID;
import com.fasterxml.jackson.core.JsonParseException;
......@@ -54,7 +55,7 @@ public class AppDescriptionFactory {
appDescription.setVersion("0.2.2-alpha");
appDescription.setHighTechnologicalRisk(false);
appDescription.getMicroservices().add(createMicroservice("Default"));
appDescription.setMicroservices(Collections.singletonList(createMicroservice("Default")));
return appDescription;
}
......@@ -64,7 +65,7 @@ public class AppDescriptionFactory {
microservice.setId(UUID.randomUUID().toString());
microservice.setName(name);
microservice.getEndpoints().add("http://mircroservice1.com/service");
microservice.setEndpoints(Collections.singletonList("http://mircroservice1.com/service"));
return microservice;
}
......
......@@ -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 {
}
}
public void reset() {
gitHandler.resetAll();
}
@Override
public void close() throws IOException {
try {
......
......@@ -52,7 +52,7 @@ public class AppDescription {
private Monitoring monitoring;
private String applicationInstanceId;
private String appInstanceId;
private Map<String, JsonNode> additionalProperties = new HashMap<>();
......@@ -176,12 +176,12 @@ public class AppDescription {
this.recommendedPatterns = recommendedPatterns;
}
public String getApplicationInstanceId() {
return applicationInstanceId;
public String getAppInstanceId() {
return appInstanceId;
}
public void setApplicationInstanceId(String applicationInstanceId) {
this.applicationInstanceId = applicationInstanceId;
public void setAppInstanceId(String appInstanceId) {
this.appInstanceId = appInstanceId;
}
@JsonAnyGetter
......
......@@ -12,26 +12,16 @@ import java.util.Map;
@JsonInclude(Include.NON_EMPTY)
public class AvailabilityNfr extends Nfr {
private String abstractValue;
private Double value;
private double quantitativeAvailability;
private String unit;
public String getAbstractValue() {
return abstractValue;
}
public void setAbstractValue(String abstractValue) {
this.abstractValue = abstractValue;
}
public Double getValue() {
return value;
public double getQuantitativeAvailability() {
return quantitativeAvailability;
}
public void setValue(double value) {
this.value = value;
public void setQuantitativeAvailability(double quantitativeAvailability) {
this.quantitativeAvailability = quantitativeAvailability;
}
public String getUnit() {
......
......@@ -13,12 +13,13 @@ import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Container {
private String id;
private String name;
private String imageName;
private String imageTag;
private String dockerPrivateRegistryIp;
private Integer dockerPrivateRegistryPort;
private int dockerPrivateRegistryPort;
private String hostname;
private String restart;
......@@ -30,23 +31,31 @@ public class Container {
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 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<>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
......@@ -79,11 +88,11 @@ public class Container {
this.dockerPrivateRegistryIp = dockerPrivateRegistryIp;
}
public Integer getDockerPrivateRegistryPort() {
public int getDockerPrivateRegistryPort() {
return dockerPrivateRegistryPort;
}
public void setDockerPrivateRegistryPort(Integer dockerPrivateRegistryPort) {
public void setDockerPrivateRegistryPort(int dockerPrivateRegistryPort) {
this.dockerPrivateRegistryPort = dockerPrivateRegistryPort;
}
......@@ -135,11 +144,11 @@ public class Container {
this.networks = networks;
}
public List<VolumeMapping> getVolumeMapping() {
public Map<String, String> getVolumeMapping() {
return volumeMapping;
}
public void setVolumeMapping(List<VolumeMapping> volumeMapping) {
public void setVolumeMapping(Map<String, String> volumeMapping) {
this.volumeMapping = volumeMapping;
}
......@@ -159,44 +168,36 @@ public class Container {
this.consulKvProviderNodeName = consulKvProviderNodeName;
}
public Integer getAddConsulService() {
public boolean isAddConsulService() {
return addConsulService;
}
public void setAddConsulService(Integer addConsulService) {
public void setAddConsulService(boolean addConsulService) {
this.addConsulService = addConsulService;
}
public List<PortMapping> getPortMapping() {
return portMapping;
}
public void setPortMapping(List<PortMapping> portMapping) {
this.portMapping = portMapping;
}
public List<Endpoint> getEndpoints() {
return endpoints;
public boolean isAddConsulTraefikRules() {
return addConsulTraefikRules;
}
public void setEndpoints(List<Endpoint> endpoints) {
this.endpoints = endpoints;
public void setAddConsulTraefikRules(boolean addConsulTraefikRules) {
this.addConsulTraefikRules = addConsulTraefikRules;
}
public Integer getConsulServicePort() {
return consulServicePort;
public Map<Integer, Integer> getPortMapping() {
return portMapping;
}
public void setConsulServicePort(Integer consulServicePort) {
this.consulServicePort = consulServicePort;
public void setPortMapping(Map<Integer, Integer> portMapping) {
this.portMapping = portMapping;
}
public void setAddConsulTraefikRules(Integer addConsulTraefikRules) {
this.addConsulTraefikRules = addConsulTraefikRules;
public Endpoint getEndpoints() {
return endpoints;
}
public Integer getAddConsulTraefikRules() {
return addConsulTraefikRules;
public void setEndpoints(Endpoint endpoints) {
this.endpoints = endpoints;
}
@JsonAnyGetter
......
......@@ -6,26 +6,16 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_EMPTY)
public class CostNfr extends Nfr {
private String abstractValue;
private Double value;
private double quantitativeCost;
private String unit;
public String getAbstractValue() {
return abstractValue;
}
public void setAbstractValue(String abstractValue) {
this.abstractValue = abstractValue;
public double getQuantitativeCost() {
return quantitativeCost;
}
public Double getValue() {
return value;
}
public void setValue(Double value) {
this.value = value;
public void setQuantitativeCost(double quantitativeCost) {
this.quantitativeCost = quantitativeCost;
}
public String getUnit() {
......@@ -35,5 +25,4 @@ public class CostNfr extends Nfr {
public void setUnit(String unit) {
this.unit = unit;
}
}
......@@ -9,8 +9,8 @@ public class DetachableResource {
private String id;
private String name;
private Boolean db;
private Boolean sql;
private boolean db;
private boolean sql;
private String specificDb;
private String size;
private String classification;
......@@ -28,11 +28,11 @@ public class DetachableResource {
this.id = id;
}
public Boolean isDb() {
public boolean isDb() {
return db;
}
public void setDb(Boolean db) {
public void setDb(boolean db) {
this.db = db;
}
......@@ -48,11 +48,11 @@ public class DetachableResource {
this.name = name;
}
public Boolean isSql() {
public boolean isSql() {
return sql;
}
public void setSql(Boolean sql) {
public void setSql(boolean sql) {
this.sql = sql;
}
......
......@@ -8,9 +8,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
public class Endpoint {
private String protocol;
private Integer port;
private Integer skipRule;
private String containerNameOverride;
private int port;
private boolean skipRule;
private boolean containerNameOverride;
public String getProtocol() {
return protocol;
......@@ -20,27 +20,27 @@ public class Endpoint {
this.protocol = protocol;
}
public Integer getPort() {
public int getPort() {
return port;
}
public void setPort(Integer port) {
public void setPort(int port) {
this.port = port;
}
public Integer getSkipRule() {
public boolean isSkipRule() {
return skipRule;
}
public void setSkipRule(Integer skipRule) {
public void setSkipRule(boolean skipRule) {
this.skipRule = skipRule;
}
public String getContainerNameOverride() {
public boolean isContainerNameOverride() {
return containerNameOverride;
}
public void setContainerNameOverride(String containerNameOverride) {
public void setContainerNameOverride(boolean containerNameOverride) {
this.containerNameOverride = containerNameOverride;
}
......
......@@ -8,24 +8,34 @@ import java.util.List;
@JsonInclude(Include.NON_EMPTY)
public class LocationNfr extends Nfr {
private String abstractValue;
private List<String> qualitativeRegions;
private List<String> value;
private List<String> qualitativeCountries;
public String getAbstractValue() {
return abstractValue;
private String qualitativePolicy;
public List<String> getQualitativeRegions() {
return qualitativeRegions;
}
public void setQualitativeRegions(List<String> qualitativeRegions) {
this.qualitativeRegions = qualitativeRegions;
}
public List<String> getQualitativeCountries() {