Author: arp
Date: Thu Jun 12 01:27:39 2014
New Revision: 1602055
URL: http://svn.apache.org/r1602055
Log:
HADOOP-10376. Refactor refresh*Protocols into a single generic
refreshConfigProtocol. (Contributed by Chris Li)
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/GenericRefreshProtocol.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshHandler.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshRegistry.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshResponse.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolClientSideTranslatorPB.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolPB.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolServerSideTranslatorPB.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/proto/GenericRefreshProtocol.proto
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/trunk/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
hadoop/common/trunk/hadoop-common-project/hadoop-common/pom.xml
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1602055&r1=1602054&r2=1602055&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Thu Jun
12 01:27:39 2014
@@ -417,6 +417,9 @@ Release 2.5.0 - UNRELEASED
TCP RST and miss session expiration event due to bug in client connection
management. (cnauroth)
+ HADOOP-10376. Refactor refresh*Protocols into a single generic
+ refreshConfigProtocol. (Chris Li via Arpit Agarwal)
+
OPTIMIZATIONS
BUG FIXES
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml?rev=1602055&r1=1602054&r2=1602055&view=diff
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
(original)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
Thu Jun 12 01:27:39 2014
@@ -287,6 +287,10 @@
<!-- protobuf generated code -->
<Class
name="~org\.apache\.hadoop\.ipc\.proto\.RefreshCallQueueProtocolProtos.*"/>
</Match>
+ <Match>
+ <!-- protobuf generated code -->
+ <Class
name="~org\.apache\.hadoop\.ipc\.proto\.GenericRefreshProtocolProtos.*"/>
+ </Match>
<!--
Manually checked, misses child thread manually syncing on parent's
intrinsic lock.
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/pom.xml
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/pom.xml?rev=1602055&r1=1602054&r2=1602055&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/pom.xml (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/pom.xml Thu Jun 12
01:27:39 2014
@@ -318,6 +318,7 @@
<include>RefreshAuthorizationPolicyProtocol.proto</include>
<include>RefreshUserMappingsProtocol.proto</include>
<include>RefreshCallQueueProtocol.proto</include>
+ <include>GenericRefreshProtocol.proto</include>
</includes>
</source>
<output>${project.build.directory}/generated-sources/java</output>
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java?rev=1602055&r1=1602054&r2=1602055&view=diff
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java
(original)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java
Thu Jun 12 01:27:39 2014
@@ -142,6 +142,9 @@ public class CommonConfigurationKeys ext
public static final String
HADOOP_SECURITY_SERVICE_AUTHORIZATION_REFRESH_CALLQUEUE =
"security.refresh.callqueue.protocol.acl";
+ public static final String
+ HADOOP_SECURITY_SERVICE_AUTHORIZATION_GENERIC_REFRESH =
+ "security.refresh.generic.protocol.acl";
public static final String
SECURITY_HA_SERVICE_PROTOCOL_ACL = "security.ha.service.protocol.acl";
public static final String
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/GenericRefreshProtocol.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/GenericRefreshProtocol.java?rev=1602055&view=auto
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/GenericRefreshProtocol.java
(added)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/GenericRefreshProtocol.java
Thu Jun 12 01:27:39 2014
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ipc;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.fs.CommonConfigurationKeys;
+import org.apache.hadoop.io.retry.Idempotent;
+import org.apache.hadoop.security.KerberosInfo;
+
+/**
+ * Protocol which is used to refresh arbitrary things at runtime.
+ */
+@KerberosInfo(
+
serverPrincipal=CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY)
[email protected]
[email protected]
+public interface GenericRefreshProtocol {
+ /**
+ * Version 1: Initial version.
+ */
+ public static final long versionID = 1L;
+
+ /**
+ * Refresh the resource based on identity passed in.
+ * @throws IOException
+ */
+ @Idempotent
+ Collection<RefreshResponse> refresh(String identifier, String[] args)
+ throws IOException;
+}
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshHandler.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshHandler.java?rev=1602055&view=auto
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshHandler.java
(added)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshHandler.java
Thu Jun 12 01:27:39 2014
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ipc;
+
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Used to registry custom methods to refresh at runtime.
+ */
[email protected]
+public interface RefreshHandler {
+ /**
+ * Implement this method to accept refresh requests from the administrator.
+ * @param identifier is the identifier you registered earlier
+ * @param args contains a list of string args from the administrator
+ * @throws Exception as a shorthand for a RefreshResponse(-1, message)
+ * @return a RefreshResponse
+ */
+ RefreshResponse handleRefresh(String identifier, String[] args);
+}
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshRegistry.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshRegistry.java?rev=1602055&view=auto
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshRegistry.java
(added)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshRegistry.java
Thu Jun 12 01:27:39 2014
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ipc;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Used to registry custom methods to refresh at runtime.
+ * Each identifier maps to one or more RefreshHandlers.
+ */
[email protected]
+public class RefreshRegistry {
+ public static final Log LOG = LogFactory.getLog(RefreshRegistry.class);
+
+ // Used to hold singleton instance
+ private static class RegistryHolder {
+ @SuppressWarnings("All")
+ public static RefreshRegistry registry = new RefreshRegistry();
+ }
+
+ // Singleton access
+ public static RefreshRegistry defaultRegistry() {
+ return RegistryHolder.registry;
+ }
+
+ private final Multimap<String, RefreshHandler> handlerTable;
+
+ public RefreshRegistry() {
+ handlerTable = HashMultimap.create();
+ }
+
+ /**
+ * Registers an object as a handler for a given identity.
+ * Note: will prevent handler from being GC'd, object should unregister
itself
+ * when done
+ * @param identifier a unique identifier for this resource,
+ * such as org.apache.hadoop.blacklist
+ * @param handler the object to register
+ */
+ public synchronized void register(String identifier, RefreshHandler handler)
{
+ if (identifier == null) {
+ throw new NullPointerException("Identifier cannot be null");
+ }
+ handlerTable.put(identifier, handler);
+ }
+
+ /**
+ * Remove the registered object for a given identity.
+ * @param identifier the resource to unregister
+ * @return the true if removed
+ */
+ public synchronized boolean unregister(String identifier, RefreshHandler
handler) {
+ return handlerTable.remove(identifier, handler);
+ }
+
+ public synchronized void unregisterAll(String identifier) {
+ handlerTable.removeAll(identifier);
+ }
+
+ /**
+ * Lookup the responsible handler and return its result.
+ * This should be called by the RPC server when it gets a refresh request.
+ * @param identifier the resource to refresh
+ * @param args the arguments to pass on, not including the program name
+ * @throws IllegalArgumentException on invalid identifier
+ * @return the response from the appropriate handler
+ */
+ public synchronized Collection<RefreshResponse> dispatch(String identifier,
String[] args) {
+ Collection<RefreshHandler> handlers = handlerTable.get(identifier);
+
+ if (handlers.size() == 0) {
+ String msg = "Identifier '" + identifier +
+ "' does not exist in RefreshRegistry. Valid options are: " +
+ Joiner.on(", ").join(handlerTable.keySet());
+
+ throw new IllegalArgumentException(msg);
+ }
+
+ ArrayList<RefreshResponse> responses =
+ new ArrayList<RefreshResponse>(handlers.size());
+
+ // Dispatch to each handler and store response
+ for(RefreshHandler handler : handlers) {
+ RefreshResponse response;
+
+ // Run the handler
+ try {
+ response = handler.handleRefresh(identifier, args);
+ if (response == null) {
+ throw new NullPointerException("Handler returned null.");
+ }
+
+ LOG.info(handlerName(handler) + " responds to '" + identifier +
+ "', says: '" + response.getMessage() + "', returns " +
+ response.getReturnCode());
+ } catch (Exception e) {
+ response = new RefreshResponse(-1, e.getLocalizedMessage());
+ }
+
+ response.setSenderName(handlerName(handler));
+ responses.add(response);
+ }
+
+ return responses;
+ }
+
+ private String handlerName(RefreshHandler h) {
+ return h.getClass().getName() + '@' + Integer.toHexString(h.hashCode());
+ }
+}
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshResponse.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshResponse.java?rev=1602055&view=auto
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshResponse.java
(added)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RefreshResponse.java
Thu Jun 12 01:27:39 2014
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ipc;
+
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Return a response in the handler method for the user to see.
+ * Useful since you may want to display status to a user even though an
+ * error has not occurred.
+ */
[email protected]
+public class RefreshResponse {
+ private int returnCode = -1;
+ private String message;
+ private String senderName;
+
+ /**
+ * Convenience method to create a response for successful refreshes.
+ * @return void response
+ */
+ public static RefreshResponse successResponse() {
+ return new RefreshResponse(0, "Success");
+ }
+
+ // Most RefreshHandlers will use this
+ public RefreshResponse(int returnCode, String message) {
+ this.returnCode = returnCode;
+ this.message = message;
+ }
+
+ /**
+ * Optionally set the sender of this RefreshResponse.
+ * This helps clarify things when multiple handlers respond.
+ * @param name The name of the sender
+ */
+ public void setSenderName(String name) {
+ senderName = name;
+ }
+ public String getSenderName() { return senderName; }
+
+ public int getReturnCode() { return returnCode; }
+ public void setReturnCode(int rc) { returnCode = rc; }
+
+ public void setMessage(String m) { message = m; }
+ public String getMessage() { return message; }
+
+ @Override
+ public String toString() {
+ String ret = "";
+
+ if (senderName != null) {
+ ret += senderName + ": ";
+ }
+
+ if (message != null) {
+ ret += message;
+ }
+
+ ret += " (exit " + returnCode + ")";
+ return ret;
+ }
+}
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolClientSideTranslatorPB.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolClientSideTranslatorPB.java?rev=1602055&view=auto
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolClientSideTranslatorPB.java
(added)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolClientSideTranslatorPB.java
Thu Jun 12 01:27:39 2014
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ipc.protocolPB;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.hadoop.ipc.ProtobufHelper;
+import org.apache.hadoop.ipc.ProtocolMetaInterface;
+import org.apache.hadoop.ipc.RPC;
+import org.apache.hadoop.ipc.RefreshResponse;
+import org.apache.hadoop.ipc.RpcClientUtil;
+import org.apache.hadoop.ipc.GenericRefreshProtocol;
+import
org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshRequestProto;
+import
org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseProto;
+import
org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseCollectionProto;
+
+import com.google.protobuf.RpcController;
+import com.google.protobuf.ServiceException;
+
+public class GenericRefreshProtocolClientSideTranslatorPB implements
+ ProtocolMetaInterface, GenericRefreshProtocol, Closeable {
+
+ /** RpcController is not used and hence is set to null. */
+ private final static RpcController NULL_CONTROLLER = null;
+ private final GenericRefreshProtocolPB rpcProxy;
+
+ public GenericRefreshProtocolClientSideTranslatorPB(
+ GenericRefreshProtocolPB rpcProxy) {
+ this.rpcProxy = rpcProxy;
+ }
+
+ @Override
+ public void close() throws IOException {
+ RPC.stopProxy(rpcProxy);
+ }
+
+ @Override
+ public Collection<RefreshResponse> refresh(String identifier, String[] args)
throws IOException {
+ List<String> argList = Arrays.asList(args);
+
+ try {
+ GenericRefreshRequestProto request =
GenericRefreshRequestProto.newBuilder()
+ .setIdentifier(identifier)
+ .addAllArgs(argList)
+ .build();
+
+ GenericRefreshResponseCollectionProto resp =
rpcProxy.refresh(NULL_CONTROLLER, request);
+ return unpack(resp);
+ } catch (ServiceException se) {
+ throw ProtobufHelper.getRemoteException(se);
+ }
+ }
+
+ private Collection<RefreshResponse>
unpack(GenericRefreshResponseCollectionProto collection) {
+ List<GenericRefreshResponseProto> responseProtos =
collection.getResponsesList();
+ List<RefreshResponse> responses = new ArrayList<RefreshResponse>();
+
+ for (GenericRefreshResponseProto rp : responseProtos) {
+ RefreshResponse response = unpack(rp);
+ responses.add(response);
+ }
+
+ return responses;
+ }
+
+ private RefreshResponse unpack(GenericRefreshResponseProto proto) {
+ // The default values
+ String message = null;
+ String sender = null;
+ int returnCode = -1;
+
+ // ... that can be overridden by data from the protobuf
+ if (proto.hasUserMessage()) {
+ message = proto.getUserMessage();
+ }
+ if (proto.hasExitStatus()) {
+ returnCode = proto.getExitStatus();
+ }
+ if (proto.hasSenderName()) {
+ sender = proto.getSenderName();
+ }
+
+ // ... and put into a RefreshResponse
+ RefreshResponse response = new RefreshResponse(returnCode, message);
+ response.setSenderName(sender);
+
+ return response;
+ }
+
+ @Override
+ public boolean isMethodSupported(String methodName) throws IOException {
+ return RpcClientUtil.isMethodSupported(rpcProxy,
+ GenericRefreshProtocolPB.class,
+ RPC.RpcKind.RPC_PROTOCOL_BUFFER,
+ RPC.getProtocolVersion(GenericRefreshProtocolPB.class),
+ methodName);
+ }
+}
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolPB.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolPB.java?rev=1602055&view=auto
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolPB.java
(added)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolPB.java
Thu Jun 12 01:27:39 2014
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ipc.protocolPB;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.fs.CommonConfigurationKeys;
+import org.apache.hadoop.ipc.ProtocolInfo;
+import org.apache.hadoop.security.KerberosInfo;
+import
org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshProtocolService;
+
+@KerberosInfo(
+
serverPrincipal=CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY)
+@ProtocolInfo(
+ protocolName = "org.apache.hadoop.ipc.GenericRefreshProtocol",
+ protocolVersion = 1)
[email protected]({"HDFS"})
[email protected]
+public interface GenericRefreshProtocolPB extends
+ GenericRefreshProtocolService.BlockingInterface {
+}
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolServerSideTranslatorPB.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolServerSideTranslatorPB.java?rev=1602055&view=auto
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolServerSideTranslatorPB.java
(added)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/protocolPB/GenericRefreshProtocolServerSideTranslatorPB.java
Thu Jun 12 01:27:39 2014
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ipc.protocolPB;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.hadoop.ipc.GenericRefreshProtocol;
+import org.apache.hadoop.ipc.RefreshResponse;
+import
org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshRequestProto;
+import
org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseProto;
+import
org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseCollectionProto;
+
+import com.google.protobuf.RpcController;
+import com.google.protobuf.ServiceException;
+
+public class GenericRefreshProtocolServerSideTranslatorPB implements
+ GenericRefreshProtocolPB {
+
+ private final GenericRefreshProtocol impl;
+
+ public GenericRefreshProtocolServerSideTranslatorPB(
+ GenericRefreshProtocol impl) {
+ this.impl = impl;
+ }
+
+ @Override
+ public GenericRefreshResponseCollectionProto refresh(
+ RpcController controller, GenericRefreshRequestProto request)
+ throws ServiceException {
+ try {
+ List<String> argList = request.getArgsList();
+ String[] args = argList.toArray(new String[argList.size()]);
+
+ if (!request.hasIdentifier()) {
+ throw new ServiceException("Request must contain identifier");
+ }
+
+ Collection<RefreshResponse> results =
impl.refresh(request.getIdentifier(), args);
+
+ return pack(results);
+ } catch (IOException e) {
+ throw new ServiceException(e);
+ }
+ }
+
+ // Convert a collection of RefreshResponse objects to a
+ // RefreshResponseCollection proto
+ private GenericRefreshResponseCollectionProto pack(
+ Collection<RefreshResponse> responses) {
+ GenericRefreshResponseCollectionProto.Builder b =
+ GenericRefreshResponseCollectionProto.newBuilder();
+
+ for (RefreshResponse response : responses) {
+ GenericRefreshResponseProto.Builder respBuilder =
+ GenericRefreshResponseProto.newBuilder();
+ respBuilder.setExitStatus(response.getReturnCode());
+ respBuilder.setUserMessage(response.getMessage());
+ respBuilder.setSenderName(response.getSenderName());
+
+ // Add to collection
+ b.addResponses(respBuilder);
+ }
+
+ return b.build();
+ }
+}
Added:
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/proto/GenericRefreshProtocol.proto
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/proto/GenericRefreshProtocol.proto?rev=1602055&view=auto
==============================================================================
---
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/proto/GenericRefreshProtocol.proto
(added)
+++
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/proto/GenericRefreshProtocol.proto
Thu Jun 12 01:27:39 2014
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * These .proto interfaces are private and stable.
+ * Please see http://wiki.apache.org/hadoop/Compatibility
+ * for what changes are allowed for a *stable* .proto interface.
+ */
+
+option java_package = "org.apache.hadoop.ipc.proto";
+option java_outer_classname = "GenericRefreshProtocolProtos";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+package hadoop.common;
+
+/**
+ * Refresh request.
+ */
+message GenericRefreshRequestProto {
+ optional string identifier = 1;
+ repeated string args = 2;
+}
+
+/**
+ * A single response from a refresh handler.
+ */
+message GenericRefreshResponseProto {
+ optional int32 exitStatus = 1; // unix exit status to return
+ optional string userMessage = 2; // to be displayed to the user
+ optional string senderName = 3; // which handler sent this message
+}
+
+/**
+ * Collection of responses from zero or more handlers.
+ */
+message GenericRefreshResponseCollectionProto {
+ repeated GenericRefreshResponseProto responses = 1;
+}
+
+/**
+ * Protocol which is used to refresh a user-specified feature.
+ */
+service GenericRefreshProtocolService {
+ rpc refresh(GenericRefreshRequestProto)
+ returns(GenericRefreshResponseCollectionProto);
+}