Search in sources :

Example 6 with ProvidedOutput

use of co.cask.cdap.internal.app.runtime.batch.dataset.output.ProvidedOutput in project cdap by caskdata.

the class MapReduceRuntimeService method fixOutputPermissions.

private void fixOutputPermissions(JobContext job, List<ProvidedOutput> outputs) {
    Configuration jobconf = job.getConfiguration();
    Set<String> outputsWithUmask = new HashSet<>();
    Set<String> outputUmasks = new HashSet<>();
    for (ProvidedOutput entry : outputs) {
        String umask = entry.getOutputFormatConfiguration().get(HADOOP_UMASK_PROPERTY);
        if (umask != null) {
            outputsWithUmask.add(entry.getOutput().getAlias());
            outputUmasks.add(umask);
        }
    }
    boolean allOutputsHaveUmask = outputsWithUmask.size() == outputs.size();
    boolean allOutputsAgree = outputUmasks.size() == 1;
    boolean jobConfHasUmask = isProgrammaticConfig(jobconf, HADOOP_UMASK_PROPERTY);
    String jobConfUmask = jobconf.get(HADOOP_UMASK_PROPERTY);
    boolean mustFixUmasks = false;
    if (jobConfHasUmask) {
        // case 1: job conf has a programmatic umask. It prevails.
        mustFixUmasks = !outputsWithUmask.isEmpty();
        if (mustFixUmasks) {
            LOG.info("Overriding permissions of outputs {} because a umask of {} was set programmatically in the job " + "configuration.", outputsWithUmask, jobConfUmask);
        }
    } else if (allOutputsHaveUmask && allOutputsAgree) {
        // case 2: no programmatic umask in job conf, all outputs want the same umask: set it in job conf
        String umaskToUse = outputUmasks.iterator().next();
        jobconf.set(HADOOP_UMASK_PROPERTY, umaskToUse);
        LOG.debug("Setting umask of {} in job configuration because all outputs {} agree on it.", umaskToUse, outputsWithUmask);
    } else {
        // case 3: some outputs configure a umask, but not all of them, or not all the same: use job conf default
        mustFixUmasks = !outputsWithUmask.isEmpty();
        if (mustFixUmasks) {
            LOG.warn("Overriding permissions of outputs {} because they configure different permissions. Falling back " + "to default umask of {} in job configuration.", outputsWithUmask, jobConfUmask);
        }
    }
    // fix all output configurations that have a umask by removing that property from their configs
    if (mustFixUmasks) {
        for (int i = 0; i < outputs.size(); i++) {
            ProvidedOutput output = outputs.get(i);
            if (outputsWithUmask.contains(output.getOutput().getAlias())) {
                Map<String, String> outputConfig = new HashMap<>(output.getOutputFormatConfiguration());
                outputConfig.remove(HADOOP_UMASK_PROPERTY);
                outputs.set(i, new ProvidedOutput(output.getOutput(), output.getOutputFormatProvider(), output.getOutputFormatClassName(), outputConfig));
            }
        }
    }
}
Also used : CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) HashMap(java.util.HashMap) ProvidedOutput(co.cask.cdap.internal.app.runtime.batch.dataset.output.ProvidedOutput) HashSet(java.util.HashSet)

Aggregations

ProvidedOutput (co.cask.cdap.internal.app.runtime.batch.dataset.output.ProvidedOutput)6 Output (co.cask.cdap.api.data.batch.Output)2 OutputFormatProvider (co.cask.cdap.api.data.batch.OutputFormatProvider)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Configuration (org.apache.hadoop.conf.Configuration)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 ProgramLifecycle (co.cask.cdap.api.ProgramLifecycle)1 TxRunnable (co.cask.cdap.api.TxRunnable)1 TransactionControl (co.cask.cdap.api.annotation.TransactionControl)1 DatasetContext (co.cask.cdap.api.data.DatasetContext)1 DatasetOutputCommitter (co.cask.cdap.api.data.batch.DatasetOutputCommitter)1 AbstractMapReduce (co.cask.cdap.api.mapreduce.AbstractMapReduce)1 MapReduce (co.cask.cdap.api.mapreduce.MapReduce)1 CombineClassLoader (co.cask.cdap.common.lang.CombineClassLoader)1 WeakReferenceDelegatorClassLoader (co.cask.cdap.common.lang.WeakReferenceDelegatorClassLoader)1 UnsupportedOutputFormat (co.cask.cdap.internal.app.runtime.batch.dataset.UnsupportedOutputFormat)1 ProvisionException (com.google.inject.ProvisionException)1 IOException (java.io.IOException)1