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 #2668.
Closes #2784.
  • Loading branch information
dadoonet committed Jan 30, 2014
1 parent 2c67ba8 commit abf9a86
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 208 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 @@ -29,18 +31,23 @@
import java.io.Serializable;

public class PluginInfo implements Streamable, Serializable, ToXContent {
public static final String DESCRIPTION_NOT_AVAILABLE = "No description found.";
public static final String VERSION_NOT_AVAILABLE = "NA";

static final class Fields {
static final XContentBuilderString NAME = new XContentBuilderString("name");
static final XContentBuilderString DESCRIPTION = new XContentBuilderString("description");
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");
}

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

public PluginInfo() {
}
Expand All @@ -52,12 +59,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 = VERSION_NOT_AVAILABLE;
}
}

/**
Expand Down Expand Up @@ -91,7 +104,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 +114,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 +133,11 @@ 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();
} else {
this.version = VERSION_NOT_AVAILABLE;
}
}

@Override
Expand All @@ -121,12 +146,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 All @@ -140,21 +169,31 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

PluginInfo p = (PluginInfo) o;
PluginInfo that = (PluginInfo) o;

return name.equals(p.getName());
if (!name.equals(that.name)) return false;
if (version != null ? !version.equals(that.version) : that.version != null) return false;

return true;
}

@Override
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 abf9a86

Please sign in to comment.