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 package org.apache.oozie.service; 019 020 import org.apache.oozie.store.StoreException; 021 import org.apache.oozie.service.Service; 022 import org.apache.oozie.store.Store; 023 import org.apache.oozie.store.CoordinatorStore; 024 import org.apache.oozie.ErrorCode; 025 026 /** 027 * Base service for persistency of jobs and actions. 028 */ 029 public class CoordinatorStoreService implements Service { 030 031 public final static String TRANSIENT_VAR_PREFIX = "oozie.coordinator."; 032 public static final String WORKFLOW_BEAN = TRANSIENT_VAR_PREFIX 033 + "coordinator.bean"; 034 final static String ACTION_ID = "action.id"; 035 final static String ACTIONS_TO_KILL = TRANSIENT_VAR_PREFIX 036 + "actions.to.kill"; 037 final static String ACTIONS_TO_FAIL = TRANSIENT_VAR_PREFIX 038 + "actions.to.fail"; 039 final static String ACTIONS_TO_START = TRANSIENT_VAR_PREFIX 040 + "actions.to.start"; 041 042 /** 043 * Return the public interface of the service. 044 * 045 * @return {@link WorkflowStoreService}. 046 */ 047 public Class<? extends Service> getInterface() { 048 return CoordinatorStoreService.class; 049 } 050 051 /** 052 * Return a workflow store instance with a fresh transaction. <p/> The coordinator store has to be committed and then 053 * closed to commit changes, if only close it rolls back. 054 * 055 * @return a coordinator store. 056 * @throws StoreException thrown if the workflow store could not be created. 057 */ 058 public CoordinatorStore create() throws StoreException { 059 try { 060 return new CoordinatorStore(false); 061 } 062 catch (Exception ex) { 063 throw new StoreException(ErrorCode.E0600, ex.getMessage(), ex); 064 } 065 } 066 067 /** 068 * Return a workflow store instance with an existing transaction. <p/> The workflow store has to be committed and then 069 * closed to commit changes, if only close it rolls back. 070 * 071 * @return a workflow store. 072 * @throws StoreException thrown if the workflow store could not be created. 073 */ 074 // to do this method can be abstract or should be overridden 075 public <S extends Store> CoordinatorStore create(S store) 076 throws StoreException { 077 try { 078 return new CoordinatorStore(store, false); 079 } 080 catch (Exception ex) { 081 throw new StoreException(ErrorCode.E0600, ex.getMessage(), ex); 082 } 083 } 084 085 /** 086 * Initializes the {@link StoreService}. 087 * 088 * @param services services instance. 089 */ 090 public void init(Services services) throws ServiceException { 091 } 092 093 /** 094 * Destroy the StoreService 095 */ 096 public void destroy() { 097 } 098 }