xyuanlu commented on code in PR #2844: URL: https://github.com/apache/helix/pull/2844#discussion_r1692188521
########## helix-gateway/src/main/java/org/apache/helix/gateway/grpcservice/HelixGatewayServiceGrpcService.java: ########## @@ -0,0 +1,118 @@ +package org.apache.helix.gateway.grpcservice; + +import io.grpc.stub.StreamObserver; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.helix.gateway.service.GatewayServiceEvent; +import org.apache.helix.gateway.service.GatewayServiceManager; +import org.apache.helix.gateway.service.HelixGatewayServiceProcessor; +import org.apache.helix.gateway.util.PerKeyLockRegistry; Review Comment: yep. https://github.com/apache/helix/tree/helix-gateway-service/helix-gateway/src/main/java/org/apache/helix/gateway/util ########## helix-gateway/src/main/java/org/apache/helix/gateway/util/StateTransitionMessageTranslateUtil.java: ########## @@ -1,17 +1,70 @@ package org.apache.helix.gateway.util; -import org.apache.helix.gateway.service.GatewayServiceManager; -import proto.org.apache.helix.gateway.HelixGatewayServiceOuterClass.TransitionMessage; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.helix.gateway.constant.GatewayServiceEventType; +import org.apache.helix.gateway.service.GatewayServiceEvent; +import proto.org.apache.helix.gateway.HelixGatewayServiceOuterClass; +import proto.org.apache.helix.gateway.HelixGatewayServiceOuterClass.ShardState; import proto.org.apache.helix.gateway.HelixGatewayServiceOuterClass.ShardStateMessage; +import proto.org.apache.helix.gateway.HelixGatewayServiceOuterClass.ShardTransitionStatus; +import proto.org.apache.helix.gateway.HelixGatewayServiceOuterClass.TransitionMessage; public final class StateTransitionMessageTranslateUtil { - public static TransitionMessage translateSTMsgToProto() { + public static TransitionMessage translateSTMsgToTransitionMessage() { return null; } - public static GatewayServiceManager.GateWayServiceEvent translateProtoToSTMsg(ShardStateMessage message) { - return null; + /** + * Translate from user sent ShardStateMessage message to Helix Gateway Service event. + */ + public static GatewayServiceEvent translateShardStateMessageToEvent(ShardStateMessage request) { + + GatewayServiceEvent.GateWayServiceEventBuilder builder; + if (request.hasShardState()) { // init connection to gateway service + ShardState shardState = request.getShardState(); + Map<String, String> shardStateMap = new HashMap<>(); + for (HelixGatewayServiceOuterClass.SingleResourceState resourceState : shardState.getResourceStateList()) { + for (HelixGatewayServiceOuterClass.SingleShardState state : resourceState.getShardStatesList()) { + shardStateMap.put(resourceState.getResource() + "_" + state.getShardName(), state.getCurrentState()); + } + } + builder = new GatewayServiceEvent.GateWayServiceEventBuilder(GatewayServiceEventType.CONNECT).setClusterName( + shardState.getClusterName()).setParticipantName(shardState.getInstanceName()); + } else { + ShardTransitionStatus shardTransitionStatus = request.getShardTransitionStatus(); + // this is status update for established connection + List<HelixGatewayServiceOuterClass.SingleShardTransitionStatus> status = + shardTransitionStatus.getShardTransitionStatusList(); + List<GatewayServiceEvent.StateTransitionResult> stResult = new ArrayList<>(); + for (HelixGatewayServiceOuterClass.SingleShardTransitionStatus shardTransition : status) { + String stateTransitionId = shardTransition.getTransitionID(); + String stateTransitionStatus = shardTransition.getCurrentState(); + String shardState = shardTransition.getCurrentState(); Review Comment: Updated. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org For additional commands, e-mail: reviews-h...@helix.apache.org