forked from apache/incubator-uniffle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#768] feat(cli): Cli method for blacklist update
- Loading branch information
Showing
16 changed files
with
293 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
cli/src/main/java/org/apache/uniffle/api/CoordinatorAdminClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.apache.uniffle.api; | ||
|
||
import org.apache.uniffle.proto.RssProtos; | ||
|
||
public interface CoordinatorAdminClient { | ||
|
||
RssProtos.RefreshAccessCheckerResponse refreshAccessChecker(RssProtos.RefreshAccessCheckerRequest request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
cli/src/main/java/org/apache/uniffle/impl/grpc/CoordinatorAdminGrpcClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.apache.uniffle.impl.grpc; | ||
|
||
import io.grpc.ManagedChannel; | ||
import org.apache.uniffle.api.CoordinatorAdminClient; | ||
import org.apache.uniffle.client.impl.grpc.GrpcClient; | ||
import org.apache.uniffle.proto.CoordinatorAdminServerGrpc; | ||
import org.apache.uniffle.proto.RssProtos; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CoordinatorAdminGrpcClient extends GrpcClient implements CoordinatorAdminClient { | ||
private static final Logger LOG = LoggerFactory.getLogger(CoordinatorAdminGrpcClient.class); | ||
private CoordinatorAdminServerGrpc.CoordinatorAdminServerBlockingStub blockingStub; | ||
|
||
public CoordinatorAdminGrpcClient(String host, int port) { | ||
this(host, port, 3); | ||
} | ||
|
||
public CoordinatorAdminGrpcClient(String host, int port, int maxRetryAttempts) { | ||
this(host, port, maxRetryAttempts, true); | ||
} | ||
|
||
public CoordinatorAdminGrpcClient(String host, int port, int maxRetryAttempts, boolean usePlaintext) { | ||
super(host, port, maxRetryAttempts, usePlaintext); | ||
blockingStub = CoordinatorAdminServerGrpc.newBlockingStub(channel); | ||
} | ||
|
||
@Override | ||
public RssProtos.RefreshAccessCheckerResponse refreshAccessChecker(RssProtos.RefreshAccessCheckerRequest request) { | ||
return blockingStub.refreshAccessChecker(request); | ||
} | ||
|
||
public int refreshAccessChecker(String checker) { | ||
System.out.println("refresh " + checker); | ||
RssProtos.RefreshAccessCheckerRequest rpcRequest = RssProtos.RefreshAccessCheckerRequest | ||
.newBuilder() | ||
.setAccessCheckerClass(checker) | ||
.build(); | ||
RssProtos.RefreshAccessCheckerResponse response = refreshAccessChecker(rpcRequest); | ||
RssProtos.RefreshAccessCheckerResponse.AdminCliStatus statusCode = response.getStatus(); | ||
switch (statusCode) { | ||
case SUCCESS: | ||
LOG.info("Refresh access checker {} succed.", checker); | ||
break; | ||
case FAILED: | ||
LOG.error("Refresh access checker {} failed. Exception:{}", checker, response.getMsg()); | ||
break; | ||
} | ||
return statusCode.getNumber(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
coordinator/src/main/java/org/apache/uniffle/coordinator/CoordinatorAdminGrpcService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.apache.uniffle.coordinator; | ||
|
||
import io.grpc.stub.StreamObserver; | ||
import org.apache.commons.collections.CollectionUtils; | ||
import org.apache.uniffle.coordinator.access.checker.AccessChecker; | ||
import org.apache.uniffle.proto.CoordinatorAdminServerGrpc; | ||
import org.apache.uniffle.proto.RssProtos; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class CoordinatorAdminGrpcService extends CoordinatorAdminServerGrpc.CoordinatorAdminServerImplBase { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(CoordinatorAdminGrpcService.class); | ||
|
||
private final CoordinatorServer coordinatorServer; | ||
|
||
public CoordinatorAdminGrpcService(CoordinatorServer coordinatorServer) { | ||
this.coordinatorServer = coordinatorServer; | ||
} | ||
|
||
@Override | ||
public void refreshAccessChecker(RssProtos.RefreshAccessCheckerRequest request, StreamObserver<RssProtos.RefreshAccessCheckerResponse> responseObserver) { | ||
List<String> checkers = coordinatorServer.getCoordinatorConf().get(CoordinatorConf.COORDINATOR_ACCESS_CHECKERS); | ||
String accessClass = request.getAccessCheckerClass(); | ||
if (CollectionUtils.isEmpty(checkers)) { | ||
LOG.warn("Access checkers is empty, will not update any checkers."); | ||
return; | ||
} | ||
try { | ||
Class<?> aClass = Class.forName(accessClass); | ||
Optional<AccessChecker> checker = coordinatorServer.getAccessManager().getAccessCheckers().stream() | ||
.filter(aClass::isInstance) | ||
.findAny(); | ||
if (!checker.isPresent()) { | ||
LOG.warn("Access checkers {} is none exist, will not update any checkers.", accessClass); | ||
return; | ||
} | ||
checker.get().refreshAccessChecker(); | ||
} catch (ClassNotFoundException e) { | ||
LOG.warn("Access checker class {} is not found.", accessClass, e); | ||
} | ||
final RssProtos.RefreshAccessCheckerResponse response = RssProtos.RefreshAccessCheckerResponse | ||
.newBuilder() | ||
.setStatus(RssProtos.RefreshAccessCheckerResponse.AdminCliStatus.SUCCESS) | ||
.setMsg("") | ||
.build(); | ||
responseObserver.onNext(response); | ||
responseObserver.onCompleted(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ration-test/common/src/test/java/org/apache/uniffle/test/CoordinatorAdminServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.apache.uniffle.test; | ||
|
||
import org.apache.uniffle.coordinator.CoordinatorConf; | ||
import org.apache.uniffle.proto.RssProtos; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CoordinatorAdminServiceTest extends CoordinatorAdminTestBase { | ||
|
||
@Test | ||
public void test() throws Exception { | ||
CoordinatorConf coordinatorConf = getCoordinatorConf(); | ||
coordinatorConf.setString(CoordinatorConf.COORDINATOR_ASSIGNMENT_STRATEGY.key(), "BASIC"); | ||
String accessChecker = "org.apache.uniffle.test.AccessClusterTest$MockedAccessChecker"; | ||
coordinatorConf.setString(CoordinatorConf.COORDINATOR_ACCESS_CHECKERS.key(), accessChecker); | ||
createCoordinatorServer(coordinatorConf); | ||
startServers(); | ||
assertEquals(coordinatorAdminClient.refreshAccessChecker(accessChecker),0); | ||
shutdownServers(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
integration-test/common/src/test/java/org/apache/uniffle/test/CoordinatorAdminTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.test; | ||
|
||
import org.apache.uniffle.impl.grpc.CoordinatorAdminGrpcClient; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
public class CoordinatorAdminTestBase extends IntegrationTestBase { | ||
|
||
protected CoordinatorAdminGrpcClient coordinatorAdminClient; | ||
|
||
@BeforeEach | ||
public void createClient() { | ||
coordinatorAdminClient = new CoordinatorAdminGrpcClient(LOCALHOST, COORDINATOR_PORT_1); | ||
} | ||
|
||
@AfterEach | ||
public void closeClient() { | ||
if (coordinatorAdminClient != null) { | ||
coordinatorAdminClient.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.