[Java] Refactor java api (#8858)

This commit is contained in:
chaokunyang
2020-06-12 10:49:01 +08:00
committed by GitHub
parent cae475c46a
commit dfa4768fc6
64 changed files with 1854 additions and 3394 deletions
@@ -3,7 +3,6 @@ package io.ray.streaming.runtime.client;
import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.options.ActorCreationOptions;
import io.ray.streaming.client.JobClient;
import io.ray.streaming.jobgraph.JobGraph;
import io.ray.streaming.runtime.config.global.CommonConfig;
@@ -27,10 +26,6 @@ public class JobClientImpl implements JobClient {
LOG.info("Submitting job [{}] with job graph [{}] and job config [{}].",
jobGraph.getJobName(), jobGraph, jobConfig);
Map<String, Double> resources = new HashMap<>();
ActorCreationOptions options = new ActorCreationOptions.Builder()
.setResources(resources)
.setMaxRestarts(-1)
.createActorCreationOptions();
// set job name and id at start
jobConfig.put(CommonConfig.JOB_ID, Ray.getRuntimeContext().getCurrentJobId().toString());
@@ -39,11 +34,14 @@ public class JobClientImpl implements JobClient {
jobGraph.getJobConfig().putAll(jobConfig);
// create job master actor
this.jobMasterActor = Ray.createActor(JobMaster::new, jobConfig, options);
this.jobMasterActor = Ray.actor(JobMaster::new, jobConfig)
.setResources(resources)
.setMaxRestarts(-1)
.remote();
try {
ObjectRef<Boolean> submitResult = jobMasterActor.call(JobMaster::submitJob,
jobMasterActor, jobGraph);
ObjectRef<Boolean> submitResult = jobMasterActor.task(JobMaster::submitJob,
jobMasterActor, jobGraph).remote();
if (submitResult.get()) {
LOG.info("Finish submitting job: {}.", jobGraph.getJobName());
@@ -6,7 +6,6 @@ import io.ray.api.Ray;
import io.ray.api.WaitResult;
import io.ray.api.function.PyActorClass;
import io.ray.api.id.ActorId;
import io.ray.api.options.ActorCreationOptions;
import io.ray.streaming.api.Language;
import io.ray.streaming.runtime.core.graph.executiongraph.ExecutionGraph;
import io.ray.streaming.runtime.core.graph.executiongraph.ExecutionVertex;
@@ -46,17 +45,18 @@ public class WorkerLifecycleController {
Language language = executionVertex.getLanguage();
ActorCreationOptions options = new ActorCreationOptions.Builder()
.setResources(executionVertex.getResource())
.setMaxRestarts(-1)
.createActorCreationOptions();
BaseActorHandle actor;
if (Language.JAVA == language) {
actor = Ray.createActor(JobWorker::new, options);
actor = Ray.actor(JobWorker::new)
.setResources(executionVertex.getResource())
.setMaxRestarts(-1)
.remote();
} else {
actor = Ray.createActor(
new PyActorClass("ray.streaming.runtime.worker", "JobWorker"));
actor = Ray.actor(new PyActorClass(
"ray.streaming.runtime.worker", "JobWorker"))
.setResources(executionVertex.getResource())
.setMaxRestarts(-1)
.remote();
}
if (null == actor) {
@@ -32,11 +32,11 @@ public class RemoteCallWorker {
// python
if (actor instanceof PyActorHandle) {
result = ((PyActorHandle) actor).call(
new PyActorMethod("init", Object.class), context.getPythonWorkerContextBytes());
result = ((PyActorHandle) actor).task(new PyActorMethod("init", Object.class),
context.getPythonWorkerContextBytes()).remote();
} else {
// java
result = ((ActorHandle<JobWorker>) actor).call(JobWorker::init, context);
result = ((ActorHandle<JobWorker>) actor).task(JobWorker::init, context).remote();
}
LOG.info("Finished calling worker to initiate.");
@@ -55,10 +55,11 @@ public class RemoteCallWorker {
// python
if (actor instanceof PyActorHandle) {
result = ((PyActorHandle) actor).call(new PyActorMethod("start", Object.class));
result = ((PyActorHandle) actor)
.task(new PyActorMethod("start", Object.class)).remote();
} else {
// java
result = ((ActorHandle<JobWorker>) actor).call(JobWorker::start);
result = ((ActorHandle<JobWorker>) actor).task(JobWorker::start).remote();
}
LOG.info("Finished calling worker to start.");