...
 
/classes/
*.class
*.lst
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
*.iml
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
pom.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
### Eclipse template
.project
.classpath
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
/classes/
*.class
*.lst
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
*.iml
.idea/
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
pom.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
### Eclipse template
.project
.classpath
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
#Windows specific
*~
This diff is collapsed.
This diff is collapsed.
<?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>
<?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.16-SNAPSHOT</version>
<distributionManagement>
<repository>
<id>paca</id>
<name>Paca Releases Repo</name>
<url>https://paca.fokus.fraunhofer.de/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>paca</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.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</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
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;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.DECIDEh2020.appManager.exceptions.DECIDEValidationException;
import eu.DECIDEh2020.appManager.models.AppDescription;
import eu.DECIDEh2020.appManager.models.Microservice;
import org.everit.json.schema.Schema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AppDescriptionFactory {
private static Logger log = LoggerFactory.getLogger(AppDescriptionFactory.class);
private static Schema schema;
static {
try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("application_description.schema.json")) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
schema = SchemaLoader.load(rawSchema);
} catch (IOException e) {
log.error("reading schema", e);
}
/*
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("application_description.schema.json");
try {
schema = factory.getJsonSchema(new ObjectMapper().readTree(is));
} catch (ProcessingException | IOException e) {
log.error("reading json schema", e);
}
*/
}
public static AppDescription createAppDescription(String name) {
AppDescription appDescription = new AppDescription();
appDescription.setId(UUID.randomUUID().toString());
appDescription.setName(name);
appDescription.setVersion("0.2.2-alpha");
appDescription.setHighTechnologicalRisk(false);
appDescription.setMicroservices(Collections.singletonList(createMicroservice("Default")));
return appDescription;
}
public static Microservice createMicroservice(String name) {
Microservice microservice = new Microservice();
microservice.setId(UUID.randomUUID().toString());
microservice.setName(name);
microservice.setEndpoints(Collections.singletonList("http://mircroservice1.com/service"));
return microservice;
}
public static AppDescription loadAppDescription(Path path) {
try {
return new ObjectMapper().readValue(path.toFile(), AppDescription.class);
} catch (IOException e) {
log.error("reading app description file", e);
return null;
}
}
public static AppDescription fromJson(String jsonString) throws JsonParseException, JsonMappingException, IOException {
return new ObjectMapper().readValue(jsonString, AppDescription.class);
}
public static void validateAppDescription(AppDescription appDescription) throws DECIDEValidationException {
try {
schema.validate(new JSONObject(new ObjectMapper().writeValueAsString(appDescription)));
} catch (JsonProcessingException e) {
log.error("json to string", e);
throw new DECIDEValidationException(e);
} catch (ValidationException e) {
log.error("validating json", e);
throw new DECIDEValidationException(e);
}
}
public static void validateAppDescription(JsonNode appDescription) throws DECIDEValidationException {
try {
validateAppDescription(new ObjectMapper().treeToValue(appDescription, AppDescription.class));
} catch (JsonProcessingException e) {
log.error("json to value", e);
throw new DECIDEValidationException(e);
}
}
}
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.UUID;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.DECIDEh2020.appManager.exceptions.DECIDEValidationException;
import eu.DECIDEh2020.appManager.models.AppDescription;
import eu.DECIDEh2020.appManager.models.Microservice;
import org.everit.json.schema.Schema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AppDescriptionFactory {
private static Logger log = LoggerFactory.getLogger(AppDescriptionFactory.class);
private static Schema schema;
static {
try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("application_description.schema.json")) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
schema = SchemaLoader.load(rawSchema);
} catch (IOException e) {
log.error("reading schema", e);
}
/*
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("application_description.schema.json");
try {
schema = factory.getJsonSchema(new ObjectMapper().readTree(is));
} catch (ProcessingException | IOException e) {
log.error("reading json schema", e);
}
*/
}
public static AppDescription createAppDescription(String name) {
AppDescription appDescription = new AppDescription();
appDescription.setId(UUID.randomUUID().toString());
appDescription.setName(name);
appDescription.setVersion("0.2.2-alpha");
appDescription.setHighTechnologicalRisk(false);
appDescription.getMicroservices().add(createMicroservice("Default"));
return appDescription;
}
public static Microservice createMicroservice(String name) {
Microservice microservice = new Microservice();
microservice.setId(UUID.randomUUID().toString());
microservice.setName(name);
microservice.getEndpoints().add("http://mircroservice1.com/service");
return microservice;
}
public static AppDescription loadAppDescription(Path path) {
try {
return new ObjectMapper().readValue(path.toFile(), AppDescription.class);
} catch (IOException e) {
log.error("reading app description file", e);
return null;
}
}
public static AppDescription fromJson(String jsonString) throws JsonParseException, JsonMappingException, IOException {
return new ObjectMapper().readValue(jsonString, AppDescription.class);
}
public static void validateAppDescription(AppDescription appDescription) throws DECIDEValidationException {
try {
schema.validate(new JSONObject(new ObjectMapper().writeValueAsString(appDescription)));
} catch (JsonProcessingException e) {
log.error("json to string", e);
throw new DECIDEValidationException(e);
} catch (ValidationException e) {
log.error("validating json", e);
throw new DECIDEValidationException(e);
}
}
public static void validateAppDescription(JsonNode appDescription) throws DECIDEValidationException {
try {
validateAppDescription(new ObjectMapper().treeToValue(appDescription, AppDescription.class));
} catch (JsonProcessingException e) {
log.error("json to value", e);
throw new DECIDEValidationException(e);
}
}
}
package eu.DECIDEh2020.appManager;
import eu.DECIDEh2020.appManager.models.AppDescription;
import eu.DECIDEh2020.appManager.models.Microservice;
import eu.DECIDEh2020.appManager.models.Nfr;
import eu.DECIDEh2020.appManager.models.Pattern;
import java.util.HashSet;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AppDescriptionHelper {
private AppDescription appDescription;
public static AppDescriptionHelper create(AppDescription appDescription) {
return new AppDescriptionHelper(appDescription);
}
private AppDescriptionHelper(AppDescription appDescription) {
this.appDescription = appDescription;
}
public Set<String> getTags() {
Set<String> tags;
if (appDescription.getMicroservices() != null) {
tags = appDescription.getMicroservices().stream().flatMap(m -> m.getTags().stream())
.collect(Collectors.toSet());
} else {
tags = new HashSet<String>();
}
if (appDescription.getNfrs() != null) {
Set<String> ntags = appDescription.getNfrs().stream().flatMap(m -> m.getTags().stream())
.collect(Collectors.toSet());
tags.addAll(ntags);
}
return tags;
}
public List<String> getMicroserviceGroups() {
Map<String, Long> tags = appDescription.getMicroservices().stream().flatMap(m -> m.getTags().stream())
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
return tags.keySet().stream().filter(t -> tags.get(t) >= 2).collect(Collectors.toList());
}
public boolean isMicroserviceGroup(String tag) {
return appDescription.getMicroservices().stream().filter(m -> m.getTags().contains(tag)).count() >= 2;
}
public List<Microservice> getGroupMicroservices(String tag) {
return appDescription.getMicroservices().stream().filter(m -> m.getTags().contains(tag)).collect(Collectors.toList());
}
public List<Nfr> getGroupNfrs(String tag) {
return appDescription.getNfrs().stream().filter(n -> n.getTags().contains(tag)).collect(Collectors.toList());
}
public List<Pattern> getGroupPatterns(String tag) {
return appDescription.getRecommendedPatterns().stream().filter(p -> p.getTags().contains(tag)).collect(Collectors.toList());
}
public String getJson() throws JsonProcessingException {
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(appDescription);
}
}
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager;
import eu.DECIDEh2020.appManager.models.AppDescription;
import eu.DECIDEh2020.appManager.models.Microservice;
import eu.DECIDEh2020.appManager.models.Nfr;
import eu.DECIDEh2020.appManager.models.Pattern;
import java.util.HashSet;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AppDescriptionHelper {
private AppDescription appDescription;
public static AppDescriptionHelper create(AppDescription appDescription) {
return new AppDescriptionHelper(appDescription);
}
private AppDescriptionHelper(AppDescription appDescription) {
this.appDescription = appDescription;
}
public Set<String> getTags() {
Set<String> tags;
if (appDescription.getMicroservices() != null) {
tags = appDescription.getMicroservices().stream().flatMap(m -> m.getTags().stream())
.collect(Collectors.toSet());
} else {
tags = new HashSet<String>();
}
if (appDescription.getNfrs() != null) {
Set<String> ntags = appDescription.getNfrs().stream().flatMap(m -> m.getTags().stream())
.collect(Collectors.toSet());
tags.addAll(ntags);
}
return tags;
}
public List<String> getMicroserviceGroups() {
Map<String, Long> tags = appDescription.getMicroservices().stream().flatMap(m -> m.getTags().stream())
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
return tags.keySet().stream().filter(t -> tags.get(t) >= 2).collect(Collectors.toList());
}
public boolean isMicroserviceGroup(String tag) {
return appDescription.getMicroservices().stream().filter(m -> m.getTags().contains(tag)).count() >= 2;
}
public List<Microservice> getGroupMicroservices(String tag) {
return appDescription.getMicroservices().stream().filter(m -> m.getTags().contains(tag)).collect(Collectors.toList());
}
public List<Nfr> getGroupNfrs(String tag) {
return appDescription.getNfrs().stream().filter(n -> n.getTags().contains(tag)).collect(Collectors.toList());
}
public List<Pattern> getGroupPatterns(String tag) {
return appDescription.getRecommendedPatterns().stream().filter(p -> p.getTags().contains(tag)).collect(Collectors.toList());
}
public String getJson() throws JsonProcessingException {
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(appDescription);
}
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;
}
}
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import eu.DECIDEh2020.appManager.exceptions.AppManagerException;
import eu.DECIDEh2020.appManager.exceptions.DECIDEValidationException;
import eu.DECIDEh2020.appManager.models.AppDescription;
import eu.DECIDEh2020.appManager.persistence.GitHandler;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -166,6 +181,10 @@ public class AppManager implements Closeable {
}
}
public void reset() {
gitHandler.resetAll();
}
@Override
public void close() throws IOException {
try {
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.DECIDEh2020.appManager.exceptions.DECIDEValidationException;
......@@ -9,6 +21,7 @@ import eu.DECIDEh2020.appManager.models.HistoryEntry;
import org.everit.json.schema.Schema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.slf4j.Logger;
......@@ -57,7 +70,8 @@ public class HistoryFactory {
public static void validateHistory(List<HistoryEntry> history) throws DECIDEValidationException {
try {
schema.validate(new ObjectMapper().writeValueAsString(history));
// must be a JSONArrat because the schema in optimus_history.schema.json declares it as an array -> otherwise the validation throws an error that a JSONObject must begin with '{'
schema.validate(new JSONArray(new ObjectMapper().writeValueAsString(history)));
} catch (JsonProcessingException e) {
log.error("json to string", e);
throw new DECIDEValidationException(e);
......@@ -69,7 +83,7 @@ public class HistoryFactory {
public static void validateHistory(JsonNode history) throws DECIDEValidationException {
try {
schema.validate(history.toString());
schema.validate(new JSONArray(history.toString()));
} catch (ValidationException e) {
log.error("validating json", e);
throw new DECIDEValidationException(e);
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import eu.DECIDEh2020.appManager.exceptions.AppManagerException;
import eu.DECIDEh2020.appManager.exceptions.DECIDEValidationException;
import eu.DECIDEh2020.appManager.models.HistoryEntry;
import eu.DECIDEh2020.appManager.persistence.GitHandler;
import org.eclipse.jgit.api.errors.GitAPIException;
......@@ -26,7 +40,7 @@ public class HistoryManager {
private boolean strict = true;
public static HistoryManager create(GitHandler gitHandler) {
static HistoryManager create(GitHandler gitHandler) {
return new HistoryManager(gitHandler);
}
......@@ -50,16 +64,20 @@ public class HistoryManager {
this.strict = strict;
}
public List<HistoryEntry> getHistory() throws AppManagerException, IOException {
public List<HistoryEntry> getHistory() throws DECIDEValidationException, IOException {
return Arrays.asList(new ObjectMapper().treeToValue(getHistoryAsTree(), HistoryEntry[].class));
}
public ArrayNode getHistoryAsTree() throws AppManagerException, IOException {
public List<HistoryEntry> getHistory(Path path) throws AppManagerException, IOException {
return HistoryFactory.loadHistory(path);
}
public ArrayNode getHistoryAsTree() throws DECIDEValidationException, IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode history = mapper.createArrayNode();
Path path = gitHandler.getRepository().getPath().resolve(descriptor);
if (Files.exists(path)) {
history = mapper.readTree(path.resolve(descriptor).toFile());
history = mapper.readTree(path.toFile());
if (strict) {
HistoryFactory.validateHistory(history);
}
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.exceptions;
public class AppManagerException extends Exception {
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.exceptions;
public class DECIDEValidationException extends AppManagerException {
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* Eclipse Public License version 2.0 which accompanies
* this distribution, and is available at
* https://opensource.org/licenses/EPL-2.0
*
* Contributors:
*
* Torben Jastrow (Fraunhofer FOKUS)
*
* **Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu */
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Torben Jastrow (Fraunhofer FOKUS)
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import java.util.ArrayList;
......@@ -52,7 +53,7 @@ public class AppDescription {
private Monitoring monitoring;
private String appInstanceId;
private String applicationInstanceId;
private Map<String, JsonNode> additionalProperties = new HashMap<>();
......@@ -176,12 +177,12 @@ public class AppDescription {
this.recommendedPatterns = recommendedPatterns;
}
public String getAppInstanceId() {
return appInstanceId;
public String getApplicationInstanceId() {
return applicationInstanceId;
}
public void setAppInstanceId(String appInstanceId) {
this.appInstanceId = appInstanceId;
public void setApplicationInstanceId(String applicationInstanceId) {
this.applicationInstanceId = applicationInstanceId;
}
@JsonAnyGetter
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import com.fasterxml.jackson.annotation.*;
......@@ -12,16 +25,26 @@ import java.util.Map;
@JsonInclude(Include.NON_EMPTY)
public class AvailabilityNfr extends Nfr {
private double quantitativeAvailability;
private String abstractValue;
private Double value;
private String unit;
public double getQuantitativeAvailability() {
return quantitativeAvailability;
public String getAbstractValue() {
return abstractValue;
}
public void setAbstractValue(String abstractValue) {
this.abstractValue = abstractValue;
}
public Double getValue() {
return value;
}
public void setQuantitativeAvailability(double quantitativeAvailability) {
this.quantitativeAvailability = quantitativeAvailability;
public void setValue(double value) {
this.value = value;
}
public String getUnit() {
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
......@@ -13,13 +26,12 @@ 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 int dockerPrivateRegistryPort;
private Integer dockerPrivateRegistryPort;
private String hostname;
private String restart;
......@@ -31,31 +43,23 @@ public class Container {
private List<String> networks = new ArrayList<>();
private Map<String, String> volumeMapping = new HashMap<>();
private List<VolumeMapping> volumeMapping = new ArrayList<>();
private List<String> environment = new ArrayList<>();
private String consulKvProviderNodeName;
private boolean addConsulService;
private Integer addConsulService;
private int consulServicePort;
private Integer consulServicePort;
private boolean addConsulTraefikRules;
private Integer addConsulTraefikRules;
private Map<Integer, Integer> portMapping = new HashMap<>();
private List<PortMapping> portMapping = new ArrayList<>();
private Endpoint endpoints;
private List<Endpoint> endpoints = new ArrayList<>();
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;
}
......@@ -88,11 +92,11 @@ public class Container {
this.dockerPrivateRegistryIp = dockerPrivateRegistryIp;
}
public int getDockerPrivateRegistryPort() {
public Integer getDockerPrivateRegistryPort() {
return dockerPrivateRegistryPort;
}
public void setDockerPrivateRegistryPort(int dockerPrivateRegistryPort) {
public void setDockerPrivateRegistryPort(Integer dockerPrivateRegistryPort) {
this.dockerPrivateRegistryPort = dockerPrivateRegistryPort;
}
......@@ -144,11 +148,11 @@ public class Container {
this.networks = networks;
}
public Map<String, String> getVolumeMapping() {
public List<VolumeMapping> getVolumeMapping() {
return volumeMapping;
}
public void setVolumeMapping(Map<String, String> volumeMapping) {
public void setVolumeMapping(List<VolumeMapping> volumeMapping) {
this.volumeMapping = volumeMapping;
}
......@@ -168,38 +172,46 @@ public class Container {
this.consulKvProviderNodeName = consulKvProviderNodeName;
}
public boolean isAddConsulService() {
public Integer getAddConsulService() {
return addConsulService;
}
public void setAddConsulService(boolean addConsulService) {
public void setAddConsulService(Integer addConsulService) {
this.addConsulService = addConsulService;
}
public boolean isAddConsulTraefikRules() {
return addConsulTraefikRules;
}
public void setAddConsulTraefikRules(boolean addConsulTraefikRules) {
this.addConsulTraefikRules = addConsulTraefikRules;
}
public Map<Integer, Integer> getPortMapping() {
public List<PortMapping> getPortMapping() {
return portMapping;
}
public void setPortMapping(Map<Integer, Integer> portMapping) {
public void setPortMapping(List<PortMapping> portMapping) {
this.portMapping = portMapping;
}
public Endpoint getEndpoints() {
public List<Endpoint> getEndpoints() {
return endpoints;
}
public void setEndpoints(Endpoint endpoints) {
public void setEndpoints(List<Endpoint> endpoints) {
this.endpoints = endpoints;
}
public Integer getConsulServicePort() {
return consulServicePort;
}
public void setConsulServicePort(Integer consulServicePort) {
this.consulServicePort = consulServicePort;
}
public void setAddConsulTraefikRules(Integer addConsulTraefikRules) {
this.addConsulTraefikRules = addConsulTraefikRules;
}
public Integer getAddConsulTraefikRules() {
return addConsulTraefikRules;
}
@JsonAnyGetter
public Map<String, JsonNode> getAdditionalProperties() {
return additionalProperties;
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import com.fasterxml.jackson.annotation.JsonInclude;
......@@ -6,16 +19,26 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_EMPTY)
public class CostNfr extends Nfr {
private double quantitativeCost;
private String abstractValue;
private Double value;
private String unit;
public double getQuantitativeCost() {
return quantitativeCost;
public String getAbstractValue() {
return abstractValue;
}
public void setAbstractValue(String abstractValue) {
this.abstractValue = abstractValue;
}
public void setQuantitativeCost(double quantitativeCost) {
this.quantitativeCost = quantitativeCost;
public Double getValue() {
return value;
}
public void setValue(Double value) {
this.value = value;
}
public String getUnit() {
......@@ -25,4 +48,5 @@ public class CostNfr extends Nfr {
public void setUnit(String unit) {
this.unit = unit;
}
}
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
......@@ -9,8 +22,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 +41,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 +61,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;
}
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
......@@ -8,9 +21,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
public class Endpoint {
private String protocol;
private int port;
private boolean skipRule;
private boolean containerNameOverride;
private Integer port;
private Integer skipRule;
private String containerNameOverride;
public String getProtocol() {
return protocol;
......@@ -20,27 +33,27 @@ public class Endpoint {
this.protocol = protocol;
}
public int getPort() {
public Integer getPort() {
return port;
}
public void setPort(int port) {
public void setPort(Integer port) {
this.port = port;
}
public boolean isSkipRule() {
public Integer getSkipRule() {
return skipRule;
}
public void setSkipRule(boolean skipRule) {
public void setSkipRule(Integer skipRule) {
this.skipRule = skipRule;
}
public boolean isContainerNameOverride() {
public String getContainerNameOverride() {
return containerNameOverride;
}
public void setContainerNameOverride(boolean containerNameOverride) {
public void setContainerNameOverride(String containerNameOverride) {
this.containerNameOverride = containerNameOverride;
}
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* <<licensing_schema_to_be_decided>> which accompanies
* this distribution, and is available at
* https://opensource.org/licenses/EPL-2.0
*
* Contributors:
*
* Majid Salehi Ghamsari Fraunhofer FOKUS
**Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
......
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/
package eu.DECIDEh2020.appManager.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
......@@ -12,7 +26,9 @@ public class HistoryEntry {
private String date;
private Map<String, HistoricalDeployment> deployments = new HashMap<>();
private SchemaElement schema = new SchemaElement();
private List<ObjectNode> slaBreaches = new ArrayList<>();
public String getDate() {
return date;
......@@ -22,12 +38,20 @@ public class HistoryEntry {
this.date = date;
}
public Map<String, HistoricalDeployment> getDeployments() {
return deployments;
public SchemaElement getSchema() {
return schema;
}
public void setSchema(SchemaElement schema) {
this.schema = schema;
}
public void setDeployments(Map<String, HistoricalDeployment> deployments) {
this.deployments = deployments;
public List<ObjectNode> getSlaBreaches() {
return slaBreaches;
}
public void setSlaBreaches(List<ObjectNode> slaBreaches) {
this.slaBreaches = slaBreaches;
}
}
/*
* Copyright (c) 2017 Fraunhofer FOKUS.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the
* GNU AGPL v3 which accompanies
* this distribution, and is available at
* http://www.gnu.org/licenses/agpl.txt
*
* Contributors:
* Simon Dutkowski Fraunhofer FOKUS
*
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
*/