001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.bridge.client;
020
021import org.apache.reef.client.DriverConfiguration;
022import org.apache.reef.client.DriverServiceConfiguration;
023import org.apache.reef.client.DriverRestartConfiguration;
024import org.apache.reef.io.network.naming.NameServerConfiguration;
025import org.apache.reef.javabridge.generic.JobDriver;
026import org.apache.reef.tang.Configuration;
027import org.apache.reef.tang.Configurations;
028import org.apache.reef.webserver.HttpHandlerConfiguration;
029import org.apache.reef.webserver.HttpServerReefEventHandler;
030import org.apache.reef.webserver.ReefEventStateManager;
031
032/**
033 * Constant Configuration instances used by the bridge.
034 */
035public final class Constants {
036
037  /**
038   * Contains all bindings of event handlers to the bridge.
039   */
040  public static final Configuration DRIVER_CONFIGURATION = DriverConfiguration.CONF
041      .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, JobDriver.AllocatedEvaluatorHandler.class)
042      .set(DriverConfiguration.ON_EVALUATOR_FAILED, JobDriver.FailedEvaluatorHandler.class)
043      .set(DriverConfiguration.ON_CONTEXT_ACTIVE, JobDriver.ActiveContextHandler.class)
044      .set(DriverConfiguration.ON_CONTEXT_CLOSED, JobDriver.ClosedContextHandler.class)
045      .set(DriverConfiguration.ON_CONTEXT_FAILED, JobDriver.FailedContextHandler.class)
046      .set(DriverConfiguration.ON_CONTEXT_MESSAGE, JobDriver.ContextMessageHandler.class)
047      .set(DriverConfiguration.ON_TASK_MESSAGE, JobDriver.TaskMessageHandler.class)
048      .set(DriverConfiguration.ON_TASK_FAILED, JobDriver.FailedTaskHandler.class)
049      .set(DriverConfiguration.ON_TASK_RUNNING, JobDriver.RunningTaskHandler.class)
050      .set(DriverConfiguration.ON_TASK_COMPLETED, JobDriver.CompletedTaskHandler.class)
051      .set(DriverConfiguration.ON_DRIVER_STARTED, JobDriver.StartHandler.class)
052      .set(DriverConfiguration.ON_TASK_SUSPENDED, JobDriver.SuspendedTaskHandler.class)
053      .set(DriverConfiguration.ON_EVALUATOR_COMPLETED, JobDriver.CompletedEvaluatorHandler.class)
054      .set(DriverConfiguration.PROGRESS_PROVIDER, JobDriver.ProgressProvider.class)
055      .build();
056
057  /**
058   * The HTTP Server configuration assumed by the bridge.
059   */
060  public static final Configuration HTTP_SERVER_CONFIGURATION = Configurations.merge(
061      HttpHandlerConfiguration.CONF
062          .set(HttpHandlerConfiguration.HTTP_HANDLERS, HttpServerReefEventHandler.class)
063          .build(),
064      DriverServiceConfiguration.CONF
065          .set(DriverServiceConfiguration.ON_EVALUATOR_ALLOCATED,
066              ReefEventStateManager.AllocatedEvaluatorStateHandler.class)
067          .set(DriverServiceConfiguration.ON_CONTEXT_ACTIVE, ReefEventStateManager.ActiveContextStateHandler.class)
068          .set(DriverServiceConfiguration.ON_TASK_RUNNING, ReefEventStateManager.TaskRunningStateHandler.class)
069          .set(DriverServiceConfiguration.ON_DRIVER_STARTED, ReefEventStateManager.StartStateHandler.class)
070          .set(DriverServiceConfiguration.ON_DRIVER_STOP, ReefEventStateManager.StopStateHandler.class)
071          .build(),
072      DriverRestartConfiguration.CONF
073          .set(DriverRestartConfiguration.ON_DRIVER_RESTARTED,
074              ReefEventStateManager.DriverRestartHandler.class)
075          .set(DriverRestartConfiguration.ON_DRIVER_RESTART_CONTEXT_ACTIVE,
076              ReefEventStateManager.DriverRestartActiveContextStateHandler.class)
077          .set(DriverRestartConfiguration.ON_DRIVER_RESTART_TASK_RUNNING,
078              ReefEventStateManager.DriverRestartTaskRunningStateHandler.class)
079          .build()
080  );
081
082  /**
083   * The name server configuration assumed by the bridge.
084   */
085  public static final Configuration NAME_SERVER_CONFIGURATION = NameServerConfiguration.CONF
086      .set(NameServerConfiguration.NAME_SERVICE_PORT, 0)
087      .build();
088
089  /**
090   * The driver configuration assumed by the the bridge.
091   */
092  public static final Configuration DRIVER_CONFIGURATION_WITH_HTTP_AND_NAMESERVER = Configurations.merge(
093      DRIVER_CONFIGURATION,
094      HTTP_SERVER_CONFIGURATION,
095      NAME_SERVER_CONFIGURATION
096  );
097
098  /**
099   * Empty private constructor to prohibit instantiation of utility class.
100   */
101  private Constants() {
102  }
103}