Skip to content

Commit

Permalink
moved PluginInfo and refactored parsing from properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Jul 22, 2015
1 parent df63ccc commit 9f3afad
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.plugins.PluginInfo;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -75,7 +76,7 @@ public static PluginsInfo readPluginsInfo(StreamInput in) throws IOException {
public void readFrom(StreamInput in) throws IOException {
int plugins_size = in.readInt();
for (int i = 0; i < plugins_size; i++) {
infos.add(PluginInfo.readPluginInfo(in));
infos.add(PluginInfo.readFromStream(in));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.carrotsearch.hppc.cursors.ObjectIntCursor;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.PluginInfo;
import org.elasticsearch.plugins.PluginInfo;
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.StreamInput;
Expand All @@ -38,7 +38,6 @@
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.monitor.fs.FsInfo;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.monitor.os.OsInfo;

import java.io.IOException;
import java.net.InetAddress;
Expand Down Expand Up @@ -143,7 +142,7 @@ public void readFrom(StreamInput in) throws IOException {
size = in.readVInt();
plugins = new HashSet<>(size);
for (; size > 0; size--) {
plugins.add(PluginInfo.readPluginInfo(in));
plugins.add(PluginInfo.readFromStream(in));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.info;
package org.elasticsearch.plugins;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
Expand All @@ -26,9 +27,15 @@
import org.elasticsearch.common.xcontent.XContentBuilderString;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;

public class PluginInfo implements Streamable, ToXContent {

public static final String ES_PLUGIN_PROPERTIES = "plugin-descriptor.properties";

static final class Fields {
static final XContentBuilderString NAME = new XContentBuilderString("name");
static final XContentBuilderString DESCRIPTION = new XContentBuilderString("description");
Expand Down Expand Up @@ -61,7 +68,7 @@ public PluginInfo() {
* @param jvm true if it's a jvm plugin
* @param version Version number
*/
public PluginInfo(String name, String description, boolean site, String version, boolean jvm, String classname, boolean isolated) {
PluginInfo(String name, String description, boolean site, String version, boolean jvm, String classname, boolean isolated) {
this.name = name;
this.description = description;
this.site = site;
Expand All @@ -71,6 +78,42 @@ public PluginInfo(String name, String description, boolean site, String version,
this.isolated = isolated;
}

/** reads (and validates) plugin metadata descriptor file */
public static PluginInfo readFromProperties(Path dir) throws IOException {
Path descriptor = dir.resolve(ES_PLUGIN_PROPERTIES);
Properties props = new Properties();
try (InputStream stream = Files.newInputStream(descriptor)) {
props.load(stream);
}
String name = dir.getFileName().toString();
String description = props.getProperty("description");
if (description == null) {
throw new IllegalArgumentException("Property [description] is missing for plugin [" + name + "]");
}
String version = props.getProperty("version");
if (version == null) {
throw new IllegalArgumentException("Property [version] is missing for plugin [" + name + "]");
}
boolean jvm = Boolean.parseBoolean(props.getProperty("jvm"));
boolean site = Boolean.parseBoolean(props.getProperty("site"));
boolean isolated = true;
String classname = "NA";
if (jvm) {
isolated = Boolean.parseBoolean(props.getProperty("isolated", "true"));
classname = props.getProperty("plugin");
String esVersionString = props.getProperty("elasticsearch.version");
if (esVersionString == null) {
throw new IllegalArgumentException("Property [elasticsearch.version] is missing for jvm plugin [" + name + "]");
}
Version esVersion = Version.fromString(esVersionString);
if (esVersion.equals(Version.CURRENT) == false) {
throw new IllegalArgumentException("Elasticsearch version [" + esVersionString + "] is too old for plugin [" + name + "]");
}
}

return new PluginInfo(name, description, site, version, jvm, classname, isolated);
}

/**
* @return Plugin's name
*/
Expand Down Expand Up @@ -133,7 +176,7 @@ public String getVersion() {
return version;
}

public static PluginInfo readPluginInfo(StreamInput in) throws IOException {
public static PluginInfo readFromStream(StreamInput in) throws IOException {
PluginInfo info = new PluginInfo();
info.readFrom(in);
return info;
Expand Down
38 changes: 1 addition & 37 deletions core/src/main/java/org/elasticsearch/plugins/PluginsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.node.info.PluginInfo;
import org.elasticsearch.action.admin.cluster.node.info.PluginsInfo;
import org.elasticsearch.bootstrap.Bootstrap;
import org.elasticsearch.bootstrap.JarHell;
Expand Down Expand Up @@ -298,41 +297,6 @@ static class Bundle {
List<PluginInfo> plugins = new ArrayList<>();
List<URL> urls = new ArrayList<>();
}

/** reads (and validates) plugin metadata descriptor file */
static PluginInfo readMetadata(Path dir) throws IOException {
Path descriptor = dir.resolve(ES_PLUGIN_PROPERTIES);
Properties props = new Properties();
try (InputStream stream = Files.newInputStream(descriptor)) {
props.load(stream);
}
String name = dir.getFileName().toString();
String description = props.getProperty("description");
if (description == null) {
throw new IllegalArgumentException("Property [description] is missing for plugin [" + name + "]");
}
String version = props.getProperty("version");
if (version == null) {
throw new IllegalArgumentException("Property [version] is missing for plugin [" + name + "]");
}
String esVersionString = props.getProperty("elasticsearch.version");
if (esVersionString == null) {
throw new IllegalArgumentException("Property [elasticsearch.version] is missing for plugin [" + name + "]");
}
Version esVersion = Version.fromString(esVersionString);
if (esVersion.equals(Version.CURRENT) == false) {
throw new IllegalArgumentException("Elasticsearch version [" + esVersionString + "] is too old for plugin [" + name + "]");
}
boolean jvm = Boolean.parseBoolean(props.getProperty("jvm"));
boolean site = Boolean.parseBoolean(props.getProperty("site"));
boolean isolated = true;
String classname = "NA";
if (jvm) {
isolated = Boolean.parseBoolean(props.getProperty("isolated", "true"));
classname = props.getProperty("plugin");
}
return new PluginInfo(name, description, site, version, jvm, classname, isolated);
}

static List<Bundle> getPluginBundles(Environment environment) throws IOException {
ESLogger logger = Loggers.getLogger(Bootstrap.class);
Expand All @@ -350,7 +314,7 @@ static List<Bundle> getPluginBundles(Environment environment) throws IOException
for (Path plugin : stream) {
try {
logger.trace("--- adding plugin [{}]", plugin.toAbsolutePath());
PluginInfo info = readMetadata(plugin);
PluginInfo info = PluginInfo.readFromProperties(plugin);
List<URL> urls = new ArrayList<>();
if (info.isJvm()) {
// a jvm plugin: gather urls for jar files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.action.admin.cluster.node.info.PluginInfo;
import org.elasticsearch.plugins.PluginInfo;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.client.Client;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.action.admin.cluster.node.info.PluginInfo;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.nodesinfo.plugin.dummy1.TestPlugin;
Expand Down

0 comments on commit 9f3afad

Please sign in to comment.