All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cdap.cdap.app.runtime.ProgramRuntimeService Maven / Gradle / Ivy

The newest version!
/*
 * Copyright © 2014-2015 Cask Data, Inc.
 *
 * Licensed 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 io.cdap.cdap.app.runtime;

import com.google.common.util.concurrent.Service;
import io.cdap.cdap.app.program.ProgramDescriptor;
import io.cdap.cdap.proto.ProgramLiveInfo;
import io.cdap.cdap.proto.ProgramType;
import io.cdap.cdap.proto.id.ProgramId;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.twill.api.RunId;

/**
 * Service for interacting with the runtime system.
 */
public interface ProgramRuntimeService extends Service {

  /**
   * Represents information of a running program.
   */
  interface RuntimeInfo {

    ProgramController getController();

    ProgramType getType();

    ProgramId getProgramId();

    @Nullable
    RunId getTwillRunId();
  }

  /**
   * Starts the given program and return a {@link RuntimeInfo} about the running program.
   *
   * @param programDescriptor describing the program to run
   * @param options {@link ProgramOptions} that are needed by the program.
   * @param runId {@link RunId} for the program run
   * @return A {@link ProgramController} for the running program.
   */
  RuntimeInfo run(ProgramDescriptor programDescriptor, ProgramOptions options, RunId runId);

  /**
   * Find the {@link RuntimeInfo} for a running program with the given {@link RunId}.
   *
   * @param programId The id of the program.
   * @param runId The program {@link RunId}.
   * @return A {@link RuntimeInfo} for the running program or {@code null} if no such program is
   *     found.
   */
  @Nullable
  RuntimeInfo lookup(ProgramId programId, RunId runId);

  /**
   * Get {@link RuntimeInfo} for all running programs of the given type.
   *
   * @param type Type of running programs to list.
   * @return An immutable map from {@link RunId} to {@link ProgramController}.
   */
  Map list(ProgramType type);

  /**
   * Get {@link RuntimeInfo} for a specified program.
   *
   * @param program The program for which the {@link RuntimeInfo} needs to be determined
   * @return An immutable map from {@link RunId} to {@link ProgramController}
   */
  Map list(ProgramId program);

  /**
   * Get runtime information about a running program. The content of this information is different
   * for each runtime environment. For example, in a distributed environment, this would contain the
   * YARN application id and the container information for each runnable. For in-memory, it may be
   * empty.
   */
  ProgramLiveInfo getLiveInfo(ProgramId programId);

  /**
   * Get information about running programs. Protected only to support v2 APIs
   *
   * @param types Types of program to check returns List of info about running programs.
   */
  List listAll(ProgramType... types);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy