reef-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (REEF-2025) A new module containing the new Java bridge
Date Tue, 05 Jun 2018 02:12:02 GMT

    [ https://issues.apache.org/jira/browse/REEF-2025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16501181#comment-16501181
] 

ASF GitHub Bot commented on REEF-2025:
--------------------------------------

motus commented on a change in pull request #1466: [REEF-2025] A new module containing the
new Java bridge
URL: https://github.com/apache/reef/pull/1466#discussion_r192923290
 
 

 ##########
 File path: lang/java/reef-bridge-proto-java/src/main/java/org/apache/reef/bridge/driver/client/grpc/DriverClientService.java
 ##########
 @@ -0,0 +1,663 @@
+/*
+ * 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.reef.bridge.driver.client.grpc;
+
+import com.google.common.collect.Lists;
+import io.grpc.Server;
+import io.grpc.ServerBuilder;
+import io.grpc.Status;
+import io.grpc.stub.StreamObserver;
+import org.apache.commons.lang.StringUtils;
+import org.apache.reef.bridge.driver.client.DriverClientDispatcher;
+import org.apache.reef.bridge.driver.client.IDriverClientService;
+import org.apache.reef.bridge.driver.client.JVMClientProcess;
+import org.apache.reef.bridge.driver.client.events.*;
+import org.apache.reef.bridge.proto.*;
+import org.apache.reef.bridge.proto.Void;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.driver.restart.DriverRestartCompleted;
+import org.apache.reef.driver.restart.DriverRestarted;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.exception.EvaluatorException;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorDescriptorImpl;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.remote.ports.TcpPortProvider;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.Time;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The driver client service that accepts incoming messages driver service and
+ * dispatches appropriate objects to the application.
+ */
+public final class DriverClientService extends DriverClientGrpc.DriverClientImplBase
+    implements IDriverClientService {
+
+  private static final Logger LOG = Logger.getLogger(DriverClientService.class.getName());
+
+  private Server server;
+
+  private final Object lock = new Object();
+
+  private final InjectionFuture<Clock> clock;
+
+  private final ExceptionCodec exceptionCodec;
+
+  private final DriverServiceClient driverServiceClient;
+
+  private final TcpPortProvider tcpPortProvider;
+
+  private final InjectionFuture<DriverClientDispatcher> clientDriverDispatcher;
+
+  private final Map<String, AllocatedEvaluatorBridge> evaluatorBridgeMap = new HashMap<>();
+
+  private final Map<String, ActiveContextBridge> activeContextBridgeMap = new HashMap<>();
+
+  private int outstandingEvaluatorCount = 0;
+
+  @Inject
+  private DriverClientService(
+      final ExceptionCodec exceptionCodec,
+      final DriverServiceClient driverServiceClient,
+      final TcpPortProvider tcpPortProvider,
+      final InjectionFuture<Clock> clock,
+      final InjectionFuture<DriverClientDispatcher> clientDriverDispatcher) {
+    this.exceptionCodec = exceptionCodec;
+    this.driverServiceClient = driverServiceClient;
+    this.tcpPortProvider = tcpPortProvider;
+    this.clock = clock;
+    this.clientDriverDispatcher = clientDriverDispatcher;
+  }
+
+  @Override
+  public void notifyEvaluatorRequest(final int count) {
+    synchronized (this.lock) {
+      this.outstandingEvaluatorCount += count;
+      this.lock.notify();
+    }
+  }
+
+  @Override
+  public void start() throws IOException {
+    for (final Integer port : this.tcpPortProvider) {
+      try {
+        this.server = ServerBuilder.forPort(port)
+            .addService(this)
+            .build()
+            .start();
+        LOG.info("Driver Client Server started, listening on " + port);
+        break;
+      } catch (IOException e) {
+        LOG.log(Level.WARNING, "Unable to bind to port [{0}]", port);
+      }
+    }
+    if (this.server == null || this.server.isTerminated()) {
+      throw new IOException("Unable to start gRPC server");
+    }
+    this.driverServiceClient.registerDriverClientService("localhost", this.server.getPort());
+  }
+
+  @Override
+  public void awaitTermination() throws InterruptedException {
+    if (this.server != null) {
+      this.server.awaitTermination();
+    }
+  }
+
+  @Override
+  public void idlenessCheckHandler(final Void request, final StreamObserver<IdleStatus>
responseObserver) {
+    if (isIdle()) {
+      LOG.log(Level.INFO, "possibly idle. waiting for some action.");
+      try {
+        synchronized (this.lock) {
+          this.lock.wait(1000); // wait a second
+        }
+      } catch (InterruptedException e) {
+        LOG.log(Level.WARNING, e.getMessage());
+      }
+    }
+    responseObserver.onNext(IdleStatus.newBuilder()
+        .setReason("DriverClient checking idleness")
+        .setIsIdle(this.isIdle())
+        .build());
+    responseObserver.onCompleted();
+  }
+
+  @Override
+  public void startHandler(final StartTimeInfo request, final StreamObserver<Void>
responseObserver) {
+    try {
+      LOG.log(Level.INFO, "StartHandler at time {0}", request.getStartTime());
+      final StartTime startTime = new StartTime(request.getStartTime());
+      this.clientDriverDispatcher.get().dispatch(startTime);
+    } finally {
+      responseObserver.onNext(null);
+      responseObserver.onCompleted();
+    }
+  }
+
+  @Override
+  public void stopHandler(final StopTimeInfo request, final StreamObserver<ExceptionInfo>
responseObserver) {
+    try {
+      LOG.log(Level.INFO, "StopHandler at time {0}", request.getStopTime());
+      final StopTime stopTime = new StopTime(request.getStopTime());
+      final Throwable error = this.clientDriverDispatcher.get().dispatch(stopTime);
+      if (error != null) {
+        responseObserver.onNext(GRPCUtils.createExceptionInfo(this.exceptionCodec, error));
+      } else {
+        responseObserver.onNext(ExceptionInfo.newBuilder().setNoError(true).build());
+      }
+    } finally {
+      responseObserver.onCompleted();
+      this.server.shutdown();
+    }
+  }
+
+  @Override
+  public void alarmTrigger(final AlarmTriggerInfo request, final StreamObserver<Void>
responseObserver) {
+    try {
+      LOG.log(Level.INFO, "Alarm Trigger id {0}", request.getAlarmId());
+      this.clientDriverDispatcher.get().dispatchAlarm(request.getAlarmId());
+    } finally {
+      responseObserver.onNext(null);
+      responseObserver.onCompleted();
+    }
+  }
+
+  @Override
+  public void allocatedEvaluatorHandler(final EvaluatorInfo request, final StreamObserver<Void>
responseObserver) {
+    try {
+      synchronized (this.lock) {
+        this.outstandingEvaluatorCount--;
+      }
+      LOG.log(Level.INFO, "Allocated evaluator id {0}", request.getEvaluatorId());
+      final AllocatedEvaluatorBridge eval = new AllocatedEvaluatorBridge(
+          request.getEvaluatorId(),
+          toEvaluatorDescriptor(request.getDescriptorInfo()),
+          this.driverServiceClient);
+      this.evaluatorBridgeMap.put(eval.getId(), eval);
+      this.clientDriverDispatcher.get().dispatch(eval);
+    } finally {
+      responseObserver.onNext(null);
+      responseObserver.onCompleted();
+    }
+  }
+
+  @Override
+  public void completedEvaluatorHandler(final EvaluatorInfo request, final StreamObserver<Void>
responseObserver) {
+    try {
+      LOG.log(Level.INFO, "Completed Evaluator id {0}", request.getEvaluatorId());
+      this.evaluatorBridgeMap.remove(request.getEvaluatorId());
+      this.clientDriverDispatcher.get().dispatch(new CompletedEvaluatorBridge(request.getEvaluatorId()));
+    } finally {
+      responseObserver.onNext(null);
+      responseObserver.onCompleted();
+    }
+  }
+
+  @Override
+  public void failedEvaluatorHandler(final EvaluatorInfo request, final StreamObserver<Void>
responseObserver) {
+    try {
+      if (!this.evaluatorBridgeMap.containsKey(request.getEvaluatorId())) {
+        LOG.log(Level.INFO, "Failed evalautor that we were not allocated");
+        synchronized (this.lock) {
+          if (this.outstandingEvaluatorCount > 0) {
+            this.outstandingEvaluatorCount--;
+          }
+        }
+        return;
+      }
+      LOG.log(Level.INFO, "Failed Evaluator id {0}", request.getEvaluatorId());
+      final AllocatedEvaluatorBridge eval = this.evaluatorBridgeMap.remove(request.getEvaluatorId());
+      List<FailedContext> failedContextList = new ArrayList<>();
+      if (request.getFailure().getFailedContextsList() != null) {
+        for (final String failedContextId : request.getFailure().getFailedContextsList())
{
+          final ActiveContextBridge context = this.activeContextBridgeMap.get(failedContextId);
+          failedContextList.add(new FailedContextBridge(
+              context.getId(),
+              eval.getId(),
+              request.getFailure().getMessage(),
+              eval.getEvaluatorDescriptor(),
+              context.getParentId().isPresent() ?
+                  Optional.<ActiveContext>of(this.activeContextBridgeMap.get(context.getParentId().get()))
:
+                  Optional.<ActiveContext>empty(),
 
 Review comment:
   `HashMap` allows null keys, so the expression above can be shortened as
   ```java
   Optional.<ActiveContext>ofNullable(this.activeContextBridgeMap.get(context.getParentId().get()))
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> A new module containing the new Java bridge
> -------------------------------------------
>
>                 Key: REEF-2025
>                 URL: https://issues.apache.org/jira/browse/REEF-2025
>             Project: REEF
>          Issue Type: Sub-task
>          Components: REEF Bridge
>    Affects Versions: 0.17
>            Reporter: Tyson Condie
>            Assignee: Tyson Condie
>            Priority: Major
>             Fix For: 0.17
>
>
> This Jira introduces the module containing the new bridge. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message