ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject [12/17] incubator-ranger git commit: Support for Solr as Audit Destination.
Date Tue, 17 Mar 2015 23:33:34 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
new file mode 100644
index 0000000..f9177c8
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/impl/XMLResponseParser.java
@@ -0,0 +1,465 @@
+/*
+ * 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.solr.client.solrj.impl;
+
+import org.apache.solr.client.solrj.ResponseParser;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.DateUtil;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.common.util.XMLErrorLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * 
+ *
+ * @since solr 1.3
+ */
+public class XMLResponseParser extends ResponseParser
+{
+  public static final String XML_CONTENT_TYPE = "application/xml; charset=UTF-8";
+  public static Logger log = LoggerFactory.getLogger(XMLResponseParser.class);
+  private static final XMLErrorLogger xmllog = new XMLErrorLogger(log);
+
+  // reuse the factory among all parser instances so things like string caches
+  // won't be duplicated
+  static final XMLInputFactory factory;
+  static {
+    factory = XMLInputFactory.newInstance();
+    try {
+      // The java 1.6 bundled stax parser (sjsxp) does not currently have a thread-safe
+      // XMLInputFactory, as that implementation tries to cache and reuse the
+      // XMLStreamReader.  Setting the parser-specific "reuse-instance" property to false
+      // prevents this.
+      // All other known open-source stax parsers (and the bea ref impl)
+      // have thread-safe factories.
+      factory.setProperty("reuse-instance", Boolean.FALSE);
+    }
+    catch( IllegalArgumentException ex ) {
+      // Other implementations will likely throw this exception since "reuse-instance"
+      // isimplementation specific.
+      log.debug( "Unable to set the 'reuse-instance' property for the input factory: "+factory );
+    }
+    factory.setXMLReporter(xmllog);
+  }
+
+  public XMLResponseParser() {}
+  
+  @Override
+  public String getWriterType()
+  {
+    return "xml";
+  }
+  
+  @Override
+  public String getContentType() {
+    return XML_CONTENT_TYPE;
+  }
+
+  @Override
+  public NamedList<Object> processResponse(Reader in) {
+    XMLStreamReader parser = null;
+    try {
+      parser = factory.createXMLStreamReader(in);
+    } catch (XMLStreamException e) {
+      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "parsing error", e);
+    }
+
+    return processResponse(parser);    
+  }
+
+  @Override
+  public NamedList<Object> processResponse(InputStream in, String encoding)
+  {
+     XMLStreamReader parser = null;
+    try {
+      parser = factory.createXMLStreamReader(in, encoding);
+    } catch (XMLStreamException e) {
+      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "parsing error", e);
+    }
+
+    return processResponse(parser);
+  }
+
+  /**
+   * parse the text into a named list...
+   */
+  private NamedList<Object> processResponse(XMLStreamReader parser)
+  {
+    try {
+      NamedList<Object> response = null;
+      for (int event = parser.next();  
+       event != XMLStreamConstants.END_DOCUMENT;
+       event = parser.next()) 
+      {
+        switch (event) {
+          case XMLStreamConstants.START_ELEMENT:
+
+            if( response != null ) {
+              throw new Exception( "already read the response!" );
+            }
+            
+            // only top-level element is "response
+            String name = parser.getLocalName();
+            if( name.equals( "response" ) || name.equals( "result" ) ) {
+              response = readNamedList( parser );
+            }
+            else if( name.equals( "solr" ) ) {
+              return new SimpleOrderedMap<>();
+            }
+            else {
+              throw new Exception( "really needs to be response or result.  " +
+                  "not:"+parser.getLocalName() );
+            }
+            break;
+        } 
+      } 
+      return response;
+    }
+    catch( Exception ex ) {
+      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "parsing error", ex );
+    }
+    finally {
+      try {
+        parser.close();
+      }
+      catch( Exception ex ){}
+    }
+  }
+
+  
+  protected enum KnownType {
+    STR    (true)  { @Override public String  read( String txt ) { return txt;                  } },
+    INT    (true)  { @Override public Integer read( String txt ) { return Integer.valueOf(txt); } },
+    FLOAT  (true)  { @Override public Float   read( String txt ) { return Float.valueOf(txt);   } },
+    DOUBLE (true)  { @Override public Double  read( String txt ) { return Double.valueOf(txt);  } },
+    LONG   (true)  { @Override public Long    read( String txt ) { return Long.valueOf(txt);    } },
+    BOOL   (true)  { @Override public Boolean read( String txt ) { return Boolean.valueOf(txt); } },
+    NULL   (true)  { @Override public Object  read( String txt ) { return null;                 } },
+    DATE   (true)  { 
+      @Override 
+      public Date read( String txt ) { 
+        try {
+          return DateUtil.parseDate(txt);      
+        }
+        catch( Exception ex ) {
+          ex.printStackTrace();
+        }
+        return null;
+      } 
+    },
+    
+    ARR    (false) { @Override public Object read( String txt ) { return null; } },
+    LST    (false) { @Override public Object read( String txt ) { return null; } },
+    RESULT (false) { @Override public Object read( String txt ) { return null; } },
+    DOC    (false) { @Override public Object read( String txt ) { return null; } };
+    
+    final boolean isLeaf;
+    
+    KnownType( boolean isLeaf )
+    {
+      this.isLeaf = isLeaf;
+    }
+    
+    public abstract Object read( String txt );
+    
+    public static KnownType get( String v )
+    {
+      if( v != null ) {
+        try {
+          return KnownType.valueOf( v.toUpperCase(Locale.ROOT) );
+        }
+        catch( Exception ex ) {}
+      }
+      return null;
+    }
+  };
+  
+  protected NamedList<Object> readNamedList( XMLStreamReader parser ) throws XMLStreamException
+  {
+    if( XMLStreamConstants.START_ELEMENT != parser.getEventType() ) {
+      throw new RuntimeException( "must be start element, not: "+parser.getEventType() );
+    }
+
+    StringBuilder builder = new StringBuilder();
+    NamedList<Object> nl = new SimpleOrderedMap<>();
+    KnownType type = null;
+    String name = null;
+    
+    // just eat up the events...
+    int depth = 0;
+    while( true ) 
+    {
+      switch (parser.next()) {
+      case XMLStreamConstants.START_ELEMENT:
+        depth++;
+        builder.setLength( 0 ); // reset the text
+        type = KnownType.get( parser.getLocalName() );
+        if( type == null ) {
+          throw new RuntimeException( "this must be known type! not: "+parser.getLocalName() );
+        }
+        
+        name = null;
+        int cnt = parser.getAttributeCount();
+        for( int i=0; i<cnt; i++ ) {
+          if( "name".equals( parser.getAttributeLocalName( i ) ) ) {
+            name = parser.getAttributeValue( i );
+            break;
+          }
+        }
+
+        /** The name in a NamedList can actually be null
+        if( name == null ) {
+          throw new XMLStreamException( "requires 'name' attribute: "+parser.getLocalName(), parser.getLocation() );
+        }
+        **/
+        
+        if( !type.isLeaf ) {
+          switch( type ) {
+          case LST:    nl.add( name, readNamedList( parser ) ); depth--; continue;
+          case ARR:    nl.add( name, readArray(     parser ) ); depth--; continue;
+          case RESULT: nl.add( name, readDocuments( parser ) ); depth--; continue;
+          case DOC:    nl.add( name, readDocument(  parser ) ); depth--; continue;
+          }
+          throw new XMLStreamException( "branch element not handled!", parser.getLocation() );
+        }
+        break;
+        
+      case XMLStreamConstants.END_ELEMENT:
+        if( --depth < 0 ) {
+          return nl;
+        }
+        //System.out.println( "NL:ELEM:"+type+"::"+name+"::"+builder );
+        nl.add( name, type.read( builder.toString().trim() ) );
+        break;
+
+      case XMLStreamConstants.SPACE: // TODO?  should this be trimmed? make sure it only gets one/two space?
+      case XMLStreamConstants.CDATA:
+      case XMLStreamConstants.CHARACTERS:
+        builder.append( parser.getText() );
+        break;
+      }
+    }
+  }
+
+  protected List<Object> readArray( XMLStreamReader parser ) throws XMLStreamException
+  {
+    if( XMLStreamConstants.START_ELEMENT != parser.getEventType() ) {
+      throw new RuntimeException( "must be start element, not: "+parser.getEventType() );
+    }
+    if( !"arr".equals( parser.getLocalName().toLowerCase(Locale.ROOT) ) ) {
+      throw new RuntimeException( "must be 'arr', not: "+parser.getLocalName() );
+    }
+    
+    StringBuilder builder = new StringBuilder();
+    KnownType type = null;
+
+    List<Object> vals = new ArrayList<>();
+
+    int depth = 0;
+    while( true ) 
+    {
+      switch (parser.next()) {
+      case XMLStreamConstants.START_ELEMENT:
+        depth++;
+        KnownType t = KnownType.get( parser.getLocalName() );
+        if( t == null ) {
+          throw new RuntimeException( "this must be known type! not: "+parser.getLocalName() );
+        }
+        if( type == null ) {
+          type = t;
+        }
+        /*** actually, there is no rule that arrays need the same type
+        else if( type != t && !(t == KnownType.NULL || type == KnownType.NULL)) {
+          throw new RuntimeException( "arrays must have the same type! ("+type+"!="+t+") "+parser.getLocalName() );
+        }
+        ***/
+        type = t;
+
+        builder.setLength( 0 ); // reset the text
+        
+        if( !type.isLeaf ) {
+          switch( type ) {
+          case LST:    vals.add( readNamedList( parser ) ); depth--; continue;
+          case ARR:    vals.add( readArray( parser ) ); depth--; continue;
+          case RESULT: vals.add( readDocuments( parser ) ); depth--; continue;
+          case DOC:    vals.add( readDocument( parser ) ); depth--; continue;
+          }
+          throw new XMLStreamException( "branch element not handled!", parser.getLocation() );
+        }
+        break;
+        
+      case XMLStreamConstants.END_ELEMENT:
+        if( --depth < 0 ) {
+          return vals; // the last element is itself
+        }
+        //System.out.println( "ARR:"+type+"::"+builder );
+        Object val = type.read( builder.toString().trim() );
+        if( val == null && type != KnownType.NULL) {
+          throw new XMLStreamException( "error reading value:"+type, parser.getLocation() );
+        }
+        vals.add( val );
+        break;
+
+      case XMLStreamConstants.SPACE: // TODO?  should this be trimmed? make sure it only gets one/two space?
+      case XMLStreamConstants.CDATA:
+      case XMLStreamConstants.CHARACTERS:
+        builder.append( parser.getText() );
+        break;
+    }
+    }
+  }
+  
+  protected SolrDocumentList readDocuments( XMLStreamReader parser ) throws XMLStreamException
+  {
+    SolrDocumentList docs = new SolrDocumentList();
+
+    // Parse the attributes
+    for( int i=0; i<parser.getAttributeCount(); i++ ) {
+      String n = parser.getAttributeLocalName( i );
+      String v = parser.getAttributeValue( i );
+      if( "numFound".equals( n ) ) {
+        docs.setNumFound( Long.parseLong( v ) );
+      }
+      else if( "start".equals( n ) ) {
+        docs.setStart( Long.parseLong( v ) );
+      }
+      else if( "maxScore".equals( n ) ) {
+        docs.setMaxScore( Float.parseFloat( v ) );
+      }
+    }
+    
+    // Read through each document
+    int event;
+    while( true ) {
+      event = parser.next();
+      if( XMLStreamConstants.START_ELEMENT == event ) {
+        if( !"doc".equals( parser.getLocalName() ) ) {
+          throw new RuntimeException( "should be doc! "+parser.getLocalName() + " :: " + parser.getLocation() );
+        }
+        docs.add( readDocument( parser ) );
+      }
+      else if ( XMLStreamConstants.END_ELEMENT == event ) {
+        return docs;  // only happens once
+      }
+    }
+  }
+
+  protected SolrDocument readDocument( XMLStreamReader parser ) throws XMLStreamException
+  {
+    if( XMLStreamConstants.START_ELEMENT != parser.getEventType() ) {
+      throw new RuntimeException( "must be start element, not: "+parser.getEventType() );
+    }
+    if( !"doc".equals( parser.getLocalName().toLowerCase(Locale.ROOT) ) ) {
+      throw new RuntimeException( "must be 'lst', not: "+parser.getLocalName() );
+    }
+
+    SolrDocument doc = new SolrDocument();
+    StringBuilder builder = new StringBuilder();
+    KnownType type = null;
+    String name = null;
+    
+    // just eat up the events...
+    int depth = 0;
+    while( true ) 
+    {
+      switch (parser.next()) {
+      case XMLStreamConstants.START_ELEMENT:
+        depth++;
+        builder.setLength( 0 ); // reset the text
+        type = KnownType.get( parser.getLocalName() );
+        if( type == null ) {
+          throw new RuntimeException( "this must be known type! not: "+parser.getLocalName() );
+        }
+        
+        name = null;
+        int cnt = parser.getAttributeCount();
+        for( int i=0; i<cnt; i++ ) {
+          if( "name".equals( parser.getAttributeLocalName( i ) ) ) {
+            name = parser.getAttributeValue( i );
+            break;
+          }
+        }
+
+        //Nested documents
+        while( type == KnownType.DOC) {
+          doc.addChildDocument(readDocument(parser));
+          int event = parser.next();
+          if (event == XMLStreamConstants.END_ELEMENT) { //Doc ends
+            return doc;
+          }
+        }
+        
+        if( name == null ) {
+          throw new XMLStreamException( "requires 'name' attribute: "+parser.getLocalName(), parser.getLocation() );
+        }
+        
+        // Handle multi-valued fields
+        if( type == KnownType.ARR ) {
+          for( Object val : readArray( parser ) ) {
+            doc.addField( name, val );
+          }
+          depth--; // the array reading clears out the 'endElement'
+        } else if( type == KnownType.LST ) {
+            doc.addField( name, readNamedList( parser ) );
+          depth--; 
+        } else if( !type.isLeaf ) {
+          System.out.println("nbot leaf!:" + type);
+          
+          throw new XMLStreamException( "must be value or array", parser.getLocation() );
+        }
+        break;
+        
+      case XMLStreamConstants.END_ELEMENT:
+        if( --depth < 0 ) {
+          return doc;
+        }
+        //System.out.println( "FIELD:"+type+"::"+name+"::"+builder );
+        Object val = type.read( builder.toString().trim() );
+        if( val == null ) {
+          throw new XMLStreamException( "error reading value:"+type, parser.getLocation() );
+        }
+        doc.addField( name, val );
+        break;
+
+      case XMLStreamConstants.SPACE: // TODO?  should this be trimmed? make sure it only gets one/two space?
+      case XMLStreamConstants.CDATA:
+      case XMLStreamConstants.CHARACTERS:
+        builder.append( parser.getText() );
+        break;
+      }
+    }
+  }
+
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/impl/package-info.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/impl/package-info.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/impl/package-info.java
new file mode 100644
index 0000000..491ef05
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/impl/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+ 
+/** 
+ * Concrete implementations of client API classes.
+
+ */
+package org.apache.solr.client.solrj.impl;
+
+

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/package-info.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/package-info.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/package-info.java
new file mode 100644
index 0000000..b88918e
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+ 
+/** 
+ * Primary APIs for communicating with a Solr Server from a Java client.
+ */
+package org.apache.solr.client.solrj;
+
+

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java
new file mode 100644
index 0000000..8fbc463
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java
@@ -0,0 +1,144 @@
+package org.apache.solr.client.solrj.request;
+/*
+ * 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.
+ */
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.UpdateParams;
+
+
+/**
+ *
+ *
+ **/
+public abstract class AbstractUpdateRequest extends SolrRequest<UpdateResponse> implements IsUpdateRequest {
+  protected ModifiableSolrParams params;
+  protected int commitWithin = -1;
+
+  public enum ACTION {
+    COMMIT,
+    OPTIMIZE
+  }
+
+  public AbstractUpdateRequest(METHOD m, String path) {
+    super(m, path);
+  }
+
+  /** Sets appropriate parameters for the given ACTION */
+  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher ) {
+    return setAction(action, waitFlush, waitSearcher, 1);
+  }
+
+  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, boolean softCommit ) {
+    return setAction(action, waitFlush, waitSearcher, softCommit, 1);
+  }
+
+  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, int maxSegments ) {
+    return setAction(action, waitFlush, waitSearcher, false, maxSegments);
+  }
+
+  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, boolean softCommit, int maxSegments ) {
+    if (params == null)
+      params = new ModifiableSolrParams();
+
+    if( action == ACTION.OPTIMIZE ) {
+      params.set( UpdateParams.OPTIMIZE, "true" );
+      params.set(UpdateParams.MAX_OPTIMIZE_SEGMENTS, maxSegments);
+    }
+    else if( action == ACTION.COMMIT ) {
+      params.set( UpdateParams.COMMIT, "true" );
+      params.set( UpdateParams.SOFT_COMMIT, String.valueOf(softCommit));
+    }
+    params.set( UpdateParams.WAIT_SEARCHER, String.valueOf(waitSearcher));
+    return this;
+  }
+
+  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, int maxSegments , boolean softCommit, boolean expungeDeletes) {
+    setAction(action, waitFlush, waitSearcher,softCommit,maxSegments) ;
+    params.set(UpdateParams.EXPUNGE_DELETES, String.valueOf(expungeDeletes));
+    return this;
+  }
+
+  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, int maxSegments , boolean expungeDeletes) {
+    return setAction(action, waitFlush, waitSearcher,maxSegments,false,expungeDeletes);
+  }
+
+  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, int maxSegments, boolean softCommit, boolean expungeDeletes, boolean openSearcher) {
+    setAction(action, waitFlush, waitSearcher, maxSegments, softCommit, expungeDeletes);
+    params.set(UpdateParams.OPEN_SEARCHER, String.valueOf(openSearcher));
+    return this;
+  }
+
+  /**
+   * @since Solr 1.4
+   */
+  public AbstractUpdateRequest rollback() {
+    if (params == null)
+      params = new ModifiableSolrParams();
+
+    params.set( UpdateParams.ROLLBACK, "true" );
+    return this;
+  }
+
+  public void setParam(String param, String value) {
+    if (params == null)
+      params = new ModifiableSolrParams();
+    params.set(param, value);
+  }
+
+  /** Sets the parameters for this update request, overwriting any previous */
+  public void setParams(ModifiableSolrParams params) {
+    this.params = params;
+  }
+
+  @Override
+  public ModifiableSolrParams getParams() {
+    return params;
+  }
+
+  @Override
+  protected UpdateResponse createResponse(SolrClient client) {
+    return new UpdateResponse();
+  }
+
+  public boolean isWaitSearcher() {
+    return params != null && params.getBool(UpdateParams.WAIT_SEARCHER, false);
+  }
+
+  public ACTION getAction() {
+    if (params==null) return null;
+    if (params.getBool(UpdateParams.COMMIT, false)) return ACTION.COMMIT;
+    if (params.getBool(UpdateParams.OPTIMIZE, false)) return ACTION.OPTIMIZE;
+    return null;
+  }
+
+  public void setWaitSearcher(boolean waitSearcher) {
+    setParam( UpdateParams.WAIT_SEARCHER, waitSearcher+"" );
+  }
+
+  public int getCommitWithin() {
+    return commitWithin;
+  }
+
+  public void setCommitWithin(int commitWithin) {
+    this.commitWithin = commitWithin;
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
new file mode 100644
index 0000000..1ad0b26
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
@@ -0,0 +1,860 @@
+/*
+ * 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.solr.client.solrj.request;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.response.CollectionAdminResponse;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.CollectionParams.CollectionAction;
+import org.apache.solr.common.params.CoreAdminParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.ShardParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStream;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * This class is experimental and subject to change.
+ *
+ * @since solr 4.5
+ */
+public class CollectionAdminRequest extends SolrRequest<CollectionAdminResponse> {
+
+  protected CollectionAction action = null;
+
+  private static String PROPERTY_PREFIX = "property.";
+
+  protected void setAction( CollectionAction action ) {
+    this.action = action;
+  }
+
+  public CollectionAdminRequest()
+  {
+    super( METHOD.GET, "/admin/collections" );
+  }
+
+  public CollectionAdminRequest( String path )
+  {
+    super( METHOD.GET, path );
+  }
+
+  @Override
+  public SolrParams getParams() {
+    if( action == null ) {
+      throw new RuntimeException( "no action specified!" );
+    }
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    params.set( CoreAdminParams.ACTION, action.toString() );
+    return params;
+  }
+
+  @Override
+  public Collection<ContentStream> getContentStreams() throws IOException {
+    return null;
+  }
+
+  @Override
+  protected CollectionAdminResponse createResponse(SolrClient client) {
+    return new CollectionAdminResponse();
+  }
+  
+  protected void addProperties(ModifiableSolrParams params, Properties props) {
+    Iterator<Map.Entry<Object, Object>> iter = props.entrySet().iterator();
+    while(iter.hasNext()) {
+      Map.Entry<Object, Object> prop = iter.next();
+      String key = (String) prop.getKey();
+      String value = (String) prop.getValue();
+      params.set(PROPERTY_PREFIX + key, value);
+    }
+  }
+
+  //---------------------------------------------------------------------------------------
+  //
+  //---------------------------------------------------------------------------------------
+
+  protected static class CollectionSpecificAdminRequest extends CollectionAdminRequest {
+    protected String collection = null;
+
+    public final void setCollectionName( String collectionName )
+    {
+      this.collection = collectionName;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.set( CoreAdminParams.NAME, collection );
+      return params;
+    }
+
+
+  }
+  
+  protected static class CollectionShardAdminRequest extends CollectionSpecificAdminRequest {
+    protected String shardName = null;
+
+    public void setShardName(String shard) { this.shardName = shard; }
+    public String getShardName() { return this.shardName; }
+
+    public ModifiableSolrParams getCommonParams() {
+      ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
+      params.set( "collection", collection );
+      params.set( "shard", shardName);
+      return params;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      return getCommonParams();
+    }
+  }
+  
+  protected static class CollectionAdminRoleRequest extends CollectionAdminRequest {
+    private String node;
+    private String role;
+
+    public void setNode(String node) {
+      this.node = node;
+    }
+
+    public String getNode() {
+      return this.node;
+    }
+
+    public void setRole(String role) {
+      this.role = role;
+    }
+
+    public String getRole() {
+      return this.role;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.set("role", this.role);
+      params.set("node", this.node);
+      return params;
+    }
+
+  }
+
+  /** Specific Collection API call implementations **/ 
+  
+  // CREATE request
+  public static class Create extends CollectionSpecificAdminRequest {
+    protected String configName = null;
+    protected String createNodeSet = null;
+    protected String routerName;
+    protected String shards;
+    protected String routerField;
+    protected Integer numShards;
+    protected Integer maxShardsPerNode;
+    protected Integer replicationFactor;
+
+    private Properties properties;
+    protected Boolean autoAddReplicas;
+    protected Integer stateFormat;
+    protected String asyncId;
+
+
+    public Create() {
+      action = CollectionAction.CREATE;
+    }
+
+    public void setConfigName(String config) { this.configName = config; }
+    public void setCreateNodeSet(String nodeSet) { this.createNodeSet = nodeSet; }
+    public void setRouterName(String routerName) { this.routerName = routerName; }
+    public void setShards(String shards) { this.shards = shards; }
+    public void setRouterField(String routerField) { this.routerField = routerField; }
+    public void setNumShards(Integer numShards) {this.numShards = numShards;}
+    public void setMaxShardsPerNode(Integer numShards) { this.maxShardsPerNode = numShards; }
+    public void setAutoAddReplicas(boolean autoAddReplicas) { this.autoAddReplicas = autoAddReplicas; }
+    public void setReplicationFactor(Integer repl) { this.replicationFactor = repl; }
+    public void setStateFormat(Integer stateFormat) { this.stateFormat = stateFormat; }
+    public void setAsyncId(String asyncId) {
+      this.asyncId = asyncId;
+    }
+
+    public String getConfigName()  { return configName; }
+    public String getCreateNodeSet() { return createNodeSet; }
+    public String getRouterName() { return  routerName; }
+    public String getShards() { return  shards; }
+    public Integer getNumShards() { return numShards; }
+    public Integer getMaxShardsPerNode() { return maxShardsPerNode; }
+    public Integer getReplicationFactor() { return replicationFactor; }
+    public Boolean getAutoAddReplicas() { return autoAddReplicas; }
+    public Integer getStateFormat() { return stateFormat; }
+    public String getAsyncId() {
+      return asyncId;
+    }
+
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
+
+      params.set( "collection.configName", configName);
+      params.set( "createNodeSet", createNodeSet);
+      if (numShards != null) {
+        params.set( ZkStateReader.NUM_SHARDS_PROP, numShards);
+      }
+      if (maxShardsPerNode != null) {
+        params.set( "maxShardsPerNode", maxShardsPerNode);
+      }
+      params.set( "router.name", routerName);
+      params.set("shards", shards);
+      if (routerField != null) {
+        params.set("router.field", routerField);
+      }
+      if (replicationFactor != null) {
+        params.set( "replicationFactor", replicationFactor);
+      }
+      params.set("async", asyncId);
+      if (autoAddReplicas != null) {
+        params.set(ZkStateReader.AUTO_ADD_REPLICAS, autoAddReplicas);
+      }
+      if(properties != null) {
+        addProperties(params, properties);
+      }
+      if (stateFormat != null) {
+        params.set(DocCollection.STATE_FORMAT, stateFormat);
+      }
+      return params;
+    }
+    
+  }
+
+  // RELOAD request
+  public static class Reload extends CollectionSpecificAdminRequest {
+    public Reload() {
+      action = CollectionAction.RELOAD;
+    }
+  }
+
+  // DELETE request
+  public static class Delete extends CollectionSpecificAdminRequest {
+    public Delete() {
+      action = CollectionAction.DELETE;
+    }
+  }
+
+  // CREATESHARD request
+  public static class CreateShard extends CollectionShardAdminRequest {
+    protected String nodeSet;
+    private Properties properties;
+
+    public void setNodeSet(String nodeSet) {
+      this.nodeSet = nodeSet;
+    }
+
+    public String getNodeSet() {
+      return nodeSet;
+    }
+
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
+
+    public CreateShard() {
+      action = CollectionAction.CREATESHARD;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = getCommonParams();
+      params.set( "createNodeSet", nodeSet);
+      if(properties != null) {
+        addProperties(params, properties);
+      }
+      return params;
+    }
+  }
+
+  // SPLITSHARD request
+  public static class SplitShard extends CollectionShardAdminRequest {
+    protected String ranges;
+    protected String splitKey;
+    protected String asyncId;
+    
+    private Properties properties;
+
+    public SplitShard() {
+      action = CollectionAction.SPLITSHARD;
+    }
+
+    public void setRanges(String ranges) { this.ranges = ranges; }
+    public String getRanges() { return ranges; }
+
+    public void setSplitKey(String splitKey) {
+      this.splitKey = splitKey;
+    }
+    
+    public String getSplitKey() {
+      return this.splitKey;
+    }
+    
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
+
+    public void setAsyncId(String asyncId) {
+      this.asyncId = asyncId;
+    }
+
+    public String getAsyncId() {
+      return asyncId;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = getCommonParams();
+      params.set( "ranges", ranges);
+
+      if(splitKey != null)
+        params.set("split.key", this.splitKey);
+      
+      if(properties != null) {
+        addProperties(params, properties);
+      }
+      
+      params.set("async", asyncId);
+      return params;
+    }
+  }
+
+  // DELETESHARD request
+  public static class DeleteShard extends CollectionShardAdminRequest {
+    public DeleteShard() {
+      action = CollectionAction.DELETESHARD;
+    }
+  }
+
+  // REQUESTSTATUS request
+  public static class RequestStatus extends CollectionAdminRequest {
+    protected  String requestId = null;
+
+    public RequestStatus() {
+      action = CollectionAction.REQUESTSTATUS;
+    }
+
+    public void setRequestId(String requestId) {this.requestId = requestId; }
+    public String getRequestId() { return this.requestId; }
+
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
+      params.set("requestid", requestId);
+      return params;
+    }
+  }
+  
+  // CREATEALIAS request
+  public static class CreateAlias extends CollectionAdminRequest {
+    protected String aliasName;
+    protected String aliasedCollections;
+
+    public CreateAlias() {
+      action = CollectionAction.CREATEALIAS;
+    }
+
+    public void setAliasName(String aliasName) {
+      this.aliasName = aliasName;
+    }
+
+    public String getAliasName() {
+      return aliasName;
+    }
+    
+    public void setAliasedCollections(String alias) { this.aliasedCollections = alias; }
+    public String getAliasedCollections() { return this.aliasedCollections; }
+    
+    @Deprecated
+    public void setCollectionName(String aliasName) {
+      this.aliasName = aliasName;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
+      params.set("name", aliasName);
+      params.set( "collections", aliasedCollections );
+      return params;
+    }
+  }
+
+  // DELETEALIAS request
+  public static class DeleteAlias extends CollectionAdminRequest {
+    protected String aliasName;
+    
+    public DeleteAlias() {
+      action = CollectionAction.DELETEALIAS;
+    }
+    
+    public void setAliasName(String aliasName) {
+      this.aliasName = aliasName;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.set("name", aliasName);
+      return params;
+    }
+  }
+
+  // ADDREPLICA request
+  public static class AddReplica extends CollectionShardAdminRequest {
+    private String node;
+    private String routeKey;
+    private String instanceDir;
+    private String dataDir;
+    private Properties properties;
+    private String asyncId;
+
+    public AddReplica() {
+      action = CollectionAction.ADDREPLICA;
+    }
+
+    public Properties getProperties() {
+      return properties;
+    }
+
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
+
+    public String getNode() {
+      return node;
+    }
+
+    public void setNode(String node) {
+      this.node = node;
+    }
+
+    public String getRouteKey() {
+      return routeKey;
+    }
+
+    public void setRouteKey(String routeKey) {
+      this.routeKey = routeKey;
+    }
+
+    public String getInstanceDir() {
+      return instanceDir;
+    }
+
+    public void setInstanceDir(String instanceDir) {
+      this.instanceDir = instanceDir;
+    }
+
+    public String getDataDir() {
+      return dataDir;
+    }
+
+    public void setDataDir(String dataDir) {
+      this.dataDir = dataDir;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      if (shardName == null || shardName.isEmpty()) {
+        params.remove("shard");
+        if (routeKey == null) {
+          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Either shard or routeKey must be provided");
+        }
+        params.add(ShardParams._ROUTE_, routeKey);
+      }
+      params.set("async", asyncId);
+      if (node != null) {
+        params.add("node", node);
+      }
+      if (instanceDir != null)  {
+        params.add("instanceDir", instanceDir);
+      }
+      if (dataDir != null)  {
+        params.add("dataDir", dataDir);
+      }
+      if (properties != null) {
+        addProperties(params, properties);
+      }
+      return params;
+    }
+
+    public void setAsyncId(String asyncId) {
+      this.asyncId = asyncId;
+    }
+    
+    public String getAsyncId() {
+      return asyncId;
+    }
+  }
+
+  // DELETEREPLICA request
+  public static class DeleteReplica extends CollectionShardAdminRequest {
+    private String replica;
+    private Boolean onlyIfDown;
+    
+    public DeleteReplica() {
+      action = CollectionAction.DELETEREPLICA;
+    }
+
+    public void setReplica(String replica) {
+      this.replica = replica;
+    }
+
+    public String getReplica() {
+      return this.replica;
+    }
+    
+    public void setOnlyIfDown(boolean onlyIfDown) {
+      this.onlyIfDown = onlyIfDown;
+    }
+    
+    public Boolean getOnlyIfDown() {
+      return this.onlyIfDown;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.set(ZkStateReader.REPLICA_PROP, this.replica);
+      
+      if(onlyIfDown != null) {
+        params.set("onlyIfDown", this.onlyIfDown);
+      }
+      return params;
+    }
+  }
+  
+  // CLUSTERPROP request
+  public static class ClusterProp extends CollectionAdminRequest {
+    private String propertyName;
+    private String propertyValue;
+    
+    public ClusterProp() {
+      this.action = CollectionAction.CLUSTERPROP;
+    }
+    
+    public void setPropertyName(String propertyName) {
+      this.propertyName = propertyName;
+    }
+
+    public String getPropertyName() {
+      return this.propertyName;
+    }
+
+    public void setPropertyValue(String propertyValue) {
+      this.propertyValue = propertyValue;
+    }
+    
+    public String getPropertyValue() {
+      return this.propertyValue;
+    }
+    
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.add("name", propertyName);
+      params.add("val", propertyValue);
+      
+      return params;
+    }
+    
+  }
+  
+  // MIGRATE request
+  public static class Migrate extends CollectionSpecificAdminRequest {
+    private String targetCollection;
+    private String splitKey;
+    private Integer forwardTimeout;
+    private Properties properties;
+    private String asyncId;
+    
+    public Migrate() {
+      action = CollectionAction.MIGRATE;
+    }
+    
+    public void setTargetCollection(String targetCollection) {
+      this.targetCollection = targetCollection;
+    }
+    
+    public String getTargetCollection() {
+      return this.targetCollection;
+    }
+    
+    public void setSplitKey(String splitKey) {
+      this.splitKey = splitKey;
+    }
+    
+    public String getSplitKey() {
+      return this.splitKey;
+    }
+    
+    public void setForwardTimeout(int forwardTimeout) {
+      this.forwardTimeout = forwardTimeout;
+    }
+    
+    public Integer getForwardTimeout() {
+      return this.forwardTimeout;
+    }
+    
+    public void setProperties(Properties properties) {
+      this.properties = properties;
+    }
+    
+    public Properties getProperties() {
+      return this.properties;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.set( "collection", collection );
+      params.set("target.collection", targetCollection);
+      params.set("split.key", splitKey);
+      if(forwardTimeout != null) {
+        params.set("forward.timeout", forwardTimeout);
+      }
+      params.set("async", asyncId);
+      
+      if(properties != null) {
+        addProperties(params, properties);
+      }
+      
+      return params;
+    }
+
+    public void setAsyncId(String asyncId) {
+      this.asyncId = asyncId;
+    }
+    
+    public String getAsyncId() {
+      return asyncId;
+    }
+  }
+  
+  // ADDROLE request
+  public static class AddRole extends CollectionAdminRoleRequest {
+    public AddRole() {
+      action = CollectionAction.ADDROLE;
+    }
+  }
+
+  // REMOVEROLE request
+  public static class RemoveRole extends CollectionAdminRoleRequest {
+    public RemoveRole() {
+      action = CollectionAction.REMOVEROLE;
+    }
+  }
+  
+  // OVERSEERSTATUS request
+  public static class OverseerStatus extends CollectionAdminRequest {
+    public OverseerStatus () {
+      action = CollectionAction.OVERSEERSTATUS;
+    }
+  }
+
+  // CLUSTERSTATUS request
+  public static class ClusterStatus extends CollectionShardAdminRequest {
+    
+    public ClusterStatus () {
+      action = CollectionAction.CLUSTERSTATUS;
+    }
+    
+  }
+
+  // LIST request
+  public static class List extends CollectionAdminRequest {
+    public List () {
+      action = CollectionAction.LIST;
+    }
+  }
+  
+  // ADDREPLICAPROP request
+  public static class AddReplicaProp extends CollectionShardAdminRequest {
+    private String replica;
+    private String propertyName;
+    private String propertyValue;
+    private Boolean shardUnique;
+    
+    public AddReplicaProp() {
+      action = CollectionAction.ADDREPLICAPROP;
+    }
+
+    public String getReplica() {
+      return replica;
+    }
+
+    public void setReplica(String replica) {
+      this.replica = replica;
+    }
+
+    public String getPropertyName() {
+      return propertyName;
+    }
+
+    public void setPropertyName(String propertyName) {
+      this.propertyName = propertyName;
+    }
+
+    public String getPropertyValue() {
+      return propertyValue;
+    }
+
+    public void setPropertyValue(String propertyValue) {
+      this.propertyValue = propertyValue;
+    }
+
+    public Boolean getShardUnique() {
+      return shardUnique;
+    }
+
+    public void setShardUnique(Boolean shardUnique) {
+      this.shardUnique = shardUnique;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.set("replica", replica);
+      params.set("property", propertyName);
+      params.set("property.value", propertyValue);
+      
+      if(shardUnique != null)
+        params.set("shardUnique", shardUnique);
+      
+      return params;
+    }
+    
+  }
+  
+  // DELETEREPLICAPROP request
+  public static class DeleteReplicaProp extends CollectionShardAdminRequest {
+    private String replica;
+    private String propertyName;
+
+    public DeleteReplicaProp() {
+      this.action = CollectionAction.DELETEREPLICAPROP;
+    }
+    
+    public String getReplica() {
+      return replica;
+    }
+
+    public void setReplica(String replica) {
+      this.replica = replica;
+    }
+
+    public String getPropertyName() {
+      return propertyName;
+    }
+
+    public void setPropertyName(String propertyName) {
+      this.propertyName = propertyName;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.set("replica", replica);
+      params.set("property", propertyName);
+      return params;
+    }
+  }
+  
+  // BALANCESHARDUNIQUE request
+  public static class BalanceShardUnique extends CollectionAdminRequest {
+    private String collection;
+    private String propertyName;
+    private Boolean onlyActiveNodes;
+    private Boolean shardUnique;
+    
+    public BalanceShardUnique() {
+      this.action = CollectionAction.BALANCESHARDUNIQUE;
+    }
+    
+    public String getPropertyName() {
+      return propertyName;
+    }
+
+    public void setPropertyName(String propertyName) {
+      this.propertyName = propertyName;
+    }
+
+    public Boolean getOnlyActiveNodes() {
+      return onlyActiveNodes;
+    }
+
+    public void setOnlyActiveNodes(Boolean onlyActiveNodes) {
+      this.onlyActiveNodes = onlyActiveNodes;
+    }
+
+    public Boolean getShardUnique() {
+      return shardUnique;
+    }
+
+    public void setShardUnique(Boolean shardUnique) {
+      this.shardUnique = shardUnique;
+    }
+
+    public void setCollection(String collection) {
+      this.collection = collection;
+    }
+    
+    public String getCollection() {
+      return collection;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
+      params.set("collection", collection);
+      params.set("property", propertyName);
+      if(onlyActiveNodes != null)
+        params.set("onlyactivenodes", onlyActiveNodes);
+      if(shardUnique != null)
+        params.set("shardUnique", shardUnique);
+      return params;
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/ContentStreamUpdateRequest.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/ContentStreamUpdateRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/ContentStreamUpdateRequest.java
new file mode 100644
index 0000000..2697e3f
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/ContentStreamUpdateRequest.java
@@ -0,0 +1,78 @@
+package org.apache.solr.client.solrj.request;
+/*
+ * 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.
+ */
+
+
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.ContentStreamBase;
+
+import java.io.IOException;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+
+/**
+ * Basic functionality to upload a File or {@link org.apache.solr.common.util.ContentStream} to a Solr Cell or some
+ * other handler that takes ContentStreams (CSV)
+ * <p>
+ * See http://wiki.apache.org/solr/ExtractingRequestHandler<br>
+ * See http://wiki.apache.org/solr/UpdateCSV
+ * 
+ *
+ **/
+public class ContentStreamUpdateRequest extends AbstractUpdateRequest {
+  List<ContentStream> contentStreams;
+
+  /**
+   *
+   * @param url The URL to send the {@link org.apache.solr.common.util.ContentStream} to in Solr.
+   */
+  public ContentStreamUpdateRequest(String url) {
+    super(METHOD.POST, url);
+    contentStreams = new ArrayList<>();
+  }
+
+  @Override
+  public Collection<ContentStream> getContentStreams() throws IOException {
+    return contentStreams;
+  }
+
+  /**
+   * Add a File to the {@link org.apache.solr.common.util.ContentStream}s.
+   * @param file The File to add.
+   * @throws IOException if there was an error with the file.
+   *
+   * @see #getContentStreams()
+   * @see org.apache.solr.common.util.ContentStreamBase.FileStream
+   */
+  public void addFile(File file, String contentType) throws IOException {
+    ContentStreamBase cs = new ContentStreamBase.FileStream(file);
+    cs.setContentType(contentType);
+    addContentStream(cs);
+  }
+
+  /**
+   * Add a {@link org.apache.solr.common.util.ContentStream} to {@link #getContentStreams()}
+   * @param contentStream The {@link org.apache.solr.common.util.ContentStream}
+   */
+  public void addContentStream(ContentStream contentStream){
+    contentStreams.add(contentStream);
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
new file mode 100644
index 0000000..b0c0409
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
@@ -0,0 +1,593 @@
+/*
+ * 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.solr.client.solrj.request;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.response.CoreAdminResponse;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.CoreAdminParams;
+import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStream;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * This class is experimental and subject to change.
+ *
+ * @since solr 1.3
+ */
+public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> {
+
+  protected String core = null;
+  protected String other = null;
+  protected boolean isIndexInfoNeeded = true;
+  protected CoreAdminParams.CoreAdminAction action = null;
+  
+  //a create core request
+  public static class Create extends CoreAdminRequest {
+
+    protected String instanceDir;
+    protected String configName = null;
+    protected String schemaName = null;
+    protected String dataDir = null;
+    protected String ulogDir = null;
+    protected String configSet = null;
+    protected String collection;
+    private Integer numShards;
+    private String shardId;
+    private String roles;
+    private String coreNodeName;
+    private Boolean loadOnStartup;
+    private Boolean isTransient;
+    private String collectionConfigName;
+
+    public Create() {
+      action = CoreAdminAction.CREATE;
+    }
+    
+    public void setInstanceDir(String instanceDir) { this.instanceDir = instanceDir; }
+    public void setSchemaName(String schema) { this.schemaName = schema; }
+    public void setConfigName(String config) { this.configName = config; }
+    public void setDataDir(String dataDir) { this.dataDir = dataDir; }
+    public void setUlogDir(String ulogDir) { this.ulogDir = ulogDir; }
+    public void setConfigSet(String configSet) {
+      this.configSet = configSet;
+    }
+    public void setCollection(String collection) { this.collection = collection; }
+    public void setNumShards(int numShards) {this.numShards = numShards;}
+    public void setShardId(String shardId) {this.shardId = shardId;}
+    public void setRoles(String roles) {this.roles = roles;}
+    public void setCoreNodeName(String coreNodeName) {this.coreNodeName = coreNodeName;}
+    public void setIsTransient(Boolean isTransient) { this.isTransient = isTransient; }
+    public void setIsLoadOnStartup(Boolean loadOnStartup) { this.loadOnStartup = loadOnStartup;}
+    public void setCollectionConfigName(String name) { this.collectionConfigName = name;}
+
+    public String getInstanceDir() { return instanceDir; }
+    public String getSchemaName()  { return schemaName; }
+    public String getConfigName()  { return configName; }
+    public String getDataDir() { return dataDir; }
+    public String getUlogDir() { return ulogDir; }
+    public String getConfigSet() {
+      return configSet;
+    }
+    public String getCollection() { return collection; }
+    public String getShardId() { return shardId; }
+    public String getRoles() { return roles; }
+    public String getCoreNodeName() { return coreNodeName; }
+    public Boolean getIsLoadOnStartup() { return loadOnStartup; }
+    public Boolean getIsTransient() { return isTransient; }
+    public String getCollectionConfigName() { return collectionConfigName;}
+    
+    @Override
+    public SolrParams getParams() {
+      if( action == null ) {
+        throw new RuntimeException( "no action specified!" );
+      }
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set( CoreAdminParams.ACTION, action.toString() );
+      if( action.equals(CoreAdminAction.CREATE) ) {
+        params.set( CoreAdminParams.NAME, core );
+      } else {
+        params.set( CoreAdminParams.CORE, core );
+      }
+      params.set( CoreAdminParams.INSTANCE_DIR, instanceDir);
+      if (configName != null) {
+        params.set( CoreAdminParams.CONFIG, configName);
+      }
+      if (schemaName != null) {
+        params.set( CoreAdminParams.SCHEMA, schemaName);
+      }
+      if (dataDir != null) {
+        params.set( CoreAdminParams.DATA_DIR, dataDir);
+      }
+      if (ulogDir != null) {
+        params.set( CoreAdminParams.ULOG_DIR, ulogDir);
+      }
+      if (configSet != null) {
+        params.set( CoreAdminParams.CONFIGSET, configSet);
+      }
+      if (collection != null) {
+        params.set( CoreAdminParams.COLLECTION, collection);
+      }
+      if (numShards != null) {
+        params.set( ZkStateReader.NUM_SHARDS_PROP, numShards);
+      }
+      if (shardId != null) {
+        params.set( CoreAdminParams.SHARD, shardId);
+      }
+      if (roles != null) {
+        params.set( CoreAdminParams.ROLES, roles);
+      }
+      if (coreNodeName != null) {
+        params.set( CoreAdminParams.CORE_NODE_NAME, coreNodeName);
+      }
+
+      if (isTransient != null) {
+        params.set(CoreAdminParams.TRANSIENT, isTransient);
+      }
+
+      if (loadOnStartup != null) {
+        params.set(CoreAdminParams.LOAD_ON_STARTUP, loadOnStartup);
+      }
+      
+      if (collectionConfigName != null) {
+        params.set("collection.configName", collectionConfigName);
+      }
+      
+      return params;
+    }
+
+  }
+  
+  public static class WaitForState extends CoreAdminRequest {
+    protected String nodeName;
+    protected String coreNodeName;
+    protected String state;
+    protected Boolean checkLive;
+    protected Boolean onlyIfLeader;
+    protected Boolean onlyIfLeaderActive;
+
+    public WaitForState() {
+      action = CoreAdminAction.PREPRECOVERY;
+    }
+    
+    public void setNodeName(String nodeName) {
+      this.nodeName = nodeName;
+    }
+    
+    public String getNodeName() {
+      return nodeName;
+    }
+    
+    public String getCoreNodeName() {
+      return coreNodeName;
+    }
+
+    public void setCoreNodeName(String coreNodeName) {
+      this.coreNodeName = coreNodeName;
+    }
+
+    public String getState() {
+      return state;
+    }
+
+    public void setState(String state) {
+      this.state = state;
+    }
+
+    public Boolean getCheckLive() {
+      return checkLive;
+    }
+
+    public void setCheckLive(Boolean checkLive) {
+      this.checkLive = checkLive;
+    }
+    
+    public boolean isOnlyIfLeader() {
+      return onlyIfLeader;
+    }
+
+    public void setOnlyIfLeader(boolean onlyIfLeader) {
+      this.onlyIfLeader = onlyIfLeader;
+    }
+    
+    public void setOnlyIfLeaderActive(boolean onlyIfLeaderActive) {
+      this.onlyIfLeaderActive = onlyIfLeaderActive;
+    }
+    
+    @Override
+    public SolrParams getParams() {
+      if( action == null ) {
+        throw new RuntimeException( "no action specified!" );
+      }
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set( CoreAdminParams.ACTION, action.toString() );
+ 
+      params.set( CoreAdminParams.CORE, core );
+      
+      if (nodeName != null) {
+        params.set( "nodeName", nodeName);
+      }
+      
+      if (coreNodeName != null) {
+        params.set( "coreNodeName", coreNodeName);
+      }
+      
+      if (state != null) {
+        params.set( "state", state);
+      }
+      
+      if (checkLive != null) {
+        params.set( "checkLive", checkLive);
+      }
+      
+      if (onlyIfLeader != null) {
+        params.set( "onlyIfLeader", onlyIfLeader);
+      }
+      
+      if (onlyIfLeaderActive != null) {
+        params.set( "onlyIfLeaderActive", onlyIfLeaderActive);
+      }
+
+      return params;
+    }
+    
+    public String toString() {
+      if (action != null) {
+        return "WaitForState: "+getParams();
+      } else {
+        return super.toString();
+      }
+    }
+  }
+  
+  public static class RequestRecovery extends CoreAdminRequest {
+
+    public RequestRecovery() {
+      action = CoreAdminAction.REQUESTRECOVERY;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      if( action == null ) {
+        throw new RuntimeException( "no action specified!" );
+      }
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set( CoreAdminParams.ACTION, action.toString() );
+ 
+      params.set( CoreAdminParams.CORE, core );
+
+      return params;
+    }
+  }
+  
+  public static class RequestSyncShard extends CoreAdminRequest {
+    private String shard;
+    private String collection;
+    
+    public RequestSyncShard() {
+      action = CoreAdminAction.REQUESTSYNCSHARD;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      if( action == null ) {
+        throw new RuntimeException( "no action specified!" );
+      }
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set(CoreAdminParams.ACTION, action.toString());
+      params.set("shard", shard);
+      params.set("collection", collection);
+      params.set(CoreAdminParams.CORE, core);
+      return params;
+    }
+
+    public String getShard() {
+      return shard;
+    }
+
+    public void setShard(String shard) {
+      this.shard = shard;
+    }
+
+    public String getCollection() {
+      return collection;
+    }
+
+    public void setCollection(String collection) {
+      this.collection = collection;
+    }
+  }
+  
+    //a persist core request
+  public static class Persist extends CoreAdminRequest {
+    protected String fileName = null;
+    
+    public Persist() {
+      action = CoreAdminAction.PERSIST;
+    }
+    
+    public void setFileName(String name) {
+      fileName = name;
+    }
+    public String getFileName() {
+      return fileName;
+    }
+    @Override
+    public SolrParams getParams() {
+      if( action == null ) {
+        throw new RuntimeException( "no action specified!" );
+      }
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set( CoreAdminParams.ACTION, action.toString() );
+      if (fileName != null) {
+        params.set( CoreAdminParams.FILE, fileName);
+      }
+      return params;
+    }
+  }
+  
+  public static class MergeIndexes extends CoreAdminRequest {
+    protected List<String> indexDirs;
+    protected List<String> srcCores;
+
+    public MergeIndexes() {
+      action = CoreAdminAction.MERGEINDEXES;
+    }
+
+    public void setIndexDirs(List<String> indexDirs) {
+      this.indexDirs = indexDirs;
+    }
+
+    public List<String> getIndexDirs() {
+      return indexDirs;
+    }
+
+    public List<String> getSrcCores() {
+      return srcCores;
+    }
+
+    public void setSrcCores(List<String> srcCores) {
+      this.srcCores = srcCores;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      if (action == null) {
+        throw new RuntimeException("no action specified!");
+      }
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set(CoreAdminParams.ACTION, action.toString());
+      params.set(CoreAdminParams.CORE, core);
+      if (indexDirs != null)  {
+        for (String indexDir : indexDirs) {
+          params.add(CoreAdminParams.INDEX_DIR, indexDir);
+        }
+      }
+      if (srcCores != null) {
+        for (String srcCore : srcCores) {
+          params.add(CoreAdminParams.SRC_CORE, srcCore);
+        }
+      }
+      return params;
+    }
+  }
+
+  public static class Unload extends CoreAdminRequest {
+    protected boolean deleteIndex;
+    protected boolean deleteDataDir;
+    protected boolean deleteInstanceDir;
+
+    public Unload(boolean deleteIndex) {
+      action = CoreAdminAction.UNLOAD;
+      this.deleteIndex = deleteIndex;
+    }
+
+    public boolean isDeleteIndex() {
+      return deleteIndex;
+    }
+
+    public void setDeleteIndex(boolean deleteIndex) {
+      this.deleteIndex = deleteIndex;
+    }
+
+    public void setDeleteDataDir(boolean deleteDataDir) {
+     this.deleteDataDir = deleteDataDir; 
+    }
+
+    public void setDeleteInstanceDir(boolean deleteInstanceDir){
+        this.deleteInstanceDir = deleteInstanceDir;
+    }
+
+    public boolean isDeleteDataDir() {
+      return deleteDataDir;
+    }
+
+    public boolean isDeleteInstanceDir() {
+      return deleteInstanceDir;
+    }
+
+    @Override
+    public SolrParams getParams() {
+      ModifiableSolrParams params = (ModifiableSolrParams) super.getParams();
+      params.set(CoreAdminParams.DELETE_INDEX, deleteIndex);
+      params.set(CoreAdminParams.DELETE_DATA_DIR, deleteDataDir);
+      params.set(CoreAdminParams.DELETE_INSTANCE_DIR, deleteInstanceDir);
+      return params;
+    }
+
+  }
+
+  public CoreAdminRequest()
+  {
+    super( METHOD.GET, "/admin/cores" );
+  }
+
+  public CoreAdminRequest( String path )
+  {
+    super( METHOD.GET, path );
+  }
+
+  public final void setCoreName( String coreName )
+  {
+    this.core = coreName;
+  }
+
+  public final void setOtherCoreName( String otherCoreName )
+  {
+    this.other = otherCoreName;
+  }
+
+  public final void setIndexInfoNeeded(boolean isIndexInfoNeeded) {
+    this.isIndexInfoNeeded = isIndexInfoNeeded;
+  }
+  
+  //---------------------------------------------------------------------------------------
+  //
+  //---------------------------------------------------------------------------------------
+
+  public void setAction( CoreAdminAction action )
+  {
+    this.action = action;
+  }
+
+  //---------------------------------------------------------------------------------------
+  //
+  //---------------------------------------------------------------------------------------
+
+  @Override
+  public SolrParams getParams() 
+  {
+    if( action == null ) {
+      throw new RuntimeException( "no action specified!" );
+    }
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    params.set( CoreAdminParams.ACTION, action.toString() );
+    params.set( CoreAdminParams.CORE, core );
+    params.set(CoreAdminParams.INDEX_INFO, (isIndexInfoNeeded ? "true" : "false"));
+    if (other != null) {
+      params.set(CoreAdminParams.OTHER, other);
+    }
+    return params;
+  }
+
+  //---------------------------------------------------------------------------------------
+  //
+  //---------------------------------------------------------------------------------------
+
+  @Override
+  public Collection<ContentStream> getContentStreams() throws IOException {
+    return null;
+  }
+
+  @Override
+  protected CoreAdminResponse createResponse(SolrClient client) {
+    return new CoreAdminResponse();
+  }
+
+  //---------------------------------------------------------------------------------------
+  //
+  //---------------------------------------------------------------------------------------
+
+  public static CoreAdminResponse reloadCore(String name, SolrClient client) throws SolrServerException, IOException
+  {
+    CoreAdminRequest req = new CoreAdminRequest();
+    req.setCoreName(name);
+    req.setAction(CoreAdminAction.RELOAD);
+    return req.process(client);
+  }
+
+  public static CoreAdminResponse unloadCore(String name, SolrClient client) throws SolrServerException, IOException
+  {
+    return unloadCore(name, false, client);
+  }
+
+  public static CoreAdminResponse unloadCore(String name, boolean deleteIndex, SolrClient client) throws SolrServerException, IOException {
+    return unloadCore(name, deleteIndex, false, client);
+  }
+
+  public static CoreAdminResponse unloadCore(String name, boolean deleteIndex, boolean deleteInstanceDir, SolrClient client) throws SolrServerException, IOException {
+    Unload req = new Unload(deleteIndex);
+    req.setCoreName(name);
+    req.setDeleteInstanceDir(deleteInstanceDir);
+    return req.process(client);
+  }
+
+  public static CoreAdminResponse renameCore(String coreName, String newName, SolrClient client ) throws SolrServerException, IOException
+  {
+    CoreAdminRequest req = new CoreAdminRequest();
+    req.setCoreName(coreName);
+    req.setOtherCoreName(newName);
+    req.setAction( CoreAdminAction.RENAME );
+    return req.process( client );
+  }
+
+  public static CoreAdminResponse getStatus( String name, SolrClient client ) throws SolrServerException, IOException
+  {
+    CoreAdminRequest req = new CoreAdminRequest();
+    req.setCoreName( name );
+    req.setAction( CoreAdminAction.STATUS );
+    return req.process( client );
+  }
+  
+  public static CoreAdminResponse createCore( String name, String instanceDir, SolrClient client ) throws SolrServerException, IOException
+  {
+    return CoreAdminRequest.createCore(name, instanceDir, client, null, null);
+  }
+  
+  public static CoreAdminResponse createCore( String name, String instanceDir, SolrClient client, String configFile, String schemaFile ) throws SolrServerException, IOException {
+    return createCore(name, instanceDir, client, configFile, schemaFile, null, null);
+  }
+  
+  public static CoreAdminResponse createCore( String name, String instanceDir, SolrClient client, String configFile, String schemaFile, String dataDir, String tlogDir ) throws SolrServerException, IOException
+  {
+    CoreAdminRequest.Create req = new CoreAdminRequest.Create();
+    req.setCoreName( name );
+    req.setInstanceDir(instanceDir);
+    if (dataDir != null) {
+      req.setDataDir(dataDir);
+    }
+    if (tlogDir != null) {
+      req.setUlogDir(tlogDir);
+    }
+    if(configFile != null){
+      req.setConfigName(configFile);
+    }
+    if(schemaFile != null){
+      req.setSchemaName(schemaFile);
+    }
+    return req.process( client );
+  }
+
+  public static CoreAdminResponse mergeIndexes(String name,
+      String[] indexDirs, String[] srcCores, SolrClient client) throws SolrServerException,
+      IOException {
+    CoreAdminRequest.MergeIndexes req = new CoreAdminRequest.MergeIndexes();
+    req.setCoreName(name);
+    req.setIndexDirs(Arrays.asList(indexDirs));
+    req.setSrcCores(Arrays.asList(srcCores));
+    return req.process(client);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java
new file mode 100644
index 0000000..1efaaf5
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.solr.client.solrj.request;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.client.solrj.util.ClientUtils;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStream;
+
+import java.util.Collection;
+
+/**
+ * Send arbitrary XML to a request handler
+ * 
+ *
+ * @since solr 1.3
+ */
+public class DirectXmlRequest extends SolrRequest<UpdateResponse> implements IsUpdateRequest {
+
+  final String xml;
+  private SolrParams params;
+  
+  public DirectXmlRequest( String path, String body )
+  {
+    super( METHOD.POST, path );
+    xml = body;
+  }
+
+  @Override
+  public Collection<ContentStream> getContentStreams() {
+    return ClientUtils.toContentStreams( xml, ClientUtils.TEXT_XML );
+  }
+
+  @Override
+  protected UpdateResponse createResponse(SolrClient client) {
+    return new UpdateResponse();
+  }
+
+  @Override
+  public SolrParams getParams() {
+    return params;
+  }
+
+
+  public void setParams(SolrParams params) {
+    this.params = params;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/40aa090d/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DocumentAnalysisRequest.java
----------------------------------------------------------------------
diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DocumentAnalysisRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DocumentAnalysisRequest.java
new file mode 100644
index 0000000..92e2064
--- /dev/null
+++ b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DocumentAnalysisRequest.java
@@ -0,0 +1,199 @@
+/*
+ * 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.solr.client.solrj.request;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.response.DocumentAnalysisResponse;
+import org.apache.solr.client.solrj.util.ClientUtils;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.AnalysisParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.ContentStream;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * A request for the org.apache.solr.handler.DocumentAnalysisRequestHandler.
+ *
+ *
+ * @since solr 1.4
+ */
+public class DocumentAnalysisRequest extends SolrRequest<DocumentAnalysisResponse> {
+
+  private List<SolrInputDocument> documents = new ArrayList<>();
+  private String query;
+  private boolean showMatch = false;
+
+  /**
+   * Constructs a new request with a default uri of "/documentanalysis".
+   */
+  public DocumentAnalysisRequest() {
+    super(METHOD.POST, "/analysis/document");
+  }
+
+  /**
+   * Constructs a new request with the given request handler uri.
+   *
+   * @param uri The of the request handler.
+   */
+  public DocumentAnalysisRequest(String uri) {
+    super(METHOD.POST, uri);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public Collection<ContentStream> getContentStreams() throws IOException {
+    return ClientUtils.toContentStreams(getXML(), ClientUtils.TEXT_XML);
+  }
+
+  @Override
+  protected DocumentAnalysisResponse createResponse(SolrClient client) {
+    return new DocumentAnalysisResponse();
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public ModifiableSolrParams getParams() {
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    if (query != null) {
+      params.add(AnalysisParams.QUERY, query);
+      params.add(AnalysisParams.SHOW_MATCH, String.valueOf(showMatch));
+    }
+    return params;
+  }
+
+  //================================================ Helper Methods ==================================================
+
+  /**
+   * Returns the xml be be set as the request body.
+   *
+   * @return The xml be be set as the request body.
+   *
+   * @throws IOException When constructing the xml fails
+   */
+  String getXML() throws IOException {
+    StringWriter writer = new StringWriter();
+    writer.write("<docs>");
+    for (SolrInputDocument document : documents) {
+      ClientUtils.writeXML(document, writer);
+    }
+    writer.write("</docs>");
+    writer.flush();
+
+    String xml = writer.toString();
+    return (xml.length() > 0) ? xml : null;
+  }
+
+
+  //============================================ Setter/Getter Methods ===============================================
+
+  /**
+   * Adds a document to be analyzed.
+   *
+   * @param doc The document to be analyzed.
+   *
+   * @return This DocumentAnalysisRequest (fluent interface support).
+   */
+  public DocumentAnalysisRequest addDocument(SolrInputDocument doc) {
+    documents.add(doc);
+    return this;
+  }
+
+  /**
+   * Adds a collection of documents to be analyzed.
+   *
+   * @param docs The documents to be analyzed.
+   *
+   * @return This DocumentAnalysisRequest (fluent interface support).
+   *
+   * @see #addDocument(org.apache.solr.common.SolrInputDocument)
+   */
+  public DocumentAnalysisRequest addDocuments(Collection<SolrInputDocument> docs) {
+    documents.addAll(docs);
+    return this;
+  }
+
+  /**
+   * Sets the query to be analyzed. By default the query is set to null, meaning no query analysis will be performed.
+   *
+   * @param query The query to be analyzed.
+   *
+   * @return This DocumentAnalysisRequest (fluent interface support).
+   */
+  public DocumentAnalysisRequest setQuery(String query) {
+    this.query = query;
+    return this;
+  }
+
+  /**
+   * Sets whether index time tokens that match query time tokens should be marked as a "match". By default this is set
+   * to {@code false}. Obviously, this flag is ignored if when the query is set to {@code null}.
+   *
+   * @param showMatch Sets whether index time tokens that match query time tokens should be marked as a "match".
+   *
+   * @return This DocumentAnalysisRequest (fluent interface support).
+   */
+  public DocumentAnalysisRequest setShowMatch(boolean showMatch) {
+    this.showMatch = showMatch;
+    return this;
+  }
+
+  /**
+   * Returns all documents that will be analyzed when processing the request.
+   *
+   * @return All documents that will be analyzed when processing the request.
+   *
+   * @see #addDocument(org.apache.solr.common.SolrInputDocument)
+   */
+  public List<SolrInputDocument> getDocuments() {
+    return documents;
+  }
+
+  /**
+   * Returns the query that will be analyzed when processing the request. May return {@code null} indicating that no
+   * query time analysis is taking place.
+   *
+   * @return The query that will be analyzed when processing the request.
+   *
+   * @see #setQuery(String)
+   */
+  public String getQuery() {
+    return query;
+  }
+
+  /**
+   * Returns whether index time tokens that match query time tokens will be marked as a "match".
+   *
+   * @return Whether index time tokens that match query time tokens will be marked as a "match".
+   *
+   * @see #setShowMatch(boolean)
+   */
+  public boolean isShowMatch() {
+    return showMatch;
+  }
+
+}


Mime
View raw message