diff --git a/pom.xml b/pom.xml
index 259f7ca..9511cc6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.camunda.community
zeebe-cherry-framework
- 2.1.0
+ 2.2.0
17
diff --git a/src/main/java/io/camunda/cherry/admin/RunnerRestController.java b/src/main/java/io/camunda/cherry/admin/RunnerRestController.java
index 3563bcc..1ae4075 100644
--- a/src/main/java/io/camunda/cherry/admin/RunnerRestController.java
+++ b/src/main/java/io/camunda/cherry/admin/RunnerRestController.java
@@ -16,20 +16,21 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.Resource;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import java.io.IOException;
-import java.nio.charset.Charset;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -38,237 +39,260 @@
@RequestMapping("cherry")
public class RunnerRestController {
-
- Logger logger = LoggerFactory.getLogger(RunnerRestController.class.getName());
- @Autowired
- CherryJobRunnerFactory cherryJobRunnerFactory;
-
- @Autowired
- CherryHistoricFactory cherryHistoricFactory;
-
- /**
- * Spring populate the list of all workers
- */
- @Autowired
- private List listRunners;
-
- /**
- * Spring populate this list with runner marked at Framework
- */
- @Autowired
- private List listFrameworkRunners;
-
-
- /**
- * Get list of worker. Multiple result is possibles
- * /api/runner/list?logo=true&stats=true&delaysstatsinhour=24
- *
- * @param logo if true, logo is returned
- * @param stats if true, execution on statistics is returned
- * @param delayStatsInHours give the delay in hour to collect data
- * @return
- */
- @GetMapping(value = "/api/runner/list", produces = "application/json")
- public List getWorkersList(@RequestParam(name = "logo", required = false) Boolean logo,
- @RequestParam(name = "stats", required = false) Boolean stats,
- @RequestParam(name = "delaystatsinhours", required = false) Integer delayStatsInHours) {
-
- return listRunners.stream()
- .map(RunnerInformation::getRunnerInformation)
- .map(w -> {
- return this.completeRunnerInformation(w,
- logo == null || logo,
- stats == null ? false : stats,
- delayStatsInHours == null ? Integer.valueOf(24) : delayStatsInHours);
- })
- .toList();
+ Logger logger = LoggerFactory.getLogger(RunnerRestController.class.getName());
+ @Autowired
+ CherryJobRunnerFactory cherryJobRunnerFactory;
+
+ @Autowired
+ CherryHistoricFactory cherryHistoricFactory;
+
+ /**
+ * Spring populate the list of all workers
+ */
+ @Autowired
+ private List listRunners;
+
+ /**
+ * Spring populate this list with runner marked at Framework
+ */
+ @Autowired
+ private List listFrameworkRunners;
+
+ /**
+ * Get list of worker. Multiple result is possibles
+ * /api/runner/list?logo=true&stats=true&delaysstatsinhour=24
+ *
+ * @param logo if true, logo is returned
+ * @param stats if true, execution on statistics is returned
+ * @param delayStatsInHours give the delay in hour to collect data
+ * @return a list of information on runner
+ */
+ @GetMapping(value = "/api/runner/list", produces = "application/json")
+ public List getWorkersList(@RequestParam(name = "logo", required = false) Boolean logo,
+ @RequestParam(name = "stats", required = false) Boolean stats,
+ @RequestParam(name = "delaystatsinhours", required = false) Integer delayStatsInHours) {
+
+ return listRunners.stream().map(RunnerInformation::getRunnerInformation).map(w -> {
+ return this.completeRunnerInformation(w, logo == null || logo, stats == null ? false : stats,
+ delayStatsInHours == null ? Integer.valueOf(24) : delayStatsInHours);
+ }).toList();
+ }
+
+ @GetMapping(value = "/api/runner/detail", produces = "application/json")
+ public Optional getWorker(@RequestParam(name = "name") String runnerName,
+ @RequestParam(name = "logo", required = false) Boolean logo,
+ @RequestParam(name = "stats", required = false) Boolean stats,
+ @RequestParam(name = "delaystatsinhours", required = false) Integer delayStatsInHours) {
+ return listRunners.stream()
+ .filter(worker -> worker.getIdentification().equals(runnerName))
+ .map(RunnerInformation::getRunnerInformation)
+ .map(w -> this.completeRunnerInformation(w, logo == null || logo, stats == null ? false : stats,
+ delayStatsInHours))
+ .findFirst();
+ }
+
+ /**
+ * Ask to stop a specific worker
+ *
+ * @param runnerName worker to stop
+ * @return NOTFOUND or the worker information on this worker
+ */
+ @PutMapping(value = "/api/runner/stop", produces = "application/json")
+ public RunnerInformation stopWorker(@RequestParam(name = "name") String runnerName) {
+ logger.info("Stop requested for [" + runnerName + "]");
+ try {
+ boolean isStopped = cherryJobRunnerFactory.stopRunner(runnerName);
+ logger.info("Stop executed for [" + runnerName + "]: " + isStopped);
+ AbstractRunner runner = getRunnerByName(runnerName);
+ RunnerInformation runnerInfo = RunnerInformation.getRunnerInformation(runner);
+ return completeRunnerInformation(runnerInfo, false, false, null);
+ } catch (CherryJobRunnerFactory.OperationException e) {
+ if (CherryJobRunnerFactory.RUNNER_NOT_FOUND.equals(e.getExceptionCode()))
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, "WorkerName [" + runnerName + "] not found");
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "WorkerName [" + runnerName + "] error " + e);
}
-
- @GetMapping(value = "/api/runner/detail", produces = "application/json")
- public Optional getWorker(@RequestParam(name = "name") String runnerName,
- @RequestParam(name = "logo", required = false) Boolean logo,
- @RequestParam(name = "stats", required = false) Boolean stats,
- @RequestParam(name = "delaystatsinhours", required = false) Integer delayStatsInHours) {
- return listRunners.stream()
- .filter(worker -> worker.getIdentification().equals(runnerName))
- .map(RunnerInformation::getRunnerInformation)
- .map(w -> this.completeRunnerInformation(w,
- logo == null || logo,
- stats == null ? false : stats,
- delayStatsInHours)
- )
- .findFirst();
- }
-
- /**
- * Ask to stop a specific worker
- *
- * @param runnerName worker to stop
- * @return NOTFOUND or the worker information on this worker
- */
- @PutMapping(value = "/api/runner/stop", produces = "application/json")
- public RunnerInformation stopWorker(@RequestParam(name = "name") String runnerName) {
- logger.info("Stop requested for [" + runnerName + "]");
- try {
- boolean isStopped = cherryJobRunnerFactory.stopRunner(runnerName);
- logger.info("Stop executed for [" + runnerName + "]: " + isStopped);
- AbstractRunner runner = getRunnerByName(runnerName);
- RunnerInformation runnerInfo = RunnerInformation.getRunnerInformation(runner);
- return completeRunnerInformation(runnerInfo, false, false, null);
- } catch (CherryJobRunnerFactory.OperationException e) {
- if (CherryJobRunnerFactory.RUNNER_NOT_FOUND.equals(e.getExceptionCode()))
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "WorkerName [" + runnerName + "] not found");
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "WorkerName [" + runnerName + "] error " + e);
- }
+ }
+
+ /**
+ * Ask to start a specific worker
+ *
+ * @param runnerName worker to start
+ * @return NOTFOUND or the worker information on this worker
+ */
+ @PutMapping(value = "/api/runner/start", produces = "application/json")
+ public RunnerInformation startWorker(@RequestParam(name = "name") String runnerName) {
+ logger.info("Start requested for [" + runnerName + "]");
+ try {
+ boolean isStarted = cherryJobRunnerFactory.startRunner(runnerName);
+ logger.info("Start executed for [" + runnerName + "]: " + isStarted);
+ AbstractRunner runner = getRunnerByName(runnerName);
+ RunnerInformation runnerInfo = RunnerInformation.getRunnerInformation(runner);
+ return completeRunnerInformation(runnerInfo, false, false, null);
+ } catch (CherryJobRunnerFactory.OperationException e) {
+ if (CherryJobRunnerFactory.RUNNER_NOT_FOUND.equals(e.getExceptionCode()))
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, "WorkerName [" + runnerName + "] not found");
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "WorkerName [" + runnerName + "] error " + e);
}
-
- /**
- * Ask to start a specific worker
- *
- * @param runnerName worker to start
- * @return NOTFOUND or the worker information on this worker
- */
- @PutMapping(value = "/api/runner/start", produces = "application/json")
- public RunnerInformation startWorker(@RequestParam(name = "name") String runnerName) {
- logger.info("Start requested for [" + runnerName + "]");
- try {
- boolean isStarted = cherryJobRunnerFactory.startRunner(runnerName);
- logger.info("Start executed for [" + runnerName + "]: " + isStarted);
- AbstractRunner runner = getRunnerByName(runnerName);
- RunnerInformation runnerInfo = RunnerInformation.getRunnerInformation(runner);
- return completeRunnerInformation(runnerInfo, false, false, null);
- } catch (CherryJobRunnerFactory.OperationException e) {
- if (CherryJobRunnerFactory.RUNNER_NOT_FOUND.equals(e.getExceptionCode()))
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "WorkerName [" + runnerName + "] not found");
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "WorkerName [" + runnerName + "] error " + e);
- }
+ }
+
+ /**
+ * Download the Template for a runner
+ *
+ * @param runnerName worker to start. If not present, all runners are part of the result
+ * @param withFrameworkRunners if true, then runners from the framework are included. In general we don't want, else these runners will be present in each collection, and Modeler will throw a duplicate errors
+ * @return NOTFOUND or the worker information on this worker
+ */
+ @GetMapping(value = "/api/runner/template", produces = "application/json")
+ public String getTemplate(@RequestParam(name = "name", required = false) String runnerName,
+ @RequestParam(name = "withframeworkrunners", required = false) Boolean withFrameworkRunners) {
+ boolean withFrameworkRunnersIncluded = (withFrameworkRunners != null && withFrameworkRunners);
+ logger.info(
+ "Download template requested for " + (runnerName == null ? "Complete collection" : "[" + runnerName + "]")
+ + " FrameworkIncluded[" + withFrameworkRunnersIncluded + "]");
+ if (runnerName == null) {
+ // generate for ALL runners
+ List