You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Status

Current state: Under Discussion

Discussion thread: here 

JIRA: Unable to render Jira issues macro, execution error.  

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

Connect Framework offers REST API that is used to mange the lifecycle of the connector. Its imperative in most enterprises to secure the API and also add authorization to the end points. We could add the ability for authentication and authorization in the framework. But the security requirements are so broad that it's not practical to support all of them in the framework.  Hence we must provide ability for users to plug resources that help achieve the required capabilities.

Public Interfaces

This is a new capability and introduces the following public interfaces

 

interface ConnectRestPlugin extends Closeable{
    void register(ConnectRestPluginContext restPluginContext);
}
interface ConnectRestPluginContext{
    ResourceConfig resourceConfig();
    WorkerConfig workerConfig();
    ConnectClusterState clusterState();
}

 

 

interface ConnectClusterState{
    /**
     * Get a list of connectors currently running in this cluster. This is a full list of connectors in the cluster gathered
     * from the current configuration.
     */
    Collection<String> connectors();
 
    /**
     * Lookup the current status of a connector.
     * @param connName name of the connector
     */
    ConnectorStateInfo connectorStatus(String connName);
 
}


This also introduces a new configuration that  rest.plugins that allows to configure a comma separated list of Plugin implementaions.

Proposed Changes

Plugin Interface

Users will be able to create a plugin by implementing the interface ConnectRestPlugin. The  key method to implement is the register method which takes ConnectRestPluginContext . This allows us to change the interface easily in future to add new parameters. Connect runtime would also provide a default implementation for the interface ConnectRestPluginContext.  One or more of the implementation can be configured via the configuration rest.plugins as a comma separated list of class names.

 

Implementations would use the ResourceConfig to register one or more Jersey resources. They can use the WorkerConfig to get any plugin specific configuration.

interface ConnectRestPlugin extends Closeable{
    void register(ConnectRestPluginContext restPluginContext);
}
 
interface ConnectRestPluginContext{
    ResourceConfig resourceConfig();
    WorkerConfig workerConfig();
    ConnectClusterState clusterState();
}
 
class ConnectRestPluginContextImpl implements ConnectRestPluginContext{
    private final ResourceConfig resourceConfig;
    private final WorkerConfig workerConfig;
    private final ConnectClusterState clusterState;
 
    ConnectRestPluginContext(ResourceConfig resourceConfig, WorkerConfig workerConfig, ConnectClusterState clusterState){
        this.resourceConfig = resourceConfig;
        this.workerConfig = workerConfig;
        this.clusterState = clusterState;
    }
 
    public ResourceConfig resourceConfig(){
        return this.resourceConfig;
    }
 
    public WorkerConfig workerConfig(){
        return this.workerConfig;
    }
 
    public ConnectClusterState clusterState(){
        return this.clusterState;
    }
}

 

We will be introducing another new public API ConnectClusterState which will at present provide some of the read only methods from the Herder.  The change would also include a default implementation ConnectClusterStateImpl in the connect runtime that will delegate to the underlying Herder. This will be useful when you want to add new resources like healthcheck, monitoring, etc.

interface ConnectClusterState{
    /**
     * Get a list of connectors currently running in this cluster. This is a full list of connectors in the cluster gathered
     * from the current configuration.
     */
    Collection<String> connectors();
 
    /**
     * Lookup the current status of a connector.
     * @param connName name of the connector
     */
    ConnectorStateInfo connectorStatus(String connName);
 
}
 
class ConnectClusterStateImpl implements ConnectClusterState{
    private final Herder herder;
 
    public ConnectClusterStateImpl(Herder herder){
        this.herder = herder;
    }
 
    @Override
    Collection<String> connectors(){
        //delegate to herder
    }
 
    @Override
    ConnectorStateInfo connectorStatus(String connName);{
        //delegate to herder
    }
}
Plugin Integration with Connect

The plugin's would be registered in the RestServer.start(Herder herder) method before registering the default Connect resources. Currently, when there are duplicate registrations the first registration wins in Jersey but it is an implementation detail of Jersey and Connect can't gurantee this. Hence, it is recommended that the plugins don't re-register the default Connect Resources. This could potentially lead to unexpected errors.The close for the plugins would be invoked as part of the stop() in the same class. 

The new extension class and its dependencies would need to be as part of the plugin path. Hence ConnectRestPlugin would be defined as a new plugin to be loaded by the PluginClassLoader.The plugin would be looked up based on Service Provider mechanism instead of the Reflections scan that is used for other plugins. This will help in terms of not adding class loader cost that is associated in scanning the classes today for other plugins.

Example

Consider the following example that defines a single plugin to add an authenticating filter and a health check resource.

class  ExampleConnectPlugin implements ConnectRestPlugin{
    public void register(ConnectRestPluginContext restPluginContext){
        resourceConfig.register(new AuthenticationFilter(restPluginContext.workerConfig()));
        resourceConfig.register(new HealthCheckResource(restPluginContext.workerConfig(), restPluginContext.clusterState()));
    }
 
    public void close() {
        //close any resources
    }
}
 
class AuthenticationFilter implements ContainerRequestFilter {
 
  public AuthenticationFilter(WorkerConfig workerConfig){
    //set up filter
  }
     
  @Override
  public void filter(ContainerRequestContext requestContext) {
        //authentication logic
  }
 
}
 
@Path("/connect")
class HealthCheckResource {
 
    public HealthCheckResource(WorkerConfig workerConfig, ConnectClusterState clusterState){
        //initialize resource
    }
 
    @path("/health")
    public void healthcheck(){
        //check herder health
    }
}

The above illustrated plugin can then be configured in the worker's configuration as below

 

connect-worker.properties
 // configure plugin
rest.plugins=com.example.ExampleConnectPlugin

 

Compatibility, Deprecation, and Migration Plan

  • This is entirely new functionality so there are no compatibility, deprecation, or migration concerns.

Rejected Alternatives

  1. Creating configs specific to the plugin and just passing them to the plugin based on a prefix. It was considered much easier to make the complete WorkerConfig. Also, in many cases the plugins would need to know just more than their configs to implement their actions. 
  2. Passing the Herder to the plugin was considered but it was rejected since the Herder API is not public and we don't want to expose the complete Herder capabilities to the plugin.
  3. Providing ability to just add Filters insteda of any kind of Jersey resource was considered but it was rejected because it was too limiting in its capability that one canot add new resource end points or add a jersey provider.
  4. Registering the plugin after the default Connector resources are registered is rejected because of the fact that we don't want to allow users to remove resources at the moment.
  5. Having the Connect REST plugin as part of class path is rejected for the same reason why we have custom interfaces like Converters and Connectors as plugin and loaded via plugin path.

 

  • No labels