com.clustercontrol.jobmanagement.util.MonitorJobWorker.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.jobmanagement.util.MonitorJobWorker.java

Source

/*
    
Copyright (C) 2016 NTT DATA Corporation
    
This program is free software; you can redistribute it and/or
Modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
    
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU General Public License for more details.
    
 */

package com.clustercontrol.jobmanagement.util;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.clustercontrol.bean.HinemosModuleConstant;
import com.clustercontrol.bean.PriorityConstant;
import com.clustercontrol.bean.RunInterval;
import com.clustercontrol.commons.bean.SettingUpdateInfo;
import com.clustercontrol.commons.util.JpaTransactionManager;
import com.clustercontrol.commons.util.MonitoredThreadPoolExecutor;
import com.clustercontrol.custom.util.CustomManagerUtil;
import com.clustercontrol.fault.FacilityNotFound;
import com.clustercontrol.fault.HinemosUnknown;
import com.clustercontrol.fault.InvalidRole;
import com.clustercontrol.fault.JobInfoNotFound;
import com.clustercontrol.fault.MonitorNotFound;
import com.clustercontrol.hinemosagent.util.AgentConnectUtil;
import com.clustercontrol.jobmanagement.bean.CommandConstant;
import com.clustercontrol.jobmanagement.bean.CommandStopTypeConstant;
import com.clustercontrol.jobmanagement.bean.CommandTypeConstant;
import com.clustercontrol.jobmanagement.bean.MonitorJobConstant;
import com.clustercontrol.jobmanagement.bean.QuartzConstant;
import com.clustercontrol.jobmanagement.bean.RunInstructionInfo;
import com.clustercontrol.jobmanagement.bean.RunResultInfo;
import com.clustercontrol.jobmanagement.bean.RunStatusConstant;
import com.clustercontrol.jobmanagement.factory.JobSessionJobImpl;
import com.clustercontrol.jobmanagement.model.JobInfoEntity;
import com.clustercontrol.jobmanagement.model.JobSessionJobEntity;
import com.clustercontrol.jobmanagement.session.JobRunManagementBean;
import com.clustercontrol.logfile.util.LogfileManagerUtil;
import com.clustercontrol.maintenance.util.HinemosPropertyUtil;
import com.clustercontrol.monitor.run.model.MonitorInfo;
import com.clustercontrol.plugin.impl.SchedulerPlugin;
import com.clustercontrol.plugin.impl.SchedulerPlugin.SchedulerType;
import com.clustercontrol.util.HinemosTime;
import com.clustercontrol.util.MessageConstant;
import com.clustercontrol.winevent.util.WinEventManagerUtil;

/**
 * HinemosManager??<BR>
 */
public class MonitorJobWorker {

    // Logger
    private static Log m_log = LogFactory.getLog(MonitorJobWorker.class);

    private static ExecutorService service;
    private static String workerName = "MonitorJobWorker";

    // ??ID?
    private static ConcurrentHashMap<String, ConcurrentHashMap<RunInstructionInfo, MonitorInfo>> monitorJobMap = new ConcurrentHashMap<>();

    // ????
    private static ConcurrentHashMap<RunInstructionInfo, Object> prevMonitorValueMap = new ConcurrentHashMap<>();

    static {
        int maxThreadPoolSize = HinemosPropertyUtil
                .getHinemosPropertyNum("job.monitor.thread.pool.size", Long.valueOf(5)).intValue();

        service = new MonitoredThreadPoolExecutor(maxThreadPoolSize, maxThreadPoolSize, 0L, TimeUnit.MICROSECONDS,
                new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
                    private volatile int _count = 0;

                    @Override
                    public Thread newThread(Runnable r) {
                        return new Thread(r, workerName + "-" + _count++);
                    }
                }, new ThreadPoolExecutor.AbortPolicy());

        // Map?
        monitorJobMap.put(HinemosModuleConstant.MONITOR_SYSTEMLOG,
                new ConcurrentHashMap<RunInstructionInfo, MonitorInfo>());
        monitorJobMap.put(HinemosModuleConstant.MONITOR_SNMPTRAP,
                new ConcurrentHashMap<RunInstructionInfo, MonitorInfo>());
        monitorJobMap.put(HinemosModuleConstant.MONITOR_LOGFILE,
                new ConcurrentHashMap<RunInstructionInfo, MonitorInfo>());
        monitorJobMap.put(HinemosModuleConstant.MONITOR_WINEVENT,
                new ConcurrentHashMap<RunInstructionInfo, MonitorInfo>());
        monitorJobMap.put(HinemosModuleConstant.MONITOR_CUSTOM_N,
                new ConcurrentHashMap<RunInstructionInfo, MonitorInfo>());
        monitorJobMap.put(HinemosModuleConstant.MONITOR_CUSTOM_S,
                new ConcurrentHashMap<RunInstructionInfo, MonitorInfo>());
        monitorJobMap.put(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N,
                new ConcurrentHashMap<RunInstructionInfo, MonitorInfo>());
        monitorJobMap.put(HinemosModuleConstant.MONITOR_CUSTOMTRAP_S,
                new ConcurrentHashMap<RunInstructionInfo, MonitorInfo>());
    }

    /**
     * ?
     * 
     * @param runInstructionInfo 
     */
    public static void runJob(RunInstructionInfo runInstructionInfo) {

        m_log.info("runJob() SessionID=" + runInstructionInfo.getSessionId() + ", JobunitID="
                + runInstructionInfo.getJobunitId() + ", JobID=" + runInstructionInfo.getJobId() + ", FacilityID="
                + runInstructionInfo.getFacilityId() + ", CommandType=" + runInstructionInfo.getCommandType());
        //?
        try {
            // ?
            service.execute(new JobMonitorTask(runInstructionInfo));
        } catch (Throwable e) {
            m_log.warn("runJob() Error : " + e.getMessage());
        }
    }

    /**
     * ?
     * 
     * @param runInstructionInfo 
     * @param priority 
     * @param messageOrg 
     * @param monitorTypeId ID
     */
    public static void endMonitorJob(RunInstructionInfo runInstructionInfo, String monitorTypeId, String message,
            String errorMessage, Integer status, Integer endValue) {

        // ?
        execJobEndNode(runInstructionInfo, status, message, errorMessage, endValue);

        if (monitorTypeId != null) {
            if (monitorTypeId.equals(HinemosModuleConstant.MONITOR_LOGFILE)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_SNMPTRAP)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_SYSTEMLOG)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_WINEVENT)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOM_N)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOM_S)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOMTRAP_S)) {
                // ?
                removeMonitorJobMap(monitorTypeId, runInstructionInfo);
            }

            if (monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOM_N)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_JMX)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_SNMP_N)
                    || monitorTypeId.equals(HinemosModuleConstant.MONITOR_PERFORMANCE)) {
                // ?
                removePrevMonitorValue(runInstructionInfo);
                // 
                if (!monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N)) {
                    try {
                        deleteSchedule(runInstructionInfo);
                    } catch (HinemosUnknown e) {
                        // ????
                        m_log.debug("schedule is not found.");
                    }
                }
            }
        }
        // 
        RunHistoryUtil.delRunHistory(runInstructionInfo);
    }

    /**
     * endNode()?
     * 
     * @param runInstructionInfo 
     * @param status 
     * @param endValue 
     * @param message 
     * @param errorMessage 
     * @return ??
     */
    private static boolean execJobEndNode(RunInstructionInfo runInstructionInfo, Integer status, String message,
            String errorMessage, Integer endValue) {

        boolean rtn = false;

        // ?
        RunResultInfo resultInfo = new RunResultInfo();
        resultInfo.setSessionId(runInstructionInfo.getSessionId());
        resultInfo.setJobunitId(runInstructionInfo.getJobunitId());
        resultInfo.setJobId(runInstructionInfo.getJobId());
        resultInfo.setFacilityId(runInstructionInfo.getFacilityId());
        resultInfo.setCommand(runInstructionInfo.getCommand());
        resultInfo.setCommandType(runInstructionInfo.getCommandType());
        resultInfo.setStopType(runInstructionInfo.getStopType());
        resultInfo.setStatus(status);
        resultInfo.setMessage(message);
        resultInfo.setErrorMessage(errorMessage);
        resultInfo.setTime(HinemosTime.getDateInstance().getTime());
        resultInfo.setEndValue(endValue);
        try {
            boolean isMonitorNestedEm = false;
            JpaTransactionManager jtm = new JpaTransactionManager();
            if (jtm.isNestedEm()) {
                // ??????
                isMonitorNestedEm = true;
                try {
                    jtm.commit(true);
                } catch (Throwable e) {
                    // ???????
                    m_log.error("execJobEndNode() jtm.commit ", e);
                } finally {
                    if (jtm != null) {
                        jtm.close();
                    }
                }
            }
            // ?
            rtn = new JobRunManagementBean().endNode(resultInfo);
            if (isMonitorNestedEm) {
                // 
                jtm = new JpaTransactionManager();
                jtm.begin();
            }
        } catch (HinemosUnknown | JobInfoNotFound | InvalidRole e) {
            m_log.error("endNode() is error : " + ", SessionID=" + runInstructionInfo.getSessionId()
                    + ", JobunitID=" + runInstructionInfo.getJobunitId() + ", JobID="
                    + runInstructionInfo.getJobId() + ", FacilityID=" + runInstructionInfo.getFacilityId());
        }
        return rtn;
    }

    /**
     * ??
     * @param runInstructionInfo 
     * @throws HinemosUnknown
     */
    public static void updateSchedule(RunInstructionInfo runInstructionInfo) throws HinemosUnknown {

        // null?
        if (runInstructionInfo == null) {
            HinemosUnknown e = new HinemosUnknown("runInstructionInfo is null.");
            m_log.warn("updateSchedule() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
            throw e;
        }

        //JobDetail????
        // ID
        Serializable[] jdArgs = new Serializable[1];
        @SuppressWarnings("unchecked")
        Class<? extends Serializable>[] jdArgsType = new Class[1];
        // 
        jdArgsType[0] = RunInstructionInfo.class;
        jdArgs[0] = runInstructionInfo;

        // 
        long startTime = HinemosTime.currentTimeMillis() + RunInterval.TYPE_MIN_01.toSec() * 1000;

        // SimpleTrigger ?
        SchedulerPlugin.scheduleSimpleJob(SchedulerType.RAM, getKey(runInstructionInfo),
                QuartzConstant.GROUP_NAME_FOR_MONITORJOB, startTime, RunInterval.TYPE_MIN_01.toSec(), true,
                JobRunManagementBean.class.getName(), QuartzConstant.METHOD_NAME_FOR_MONITORJOB, jdArgsType,
                jdArgs);
    }

    /**
     * ?
     * @param runInstructionInfo 
     * @throws HinemosUnknown
     */
    public static void deleteSchedule(RunInstructionInfo runInstructionInfo) throws HinemosUnknown {

        // null?
        if (runInstructionInfo == null) {
            HinemosUnknown e = new HinemosUnknown("runInstructionInfo is null.");
            m_log.warn("deleteSchedule() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
            throw e;
        }
        SchedulerPlugin.deleteJob(SchedulerType.RAM, getKey(runInstructionInfo),
                QuartzConstant.GROUP_NAME_FOR_MONITORJOB);
    }

    /**
     * ??
     * 
     * @param runInstructionInfo 
     * @return 
     */
    private static String getKey(RunInstructionInfo runInstructionInfo) {
        return runInstructionInfo.getSessionId() + runInstructionInfo.getJobunitId() + runInstructionInfo.getJobId()
                + runInstructionInfo.getFacilityId();
    }

    /**
     * ????
     * 
     * @param runInstructionInfo 
     * @param priority 
     * @return 
     */
    public static Integer getReturnValue(RunInstructionInfo runInstructionInfo, Integer priority) {
        try {
            // ?
            JobInfoEntity jobInfoEntity = QueryUtil.getJobInfoEntityPK(runInstructionInfo.getSessionId(),
                    runInstructionInfo.getJobunitId(), runInstructionInfo.getJobId());

            if (priority == null) {
                return jobInfoEntity.getMonitorUnknownEndValue();
            } else if (priority == PriorityConstant.TYPE_INFO) {
                return jobInfoEntity.getMonitorInfoEndValue();
            } else if (priority == PriorityConstant.TYPE_WARNING) {
                return jobInfoEntity.getMonitorWarnEndValue();
            } else if (priority == PriorityConstant.TYPE_CRITICAL) {
                return jobInfoEntity.getMonitorCriticalEndValue();
            } else {
                return jobInfoEntity.getMonitorUnknownEndValue();
            }
        } catch (JobInfoNotFound | InvalidRole e) {
            return MonitorJobConstant.INITIAL_END_VALUE_UNKNOWN;
        }
    }

    /**
     * ?
     * @param monitorTypeId ID
     * @return 
     */
    public static Map<RunInstructionInfo, MonitorInfo> getMonitorJobMap(String monitorTypeId) {
        return monitorJobMap.get(monitorTypeId);
    }

    /**
     * 
     * @param runInstructionInfo 
     * @param monitorInfo 
     */
    private static void addMonitorJobMap(RunInstructionInfo runInstructionInfo, MonitorInfo monitorInfo) {
        monitorJobMap.get(monitorInfo.getMonitorTypeId()).put(runInstructionInfo, monitorInfo);

        // ?HinemosAgent??
        if (monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_LOGFILE)) {
            // 
            SettingUpdateInfo.getInstance().setLogFileMonitorUpdateTime(HinemosTime.currentTimeMillis());
            LogfileManagerUtil.broadcastConfigured();
        } else if (monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_WINEVENT)) {
            // Windows
            SettingUpdateInfo.getInstance().setWinEventMonitorUpdateTime(HinemosTime.currentTimeMillis());
            WinEventManagerUtil.broadcastConfigured();
        } else if (monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_CUSTOM_N)
                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_CUSTOM_S)) {
            // ?HinemosAgent??
            SettingUpdateInfo.getInstance().setCustomMonitorUpdateTime(HinemosTime.currentTimeMillis());
            CustomManagerUtil.broadcastConfigured();
        }
    }

    /**
     * 
     * @param runInstructionInfo 
     */
    public static void removeMonitorJobMap(String monitorTypeId, RunInstructionInfo runInstructionInfo) {
        if (monitorJobMap.get(monitorTypeId) == null) {
            return;
        }

        for (Map.Entry<RunInstructionInfo, MonitorInfo> entry : monitorJobMap.get(monitorTypeId).entrySet()) {
            if (getKey(entry.getKey()).equals(getKey(runInstructionInfo))) {
                monitorJobMap.get(monitorTypeId).remove(entry.getKey());
                break;
            }
        }

        // ?HinemosAgent??
        if (monitorTypeId.equals(HinemosModuleConstant.MONITOR_LOGFILE)) {
            // 
            SettingUpdateInfo.getInstance().setLogFileMonitorUpdateTime(HinemosTime.currentTimeMillis());
            LogfileManagerUtil.broadcastConfigured();
        } else if (monitorTypeId.equals(HinemosModuleConstant.MONITOR_WINEVENT)) {
            // Windows
            SettingUpdateInfo.getInstance().setWinEventMonitorUpdateTime(HinemosTime.currentTimeMillis());
            WinEventManagerUtil.broadcastConfigured();
        } else if (monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOM_N)
                || monitorTypeId.equals(HinemosModuleConstant.MONITOR_CUSTOM_S)) {
            // ?HinemosAgent??
            SettingUpdateInfo.getInstance().setCustomMonitorUpdateTime(HinemosTime.currentTimeMillis());
            CustomManagerUtil.broadcastConfigured();
        }
    }

    /**
     * ??
     * @param runInstructionInfo 
     * @return ?
     */
    public static Object getPrevMonitorValue(RunInstructionInfo runInstructionInfo) {
        return prevMonitorValueMap.get(runInstructionInfo);
    }

    /**
     * ?
     * @param runInstructionInfo 
     * @param prevMonitorVale ?
     */
    public static void addPrevMonitorValue(RunInstructionInfo runInstructionInfo, Object prevMonitorValue) {
        prevMonitorValueMap.put(runInstructionInfo, prevMonitorValue);
    }

    /**
     * ?
     * @param runInstructionInfo 
     */
    public static void removePrevMonitorValue(RunInstructionInfo runInstructionInfo) {
        for (Map.Entry<RunInstructionInfo, Object> entry : prevMonitorValueMap.entrySet()) {
            if (getKey(entry.getKey()).equals(getKey(runInstructionInfo))) {
                prevMonitorValueMap.remove(entry.getKey());
                break;
            }
        }
        prevMonitorValueMap.remove(runInstructionInfo);
    }

    /**
     * 
     * @param sessionId ID
     */
    public static void removeInfoBySessionId(String sessionId) {
        if (sessionId == null || sessionId.isEmpty()) {
            return;
        }

        /**  */
        List<RunInstructionInfo> runInstructionInfoList = RunHistoryUtil.findRunHistoryBySessionId(sessionId);
        for (RunInstructionInfo runInstructionInfo : runInstructionInfoList) {
            try {
                deleteSchedule(runInstructionInfo);
            } catch (HinemosUnknown e) {
                // ????
                m_log.debug("schedule is not found.");
            }
        }

        /**  */
        HashSet<String> keySet = new HashSet<>();
        for (Map.Entry<String, ConcurrentHashMap<RunInstructionInfo, MonitorInfo>> entry : monitorJobMap
                .entrySet()) {
            for (Map.Entry<RunInstructionInfo, MonitorInfo> childEntry : entry.getValue().entrySet()) {
                if (sessionId.equals(childEntry.getKey().getSessionId())) {
                    monitorJobMap.get(childEntry.getValue().getMonitorTypeId()).remove(childEntry.getKey());
                    keySet.add(childEntry.getValue().getMonitorTypeId());
                }
            }
        }

        // ?HinemosAgent??
        if (keySet.contains(HinemosModuleConstant.MONITOR_LOGFILE)) {
            // 
            SettingUpdateInfo.getInstance().setLogFileMonitorUpdateTime(HinemosTime.currentTimeMillis());
            LogfileManagerUtil.broadcastConfigured();
        } else if (keySet.contains(HinemosModuleConstant.MONITOR_WINEVENT)) {
            // Windows
            SettingUpdateInfo.getInstance().setWinEventMonitorUpdateTime(HinemosTime.currentTimeMillis());
            WinEventManagerUtil.broadcastConfigured();
        } else if (keySet.contains(HinemosModuleConstant.MONITOR_CUSTOM_N)
                || keySet.contains(HinemosModuleConstant.MONITOR_CUSTOM_S)) {
            // ?HinemosAgent??
            SettingUpdateInfo.getInstance().setCustomMonitorUpdateTime(HinemosTime.currentTimeMillis());
            CustomManagerUtil.broadcastConfigured();
        }

        /** ? */
        for (Map.Entry<RunInstructionInfo, Object> entry : prevMonitorValueMap.entrySet()) {
            if (sessionId.equals(entry.getKey().getSessionId())) {
                prevMonitorValueMap.remove(entry.getKey());
            }
        }

        /** RunHistory */
        for (RunInstructionInfo runInstructionInfo : runInstructionInfoList) {
            RunHistoryUtil.delRunHistory(runInstructionInfo);
        }
    }

    /**
     * ??
     */
    private static class JobMonitorTask extends Thread {

        // Logger
        static private Log m_log = LogFactory.getLog(JobMonitorTask.class);

        // 
        private RunInstructionInfo m_runInstructionInfo = null;

        /**
         * 
         * 
         * @param runInstructionInfo 
         */
        public JobMonitorTask(RunInstructionInfo runInstructionInfo) {
            // 
            this.m_runInstructionInfo = runInstructionInfo;
        }

        /**
         * ?<BR>
         */
        @Override
        public void run() {

            m_log.info("run() SessionID=" + this.m_runInstructionInfo.getSessionId() + ", JobunitID="
                    + this.m_runInstructionInfo.getJobunitId() + ", JobID=" + this.m_runInstructionInfo.getJobId()
                    + ", FacilityID=" + this.m_runInstructionInfo.getFacilityId() + ", CommandType="
                    + this.m_runInstructionInfo.getCommandType());

            JpaTransactionManager jtm = null;
            MonitorInfo monitorInfo = null;
            JobSessionJobEntity sessionJob = null;
            JobInfoEntity jobInfoEntity = null;
            try {
                jtm = new JpaTransactionManager();
                jtm.begin();

                // ??
                //ID?ID???
                sessionJob = QueryUtil.getJobSessionJobPK(m_runInstructionInfo.getSessionId(),
                        m_runInstructionInfo.getJobunitId(), m_runInstructionInfo.getJobId());
                jobInfoEntity = sessionJob.getJobInfoEntity();
                // ??
                monitorInfo = com.clustercontrol.monitor.run.util.QueryUtil
                        .getMonitorInfoPK_OR(jobInfoEntity.getMonitorId(), sessionJob.getOwnerRoleId());

                if (RunHistoryUtil.findRunHistory(m_runInstructionInfo) == null) {
                    if (m_runInstructionInfo.getCommand().equals(CommandConstant.MONITOR)) {
                        // ?
                        if (!execJobEndNode(m_runInstructionInfo, RunStatusConstant.START, "", "",
                                MonitorJobConstant.INITIAL_END_VALUE_INFO)) {
                            // ????????
                            m_log.warn("This job already run by other agent. " + "SessionID="
                                    + m_runInstructionInfo.getSessionId() + ", JobunitID="
                                    + m_runInstructionInfo.getJobunitId() + ", JobID="
                                    + m_runInstructionInfo.getJobId() + ", FacilityID="
                                    + m_runInstructionInfo.getFacilityId());
                            return;
                        }
                        // Hinemos????Hinemos???????
                        if ((monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_LOGFILE)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_WINEVENT)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_CUSTOM_N)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_CUSTOM_S))
                                && !AgentConnectUtil.isValidAgent(m_runInstructionInfo.getFacilityId())) {
                            // ?
                            execJobEndNode(m_runInstructionInfo, RunStatusConstant.ERROR, "",
                                    MessageConstant.MESSAGE_AGENT_IS_NOT_AVAILABLE.getMessage(),
                                    getReturnValue(m_runInstructionInfo, PriorityConstant.TYPE_UNKNOWN));
                            return;
                        }

                        // ?
                        RunHistoryUtil.addRunHistory(m_runInstructionInfo);
                        // 
                        if (monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_SYSTEMLOG)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_SNMPTRAP)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_LOGFILE)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_WINEVENT)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_CUSTOM_N)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_CUSTOM_S)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N)
                                || monitorInfo.getMonitorTypeId()
                                        .equals(HinemosModuleConstant.MONITOR_CUSTOMTRAP_S)) {
                            // ??
                            addMonitorJobMap(m_runInstructionInfo, monitorInfo);
                        } else {
                            // ?
                            new JobRunManagementBean().runMonitorJob(m_runInstructionInfo);
                        }

                        // ?????
                        if (monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_SYSTEMLOG)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_SNMPTRAP)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_LOGFILE)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_WINEVENT)
                                || monitorInfo.getMonitorTypeId().equals(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N)
                                || monitorInfo.getMonitorTypeId()
                                        .equals(HinemosModuleConstant.MONITOR_CUSTOMTRAP_S)) {
                            JobSessionJobImpl.addForceCheck(m_runInstructionInfo.getSessionId());
                        }
                    } else {
                        //?????
                        m_log.warn("runJob() : command is not specified correctly.");
                    }
                } else {
                    // ??
                    if (m_runInstructionInfo.getCommandType() == CommandTypeConstant.STOP
                            && m_runInstructionInfo.getStopType() == CommandStopTypeConstant.DESTROY_PROCESS) {

                        // ????????
                        if (RunHistoryUtil.findRunHistory(m_runInstructionInfo) == null) {
                            // ?
                            endMonitorJob(m_runInstructionInfo, null,
                                    "Internal Error : Ex. Job already terminated.", "", RunStatusConstant.ERROR,
                                    getReturnValue(m_runInstructionInfo, PriorityConstant.TYPE_UNKNOWN));
                        } else {
                            // ?
                            if (!execJobEndNode(m_runInstructionInfo, RunStatusConstant.START, "", "",
                                    MonitorJobConstant.INITIAL_END_VALUE_INFO)) {
                                // ????????
                                m_log.warn("This job already run by other. " + ", SessionID="
                                        + m_runInstructionInfo.getSessionId() + ", JobunitID="
                                        + m_runInstructionInfo.getJobunitId() + ", JobID="
                                        + m_runInstructionInfo.getJobId() + ", FacilityID="
                                        + m_runInstructionInfo.getFacilityId());
                                return;
                            }

                            // ?
                            // ?
                            endMonitorJob(m_runInstructionInfo, monitorInfo.getMonitorTypeId(), "", "",
                                    RunStatusConstant.END, MonitorJobConstant.INITIAL_END_VALUE_INFO);
                        }
                    }
                }
                // ?
                jtm.commit();

            } catch (JobInfoNotFound | InvalidRole | MonitorNotFound | FacilityNotFound | HinemosUnknown e) {
                // ?
                // ?
                String monitorTypeId = null;
                if (monitorInfo != null) {
                    monitorTypeId = monitorInfo.getMonitorTypeId();
                }
                endMonitorJob(m_runInstructionInfo, monitorTypeId, "", e.getMessage(), RunStatusConstant.ERROR,
                        getReturnValue(m_runInstructionInfo, PriorityConstant.TYPE_UNKNOWN));
                if (jtm != null)
                    jtm.rollback();
            } finally {
                if (jtm != null)
                    jtm.close();
            }
        }
    }

}