com.clustercontrol.jobmanagement.factory.OperateMaintenanceOfJob.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.jobmanagement.factory.OperateMaintenanceOfJob.java

Source

/*
    
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 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.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;

/**
 * ???[]???
 *
 * @version 2.1.0
 * @since 2.1.0
 */
public class OperateMaintenanceOfJob {
    /** ? */
    private static Log m_log = LogFactory.getLog(OperateMaintenanceOfJob.class);

    /**
     * 
     */
    public OperateMaintenanceOfJob() {
        super();
    }

    /**
     * ?[]???
     * 
     * @param sessionId ID
     * @param jobunitId ?ID
     * @param jobId ID
     * @param facilityId ID
     * @param endValue 
     * @throws JobInfoNotFound
     * @throws InvalidRole
     * @throws HinemosUnknown
     */
    public void maintenanceNode(String sessionId, String jobunitId, String jobId, String facilityId,
            Integer endValue) throws JobInfoNotFound, InvalidRole, HinemosUnknown {
        m_log.debug("maintenanceJob() : sessionId=" + sessionId + ", jobunitId=" + jobunitId + ", jobId=" + jobId
                + ", facilityId=" + facilityId + ", endValue=" + endValue);

        //ID?ID???
        JobSessionNodeEntity sessionNode = QueryUtil.getJobSessionNodePK(sessionId, jobunitId, jobId, facilityId);

        if (sessionNode != null) {
            //??????????
            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_MODIFIED);
            //
            sessionNode.setEndValue(endValue);
            //
            sessionNode.setEndDate(HinemosTime.currentTimeMillis());
            //?
            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);
            }
        }
    }

    /**
     * ?[]???
     * 
     * @param sessionId ID
     * @param jobunitId ?ID
     * @param jobId ID
     * @param facilityId ID
     * @param endValue 
     * @throws JobInfoNotFound
     * @throws InvalidRole
     * @throws HinemosUnknown
     * @throws FacilityNotFound 
     */
    public void maintenanceJob(String sessionId, String jobunitId, String jobId, Integer status, Integer endStatus,
            Integer endValue) throws JobInfoNotFound, InvalidRole, HinemosUnknown, FacilityNotFound {
        m_log.debug("maintenanceJob() : sessionId=" + sessionId + ", jobunitId=" + jobunitId + ", jobId=" + jobId
                + ", endStatus=" + endStatus + ", endValue=" + endValue);

        //ID?ID???
        JobSessionJobEntity sessionJob = QueryUtil.getJobSessionJobPK(sessionId, jobunitId, jobId);

        if (sessionJob != null) {
            //??
            sessionJob.setStatus(status);
            //
            sessionJob.setEndStatus(endStatus);
            //
            sessionJob.setEndValue(endValue);
            //
            sessionJob.setEndDate(HinemosTime.currentTimeMillis());
            //?
            new JobSessionJobImpl().endJob(sessionId, jobunitId, jobId, null, false);
        }
    }
}