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 java.util.Date;
022import java.util.Iterator;
023import java.util.List;
024import java.util.Map;
025
026import org.apache.hadoop.conf.Configuration;
027import org.apache.oozie.client.event.JobEvent.EventStatus;
028import org.apache.oozie.executor.jpa.JPAExecutorException;
029import org.apache.oozie.service.ServiceException;
030import org.apache.oozie.util.Pair;
031
032public interface SLACalculator {
033
034    void init(Configuration conf) throws ServiceException;
035
036    int size();
037
038    Iterator<String> iterator();
039
040    boolean isEmpty();
041
042    boolean addRegistration(String jobId, SLARegistrationBean reg) throws JPAExecutorException;
043
044    boolean updateRegistration(String jobId, SLARegistrationBean reg) throws JPAExecutorException;
045
046    void removeRegistration(String jobId);
047
048    boolean addJobStatus(String jobId, String jobStatus, EventStatus jobEventStatus, Date startTime, Date endTime)
049            throws JPAExecutorException, ServiceException;
050
051    void updateAllSlaStatus();
052
053    void clear();
054
055    SLACalcStatus get(String jobId) throws JPAExecutorException;
056
057    /**
058     * Enable jobs sla alert.
059     *
060     * @param jobId the job ids
061     * @return true, if successful
062     * @throws JPAExecutorException the JPA executor exception
063     * @throws ServiceException the service exception
064     */
065    boolean enableAlert(List<String> jobId) throws JPAExecutorException, ServiceException;
066
067    /**
068     * Enable sla alert for child jobs.
069     * @param parentJobIds the parent job ids
070     * @return
071     * @throws JPAExecutorException
072     * @throws ServiceException
073     */
074    boolean enableChildJobAlert(List<String> parentJobIds) throws JPAExecutorException, ServiceException;
075
076    /**
077     * Disable jobs Sla alert.
078     *
079     * @param jobId the job ids
080     * @return true, if successful
081     * @throws JPAExecutorException the JPA executor exception
082     * @throws ServiceException the service exception
083     */
084    boolean disableAlert(List<String> jobId) throws JPAExecutorException, ServiceException;
085
086
087    /**
088     * Disable Sla alert for child jobs.
089     * @param parentJobIds the parent job ids
090     * @return
091     * @throws JPAExecutorException
092     * @throws ServiceException
093     */
094    boolean disableChildJobAlert(List<String> parentJobIds) throws JPAExecutorException, ServiceException;
095
096    /**
097     * Change jobs Sla definitions
098     * It takes list of pairs of jobid and key/value pairs of el evaluated sla definition.
099     * Support definition are sla-should-start, sla-should-end, sla-nominal-time and sla-max-duration.
100     *
101     * @param jobIdsSLAPair the job ids sla pair
102     * @return true, if successful
103     * @throws JPAExecutorException the JPA executor exception
104     * @throws ServiceException the service exception
105     */
106    boolean changeDefinition(List<Pair<String, Map<String,String>>> jobIdsSLAPair ) throws JPAExecutorException,
107            ServiceException;
108}