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
019package org.apache.oozie.command.sla;
020
021import org.apache.oozie.WorkflowJobBean;
022import org.apache.oozie.client.WorkflowJob;
023import org.apache.oozie.command.CommandException;
024import org.apache.oozie.executor.jpa.JPAExecutorException;
025import org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor;
026import org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery;
027import org.apache.oozie.sla.SLACalcStatus;
028import org.apache.oozie.util.LogUtils;
029
030public class SLAWorkflowJobEventXCommand extends SLAJobEventXCommand {
031    WorkflowJobBean wf;
032
033    public SLAWorkflowJobEventXCommand(SLACalcStatus slaCalc, long lockTimeOut) {
034        super(slaCalc, lockTimeOut);
035    }
036
037    @Override
038    protected void loadState() throws CommandException {
039        try {
040            wf = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_FOR_SLA, slaCalc.getId());
041        }
042        catch (JPAExecutorException e) {
043            throw new CommandException(e);
044        }
045        LogUtils.setLogInfo(wf);
046
047    }
048
049
050    @Override
051    protected void updateJobInfo() {
052        if (wf.inTerminalState()) {
053            setEnded(true);
054            if (wf.getStatus() == WorkflowJob.Status.KILLED || wf.getStatus() == WorkflowJob.Status.FAILED
055                    || wf.getEndTime().getTime() > slaCalc.getExpectedEnd().getTime()) {
056                setEndMiss(true);
057            }
058            slaCalc.setActualEnd(wf.getEndTime());
059        }
060        slaCalc.setActualStart(wf.getStartTime());
061        slaCalc.setJobStatus(wf.getStatusStr());
062    }
063
064}