[PlacementGroup]Add PlacementGroup wait java api (#12499)

* add part code

* add part code

* add part code

* add part code

* fix review comments

* fix compile bug

* fix compile bug

* fix review comments

* fix review comments

* fix code style

* add part code

* fix review comments

* fix review comments

* fix code style

* rebase master

* fix bug

* fix lint error

* fix compile bug

* fix newline issue

Co-authored-by: 灵洵 <fengbin.ffb@antgroup.com>
This commit is contained in:
fangfengbin
2020-12-05 16:40:04 +08:00
committed by GitHub
parent 1c0d10f67e
commit 260b07cf0c
26 changed files with 242 additions and 14 deletions
@@ -221,4 +221,12 @@ public interface RayRuntime {
* @param id Id of the placement group.
*/
void removePlacementGroup(PlacementGroupId id);
/**
* Wait for the placement group to be ready within the specified time.
* @param id Id of placement group.
* @param timeoutMs Timeout in milliseconds.
* @return True if the placement group is created. False otherwise.
*/
boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutMs);
}
@@ -200,6 +200,11 @@ public abstract class AbstractRayRuntime implements RayRuntimeInternal {
return gcsClient.getAllPlacementGroupInfo();
}
@Override
public boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutMs) {
return taskSubmitter.waitPlacementGroupReady(id, timeoutMs);
}
@SuppressWarnings("unchecked")
@Override
public <T extends BaseActorHandle> T getActorHandle(ActorId actorId) {
@@ -82,8 +82,7 @@ public class GlobalStateAccessor {
public byte[] getPlacementGroupInfo(PlacementGroupId placementGroupId) {
synchronized (GlobalStateAccessor.class) {
Preconditions.checkNotNull(placementGroupId,
"PlacementGroupId can't be null when get placement group info.");
validateGlobalStateAccessorPointer();
return nativeGetPlacementGroupInfo(globalStateAccessorNativePointer,
placementGroupId.getBytes());
}
@@ -1,5 +1,6 @@
package io.ray.runtime.placementgroup;
import io.ray.api.Ray;
import io.ray.api.id.PlacementGroupId;
import io.ray.api.placementgroup.PlacementGroup;
import io.ray.api.placementgroup.PlacementGroupState;
@@ -49,6 +50,15 @@ public class PlacementGroupImpl implements PlacementGroup {
return state;
}
/**
* Wait for the placement group to be ready within the specified time.
* @param timeoutMs Timeout in milliseconds.
* @return True if the placement group is created. False otherwise.
*/
public boolean wait(int timeoutMs) {
return Ray.internal().waitPlacementGroupReady(id, timeoutMs);
}
/**
* A help class for create the placement group.
*/
@@ -240,6 +240,11 @@ public class LocalModeTaskSubmitter implements TaskSubmitter {
placementGroups.remove(id);
}
@Override
public boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutMs) {
return true;
}
@Override
public BaseActorHandle getActor(ActorId actorId) {
return actorHandles.get(actorId).copy();
@@ -91,6 +91,11 @@ public class NativeTaskSubmitter implements TaskSubmitter {
nativeRemovePlacementGroup(id.getBytes());
}
@Override
public boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutMs) {
return nativeWaitPlacementGroupReady(id.getBytes(), timeoutMs);
}
private static native List<byte[]> nativeSubmitTask(FunctionDescriptor functionDescriptor,
int functionDescriptorHash, List<FunctionArg> args, int numReturns, CallOptions callOptions);
@@ -107,4 +112,6 @@ public class NativeTaskSubmitter implements TaskSubmitter {
private static native void nativeRemovePlacementGroup(byte[] placementGroupId);
private static native boolean nativeWaitPlacementGroupReady(byte[] placementGroupId,
int timeoutMs);
}
@@ -68,6 +68,14 @@ public interface TaskSubmitter {
*/
void removePlacementGroup(PlacementGroupId id);
/**
* Wait for the placement group to be ready within the specified time.
* @param id Id of placement group.
* @param timeoutMs Timeout in milliseconds.
* @return True if the placement group is created. False otherwise.
*/
boolean waitPlacementGroupReady(PlacementGroupId id, int timeoutMs);
BaseActorHandle getActor(ActorId actorId);
}
@@ -31,8 +31,10 @@ public class PlacementGroupTest extends BaseTest {
// This test just creates a placement group with one bundle.
// It's not comprehensive to test all placement group test cases.
public void testCreateAndCallActor() {
PlacementGroup placementGroup = PlacementGroupTestUtils.createSimpleGroup();
Assert.assertEquals(((PlacementGroupImpl)placementGroup).getName(),"unnamed_group");
PlacementGroupImpl placementGroup = (PlacementGroupImpl)PlacementGroupTestUtils
.createSimpleGroup();
Assert.assertTrue(placementGroup.wait(10000));
Assert.assertEquals(placementGroup.getName(),"unnamed_group");
// Test creating an actor from a constructor.
ActorHandle<Counter> actor = Ray.actor(Counter::new, 1)
@@ -52,6 +54,8 @@ public class PlacementGroupTest extends BaseTest {
PlacementGroupImpl secondPlacementGroup = (PlacementGroupImpl)PlacementGroupTestUtils
.createNameSpecifiedSimpleGroup("CPU", 1, PlacementStrategy.PACK,
1.0, "second_placement_group");
Assert.assertTrue(firstPlacementGroup.wait(10000));
Assert.assertTrue(secondPlacementGroup.wait(10000));
PlacementGroupImpl firstPlacementGroupRes =
(PlacementGroupImpl)Ray.getPlacementGroup((firstPlacementGroup).getId());