001 /**
002 * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
003 * Licensed under the Apache License, Version 2.0 (the "License");
004 * you may not use this file except in compliance with the License.
005 * You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software
010 * distributed under the License is distributed on an "AS IS" BASIS,
011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 * See the License for the specific language governing permissions and
013 * limitations under the License. See accompanying LICENSE file.
014 */
015 package org.apache.oozie.service;
016
017 import org.apache.oozie.store.StoreException;
018 import org.apache.oozie.service.Service;
019 import org.apache.oozie.store.Store;
020 import org.apache.oozie.store.CoordinatorStore;
021 import org.apache.oozie.ErrorCode;
022
023 /**
024 * Base service for persistency of jobs and actions.
025 */
026 public class CoordinatorStoreService implements Service {
027
028 public final static String TRANSIENT_VAR_PREFIX = "oozie.coordinator.";
029 public static final String WORKFLOW_BEAN = TRANSIENT_VAR_PREFIX
030 + "coordinator.bean";
031 final static String ACTION_ID = "action.id";
032 final static String ACTIONS_TO_KILL = TRANSIENT_VAR_PREFIX
033 + "actions.to.kill";
034 final static String ACTIONS_TO_FAIL = TRANSIENT_VAR_PREFIX
035 + "actions.to.fail";
036 final static String ACTIONS_TO_START = TRANSIENT_VAR_PREFIX
037 + "actions.to.start";
038
039 /**
040 * Return the public interface of the service.
041 *
042 * @return {@link WorkflowStoreService}.
043 */
044 public Class<? extends Service> getInterface() {
045 return CoordinatorStoreService.class;
046 }
047
048 /**
049 * Return a workflow store instance with a fresh transaction. <p/> The coordinator store has to be committed and then
050 * closed to commit changes, if only close it rolls back.
051 *
052 * @return a coordinator store.
053 * @throws StoreException thrown if the workflow store could not be created.
054 */
055 public CoordinatorStore create() throws StoreException {
056 try {
057 return new CoordinatorStore(false);
058 }
059 catch (Exception ex) {
060 throw new StoreException(ErrorCode.E0600, ex.getMessage(), ex);
061 }
062 }
063
064 /**
065 * Return a workflow store instance with an existing transaction. <p/> The workflow store has to be committed and then
066 * closed to commit changes, if only close it rolls back.
067 *
068 * @return a workflow store.
069 * @throws StoreException thrown if the workflow store could not be created.
070 */
071 // to do this method can be abstract or should be overridden
072 public <S extends Store> CoordinatorStore create(S store)
073 throws StoreException {
074 try {
075 return new CoordinatorStore(store, false);
076 }
077 catch (Exception ex) {
078 throw new StoreException(ErrorCode.E0600, ex.getMessage(), ex);
079 }
080 }
081
082 /**
083 * Initializes the {@link StoreService}.
084 *
085 * @param services services instance.
086 */
087 public void init(Services services) throws ServiceException {
088 }
089
090 /**
091 * Destroy the StoreService
092 */
093 public void destroy() {
094 }
095 }