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

org.apache.twill.internal.yarn.Hadoop21YarnLaunchContext Maven / Gradle / Ivy

/*
 * 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.twill.internal.yarn;

import com.google.common.base.Function;
import com.google.common.collect.Maps;
import org.apache.hadoop.security.Credentials;
import org.apache.hadoop.yarn.api.records.ApplicationAccessType;
import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
import org.apache.hadoop.yarn.api.records.LocalResource;
import org.apache.hadoop.yarn.util.Records;

import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;

/**
 *
 */
public final class Hadoop21YarnLaunchContext implements YarnLaunchContext {

  private static final Function RESOURCE_TRANSFORM;

  static {
    // Creates transform function from YarnLocalResource -> LocalResource
    RESOURCE_TRANSFORM = new Function() {
      @Override
      public LocalResource apply(YarnLocalResource input) {
        return input.getLocalResource();
      }
    };
  }

  private final ContainerLaunchContext launchContext;

  public Hadoop21YarnLaunchContext() {
    launchContext = Records.newRecord(ContainerLaunchContext.class);
  }

  @Override
  public  T getLaunchContext() {
    return (T) launchContext;
  }

  @Override
  public void setCredentials(Credentials credentials) {
    launchContext.setTokens(YarnUtils.encodeCredentials(credentials));
  }

  @Override
  public void setLocalResources(Map localResources) {
    launchContext.setLocalResources(Maps.transformValues(localResources, RESOURCE_TRANSFORM));
  }

  @Override
  public void setServiceData(Map serviceData) {
    launchContext.setServiceData(serviceData);
  }

  @Override
  public Map getEnvironment() {
    return launchContext.getEnvironment();
  }

  @Override
  public void setEnvironment(Map environment) {
    launchContext.setEnvironment(environment);
  }

  @Override
  public List getCommands() {
    return launchContext.getCommands();
  }

  @Override
  public void setCommands(List commands) {
    launchContext.setCommands(commands);
  }

  @Override
  public void setApplicationACLs(Map acls) {
    launchContext.setApplicationACLs(acls);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy