Package org.springframework.yarn.client

Source Code of org.springframework.yarn.client.DefaultApplicationYarnClient

/*
* 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.client;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.springframework.yarn.YarnSystemException;

/**
* An implementation of {@link ApplicationYarnClient} verifying application
* install and submit statuses.
*
* @author Janne Valkealahti
*
*/
public class DefaultApplicationYarnClient extends CommandYarnClient implements ApplicationYarnClient {

  /**
   * Instantiates a new default application yarn client.
   *
   * @param clientRmOperations the client rm operations
   */
  public DefaultApplicationYarnClient(ClientRmOperations clientRmOperations) {
    super(clientRmOperations);
  }

  @Override
  public void installApplication(ApplicationDescriptor descriptor) {
    preInstallVerify(descriptor);
    installApplication();
    postInstallVerify(descriptor);
  }

  @Override
  public ApplicationId submitApplication(ApplicationDescriptor descriptor) {
    preSubmitVerify(descriptor);
    ApplicationId applicationId = submitApplication(false);
    postSubmitVerify(applicationId, descriptor);
    return applicationId;
  }

  /**
   * Pre install verify.
   *
   * @param descriptor the application descriptor
   */
  protected void preInstallVerify(ApplicationDescriptor descriptor) {
    try {
      Path path = new Path(descriptor.getDirectory());
      FileSystem fs = path.getFileSystem(getConfiguration());
      if (fs.exists(path)) {
        throw new IllegalArgumentException("Application directory " + descriptor.getDirectory() + " already exists");
      }
    } catch (Exception e) {
      throw new YarnSystemException("Error", e);
    }
  }

  /**
   * Post install verify.
   *
   * @param descriptor the application descriptor
   */
  protected void postInstallVerify(ApplicationDescriptor descriptor) {
  }

  /**
   * Pre submit verify.
   *
   * @param descriptor the application descriptor
   */
  protected void preSubmitVerify(ApplicationDescriptor descriptor) {
    try {
      Path path = new Path(descriptor.getDirectory());
      FileSystem fs = path.getFileSystem(getConfiguration());
      if (!fs.exists(path)) {
        throw new IllegalArgumentException("Application directory " + descriptor.getDirectory() + " doesn't exist");
      }
    } catch (Exception e) {
      throw new YarnSystemException("Error", e);
    }
  }

  /**
   * Post submit verify.
   *
   * @param applicationId the application id
   * @param descriptor the application descriptor
   */
  protected void postSubmitVerify(ApplicationId applicationId, ApplicationDescriptor descriptor) {
  }

}
TOP

Related Classes of org.springframework.yarn.client.DefaultApplicationYarnClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.