/*
 * Copyright 2013 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.elasticsearch.hadoop.util;

import org.apache.commons.lang.reflect.FieldUtils;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.filecache.TrackerDistributedCacheManager;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.mapreduce.JobSubmissionFiles;

public class TestUtils {

    /**
     * Hack to allow Hadoop client to run on windows (which otherwise fails due to some permission problem).
     */
    public static void hackHadoopStagingOnWin() {
        // do the assignment only on Windows systems
        if (isWindows()) {
            // 0655 = -rwxr-xr-x
            JobSubmissionFiles.JOB_DIR_PERMISSION.fromShort((short) 0650);
            JobSubmissionFiles.JOB_FILE_PERMISSION.fromShort((short) 0650);

            // handle jar permissions as well
            try {
                FsPermission perm = (FsPermission) FieldUtils.readStaticField(TrackerDistributedCacheManager.class, "PUBLIC_CACHE_OBJECT_PERM", true);
                perm.fromShort((short) 0650);
            } catch (Exception ex) {
                LogFactory.getLog(TestUtils.class).warn("Cannot set permission for TrackerDistributedCacheManager", ex);
            }
        }
    }

    public static boolean isWindows() {
        return System.getProperty("os.name").toLowerCase().startsWith("win");
    }
}

@@ -750,75 +750,8 @@
 ry;%0A
-import org.apache.hadoop.filecache.TrackerDistributedCacheManager;%0A
 impo
@@ -1370,26 +1370,174 @@
 well
-%0A            try %7B
+ - temporarely disable for CDH 4 / YARN%0A            try %7B%0A                Class%3C?%3E tdcm = Class.forName(%22org.apache.hadoop.filecache.TrackerDistributedCacheManager%22);
 %0A   
@@ -1615,44 +1615,12 @@
 eld(
-TrackerDistributedCacheManager.class
+tdcm
 , %22P
@@ -1690,32 +1690,133 @@
 ((short) 0650);%0A
+            %7D catch (ClassNotFoundException cnfe) %7B%0A                //ignore%0A                return;%0A
             %7D ca

improve TestUtils when compiling against Hadoop 2.x/CDH4 YARN