001    /**
002     * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
003     * Licensed under the Apache License, Version 2.0 (the "License");
004     * you may not use this file except in compliance with the License.
005     * You may obtain a copy of the License at
006     *
007     *   http://www.apache.org/licenses/LICENSE-2.0
008     *
009     *  Unless required by applicable law or agreed to in writing, software
010     *  distributed under the License is distributed on an "AS IS" BASIS,
011     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012     *  See the License for the specific language governing permissions and
013     *  limitations under the License. See accompanying LICENSE file.
014     */
015    package org.apache.oozie.action.hadoop;
016    
017    import java.util.concurrent.Callable;
018    
019    //TODO this class goes away when doing 20.100+ only
020    
021    //TODO this class is for testing, but is here to allow selective compilation
022    public class DoAs implements Callable<Void> {
023        private String user;
024        private Callable<Void> callable;
025    
026        public void setUser(String user) {
027            this.user = user;
028        }
029    
030        protected String getUser() {
031            return user;
032        }
033    
034        protected Callable<Void> getCallable() {
035            return callable;
036        }
037    
038        public void setCallable(Callable<Void> callable) {
039            this.callable = callable;
040        }
041    
042        public Void call() throws Exception {
043            callable.call();
044            return null;
045        }
046    
047        public static void call(String user, Callable<Void> callable) throws Exception {
048            Class klass;
049            try {
050                klass = Class.forName("org.apache.oozie.action.hadoop.KerberosDoAs");
051            }
052            catch (ClassNotFoundException ex) {
053                klass = DoAs.class;
054            }
055            DoAs doAs = (DoAs) klass.newInstance();
056            doAs.setCallable(new Callable<Void>() {
057                @Override
058                public Void call() throws Exception {
059                    PigMain.main(null);
060                    return null;
061                }
062            });
063            doAs.setUser(user);
064            doAs.setCallable(callable);
065            doAs.call();
066        }
067    
068    }