Skip to content

Commit

Permalink
Package manager fixes and docs (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatman authored Jul 6, 2020
1 parent 0d5de54 commit 5501bdd
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 27 deletions.
45 changes: 38 additions & 7 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,54 @@ address accordingly

== Installation

=== Solr Plugin (Recommended)
=== Solr Package (Recommended as of Solr 8.6)

You can install **{project-name}** as a Solr Plugin:
==== Installation
You can install **{project-name}** as a Solr package:

[source,bash,subs="verbatim,attributes"]
----
bin/solr package add-repo yasa "https://raw.githubusercontent.com/yasa-org/yasa/master/repo/"
bin/solr package install yasa
# Should be unnecessary in the future
curl "http://localhost:8983/solr/admin/collections?action=CREATE&name=whatever&numShards=1"
bin/solr package undeploy yasa -y -collections whatever
bin/solr package deploy yasa -y -collections whatever
bin/solr package deploy yasa -y -cluster
----

Then navigate your browser to http://localhost:8983/v2/yasa

To register **{project-name}** at another path, you can use:
[source,bash,subs="verbatim,attributes"]
----
bin/solr package deploy yasa -y -cluster -p YASA-PATH-PREFIX=mysolrui
----

Then navigate your browser to http://localhost:8983/v2/mysolrui

==== Updating to a newer version
To check installed version and available versions of the package,
[source,bash,subs="verbatim,attributes"]
----
bin/solr package list-installed
bin/solr package list-available
----

To update to a newer version,
[source,bash,subs="verbatim,attributes"]
----
bin/solr package install yasa:<new-version>
bin/solr package deploy yasa:<new-version> -y -cluster -update
----

==== Undeploying
To undeploy,
[source,bash,subs="verbatim,attributes"]
----
bin/solr package undeploy yasa -cluster
----

Then navigate your browser to http://localhost:8983/v2/plugin/yasa/index.html

=== Standalone Mode

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<groupId>io.github.kezhenxu94</groupId>
<artifactId>yasa</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>

<modules>
<module>yasa-ui</module>
Expand Down
2 changes: 1 addition & 1 deletion yasa-solr-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>yasa</artifactId>
<groupId>io.github.kezhenxu94</groupId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
package io.github.kezhenxu94;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.IOUtils;
import org.apache.http.entity.ContentType;
import org.apache.lucene.analysis.util.ResourceLoader;
import org.apache.lucene.analysis.util.ResourceLoaderAware;
import org.apache.solr.api.Command;
import org.apache.solr.api.EndPoint;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.core.CoreContainer;
Expand All @@ -36,35 +42,50 @@
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.security.PermissionNameProvider;

import static io.github.kezhenxu94.YasaHandler.PLUGIN_PATH;

@EndPoint(
method = METHOD.GET,
path = PLUGIN_PATH + "/*",
path = "$path-prefix/*",
permission = PermissionNameProvider.Name.CONFIG_READ_PERM
)
@RequiredArgsConstructor
@SuppressWarnings("unused")
public class YasaHandler {
public static final String PLUGIN_PATH = "/plugin/yasa";

public class YasaHandler implements ResourceLoaderAware {
@SuppressWarnings("unused")
private final CoreContainer coreContainer;

private ResourceLoader loader = null;

@Override
public void inform(ResourceLoader loader) {
this.loader = loader;
}

@Command
public void call(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
final String path = req.getHttpSolrCall().getPath();
String path = req.getHttpSolrCall().getPath();
String filepath = resolveFilePath(path);

String filepath = path.substring(path.indexOf(PLUGIN_PATH) + PLUGIN_PATH.length());
if ("".equalsIgnoreCase(filepath) || "/".equalsIgnoreCase(filepath)) {
filepath = "/index.html";
final InputStream inputStream = loader.openResource(filepath);
if (inputStream == null) {
throw new SolrException(ErrorCode.NOT_FOUND, "File not found: " + filepath);
}

final byte[] data;
final String contentType;

if ("".equals(filepath)) {
String indexPath = path.endsWith("/") ? path + "index.html" : path + "/index.html";
indexPath = indexPath.replaceAll("____v2", "v2");
data = ("<meta http-equiv=\"Refresh\" content=\"0; url='" + indexPath + "'\" />").getBytes(
StandardCharsets.UTF_8);
contentType = ContentType.TEXT_HTML.getMimeType();
} else {
data = IOUtils.toByteArray(inputStream);
contentType = contentType(filepath);
}
final ModifiableSolrParams newParams = new ModifiableSolrParams(req.getOriginalParams());
newParams.set(CommonParams.WT, ReplicationHandler.FILE_STREAM);
req.setParams(newParams);

final String contentType = contentType(filepath);
final byte[] data = IOUtils.toByteArray(getClass().getResourceAsStream(filepath));
final SolrCore.RawWriter writer = new SolrCore.RawWriter() {

@Override
Expand Down Expand Up @@ -98,4 +119,18 @@ private String contentType(final String filepath) {
final String extension = filepath.split("\\.")[filepath.split("\\.").length - 1];
return types.getOrDefault(extension, "text/plain");
}

private String resolveFilePath(String path) {
// Path can be: /____v2/yasa/index.html
if (path.split("/").length < 3) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Can't parse path: " + path);
}
String basepath = "/" + path.split("/")[1] + "/" + path.split("/")[2];
String filepath = path.substring(path.indexOf(basepath) + basepath.length());

if (filepath.startsWith("/")) {
filepath = filepath.substring(1);
}
return filepath;
}
}
19 changes: 15 additions & 4 deletions yasa-solr-plugin/src/main/resources/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,35 @@
"plugins": [
{
"name": "yasa",
"type": "cluster",
"setup-command": {
"path": "/api/cluster/plugin",
"method": "POST",
"payload": {
"add": {
"name": "yasa",
"name": "${package-name}:${plugin-name}",
"class": "yasa:io.github.kezhenxu94.YasaHandler",
"version": "${package-version}"
"version": "${package-version}",
"path-prefix": "${YASA-PATH-PREFIX}"
}
}
},
"verify-command": {
"path": "/api/cluster/zk/data/clusterprops.json",
"method": "GET",
"condition": "$['plugin'].['${package-name}:${plugin-name}'].['version']",
"expected": "${package-version}"
},
"uninstall-command": {
"path": "/api/cluster/plugin",
"method": "POST",
"payload": {
"remove": "yasa"
"remove": "${package-name}:${plugin-name}"
}
}
}
]
],
"parameter-defaults": {
"YASA-PATH-PREFIX": "yasa"
}
}
2 changes: 1 addition & 1 deletion yasa-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>yasa</artifactId>
<groupId>io.github.kezhenxu94</groupId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down

0 comments on commit 5501bdd

Please sign in to comment.