Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ dependencies {
implementation project (':EE-Visualization')
}else {
implementation 'com.github.Apollo-Core:EE-Core:v1.0.0'
implementation 'com.github.Apollo-Core:EE-Guice:v1.0.0'
implementation 'com.github.Apollo-Core:EE-Guice:v1.0.1'
implementation 'com.github.Apollo-Core:EE-Model:v1.0.0'
implementation 'com.github.Apollo-Core:EE-IO:v1.0.0'
implementation 'com.github.Apollo-Core:EE-Enactables:v1.0.0'
implementation 'com.github.Apollo-Core:EE-Control:v1.0.0'
implementation 'com.github.Apollo-Core:EE-Visualization:v1.0.0'
implementation 'com.github.Apollo-Core:SC-Core:v1.0.0'
implementation 'com.github.Apollo-Core:EE-IO:v1.0.1'
implementation 'com.github.Apollo-Core:EE-Enactables:v1.0.1'
implementation 'com.github.Apollo-Core:EE-Control:v1.0.1'
implementation 'com.github.Apollo-Core:EE-Visualization:v1.0.1'
implementation 'com.github.Apollo-Core:SC-Core:v1.0.1'
}

// dependency to Opt4J
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import at.uibk.dps.ee.io.script.ModuleLoaderString;
import at.uibk.dps.sc.core.ScheduleModel;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import net.sf.opendse.io.SpecificationReader;
import net.sf.opendse.model.Specification;

Expand All @@ -31,12 +32,23 @@
*/
public abstract class ImplementationRunAbstract {

protected final SpecificationReader reader = new SpecificationReader();
protected final ModuleLoaderString moduleLoader =
new ModuleLoaderString(new ModuleRegister(new ModuleAutoFinder()));
protected final SpecificationReader reader;
protected final ModuleLoaderString moduleLoader;
protected final Vertx vertx;
protected Optional<SpecFromString> specOpt = Optional.empty();
protected Optional<ScheduleModel> scheduleOpt = Optional.empty();

/**
* Standard constructor.
*
* @param vertx the Vertx instance used by the server triggerring the run
*/
public ImplementationRunAbstract(final Vertx vertx) {
this.vertx = vertx;
this.reader = new SpecificationReader();
this.moduleLoader = new ModuleLoaderString(new ModuleRegister(new ModuleAutoFinder()));
}

/**
* Builds the {@link EeCoreInjectable} of apollo based on the provided strings.
*
Expand All @@ -46,6 +58,8 @@ public abstract class ImplementationRunAbstract {
*/
protected EeCoreInjectable buildEeCore(final String specString, final String configString) {
final Set<Module> modules = readModuleList(configString);
modules.add(createSpecModule(specString));
modules.add(new VertxProviderModule(vertx));
final SpecFromStringModule specModule = new SpecFromStringModule();
specModule.setSpecString(specString);
modules.add(specModule);
Expand All @@ -60,6 +74,18 @@ protected EeCoreInjectable buildEeCore(final String specString, final String con
}
}

/**
* Creates the module configuring the specification from a spec string.
*
* @param specString the string containing the specification information
* @return the module configuring the specification from a spec string
*/
protected Module createSpecModule(final String specString) {
final SpecFromStringModule specModule = new SpecFromStringModule();
specModule.setSpecString(specString);
return specModule;
}

/**
* Reads in the configuration file and returns a list of modules.
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/at/uibk/dps/ee/deploy/run/ImplementationRunBare.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import at.uibk.dps.ee.deploy.FileStringConverter;
import at.uibk.dps.ee.guice.EeCoreInjectable;
import io.vertx.core.Future;
import io.vertx.core.Vertx;

/**
* The {@link ImplementationRunBare} runs an implementation as a method.
Expand All @@ -13,6 +14,15 @@
*/
public class ImplementationRunBare extends ImplementationRunAbstract {

/**
* Standard constructor.
*
* @param vertx the VertX instance used by the triggerring server
*/
public ImplementationRunBare(Vertx vertx) {
super(vertx);
}

/**
* Implements the application as specified by the provided strings. Returns the
* resulting Json object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import at.uibk.dps.ee.guice.EeCoreInjectable;
import at.uibk.dps.sc.core.ScheduleModel;
import io.vertx.core.Future;
import io.vertx.core.Vertx;

/**
* The {@link ImplementationRunConfigured} is used to implement an application
Expand All @@ -19,6 +20,15 @@ public class ImplementationRunConfigured extends ImplementationRunAbstract {

protected Optional<EeCoreInjectable> eeCore = Optional.empty();

/**
* The standard constructor
*
* @param vertx the VertX instance used by the server triggerring the execution
*/
public ImplementationRunConfigured(Vertx vertx) {
super(vertx);
}

/**
* Configures the eeCore to be used for the implementation.
*
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/at/uibk/dps/ee/deploy/run/VertxProviderModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package at.uibk.dps.ee.deploy.run;

import org.opt4j.core.start.Opt4JModule;
import at.uibk.dps.ee.guice.starter.VertxProvider;
import io.vertx.core.Vertx;

/**
* The VertX provider module is used to bind the {@link VertxProvider} to an
* instance which is created with a provided VertX context, instead of letting
* Guice create a new VertX instance when providing the VertXProvider singleton.
*
* @author Fedor Smirnov
*/
public class VertxProviderModule extends Opt4JModule {

protected final Vertx vertxInstance;

/**
* The constructor to be used (this module has to be instantiated manually).
*
* @param vertxInstance the VertX instance which is to be used.
*/
public VertxProviderModule(Vertx vertxInstance) {
this.vertxInstance = vertxInstance;
}

@Override
protected void config() {
VertxProvider providerWithFixInstance = new VertxProvider(vertxInstance);
bind(VertxProvider.class).toInstance(providerWithFixInstance);
}
}
14 changes: 8 additions & 6 deletions src/main/java/at/uibk/dps/ee/deploy/server/ApolloServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public class ApolloServer {
public ApolloServer(final Vertx vertx, final String host) {
this.router = Router.router(vertx);
this.server = vertx.createHttpServer();
this.configuredRun = new ImplementationRunConfigured();
this.configuredRun = new ImplementationRunConfigured(vertx);
this.host = Optional.of(host);
configureRoutes();
configureRoutes(vertx);
}

/**
Expand All @@ -54,8 +54,8 @@ public ApolloServer(final Vertx vertx, final String host) {
public ApolloServer(final Vertx vertx) {
this.router = Router.router(vertx);
this.server = vertx.createHttpServer();
this.configuredRun = new ImplementationRunConfigured();
configureRoutes();
this.configuredRun = new ImplementationRunConfigured(vertx);
configureRoutes(vertx);
}

/**
Expand Down Expand Up @@ -88,8 +88,10 @@ public static void main(final String[] args) {

/**
* Configures the routes of the server.
*
* @param vertx the vertx instance used by the server
*/
protected final void configureRoutes() {
protected final void configureRoutes(Vertx vertx) {
// help message route
final Route routeHelp = router.route(ConstantsServer.routeHelpRoutes).method(HttpMethod.GET);
final RequestHandlerRoutes handlerHelp = new RequestHandlerRoutes();
Expand All @@ -102,7 +104,7 @@ protected final void configureRoutes() {
bareRoute.blockingHandler(handlerBareStrings::handle);

// routes for the configured enactment
final ImplementationRunConfigured configuredRun = new ImplementationRunConfigured();
final ImplementationRunConfigured configuredRun = new ImplementationRunConfigured(vertx);

// config route
final Route configRoute = router.route(ConstantsServer.routeConfigStrings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void handle(final RoutingContext ctx) {
final String inputString = json.getString(ConstantsServer.jsonKeyInput);
final String specString = json.getString(ConstantsServer.jsonKeySpec);
final String configString = json.getString(ConstantsServer.jsonKeyConfigs);
final ImplementationRunBare implRun = new ImplementationRunBare();
final ImplementationRunBare implRun = new ImplementationRunBare(ctx.vertx());
final String apolloResponse =
implRun.implement(inputString, specString, configString).toString();
response.end(apolloResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,58 @@

import static org.junit.jupiter.api.Assertions.*;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.google.gson.JsonObject;
import com.google.inject.Module;
import at.uibk.dps.ee.deploy.resources.ReadTestStrings;
import io.vertx.core.Vertx;
import net.sf.opendse.model.Specification;

public class ImplementationRunAbstractTest {

protected class ImplementationRunMock extends ImplementationRunAbstract {
public ImplementationRunMock(Vertx vertx) {
super(vertx);
}
}

protected Vertx vertx;

@Test
public void testReadConfig() {
ImplementationRunMock tested = new ImplementationRunMock();
ImplementationRunMock tested = new ImplementationRunMock(vertx);
String testString = ReadTestStrings.configString;
Set<Module> result = tested.readModuleList(testString);
assertEquals(3, result.size());
}

@Test
public void testReadInput() {
ImplementationRunAbstract tested = new ImplementationRunMock();
ImplementationRunAbstract tested = new ImplementationRunMock(vertx);
String testString = ReadTestStrings.inputString;
JsonObject result = tested.readInputString(testString);
assertEquals(3, result.get("input1").getAsInt());
}

@Test
public void testReadSpec() {
ImplementationRunAbstract tested = new ImplementationRunMock();
ImplementationRunAbstract tested = new ImplementationRunMock(vertx);
String testString = ReadTestStrings.specString;
Specification result = tested.readSpecification(testString);
assertEquals(1, result.getArchitecture().getVertexCount());
assertEquals(18, result.getApplication().getVertexCount());
assertEquals(5, result.getMappings().size());
}

@BeforeEach
void setup() {
vertx = Vertx.vertx();
}

@AfterEach
void cleanUp() {
vertx.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@

import static org.junit.jupiter.api.Assertions.*;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import com.google.gson.JsonObject;
import at.uibk.dps.ee.deploy.resources.ReadTestStrings;
import io.vertx.core.Vertx;

public class ImplementationRunBareTest {

protected Vertx vertx;

@Test
@Timeout(value = 10, unit = TimeUnit.SECONDS)
public void testRun() {
ImplementationRunBare tested = new ImplementationRunBare();
ImplementationRunBare tested = new ImplementationRunBare(vertx);
String configString = ReadTestStrings.configString;
String specString = ReadTestStrings.specString;
String inputString = ReadTestStrings.inputString;
JsonObject result = tested.implement(inputString, specString, configString);
assertTrue(result.has("result"));
assertEquals(16, result.get("result").getAsInt());
}

@BeforeEach
void setup() {
this.vertx = Vertx.vertx();
}

@AfterEach
void cleanUp() {
vertx.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

import static org.junit.jupiter.api.Assertions.*;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import com.google.gson.JsonObject;
import at.uibk.dps.ee.deploy.resources.ReadTestStrings;
import io.vertx.core.Vertx;

public class ImplementationRunConfiguredTest {

protected Vertx vertx;

@Test
@Timeout(value = 5, unit = TimeUnit.SECONDS)
public void testRun() {
ImplementationRunConfigured tested = new ImplementationRunConfigured();
ImplementationRunConfigured tested = new ImplementationRunConfigured(vertx);
String configString = ReadTestStrings.configString;
String specString = ReadTestStrings.specString;
String inputString = ReadTestStrings.inputString;
Expand All @@ -26,9 +31,19 @@ public void testRun() {
@Test
public void testNoConfig() {
assertThrows(IllegalStateException.class, () -> {
ImplementationRunConfigured tested = new ImplementationRunConfigured();
ImplementationRunConfigured tested = new ImplementationRunConfigured(vertx);
String inputString = ReadTestStrings.inputString;
tested.implementInput(inputString);
});
}

@BeforeEach
void setup() {
this.vertx = Vertx.vertx();
}

@AfterEach
void cleanUp() {
vertx.close();
}
}