Skip to content

Commit 545c712

Browse files
committed
Update java executor and make package
1 parent e702aa8 commit 545c712

File tree

11 files changed

+158
-32
lines changed

11 files changed

+158
-32
lines changed

Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ MAINTAINER ProcessMaker Inc.
44

55
COPY /src /opt/executor
66

7-
WORKDIR /opt/executor/spark-sdk-java
7+
WORKDIR /opt/executor
8+
9+
# https://superuser.com/questions/1423486
10+
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list
11+
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50
12+
RUN apt-get update && apt-get install -y git-core
13+
RUN if [ ! -d "sdk-java" ]; then git clone --depth 1 https://github.com/ProcessMaker/sdk-java.git; fi
14+
15+
WORKDIR /opt/executor/sdk-java
816

9-
RUN mvn package -DmyProperty=3.9.1
17+
RUN mvn clean install
1018

1119
WORKDIR /opt/executor

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# spark-docker-executor-java
1+
# docker-executor-java
22
Script Task Executor Engine with Java Runtime
33

4-
This docker image provides a sandboxed protected environment to run custom Java scripts that are written in ProcessMaker Spark.
4+
This docker image provides a sandboxed protected environment to run custom Java scripts that are written in ProcessMaker 4.
55

66
## How to use
77
The execution requires a data.json, config.json and an output.json file be present on the host system. The data.json represents the
@@ -13,8 +13,9 @@ It is the responsibility of the caller to have these files prepared before execu
1313
### Install
1414

1515
```
16-
git clone https://github.com/ProcessMaker/spark-docker-executor-java.git
17-
./build.sh
16+
git clone https://github.com/ProcessMaker/docker-executor-java.git
17+
cd docker-executor-java
18+
docker build -t processmaker4/docker-executor-java .
1819
```
1920

2021
### Example data.json
@@ -54,8 +55,8 @@ public class Script implements BaseScript {
5455
```bash
5556
$ docker run -v <path to local data.json>:/opt/executor/data.json \
5657
-v <path to local config.json>:/opt/executor/config.json \
57-
-v <path to local script.Java>:/opt/executor/script.Java \
58+
-v <path to local Script.java>:/opt/executor/Script.java \
5859
-v <path to local output.json>:/opt/executor/output.json \
59-
processmaker/spark-docker-executor-java:dev-master \
60+
processmaker4/docker-executor-java \
6061
/opt/executor/run.sh
6162
```

build.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "processmaker/docker-executor-java",
3+
"friendly_name": "Java Docker Executor",
4+
"description": "Java script executor for processmaker 4",
5+
"version": "0.0.1",
6+
"minimum-stability": "dev",
7+
"autoload": {
8+
"psr-4": {
9+
"ProcessMaker\\Package\\DockerExecutorJava\\": "src",
10+
"ProcessMaker\\ScriptRunners\\": "src/ScriptRunners"
11+
}
12+
},
13+
"extra": {
14+
"laravel": {
15+
"providers": [
16+
"ProcessMaker\\Package\\DockerExecutorJava\\DockerExecutorJavaServiceProvider"
17+
]
18+
}
19+
}
20+
}

src/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
spark-sdk-java/
1+
sdk-java/
22

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
namespace ProcessMaker\Package\DockerExecutorJava;
3+
4+
use Illuminate\Support\Facades\Route;
5+
use Illuminate\Support\ServiceProvider;
6+
use ProcessMaker\Traits\PluginServiceProviderTrait;
7+
use ProcessMaker\Package\Packages\Events\PackageEvent;
8+
use ProcessMaker\Package\WebEntry\Listeners\PackageListener;
9+
10+
class DockerExecutorJavaServiceProvider extends ServiceProvider
11+
{
12+
use PluginServiceProviderTrait;
13+
14+
const version = '0.0.1'; // Required for PluginServiceProviderTrait
15+
16+
public function register()
17+
{
18+
}
19+
20+
/**
21+
* After all service provider's register methods have been called, your boot method
22+
* will be called. You can perform any initialization code that is dependent on
23+
* other service providers at this time. We've included some example behavior
24+
* to get you started.
25+
*
26+
* See: https://laravel.com/docs/5.6/providers#the-boot-method
27+
*/
28+
public function boot()
29+
{
30+
\Artisan::command('docker-executor-java:install', function () {
31+
// nothing to do here
32+
});
33+
34+
$config = [
35+
'name' => 'Java',
36+
'runner' => 'JavaRunner',
37+
'mime_type' => 'application/java',
38+
'image' => env('SCRIPTS_JAVA_IMAGE', 'processmaker4/executor-java'),
39+
'options' => ['invokerPackage' => "ProcessMaker_Client"]
40+
];
41+
config(['script-runners.java' => $config]);
42+
43+
$this->app['events']->listen(PackageEvent::class, PackageListener::class);
44+
45+
// Complete the plugin booting
46+
$this->completePluginBoot();
47+
}
48+
}

src/Listeners/PackageListener.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace ProcessMaker\Package\DockerExecutorJava\Listeners;
4+
5+
use Carbon\Carbon;
6+
use DateTime;
7+
use ProcessMaker\Package\Packages\Events\PackageEvent;
8+
9+
class PackageListener
10+
{
11+
/**
12+
* Gets the attributes from this package and add to event list
13+
* The attributes are read them from composer.json file for this package,
14+
* The especial attribute "expire_in" is getting from ioncube loader function with timezone of the ProcessMaker server
15+
* @param PackageEvent $event
16+
* @return mixed
17+
*/
18+
public function handle(PackageEvent $event){
19+
$composer = json_decode(file_get_contents(__DIR__ . '/../../composer.json'), true);
20+
$expires_on = null;
21+
if(in_array('ionCube Loader', get_loaded_extensions()) && ioncube_file_info())
22+
$expires_on = Carbon::createFromTimestamp(ioncube_file_info()['FILE_EXPIRY'], config('app.timezone'))->format(DateTime::ISO8601);
23+
24+
$infoPackage = [
25+
'name' => $composer['name'],
26+
'friendly_name' => isset($composer['friendly_name']) ? $composer['friendly_name'] : '',
27+
'description' => $composer['description'],
28+
'version' => $composer['version'],
29+
'expires_on' => $expires_on
30+
];
31+
$event->packages->push($infoPackage);
32+
return $event->packages->last();
33+
}
34+
}

src/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public class Main {
1111

1212
public static void main(String args[]) throws FileNotFoundException {
1313
Script script = new Script();
14-
Map<String, Object> data = Spark.data();
15-
Map<String, Object> config = Spark.config();
14+
Map<String, Object> data = ProcessMaker.data();
15+
Map<String, Object> config = ProcessMaker.config();
1616
Map<String, Object> output = new HashMap<String, Object>();
17-
ApiClient api = Spark.api();
17+
ApiClient api = ProcessMaker.api();
1818
script.execute(data, config, output, api);
19-
Spark.printOutput(output);
19+
ProcessMaker.printOutput(output);
2020
}
2121
}

src/Spark.java renamed to src/ProcessMaker.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.openapitools.client.api.UsersApi;
21
import ProcessMaker_Client.ApiClient;
32
import com.google.gson.Gson;
43
import java.io.*;
@@ -7,7 +6,7 @@
76
import java.util.Map;
87
import java.util.HashMap;
98

10-
public class Spark {
9+
public class ProcessMaker {
1110

1211
public static ApiClient api() {
1312
String baseApiUrl = System.getenv("API_HOST");
@@ -42,6 +41,14 @@ public static Map<String, Object> config() throws FileNotFoundException {
4241

4342
public static void printOutput(Map<String, Object> data) {
4443
String jsonString = new Gson().toJson(data);
45-
System.out.println(jsonString);
44+
45+
// System.out.println(jsonString);
46+
try {
47+
Writer fileWriter = new FileWriter("output.json", false);
48+
fileWriter.write(jsonString);
49+
fileWriter.close();
50+
} catch(Exception e) {
51+
System.out.println(e.getMessage());
52+
}
4653
}
4754
}

src/ScriptRunners/JavaRunner.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace ProcessMaker\ScriptRunners;
4+
5+
class JavaRunner extends Base
6+
{
7+
/**
8+
* Configure docker with java executor
9+
*
10+
* @param string $code
11+
* @param array $dockerConfig
12+
*
13+
* @return array
14+
*/
15+
public function config($code, array $dockerConfig)
16+
{
17+
$dockerConfig['image'] = config('script-runners.java.image');
18+
$dockerConfig['command'] = '/bin/sh /opt/executor/run.sh';
19+
$dockerConfig['inputs']['/opt/executor/Script.java'] = $code;
20+
return $dockerConfig;
21+
}
22+
}

0 commit comments

Comments
 (0)