Skip to content

Commit

Permalink
Add version to plugins
Browse files Browse the repository at this point in the history
Plugin developpers can now add a version number to their es-plugin.properties file:

```properties
plugin=org.elasticsearch.test.integration.nodesinfo.TestPlugin
version=0.0.7-SNAPSHOT
```

Also, for site plugins, it's recommended to add a `es-plugin.properties` file in root site directory with `description` and `version` properties:

```properties
description=This is a description for a dummy test site plugin.
version=0.0.7-BOND-SITE
```

When running Nodes Info API, you will get information on versions:

```sh
$ curl 'http://localhost:9200/_nodes?plugin=true&pretty'
```

```javascript
{
  "ok" : true,
  "cluster_name" : "test-cluster-MacBook-Air-de-David.local",
  "nodes" : {
    "RHMsToxiRcCXwHiS6mEaFw" : {
      "name" : "node2",
      "transport_address" : "inet[/192.168.0.15:9301]",
      "hostname" : "MacBook-Air-de-David.local",
      "version" : "0.90.0.Beta2-SNAPSHOT",
      "http_address" : "inet[/192.168.0.15:9201]",
      "plugins" : [ {
        "name" : "dummy",
        "version" : "0.0.7-BOND-SITE",
        "description" : "This is a description for a dummy test site plugin.",
        "url" : "/_plugin/dummy/",
        "site" : true,
        "jvm" : false
      } ]
    },
    "IKiUOo-LSCq1Km1GUhBwPg" : {
      "name" : "node3",
      "transport_address" : "inet[/192.168.0.15:9302]",
      "hostname" : "MacBook-Air-de-David.local",
      "version" : "0.90.0.Beta2-SNAPSHOT",
      "http_address" : "inet[/192.168.0.15:9202]",
      "plugins" : [ {
        "name" : "test-plugin",
        "version" : "0.0.7-SNAPSHOT",
        "description" : "test-plugin description",
        "site" : false,
        "jvm" : true
      } ]
    },
    "H64dcSF2R_GNWh6XRCYZJA" : {
      "name" : "node1",
      "transport_address" : "inet[/192.168.0.15:9300]",
      "hostname" : "MacBook-Air-de-David.local",
      "version" : "0.90.0.Beta2-SNAPSHOT",
      "http_address" : "inet[/192.168.0.15:9200]",
      "plugins" : [ ]
    },
    "mGEZcYl8Tye0Rm5AACBhPA" : {
      "name" : "node4",
      "transport_address" : "inet[/192.168.0.15:9303]",
      "hostname" : "MacBook-Air-de-David.local",
      "version" : "0.90.0.Beta2-SNAPSHOT",
      "http_address" : "inet[/192.168.0.15:9203]",
      "plugins" : [ {
        "name" : "test-plugin",
        "version" : "0.0.7-SNAPSHOT",
        "description" : "test-plugin description",
        "site" : false,
        "jvm" : true
      }, {
        "name" : "test-no-version-plugin",
        "version" : "NA",
        "description" : "test-no-version-plugin description",
        "site" : false,
        "jvm" : true
      }, {
        "name" : "dummy",
        "version" : "NA",
        "description" : "No description found for dummy.",
        "url" : "/_plugin/dummy/",
        "site" : true,
        "jvm" : false
      } ]
    }
  }
}
```

Relative to elastic#2668.
Closes elastic#2784.
  • Loading branch information
dadoonet committed Jan 30, 2014
1 parent 0541456 commit 05a58e6
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.elasticsearch.action.admin.cluster.node.info;

import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
Expand All @@ -35,12 +37,15 @@ static final class Fields {
static final XContentBuilderString URL = new XContentBuilderString("url");
static final XContentBuilderString JVM = new XContentBuilderString("jvm");
static final XContentBuilderString SITE = new XContentBuilderString("site");
static final XContentBuilderString VERSION = new XContentBuilderString("version");
static final String VERSION_DEFAULT = "NA";
}

private String name;
private String description;
private boolean site;
private boolean jvm;
private String version;

public PluginInfo() {
}
Expand All @@ -52,12 +57,18 @@ public PluginInfo() {
* @param description Its description
* @param site true if it's a site plugin
* @param jvm true if it's a jvm plugin
* @param version Version number is applicable (NA otherwise)
*/
public PluginInfo(String name, String description, boolean site, boolean jvm) {
public PluginInfo(String name, String description, boolean site, boolean jvm, String version) {
this.name = name;
this.description = description;
this.site = site;
this.jvm = jvm;
if (Strings.hasText(version)) {
this.version = version;
} else {
this.version = Fields.VERSION_DEFAULT;
}
}

/**
Expand Down Expand Up @@ -91,7 +102,7 @@ public boolean isJvm() {
/**
* We compute the URL for sites: "/_plugin/" + name + "/"
*
* @return
* @return relative URL for site plugin
*/
public String getUrl() {
if (site) {
Expand All @@ -101,6 +112,13 @@ public String getUrl() {
}
}

/**
* @return Version number for the plugin
*/
public String getVersion() {
return version;
}

public static PluginInfo readPluginInfo(StreamInput in) throws IOException {
PluginInfo info = new PluginInfo();
info.readFrom(in);
Expand All @@ -113,6 +131,9 @@ public void readFrom(StreamInput in) throws IOException {
this.description = in.readString();
this.site = in.readBoolean();
this.jvm = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_1_0_0_RC2)) {
this.version = in.readString();
}
}

@Override
Expand All @@ -121,12 +142,16 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(description);
out.writeBoolean(site);
out.writeBoolean(jvm);
if (out.getVersion().onOrAfter(Version.V_1_0_0_RC2)) {
out.writeString(version);
}
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(Fields.NAME, name);
builder.field(Fields.VERSION, version);
builder.field(Fields.DESCRIPTION, description);
if (site) {
builder.field(Fields.URL, getUrl());
Expand Down Expand Up @@ -157,4 +182,15 @@ public int hashCode() {
return name.hashCode();
}

@Override
public String toString() {
final StringBuffer sb = new StringBuffer("PluginInfo{");
sb.append("name='").append(name).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append(", site=").append(site);
sb.append(", jvm=").append(jvm);
sb.append(", version='").append(version).append('\'');
sb.append('}');
return sb.toString();
}
}
54 changes: 0 additions & 54 deletions src/main/java/org/elasticsearch/plugins/PluginsHelper.java

This file was deleted.

Loading

0 comments on commit 05a58e6

Please sign in to comment.