Bootstrap
The detailed steps to bootstrap a custom worker follow.
Start a Java project with Spring Boot.
In your build file, declare a Maven dependency on "com.decisionbrain:optimserver-worker:4.4.0".
In the resources, create a worker.yml file, and declare tasks the worker will be able to perform. See the TaskParameter class in the page for a description of the fields. An example is given below.
tasks: - id: kcoloring implementationClassName: com.decisionbrain.kcoloringworker.KColoringTask description: This task computes a coloration of a partial Europe map with k colors. inputs: - name: k type: NUMERIC description: Number of colors to be used by the coloration. required: true outputs: - name: coloration type: JSON description: "The coloration found: for each country, the associated color."
In the resources, write an application.yml file with the following content. Set the relevant property values.
spring: application: name: MyCustomWorker rabbitmq: username: decisionbrain password: decisionbrain host: localhost port: 5672 optim-server: url: http://localhost:8080/
Write a Spring Boot application, with the EnableOptimServerWorker annotation, like this one:
@EnableOptimServerWorker @SpringBootApplication public class MyCustomWorker { public static void main(String[] args) { SpringApplication.run(MyCustomWorker.class, args); } }
Write a Java class for each declared task, and reference it in the worker.yml file. This class has to implement Interface com.decisionbrain.optimserver.worker.api.Task (see page. Here is the skeleton of such a class:
public class KColoringTask implements Task { private static final Logger LOGGER = LoggerFactory.getLogger(KColoringTask.class); @Override public void execute(Parameter input, Parameter output, ExecutionContext context) { // TODO: put your optimization code here } }
Now your worker is actually able to handle the declared tasks, it has to be packaged as a docker image to be deployable. First, a jar file should be built, using your favorite build tool (gradle for example). Then a docker image has to be built, using a Dockerfile, and the docker shell client, or any docker plugin for your build tool. Here is a typical Dockerfile:
FROM <YOUR_BASE_DOCKER_IMAGE_WITH_CPLEX> ADD build/libs/my-custom-worker.jar my-custom-worker.jar CMD java $JAVA_OPTS -jar my-custom-worker.jar $PROGRAM_ARGS
Then a docker image can be built using:
docker build .