org.springframework.yarn.am.AbstractAppmaster Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014 the original author or authors.
*
* 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 org.springframework.yarn.am;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest;
import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse;
import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.Container;
import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
import org.apache.hadoop.yarn.util.Records;
import org.springframework.util.Assert;
import org.springframework.yarn.YarnSystemException;
import org.springframework.yarn.am.assign.ContainerAssign;
import org.springframework.yarn.am.assign.DefaultContainerAssign;
import org.springframework.yarn.am.container.ContainerShutdown;
import org.springframework.yarn.fs.ResourceLocalizer;
import org.springframework.yarn.fs.SmartResourceLocalizer;
import org.springframework.yarn.listener.AppmasterStateListener;
import org.springframework.yarn.listener.AppmasterStateListener.AppmasterState;
import org.springframework.yarn.listener.CompositeAppmasterStateListener;
import org.springframework.yarn.support.LifecycleObjectSupport;
import org.springframework.yarn.support.YarnContextUtils;
import org.springframework.yarn.support.YarnUtils;
/**
* Base class providing functionality for common application
* master instances.
*
* @author Janne Valkealahti
*
*/
public abstract class AbstractAppmaster extends LifecycleObjectSupport {
private static final Log log = LogFactory.getLog(AbstractAppmaster.class);
/** Environment variables for the process */
private final HashMap> environments = new HashMap>();
/** Yarn configuration */
private Configuration configuration;
/** Commands for container start where value mapped with null key indicates defaults */
private final Map> commands = new HashMap>();
/** Template operations talking to resource manager */
private AppmasterRmOperations rmTemplate;
/** Cached app attempt id */
private ApplicationAttemptId applicationAttemptId;
/** Parameters passed to application */
private Properties parameters;
/** Resource localizer for the containers */
private ResourceLocalizer resourceLocalizer;
/** Handle to service if exists */
private AppmasterService appmasterService;
/** Handle to client service if exists */
private AppmasterService appmasterClientService;
/** Handle to track service if exists */
private AppmasterTrackService appmasterTrackService;
/** Handle to container shutdown if exists */
private ContainerShutdown containerShutdown;
/** State if we're done successful registration */
private boolean applicationRegistered;
/** Appstatus when we send finish request */
private FinalApplicationStatus finalApplicationStatus;
/** Listener handling state events */
private CompositeAppmasterStateListener stateListener = new CompositeAppmasterStateListener();
/** Holder for container assigned data */
private ContainerAssign