Skip to content

Commit

Permalink
remove Solr backend
Browse files Browse the repository at this point in the history
  • Loading branch information
hmarkc committed Aug 30, 2021
1 parent 902e680 commit 4c9a069
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 815 deletions.
25 changes: 8 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<packaging>hpi</packaging>
<properties>
<lucene.version>5.3.1</lucene.version>
<solr.version>5.3.1</solr.version>
<junit.version>1.9</junit.version>
</properties>

Expand Down Expand Up @@ -70,22 +69,6 @@
<artifactId>lucene-highlighter</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>${solr.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-backward-codecs</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down Expand Up @@ -123,6 +106,14 @@
<forkCount>1</forkCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.remoting.VirtualChannel;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import hudson.util.LogTaskListener;
import jenkins.MasterToSlaveFileCallable;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.File;
import java.io.IOException;
Expand All @@ -21,13 +26,6 @@
import java.util.Map;
import java.util.logging.Level;

import jenkins.MasterToSlaveFileCallable;

import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Supplies the methods and configuration data needed to get index artifacts.
* Doesn't do anything in the perform step, but should conceptually be a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,9 @@
import com.google.common.annotations.VisibleForTesting;
import hudson.Extension;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import jenkins.model.GlobalConfiguration;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
Expand All @@ -30,50 +16,43 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Extension
public class SearchBackendConfiguration extends GlobalConfiguration {

private static final String LUCENE_PATH = "lucenePath";
private static final String SOLR_URL = "solrUrl";
private static final String SOLR_COLLECTION = "solrCollection";
private static final String USE_SECURITY = "useSecurity";

@Inject
private transient SearchBackendManager backendManager;

private URI solrUrl = URI.create("http://127.0.0.1:8983/");
private File lucenePath = new File(Jenkins.getInstance().getRootDir(), "luceneIndex");
private String solrCollection = "collection1";
private SearchBackendEngine searchBackend = SearchBackendEngine.LUCENE;
private boolean useSecurity;

@DataBoundConstructor
public SearchBackendConfiguration(final String solrUrl, final String lucenePath, final String searchBackend,
final String solrCollection, boolean useSecurity) {
this(URI.create(solrUrl), new File(lucenePath), SearchBackendEngine.valueOf(searchBackend), solrCollection);
public SearchBackendConfiguration(final String lucenePath,
boolean useSecurity) {
this(new File(lucenePath), useSecurity);
}

public SearchBackendConfiguration(final URI solrUrl, final File lucenePath,
final SearchBackendEngine searchBackend, final String solrCollection) {
public SearchBackendConfiguration(final File lucenePath, boolean useSecurity) {
load();
this.searchBackend = searchBackend;
this.lucenePath = lucenePath;
this.solrUrl = solrUrl;
this.solrCollection = solrCollection;
this.useSecurity = useSecurity;
}

public SearchBackendConfiguration() {
load();
}

public String getSolrUrl() {
return solrUrl.toString();
}

public void setSolrUrl(final URI solrUrl) {
this.solrUrl = solrUrl;
}

public String getLucenePath() {
return lucenePath.toString();
}
Expand All @@ -82,18 +61,6 @@ public void setLucenePath(final File lucenePath) {
this.lucenePath = lucenePath;
}

public String getSearchBackend() {
return searchBackend.toString();
}

public SearchBackendEngine getSearchBackendEngine() {
return searchBackend;
}

public void setSearchBackend(final SearchBackendEngine searchBackend) {
this.searchBackend = searchBackend;
}

public FormValidation doCheckLucenePath(@QueryParameter final String lucenePath) {
try {
new File(lucenePath);
Expand Down Expand Up @@ -122,78 +89,9 @@ private List<String> getCollections(String baseUrl) throws IOException {
}
}

public ListBoxModel doFillSolrCollectionItems(@QueryParameter String solrUrl) {
ListBoxModel items = new ListBoxModel();
try {
for (String collection : getCollections(solrUrl)) {
items.add(collection);
}
} catch (IOException e) {
items.add("URL invalid");
}
return items;
}

@VisibleForTesting
public URI makeSolrUrl(final String solrUrlX) throws IOException {
IOException e = null;
String solrUrl = solrUrlX.replaceAll("/*$", "");
for (String s : new String[] { solrUrl + "/src/test/resources/solr", solrUrl }) {
try {
getCollections(s);
return URI.create(s);
} catch (IOException e2) {
e = e2;
}
}
throw e;
}

public FormValidation doCheckSolrUrl(@QueryParameter final String solrUrl) {
try {
URI uri = makeSolrUrl(solrUrl);
if (solrUrl.equals(uri.toString())) {
return FormValidation.ok();
} else {
return FormValidation.warning("Incomplete url, but solr was found at " + uri.toString());
}
} catch (IOException e) {
return FormValidation.error(e.getMessage());
}
}

public FormValidation doCheckSolrCollection(@QueryParameter final String solrCollection,
@QueryParameter String solrUrl) {
try {
List<String> collections = getCollections(solrUrl);
if (collections.contains(solrCollection)) {
return FormValidation.ok();
} else {
return FormValidation.error("Collection not found among: " + collections);
}
} catch (IOException e) {
return FormValidation.error(e.getMessage());
}
}

@Override
public boolean configure(final StaplerRequest req, final JSONObject json) throws FormException {
JSONObject selectedJson = json.getJSONObject("searchBackend");
if (selectedJson.containsKey(SOLR_URL)) {
String solrUrl = selectedJson.getString(SOLR_URL);
ensureNotError(doCheckSolrUrl(solrUrl), SOLR_URL);
try {
setSolrUrl(makeSolrUrl(solrUrl));
} catch (IOException e) {
// Really shouldn't be possible, but this is the correct action, should it ever happen
throw new FormException("Incorrect freetext config", SOLR_URL);
}
}
if (selectedJson.containsKey(SOLR_COLLECTION)) {
String solrCollection = selectedJson.getString(SOLR_COLLECTION);
ensureNotError(doCheckSolrCollection(solrCollection, getSolrUrl()), SOLR_COLLECTION);
setSolrCollection(solrCollection);
}
if (selectedJson.containsKey(LUCENE_PATH)) {
String lucenePath = selectedJson.getString(LUCENE_PATH);
ensureNotError(doCheckLucenePath(lucenePath), LUCENE_PATH);
Expand All @@ -202,14 +100,17 @@ public boolean configure(final StaplerRequest req, final JSONObject json) throws
if (json.containsKey(USE_SECURITY)) {
setUseSecurity(json.getBoolean(USE_SECURITY));
}
setSearchBackend(SearchBackendEngine.valueOf(json.get("").toString()));
reconfigure();
try {
reconfigure();
} catch (IOException e) {
//
}
return super.configure(req, json);
}

@VisibleForTesting
public void reconfigure() {
backendManager.reconfigure(searchBackend, getConfig());
public void reconfigure() throws IOException {
backendManager.reconfigure(getConfig());
save();
}

Expand All @@ -221,20 +122,10 @@ private void ensureNotError(FormValidation formValidation, String field) throws

public Map<String, Object> getConfig() {
Map<String, Object> config = new HashMap<String, Object>();
config.put("solrUrl", solrUrl);
config.put("lucenePath", lucenePath);
config.put("solrCollection", solrCollection);
return config;
}

public String getSolrCollection() {
return solrCollection;
}

public void setSolrCollection(String solrCollection) {
this.solrCollection = solrCollection;
}

public boolean isUseSecurity() {
return useSecurity;
}
Expand Down

This file was deleted.

0 comments on commit 4c9a069

Please sign in to comment.