Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update to version 8.11 #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
466 changes: 233 additions & 233 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.plugtree.solrmeter.model;

import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.AuthState;
import org.apache.http.auth.Credentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpCoreContext;

import java.io.IOException;

class PreemptiveAuthInterceptor implements HttpRequestInterceptor {

public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
// If no auth scheme available yet, try to initialize it
// preemptively
if (authState.getAuthScheme() == null) {
CredentialsProvider credsProvider = (CredentialsProvider)
context.getAttribute(HttpClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
Credentials creds = credsProvider.getCredentials(authScope);
if(creds == null){

}
authState.update(new BasicScheme(), creds);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.plugtree.solrmeter.model;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;

import com.plugtree.solrmeter.model.exception.QueryException;
Expand All @@ -27,17 +27,17 @@
public interface QueryExecutor {

/**
*
*
* @return The current Solr Server. If there is no current Solr Server, then the method returns a new one.
*/
SolrServer getSolrServer();
SolrClient getSolrServer();

/**
* To be executed when a Query succeeds.
* @param response
*/
void notifyQueryExecuted(QueryResponse response,
long clientTime);
long clientTime);

/**
* To be executed when a query fails
Expand Down Expand Up @@ -73,14 +73,14 @@ void notifyQueryExecuted(QueryResponse response,
void stop();

/**
* Set the number of operations expected per second
*/
* Set the number of operations expected per second
*/
void setOperationsPerSecond(int newOperationsPerSecond);

/**
* Determines whether this executor is running.
* @return
*/
boolean isRunning();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@
*/
package com.plugtree.solrmeter.model;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
/**
* This registry holds all the created solr servers. It will be one for each different url
* This registry holds all the created solr servers. It will be one for each different url
* and it wont change between tests.
* @author tflobbe
*
Expand All @@ -32,29 +42,42 @@ public class SolrServerRegistry {

protected static final Logger logger = Logger.getLogger(SolrServerRegistry.class);

private static final Map<String, SolrServer> servers = new HashMap<String, SolrServer>();
private static final Map<String, HttpSolrClient> servers = new HashMap<String, HttpSolrClient>();

public static synchronized SolrServer getSolrServer(String url) {
SolrServer server = servers.get(url);
public static synchronized SolrClient getSolrServer(String url) {
SolrClient server = servers.get(url);
if(server == null) {
logger.info("Connecting to Solr: " + url);
HttpSolrServer httpServer = new HttpSolrServer(url);
httpServer.setSoTimeout(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.soTimeout", "60000"))); // socket read timeout
httpServer.setConnectionTimeout(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.connectionTimeout", "60000")));
httpServer.setDefaultMaxConnectionsPerHost(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.defaultMaxConnectionsPerHost", "100000")));
httpServer.setMaxTotalConnections(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.maxTotalConnections", "1000000")));
httpServer.setFollowRedirects(Boolean.parseBoolean(SolrMeterConfiguration.getProperty("solr.server.configuration.followRedirect", "false"))); // defaults to false
httpServer.setAllowCompression(Boolean.parseBoolean(SolrMeterConfiguration.getProperty("solr.server.configuration.allowCompression", "true")));
httpServer.setMaxRetries(Integer.parseInt(SolrMeterConfiguration.getProperty("solr.server.configuration.maxRetries", "1"))); // defaults to 0. > 1 not recommended.
setAuthentication(httpServer);
servers.put(url, httpServer);
return httpServer;
String user = SolrMeterConfiguration.getProperty("solr.server.configuration.httpAuthUser");
String pass = SolrMeterConfiguration.getProperty("solr.server.configuration.httpAuthPass");
HttpSolrClient client;

HttpClientBuilder builder = HttpClientBuilder.create();
if (StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(pass)) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
AuthScope.ANY,
creds);

builder.addInterceptorFirst(new PreemptiveAuthInterceptor());
builder.setDefaultCredentialsProvider(credsProvider);
}

CloseableHttpClient httpClient = builder.build();

client = new HttpSolrClient.Builder().withBaseSolrUrl(url)
.withHttpClient(httpClient)
.build();

servers.put(url, client);
return client;

}
return server;
}

private static void setAuthentication(HttpSolrServer httpServer) {
private static void setAuthentication(HttpSolrClient httpServer) {
String user = SolrMeterConfiguration.getProperty("solr.server.configuration.httpAuthUser");
String pass = SolrMeterConfiguration.getProperty("solr.server.configuration.httpAuthPass");
if(user != null && !user.isEmpty() && pass != null && !pass.isEmpty()) {
Expand All @@ -67,9 +90,11 @@ private static void setAuthentication(HttpSolrServer httpServer) {
* Drops all existing SolrServers
*/
public static void invalidate() {
for(SolrServer server:servers.values()) {
if(server instanceof HttpSolrServer) {
((HttpSolrServer) server).shutdown();
for(SolrClient server:servers.values()) {
try {
server.close();
} catch (IOException e) {
e.printStackTrace();
}
}
servers.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.plugtree.solrmeter.model;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.response.UpdateResponse;

import com.plugtree.solrmeter.model.exception.CommitException;
Expand All @@ -28,10 +28,10 @@
public interface UpdateExecutor {

/**
*
*
* @return The current Solr Server. If there is no current Solr Server, then the method returns a new one.
*/
public SolrServer getSolrServer();
public SolrClient getSolrServer();

/**
* Starts this executor
Expand Down Expand Up @@ -80,13 +80,13 @@ public interface UpdateExecutor {
public int getNotCommitedDocuments();

/**
* Set the number of documents that has to be added before a commit is performed
* by solrmeter. This number is useless when solrmeter doesn't perform commits.
*/
* Set the number of documents that has to be added before a commit is performed
* by solrmeter. This number is useless when solrmeter doesn't perform commits.
*/
public void setNumberOfDocumentsBeforeCommit(int value);

/**
*
*
* @return The number of documents that has to be added before a commit is performed by
* solrmeter.
*/
Expand All @@ -100,7 +100,7 @@ public interface UpdateExecutor {
public void setMaxTimeBeforeCommit(Integer value);

/**
*
*
* @return The time interval between commits executed by solrmeter.
*/
public Integer getMaxTimeBeforeCommit();
Expand All @@ -113,21 +113,21 @@ public interface UpdateExecutor {
public boolean isAutocommit();

/**
*
*
* @return The number of update operations that has to be executed per minute
*/
public Integer getUpdatesPerMinute();

/**
*
*
* @return true if the executor is currently running.
* false if the executor is not currently running.
*/
public boolean isRunning();

/**
* Set the number of updates that has to be executed in a minute.
*/
public void setOperationsPerSecond(int value);
* Set the number of updates that has to be executed in a minute.
*/
public void setOperationsPerSecond(int value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrClient;

import com.plugtree.solrmeter.model.FileUtils;
import com.plugtree.solrmeter.model.SolrMeterConfiguration;
Expand Down Expand Up @@ -169,7 +169,7 @@ public void stop() {
* @return Return the Solr Server instance for the url. There is only one
* Solr Server for every difFerent url
*/
public SolrServer getSolrServer(String url) {
public SolrClient getSolrServer(String url) {
return SolrServerRegistry.getSolrServer(url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,54 @@
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrServer;

import com.plugtree.solrmeter.model.OptimizeExecutor;
import com.plugtree.solrmeter.model.OptimizeStatistic;
import com.plugtree.solrmeter.model.SolrMeterConfiguration;
import com.plugtree.solrmeter.model.SolrServerRegistry;
import com.plugtree.solrmeter.model.exception.OptimizeException;
import com.plugtree.stressTestScope.StressTestScope;
import org.apache.solr.client.solrj.SolrClient;

/**
* Executes an optimize only when the "execute" method is invoked
* @author tflobbe
*
*/
@StressTestScope
public class OnDemandOptimizeExecutor implements OptimizeExecutor {

protected final static Logger logger = Logger.getLogger(OnDemandOptimizeExecutor.class);

/**
* The Solr Server were the optimize is going to run.
*/
protected SolrServer server = null;
protected SolrClient server = null;

/**
* Indicates whether the index is being optimized or not at this time
*/
private boolean isOptimizing = false;

/**
* List of Statistics observing the operation
*/
protected List<OptimizeStatistic> optimizeObservers;

public OnDemandOptimizeExecutor() {
this(SolrServerRegistry.getSolrServer(SolrMeterConfiguration.getProperty(SolrMeterConfiguration.SOLR_ADD_URL)));
}
public OnDemandOptimizeExecutor(SolrServer server) {

public OnDemandOptimizeExecutor(SolrClient server) {
super();
optimizeObservers = new LinkedList<OptimizeStatistic>();
this.server = server;
}

/**
* {@inheritDoc}
*/
@Override
public synchronized void execute() {
if(isOptimizing) {
logger.warn("Trying to optimize while already optimizing");
Expand Down Expand Up @@ -118,17 +120,19 @@ private void notifyOptimizeFinished(long delay) {
observer.onOptimizeFinished(delay);
}
}

/**
* {@inheritDoc}
*/
@Override
public void addStatistic(OptimizeStatistic observer) {
this.optimizeObservers.add(observer);
}

/**
* {@inheritDoc}
*/
@Override
public boolean isOptimizing() {
return isOptimizing;
}
Expand Down
Loading