http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/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 deleted file mode 100644 index b0c0409..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java +++ /dev/null @@ -1,593 +0,0 @@ -/* - * 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/d9a661cf/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 deleted file mode 100644 index 1efaaf5..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/d9a661cf/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 deleted file mode 100644 index 92e2064..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/DocumentAnalysisRequest.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * 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; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/FieldAnalysisRequest.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/FieldAnalysisRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/FieldAnalysisRequest.java deleted file mode 100644 index 66ef535..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/FieldAnalysisRequest.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * 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.FieldAnalysisResponse; -import org.apache.solr.common.params.AnalysisParams; -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.Collection; -import java.util.LinkedList; -import java.util.List; - -/** - * A request for the org.apache.solr.handler.FieldAnalysisRequestHandler. - * - * - * @since solr.14 - */ -public class FieldAnalysisRequest extends SolrRequest<FieldAnalysisResponse> { - - private String fieldValue; - private String query; - private boolean showMatch; - private List<String> fieldNames; - private List<String> fieldTypes; - - /** - * Constructs a new FieldAnalysisRequest with a default uri of "/fieldanalysis". - */ - public FieldAnalysisRequest() { - super(METHOD.GET, "/analysis/field"); - } - - /** - * Constructs a new FieldAnalysisRequest with a given uri. - * - * @param uri the uri of the request handler. - */ - public FieldAnalysisRequest(String uri) { - super(METHOD.GET, uri); - } - - /** - * {@inheritDoc} - */ - @Override - public Collection<ContentStream> getContentStreams() throws IOException { - return null; - } - - @Override - protected FieldAnalysisResponse createResponse(SolrClient client) { - if (fieldTypes == null && fieldNames == null) { - throw new IllegalStateException("At least one field type or field name need to be specified"); - } - if (fieldValue == null) { - throw new IllegalStateException("The field value must be set"); - } - return new FieldAnalysisResponse(); - } - - /** - * {@inheritDoc} - */ - @Override - public SolrParams getParams() { - ModifiableSolrParams params = new ModifiableSolrParams(); - params.set(AnalysisParams.FIELD_VALUE, fieldValue); - if (query != null) { - params.add(AnalysisParams.QUERY, query); - params.add(AnalysisParams.SHOW_MATCH, String.valueOf(showMatch)); - } - if (fieldNames != null) { - String fieldNameValue = listToCommaDelimitedString(fieldNames); - params.add(AnalysisParams.FIELD_NAME, fieldNameValue); - } - if (fieldTypes != null) { - String fieldTypeValue = listToCommaDelimitedString(fieldTypes); - params.add(AnalysisParams.FIELD_TYPE, fieldTypeValue); - } - return params; - } - - //================================================ Helper Methods ================================================== - - /** - * Convers the given list of string to a comma-separated string. - * - * @param list The list of string. - * - * @return The comma-separated string. - */ - static String listToCommaDelimitedString(List<String> list) { - StringBuilder result = new StringBuilder(); - for (String str : list) { - if (result.length() > 0) { - result.append(","); - } - result.append(str); - } - return result.toString(); - } - - - //============================================ Setter/Getter Methods =============================================== - - /** - * Sets the field value to be analyzed. - * - * @param fieldValue The field value to be analyzed. - * - * @return This FieldAnalysisRequest (fluent interface support). - */ - public FieldAnalysisRequest setFieldValue(String fieldValue) { - this.fieldValue = fieldValue; - return this; - } - - /** - * Returns the field value that will be analyzed when this request is processed. - * - * @return The field value that will be analyzed when this request is processed. - */ - public String getFieldValue() { - return fieldValue; - } - - /** - * Sets the query to be analyzed. May be {@code null} indicated that no query analysis should take place. - * - * @param query The query to be analyzed. - * - * @return This FieldAnalysisRequest (fluent interface support). - */ - public FieldAnalysisRequest setQuery(String query) { - this.query = query; - return this; - } - - /** - * Returns the query that will be analyzed. May return {@code null} indicating that no query analysis will be - * performed. - * - * @return The query that will be analyzed. May return {@code null} indicating that no query analysis will be - * performed. - */ - public String getQuery() { - return query; - } - - /** - * 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 FieldAnalysisRequest (fluent interface support). - */ - public FieldAnalysisRequest setShowMatch(boolean showMatch) { - this.showMatch = showMatch; - return this; - } - - /** - * Returns whether index time tokens that match query time tokens should be marked as a "match". - * - * @return Whether index time tokens that match query time tokens should be marked as a "match". - * - * @see #setShowMatch(boolean) - */ - public boolean isShowMatch() { - return showMatch; - } - - /** - * Adds the given field name for analysis. - * - * @param fieldName A field name on which the analysis should be performed. - * - * @return this FieldAnalysisRequest (fluent interface support). - */ - public FieldAnalysisRequest addFieldName(String fieldName) { - if (fieldNames == null) { - fieldNames = new LinkedList<>(); - } - fieldNames.add(fieldName); - return this; - } - - /** - * Sets the field names on which the analysis should be performed. - * - * @param fieldNames The field names on which the analysis should be performed. - * - * @return this FieldAnalysisRequest (fluent interface support). - */ - public FieldAnalysisRequest setFieldNames(List<String> fieldNames) { - this.fieldNames = fieldNames; - return this; - } - - /** - * Returns a list of field names the analysis should be performed on. May return {@code null} indicating that no - * analysis will be performed on field names. - * - * @return The field names the analysis should be performed on. - */ - public List<String> getFieldNames() { - return fieldNames; - } - - /** - * Adds the given field type for analysis. - * - * @param fieldTypeName A field type name on which analysis should be performed. - * - * @return This FieldAnalysisRequest (fluent interface support). - */ - public FieldAnalysisRequest addFieldType(String fieldTypeName) { - if (fieldTypes == null) { - fieldTypes = new LinkedList<>(); - } - fieldTypes.add(fieldTypeName); - return this; - } - -/** - * Sets the field types on which analysis should be performed. - * - * @param fieldTypes The field type names on which analysis should be performed. - * - * @return This FieldAnalysisRequest (fluent interface support). - */ - public FieldAnalysisRequest setFieldTypes(List<String> fieldTypes) { - this.fieldTypes = fieldTypes; - return this; - } - - - /** - * Returns a list of field types the analysis should be performed on. May return {@code null} indicating that no - * analysis will be peformed on field types. - * - * @return The field types the analysis should be performed on. - */ - public List<String> getFieldTypes() { - return fieldTypes; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/IsUpdateRequest.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/IsUpdateRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/IsUpdateRequest.java deleted file mode 100644 index c1907d0..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/IsUpdateRequest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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; - -/** - * Marker class so that we can determine which requests are updates. - */ -public interface IsUpdateRequest { - -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/JavaBinUpdateRequestCodec.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/JavaBinUpdateRequestCodec.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/JavaBinUpdateRequestCodec.java deleted file mode 100644 index b46dc94..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/JavaBinUpdateRequestCodec.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * 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 java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.params.SolrParams; -import org.apache.solr.common.util.DataInputInputStream; -import org.apache.solr.common.util.JavaBinCodec; -import org.apache.solr.common.util.NamedList; - -/** - * Provides methods for marshalling an UpdateRequest to a NamedList which can be serialized in the javabin format and - * vice versa. - * - * - * @see org.apache.solr.common.util.JavaBinCodec - * @since solr 1.4 - */ -public class JavaBinUpdateRequestCodec { - - /** - * Converts an UpdateRequest to a NamedList which can be serialized to the given OutputStream in the javabin format - * - * @param updateRequest the UpdateRequest to be written out - * @param os the OutputStream to which the request is to be written - * - * @throws IOException in case of an exception during marshalling or writing to the stream - */ - public void marshal(UpdateRequest updateRequest, OutputStream os) throws IOException { - NamedList nl = new NamedList(); - NamedList params = solrParamsToNamedList(updateRequest.getParams()); - if (updateRequest.getCommitWithin() != -1) { - params.add("commitWithin", updateRequest.getCommitWithin()); - } - Iterator<SolrInputDocument> docIter = null; - - if(updateRequest.getDocIterator() != null){ - docIter = updateRequest.getDocIterator(); - } - - Map<SolrInputDocument,Map<String,Object>> docMap = updateRequest.getDocumentsMap(); - - nl.add("params", params);// 0: params - if (updateRequest.getDeleteByIdMap() != null) { - nl.add("delByIdMap", updateRequest.getDeleteByIdMap()); - } - nl.add("delByQ", updateRequest.getDeleteQuery()); - - if (docMap != null) { - nl.add("docsMap", docMap.entrySet().iterator()); - } else { - if (updateRequest.getDocuments() != null) { - docIter = updateRequest.getDocuments().iterator(); - } - nl.add("docs", docIter); - } - JavaBinCodec codec = new JavaBinCodec(); - codec.marshal(nl, os); - } - - /** - * Reads a NamedList from the given InputStream, converts it into a SolrInputDocument and passes it to the given - * StreamingUpdateHandler - * - * @param is the InputStream from which to read - * @param handler an instance of StreamingUpdateHandler to which SolrInputDocuments are streamed one by one - * - * @return the UpdateRequest - * - * @throws IOException in case of an exception while reading from the input stream or unmarshalling - */ - public UpdateRequest unmarshal(InputStream is, final StreamingUpdateHandler handler) throws IOException { - final UpdateRequest updateRequest = new UpdateRequest(); - List<String> delById; - Map<String,Map<String,Object>> delByIdMap; - List<String> delByQ; - final NamedList[] namedList = new NamedList[1]; - JavaBinCodec codec = new JavaBinCodec() { - - // NOTE: this only works because this is an anonymous inner class - // which will only ever be used on a single stream -- if this class - // is ever refactored, this will not work. - private boolean seenOuterMostDocIterator = false; - - @Override - public NamedList readNamedList(DataInputInputStream dis) throws IOException { - int sz = readSize(dis); - NamedList nl = new NamedList(); - if (namedList[0] == null) { - namedList[0] = nl; - } - for (int i = 0; i < sz; i++) { - String name = (String) readVal(dis); - Object val = readVal(dis); - nl.add(name, val); - } - return nl; - } - - @Override - public List readIterator(DataInputInputStream fis) throws IOException { - - // default behavior for reading any regular Iterator in the stream - if (seenOuterMostDocIterator) return super.readIterator(fis); - - // special treatment for first outermost Iterator - // (the list of documents) - seenOuterMostDocIterator = true; - return readOuterMostDocIterator(fis); - } - - private List readOuterMostDocIterator(DataInputInputStream fis) throws IOException { - NamedList params = (NamedList) namedList[0].get("params"); - updateRequest.setParams(new ModifiableSolrParams(SolrParams.toSolrParams(params))); - if (handler == null) return super.readIterator(fis); - Integer commitWithin = null; - Boolean overwrite = null; - while (true) { - Object o = readVal(fis); - if (o == END_OBJ) break; - SolrInputDocument sdoc = null; - if (o instanceof List) { - sdoc = listToSolrInputDocument((List<NamedList>) o); - } else if (o instanceof NamedList) { - UpdateRequest req = new UpdateRequest(); - req.setParams(new ModifiableSolrParams(SolrParams.toSolrParams((NamedList) o))); - handler.update(null, req, null, null); - } else if (o instanceof Map.Entry){ - sdoc = (SolrInputDocument) ((Map.Entry) o).getKey(); - Map p = (Map) ((Map.Entry) o).getValue(); - if (p != null) { - commitWithin = (Integer) p.get(UpdateRequest.COMMIT_WITHIN); - overwrite = (Boolean) p.get(UpdateRequest.OVERWRITE); - } - } else { - - sdoc = (SolrInputDocument) o; - } - handler.update(sdoc, updateRequest, commitWithin, overwrite); - } - return Collections.EMPTY_LIST; - } - - }; - - codec.unmarshal(is); - - // NOTE: if the update request contains only delete commands the params - // must be loaded now - if(updateRequest.getParams()==null) { - NamedList params = (NamedList) namedList[0].get("params"); - if(params!=null) { - updateRequest.setParams(new ModifiableSolrParams(SolrParams.toSolrParams(params))); - } - } - delById = (List<String>) namedList[0].get("delById"); - delByIdMap = (Map<String,Map<String,Object>>) namedList[0].get("delByIdMap"); - delByQ = (List<String>) namedList[0].get("delByQ"); - - // we don't add any docs, because they were already processed - // deletes are handled later, and must be passed back on the UpdateRequest - - if (delById != null) { - for (String s : delById) { - updateRequest.deleteById(s); - } - } - if (delByIdMap != null) { - for (Map.Entry<String,Map<String,Object>> entry : delByIdMap.entrySet()) { - Map<String,Object> params = entry.getValue(); - if (params != null) { - Long version = (Long) params.get(UpdateRequest.VER); - if (params.containsKey(UpdateRequest.ROUTE)) - updateRequest.deleteById(entry.getKey(), (String) params.get(UpdateRequest.ROUTE)); - else - updateRequest.deleteById(entry.getKey(), version); - } else { - updateRequest.deleteById(entry.getKey()); - } - - } - } - if (delByQ != null) { - for (String s : delByQ) { - updateRequest.deleteByQuery(s); - } - } - - return updateRequest; - } - - private SolrInputDocument listToSolrInputDocument(List<NamedList> namedList) { - SolrInputDocument doc = new SolrInputDocument(); - for (int i = 0; i < namedList.size(); i++) { - NamedList nl = namedList.get(i); - if (i == 0) { - doc.setDocumentBoost(nl.getVal(0) == null ? 1.0f : (Float) nl.getVal(0)); - } else { - doc.addField((String) nl.getVal(0), - nl.getVal(1), - nl.getVal(2) == null ? 1.0f : (Float) nl.getVal(2)); - } - } - return doc; - } - - private NamedList solrParamsToNamedList(SolrParams params) { - if (params == null) return new NamedList(); - return params.toNamedList(); - } - - public interface StreamingUpdateHandler { - void update(SolrInputDocument document, UpdateRequest req, Integer commitWithin, Boolean override); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/LukeRequest.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/LukeRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/LukeRequest.java deleted file mode 100644 index 82b5330..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/LukeRequest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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.LukeResponse; -import org.apache.solr.common.params.CommonParams; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.params.SolrParams; -import org.apache.solr.common.util.ContentStream; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * - * - * @since solr 1.3 - */ -public class LukeRequest extends SolrRequest<LukeResponse> { - - private List<String> fields; - private int numTerms = -1; - private boolean showSchema = false; - - public LukeRequest() - { - super( METHOD.GET, "/admin/luke" ); - } - - public LukeRequest( String path ) - { - super( METHOD.GET, path ); - } - - //--------------------------------------------------------------------------------- - //--------------------------------------------------------------------------------- - - public void addField( String f ) - { - if( fields == null ) { - fields = new ArrayList<>(); - } - fields.add( f ); - } - - public void setFields( List<String> f ) - { - fields = f; - } - - //--------------------------------------------------------------------------------- - //--------------------------------------------------------------------------------- - - public boolean isShowSchema() { - return showSchema; - } - - public void setShowSchema(boolean showSchema) { - this.showSchema = showSchema; - } - - public int getNumTerms() { - return numTerms; - } - - /** - * the number of terms to return for a given field. If the number is 0, it will not traverse the terms. - */ - public void setNumTerms(int count) { - this.numTerms = count; - } - - //--------------------------------------------------------------------------------- - //--------------------------------------------------------------------------------- - - @Override - public Collection<ContentStream> getContentStreams() { - return null; - } - - @Override - protected LukeResponse createResponse(SolrClient client) { - return new LukeResponse(); - } - - @Override - public SolrParams getParams() { - ModifiableSolrParams params = new ModifiableSolrParams(); - if( fields != null && fields.size() > 0 ) { - params.add( CommonParams.FL, fields.toArray( new String[fields.size()] ) ); - } - if( numTerms >= 0 ) { - params.add( "numTerms", numTerms+"" ); - } - if (showSchema) { - params.add("show", "schema"); - } - return params; - } - -} - http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/QueryRequest.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/QueryRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/QueryRequest.java deleted file mode 100644 index 9d47f99..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/QueryRequest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.QueryResponse; -import org.apache.solr.common.params.CommonParams; -import org.apache.solr.common.params.SolrParams; -import org.apache.solr.common.util.ContentStream; - -import java.util.Collection; - -/** - * - * - * @since solr 1.3 - */ -public class QueryRequest extends SolrRequest<QueryResponse> { - - private SolrParams query; - - public QueryRequest() - { - super( METHOD.GET, null ); - } - - public QueryRequest( SolrParams q ) - { - super( METHOD.GET, null ); - query = q; - } - - public QueryRequest( SolrParams q, METHOD method ) - { - super( method, null ); - query = q; - } - - /** - * Use the params 'QT' parameter if it exists - */ - @Override - public String getPath() { - String qt = query == null ? null : query.get( CommonParams.QT ); - if( qt == null ) { - qt = super.getPath(); - } - if( qt != null && qt.startsWith( "/" ) ) { - return qt; - } - return "/select"; - } - - //--------------------------------------------------------------------------------- - //--------------------------------------------------------------------------------- - - @Override - public Collection<ContentStream> getContentStreams() { - return null; - } - - @Override - protected QueryResponse createResponse(SolrClient client) { - return new QueryResponse(client); - } - - @Override - public SolrParams getParams() { - return query; - } - -} - http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/RequestWriter.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/RequestWriter.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/RequestWriter.java deleted file mode 100644 index 15872b2..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/RequestWriter.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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.SolrRequest; -import org.apache.solr.client.solrj.util.ClientUtils; -import org.apache.solr.common.util.ContentStream; -import org.apache.solr.common.util.ContentStreamBase; - -import java.io.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -/** - * A RequestWriter is used to write requests to Solr. - * <p> - * A subclass can override the methods in this class to supply a custom format in which a request can be sent. - * - * - * @since solr 1.4 - */ -public class RequestWriter { - public static final Charset UTF_8 = StandardCharsets.UTF_8; - - public Collection<ContentStream> getContentStreams(SolrRequest req) throws IOException { - if (req instanceof UpdateRequest) { - UpdateRequest updateRequest = (UpdateRequest) req; - if (isEmpty(updateRequest)) return null; - List<ContentStream> l = new ArrayList<>(); - l.add(new LazyContentStream(updateRequest)); - return l; - } - return req.getContentStreams(); - } - - private boolean isEmpty(UpdateRequest updateRequest) { - return isNull(updateRequest.getDocuments()) && - isNull(updateRequest.getDeleteByIdMap()) && - isNull(updateRequest.getDeleteQuery()) && - updateRequest.getDocIterator() == null; - } - - public String getPath(SolrRequest req) { - return req.getPath(); - } - - public ContentStream getContentStream(UpdateRequest req) throws IOException { - return new ContentStreamBase.StringStream(req.getXML()); - } - - public void write(SolrRequest request, OutputStream os) throws IOException { - if (request instanceof UpdateRequest) { - UpdateRequest updateRequest = (UpdateRequest) request; - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, UTF_8)); - updateRequest.writeXML(writer); - writer.flush(); - } - } - - public String getUpdateContentType() { - return ClientUtils.TEXT_XML; - - } - - public class LazyContentStream implements ContentStream { - ContentStream contentStream = null; - UpdateRequest req = null; - - public LazyContentStream(UpdateRequest req) { - this.req = req; - } - - private ContentStream getDelegate() { - if (contentStream == null) { - try { - contentStream = getContentStream(req); - } catch (IOException e) { - throw new RuntimeException("Unable to write xml into a stream", e); - } - } - return contentStream; - } - - @Override - public String getName() { - return getDelegate().getName(); - } - - @Override - public String getSourceInfo() { - return getDelegate().getSourceInfo(); - } - - @Override - public String getContentType() { - return getUpdateContentType(); - } - - @Override - public Long getSize() { - return getDelegate().getSize(); - } - - @Override - public InputStream getStream() throws IOException { - return getDelegate().getStream(); - } - - @Override - public Reader getReader() throws IOException { - return getDelegate().getReader(); - } - - public void writeTo(OutputStream os) throws IOException { - write(req, os); - - } - } - - protected boolean isNull(List l) { - return l == null || l.isEmpty(); - } - - protected boolean isNull(Map l) { - return l == null || l.isEmpty(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/SolrPing.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/SolrPing.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/SolrPing.java deleted file mode 100644 index 00ad41f..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/SolrPing.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.SolrPingResponse; -import org.apache.solr.common.params.CommonParams; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.util.ContentStream; - -import java.util.Collection; - -/** - * Verify that there is a working Solr core at the URL of a {@link org.apache.solr.client.solrj.SolrClient}. - * To use this class, the solrconfig.xml for the relevant core must include the - * request handler for <code>/admin/ping</code>. - * - * @since solr 1.3 - */ -public class SolrPing extends SolrRequest<SolrPingResponse> { - - /** serialVersionUID. */ - private static final long serialVersionUID = 5828246236669090017L; - - /** Request parameters. */ - private ModifiableSolrParams params; - - /** - * Create a new SolrPing object. - */ - public SolrPing() { - super(METHOD.GET, CommonParams.PING_HANDLER); - params = new ModifiableSolrParams(); - } - - @Override - public Collection<ContentStream> getContentStreams() { - return null; - } - - @Override - protected SolrPingResponse createResponse(SolrClient client) { - return new SolrPingResponse(); - } - - @Override - public ModifiableSolrParams getParams() { - return params; - } - - /** - * Remove the action parameter from this request. This will result in the same - * behavior as {@code SolrPing#setActionPing()}. For Solr server version 4.0 - * and later. - * - * @return this - */ - public SolrPing removeAction() { - params.remove(CommonParams.ACTION); - return this; - } - - /** - * Set the action parameter on this request to enable. This will delete the - * health-check file for the Solr core. For Solr server version 4.0 and later. - * - * @return this - */ - public SolrPing setActionDisable() { - params.set(CommonParams.ACTION, CommonParams.DISABLE); - return this; - } - - /** - * Set the action parameter on this request to enable. This will create the - * health-check file for the Solr core. For Solr server version 4.0 and later. - * - * @return this - */ - public SolrPing setActionEnable() { - params.set(CommonParams.ACTION, CommonParams.ENABLE); - return this; - } - - /** - * Set the action parameter on this request to ping. This is the same as not - * including the action at all. For Solr server version 4.0 and later. - * - * @return this - */ - public SolrPing setActionPing() { - params.set(CommonParams.ACTION, CommonParams.PING); - return this; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/UpdateRequest.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/UpdateRequest.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/UpdateRequest.java deleted file mode 100644 index 0e6580c..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/UpdateRequest.java +++ /dev/null @@ -1,463 +0,0 @@ -/* - * 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.impl.LBHttpSolrClient; -import org.apache.solr.client.solrj.util.ClientUtils; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.cloud.DocCollection; -import org.apache.solr.common.cloud.DocRouter; -import org.apache.solr.common.cloud.Slice; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.util.ContentStream; -import org.apache.solr.common.util.XML; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -/** - * - * - * @since solr 1.3 - */ -public class UpdateRequest extends AbstractUpdateRequest { - - public static final String REPFACT = "rf"; - public static final String MIN_REPFACT = "min_rf"; - public static final String VER = "ver"; - public static final String ROUTE = "_route_"; - public static final String OVERWRITE = "ow"; - public static final String COMMIT_WITHIN = "cw"; - private Map<SolrInputDocument,Map<String,Object>> documents = null; - private Iterator<SolrInputDocument> docIterator = null; - private Map<String,Map<String,Object>> deleteById = null; - private List<String> deleteQuery = null; - - public UpdateRequest() { - super(METHOD.POST, "/update"); - } - - public UpdateRequest(String url) { - super(METHOD.POST, url); - } - - // --------------------------------------------------------------------------- - // --------------------------------------------------------------------------- - - /** - * clear the pending documents and delete commands - */ - public void clear() { - if (documents != null) { - documents.clear(); - } - if (deleteById != null) { - deleteById.clear(); - } - if (deleteQuery != null) { - deleteQuery.clear(); - } - } - - // --------------------------------------------------------------------------- - // --------------------------------------------------------------------------- - - public UpdateRequest add(final SolrInputDocument doc) { - if (documents == null) { - documents = new LinkedHashMap<>(); - } - documents.put(doc, null); - return this; - } - - public UpdateRequest add(final SolrInputDocument doc, Boolean overwrite) { - return add(doc, null, overwrite); - } - - public UpdateRequest add(final SolrInputDocument doc, Integer commitWithin) { - return add(doc, commitWithin, null); - } - - public UpdateRequest add(final SolrInputDocument doc, Integer commitWithin, - Boolean overwrite) { - if (documents == null) { - documents = new LinkedHashMap<>(); - } - Map<String,Object> params = new HashMap<>(2); - if (commitWithin != null) params.put(COMMIT_WITHIN, commitWithin); - if (overwrite != null) params.put(OVERWRITE, overwrite); - - documents.put(doc, params); - - return this; - } - - public UpdateRequest add(final Collection<SolrInputDocument> docs) { - if (documents == null) { - documents = new LinkedHashMap<>(); - } - for (SolrInputDocument doc : docs) { - documents.put(doc, null); - } - return this; - } - - public UpdateRequest deleteById(String id) { - if (deleteById == null) { - deleteById = new LinkedHashMap<>(); - } - deleteById.put(id, null); - return this; - } - - public UpdateRequest deleteById(String id, String route) { - return deleteById(id, route, null); - } - - public UpdateRequest deleteById(String id, String route, Long version) { - if (deleteById == null) { - deleteById = new LinkedHashMap<>(); - } - Map<String, Object> params = (route == null && version == null) ? null : new HashMap<String, Object>(1); - if (version != null) - params.put(VER, version); - if (route != null) - params.put(ROUTE, route); - deleteById.put(id, params); - return this; - } - - - public UpdateRequest deleteById(List<String> ids) { - if (deleteById == null) { - deleteById = new LinkedHashMap<>(); - } - - for (String id : ids) { - deleteById.put(id, null); - } - - return this; - } - - public UpdateRequest deleteById(String id, Long version) { - return deleteById(id, null, version); - } - - public UpdateRequest deleteByQuery(String q) { - if (deleteQuery == null) { - deleteQuery = new ArrayList<>(); - } - deleteQuery.add(q); - return this; - } - - /** - * @param router to route updates with - * @param col DocCollection for the updates - * @param urlMap of the cluster - * @param params params to use - * @param idField the id field - * @return a Map of urls to requests - */ - public Map<String,LBHttpSolrClient.Req> getRoutes(DocRouter router, - DocCollection col, Map<String,List<String>> urlMap, - ModifiableSolrParams params, String idField) { - - if ((documents == null || documents.size() == 0) - && (deleteById == null || deleteById.size() == 0)) { - return null; - } - - Map<String,LBHttpSolrClient.Req> routes = new HashMap<>(); - if (documents != null) { - Set<Entry<SolrInputDocument,Map<String,Object>>> entries = documents.entrySet(); - for (Entry<SolrInputDocument,Map<String,Object>> entry : entries) { - SolrInputDocument doc = entry.getKey(); - Object id = doc.getFieldValue(idField); - if (id == null) { - return null; - } - Slice slice = router.getTargetSlice(id - .toString(), doc, null, null, col); - if (slice == null) { - return null; - } - List<String> urls = urlMap.get(slice.getName()); - String leaderUrl = urls.get(0); - LBHttpSolrClient.Req request = (LBHttpSolrClient.Req) routes - .get(leaderUrl); - if (request == null) { - UpdateRequest updateRequest = new UpdateRequest(); - updateRequest.setMethod(getMethod()); - updateRequest.setCommitWithin(getCommitWithin()); - updateRequest.setParams(params); - updateRequest.setPath(getPath()); - request = new LBHttpSolrClient.Req(updateRequest, urls); - routes.put(leaderUrl, request); - } - UpdateRequest urequest = (UpdateRequest) request.getRequest(); - Map<String,Object> value = entry.getValue(); - Boolean ow = null; - if (value != null) { - ow = (Boolean) value.get(OVERWRITE); - } - if (ow != null) { - urequest.add(doc, ow); - } else { - urequest.add(doc); - } - } - } - - // Route the deleteById's - - if (deleteById != null) { - - Iterator<Map.Entry<String,Map<String,Object>>> entries = deleteById.entrySet() - .iterator(); - while (entries.hasNext()) { - - Map.Entry<String,Map<String,Object>> entry = entries.next(); - - String deleteId = entry.getKey(); - Map<String,Object> map = entry.getValue(); - Long version = null; - if (map != null) { - version = (Long) map.get(VER); - } - Slice slice = router.getTargetSlice(deleteId, null, null, null, col); - if (slice == null) { - return null; - } - List<String> urls = urlMap.get(slice.getName()); - String leaderUrl = urls.get(0); - LBHttpSolrClient.Req request = routes.get(leaderUrl); - if (request != null) { - UpdateRequest urequest = (UpdateRequest) request.getRequest(); - urequest.deleteById(deleteId, version); - } else { - UpdateRequest urequest = new UpdateRequest(); - urequest.setParams(params); - urequest.deleteById(deleteId, version); - request = new LBHttpSolrClient.Req(urequest, urls); - routes.put(leaderUrl, request); - } - } - } - - return routes; - } - - public void setDocIterator(Iterator<SolrInputDocument> docIterator) { - this.docIterator = docIterator; - } - - public void setDeleteQuery(List<String> deleteQuery) { - this.deleteQuery = deleteQuery; - } - - // -------------------------------------------------------------------------- - // -------------------------------------------------------------------------- - - @Override - public Collection<ContentStream> getContentStreams() throws IOException { - return ClientUtils.toContentStreams(getXML(), ClientUtils.TEXT_XML); - } - - public String getXML() throws IOException { - StringWriter writer = new StringWriter(); - writeXML(writer); - writer.flush(); - - // If action is COMMIT or OPTIMIZE, it is sent with params - String xml = writer.toString(); - // System.out.println( "SEND:"+xml ); - return (xml.length() > 0) ? xml : null; - } - - private List<Map<SolrInputDocument,Map<String,Object>>> getDocLists(Map<SolrInputDocument,Map<String,Object>> documents) { - List<Map<SolrInputDocument,Map<String,Object>>> docLists = new ArrayList<>(); - Map<SolrInputDocument,Map<String,Object>> docList = null; - if (this.documents != null) { - - Boolean lastOverwrite = true; - Integer lastCommitWithin = -1; - - Set<Entry<SolrInputDocument,Map<String,Object>>> entries = this.documents - .entrySet(); - for (Entry<SolrInputDocument,Map<String,Object>> entry : entries) { - Map<String,Object> map = entry.getValue(); - Boolean overwrite = null; - Integer commitWithin = null; - if (map != null) { - overwrite = (Boolean) entry.getValue().get(OVERWRITE); - commitWithin = (Integer) entry.getValue().get(COMMIT_WITHIN); - } - if (overwrite != lastOverwrite || commitWithin != lastCommitWithin - || docLists.size() == 0) { - docList = new LinkedHashMap<>(); - docLists.add(docList); - } - docList.put(entry.getKey(), entry.getValue()); - lastCommitWithin = commitWithin; - lastOverwrite = overwrite; - } - } - - if (docIterator != null) { - docList = new LinkedHashMap<>(); - docLists.add(docList); - while (docIterator.hasNext()) { - SolrInputDocument doc = docIterator.next(); - if (doc != null) { - docList.put(doc, null); - } - } - - } - - return docLists; - } - - /** - * @since solr 1.4 - */ - public void writeXML(Writer writer) throws IOException { - List<Map<SolrInputDocument,Map<String,Object>>> getDocLists = getDocLists(documents); - - for (Map<SolrInputDocument,Map<String,Object>> docs : getDocLists) { - - if ((docs != null && docs.size() > 0)) { - Entry<SolrInputDocument,Map<String,Object>> firstDoc = docs.entrySet() - .iterator().next(); - Map<String,Object> map = firstDoc.getValue(); - Integer cw = null; - Boolean ow = null; - if (map != null) { - cw = (Integer) firstDoc.getValue().get(COMMIT_WITHIN); - ow = (Boolean) firstDoc.getValue().get(OVERWRITE); - } - if (ow == null) ow = true; - int commitWithin = (cw != null && cw != -1) ? cw : this.commitWithin; - boolean overwrite = ow; - if (commitWithin > -1 || overwrite != true) { - writer.write("<add commitWithin=\"" + commitWithin + "\" " - + "overwrite=\"" + overwrite + "\">"); - } else { - writer.write("<add>"); - } - - Set<Entry<SolrInputDocument,Map<String,Object>>> entries = docs - .entrySet(); - for (Entry<SolrInputDocument,Map<String,Object>> entry : entries) { - ClientUtils.writeXML(entry.getKey(), writer); - } - - writer.write("</add>"); - } - } - - // Add the delete commands - boolean deleteI = deleteById != null && deleteById.size() > 0; - boolean deleteQ = deleteQuery != null && deleteQuery.size() > 0; - if (deleteI || deleteQ) { - if (commitWithin > 0) { - writer.append("<delete commitWithin=\"" + commitWithin + "\">"); - } else { - writer.append("<delete>"); - } - if (deleteI) { - for (Map.Entry<String,Map<String,Object>> entry : deleteById.entrySet()) { - writer.append("<id"); - Map<String,Object> map = entry.getValue(); - if (map != null) { - Long version = (Long) map.get(VER); - String route = (String)map.get(ROUTE); - if (version != null) { - writer.append(" version=\"" + version + "\""); - } - - if (route != null) { - writer.append(" _route_=\"" + route + "\""); - } - } - writer.append(">"); - - XML.escapeCharData(entry.getKey(), writer); - writer.append("</id>"); - } - } - if (deleteQ) { - for (String q : deleteQuery) { - writer.append("<query>"); - XML.escapeCharData(q, writer); - writer.append("</query>"); - } - } - writer.append("</delete>"); - } - } - - // -------------------------------------------------------------------------- - // -------------------------------------------------------------------------- - - // -------------------------------------------------------------------------- - // - // -------------------------------------------------------------------------- - - public List<SolrInputDocument> getDocuments() { - if (documents == null) return null; - List<SolrInputDocument> docs = new ArrayList<>(documents.size()); - docs.addAll(documents.keySet()); - return docs; - } - - public Map<SolrInputDocument,Map<String,Object>> getDocumentsMap() { - return documents; - } - - public Iterator<SolrInputDocument> getDocIterator() { - return docIterator; - } - - public List<String> getDeleteById() { - if (deleteById == null) return null; - List<String> deletes = new ArrayList<>(deleteById.keySet()); - return deletes; - } - - public Map<String,Map<String,Object>> getDeleteByIdMap() { - return deleteById; - } - - public List<String> getDeleteQuery() { - return deleteQuery; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d9a661cf/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/package-info.java ---------------------------------------------------------------------- diff --git a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/package-info.java b/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/package-info.java deleted file mode 100644 index 899a562..0000000 --- a/ranger_solrj/src/main/java/org/apache/solr/client/solrj/request/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ - -/** - * Convenience classes for dealing with various types of Solr requests. - */ -package org.apache.solr.client.solrj.request; - -