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.hadoop.ha;
019
020 import org.apache.hadoop.classification.InterfaceAudience;
021 import org.apache.hadoop.classification.InterfaceStability;
022 import org.apache.hadoop.fs.CommonConfigurationKeys;
023 import org.apache.hadoop.io.retry.Idempotent;
024 import org.apache.hadoop.security.AccessControlException;
025 import org.apache.hadoop.security.KerberosInfo;
026
027 import java.io.IOException;
028
029 /**
030 * Protocol interface that provides High Availability related primitives to
031 * monitor and fail-over the service.
032 *
033 * This interface could be used by HA frameworks to manage the service.
034 */
035 @KerberosInfo(
036 serverPrincipal=CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY)
037 @InterfaceAudience.Public
038 @InterfaceStability.Evolving
039 public interface HAServiceProtocol {
040 /**
041 * Initial version of the protocol
042 */
043 public static final long versionID = 1L;
044
045 /**
046 * An HA service may be in active or standby state. During
047 * startup, it is in an unknown INITIALIZING state.
048 */
049 public enum HAServiceState {
050 INITIALIZING("initializing"),
051 ACTIVE("active"),
052 STANDBY("standby");
053
054 private String name;
055
056 HAServiceState(String name) {
057 this.name = name;
058 }
059
060 @Override
061 public String toString() {
062 return name;
063 }
064 }
065
066 public static enum RequestSource {
067 REQUEST_BY_USER,
068 REQUEST_BY_USER_FORCED,
069 REQUEST_BY_ZKFC;
070 }
071
072 /**
073 * Information describing the source for a request to change state.
074 * This is used to differentiate requests from automatic vs CLI
075 * failover controllers, and in the future may include epoch
076 * information.
077 */
078 public static class StateChangeRequestInfo {
079 private final RequestSource source;
080
081 public StateChangeRequestInfo(RequestSource source) {
082 super();
083 this.source = source;
084 }
085
086 public RequestSource getSource() {
087 return source;
088 }
089 }
090
091 /**
092 * Monitor the health of service. This periodically called by the HA
093 * frameworks to monitor the health of the service.
094 *
095 * Service is expected to perform checks to ensure it is functional.
096 * If the service is not healthy due to failure or partial failure,
097 * it is expected to throw {@link HealthCheckFailedException}.
098 * The definition of service not healthy is left to the service.
099 *
100 * Note that when health check of an Active service fails,
101 * failover to standby may be done.
102 *
103 * @throws HealthCheckFailedException
104 * if the health check of a service fails.
105 * @throws AccessControlException
106 * if access is denied.
107 * @throws IOException
108 * if other errors happen
109 */
110 @Idempotent
111 public void monitorHealth() throws HealthCheckFailedException,
112 AccessControlException,
113 IOException;
114
115 /**
116 * Request service to transition to active state. No operation, if the
117 * service is already in active state.
118 *
119 * @throws ServiceFailedException
120 * if transition from standby to active fails.
121 * @throws AccessControlException
122 * if access is denied.
123 * @throws IOException
124 * if other errors happen
125 */
126 @Idempotent
127 public void transitionToActive(StateChangeRequestInfo reqInfo)
128 throws ServiceFailedException,
129 AccessControlException,
130 IOException;
131
132 /**
133 * Request service to transition to standby state. No operation, if the
134 * service is already in standby state.
135 *
136 * @throws ServiceFailedException
137 * if transition from active to standby fails.
138 * @throws AccessControlException
139 * if access is denied.
140 * @throws IOException
141 * if other errors happen
142 */
143 @Idempotent
144 public void transitionToStandby(StateChangeRequestInfo reqInfo)
145 throws ServiceFailedException,
146 AccessControlException,
147 IOException;
148
149 /**
150 * Return the current status of the service. The status indicates
151 * the current <em>state</em> (e.g ACTIVE/STANDBY) as well as
152 * some additional information. {@see HAServiceStatus}
153 *
154 * @throws AccessControlException
155 * if access is denied.
156 * @throws IOException
157 * if other errors happen
158 */
159 @Idempotent
160 public HAServiceStatus getServiceStatus() throws AccessControlException,
161 IOException;
162 }