This project has retired. For details please refer to its
Attic page.
001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.oozie.action.hadoop;
019
020 import java.util.Map;
021
022 import org.apache.hadoop.conf.Configuration;
023 import org.apache.hadoop.hbase.HBaseConfiguration;
024 import org.apache.hadoop.hbase.security.User;
025 import org.apache.hadoop.mapred.JobConf;
026 import org.apache.oozie.action.ActionExecutor.Context;
027 import org.apache.oozie.action.hadoop.Credentials;
028 import org.apache.oozie.action.hadoop.CredentialsProperties;
029 import org.apache.oozie.util.XLog;
030 import org.apache.hadoop.security.UserGroupInformation;
031
032
033 /**
034 * Hbase Credentials implementation to store in jobConf
035 * The jobConf is used further to pass credentials to the tasks while running
036 * Oozie server should be configured to use this Credentials class by including it via property 'oozie.credentials.credentialclasses'
037 *
038 */
039 public class HbaseCredentials extends Credentials {
040
041
042 /* (non-Javadoc)
043 * @see org.apache.oozie.action.hadoop.Credentials#addtoJobConf(org.apache.hadoop.mapred.JobConf, org.apache.oozie.action.hadoop.CredentialsProperties, org.apache.oozie.action.ActionExecutor.Context)
044 */
045 @Override
046 public void addtoJobConf(JobConf jobConf, CredentialsProperties props, Context context) throws Exception {
047 try {
048 // Create configuration using hbase-site.xml/hbase-default.xml
049 Configuration hbaseConf = HBaseConfiguration.create();
050 // copy conf from hbaseConf to jobConf without overriding the
051 // already existing values of jobConf
052 injectConf(hbaseConf, jobConf);
053 String user = context.getWorkflow().getUser();
054 UserGroupInformation ugi = UserGroupInformation.createProxyUser(user, UserGroupInformation.getLoginUser());
055 User u = User.create(ugi);
056 u.obtainAuthTokenForJob(jobConf);
057 }
058 catch (Exception e) {
059 XLog.getLog(getClass()).warn("Exception in receiving hbase credentials", e);
060 throw e;
061 }
062 }
063
064 private void injectConf(Configuration srcConf, Configuration destConf) {
065 for (Map.Entry<String, String> entry : srcConf) {
066 String name = entry.getKey();
067 if (destConf.get(name) == null) {
068 String value = entry.getValue();
069 destConf.set(name, value);
070 }
071 }
072 }
073 }