Java tutorial
/* Copyright (C) 2006 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.factory; import java.util.List; import javax.persistence.EntityExistsException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.clustercontrol.bean.StatusConstant; import com.clustercontrol.commons.util.JpaTransactionManager; import com.clustercontrol.fault.FacilityNotFound; import com.clustercontrol.fault.HinemosUnknown; import com.clustercontrol.fault.InvalidRole; import com.clustercontrol.fault.JobInfoNotFound; import com.clustercontrol.jobmanagement.bean.JobConstant; import com.clustercontrol.jobmanagement.model.JobSessionJobEntity; import com.clustercontrol.jobmanagement.model.JobSessionNodeEntity; import com.clustercontrol.jobmanagement.util.FromRunningAfterCommitCallback; import com.clustercontrol.jobmanagement.util.JobMultiplicityCache; import com.clustercontrol.jobmanagement.util.QueryUtil; import com.clustercontrol.util.HinemosTime; import com.clustercontrol.util.MessageConstant; /** * ???[]??? * * */ public class OperateForceStopOfJob { /** ? */ private static Log m_log = LogFactory.getLog(OperateForceStopOfJob.class); /** * */ public OperateForceStopOfJob() { super(); } /** * ?[]??? * * @param sessionId ID * @param jobunitId ?ID * @param jobId ID * @param facilityId ID * @param endValue * @throws JobInfoNotFound * @throws InvalidRole * @throws HinemosUnknown */ public void forceStopNode(String sessionId, String jobunitId, String jobId, String facilityId, Integer endValue) throws JobInfoNotFound, InvalidRole, HinemosUnknown { m_log.debug("forceStopJob() : sessionId=" + sessionId + ", jobunitId=" + jobunitId + ", jobId=" + jobId + ", facilityId=" + facilityId + ", endValue=" + endValue); forceStopNode2(sessionId, jobunitId, jobId, facilityId, endValue); //? try { new JobSessionNodeImpl().endNodeFinish(sessionId, jobunitId, jobId, facilityId, null, null); } catch (EntityExistsException e) { // TODO // throw?ExceptionHinemosUnknown?????????? m_log.warn("maintenanceNode " + e, e); throw new HinemosUnknown(e.getMessage(), e); } catch (FacilityNotFound e) { m_log.warn("maintenanceNode " + e, e); throw new HinemosUnknown(e.getMessage(), e); } } private void forceStopNode2(String sessionId, String jobunitId, String jobId, String facilityId, Integer endValue) throws JobInfoNotFound, InvalidRole, HinemosUnknown { m_log.debug("forceStopJob2() : sessionId=" + sessionId + ", jobunitId=" + jobunitId + ", jobId=" + jobId + ", facilityId=" + facilityId + ", endValue=" + endValue); //ID?ID??? JobSessionNodeEntity sessionNode = QueryUtil.getJobSessionNodePK(sessionId, jobunitId, jobId, facilityId); // ???????????JobOperationJudgement.java if (sessionNode.getStatus() != StatusConstant.TYPE_WAIT && sessionNode.getStatus() != StatusConstant.TYPE_STOPPING) { return; } //?????????? if (sessionNode.getStatus() == StatusConstant.TYPE_RUNNING) { JpaTransactionManager jtm = new JpaTransactionManager(); jtm.addCallback(new FromRunningAfterCommitCallback(sessionNode.getId())); } else if (sessionNode.getStatus() == StatusConstant.TYPE_WAIT) { JobMultiplicityCache.removeWait(sessionNode.getId()); } //?? sessionNode.setStatus(StatusConstant.TYPE_END); // sessionNode.setEndValue(endValue); // sessionNode.setEndDate(HinemosTime.currentTimeMillis()); // new JobSessionNodeImpl().setMessage(sessionNode, MessageConstant.JOB_STOP_FORCE.getMessage()); } /** * ?[]??? * * @param sessionId ID * @param jobunitId ?ID * @param jobId ID * @param facilityId ID * @param endValue * @throws JobInfoNotFound * @throws InvalidRole * @throws HinemosUnknown * @throws FacilityNotFound */ public void forceStopJob(String sessionId, String jobunitId, String jobId, Integer endStatus, Integer endValue) throws JobInfoNotFound, InvalidRole, HinemosUnknown, FacilityNotFound { m_log.debug("forceStopJob() : sessionId=" + sessionId + ", jobunitId=" + jobunitId + ", jobId=" + jobId + ", endValue=" + endValue); forceStopJob2(sessionId, jobunitId, jobId, endStatus, endValue); //?(??) new JobSessionJobImpl().endJob(sessionId, jobunitId, jobId, null, false); } private void forceStopJob2(String sessionId, String jobunitId, String jobId, Integer endStatus, Integer endValue) throws JobInfoNotFound, InvalidRole, HinemosUnknown { m_log.debug("forceStopJob2() : sessionId=" + sessionId + ", jobunitId=" + jobunitId + ", jobId=" + jobId + ", endValue=" + endValue); //ID?ID??? JobSessionJobEntity sessionJob = QueryUtil.getJobSessionJobPK(sessionId, jobunitId, jobId); // ???????????JobOperationJudgement.java if (sessionJob.getStatus() != StatusConstant.TYPE_WAIT && sessionJob.getStatus() != StatusConstant.TYPE_STOPPING) { return; } if (sessionJob.getJobInfoEntity().getJobType() != JobConstant.TYPE_JOB && sessionJob.getJobInfoEntity().getJobType() != JobConstant.TYPE_APPROVALJOB && sessionJob.getJobInfoEntity().getJobType() != JobConstant.TYPE_MONITORJOB) { // ???? List<JobSessionJobEntity> childJob = QueryUtil.getChildJobSessionJob(sessionId, jobunitId, jobId); for (JobSessionJobEntity job : childJob) { forceStopJob2(sessionId, jobunitId, job.getId().getJobId(), endStatus, endValue); } } else { // ???? List<JobSessionNodeEntity> nodeJobList = sessionJob.getJobSessionNodeEntities(); for (JobSessionNodeEntity node : nodeJobList) { if (!StatusConstant.isEndGroup(node.getStatus())) { forceStopNode2(sessionId, jobunitId, jobId, node.getId().getFacilityId(), endValue); } } } //?? sessionJob.setStatus(StatusConstant.TYPE_END); sessionJob.setEndStatus(endStatus); sessionJob.setEndValue(endValue); sessionJob.setEndDate(HinemosTime.currentTimeMillis()); } }