Package org.apache.airavata.gfac.hadoop.provider.utils

Source Code of org.apache.airavata.gfac.hadoop.provider.utils.HadoopUtils

/*
*
* 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.airavata.gfac.hadoop.provider.utils;

import org.apache.airavata.gfac.core.context.JobExecutionContext;
import org.apache.airavata.gfac.core.context.MessageContext;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Collection;

public class HadoopUtils {
    public static Configuration createHadoopConfiguration(
            JobExecutionContext jobExecutionContext,
            boolean isWhirrBasedDeployment,
            File hadoopConfigDir) throws FileNotFoundException {
        MessageContext inMessageContext = jobExecutionContext.getInMessageContext();
        Configuration hadoopConf = new Configuration();

        if(isWhirrBasedDeployment){
            hadoopConf.addResource(new FileInputStream(
                    new File((String)inMessageContext.getParameter("HADOOP_SITE_XML"))));
        } else {
            readHadoopClusterConfigurationFromDirectory(hadoopConfigDir, hadoopConf);
        }

        return hadoopConf;
    }

    private static void readHadoopClusterConfigurationFromDirectory(File localHadoopConfigurationDirectory, Configuration hadoopConf)
            throws FileNotFoundException {
        Collection hadoopConfigurationFiles =
                FileUtils.listFiles(localHadoopConfigurationDirectory, null, false);
        for (Object f : hadoopConfigurationFiles) {
            hadoopConf.addResource(new FileInputStream((File)f));
        }
    }
}
TOP

Related Classes of org.apache.airavata.gfac.hadoop.provider.utils.HadoopUtils

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.