SLIDER-782: "REST" test delegate for the IPC API; shares all the tests with the REST Slider Client API. Some exception translation now takes place, though only a little.
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/41244893 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/41244893 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/41244893 Branch: refs/heads/develop Commit: 41244893c792d8c4932c8aa2683e4aaa8ea5de3a Parents: 1474abc Author: Steve Loughran <[email protected]> Authored: Fri Feb 13 15:20:08 2015 +0000 Committer: Steve Loughran <[email protected]> Committed: Fri Feb 13 15:20:08 2015 +0000 ---------------------------------------------------------------------- .../slider/api/proto/RestTypeMarshalling.java | 9 +- .../client/ipc/SliderApplicationIpcClient.java | 121 ++++++++++++++++--- .../client/ipc/SliderClusterOperations.java | 9 ++ .../rest/SliderApplicationApiRestClient.java | 9 ++ .../core/exceptions/NoSuchNodeException.java | 2 +- .../server/appmaster/SliderAppMaster.java | 8 +- .../slider/server/appmaster/rpc/RpcBinder.java | 64 ++++++---- .../rpc/SliderClusterProtocolPBImpl.java | 49 ++++++-- .../rpc/SliderClusterProtocolProxy.java | 15 ++- .../server/appmaster/rpc/SliderIPCService.java | 1 + .../slider/server/appmaster/state/AppState.java | 2 +- .../rest/AbstractAppApiTestDelegates.groovy | 32 ++++- .../agent/rest/IpcApiClientTestDelegates.java | 29 +++++ .../rest/RestAPIClientTestDelegates.groovy | 20 +-- .../slider/agent/rest/TestStandaloneREST.groovy | 12 ++ 15 files changed, 302 insertions(+), 80 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java b/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java index 5c854a0..fcd8582 100644 --- a/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java +++ b/slider-core/src/main/java/org/apache/slider/api/proto/RestTypeMarshalling.java @@ -149,6 +149,7 @@ public class RestTypeMarshalling { if (info.component != null) { builder.setComponent(info.component); } + builder.setCreateTime(info.createTime); if (info.diagnostics != null) { builder.setDiagnostics(info.diagnostics); } @@ -158,14 +159,14 @@ public class RestTypeMarshalling { if (info.hostURL != null) { builder.setHostURL(info.hostURL); } - if (info.released != null) { - builder.setReleased(info.released); - } if (info.output != null) { builder.addAllOutput(Arrays.asList(info.output)); } - builder.setCreateTime(info.createTime); + if (info.released != null) { + builder.setReleased(info.released); + } builder.setStartTime(info.startTime); + builder.setState(info.state); return builder.build(); } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/client/ipc/SliderApplicationIpcClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/ipc/SliderApplicationIpcClient.java b/slider-core/src/main/java/org/apache/slider/client/ipc/SliderApplicationIpcClient.java index 6abbd85..13a2e03 100644 --- a/slider-core/src/main/java/org/apache/slider/client/ipc/SliderApplicationIpcClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/ipc/SliderApplicationIpcClient.java @@ -18,6 +18,8 @@ package org.apache.slider.client.ipc; +import com.google.common.base.Preconditions; +import org.apache.slider.api.SliderClusterProtocol; import org.apache.slider.api.types.ApplicationLivenessInformation; import org.apache.slider.api.types.ComponentInformation; import org.apache.slider.api.types.ContainerInformation; @@ -25,14 +27,20 @@ import org.apache.slider.api.types.PingInformation; import org.apache.slider.api.SliderApplicationApi; import org.apache.slider.core.conf.AggregateConf; import org.apache.slider.core.conf.ConfTreeOperations; +import org.apache.slider.core.exceptions.NoSuchNodeException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; /** * Implementation of the Slider RESTy Application API over IPC. + * <p> + * Operations are executed via the {@link SliderClusterOperations} + * instance passed in; raised exceptions may be converted into ones + * consistent with the REST API. */ public class SliderApplicationIpcClient implements SliderApplicationApi { @@ -42,65 +50,137 @@ public class SliderApplicationIpcClient implements SliderApplicationApi { private final SliderClusterOperations operations; public SliderApplicationIpcClient(SliderClusterOperations operations) { + Preconditions.checkArgument(operations != null, "null operations"); this.operations = operations; } + /** + * Convert received (And potentially unmarshalled) local/remote + * exceptions into the equivalents in the REST API. + * Best effort. + * <p> + * If there is no translation, the original exception is returned. + * <p> + * If a new exception was created, it will have the message of the + * string value of the original exception, and that original + * exception will be the nested cause of this one + * @param exception IOException to convert + * @return an exception to throw + */ + private IOException convert(IOException exception) { + IOException result = exception; + if (exception instanceof NoSuchNodeException) { + result = new FileNotFoundException(exception.toString()); + result.initCause(exception); + } else { + // TODO: remap any other exceptions + } + return result; + } + + public SliderApplicationIpcClient(SliderClusterProtocol proxy) { + this(new SliderClusterOperations(proxy)); + } + @Override public AggregateConf getDesiredModel() throws IOException { - return operations.getModelDesired(); + try { + return operations.getModelDesired(); + } catch (IOException e) { + throw convert(e); + } } @Override public ConfTreeOperations getDesiredAppconf() throws IOException { - return operations.getModelDesiredAppconf(); + try { + return operations.getModelDesiredAppconf(); + } catch (IOException e) { + throw convert(e); + } } @Override public ConfTreeOperations getDesiredResources() throws IOException { - return operations.getModelDesiredResources(); + try { + return operations.getModelDesiredResources(); + } catch (IOException e) { + throw convert(e); + } } @Override public AggregateConf getResolvedModel() throws IOException { - return operations.getModelResolved(); + try { + return operations.getModelResolved(); + } catch (IOException e) { + throw convert(e); + } } @Override public ConfTreeOperations getResolvedAppconf() throws IOException { - return operations.getModelResolvedAppconf(); + try { + return operations.getModelResolvedAppconf(); + } catch (IOException e) { + throw convert(e); + } } @Override public ConfTreeOperations getResolvedResources() throws IOException { - return operations.getModelResolvedResources(); + try { + return operations.getModelResolvedResources(); + } catch (IOException e) { + throw convert(e); + } } @Override public ConfTreeOperations getLiveResources() throws IOException { - return operations.getLiveResources(); + try { + return operations.getLiveResources(); + } catch (IOException e) { + throw convert(e); + } } @Override public Map<String, ContainerInformation> enumContainers() throws IOException { - return operations.enumContainers(); + try { + return operations.enumContainers(); + } catch (IOException e) { + throw convert(e); + } } @Override public ContainerInformation getContainer(String containerId) throws IOException { - return operations.getContainer(containerId); + try { + return operations.getContainer(containerId); + } catch (IOException e) { + throw convert(e); + } } @Override public Map<String, ComponentInformation> enumComponents() throws IOException { - return operations.enumComponents(); + try { + return operations.enumComponents(); + } catch (IOException e) { + throw convert(e); + } } @Override public ComponentInformation getComponent(String componentName) throws IOException { - return operations.getComponent(componentName); - + try { + return operations.getComponent(componentName); + } catch (IOException e) { + throw convert(e); + } } @Override @@ -110,12 +190,25 @@ public class SliderApplicationIpcClient implements SliderApplicationApi { @Override public void stop(String text) throws IOException { - operations.stop(text); + try { + operations.stop(text); + } catch (IOException e) { + throw convert(e); + } } @Override public ApplicationLivenessInformation getApplicationLiveness() throws IOException { - return operations.getApplicationLiveness(); + try { + return operations.getApplicationLiveness(); + } catch (IOException e) { + throw convert(e); + } + } + + @Override + public String toString() { + return "IPC implementation of SliderApplicationApi bonded to " + operations; } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java b/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java index a78d539..faaf619 100644 --- a/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java +++ b/slider-core/src/main/java/org/apache/slider/client/ipc/SliderClusterOperations.java @@ -68,6 +68,15 @@ public class SliderClusterOperations { this.appMaster = appMaster; } + @Override + public String toString() { + final StringBuilder sb = + new StringBuilder("SliderClusterOperations{"); + sb.append("IPC binding=").append(appMaster); + sb.append('}'); + return sb.toString(); + } + /** * Get a node from the AM * @param uuid uuid of node http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java index c38d5b1..d1c81b0 100644 --- a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java @@ -62,6 +62,15 @@ public class SliderApplicationApiRestClient extends BaseRestClient this.appResource = appResource; } + @Override + public String toString() { + final StringBuilder sb = + new StringBuilder("SliderApplicationApiRestClient{"); + sb.append("appResource=").append(appResource); + sb.append('}'); + return sb.toString(); + } + /** * Create a resource under the application path set up to accept * JSON http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/core/exceptions/NoSuchNodeException.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/core/exceptions/NoSuchNodeException.java b/slider-core/src/main/java/org/apache/slider/core/exceptions/NoSuchNodeException.java index f86b336..ad2f1a4 100644 --- a/slider-core/src/main/java/org/apache/slider/core/exceptions/NoSuchNodeException.java +++ b/slider-core/src/main/java/org/apache/slider/core/exceptions/NoSuchNodeException.java @@ -27,6 +27,6 @@ import java.io.IOException; public class NoSuchNodeException extends IOException { public NoSuchNodeException(String uuid) { - super("Unknown node: " + uuid); + super(uuid); } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java index 21c6eaf..f778138 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java @@ -1514,11 +1514,11 @@ public class SliderAppMaster extends AbstractSliderLaunchedService protobufRelay); int port = getPortToRequest(); + InetSocketAddress rpcAddress = new InetSocketAddress("0.0.0.0", port); rpcService = - new WorkflowRpcService("SliderRPC", RpcBinder.createProtobufServer( - new InetSocketAddress("0.0.0.0", port), - getConfig(), - secretManager, + new WorkflowRpcService("SliderRPC", + RpcBinder.createProtobufServer(rpcAddress, getConfig(), + secretManager, NUM_RPC_HANDLERS, blockingService, null)); http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/RpcBinder.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/RpcBinder.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/RpcBinder.java index 080d0f2..9cc612e 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/RpcBinder.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/RpcBinder.java @@ -43,6 +43,7 @@ import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.slider.api.SliderClusterProtocol; import org.apache.slider.common.SliderExitCodes; import org.apache.slider.common.tools.Duration; +import org.apache.slider.common.tools.SliderUtils; import org.apache.slider.core.exceptions.BadClusterStateException; import org.apache.slider.core.exceptions.ErrorStrings; import org.apache.slider.core.exceptions.ServiceNotReadyException; @@ -61,6 +62,17 @@ public class RpcBinder { protected static final Logger log = LoggerFactory.getLogger(RpcBinder.class); + /** + * Create a protobuf server bonded to the specific socket address + * @param addr address to listen to; 0.0.0.0 as hostname acceptable + * @param conf config + * @param secretManager token secret handler + * @param numHandlers threads to service requests + * @param blockingService service to handle + * @param portRangeConfig range of ports + * @return the IPC server itself + * @throws IOException + */ public static Server createProtobufServer(InetSocketAddress addr, Configuration conf, SecretManager<? extends TokenIdentifier> secretManager, @@ -89,7 +101,7 @@ public class RpcBinder { /** * Add the protobuf engine to the configuration. Harmless and inexpensive - * if repeated + * if repeated. * @param conf configuration to patch * @return the protocol class */ @@ -109,7 +121,7 @@ public class RpcBinder { * Verify that the conf is set up for protobuf transport of Slider RPC * @param conf configuration * @param sliderClusterAPIClass class for the API - * @return + * @return true if the RPC engine is protocol buffers */ public static boolean verifyBondedToProtobuf(Configuration conf, Class<SliderClusterProtocolPB> sliderClusterAPIClass) { @@ -131,8 +143,8 @@ public class RpcBinder { UserGroupInformation currentUser, Configuration conf, int rpcTimeout) throws IOException { - Class<SliderClusterProtocolPB> sliderClusterAPIClass = registerSliderAPI( - conf); + Class<SliderClusterProtocolPB> sliderClusterAPIClass = + registerSliderAPI(conf); final RetryPolicy retryPolicy = RetryUtils.getDefaultRetryPolicy( @@ -178,20 +190,17 @@ public class RpcBinder { final ApplicationClientProtocol rmClient, ApplicationReport application, final int connectTimeout, - - final int rpcTimeout) throws - IOException, - YarnException, - InterruptedException { + final int rpcTimeout) + throws IOException, YarnException, InterruptedException { ApplicationId appId; appId = application.getApplicationId(); Duration timeout = new Duration(connectTimeout); timeout.start(); Exception exception = null; YarnApplicationState state = null; - while (application != null && - (state= application.getYarnApplicationState()).equals( - YarnApplicationState.RUNNING)) { + while (application != null && + (state = application.getYarnApplicationState()).equals( + YarnApplicationState.RUNNING)) { try { return getProxy(conf, application, rpcTimeout); @@ -205,7 +214,6 @@ public class RpcBinder { throw e; } exception = e; - } //at this point: app failed to work log.debug("Could not connect to {}. Waiting for getting the latest AM address...", @@ -213,8 +221,8 @@ public class RpcBinder { Thread.sleep(1000); //or get the app report application = - rmClient.getApplicationReport(GetApplicationReportRequest.newInstance( - appId)).getApplicationReport(); + rmClient.getApplicationReport( + GetApplicationReportRequest.newInstance(appId)).getApplicationReport(); } //get here if the app is no longer running. Raise a specific //exception but init it with the previous failure @@ -223,17 +231,25 @@ public class RpcBinder { ErrorStrings.E_FINISHED_APPLICATION, appId, state ); } + /** + * Get a proxy from the application report + * @param conf config to use + * @param application app report + * @param rpcTimeout timeout in RPC operations + * @return the proxy + * @throws IOException + * @throws SliderException + * @throws InterruptedException + */ public static SliderClusterProtocol getProxy(final Configuration conf, - ApplicationReport application, - final int rpcTimeout) throws - IOException, - SliderException, - InterruptedException { + final ApplicationReport application, + final int rpcTimeout) + throws IOException, SliderException, InterruptedException { String host = application.getHost(); int port = application.getRpcPort(); String address = host + ":" + port; - if (host == null || 0 == port) { + if (SliderUtils.isUnset(host) || 0 == port) { throw new SliderException(SliderExitCodes.EXIT_CONNECTIVITY_PROBLEM, "Slider instance " + application.getName() + " isn't providing a valid address for the" + @@ -243,8 +259,8 @@ public class RpcBinder { UserGroupInformation currentUser = UserGroupInformation.getCurrentUser(); final UserGroupInformation newUgi = UserGroupInformation.createRemoteUser( currentUser.getUserName()); - final InetSocketAddress serviceAddr = NetUtils.createSocketAddrForHost( - application.getHost(), application.getRpcPort()); + final InetSocketAddress serviceAddr = + NetUtils.createSocketAddrForHost(host, port); SliderClusterProtocol realProxy; log.debug("Connecting to {}", serviceAddr); @@ -262,7 +278,7 @@ public class RpcBinder { } }); } else { - return connectToServer(serviceAddr, newUgi, conf, rpcTimeout); + realProxy = connectToServer(serviceAddr, newUgi, conf, rpcTimeout); } return realProxy; } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolPBImpl.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolPBImpl.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolPBImpl.java index d34ce42..dded9b9 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolPBImpl.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolPBImpl.java @@ -149,8 +149,7 @@ public class SliderClusterProtocolPBImpl implements SliderClusterProtocolPB { throw wrap(e); } } - - + @Override public Messages.AMSuicideResponseProto amSuicide(RpcController controller, Messages.AMSuicideRequestProto request) throws @@ -173,8 +172,7 @@ public class SliderClusterProtocolPBImpl implements SliderClusterProtocolPB { throw wrap(e); } } - - + @Override public Messages.GetLiveContainersResponseProto getLiveContainers(RpcController controller, Messages.GetLiveContainersRequestProto request) throws ServiceException { @@ -218,42 +216,69 @@ public class SliderClusterProtocolPBImpl implements SliderClusterProtocolPB { @Override public Messages.WrappedJsonProto getModelDesired(RpcController controller, Messages.EmptyPayloadProto request) throws ServiceException { - return null; + try { + return real.getModelDesired(request); + } catch (Exception e) { + throw wrap(e); + } } @Override public Messages.WrappedJsonProto getModelDesiredAppconf(RpcController controller, Messages.EmptyPayloadProto request) throws ServiceException { - return null; - } + try { + return real.getModelDesiredAppconf(request); + } catch (Exception e) { + throw wrap(e); + } } @Override public Messages.WrappedJsonProto getModelDesiredResources(RpcController controller, Messages.EmptyPayloadProto request) throws ServiceException { - return null; + try { + return real.getModelDesiredResources(request); + } catch (Exception e) { + throw wrap(e); + } } @Override public Messages.WrappedJsonProto getModelResolved(RpcController controller, Messages.EmptyPayloadProto request) throws ServiceException { - return null; + try { + return real.getModelResolved(request); + } catch (Exception e) { + throw wrap(e); + } } @Override public Messages.WrappedJsonProto getModelResolvedAppconf(RpcController controller, Messages.EmptyPayloadProto request) throws ServiceException { - return null; + try { + return real.getModelResolvedAppconf(request); + } catch (Exception e) { + throw wrap(e); + } } @Override public Messages.WrappedJsonProto getModelResolvedResources(RpcController controller, Messages.EmptyPayloadProto request) throws ServiceException { - return null; + try { + return real.getModelResolvedResources(request); + } catch (Exception e) { + throw wrap(e); + } } @Override public Messages.WrappedJsonProto getLiveResources(RpcController controller, Messages.EmptyPayloadProto request) throws ServiceException { - return null; + try { + return real.getLiveResources(request); + } catch (Exception e) { + throw wrap(e); + } } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolProxy.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolProxy.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolProxy.java index a5e80fd..7ecbbb6 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolProxy.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderClusterProtocolProxy.java @@ -18,6 +18,7 @@ package org.apache.slider.server.appmaster.rpc; +import com.google.common.base.Preconditions; import com.google.protobuf.RpcController; import com.google.protobuf.ServiceException; import org.apache.hadoop.ipc.ProtobufHelper; @@ -39,10 +40,20 @@ public class SliderClusterProtocolProxy implements SliderClusterProtocol { public SliderClusterProtocolProxy(SliderClusterProtocolPB endpoint, InetSocketAddress address) { + Preconditions.checkArgument(endpoint != null, "null endpoint"); + Preconditions.checkNotNull(address != null, "null address"); this.endpoint = endpoint; this.address = address; } + @Override + public String toString() { + final StringBuilder sb = + new StringBuilder("SliderClusterProtocolProxy{"); + sb.append("address=").append(address); + sb.append('}'); + return sb.toString(); + } @Override public ProtocolSignature getProtocolSignature(String protocol, @@ -72,9 +83,7 @@ public class SliderClusterProtocolProxy implements SliderClusterProtocol { IOException ioe = ProtobufHelper.getRemoteException(se); if (ioe instanceof RemoteException) { RemoteException remoteException = (RemoteException) ioe; - return new RemoteException( - remoteException.getClassName(), - address.toString() + ": " + remoteException.getMessage()); + return remoteException.unwrapRemoteException(); } return ioe; } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderIPCService.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderIPCService.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderIPCService.java index 07b91b8..882c963 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderIPCService.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/rpc/SliderIPCService.java @@ -32,6 +32,7 @@ import org.apache.slider.api.types.ComponentInformation; import org.apache.slider.api.types.ContainerInformation; import org.apache.slider.core.conf.AggregateConf; import org.apache.slider.core.conf.ConfTree; +import org.apache.slider.core.exceptions.NoSuchNodeException; import org.apache.slider.core.exceptions.ServiceNotReadyException; import org.apache.slider.core.main.LauncherExitCodes; import org.apache.slider.core.persist.AggregateConfSerDeser; http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java index 854a706..4652701 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/state/AppState.java @@ -1037,7 +1037,7 @@ public class AppState { return found; } else { //at this point: no node - throw new NoSuchNodeException(containerId); + throw new NoSuchNodeException("Unknown node: " + containerId); } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy index f510c5a..0310be5 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy @@ -35,15 +35,25 @@ import static org.apache.slider.common.SliderKeys.COMPONENT_AM @Slf4j public abstract class AbstractAppApiTestDelegates extends AbstractRestTestDelegate { - protected SliderApplicationApi appAPI; + private SliderApplicationApi appAPI; AbstractAppApiTestDelegates( boolean enableComplexVerbs, SliderApplicationApi appAPI) { super(enableComplexVerbs) - this.appAPI = appAPI + if (appAPI) { + setAppAPI(appAPI) + } } + SliderApplicationApi getAppAPI() { + return appAPI + } + + protected void setAppAPI(SliderApplicationApi appAPI) { + log.info("Setting API implementation to $appAPI") + this.appAPI = appAPI + } public void testGetDesiredModel() throws Throwable { appAPI.getDesiredModel() @@ -92,7 +102,7 @@ public abstract class AbstractAppApiTestDelegates extends AbstractRestTestDelega assert amContainerInfo.component == COMPONENT_AM assert amContainerInfo.createTime > 0 assert amContainerInfo.exitCode == null - assert amContainerInfo.output == null + assert amContainerInfo.output == null || !amContainerInfo.output.length assert amContainerInfo.released == null assert amContainerInfo.state == StateValues.STATE_LIVE @@ -205,4 +215,20 @@ public abstract class AbstractAppApiTestDelegates extends AbstractRestTestDelega return Outcome.Success } } + + @Override + public void testSuiteGetOperations() { + testGetDesiredModel() + testGetResolvedModel() + testLiveResources() + testLiveContainers(); + testRESTModel() + testAppLiveness() + } + + @Override + public void testSuiteComplexVerbs() { + testPing(); + } + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/test/groovy/org/apache/slider/agent/rest/IpcApiClientTestDelegates.java ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/IpcApiClientTestDelegates.java b/slider-core/src/test/groovy/org/apache/slider/agent/rest/IpcApiClientTestDelegates.java new file mode 100644 index 0000000..9411c3c --- /dev/null +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/IpcApiClientTestDelegates.java @@ -0,0 +1,29 @@ +/* + * 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.slider.agent.rest; + +import org.apache.slider.api.SliderApplicationApi; + +public class IpcApiClientTestDelegates extends AbstractAppApiTestDelegates { + + public IpcApiClientTestDelegates(SliderApplicationApi appAPI) { + super(true, appAPI); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy index d57a2a1..99129e5 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy @@ -36,7 +36,12 @@ import static org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_ @Slf4j class RestAPIClientTestDelegates extends AbstractAppApiTestDelegates { - + /** + * constructor + * @param appmaster AM URL + * @param jersey jersey impl + * @param enableComplexVerbs flag to enable complex verbs + */ RestAPIClientTestDelegates(String appmaster, Client jersey, boolean enableComplexVerbs = true) { super(enableComplexVerbs, null) @@ -47,17 +52,4 @@ class RestAPIClientTestDelegates extends AbstractAppApiTestDelegates { } - public void testSuiteGetOperations() { - testGetDesiredModel() - testGetResolvedModel() - testLiveResources() - testLiveContainers(); - testRESTModel() - testAppLiveness() - } - - public void testSuiteComplexVerbs() { - testPing(); - } - } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/41244893/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy index 7306c48..7e10d30 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy @@ -32,12 +32,14 @@ import org.apache.hadoop.registry.client.api.RegistryOperations import org.apache.hadoop.yarn.api.records.ApplicationReport import org.apache.slider.agent.AgentMiniClusterTestBase import org.apache.slider.client.SliderClient +import org.apache.slider.client.ipc.SliderApplicationIpcClient import org.apache.slider.client.rest.RestClientFactory import org.apache.slider.common.SliderKeys import org.apache.slider.common.SliderXmlConfKeys import org.apache.slider.common.params.Arguments import org.apache.slider.core.main.ServiceLauncher import org.apache.slider.core.restclient.HttpOperationResponse +import org.apache.slider.server.appmaster.rpc.RpcBinder import org.junit.Test import static org.apache.slider.server.appmaster.management.MetricsKeys.METRICS_LOGGING_ENABLED @@ -73,6 +75,7 @@ class TestStandaloneREST extends AgentMiniClusterTestBase { def proxyAM = report.trackingUrl def directAM = report.originalTrackingUrl + // set up url config to match initHttpTestSupport(launcher.configuration) @@ -171,6 +174,15 @@ class TestStandaloneREST extends AgentMiniClusterTestBase { sliderApplicationApi.ping("registry located") } + describe( "IPC equivalent operations") + def sliderClusterProtocol = RpcBinder.getProxy(conf, report, 1000) + SliderApplicationIpcClient ipcClient = + new SliderApplicationIpcClient(sliderClusterProtocol) + IpcApiClientTestDelegates ipcDelegates = + new IpcApiClientTestDelegates(ipcClient) + ipcDelegates.testSuiteAll() + + // log the metrics to show what's up direct.logCodahaleMetrics();
