bugfixes
This commit is contained in:
parent
27ccc54458
commit
6c17b20c55
3
Californium3.properties
Normal file
3
Californium3.properties
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Californium3 CoAP Properties file
|
||||
# Wed Dec 15 21:41:00 CET 2021
|
||||
#
|
|
@ -1,4 +1,4 @@
|
|||
package ch.unisg.executorBase.executor.adapter.in.web;
|
||||
package ch.unisg.executorbase.executor.adapter.in.web;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class TaskAvailableController {
|
|||
@GetMapping(path = "/newtask/{taskType}", consumes = { "application/json" })
|
||||
public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskType") String taskType) {
|
||||
|
||||
logger.info("New " + taskType + " available");
|
||||
logger.info("ExecutorBase | New " + taskType + " task available");
|
||||
|
||||
if (ExecutorType.contains(taskType.toUpperCase())) {
|
||||
TaskAvailableCommand command = new TaskAvailableCommand(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ch.unisg.executorBase.executor.adapter.out.web;
|
||||
package ch.unisg.executorbase.executor.adapter.out.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
@ -28,6 +28,8 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
|||
@Override
|
||||
public void publishExecutionFinishedEvent(ExecutionFinishedEvent event) {
|
||||
|
||||
logger.log(Level.INFO, "ExecutorBase | Sending finish execution event....");
|
||||
|
||||
String body = new JSONObject()
|
||||
.put("taskID", event.getTaskID())
|
||||
.put("outputData", event.getOutputData())
|
||||
|
@ -51,8 +53,7 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
|||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
logger.log(Level.INFO, "Finish execution event sent with result: {0}", event.getOutputData());
|
||||
|
||||
logger.log(Level.INFO, "ExecutorBase | Finish execution event sent with result: {0}", event.getOutputData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.net.http.HttpResponse;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -52,15 +51,17 @@ public class GetAssignmentAdapter implements GetAssignmentPort {
|
|||
try {
|
||||
logger.info("ExecutorBase | Sending getAssignment request");
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
if (response.statusCode() != HttpStatus.CREATED.value()) {
|
||||
if (response.statusCode() != HttpStatus.OK.value()) {
|
||||
logger.info("ExecutorBase | No task assigned");
|
||||
return null;
|
||||
}
|
||||
logger.info("ExecutorBase | Task assigned");
|
||||
JSONObject responseBody = new JSONObject(response.body());
|
||||
|
||||
String inputData = responseBody.getString("inputData");
|
||||
return new Task(responseBody.getString("taskID"), inputData);
|
||||
if (!responseBody.get("inputData").equals(null)) {
|
||||
return new Task(responseBody.getString("taskID"), responseBody.getString("inputData"));
|
||||
}
|
||||
return new Task(responseBody.getString("taskID"));
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
|
@ -4,9 +4,11 @@ import javax.validation.constraints.NotNull;
|
|||
|
||||
import ch.unisg.common.validation.SelfValidating;
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorType;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class TaskAvailableCommand extends SelfValidating<TaskAvailableCommand> {
|
||||
|
||||
@NotNull
|
||||
|
|
|
@ -15,6 +15,6 @@ public class TaskAvailableService implements TaskAvailableUseCase {
|
|||
|
||||
@Override
|
||||
public void newTaskAvailable(TaskAvailableCommand command) {
|
||||
// Placeholder so spring can create a bean, implementation of this function is inside the executors
|
||||
// Placeholder so spring can create a bean, implementation of this service is inside the individual executors
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package ch.unisg.executorbase.executor.domain;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.unisg.common.valueobject.ExecutorURI;
|
||||
import ch.unisg.executorBase.executor.adapter.out.web.ExecutionFinishedEventAdapter;
|
||||
import ch.unisg.executorbase.executor.adapter.out.web.ExecutionFinishedEventAdapter;
|
||||
import ch.unisg.executorbase.executor.adapter.out.web.GetAssignmentAdapter;
|
||||
import ch.unisg.executorbase.executor.adapter.out.web.NotifyExecutorPoolAdapter;
|
||||
import ch.unisg.executorbase.executor.application.port.out.ExecutionFinishedEventPort;
|
||||
|
@ -35,18 +34,19 @@ public abstract class ExecutorBase {
|
|||
Logger logger = Logger.getLogger(ExecutorBase.class.getName());
|
||||
|
||||
protected ExecutorBase(ExecutorType executorType) {
|
||||
logger.info("Starting Executor");
|
||||
logger.info("ExecutorBase | Starting Executor");
|
||||
this.status = ExecutorStatus.STARTING_UP;
|
||||
this.executorType = executorType;
|
||||
// TODO set this automaticly
|
||||
this.executorURI = new ExecutorURI("http://localhost:8084");
|
||||
// TODO do this in main
|
||||
// Notify executor-pool about existence. If executor-pools response is successfull start with getting an assignment, else shut down executor.
|
||||
logger.info("ExecutorBase | Notifying executor-pool about existens");
|
||||
if(!notifyExecutorPoolService.notifyExecutorPool(this.executorURI, this.executorType)) {
|
||||
logger.log(Level.WARNING, "Executor could not connect to executor pool! Shuting down!");
|
||||
logger.log(Level.WARNING, "ExecutorBase | Executor could not connect to executor pool! Shuting down!");
|
||||
System.exit(0);
|
||||
} else {
|
||||
logger.info("Executor conntected to executor pool");
|
||||
logger.info("ExecutorBase | Executor conntected to executor pool");
|
||||
this.status = ExecutorStatus.IDLING;
|
||||
getAssignment();
|
||||
}
|
||||
|
@ -59,10 +59,10 @@ public abstract class ExecutorBase {
|
|||
public void getAssignment() {
|
||||
Task newTask = getAssignmentPort.getAssignment(this.getExecutorType(), this.getExecutorURI());
|
||||
if (newTask != null) {
|
||||
logger.info("Executor got a new task");
|
||||
logger.info("ExecutorBase | Executor got a new task");
|
||||
this.executeTask(newTask);
|
||||
} else {
|
||||
logger.info("Executor got no new task");
|
||||
logger.info("ExecutorBase | Executor got no new task");
|
||||
this.status = ExecutorStatus.IDLING;
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public abstract class ExecutorBase {
|
|||
* @return void
|
||||
**/
|
||||
private void executeTask(Task task) {
|
||||
logger.info("Starting execution");
|
||||
logger.info("ExecutorBase | Starting execution");
|
||||
this.status = ExecutorStatus.EXECUTING;
|
||||
|
||||
task.setOutputData(execution(task.getInputData()));
|
||||
|
@ -81,7 +81,7 @@ public abstract class ExecutorBase {
|
|||
executionFinishedEventPort.publishExecutionFinishedEvent(
|
||||
new ExecutionFinishedEvent(task.getTaskID(), task.getOutputData(), "SUCCESS"));
|
||||
|
||||
logger.info("Finish execution");
|
||||
logger.info("ExecutorBase | Finish execution");
|
||||
getAssignment();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,4 +22,9 @@ public class Task {
|
|||
this.inputData = inputData;
|
||||
}
|
||||
|
||||
public Task(String taskID) {
|
||||
this.taskID = taskID;
|
||||
this.inputData = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package ch.unisg.executorcomputation;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
@ -10,13 +12,15 @@ import ch.unisg.executorcomputation.executor.domain.Executor;
|
|||
@SpringBootApplication
|
||||
public class ExecutorcomputationApplication {
|
||||
|
||||
static Logger logger = Logger.getLogger(ExecutorcomputationApplication.class.getName());
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
SpringApplication.run(ExecutorcomputationApplication.class, args);
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
package ch.unisg.executorcomputation.executor.domain;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorBase;
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorType;
|
||||
|
||||
public class Executor extends ExecutorBase {
|
||||
|
||||
private static Logger executorLogger = Logger.getLogger(Executor.class.getName());
|
||||
|
||||
private static final Executor executor = new Executor(ExecutorType.COMPUTATION);
|
||||
|
||||
public static Executor getExecutor() {
|
||||
|
@ -21,43 +29,30 @@ public class Executor extends ExecutorBase {
|
|||
protected
|
||||
String execution(String inputData) {
|
||||
|
||||
String operator = "";
|
||||
if (inputData.contains("+")) {
|
||||
operator = "+";
|
||||
} else if (inputData.contains("-")) {
|
||||
operator = "-";
|
||||
} else if (inputData.contains("*")) {
|
||||
operator = "*";
|
||||
} else {
|
||||
return "invalid data";
|
||||
}
|
||||
executorLogger.info("TEST");
|
||||
executorLogger.info("Executor | Starting execution with inputData: " + inputData);
|
||||
|
||||
double result = Double.NaN;
|
||||
ScriptEngineManager mgr = new ScriptEngineManager();
|
||||
ScriptEngine engine = mgr.getEngineByName("JavaScript");
|
||||
|
||||
String result = "";
|
||||
try {
|
||||
result = engine.eval(inputData).toString();
|
||||
} catch (ScriptException e1) {
|
||||
// TODO some logic if execution fails
|
||||
executorLogger.severe(e1.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
executorLogger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
if (operator.equalsIgnoreCase("+")) {
|
||||
String[] parts = inputData.split("\\+");
|
||||
double a = Double.parseDouble(parts[0]);
|
||||
double b = Double.parseDouble(parts[1]);
|
||||
result = a + b;
|
||||
} else if (operator.equalsIgnoreCase("*")) {
|
||||
String[] parts = inputData.split("\\*");
|
||||
double a = Double.parseDouble(parts[0]);
|
||||
double b = Double.parseDouble(parts[1]);
|
||||
result = a * b;
|
||||
} else if (operator.equalsIgnoreCase("-")) {
|
||||
String[] parts = inputData.split("-");
|
||||
double a = Double.parseDouble(parts[0]);
|
||||
double b = Double.parseDouble(parts[1]);
|
||||
result = a - b;
|
||||
}
|
||||
|
||||
return Double.toString(result);
|
||||
executorLogger.info("Executor | Finish execution");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
33
executor-humidity/.gitignore
vendored
Normal file
33
executor-humidity/.gitignore
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
117
executor-humidity/.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
117
executor-humidity/.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright 2007-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if(mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if(mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if(!outputFile.getParentFile().exists()) {
|
||||
if(!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
|
||||
}
|
BIN
executor-humidity/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
executor-humidity/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
2
executor-humidity/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
2
executor-humidity/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
3
executor-humidity/Californium3.properties
Normal file
3
executor-humidity/Californium3.properties
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Californium3 CoAP Properties file
|
||||
# Wed Dec 15 22:23:03 CET 2021
|
||||
#
|
310
executor-humidity/mvnw
vendored
Executable file
310
executor-humidity/mvnw
vendored
Executable file
|
@ -0,0 +1,310 @@
|
|||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Maven Start Up Batch script
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
# JAVA_HOME - location of a JDK home dir
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# M2_HOME - location of maven2's installed home dir
|
||||
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
# e.g. to debug Maven itself, use
|
||||
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||
|
||||
if [ -f /etc/mavenrc ] ; then
|
||||
. /etc/mavenrc
|
||||
fi
|
||||
|
||||
if [ -f "$HOME/.mavenrc" ] ; then
|
||||
. "$HOME/.mavenrc"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# OS specific support. $var _must_ be set to either true or false.
|
||||
cygwin=false;
|
||||
darwin=false;
|
||||
mingw=false
|
||||
case "`uname`" in
|
||||
CYGWIN*) cygwin=true ;;
|
||||
MINGW*) mingw=true;;
|
||||
Darwin*) darwin=true
|
||||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
if [ -x "/usr/libexec/java_home" ]; then
|
||||
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||
else
|
||||
export JAVA_HOME="/Library/Java/Home"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
if [ -r /etc/gentoo-release ] ; then
|
||||
JAVA_HOME=`java-config --jre-home`
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$M2_HOME" ] ; then
|
||||
## resolve links - $0 may be a link to maven's home
|
||||
PRG="$0"
|
||||
|
||||
# need this for relative symlinks
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG="`dirname "$PRG"`/$link"
|
||||
fi
|
||||
done
|
||||
|
||||
saveddir=`pwd`
|
||||
|
||||
M2_HOME=`dirname "$PRG"`/..
|
||||
|
||||
# make it fully qualified
|
||||
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||
|
||||
cd "$saveddir"
|
||||
# echo Using m2 at $M2_HOME
|
||||
fi
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||
if $cygwin ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||
fi
|
||||
|
||||
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||
if $mingw ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
javaExecutable="`which javac`"
|
||||
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
||||
# readlink(1) is not available as standard on Solaris 10.
|
||||
readLink=`which readlink`
|
||||
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
||||
if $darwin ; then
|
||||
javaHome="`dirname \"$javaExecutable\"`"
|
||||
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
||||
else
|
||||
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
||||
fi
|
||||
javaHome="`dirname \"$javaExecutable\"`"
|
||||
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
||||
JAVA_HOME="$javaHome"
|
||||
export JAVA_HOME
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$JAVACMD" ] ; then
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
else
|
||||
JAVACMD="`which java`"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||
echo " We cannot execute $JAVACMD" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
echo "Warning: JAVA_HOME environment variable is not set."
|
||||
fi
|
||||
|
||||
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||
|
||||
# traverses directory structure from process work directory to filesystem root
|
||||
# first directory with .mvn subdirectory is considered project base directory
|
||||
find_maven_basedir() {
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Path not specified to find_maven_basedir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
basedir="$1"
|
||||
wdir="$1"
|
||||
while [ "$wdir" != '/' ] ; do
|
||||
if [ -d "$wdir"/.mvn ] ; then
|
||||
basedir=$wdir
|
||||
break
|
||||
fi
|
||||
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||
if [ -d "${wdir}" ]; then
|
||||
wdir=`cd "$wdir/.."; pwd`
|
||||
fi
|
||||
# end of workaround
|
||||
done
|
||||
echo "${basedir}"
|
||||
}
|
||||
|
||||
# concatenates all lines of a file
|
||||
concat_lines() {
|
||||
if [ -f "$1" ]; then
|
||||
echo "$(tr -s '\n' ' ' < "$1")"
|
||||
fi
|
||||
}
|
||||
|
||||
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||
if [ -z "$BASE_DIR" ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
##########################################################################################
|
||||
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
##########################################################################################
|
||||
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found .mvn/wrapper/maven-wrapper.jar"
|
||||
fi
|
||||
else
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
||||
fi
|
||||
if [ -n "$MVNW_REPOURL" ]; then
|
||||
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
else
|
||||
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
fi
|
||||
while IFS="=" read key value; do
|
||||
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
|
||||
esac
|
||||
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Downloading from: $jarUrl"
|
||||
fi
|
||||
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
||||
if $cygwin; then
|
||||
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
|
||||
fi
|
||||
|
||||
if command -v wget > /dev/null; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found wget ... using wget"
|
||||
fi
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
wget "$jarUrl" -O "$wrapperJarPath"
|
||||
else
|
||||
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
|
||||
fi
|
||||
elif command -v curl > /dev/null; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found curl ... using curl"
|
||||
fi
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
curl -o "$wrapperJarPath" "$jarUrl" -f
|
||||
else
|
||||
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
|
||||
fi
|
||||
|
||||
else
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Falling back to using Java to download"
|
||||
fi
|
||||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||
# For Cygwin, switch paths to Windows format before running javac
|
||||
if $cygwin; then
|
||||
javaClass=`cygpath --path --windows "$javaClass"`
|
||||
fi
|
||||
if [ -e "$javaClass" ]; then
|
||||
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo " - Compiling MavenWrapperDownloader.java ..."
|
||||
fi
|
||||
# Compiling the Java class
|
||||
("$JAVA_HOME/bin/javac" "$javaClass")
|
||||
fi
|
||||
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||
# Running the downloader
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo " - Running MavenWrapperDownloader.java ..."
|
||||
fi
|
||||
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
##########################################################################################
|
||||
# End of extension
|
||||
##########################################################################################
|
||||
|
||||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo $MAVEN_PROJECTBASEDIR
|
||||
fi
|
||||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||
fi
|
||||
|
||||
# Provide a "standardized" way to retrieve the CLI args that will
|
||||
# work with both Windows and non-Windows executions.
|
||||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
|
||||
export MAVEN_CMD_LINE_ARGS
|
||||
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
182
executor-humidity/mvnw.cmd
vendored
Normal file
182
executor-humidity/mvnw.cmd
vendored
Normal file
|
@ -0,0 +1,182 @@
|
|||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM https://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Maven Start Up Batch script
|
||||
@REM
|
||||
@REM Required ENV vars:
|
||||
@REM JAVA_HOME - location of a JDK home dir
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM M2_HOME - location of maven2's installed home dir
|
||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
|
||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
@REM e.g. to debug Maven itself, use
|
||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||
@echo off
|
||||
@REM set title of command window
|
||||
title %0
|
||||
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
|
||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||
|
||||
@REM set %HOME% to equivalent of $HOME
|
||||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||
|
||||
@REM Execute a user defined script before this one
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
|
||||
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
|
||||
:skipRcPre
|
||||
|
||||
@setlocal
|
||||
|
||||
set ERROR_CODE=0
|
||||
|
||||
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||
@setlocal
|
||||
|
||||
@REM ==== START VALIDATION ====
|
||||
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME not found in your environment. >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
:OkJHome
|
||||
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
@REM ==== END VALIDATION ====
|
||||
|
||||
:init
|
||||
|
||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||
@REM Fallback to current working directory if not found.
|
||||
|
||||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||
|
||||
set EXEC_DIR=%CD%
|
||||
set WDIR=%EXEC_DIR%
|
||||
:findBaseDir
|
||||
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||
cd ..
|
||||
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||
set WDIR=%CD%
|
||||
goto findBaseDir
|
||||
|
||||
:baseDirFound
|
||||
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||
cd "%EXEC_DIR%"
|
||||
goto endDetectBaseDir
|
||||
|
||||
:baseDirNotFound
|
||||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||
cd "%EXEC_DIR%"
|
||||
|
||||
:endDetectBaseDir
|
||||
|
||||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||
|
||||
@setlocal EnableExtensions EnableDelayedExpansion
|
||||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||
|
||||
:endReadAdditionalConfig
|
||||
|
||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
|
||||
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
||||
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
|
||||
)
|
||||
|
||||
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
if exist %WRAPPER_JAR% (
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Found %WRAPPER_JAR%
|
||||
)
|
||||
) else (
|
||||
if not "%MVNW_REPOURL%" == "" (
|
||||
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
)
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||
echo Downloading from: %DOWNLOAD_URL%
|
||||
)
|
||||
|
||||
powershell -Command "&{"^
|
||||
"$webclient = new-object System.Net.WebClient;"^
|
||||
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
|
||||
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
|
||||
"}"^
|
||||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
|
||||
"}"
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Finished downloading %WRAPPER_JAR%
|
||||
)
|
||||
)
|
||||
@REM End of extension
|
||||
|
||||
@REM Provide a "standardized" way to retrieve the CLI args that will
|
||||
@REM work with both Windows and non-Windows executions.
|
||||
set MAVEN_CMD_LINE_ARGS=%*
|
||||
|
||||
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
:error
|
||||
set ERROR_CODE=1
|
||||
|
||||
:end
|
||||
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
|
||||
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
|
||||
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
|
||||
:skipRcPost
|
||||
|
||||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||
if "%MAVEN_BATCH_PAUSE%" == "on" pause
|
||||
|
||||
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
|
||||
|
||||
exit /B %ERROR_CODE%
|
|
@ -9,11 +9,14 @@
|
|||
<version>2.5.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>org.unisg</groupId>
|
||||
<groupId>ch.unisg</groupId>
|
||||
<artifactId>executor-humidity</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>executor-humidity</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
|
@ -33,6 +36,12 @@
|
|||
<version>5.3.10</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.unisg</groupId>
|
||||
<artifactId>executor-base</artifactId>
|
||||
|
@ -52,11 +61,6 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>16</maven.compiler.source>
|
||||
<maven.compiler.target>16</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package ch.unisg.executorhumidity;
|
||||
|
||||
|
||||
import ch.unisg.executorhumidity.executor.domain.Executor;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import ch.unisg.executorhumidity.executor.domain.Executor;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ExecutorhumidityApplication {
|
||||
|
||||
|
|
|
@ -9,12 +9,18 @@ import ch.unisg.ics.interactions.wot.td.clients.TDCoapResponse;
|
|||
import ch.unisg.ics.interactions.wot.td.io.TDGraphReader;
|
||||
import ch.unisg.ics.interactions.wot.td.schemas.ObjectSchema;
|
||||
import ch.unisg.ics.interactions.wot.td.vocabularies.TD;
|
||||
import org.eclipse.californium.core.CoapClient;
|
||||
import org.eclipse.californium.elements.exception.ConnectorException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
|
@ -22,16 +28,21 @@ import java.net.http.HttpResponse;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class GetHumidityAdapter implements GetHumidityPort {
|
||||
|
||||
String endpoint = System.getenv("SEARCH_ENGINE_URI") == null ?
|
||||
"https://api.interactions.ics.unisg.ch/search/searchEngine" : System.getenv("SEARCH_ENGINE_URI");
|
||||
|
||||
@Override
|
||||
public String getHumidity() {
|
||||
|
||||
String endpoint = "https://api.interactions.ics.unisg.ch/search/searchEngine";
|
||||
|
||||
String input = "@prefix dct: <http://purl.org/dc/terms/> . select ?title where { ?title dct:title 'Mirogate' }";
|
||||
|
||||
var httpRequest = HttpRequest.newBuilder()
|
||||
|
@ -44,20 +55,39 @@ public class GetHumidityAdapter implements GetHumidityPort {
|
|||
|
||||
try {
|
||||
String description = client.send(httpRequest, HttpResponse.BodyHandlers.ofString()).body();
|
||||
String mirogateUri = null;
|
||||
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(new InputSource(new StringReader(description)));
|
||||
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
NodeList results = doc.getElementsByTagName("uri");
|
||||
for (int temp = 0; temp < results.getLength(); temp += 1) {
|
||||
Node nNode = results.item(temp);
|
||||
if (nNode.getTextContent().contains("mirogate")) {
|
||||
mirogateUri = nNode.getTextContent();
|
||||
}
|
||||
}
|
||||
if (mirogateUri == null) {
|
||||
// TODO implement logic if execution failed
|
||||
return "";
|
||||
}
|
||||
|
||||
// Parse a TD from a string
|
||||
ThingDescription td = TDGraphReader.readFromString(ThingDescription.TDFormat.RDF_TURTLE, description);
|
||||
ThingDescription td = TDGraphReader.readFromURL(ThingDescription.TDFormat.RDF_TURTLE, mirogateUri);
|
||||
|
||||
Optional<PropertyAffordance> humidity = td.getPropertyByName("humidity");
|
||||
|
||||
if (humidity.isPresent()) {
|
||||
Optional<Form> form = humidity.get().getFirstFormForOperationType(TD.readProperty);
|
||||
|
||||
// System.out.println(humidity.get().getDataSchema().getDatatype());
|
||||
if (form.isPresent()) {
|
||||
TDCoapRequest request = new TDCoapRequest(form.get(), TD.readProperty);
|
||||
try {
|
||||
TDCoapResponse response = request.execute();
|
||||
|
||||
Map<String, Object> payload = response.getPayloadAsObject((ObjectSchema) humidity.get().getDataSchema());
|
||||
Object result = payload.get("https://interactions.ics.unisg.ch/mirogate#HumidityValue");
|
||||
return result.toString();
|
||||
|
@ -72,6 +102,12 @@ public class GetHumidityAdapter implements GetHumidityPort {
|
|||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
} catch (SAXException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
16
executor-humidity/src/main/resources/application.properties
Normal file
16
executor-humidity/src/main/resources/application.properties
Normal file
|
@ -0,0 +1,16 @@
|
|||
server.port=8087
|
||||
|
||||
search.engine.uri=https://api.interactions.ics.unisg.ch/search/searchEngine
|
||||
|
||||
spring.profiles.active=chaos-monkey
|
||||
chaos.monkey.enabled=false
|
||||
management.endpoint.chaosmonkey.enabled=true
|
||||
management.endpoint.chaosmonkeyjmx.enabled=true
|
||||
# include specific endpoints
|
||||
management.endpoints.web.exposure.include=health,info,chaosmonkey
|
||||
chaos.monkey.watcher.controller=true
|
||||
chaos.monkey.watcher.restController=true
|
||||
chaos.monkey.watcher.service=true
|
||||
chaos.monkey.watcher.repository=true
|
||||
chaos.monkey.watcher.component=true
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
package ch.unisg.executorpool;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -21,14 +19,6 @@ public class ExecutorPoolApplication {
|
|||
private LoadExecutorPort loadExecutorPort;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
SpringApplication.run(ExecutorPoolApplication.class, args);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class InstructionToRobotAdapter implements InstructionToRobotPort {
|
|||
|
||||
String endpoint = "https://api.interactions.ics.unisg.ch/search/searchEngine";
|
||||
|
||||
String input = "@prefix dct: <http://purl.org/dc/terms/> . select ?title where { ?title dct:title 'Mirogate' }";
|
||||
String input = "@prefix dct: <http://purl.org/dc/terms/> . select ?title where { ?title dct:title 'leubot1' }";
|
||||
|
||||
var httpRequest = HttpRequest.newBuilder()
|
||||
.uri(URI.create(endpoint))
|
||||
|
|
|
@ -45,8 +45,10 @@ public class UserToRobotAdapter implements UserToRobotPort {
|
|||
try {
|
||||
var description = client.send(httpRequest, HttpResponse.BodyHandlers.ofString()).body();
|
||||
|
||||
String uri = "http://yggdrasil.interactions.ics.unisg.ch/environments/61/workspaces/102/artifacts/leubot1";
|
||||
|
||||
// Parse a TD from a string
|
||||
ThingDescription td = TDGraphReader.readFromString(ThingDescription.TDFormat.RDF_TURTLE, description);
|
||||
ThingDescription td = TDGraphReader.readFromURL(ThingDescription.TDFormat.RDF_TURTLE, uri);
|
||||
|
||||
// Create the payload to be sent with the HTTP request
|
||||
Map<String, Object> logInPayload = new HashMap<>();
|
||||
|
|
|
@ -4,17 +4,19 @@ import java.util.List;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import ch.unisg.roster.roster.adapter.out.persistence.mongodb.RosterRepository;
|
||||
import ch.unisg.roster.roster.application.port.in.LoadRosterItemPort;
|
||||
import ch.unisg.roster.roster.domain.Roster;
|
||||
import ch.unisg.roster.roster.domain.RosterItem;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import ch.unisg.roster.roster.adapter.common.clients.TapasMqttClient;
|
||||
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventMqttListener;
|
||||
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventsMqttDispatcher;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
|
@ -26,14 +28,14 @@ public class RosterApplication {
|
|||
|
||||
private static ConfigurableEnvironment ENVIRONMENT;
|
||||
|
||||
private static LoadRosterItemPort loadRosterItemPort;
|
||||
@Autowired
|
||||
private LoadRosterItemPort loadRosterItemPort;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication rosterApp = new SpringApplication(RosterApplication.class);
|
||||
ENVIRONMENT = rosterApp.run(args).getEnvironment();
|
||||
bootstrapMarketplaceWithMqtt();
|
||||
// initialiseRoster();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +54,8 @@ public class RosterApplication {
|
|||
}
|
||||
}
|
||||
|
||||
private static void initialiseRoster(){
|
||||
@PostConstruct
|
||||
private void initialiseRoster(){
|
||||
List<RosterItem> rosterItemList = loadRosterItemPort.loadAllRosterItems();
|
||||
Roster.getInstance().initialiseRoster(rosterItemList);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ public class ExecutorAddedEventListenerMqttAdapter extends ExecutorEventMqttList
|
|||
@Override
|
||||
public boolean handleEvent(MqttMessage message) {
|
||||
|
||||
System.out.println("New Executor added!");
|
||||
|
||||
String payload = new String(message.getPayload());
|
||||
|
||||
try {
|
||||
|
@ -30,6 +28,8 @@ public class ExecutorAddedEventListenerMqttAdapter extends ExecutorEventMqttList
|
|||
String taskType = data.get("executorTaskType").asText();
|
||||
String executorId = data.get("executorUri").asText();
|
||||
|
||||
LOGGER.info("Roster | New executor with type " + taskType + " added.");
|
||||
|
||||
ExecutorAddedEvent executorAddedEvent = new ExecutorAddedEvent(
|
||||
new ExecutorURI(executorId),
|
||||
new ExecutorType(taskType)
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package ch.unisg.roster.roster.adapter.in.web;
|
||||
|
||||
import ch.unisg.roster.roster.domain.Roster;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@ -16,8 +13,6 @@ import ch.unisg.roster.roster.domain.ExecutorInfo;
|
|||
import ch.unisg.roster.roster.domain.Task;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
@RestController
|
||||
public class ApplyForTaskWebController {
|
||||
private final ApplyForTaskUseCase applyForTaskUseCase;
|
||||
|
@ -26,14 +21,15 @@ public class ApplyForTaskWebController {
|
|||
this.applyForTaskUseCase = applyForTaskUseCase;
|
||||
}
|
||||
|
||||
// TODO fix return type
|
||||
Logger logger = Logger.getLogger(ApplyForTaskWebController.class.getName());
|
||||
|
||||
/**
|
||||
* Checks if task is available for the requesting executor.
|
||||
* @return a task or null if no task found
|
||||
* @return a task or 404 if no task available
|
||||
**/
|
||||
@PostMapping(path = "/task/apply", consumes = {"application/json"})
|
||||
public ResponseEntity<String> applyForTask (@RequestBody ExecutorInfo executorInfo) {
|
||||
|
||||
public Task applyForTask (@RequestBody ExecutorInfo executorInfo) {
|
||||
logger.info("Roster | Execuor applying for task");
|
||||
ApplyForTaskCommand command = new ApplyForTaskCommand(executorInfo.getExecutorType(),
|
||||
executorInfo.getExecutorURI());
|
||||
|
||||
|
@ -43,23 +39,6 @@ public class ApplyForTaskWebController {
|
|||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
String executorType = command.getTaskType().getValue().toString();
|
||||
String executorURI = command.getExecutorURI().getValue().toString();
|
||||
|
||||
String jsonPayLoad = new JSONObject()
|
||||
.put("executorType", executorType)
|
||||
.put("executorURI", executorURI)
|
||||
.toString();
|
||||
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.add("Content-Type", "application/json");
|
||||
|
||||
return new ResponseEntity<>(jsonPayLoad, responseHeaders, HttpStatus.CREATED);
|
||||
} catch (ConstraintViolationException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package ch.unisg.roster.roster.adapter.in.web;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import ch.unisg.roster.roster.application.port.in.DeleteTaskCommand;
|
||||
import ch.unisg.roster.roster.application.port.in.DeleteTaskUseCase;
|
||||
import ch.unisg.roster.roster.domain.Task;
|
||||
|
||||
@RestController
|
||||
public class DeleteTaskController {
|
||||
|
@ -19,13 +19,15 @@ public class DeleteTaskController {
|
|||
this.deleteTaskUseCase = deleteTaskUseCase;
|
||||
}
|
||||
|
||||
Logger logger = Logger.getLogger(DeleteTaskController.class.getName());
|
||||
|
||||
/**
|
||||
* Controller to delete a task
|
||||
* @return 200 OK, 409 Conflict
|
||||
**/
|
||||
@DeleteMapping(path = "/task/{taskId}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable("taskId") String taskId) {
|
||||
|
||||
logger.info("Roster | Delete task request.");
|
||||
DeleteTaskCommand command = new DeleteTaskCommand(taskId);
|
||||
|
||||
if (deleteTaskUseCase.deleteTask(command)) {
|
||||
|
|
|
@ -2,11 +2,14 @@ package ch.unisg.roster.roster.adapter.in.web;
|
|||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.function.ServerRequest.Headers;
|
||||
|
||||
import ch.unisg.roster.roster.application.port.in.NewTaskCommand;
|
||||
import ch.unisg.roster.roster.application.port.in.NewTaskUseCase;
|
||||
|
@ -27,16 +30,33 @@ public class NewTaskController {
|
|||
* @return 201 Create or 409 Conflict
|
||||
**/
|
||||
@PostMapping(path = "/task", consumes = {"application/task+json"})
|
||||
public ResponseEntity<Void> newTaskController(@RequestBody Task task) {
|
||||
public ResponseEntity<Void> newTaskController(@RequestBody Task task, @RequestHeader HttpHeaders header) {
|
||||
|
||||
logger.info("New task with id:" + task.getTaskID());
|
||||
logger.info("Roster | New task with id:" + task.getTaskID());
|
||||
|
||||
NewTaskCommand command = new NewTaskCommand(task.getTaskID(), task.getTaskUri(), task.getTaskType(),
|
||||
// Check if task URI is passed in body. (This happends when we handeling an external task) Else get task URI from header.
|
||||
String taskUri = task.getTaskUri();
|
||||
if (taskUri == null) {
|
||||
if (header.containsKey("Link")) {
|
||||
for (String location : header.get("Link")) {
|
||||
if (location.contains("rel=\"task\"")) {
|
||||
taskUri = location.split(">")[0].substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (taskUri == null) {
|
||||
logger.warning("Roster | TaskUri still null, something went wrong!");
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
NewTaskCommand command = new NewTaskCommand(task.getTaskID(), taskUri, task.getTaskType(),
|
||||
task.getInputData());
|
||||
|
||||
boolean success = newTaskUseCase.addNewTaskToQueue(command);
|
||||
|
||||
logger.info("Could create task: " + success);
|
||||
logger.info("Roster | Could create task: " + success);
|
||||
|
||||
if (success) {
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.net.http.HttpClient;
|
|||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -24,15 +26,15 @@ public class LaunchAuctionEventAdapter implements LaunchAuctionEventPort {
|
|||
@Value("${auction.house.uri}")
|
||||
String server;
|
||||
|
||||
Logger logger = Logger.getLogger(LaunchAuctionEventAdapter.class.getName());
|
||||
|
||||
@Override
|
||||
public void launchAuctionEvent(LaunchAuctionEvent launchAuctionEvent) {
|
||||
|
||||
var values = new HashMap<String, String>() {{
|
||||
var values = new HashMap<String, String>();
|
||||
|
||||
put("taskUri", launchAuctionEvent.taskUri);
|
||||
put("taskType", launchAuctionEvent.taskType.getValue());
|
||||
|
||||
}};
|
||||
values.put("taskUri", launchAuctionEvent.taskUri);
|
||||
values.put("taskType", launchAuctionEvent.taskType.getValue());
|
||||
|
||||
var objectMapper = new ObjectMapper();
|
||||
String requestBody = null;
|
||||
|
@ -45,16 +47,17 @@ public class LaunchAuctionEventAdapter implements LaunchAuctionEventPort {
|
|||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server + "/auctions/"))
|
||||
.header("Content-Type", "application/task+json")
|
||||
.header("Content-Type", "application/auction+json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package ch.unisg.roster.roster.application.port.in;
|
||||
|
||||
import ch.unisg.roster.roster.domain.RosterItem;
|
||||
|
||||
public interface DeleteRosterItem {
|
||||
|
||||
void deleteRosterItem(String taskId);
|
||||
|
|
|
@ -2,7 +2,6 @@ package ch.unisg.roster.roster.application.port.in;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import ch.unisg.roster.roster.domain.valueobject.ExecutorType;
|
||||
import ch.unisg.common.validation.SelfValidating;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
|
|
@ -19,10 +19,8 @@ public class NewTaskCommand extends SelfValidating<NewTaskCommand> {
|
|||
@NotNull
|
||||
private final ExecutorType taskType;
|
||||
|
||||
@NotNull
|
||||
private final String inputData;
|
||||
|
||||
@NotNull
|
||||
private final String taskUri;
|
||||
|
||||
public NewTaskCommand(String taskID, String taskUri, ExecutorType taskType, String inputData) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ch.unisg.roster.roster.application.service;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -24,6 +26,8 @@ public class NewTaskService implements NewTaskUseCase {
|
|||
|
||||
private final LaunchAuctionEventPort launchAuctionEventPort;
|
||||
|
||||
Logger logger = Logger.getLogger(NewTaskService.class.getName());
|
||||
|
||||
/**
|
||||
* Checks if we can execute the give task, if yes the task gets added to the task queue and return true.
|
||||
* If the task can not be executed by an internal or auction house executor, the method return false.
|
||||
|
@ -35,12 +39,15 @@ public class NewTaskService implements NewTaskUseCase {
|
|||
ExecutorRegistry executorRegistry = ExecutorRegistry.getInstance();
|
||||
|
||||
if (!executorRegistry.containsTaskType(command.getTaskType())) {
|
||||
logger.info("Roster | Task with type " + command.getTaskType() + "can not be handled internaly. Send to auction house!");
|
||||
LaunchAuctionEvent launchAuctionEvent = new LaunchAuctionEvent( command.getTaskUri(),
|
||||
command.getTaskType());
|
||||
launchAuctionEventPort.launchAuctionEvent(launchAuctionEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
logger.info("Roster | Task with type " + command.getTaskType() + " can be handled internaly.");
|
||||
|
||||
Task task = new Task(command.getTaskID(), command.getTaskType(), command.getInputData());
|
||||
|
||||
Roster.getInstance().addTaskToQueue(task);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
server.port=8082
|
||||
executor.robot.uri=http://127.0.0.1:8084
|
||||
executor.computation.uri=http://127.0.0.1:8085
|
||||
executor.humidity.uri=http://127.0.0.1:8087
|
||||
auction.house.uri=http://127.0.0.1:8086
|
||||
task.list.uri=http://127.0.0.1:8081
|
||||
# mqtt.broker.uri=tcp://localhost:1883
|
||||
|
|
|
@ -2,23 +2,16 @@ package ch.unisg.tapas;
|
|||
|
||||
import ch.unisg.tapas.auctionhouse.adapter.common.clients.TapasMqttClient;
|
||||
import ch.unisg.tapas.auctionhouse.adapter.in.messaging.mqtt.AuctionEventsMqttDispatcher;
|
||||
import ch.unisg.tapas.auctionhouse.domain.AuctionHouseDiscovery;
|
||||
import ch.unisg.tapas.auctionhouse.domain.AuctionHouseDiscoveryInformation;
|
||||
import ch.unisg.tapas.auctionhouse.adapter.common.clients.WebSubSubscriber;
|
||||
import ch.unisg.tapas.common.AuctionHouseResourceDirectory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Main TAPAS Auction House application.
|
||||
|
@ -36,8 +29,8 @@ public class TapasAuctionHouseApplication {
|
|||
ENVIRONMENT = tapasAuctioneerApp.run(args).getEnvironment();
|
||||
// TODO Set start up of message services with config
|
||||
// We will use these bootstrap methods in Week 6:
|
||||
bootstrapMarketplaceWithWebSub();
|
||||
//bootstrapMarketplaceWithMqtt();
|
||||
// bootstrapMarketplaceWithWebSub();
|
||||
bootstrapMarketplaceWithMqtt();
|
||||
}
|
||||
/**
|
||||
* Discovers auction houses and subscribes to WebSub notifications
|
||||
|
|
|
@ -50,7 +50,6 @@ public class TapasMqttClient {
|
|||
mqttClient = new org.eclipse.paho.client.mqttv3.MqttClient(brokerAddress, mqttClientId, new MemoryPersistence());
|
||||
mqttClient.connect();
|
||||
mqttClient.setCallback(messageReceivedCallback);
|
||||
|
||||
subscribeToAllTopics();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,26 +13,27 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class ExternalAuctionStartedEventListenerMqttAdapter extends AuctionEventMqttListener{
|
||||
private static final Logger LOGGER = LogManager.getLogger(ExternalAuctionStartedEventListenerMqttAdapter.class);
|
||||
|
||||
String auctionHouseURI = "https://tapas-auction-house.86-119-35-40.nip.io/";
|
||||
// String auctionHouseURI = "https://tapas-auction-house.86-119-35-40.nip.io/";
|
||||
String auctionHouseURI = "http://a888-77-59-152-182.eu.ngrok.io";
|
||||
|
||||
String taskListURI = "https://tapas-tasks.86-119-35-40.nip.io";
|
||||
// String taskListURI = "https://tapas-tasks.86-119-35-40.nip.io";
|
||||
String taskListURI = "http://e021-77-59-152-182.ngrok.io";
|
||||
|
||||
@Override
|
||||
public boolean handleEvent(MqttMessage message){
|
||||
String payload = new String(message.getPayload());
|
||||
|
||||
System.out.println("New auction");
|
||||
|
||||
try {
|
||||
// Note: this message representation is provided only as an example. You should use a
|
||||
// representation that makes sense in the context of your application.
|
||||
|
@ -46,6 +47,7 @@ public class ExternalAuctionStartedEventListenerMqttAdapter extends AuctionEvent
|
|||
String deadline = data.get("deadline").asText();
|
||||
|
||||
var capable = ExecutorRegistry.getInstance().containsTaskType(new Auction.AuctionedTaskType(taskType));
|
||||
System.out.println("Capable: " + capable);
|
||||
// TODO check deadline
|
||||
if(capable){
|
||||
var bid = new Bid(
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package ch.unisg.tapas.auctionhouse.adapter.in.web;
|
||||
|
||||
import ch.unisg.tapas.auctionhouse.adapter.common.formats.AuctionJsonRepresentation;
|
||||
import ch.unisg.tapas.auctionhouse.adapter.common.formats.BidJsonRepresentation;
|
||||
import ch.unisg.tapas.auctionhouse.adapter.common.formats.TaskJsonRepresentation;
|
||||
import ch.unisg.tapas.auctionhouse.adapter.in.messaging.mqtt.ExternalAuctionStartedEventListenerMqttAdapter;
|
||||
import ch.unisg.tapas.auctionhouse.domain.Task;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
@ -35,7 +30,7 @@ public class WinningBidWebController {
|
|||
try {
|
||||
var body = payload.serialize();
|
||||
LOGGER.info(body);
|
||||
var postURI = URI.create("https://tapas-tasks.86-119-35-40.nip.io/tasks/");
|
||||
var postURI = URI.create(taskListURI + "/tasks/");
|
||||
HttpRequest postRequest = HttpRequest.newBuilder()
|
||||
.uri(postURI)
|
||||
.header("Content-Type", TaskJsonRepresentation.MEDIA_TYPE)
|
||||
|
@ -49,7 +44,7 @@ public class WinningBidWebController {
|
|||
|
||||
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
return new ResponseEntity<>(responseHeaders, HttpStatus.NO_CONTENT);
|
||||
return new ResponseEntity<>(responseHeaders, HttpStatus.ACCEPTED);
|
||||
}
|
||||
catch (
|
||||
IOException | InterruptedException e) {
|
||||
|
|
|
@ -6,31 +6,33 @@ import ch.unisg.tapas.auctionhouse.adapter.in.messaging.mqtt.AuctionEventsMqttDi
|
|||
import ch.unisg.tapas.auctionhouse.application.port.out.AuctionStartedEventPort;
|
||||
import ch.unisg.tapas.auctionhouse.domain.AuctionStartedEvent;
|
||||
import ch.unisg.tapas.common.ConfigProperties;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
// @Primary
|
||||
@Primary
|
||||
public class PublishAuctionStartedEventMqttAdapter implements AuctionStartedEventPort {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(PublishAuctionStartedEventMqttAdapter.class);
|
||||
Logger logger = Logger.getLogger(PublishAuctionStartedEventMqttAdapter.class.getName());
|
||||
|
||||
@Autowired
|
||||
private ConfigProperties config;
|
||||
|
||||
@Override
|
||||
public void publishAuctionStartedEvent(AuctionStartedEvent event) {
|
||||
logger.info("AuctionHouse | Publish auction started over Mqtt!");
|
||||
try{
|
||||
var mqttClient = TapasMqttClient.getInstance(config.getMqttBrokerUri().toString(), new AuctionEventsMqttDispatcher());
|
||||
mqttClient.publishMessage("ch/unisg/tapas/auctions", AuctionJsonRepresentation.serialize(event.getAuction()));
|
||||
}
|
||||
catch (MqttException | JsonProcessingException e){
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
logger.severe(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.logging.Logger;
|
|||
* This class is a template for publishing auction started events via WebSub.
|
||||
*/
|
||||
@Component
|
||||
@Primary
|
||||
// @Primary
|
||||
public class PublishAuctionStartedEventWebSubAdapter implements AuctionStartedEventPort {
|
||||
@Value("${auction.house.uri}")
|
||||
private String auctionHouseUri;
|
||||
|
@ -31,12 +31,12 @@ public class PublishAuctionStartedEventWebSubAdapter implements AuctionStartedEv
|
|||
|
||||
@Override
|
||||
public void publishAuctionStartedEvent(AuctionStartedEvent event) {
|
||||
logger.info("AuctionHouse | Publish auction started over WebSub!");
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
String body = "hub.url=" + auctionHouseUri + "/auctions/&hub.mode=publish";
|
||||
|
||||
logger.info("Auctions updated:" + body);
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(webSubHubUri))
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
@ -46,7 +46,7 @@ public class PublishAuctionStartedEventWebSubAdapter implements AuctionStartedEv
|
|||
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
logger.info("WEBSUB send successfuly");
|
||||
logger.info("AuctionHouse | Publish auction over WebSub successfuly!");
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package ch.unisg.tapas.auctionhouse.adapter.out.web;
|
||||
|
||||
import ch.unisg.tapas.auctionhouse.adapter.common.formats.TaskJsonRepresentation;
|
||||
import ch.unisg.tapas.auctionhouse.application.handler.AuctionStartedHandler;
|
||||
import ch.unisg.tapas.auctionhouse.application.port.out.AuctionWonEventPort;
|
||||
import ch.unisg.tapas.auctionhouse.domain.AuctionRegistry;
|
||||
import ch.unisg.tapas.auctionhouse.domain.AuctionWonEvent;
|
||||
|
@ -11,6 +10,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -45,6 +45,10 @@ public class AuctionWonEventHttpAdapter implements AuctionWonEventPort {
|
|||
.build();
|
||||
|
||||
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
if (response.statusCode() != HttpStatus.OK.value()) {
|
||||
LOGGER.info("AuctionHouse | Could not get task from tasklist. Something went wrong...");
|
||||
return;
|
||||
}
|
||||
LOGGER.info(response.body());
|
||||
JSONObject responseBody = new JSONObject(response.body());
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package ch.unisg.tapas.auctionhouse.application.service;
|
|||
|
||||
import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionCommand;
|
||||
import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionUseCase;
|
||||
import ch.unisg.tapas.auctionhouse.application.port.in.LaunchAuctionUseCase;
|
||||
import ch.unisg.tapas.auctionhouse.application.port.out.AuctionWonEventPort;
|
||||
import ch.unisg.tapas.auctionhouse.application.port.out.AuctionStartedEventPort;
|
||||
import ch.unisg.tapas.auctionhouse.domain.*;
|
||||
|
@ -13,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
@ -27,10 +27,10 @@ import java.util.concurrent.TimeUnit;
|
|||
public class StartAuctionService implements LaunchAuctionUseCase {
|
||||
private static final Logger LOGGER = LogManager.getLogger(StartAuctionService.class);
|
||||
|
||||
private final Timestamp DEFAULT_AUCTION_DEADLINE_MILLIS = Timestamp.valueOf("1970-01-01 00:00:01");
|
||||
private final Timestamp DEFAULT_AUCTION_DEADLINE_MILLIS = new Timestamp(System.currentTimeMillis() + 20000);
|
||||
|
||||
// Event port used to publish an auction started event
|
||||
private final AuctionStartedEventPort auctionStartedEventPort;
|
||||
private final List<AuctionStartedEventPort> auctionStartedEventPorts;
|
||||
// Event port used to publish an auction won event
|
||||
private final AuctionWonEventPort auctionWonEventPort;
|
||||
|
||||
|
@ -40,9 +40,9 @@ public class StartAuctionService implements LaunchAuctionUseCase {
|
|||
@Autowired
|
||||
private ConfigProperties config;
|
||||
|
||||
public StartAuctionService(AuctionStartedEventPort auctionStartedEventPort,
|
||||
public StartAuctionService(List<AuctionStartedEventPort> auctionStartedEventPorts,
|
||||
AuctionWonEventPort auctionWonEventPort) {
|
||||
this.auctionStartedEventPort = auctionStartedEventPort;
|
||||
this.auctionStartedEventPorts = auctionStartedEventPorts;
|
||||
this.auctionWonEventPort = auctionWonEventPort;
|
||||
this.auctions = AuctionRegistry.getInstance();
|
||||
this.service = Executors.newScheduledThreadPool(1);
|
||||
|
@ -70,7 +70,9 @@ public class StartAuctionService implements LaunchAuctionUseCase {
|
|||
|
||||
// Publish an auction started event
|
||||
AuctionStartedEvent auctionStartedEvent = new AuctionStartedEvent(auction);
|
||||
for (AuctionStartedEventPort auctionStartedEventPort : auctionStartedEventPorts) {
|
||||
auctionStartedEventPort.publishAuctionStartedEvent(auctionStartedEvent);
|
||||
}
|
||||
|
||||
return auction;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@ broker.mqtt=tcp://broker.hivemq.com
|
|||
websub.hub=https://websub.appspot.com/
|
||||
websub.hub.publish=https://websub.appspot.com/
|
||||
|
||||
group=tapas-group-tutors
|
||||
group=tapas-group-1
|
||||
auction.house.uri=https://tapas-auction-house.86-119-35-40.nip.io
|
||||
# auction.house.uri=http://a888-77-59-152-182.eu.ngrok.io
|
||||
tasks.list.uri=http://localhost:8081
|
||||
|
||||
application.environment=development
|
||||
|
|
|
@ -12,7 +12,6 @@ public class TapasTasksApplication {
|
|||
public static void main(String[] args) {
|
||||
SpringApplication tapasTasksApp = new SpringApplication(TapasTasksApplication.class);
|
||||
tapasTasksApp.run(args);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.springframework.web.server.ResponseStatusException;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -39,7 +40,9 @@ import java.util.Optional;
|
|||
public class TaskEventHttpDispatcher {
|
||||
// The standard media type for JSON Patch registered with IANA
|
||||
// See: https://www.iana.org/assignments/media-types/application/json-patch+json
|
||||
private final static String JSON_PATCH_MEDIA_TYPE = "application/json-patch+json";
|
||||
private static final String JSON_PATCH_MEDIA_TYPE = "application/json-patch+json";
|
||||
|
||||
Logger logger = Logger.getLogger(TaskEventHttpDispatcher.class.getName());
|
||||
|
||||
/**
|
||||
* Handles HTTP PATCH requests with a JSON Patch payload. Routes the requests based on the
|
||||
|
@ -55,6 +58,7 @@ public class TaskEventHttpDispatcher {
|
|||
@PatchMapping(path = "/tasks/{taskId}", consumes = {JSON_PATCH_MEDIA_TYPE})
|
||||
public ResponseEntity<String> dispatchTaskEvents(@PathVariable("taskId") String taskId,
|
||||
@RequestBody JsonNode payload) {
|
||||
logger.info("TaskList | Incoming patch task request for task: " + taskId);
|
||||
try {
|
||||
// Throw an exception if the JSON Patch format is invalid. This call is only used to
|
||||
// validate the JSON PATCH syntax.
|
||||
|
@ -78,6 +82,8 @@ public class TaskEventHttpDispatcher {
|
|||
case EXECUTED:
|
||||
listener = new TaskExecutedEventListenerHttpAdapter();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +98,7 @@ public class TaskEventHttpDispatcher {
|
|||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskJsonRepresentation.MEDIA_TYPE);
|
||||
|
||||
logger.info("TaskList | Task with id " + taskId + " patched successfuly");
|
||||
return new ResponseEntity<>(TaskJsonRepresentation.serialize(task), responseHeaders,
|
||||
HttpStatus.OK);
|
||||
} catch (TaskNotFoundException e) {
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.springframework.web.server.ResponseStatusException;
|
|||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Controller that handles HTTP requests for creating new tasks. This controller implements the
|
||||
|
@ -35,6 +36,8 @@ import java.util.Optional;
|
|||
public class AddNewTaskToTaskListWebController {
|
||||
private final AddNewTaskToTaskListUseCase addNewTaskToTaskListUseCase;
|
||||
|
||||
Logger logger = Logger.getLogger(AddNewTaskToTaskListWebController.class.getName());
|
||||
|
||||
// Used to retrieve properties from application.properties
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
@ -45,6 +48,7 @@ public class AddNewTaskToTaskListWebController {
|
|||
|
||||
@PostMapping(path = "/tasks/", consumes = {TaskJsonRepresentation.MEDIA_TYPE})
|
||||
public ResponseEntity<String> addNewTaskTaskToTaskList(@RequestBody TaskJsonRepresentation payload) {
|
||||
logger.info("TaskList | Create new task request.");
|
||||
try {
|
||||
Task.TaskName taskName = new Task.TaskName(payload.getTaskName());
|
||||
Task.TaskType taskType = new Task.TaskType(payload.getTaskType());
|
||||
|
@ -76,9 +80,7 @@ public class AddNewTaskToTaskListWebController {
|
|||
HttpStatus.CREATED);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
} catch (ConstraintViolationException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
} catch (NullPointerException e) {
|
||||
} catch (ConstraintViolationException | NullPointerException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,30 +8,28 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
@RestController
|
||||
public class CompleteTaskWebController {
|
||||
private final CompleteTaskUseCase completeTaskUseCase;
|
||||
|
||||
Logger logger = Logger.getLogger(CompleteTaskWebController.class.getName());
|
||||
|
||||
public CompleteTaskWebController(CompleteTaskUseCase completeTaskUseCase){
|
||||
this.completeTaskUseCase = completeTaskUseCase;
|
||||
}
|
||||
|
||||
@PostMapping(path = "/tasks/completeTask")
|
||||
public ResponseEntity<String> completeTask (@RequestBody TaskJsonRepresentation payload) {
|
||||
|
||||
System.out.println("completeTask");
|
||||
System.out.println(payload.getTaskId());
|
||||
|
||||
logger.info("TaskList | Complete task request.");
|
||||
|
||||
try {
|
||||
CompleteTaskCommand command = new CompleteTaskCommand(
|
||||
|
@ -43,6 +41,7 @@ public class CompleteTaskWebController {
|
|||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskJsonRepresentation.MEDIA_TYPE);
|
||||
|
||||
logger.info("TaskList | Task completed successfuly");
|
||||
return new ResponseEntity<>(TaskJsonRepresentation.serialize(updateATask), responseHeaders, HttpStatus.ACCEPTED);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Controller that handles HTTP GET requests for retrieving tasks. This controller implements the
|
||||
|
@ -22,6 +23,8 @@ import java.util.Optional;
|
|||
public class RetrieveTaskFromTaskListWebController {
|
||||
private final RetrieveTaskFromTaskListUseCase retrieveTaskFromTaskListUseCase;
|
||||
|
||||
Logger logger = Logger.getLogger(RetrieveTaskFromTaskListWebController.class.getName());
|
||||
|
||||
public RetrieveTaskFromTaskListWebController(RetrieveTaskFromTaskListUseCase retrieveTaskFromTaskListUseCase) {
|
||||
this.retrieveTaskFromTaskListUseCase = retrieveTaskFromTaskListUseCase;
|
||||
}
|
||||
|
@ -35,6 +38,7 @@ public class RetrieveTaskFromTaskListWebController {
|
|||
*/
|
||||
@GetMapping(path = "/tasks/{taskId}")
|
||||
public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskId") String taskId) {
|
||||
logger.info("TaskList | Retrieving task with id: " + taskId);
|
||||
RetrieveTaskFromTaskListQuery query = new RetrieveTaskFromTaskListQuery(new Task.TaskId(taskId));
|
||||
Optional<Task> updatedTaskOpt = retrieveTaskFromTaskListUseCase.retrieveTaskFromTaskList(query);
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ public class TaskPersistenceAdapter implements
|
|||
@Override
|
||||
public Task loadTask(Task.TaskId taskId, TaskList.TaskListName taskListName) {
|
||||
MongoTaskDocument mongoTaskDocument = taskRepository.findByTaskId(taskId.getValue(),taskListName.getValue());
|
||||
Task task = taskMapper.mapToDomainEntity(mongoTaskDocument);
|
||||
return task;
|
||||
return taskMapper.mapToDomainEntity(mongoTaskDocument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package ch.unisg.tapastasks.tasks.adapter.out.web;
|
|||
|
||||
import ch.unisg.tapastasks.tasks.application.port.out.CanTaskBeDeletedPort;
|
||||
import ch.unisg.tapastasks.tasks.domain.DeleteTaskEvent;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
@ -16,21 +14,23 @@ import java.net.URI;
|
|||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class CanTaskBeDeletedWebAdapter implements CanTaskBeDeletedPort {
|
||||
|
||||
Logger logger = Logger.getLogger(CanTaskBeDeletedWebAdapter.class.getName());
|
||||
|
||||
@Value("${roster.uri}")
|
||||
String server;
|
||||
|
||||
@Override
|
||||
public boolean canTaskBeDeletedEvent(DeleteTaskEvent event){
|
||||
//Todo: Question: How do we include the URI from the DeleteTaskEvent? Do we even need it?
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server+"$/task/" + event.taskId))
|
||||
.uri(URI.create(server + "/task/" + event.taskId))
|
||||
.header("Content-Type", "application/task+json")
|
||||
.DELETE()
|
||||
.build();
|
||||
|
@ -39,9 +39,10 @@ public class CanTaskBeDeletedWebAdapter implements CanTaskBeDeletedPort {
|
|||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response.statusCode() == HttpStatus.OK.value();
|
||||
} catch (IOException e){
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -8,9 +8,6 @@ import java.net.http.HttpResponse;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.github.fge.jsonpatch.JsonPatch;
|
||||
import com.github.fge.jsonpatch.JsonPatchOperation;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -33,6 +30,8 @@ public class ExternalTaskExecutedWebAdapter implements ExternalTaskExecutedEvent
|
|||
@Override
|
||||
public void handleEvent(ExternalTaskExecutedEvent externalTaskExecutedEvent) {
|
||||
|
||||
logger.info("TaskList | Notify external task-list about task execution.");
|
||||
|
||||
JSONObject op1;
|
||||
JSONObject op2;
|
||||
try {
|
||||
|
|
|
@ -15,24 +15,30 @@ import java.net.http.HttpClient;
|
|||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort {
|
||||
|
||||
Logger logger = Logger.getLogger(PublishNewTaskAddedEventWebAdapter.class.getName());
|
||||
|
||||
@Value("${roster.uri}")
|
||||
String server;
|
||||
|
||||
@Value("${baseuri}")
|
||||
String baseuri;
|
||||
|
||||
@Override
|
||||
public void publishNewTaskAddedEvent(NewTaskAddedEvent event) {
|
||||
|
||||
// Here we would need to work with DTOs in case the payload of calls becomes more complex
|
||||
|
||||
var values = new HashMap<String, String>() {{
|
||||
put("taskID", event.taskId);
|
||||
put("taskType", event.taskType);
|
||||
put("inputData", event.inputData);
|
||||
}};
|
||||
var values = new HashMap<String, String>();
|
||||
values.put("taskID", event.taskId);
|
||||
values.put("taskType", event.taskType);
|
||||
values.put("inputData", event.inputData);
|
||||
|
||||
var objectMapper = new ObjectMapper();
|
||||
String requestBody = null;
|
||||
|
@ -46,15 +52,17 @@ public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort
|
|||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server+"/task"))
|
||||
.header("Content-Type", "application/task+json")
|
||||
.header("Link", "<" + baseuri + "tasks/" + event.taskId + ">; rel=\"task\"")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,13 @@ package ch.unisg.tapastasks.tasks.application.port.in;
|
|||
import ch.unisg.tapastasks.common.SelfValidating;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task.OutputData;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task.TaskId;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task.TaskResult;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Value
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class CompleteTaskCommand extends SelfValidating<CompleteTaskCommand> {
|
||||
@NotNull
|
||||
private final TaskId taskId;
|
||||
|
|
|
@ -3,11 +3,13 @@ package ch.unisg.tapastasks.tasks.application.port.in;
|
|||
import ch.unisg.tapastasks.common.SelfValidating;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task.TaskId;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task.OriginalTaskUri;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Value
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class DeleteTaskCommand extends SelfValidating<DeleteTaskCommand> {
|
||||
@NotNull
|
||||
private final TaskId taskId;
|
||||
|
|
|
@ -25,14 +25,11 @@ public class AddNewTaskToTaskListService implements AddNewTaskToTaskListUseCase
|
|||
|
||||
private final NewTaskAddedEventPort newTaskAddedEventPort;
|
||||
private final AddTaskPort addTaskToRepositoryPort;
|
||||
private final TaskListLock taskListLock;
|
||||
|
||||
@Override
|
||||
public Task addNewTaskToTaskList(AddNewTaskToTaskListCommand command) {
|
||||
TaskList taskList = TaskList.getTapasTaskList();
|
||||
|
||||
// taskListLock.lockTaskList(taskList.getTaskListName());
|
||||
|
||||
Task newTask;
|
||||
|
||||
if (command.getOriginalTaskUri().isPresent() && command.getInputData().isPresent()) {
|
||||
|
@ -49,7 +46,6 @@ public class AddNewTaskToTaskListService implements AddNewTaskToTaskListUseCase
|
|||
}
|
||||
|
||||
addTaskToRepositoryPort.addTask(newTask);
|
||||
// taskListLock.releaseTaskList(taskList.getTaskListName());
|
||||
|
||||
//Here we are using the application service to emit the domain event to the outside of the bounded context.
|
||||
//This event should be considered as a light-weight "integration event" to communicate with other services.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
server.port=8081
|
||||
spring.data.mongodb.uri=mongodb://root:password@localhost:27017/
|
||||
spring.data.mongodb.database=tapas-tasks
|
||||
# baseuri=http://e021-77-59-152-182.ngrok.io/
|
||||
baseuri=https://tapas-tasks.86-119-34-23.nip.io/
|
||||
|
||||
roster.uri=http://127.0.0.1:8082
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AddNewTaskToTaskListServiceTest {
|
|||
private final TaskListLock taskListLock = Mockito.mock(TaskListLock.class);
|
||||
private final NewTaskAddedEventPort newTaskAddedEventPort = Mockito.mock(NewTaskAddedEventPort.class);
|
||||
private final AddNewTaskToTaskListService addNewTaskToTaskListService = new AddNewTaskToTaskListService(
|
||||
newTaskAddedEventPort, addTaskPort, taskListLock);
|
||||
newTaskAddedEventPort, addTaskPort);
|
||||
|
||||
@Test
|
||||
void addingSucceeds() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user