[JavaWorker] Java code lint check and binding to CI (#2225)

* add java code lint check and fix the java code lint error

* add java doc lint check and fix the java doc lint error

* add java code and doc lint to the CI
This commit is contained in:
Yujie Liu
2018-06-10 07:26:54 +08:00
committed by Philipp Moritz
parent 5789a247f9
commit 3b5e700fd7
158 changed files with 3805 additions and 3325 deletions
+44 -44
View File
@@ -1,54 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.ray.parent</groupId>
<artifactId>ray-superpom</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.ray</groupId>
<artifactId>ray-runtime-dev</artifactId>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.ray.parent</groupId>
<artifactId>ray-superpom</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.ray</groupId>
<artifactId>ray-runtime-dev</artifactId>
<name>runtime-dev</name>
<description>runtime for app development</description>
<url></url>
<name>runtime-dev</name>
<description>runtime for app development</description>
<url></url>
<packaging>jar</packaging>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.ray</groupId>
<artifactId>ray-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.ray</groupId>
<artifactId>ray-runtime-common</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>2.47</version>
</dependency>
<dependencies>
<dependency>
<groupId>org.ray</groupId>
<artifactId>ray-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.ray</groupId>
<artifactId>ray-runtime-common</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>2.47</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.davidmoten/flatbuffers-java -->
<dependency>
<groupId>com.github.davidmoten</groupId>
<artifactId>flatbuffers-java</artifactId>
<version>1.7.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.davidmoten/flatbuffers-java -->
<dependency>
<groupId>com.github.davidmoten</groupId>
<artifactId>flatbuffers-java</artifactId>
<version>1.7.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
</project>
@@ -21,21 +21,11 @@ import org.ray.util.logger.RayLog;
public class RayDevRuntime extends RayRuntime {
private final ConcurrentHashMap<UniqueID, Object> actors = new ConcurrentHashMap<>();
protected RayDevRuntime() {
}
@Override
public void start(RayParameters params) {
PathConfig pathConfig = new PathConfig(configReader);
RemoteFunctionManager rfm = new NopRemoteFunctionManager(params.driver_id);
MockObjectStore store = new MockObjectStore();
MockLocalScheduler scheduler = new MockLocalScheduler(store);
init(scheduler, store, rfm, pathConfig);
scheduler.setLocalFunctionManager(this.functions);
}
private final ConcurrentHashMap<UniqueID, Object> actors = new ConcurrentHashMap<>();
@RayRemote
private static byte[] createActor(String className) {
return ((RayDevRuntime) RayRuntime.getInstance()).createLocalActor(className);
@@ -56,7 +46,9 @@ public class RayDevRuntime extends RayRuntime {
actors.put(actorId, r);
RayLog.core.info("TaskId " + taskId + ", create actor ok " + actorId);
return actorId.getBytes();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
String logInfo =
@@ -69,8 +61,18 @@ public class RayDevRuntime extends RayRuntime {
}
@Override
public <T> RayActor<T> create(Class<T> cls) {
return new RayActor<>(Ray.call(RayDevRuntime::createActor, cls.getName()).getId());
public void start(RayParameters params) {
PathConfig pathConfig = new PathConfig(configReader);
RemoteFunctionManager rfm = new NopRemoteFunctionManager(params.driver_id);
MockObjectStore store = new MockObjectStore();
MockLocalScheduler scheduler = new MockLocalScheduler(store);
init(scheduler, store, rfm, pathConfig);
scheduler.setLocalFunctionManager(this.functions);
}
@Override
public void cleanUp() {
// nothing to do
}
@Override
@@ -79,7 +81,7 @@ public class RayDevRuntime extends RayRuntime {
}
@Override
public void cleanUp() {
// nothing to do
public <T> RayActor<T> create(Class<T> cls) {
return new RayActor<>(Ray.call(RayDevRuntime::createActor, cls.getName()).getId());
}
}
@@ -15,34 +15,46 @@ import org.ray.spi.model.TaskSpec;
*/
public class MockLocalScheduler implements LocalSchedulerLink {
private final Map<UniqueID, Map<UniqueID, TaskSpec>> waitTasks_ = new ConcurrentHashMap<>();
private final MockObjectStore store_;
private LocalFunctionManager functions_ = null;
private final Map<UniqueID, Map<UniqueID, TaskSpec>> waitTasks = new ConcurrentHashMap<>();
private final MockObjectStore store;
private LocalFunctionManager functions = null;
public MockLocalScheduler(MockObjectStore store) {
store_ = store;
this.store = store;
store.registerScheduler(this);
}
public void setLocalFunctionManager(LocalFunctionManager mgr) {
functions_ = mgr;
functions = mgr;
}
public void onObjectPut(UniqueID id) {
Map<UniqueID, TaskSpec> bucket = waitTasks_.get(id);
Map<UniqueID, TaskSpec> bucket = waitTasks.get(id);
if (bucket != null) {
waitTasks_.remove(id);
waitTasks.remove(id);
for (TaskSpec ts : bucket.values()) {
submitTask(ts);
}
}
}
@Override
public void submitTask(TaskSpec task) {
UniqueID id = isTaskReady(task);
if (id == null) {
Worker.execute(task, functions);
} else {
Map<UniqueID, TaskSpec> bucket = waitTasks
.computeIfAbsent(id, id_ -> new ConcurrentHashMap<>());
bucket.put(id, task);
}
}
private UniqueID isTaskReady(TaskSpec spec) {
for (FunctionArg arg : spec.args) {
if (arg.ids != null) {
for (UniqueID id : arg.ids) {
if (!store_.isObjectReady(id)) {
if (!store.isObjectReady(id)) {
return id;
}
}
@@ -51,18 +63,6 @@ public class MockLocalScheduler implements LocalSchedulerLink {
return null;
}
@Override
public void submitTask(TaskSpec task) {
UniqueID id = isTaskReady(task);
if (id == null) {
Worker.execute(task, functions_);
} else {
Map<UniqueID, TaskSpec> bucket = waitTasks_
.computeIfAbsent(id, id_ -> new ConcurrentHashMap<>());
bucket.put(id, task);
}
}
@Override
public TaskSpec getTaskTodo() {
throw new RuntimeException("invalid execution flow here");
@@ -5,7 +5,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.arrow.plasma.ObjectStoreLink;
import org.ray.api.UniqueID;
import org.ray.core.WorkerContext;
@@ -16,9 +15,9 @@ import org.ray.util.logger.RayLog;
*/
public class MockObjectStore implements ObjectStoreLink {
private final Map<UniqueID, byte[]> data_ = new ConcurrentHashMap<>();
private final Map<UniqueID, byte[]> metadata_ = new ConcurrentHashMap<>();
private MockLocalScheduler scheduler_ = null;
private final Map<UniqueID, byte[]> data = new ConcurrentHashMap<>();
private final Map<UniqueID, byte[]> metadata = new ConcurrentHashMap<>();
private MockLocalScheduler scheduler = null;
@Override
public void put(byte[] objectId, byte[] value, byte[] metadataValue) {
@@ -27,47 +26,33 @@ public class MockObjectStore implements ObjectStoreLink {
.error(logPrefix() + "cannot put null: " + objectId + "," + Arrays.toString(value));
System.exit(-1);
}
UniqueID uniqueID = new UniqueID(objectId);
data_.put(uniqueID, value);
metadata_.put(uniqueID, metadataValue);
UniqueID uniqueId = new UniqueID(objectId);
data.put(uniqueId, value);
metadata.put(uniqueId, metadataValue);
if (scheduler_ != null) {
scheduler_.onObjectPut(uniqueID);
if (scheduler != null) {
scheduler.onObjectPut(uniqueId);
}
}
@Override
public List<byte[]> get(byte[][] objectIds, int timeoutMs, boolean isMetadata) {
final Map<UniqueID, byte[]> dataMap = isMetadata ? metadata_ : data_;
final Map<UniqueID, byte[]> dataMap = isMetadata ? metadata : data;
ArrayList<byte[]> rets = new ArrayList<>(objectIds.length);
for (byte[] objId : objectIds) {
UniqueID uniqueID = new UniqueID(objId);
RayLog.core.info(logPrefix() + " is notified for objectid " + uniqueID);
rets.add(dataMap.get(uniqueID));
UniqueID uniqueId = new UniqueID(objId);
RayLog.core.info(logPrefix() + " is notified for objectid " + uniqueId);
rets.add(dataMap.get(uniqueId));
}
return rets;
}
private String logPrefix() {
return WorkerContext.currentTask().taskId + "-" + getUserTrace() + " -> ";
}
private String getUserTrace() {
StackTraceElement stes[] = Thread.currentThread().getStackTrace();
int k = 1;
while (stes[k].getClassName().startsWith("org.ray")
&& !stes[k].getClassName().contains("test")) {
k++;
}
return stes[k].getFileName() + ":" + stes[k].getLineNumber();
}
@Override
public List<byte[]> wait(byte[][] objectIds, int timeoutMs, int numReturns) {
ArrayList<byte[]> rets = new ArrayList<>();
for (byte[] objId : objectIds) {
//tod test
if (data_.containsKey(new UniqueID(objId))) {
if (data.containsKey(new UniqueID(objId))) {
rets.add(objId);
}
}
@@ -89,14 +74,6 @@ public class MockObjectStore implements ObjectStoreLink {
return 0;
}
public boolean isObjectReady(UniqueID id) {
return data_.containsKey(id);
}
public void registerScheduler(MockLocalScheduler s) {
scheduler_ = s;
}
@Override
public void release(byte[] objectId) {
return;
@@ -105,6 +82,28 @@ public class MockObjectStore implements ObjectStoreLink {
@Override
public boolean contains(byte[] objectId) {
return data_.containsKey(new UniqueID(objectId));
return data.containsKey(new UniqueID(objectId));
}
private String logPrefix() {
return WorkerContext.currentTask().taskId + "-" + getUserTrace() + " -> ";
}
private String getUserTrace() {
StackTraceElement[] stes = Thread.currentThread().getStackTrace();
int k = 1;
while (stes[k].getClassName().startsWith("org.ray")
&& !stes[k].getClassName().contains("test")) {
k++;
}
return stes[k].getFileName() + ":" + stes[k].getLineNumber();
}
public boolean isObjectReady(UniqueID id) {
return data.containsKey(id);
}
public void registerScheduler(MockLocalScheduler s) {
scheduler = s;
}
}