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.sla;
020
021import org.apache.oozie.command.sla.SLACoordActionJobEventXCommand;
022import org.apache.oozie.command.sla.SLACoordActionJobHistoryXCommand;
023import org.apache.oozie.command.sla.SLAJobEventXCommand;
024import org.apache.oozie.command.sla.SLAJobHistoryXCommand;
025import org.apache.oozie.command.sla.SLAWorkflowActionJobEventXCommand;
026import org.apache.oozie.command.sla.SLAWorkflowActionJobHistoryXCommand;
027import org.apache.oozie.command.sla.SLAWorkflowJobEventXCommand;
028import org.apache.oozie.command.sla.SLAWorkflowJobHistoryXCommand;
029
030/**
031 * A factory for creating SLACommand objects.
032 */
033public class SLAXCommandFactory {
034
035    /**
036     * Gets the SLA job history  command.
037     *
038     * @param jobId the job id
039     * @return the SLA job history x command
040     */
041    public static SLAJobHistoryXCommand getSLAJobHistoryXCommand(String jobId) {
042        if (jobId.endsWith("-W")) {
043            return new SLAWorkflowJobHistoryXCommand(jobId);
044        }
045        else if (jobId.contains("-W@")) {
046            return new SLAWorkflowActionJobHistoryXCommand(jobId);
047
048        }
049        else if (jobId.contains("-C@")) {
050            return new SLACoordActionJobHistoryXCommand(jobId);
051        }
052
053        else {
054            return null;
055        }
056    }
057
058    /**
059     * Gets the SLAevent  command.
060     *
061     * @param slaCalc the sla calc
062     * @return the SLA event x command
063     */
064    public static SLAJobEventXCommand getSLAEventXCommand(SLACalcStatus slaCalc) {
065        return getSLAEventXCommand(slaCalc, 0);
066    }
067
068    /**
069     * Gets the SLA event x command.
070     *
071     * @param slaCalc the sla calc
072     * @param lockTimeOut the lock time out
073     * @return the SLA event x command
074     */
075    public static SLAJobEventXCommand getSLAEventXCommand(SLACalcStatus slaCalc, long lockTimeOut) {
076        if (slaCalc.getId().endsWith("-W")) {
077            return new SLAWorkflowJobEventXCommand(slaCalc, lockTimeOut);
078        }
079        else if (slaCalc.getId().contains("-W@")) {
080            return new SLAWorkflowActionJobEventXCommand(slaCalc, lockTimeOut);
081
082        }
083        else if (slaCalc.getId().contains("-C@")) {
084            return new SLACoordActionJobEventXCommand(slaCalc, lockTimeOut);
085        }
086
087        else {
088            return null;
089        }
090    }
091
092}