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 */
018package org.apache.oozie.executor.jpa.sla;
019
020import java.util.Date;
021
022import javax.persistence.EntityManager;
023import javax.persistence.Query;
024
025import org.apache.oozie.ErrorCode;
026import org.apache.oozie.executor.jpa.JPAExecutor;
027import org.apache.oozie.executor.jpa.JPAExecutorException;
028import org.apache.oozie.sla.SLASummaryBean;
029import org.apache.oozie.util.ParamChecker;
030
031/**
032 * Update the slaStatus, eventStatus, eventProcessed, jobStatus, actualStart,
033 * actualEnd, actualDuration and lastModifiedTime of SLAsummaryBean
034 */
035public class SLASummaryUpdateForSLAStatusActualTimesJPAExecutor implements JPAExecutor<Void> {
036
037    private SLASummaryBean slaSummaryBean = null;
038
039    public SLASummaryUpdateForSLAStatusActualTimesJPAExecutor(SLASummaryBean slaSummaryBean) {
040        ParamChecker.notNull(slaSummaryBean, "slaSummaryBean");
041        this.slaSummaryBean = slaSummaryBean;
042    }
043
044    /*
045     * (non-Javadoc)
046     *
047     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.
048     * EntityManager)
049     */
050    @Override
051    public Void execute(EntityManager em) throws JPAExecutorException {
052        try {
053            Query q = em.createNamedQuery("UPDATE_SLA_SUMMARY_FOR_STATUS_ACTUAL_TIMES");
054            q.setParameter("jobId", slaSummaryBean.getId());
055            q.setParameter("slaStatus", slaSummaryBean.getSLAStatusString());
056            q.setParameter("lastModifiedTS", new Date());
057            q.setParameter("eventStatus", slaSummaryBean.getEventStatusString());
058            q.setParameter("jobStatus", slaSummaryBean.getJobStatus());
059            q.setParameter("eventProcessed", slaSummaryBean.getEventProcessed());
060            q.setParameter("actualStartTS", slaSummaryBean.getActualStart());
061            q.setParameter("actualEndTS", slaSummaryBean.getActualEnd());
062            q.setParameter("actualDuration", slaSummaryBean.getActualDuration());
063            q.executeUpdate();
064            return null;
065        }
066        catch (Exception e) {
067            throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
068        }
069    }
070
071    /*
072     * (non-Javadoc)
073     *
074     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
075     */
076    @Override
077    public String getName() {
078        return "SLASummaryUpdateForSLAStatusActualTimesJPAExecutor";
079    }
080}