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.util; 016 017 import org.apache.oozie.BundleJobBean; 018 import org.apache.oozie.CoordinatorActionBean; 019 import org.apache.oozie.CoordinatorJobBean; 020 import org.apache.oozie.WorkflowActionBean; 021 import org.apache.oozie.WorkflowJobBean; 022 import org.apache.oozie.service.DagXLogInfoService; 023 import org.apache.oozie.service.XLogService; 024 025 /** 026 * logging utilities. 027 */ 028 public class LogUtils { 029 030 /** 031 * Set the log info with the context of the given coordinator bean. 032 * 033 * @param cBean coordinator bean. 034 * @param logInfo log info 035 */ 036 public static void setLogInfo(CoordinatorJobBean cBean, XLog.Info logInfo) { 037 if (logInfo.getParameter(XLogService.GROUP) == null) { 038 logInfo.setParameter(XLogService.GROUP, cBean.getGroup()); 039 } 040 if (logInfo.getParameter(XLogService.USER) == null) { 041 logInfo.setParameter(XLogService.USER, cBean.getUser()); 042 } 043 logInfo.setParameter(DagXLogInfoService.JOB, cBean.getId()); 044 logInfo.setParameter(DagXLogInfoService.TOKEN, ""); 045 logInfo.setParameter(DagXLogInfoService.APP, cBean.getAppName()); 046 XLog.Info.get().setParameters(logInfo); 047 } 048 049 /** 050 * Set the log info with the context of the given coordinator action bean. 051 * 052 * @param action action bean. 053 * @param logInfo log info 054 */ 055 public static void setLogInfo(CoordinatorActionBean action, XLog.Info logInfo) { 056 logInfo.setParameter(DagXLogInfoService.JOB, action.getJobId()); 057 logInfo.setParameter(DagXLogInfoService.ACTION, action.getId()); 058 XLog.Info.get().setParameters(logInfo); 059 } 060 061 /** 062 * Set the log info with the context of the given workflow bean. 063 * 064 * @param workflow workflow bean. 065 * @param logInfo log info 066 */ 067 public static void setLogInfo(WorkflowJobBean workflow, XLog.Info logInfo) { 068 logInfo.setParameter(XLogService.GROUP, workflow.getGroup()); 069 logInfo.setParameter(XLogService.USER, workflow.getUser()); 070 logInfo.setParameter(DagXLogInfoService.JOB, workflow.getId()); 071 logInfo.setParameter(DagXLogInfoService.TOKEN, workflow.getLogToken()); 072 logInfo.setParameter(DagXLogInfoService.APP, workflow.getAppName()); 073 XLog.Info.get().setParameters(logInfo); 074 } 075 076 /** 077 * Set the log info with the context of the given action bean. 078 * 079 * @param action action bean. 080 * @param logInfo log info 081 */ 082 public static void setLogInfo(WorkflowActionBean action, XLog.Info logInfo) { 083 logInfo.setParameter(DagXLogInfoService.JOB, action.getJobId()); 084 logInfo.setParameter(DagXLogInfoService.TOKEN, action.getLogToken()); 085 logInfo.setParameter(DagXLogInfoService.ACTION, action.getId()); 086 XLog.Info.get().setParameters(logInfo); 087 } 088 089 /** 090 * Set the log info with the context of the given bundle bean. 091 * 092 * @param bBean bundle bean. 093 * @param logInfo log info 094 */ 095 public static void setLogInfo(BundleJobBean bBean, XLog.Info logInfo) { 096 if (logInfo.getParameter(XLogService.GROUP) == null) { 097 logInfo.setParameter(XLogService.GROUP, bBean.getGroup()); 098 } 099 if (logInfo.getParameter(XLogService.USER) == null) { 100 logInfo.setParameter(XLogService.USER, bBean.getUser()); 101 } 102 logInfo.setParameter(DagXLogInfoService.JOB, bBean.getId()); 103 logInfo.setParameter(DagXLogInfoService.TOKEN, ""); 104 logInfo.setParameter(DagXLogInfoService.APP, bBean.getAppName()); 105 XLog.Info.get().setParameters(logInfo); 106 } 107 108 /** 109 * Set the thread local log info with the context of the given Info object. 110 * 111 * @param logInfo log info 112 */ 113 public static void setLogInfo(XLog.Info logInfo) { 114 XLog.Info.get().setParameters(logInfo); 115 } 116 117 }