Skip to content

Commit 2ed1fb1

Browse files
committed
Add version to plugins
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.
1 parent cf7f1b0 commit 2ed1fb1

File tree

5 files changed

+284
-208
lines changed

5 files changed

+284
-208
lines changed

src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginInfo.java

+49-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.elasticsearch.action.admin.cluster.node.info;
2020

21+
import org.elasticsearch.Version;
22+
import org.elasticsearch.common.Strings;
2123
import org.elasticsearch.common.io.stream.StreamInput;
2224
import org.elasticsearch.common.io.stream.StreamOutput;
2325
import org.elasticsearch.common.io.stream.Streamable;
@@ -29,18 +31,23 @@
2931
import java.io.Serializable;
3032

3133
public class PluginInfo implements Streamable, Serializable, ToXContent {
34+
public static final String DESCRIPTION_NOT_AVAILABLE = "No description found.";
35+
public static final String VERSION_NOT_AVAILABLE = "NA";
36+
3237
static final class Fields {
3338
static final XContentBuilderString NAME = new XContentBuilderString("name");
3439
static final XContentBuilderString DESCRIPTION = new XContentBuilderString("description");
3540
static final XContentBuilderString URL = new XContentBuilderString("url");
3641
static final XContentBuilderString JVM = new XContentBuilderString("jvm");
3742
static final XContentBuilderString SITE = new XContentBuilderString("site");
43+
static final XContentBuilderString VERSION = new XContentBuilderString("version");
3844
}
3945

4046
private String name;
4147
private String description;
4248
private boolean site;
4349
private boolean jvm;
50+
private String version;
4451

4552
public PluginInfo() {
4653
}
@@ -52,12 +59,18 @@ public PluginInfo() {
5259
* @param description Its description
5360
* @param site true if it's a site plugin
5461
* @param jvm true if it's a jvm plugin
62+
* @param version Version number is applicable (NA otherwise)
5563
*/
56-
public PluginInfo(String name, String description, boolean site, boolean jvm) {
64+
public PluginInfo(String name, String description, boolean site, boolean jvm, String version) {
5765
this.name = name;
5866
this.description = description;
5967
this.site = site;
6068
this.jvm = jvm;
69+
if (Strings.hasText(version)) {
70+
this.version = version;
71+
} else {
72+
this.version = VERSION_NOT_AVAILABLE;
73+
}
6174
}
6275

6376
/**
@@ -91,7 +104,7 @@ public boolean isJvm() {
91104
/**
92105
* We compute the URL for sites: "/_plugin/" + name + "/"
93106
*
94-
* @return
107+
* @return relative URL for site plugin
95108
*/
96109
public String getUrl() {
97110
if (site) {
@@ -101,6 +114,13 @@ public String getUrl() {
101114
}
102115
}
103116

117+
/**
118+
* @return Version number for the plugin
119+
*/
120+
public String getVersion() {
121+
return version;
122+
}
123+
104124
public static PluginInfo readPluginInfo(StreamInput in) throws IOException {
105125
PluginInfo info = new PluginInfo();
106126
info.readFrom(in);
@@ -113,6 +133,11 @@ public void readFrom(StreamInput in) throws IOException {
113133
this.description = in.readString();
114134
this.site = in.readBoolean();
115135
this.jvm = in.readBoolean();
136+
if (in.getVersion().onOrAfter(Version.V_1_0_0_RC2)) {
137+
this.version = in.readString();
138+
} else {
139+
this.version = VERSION_NOT_AVAILABLE;
140+
}
116141
}
117142

118143
@Override
@@ -121,12 +146,16 @@ public void writeTo(StreamOutput out) throws IOException {
121146
out.writeString(description);
122147
out.writeBoolean(site);
123148
out.writeBoolean(jvm);
149+
if (out.getVersion().onOrAfter(Version.V_1_0_0_RC2)) {
150+
out.writeString(version);
151+
}
124152
}
125153

126154
@Override
127155
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
128156
builder.startObject();
129157
builder.field(Fields.NAME, name);
158+
builder.field(Fields.VERSION, version);
130159
builder.field(Fields.DESCRIPTION, description);
131160
if (site) {
132161
builder.field(Fields.URL, getUrl());
@@ -140,21 +169,31 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
140169

141170
@Override
142171
public boolean equals(Object o) {
143-
if (this == o) {
144-
return true;
145-
}
146-
if (o == null || getClass() != o.getClass()) {
147-
return false;
148-
}
172+
if (this == o) return true;
173+
if (o == null || getClass() != o.getClass()) return false;
149174

150-
PluginInfo p = (PluginInfo) o;
175+
PluginInfo that = (PluginInfo) o;
151176

152-
return name.equals(p.getName());
177+
if (!name.equals(that.name)) return false;
178+
if (version != null ? !version.equals(that.version) : that.version != null) return false;
179+
180+
return true;
153181
}
154182

155183
@Override
156184
public int hashCode() {
157185
return name.hashCode();
158186
}
159187

188+
@Override
189+
public String toString() {
190+
final StringBuffer sb = new StringBuffer("PluginInfo{");
191+
sb.append("name='").append(name).append('\'');
192+
sb.append(", description='").append(description).append('\'');
193+
sb.append(", site=").append(site);
194+
sb.append(", jvm=").append(jvm);
195+
sb.append(", version='").append(version).append('\'');
196+
sb.append('}');
197+
return sb.toString();
198+
}
160199
}

src/main/java/org/elasticsearch/plugins/PluginsHelper.java

-54
This file was deleted.

0 commit comments

Comments
 (0)