From 2cd7c74bc708995bd4bf8d8eab67b762cd76dadb Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Wed, 4 May 2016 21:42:11 +0200 Subject: [PATCH 01/13] Security: Replace `_shield/` urls with `_xpack/security` (elastic/elasticsearch#2174) This changes the security endpoints to _xpack/security, fixes the rest api spec to also use the xpack.security prefix and adds documentation and tests. Original commit: elastic/x-pack-elasticsearch@7977575f0eda3c259f1d6f2fc709bfc9af0c4b3d --- .../rest/action/RestAuthenticateAction.java | 3 +-- .../action/realm/RestClearRealmCacheAction.java | 4 ++-- .../action/role/RestClearRolesCacheAction.java | 2 +- .../rest/action/role/RestDeleteRoleAction.java | 2 +- .../rest/action/role/RestGetRolesAction.java | 4 ++-- .../rest/action/role/RestPutRoleAction.java | 4 ++-- .../action/user/RestChangePasswordAction.java | 8 ++++---- .../rest/action/user/RestDeleteUserAction.java | 2 +- .../rest/action/user/RestGetUsersAction.java | 4 ++-- .../rest/action/user/RestPutUserAction.java | 4 ++-- .../integration/ClearRealmsCacheTests.java | 4 ++-- .../integration/ClearRolesCacheTests.java | 4 ++-- .../rest/action/RestAuthenticateActionTests.java | 4 ++-- ...ate.json => xpack.security.authenticate.json} | 6 +++--- ....json => xpack.security.change_password.json} | 6 +++--- ...n => xpack.security.clear_cached_realms.json} | 6 +++--- ...on => xpack.security.clear_cached_roles.json} | 6 +++--- ...role.json => xpack.security.delete_role.json} | 6 +++--- ...user.json => xpack.security.delete_user.json} | 6 +++--- ...et_role.json => xpack.security.get_role.json} | 6 +++--- ...et_user.json => xpack.security.get_user.json} | 6 +++--- ...ut_role.json => xpack.security.put_role.json} | 6 +++--- ...ut_user.json => xpack.security.put_user.json} | 6 +++--- .../test/authenticate/10_basic.yaml | 2 +- .../test/change_password/10_basic.yaml | 16 ++++++++-------- .../rest-api-spec/test/roles/10_basic.yaml | 6 +++--- .../rest-api-spec/test/roles/11_idx_arrays.yaml | 6 +++--- .../rest-api-spec/test/roles/20_get_missing.yaml | 4 ++-- .../rest-api-spec/test/users/10_basic.yaml | 4 ++-- .../test/users/15_overwrite_user.yaml | 8 ++++---- .../rest-api-spec/test/users/16_update_user.yaml | 14 +++++++------- .../rest-api-spec/test/users/20_get_missing.yaml | 4 ++-- .../xpack/test/rest/XPackRestTestCase.java | 8 ++++---- 33 files changed, 90 insertions(+), 91 deletions(-) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.authenticate.json => xpack.security.authenticate.json} (58%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.change_password.json => xpack.security.change_password.json} (74%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.clear_cached_realms.json => xpack.security.clear_cached_realms.json} (75%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.clear_cached_roles.json => xpack.security.clear_cached_roles.json} (66%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.delete_role.json => xpack.security.delete_role.json} (77%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.delete_user.json => xpack.security.delete_user.json} (76%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.get_role.json => xpack.security.get_role.json} (67%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.get_user.json => xpack.security.get_user.json} (68%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.put_role.json => xpack.security.put_role.json} (80%) rename elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/{shield.put_user.json => xpack.security.put_user.json} (80%) diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/RestAuthenticateAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/RestAuthenticateAction.java index 99428b51b28..d769e54edfc 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/RestAuthenticateAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/RestAuthenticateAction.java @@ -34,8 +34,7 @@ public class RestAuthenticateAction extends BaseRestHandler { public RestAuthenticateAction(Settings settings, RestController controller, Client client, SecurityContext securityContext) { super(settings, client); this.securityContext = securityContext; - controller.registerHandler(GET, "/_shield/authenticate", this); // deprecate - controller.registerHandler(GET, "/_shield/_authenticate", this); + controller.registerHandler(GET, "/_xpack/security/authenticate", this); // deprecate } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java index 2a7b019527f..dce0470f94b 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java @@ -29,8 +29,8 @@ public class RestClearRealmCacheAction extends BaseRestHandler { @Inject public RestClearRealmCacheAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(POST, "/_shield/realm/{realms}/_cache/clear", this); // deprecated - controller.registerHandler(POST, "/_shield/realm/{realms}/_clear_cache", this); + controller.registerHandler(POST, "/_xpack/security/realm/{realms}/_cache/clear", this); // deprecated + controller.registerHandler(POST, "/_xpack/security/realm/{realms}/_clear_cache", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java index 95460af5a7b..7432dc8c0e0 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java @@ -32,7 +32,7 @@ public class RestClearRolesCacheAction extends BaseRestHandler { @Inject public RestClearRolesCacheAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(POST, "/_shield/role/{name}/_clear_cache", this); + controller.registerHandler(POST, "/_xpack/security/role/{name}/_clear_cache", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestDeleteRoleAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestDeleteRoleAction.java index 9ed99f57604..fca173893ca 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestDeleteRoleAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestDeleteRoleAction.java @@ -29,7 +29,7 @@ public class RestDeleteRoleAction extends BaseRestHandler { @Inject public RestDeleteRoleAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(RestRequest.Method.DELETE, "/_shield/role/{name}", this); + controller.registerHandler(RestRequest.Method.DELETE, "/_xpack/security/role/{name}", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestGetRolesAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestGetRolesAction.java index dc288a2ddc7..eafd4a4fda0 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestGetRolesAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestGetRolesAction.java @@ -30,8 +30,8 @@ public class RestGetRolesAction extends BaseRestHandler { @Inject public RestGetRolesAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(RestRequest.Method.GET, "/_shield/role/", this); - controller.registerHandler(RestRequest.Method.GET, "/_shield/role/{name}", this); + controller.registerHandler(RestRequest.Method.GET, "/_xpack/security/role/", this); + controller.registerHandler(RestRequest.Method.GET, "/_xpack/security/role/{name}", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestPutRoleAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestPutRoleAction.java index dd44d51d3eb..20334f56efc 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestPutRoleAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestPutRoleAction.java @@ -29,8 +29,8 @@ public class RestPutRoleAction extends BaseRestHandler { @Inject public RestPutRoleAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(RestRequest.Method.POST, "/_shield/role/{name}", this); - controller.registerHandler(RestRequest.Method.PUT, "/_shield/role/{name}", this); + controller.registerHandler(RestRequest.Method.POST, "/_xpack/security/role/{name}", this); + controller.registerHandler(RestRequest.Method.PUT, "/_xpack/security/role/{name}", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestChangePasswordAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestChangePasswordAction.java index 763591d0742..9be684b4598 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestChangePasswordAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestChangePasswordAction.java @@ -32,10 +32,10 @@ public class RestChangePasswordAction extends BaseRestHandler { public RestChangePasswordAction(Settings settings, Client client, RestController controller, SecurityContext securityContext) { super(settings, client); this.securityContext = securityContext; - controller.registerHandler(RestRequest.Method.POST, "/_shield/user/{username}/_password", this); - controller.registerHandler(RestRequest.Method.PUT, "/_shield/user/{username}/_password", this); - controller.registerHandler(RestRequest.Method.POST, "/_shield/user/_password", this); - controller.registerHandler(RestRequest.Method.PUT, "/_shield/user/_password", this); + controller.registerHandler(RestRequest.Method.POST, "/_xpack/security/user/{username}/_password", this); + controller.registerHandler(RestRequest.Method.PUT, "/_xpack/security/user/{username}/_password", this); + controller.registerHandler(RestRequest.Method.POST, "/_xpack/security/user/_password", this); + controller.registerHandler(RestRequest.Method.PUT, "/_xpack/security/user/_password", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestDeleteUserAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestDeleteUserAction.java index a31d30e1ffb..853c5d0a974 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestDeleteUserAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestDeleteUserAction.java @@ -30,7 +30,7 @@ public class RestDeleteUserAction extends BaseRestHandler { @Inject public RestDeleteUserAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(RestRequest.Method.DELETE, "/_shield/user/{username}", this); + controller.registerHandler(RestRequest.Method.DELETE, "/_xpack/security/user/{username}", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestGetUsersAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestGetUsersAction.java index 93d6a1483e6..1cfddb7bb88 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestGetUsersAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestGetUsersAction.java @@ -31,8 +31,8 @@ public class RestGetUsersAction extends BaseRestHandler { @Inject public RestGetUsersAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(RestRequest.Method.GET, "/_shield/user/", this); - controller.registerHandler(RestRequest.Method.GET, "/_shield/user/{username}", this); + controller.registerHandler(RestRequest.Method.GET, "/_xpack/security/user/", this); + controller.registerHandler(RestRequest.Method.GET, "/_xpack/security/user/{username}", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestPutUserAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestPutUserAction.java index fa348ba66f9..863a960d47e 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestPutUserAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/user/RestPutUserAction.java @@ -29,8 +29,8 @@ public class RestPutUserAction extends BaseRestHandler { @Inject public RestPutUserAction(Settings settings, RestController controller, Client client) { super(settings, client); - controller.registerHandler(RestRequest.Method.POST, "/_shield/user/{username}", this); - controller.registerHandler(RestRequest.Method.PUT, "/_shield/user/{username}", this); + controller.registerHandler(RestRequest.Method.POST, "/_xpack/security/user/{username}", this); + controller.registerHandler(RestRequest.Method.PUT, "/_xpack/security/user/{username}", this); } @Override diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRealmsCacheTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRealmsCacheTests.java index 35b994848f5..070f7c7eb44 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRealmsCacheTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRealmsCacheTests.java @@ -106,7 +106,7 @@ public class ClearRealmsCacheTests extends ShieldIntegTestCase { @Override public void executeRequest() throws Exception { - executeHttpRequest("/_shield/realm/" + (randomBoolean() ? "*" : "_all") + "/_clear_cache", + executeHttpRequest("/_xpack/security/realm/" + (randomBoolean() ? "*" : "_all") + "/_clear_cache", Collections.emptyMap()); } }, @@ -129,7 +129,7 @@ public class ClearRealmsCacheTests extends ShieldIntegTestCase { @Override public void executeRequest() throws Exception { - String path = "/_shield/realm/" + (randomBoolean() ? "*" : "_all") + "/_clear_cache"; + String path = "/_xpack/security/realm/" + (randomBoolean() ? "*" : "_all") + "/_clear_cache"; Map params = Collections.singletonMap("usernames", String.join(",", evicted_usernames)); executeHttpRequest(path, params); } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRolesCacheTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRolesCacheTests.java index 79342815753..a2cda298e38 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRolesCacheTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRolesCacheTests.java @@ -131,9 +131,9 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase { if (useHttp) { String path; if (rolesToClear == null) { - path = "/_shield/role/" + (randomBoolean() ? "*" : "_all") + "/_clear_cache"; + path = "/_xpack/security/role/" + (randomBoolean() ? "*" : "_all") + "/_clear_cache"; } else { - path = "/_shield/role/" + Strings.arrayToCommaDelimitedString(rolesToClear) + "/_clear_cache"; + path = "/_xpack/security/role/" + Strings.arrayToCommaDelimitedString(rolesToClear) + "/_clear_cache"; } HttpResponse response = httpClient().path(path).method("POST") .addHeader("Authorization", diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/rest/action/RestAuthenticateActionTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/rest/action/RestAuthenticateActionTests.java index 6aa5d03edb7..1395aac78a4 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/rest/action/RestAuthenticateActionTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/rest/action/RestAuthenticateActionTests.java @@ -47,7 +47,7 @@ public class RestAuthenticateActionTests extends ShieldIntegTestCase { } public void testAuthenticateApi() throws Exception { - HttpResponse response = httpClient().method("GET").path("/_shield/authenticate") + HttpResponse response = httpClient().method("GET").path("/_xpack/security/authenticate") .addHeader("Authorization", basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME, new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))) .execute(); @@ -61,7 +61,7 @@ public class RestAuthenticateActionTests extends ShieldIntegTestCase { } public void testAuthenticateApiWithoutAuthentication() throws Exception { - HttpResponse response = httpClient().method("GET").path("/_shield/authenticate") + HttpResponse response = httpClient().method("GET").path("/_xpack/security/authenticate") .execute(); if (anonymousEnabled) { diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.authenticate.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.authenticate.json similarity index 58% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.authenticate.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.authenticate.json index 8c470760f97..c72c132778c 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.authenticate.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.authenticate.json @@ -1,10 +1,10 @@ { - "shield.authenticate": { + "xpack.security.authenticate": { "documentation": "Retrieve details about the currently authenticated user", "methods": [ "GET" ], "url": { - "path": "/_shield/authenticate", - "paths": [ "/_shield/authenticate" ], + "path": "/_xpack/security/authenticate", + "paths": [ "/_xpack/security/authenticate" ], "parts": {}, "params": {} }, diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.change_password.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.change_password.json similarity index 74% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.change_password.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.change_password.json index 5225209593c..c8607c84f87 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.change_password.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.change_password.json @@ -1,10 +1,10 @@ { - "shield.change_password": { + "xpack.security.change_password": { "documentation": "Change the password of a user", "methods": [ "PUT", "POST" ], "url": { - "path": "/_shield/user/{username}/_password", - "paths": [ "/_shield/user/{username}/_password", "/_shield/user/_password" ], + "path": "/_xpack/security/user/{username}/_password", + "paths": [ "/_xpack/security/user/{username}/_password", "/_xpack/security/user/_password" ], "parts": { "username": { "type" : "string", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.clear_cached_realms.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.clear_cached_realms.json similarity index 75% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.clear_cached_realms.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.clear_cached_realms.json index 54fc8c0e68b..8818b0e1768 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.clear_cached_realms.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.clear_cached_realms.json @@ -1,10 +1,10 @@ { - "shield.clear_cached_realms": { + "xpack.security.clear_cached_realms": { "documentation": "Clears the internal user caches for specified realms", "methods": [ "POST" ], "url": { - "path": "/_shield/realm/{realms}/_clear_cache", - "paths": [ "/_shield/realm/{realms}/_clear_cache" ], + "path": "/_xpack/security/realm/{realms}/_clear_cache", + "paths": [ "/_xpack/security/realm/{realms}/_clear_cache" ], "parts": { "realms": { "type" : "string", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.clear_cached_roles.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.clear_cached_roles.json similarity index 66% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.clear_cached_roles.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.clear_cached_roles.json index ea6aa06923b..f7a68a33000 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.clear_cached_roles.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.clear_cached_roles.json @@ -1,10 +1,10 @@ { - "shield.clear_cached_roles": { + "xpack.security.clear_cached_roles": { "documentation": "Clears the internal caches for specified roles", "methods": [ "PUT", "POST" ], "url": { - "path": "/_shield/role/{name}/_clear_cache", - "paths": [ "/_shield/role/{name}/_clear_cache" ], + "path": "/_xpack/security/role/{name}/_clear_cache", + "paths": [ "/_xpack/security/role/{name}/_clear_cache" ], "parts": { "name": { "type" : "string", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.delete_role.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.delete_role.json similarity index 77% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.delete_role.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.delete_role.json index 4a911ec3484..afb0ea086b0 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.delete_role.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.delete_role.json @@ -1,10 +1,10 @@ { - "shield.delete_role": { + "xpack.security.delete_role": { "documentation": "Remove a role from the native shield realm", "methods": [ "DELETE" ], "url": { - "path": "/_shield/role/{name}", - "paths": [ "/_shield/role/{name}" ], + "path": "/_xpack/security/role/{name}", + "paths": [ "/_xpack/security/role/{name}" ], "parts": { "name": { "type" : "string", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.delete_user.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.delete_user.json similarity index 76% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.delete_user.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.delete_user.json index 6b31f4889f2..e021ff0a286 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.delete_user.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.delete_user.json @@ -1,10 +1,10 @@ { - "shield.delete_user": { + "xpack.security.delete_user": { "documentation": "Remove a user from the native shield realm", "methods": [ "DELETE" ], "url": { - "path": "/_shield/user/{username}", - "paths": [ "/_shield/user/{username}" ], + "path": "/_xpack/security/user/{username}", + "paths": [ "/_xpack/security/user/{username}" ], "parts": { "username": { "type" : "string", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.get_role.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.get_role.json similarity index 67% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.get_role.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.get_role.json index 2dc241795b5..79664dd2609 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.get_role.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.get_role.json @@ -1,10 +1,10 @@ { - "shield.get_role": { + "xpack.security.get_role": { "documentation": "Retrieve one or more roles from the native shield realm", "methods": [ "GET" ], "url": { - "path": "/_shield/role/{name}", - "paths": [ "/_shield/role/{name}", "/_shield/role" ], + "path": "/_xpack/security/role/{name}", + "paths": [ "/_xpack/security/role/{name}", "/_xpack/security/role" ], "parts": { "name": { "type" : "string", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.get_user.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.get_user.json similarity index 68% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.get_user.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.get_user.json index da821e5e67f..90ac12b9fad 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.get_user.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.get_user.json @@ -1,10 +1,10 @@ { - "shield.get_user": { + "xpack.security.get_user": { "documentation": "Retrieve one or more users from the native shield realm", "methods": [ "GET" ], "url": { - "path": "/_shield/user/{username}", - "paths": [ "/_shield/user/{username}", "/_shield/user" ], + "path": "/_xpack/security/user/{username}", + "paths": [ "/_xpack/security/user/{username}", "/_xpack/security/user" ], "parts": { "username": { "type" : "list", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.put_role.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.put_role.json similarity index 80% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.put_role.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.put_role.json index 8909d35ca7b..f69887c083b 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.put_role.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.put_role.json @@ -1,10 +1,10 @@ { - "shield.put_role": { + "xpack.security.put_role": { "documentation": "Update or create a role for the native shield realm", "methods": [ "PUT", "POST" ], "url": { - "path": "/_shield/role/{name}", - "paths": [ "/_shield/role/{name}" ], + "path": "/_xpack/security/role/{name}", + "paths": [ "/_xpack/security/role/{name}" ], "parts": { "name": { "type" : "string", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.put_user.json b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.put_user.json similarity index 80% rename from elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.put_user.json rename to elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.put_user.json index 18cc6112d9d..e79123db9d0 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/shield.put_user.json +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/api/xpack.security.put_user.json @@ -1,10 +1,10 @@ { - "shield.put_user": { + "xpack.security.put_user": { "documentation": "Update or create a user for the native shield realm", "methods": [ "PUT", "POST" ], "url": { - "path": "/_shield/user/{username}", - "paths": [ "/_shield/user/{username}" ], + "path": "/_xpack/security/user/{username}", + "paths": [ "/_xpack/security/user/{username}" ], "parts": { "username": { "type" : "string", diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/authenticate/10_basic.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/authenticate/10_basic.yaml index f4563f90b43..1fa3d101931 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/authenticate/10_basic.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/authenticate/10_basic.yaml @@ -5,7 +5,7 @@ cluster.health: wait_for_status: yellow - do: - shield.authenticate: {} + xpack.security.authenticate: {} - match: { username: "test_user" } - match: { roles.0: "superuser" } diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/change_password/10_basic.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/change_password/10_basic.yaml index a2249bc09e5..9f83345d7b6 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/change_password/10_basic.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/change_password/10_basic.yaml @@ -8,7 +8,7 @@ wait_for_status: yellow - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -26,7 +26,7 @@ # change password - do: - shield.change_password: + xpack.security.change_password: username: "joe" body: > { @@ -57,7 +57,7 @@ wait_for_status: yellow - do: - shield.put_role: + xpack.security.put_role: name: "user" body: > { @@ -72,7 +72,7 @@ - match: { role: { created: true } } - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -92,7 +92,7 @@ - do: headers: Authorization: "Basic am9lOnMza3JpdA==" - shield.change_password: + xpack.security.change_password: body: > { "password" : "s3krit2" @@ -122,7 +122,7 @@ wait_for_status: yellow - do: - shield.put_role: + xpack.security.put_role: name: "user" body: > { @@ -137,7 +137,7 @@ - match: { role: { created: true } } - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -158,7 +158,7 @@ headers: Authorization: "Basic am9lOnMza3JpdA==" catch: forbidden - shield.change_password: + xpack.security.change_password: username: "anotheruser" body: > { diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/10_basic.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/10_basic.yaml index 2e87530f125..6f4695a8c18 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/10_basic.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/10_basic.yaml @@ -8,7 +8,7 @@ wait_for_status: yellow - do: - shield.put_role: + xpack.security.put_role: name: "admin_role" body: > { @@ -23,7 +23,7 @@ - match: { role: { created: true } } - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -40,7 +40,7 @@ - match: { timed_out: false } - do: - shield.get_role: + xpack.security.get_role: name: "admin_role" - match: { admin_role.cluster.0: "all" } - match: { admin_role.indices.0.names.0: "*" } diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/11_idx_arrays.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/11_idx_arrays.yaml index d02c68e95c7..aeda2d10749 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/11_idx_arrays.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/11_idx_arrays.yaml @@ -8,7 +8,7 @@ wait_for_status: yellow - do: - shield.put_role: + xpack.security.put_role: name: "admin_role2" body: > { @@ -23,7 +23,7 @@ - match: { role: { created: true } } - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -61,7 +61,7 @@ - match: { timed_out: false } - do: - shield.get_role: + xpack.security.get_role: name: "admin_role2" - match: { admin_role2.cluster.0: "all" } - match: { admin_role2.indices.0.names.0: "foo" } diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/20_get_missing.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/20_get_missing.yaml index cbfa09b8d33..ebe0a5d9df3 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/20_get_missing.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/roles/20_get_missing.yaml @@ -1,12 +1,12 @@ "Get missing role": - do: catch: missing - shield.get_role: + xpack.security.get_role: name: 'foo' --- "Get missing (multiple) roles": - do: catch: missing - shield.get_role: + xpack.security.get_role: name: [ 'foo', 'bar' ] diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/10_basic.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/10_basic.yaml index 9135dc41764..309b9d693fd 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/10_basic.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/10_basic.yaml @@ -8,7 +8,7 @@ wait_for_status: yellow - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -30,7 +30,7 @@ - match: { timed_out: false } - do: - shield.get_user: + xpack.security.get_user: username: "joe" - match: { joe.username: "joe" } - match: { joe.roles.0: "superuser" } diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/15_overwrite_user.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/15_overwrite_user.yaml index 1207987d90a..16eb52fbfcc 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/15_overwrite_user.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/15_overwrite_user.yaml @@ -8,7 +8,7 @@ wait_for_status: yellow - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -18,7 +18,7 @@ - match: { user: { created: true } } - do: - shield.get_user: + xpack.security.get_user: username: "joe" - match: { joe.username: "joe" } - match: { joe.roles.0: "superuser" } @@ -30,7 +30,7 @@ - match: { timed_out: false } - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -46,7 +46,7 @@ - match: { user: { created: false } } - do: - shield.get_user: + xpack.security.get_user: username: "joe" - match: { joe.username: "joe" } - match: { joe.roles.0: "superuser" } diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/16_update_user.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/16_update_user.yaml index 63862bd79d9..71cba78bf22 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/16_update_user.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/16_update_user.yaml @@ -6,7 +6,7 @@ - do: catch: request - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -24,7 +24,7 @@ wait_for_status: yellow - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -41,7 +41,7 @@ - match: { timed_out: false } - do: - shield.get_user: + xpack.security.get_user: username: "joe" - match: { joe.username: "joe" } - match: { joe.roles.0: "superuser" } @@ -51,7 +51,7 @@ # update the user without a password - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -74,7 +74,7 @@ # validate other properties - do: - shield.get_user: + xpack.security.get_user: username: "joe" - match: { joe.username: "joe" } - match: { joe.roles.0: "superuser" } @@ -86,7 +86,7 @@ # update with password - do: - shield.put_user: + xpack.security.put_user: username: "joe" body: > { @@ -118,7 +118,7 @@ # validate properties - do: - shield.get_user: + xpack.security.get_user: username: "joe" - match: { joe.username: "joe" } - match: { joe.roles.0: "superuser" } diff --git a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/20_get_missing.yaml b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/20_get_missing.yaml index ad729210ba5..290e612f427 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/20_get_missing.yaml +++ b/elasticsearch/x-pack/shield/src/test/resources/rest-api-spec/test/users/20_get_missing.yaml @@ -1,12 +1,12 @@ "Get missing user": - do: catch: missing - shield.get_user: + xpack.security.get_user: username: 'foo' --- "Get missing (multiple) users": - do: catch: missing - shield.get_user: + xpack.security.get_user: username: [ 'foo', 'bar' ] diff --git a/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestCase.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestCase.java index b987ae6ec91..9cf0da510e6 100644 --- a/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestCase.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestCase.java @@ -88,7 +88,7 @@ public abstract class XPackRestTestCase extends ESRestTestCase { // TODO remove this once the built-in SUPERUSER role is added that can delete the index and we use the built in admin user here try (CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) { final URL url = getClusterUrls()[0]; - HttpGet getUsersRequest = new HttpGet(new URI("http", null, url.getHost(), url.getPort(), "/_shield/user", null, null)); + HttpGet getUsersRequest = new HttpGet(new URI("http", null, url.getHost(), url.getPort(), "/_xpack/security/user", null, null)); getUsersRequest.addHeader("Authorization", BASIC_AUTH_VALUE); try (CloseableHttpResponse closeableHttpResponse = client.execute(getUsersRequest)) { assertThat(closeableHttpResponse.getStatusLine().getStatusCode(), is(200)); @@ -99,14 +99,14 @@ public abstract class XPackRestTestCase extends ESRestTestCase { // in the structure of this API, the users are the keyset for (String user : responseMap.keySet()) { HttpDelete delete = new HttpDelete(new URI("http", null, url.getHost(), url.getPort(), - "/_shield/user/" + user, null, null)); + "/_xpack/security/user/" + user, null, null)); delete.addHeader("Authorization", BASIC_AUTH_VALUE); try (CloseableHttpResponse deleteResponse = client.execute(delete)) { } } } - HttpGet getRolesRequest = new HttpGet(new URI("http", null, url.getHost(), url.getPort(), "/_shield/role", + HttpGet getRolesRequest = new HttpGet(new URI("http", null, url.getHost(), url.getPort(), "/_xpack/security/role", null, null)); getRolesRequest.addHeader("Authorization", BASIC_AUTH_VALUE); try (CloseableHttpResponse closeableHttpResponse = client.execute(getRolesRequest)) { @@ -118,7 +118,7 @@ public abstract class XPackRestTestCase extends ESRestTestCase { // in the structure of this API, the users are the keyset for (String role : responseMap.keySet()) { HttpDelete delete = new HttpDelete(new URI("http", null, url.getHost(), url.getPort(), - "/_shield/role/" + role, null, null)); + "/_xpack/security/role/" + role, null, null)); delete.addHeader("Authorization", BASIC_AUTH_VALUE); try (CloseableHttpResponse deleteResponse = client.execute(delete)) { } From d9e9f7dfd020dd64c709a682d0fba013c7a4c646 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Tue, 19 Apr 2016 10:18:17 -0400 Subject: [PATCH 02/13] Disable licensing services and management APIs for tribe node closes elastic/elasticsearch#1426 Original commit: elastic/x-pack-elasticsearch@d8a312b1b50889ba719c8f027bf64aac24d59394 --- .../license/plugin/Licensing.java | 35 +-- .../license/plugin/LicenseTribeTests.java | 234 ++++++++++++++++++ .../plugin/LicensesTransportTests.java | 61 +++-- 3 files changed, 294 insertions(+), 36 deletions(-) create mode 100644 elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java index 4837f733728..22c95840dd9 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java @@ -6,8 +6,6 @@ package org.elasticsearch.license.plugin; import org.elasticsearch.action.ActionModule; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Inject; @@ -28,15 +26,19 @@ import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction; import org.elasticsearch.license.plugin.rest.RestGetLicenseAction; import org.elasticsearch.license.plugin.rest.RestPutLicenseAction; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import static org.elasticsearch.xpack.XPackPlugin.isTribeClientNode; +import static org.elasticsearch.xpack.XPackPlugin.isTribeNode; +import static org.elasticsearch.xpack.XPackPlugin.transportClientMode; + + public class Licensing { public static final String NAME = "license"; - private final boolean isEnabled; - protected final boolean transportClient; + private final boolean isTransportClient; + private final boolean isTribeNode; static { MetaData.registerPrototype(LicensesMetaData.TYPE, LicensesMetaData.PROTO); @@ -44,12 +46,12 @@ public class Licensing { @Inject public Licensing(Settings settings) { - this.transportClient = TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey())); - isEnabled = transportClient == false; + isTransportClient = transportClientMode(settings); + isTribeNode = isTribeNode(settings); } public void onModule(NetworkModule module) { - if (transportClient == false) { + if (isTransportClient == false && isTribeNode == false) { module.registerRestHandler(RestPutLicenseAction.class); module.registerRestHandler(RestGetLicenseAction.class); module.registerRestHandler(RestDeleteLicenseAction.class); @@ -57,21 +59,22 @@ public class Licensing { } public void onModule(ActionModule module) { - module.registerAction(PutLicenseAction.INSTANCE, TransportPutLicenseAction.class); - module.registerAction(GetLicenseAction.INSTANCE, TransportGetLicenseAction.class); - module.registerAction(DeleteLicenseAction.INSTANCE, TransportDeleteLicenseAction.class); + if (isTribeNode == false) { + module.registerAction(PutLicenseAction.INSTANCE, TransportPutLicenseAction.class); + module.registerAction(GetLicenseAction.INSTANCE, TransportGetLicenseAction.class); + module.registerAction(DeleteLicenseAction.INSTANCE, TransportDeleteLicenseAction.class); + } } public Collection> nodeServices() { - Collection> services = new ArrayList<>(); - if (isEnabled) { - services.add(LicensesService.class); + if (isTransportClient == false && isTribeNode == false) { + return Collections.>singletonList(LicensesService.class); } - return services; + return Collections.emptyList(); } public Collection nodeModules() { - if (isEnabled) { + if (isTransportClient == false && isTribeNode == false) { return Collections.singletonList(new LicensingModule()); } return Collections.emptyList(); diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java new file mode 100644 index 00000000000..7a8fe75f639 --- /dev/null +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java @@ -0,0 +1,234 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.license.plugin; + +import org.elasticsearch.action.Action; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.Requests; +import org.elasticsearch.client.transport.NoNodeAvailableException; +import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.Priority; +import org.elasticsearch.common.UUIDs; +import org.elasticsearch.common.network.NetworkModule; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; +import org.elasticsearch.graph.Graph; +import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction; +import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest; +import org.elasticsearch.license.plugin.action.get.GetLicenseAction; +import org.elasticsearch.license.plugin.action.get.GetLicenseRequest; +import org.elasticsearch.license.plugin.action.put.PutLicenseAction; +import org.elasticsearch.license.plugin.action.put.PutLicenseRequest; +import org.elasticsearch.marvel.Monitoring; +import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.shield.Security; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import org.elasticsearch.test.ESIntegTestCase.Scope; +import org.elasticsearch.test.InternalTestCluster; +import org.elasticsearch.test.NodeConfigurationSource; +import org.elasticsearch.test.TestCluster; +import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.xpack.watcher.Watcher; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; + +@ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 0, numDataNodes = 0) +public class LicenseTribeTests extends ESIntegTestCase { + + @Override + protected Settings nodeSettings(int nodeOrdinal) { + return Settings.builder() + .put(XPackPlugin.featureEnabledSetting(Security.NAME), false) + .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) + .put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) + .put(XPackPlugin.featureEnabledSetting(Graph.NAME), false) + .put(NetworkModule.HTTP_ENABLED.getKey(), false) + .put(Node.NODE_LOCAL_SETTING.getKey(), true) + .build(); + } + + @Override + protected Collection> nodePlugins() { + return Collections.>singletonList(XPackPlugin.class); + } + + @Override + protected Collection> transportClientPlugins() { + return nodePlugins(); + } + + public void testTribeSetup() throws Exception { + NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() { + @Override + public Settings nodeSettings(int nodeOrdinal) { + return LicenseTribeTests.this.nodeSettings(nodeOrdinal); + } + + @Override + public Collection> nodePlugins() { + return LicenseTribeTests.this.nodePlugins(); + } + + @Override + public Settings transportClientSettings() { + return LicenseTribeTests.this.transportClientSettings(); + } + + @Override + public Collection> transportClientPlugins() { + return LicenseTribeTests.this.transportClientPlugins(); + } + }; + final InternalTestCluster cluster2 = new InternalTestCluster(InternalTestCluster.configuredNodeMode(), + randomLong(), createTempDir(), 2, 2, + UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 0, false, "tribe_node2", + getMockPlugins(), getClientWrapper()); + + cluster2.beforeTest(random(), 0.0); + cluster2.ensureAtLeastNumDataNodes(2); + + logger.info("create 2 indices, test1 on t1, and test2 on t2"); + assertAcked(internalCluster().client().admin().indices().prepareCreate("test1").get()); + assertAcked(cluster2.client().admin().indices().prepareCreate("test2").get()); + ensureYellow(internalCluster()); + ensureYellow(cluster2); + Map asMap = internalCluster().getDefaultSettings().getAsMap(); + Settings.Builder tribe1Defaults = Settings.builder(); + Settings.Builder tribe2Defaults = Settings.builder(); + for (Map.Entry entry : asMap.entrySet()) { + if (entry.getKey().startsWith("path.")) { + continue; + } + tribe1Defaults.put("tribe.t1." + entry.getKey(), entry.getValue()); + tribe2Defaults.put("tribe.t2." + entry.getKey(), entry.getValue()); + } + // give each tribe it's unicast hosts to connect to + tribe1Defaults.putArray("tribe.t1." + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), + getUnicastHosts(internalCluster().client())); + tribe1Defaults.putArray("tribe.t2." + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), + getUnicastHosts(cluster2.client())); + + Settings merged = Settings.builder() + .put("tribe.t1.cluster.name", internalCluster().getClusterName()) + .put("tribe.t2.cluster.name", cluster2.getClusterName()) + .put("tribe.blocks.write", false) + .put(tribe1Defaults.build()) + .put(tribe2Defaults.build()) + .put(internalCluster().getDefaultSettings()) + .put("node.name", "tribe_node") // make sure we can identify threads from this node + .put(Node.NODE_LOCAL_SETTING.getKey(), true) + .build(); + + final Node tribeNode = new Node(merged).start(); + Client tribeClient = tribeNode.client(); + + logger.info("wait till tribe has the same nodes as the 2 clusters"); + assertBusy(() -> { + DiscoveryNodes tribeNodes = tribeNode.client().admin().cluster().prepareState().get().getState().getNodes(); + assertThat(countDataNodesForTribe("t1", tribeNodes), + equalTo(internalCluster().client().admin().cluster().prepareState().get().getState() + .getNodes().getDataNodes().size())); + assertThat(countDataNodesForTribe("t2", tribeNodes), + equalTo(cluster2.client().admin().cluster().prepareState().get().getState() + .getNodes().getDataNodes().size())); + }); + verifyActionOnTribeNode(tribeClient); + verifyActionOnDataNode((randomBoolean() ? internalCluster() : cluster2).dataNodeClient()); + verifyActionOnDataNode((randomBoolean() ? internalCluster() : cluster2).masterClient()); + try { + cluster2.wipe(Collections.emptySet()); + } catch (NoNodeAvailableException ignored) { + } finally { + cluster2.afterTest(); + } + tribeNode.close(); + cluster2.close(); + } + + protected void verifyActionOnDataNode(Client dataNodeClient) throws Exception { + dataNodeClient.execute(GetLicenseAction.INSTANCE, new GetLicenseRequest()).get(); + dataNodeClient.execute(PutLicenseAction.INSTANCE, new PutLicenseRequest() + .license(generateSignedLicense(TimeValue.timeValueHours(1)))); + dataNodeClient.execute(DeleteLicenseAction.INSTANCE, new DeleteLicenseRequest()); + } + + protected void verifyActionOnTribeNode(Client tribeClient) { + failAction(tribeClient, GetLicenseAction.INSTANCE); + failAction(tribeClient, PutLicenseAction.INSTANCE); + failAction(tribeClient, DeleteLicenseAction.INSTANCE); + } + + protected void failAction(Client client, Action action) { + try { + client.execute(action, action.newRequestBuilder(client).request()); + fail("expected [" + action.name() + "] to fail"); + } catch (IllegalStateException e) { + assertThat(e.getMessage(), containsString("failed to find action")); + } + } + + private void ensureYellow(TestCluster testCluster) { + ClusterHealthResponse actionGet; + while (true) { + try { + actionGet = testCluster.client().admin().cluster() + .health(Requests.clusterHealthRequest().waitForYellowStatus() + .waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet(); + break; + } catch (NoNodeAvailableException ignored) { + } + } + if (actionGet.isTimedOut()) { + logger.info("ensureGreen timed out, cluster state:\n{}\n{}", testCluster.client().admin().cluster() + .prepareState().get().getState().prettyPrint(), + testCluster.client().admin().cluster().preparePendingClusterTasks().get().prettyPrint()); + assertThat("timed out waiting for yellow state", actionGet.isTimedOut(), equalTo(false)); + } + assertThat(actionGet.getStatus(), anyOf(equalTo(ClusterHealthStatus.YELLOW), equalTo(ClusterHealthStatus.GREEN))); + } + + private int countDataNodesForTribe(String tribeName, DiscoveryNodes nodes) { + int count = 0; + for (DiscoveryNode node : nodes) { + if (!node.isDataNode()) { + continue; + } + if (tribeName.equals(node.getAttributes().get("tribe.name"))) { + count++; + } + } + return count; + } + + public static String[] getUnicastHosts(Client client) { + ArrayList unicastHosts = new ArrayList<>(); + NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setTransport(true).get(); + for (NodeInfo info : nodeInfos.getNodes()) { + TransportAddress address = info.getTransport().getAddress().publishAddress(); + unicastHosts.add(address.getAddress() + ":" + address.getPort()); + } + return unicastHosts.toArray(new String[unicastHosts.size()]); + } + +} diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesTransportTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesTransportTests.java index 4a0f7343458..1e3db66f25e 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesTransportTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesTransportTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.license.plugin; import org.elasticsearch.action.ActionFuture; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction; @@ -18,20 +19,42 @@ import org.elasticsearch.license.plugin.action.put.PutLicenseAction; import org.elasticsearch.license.plugin.action.put.PutLicenseRequestBuilder; import org.elasticsearch.license.plugin.action.put.PutLicenseResponse; import org.elasticsearch.license.plugin.core.LicensesStatus; -import org.elasticsearch.test.ESIntegTestCase.ClusterScope; -import org.junit.After; +import org.elasticsearch.marvel.Monitoring; +import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.shield.Security; +import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.xpack.watcher.Watcher; + +import java.util.Collection; +import java.util.Collections; import static org.elasticsearch.license.plugin.TestUtils.dateMath; import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense; -import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; -@ClusterScope(scope = TEST, numDataNodes = 10) -public class LicensesTransportTests extends AbstractLicensesIntegrationTestCase { - @After - public void beforeTest() throws Exception { - wipeAllLicenses(); +public class LicensesTransportTests extends ESSingleNodeTestCase { + + @Override + protected boolean resetNodeAfterTest() { + return true; + } + + @Override + protected Collection> getPlugins() { + return Collections.singletonList(XPackPlugin.class); + } + + @Override + protected Settings nodeSettings() { + Settings.Builder newSettings = Settings.builder(); + newSettings.put(XPackPlugin.featureEnabledSetting(Security.NAME), false); + newSettings.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false); + newSettings.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false); + newSettings.put(Node.NODE_DATA_SETTING.getKey(), true); + return newSettings.build(); } public void testEmptyGetLicense() throws Exception { @@ -47,7 +70,8 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTestCase // put license PutLicenseRequestBuilder putLicenseRequestBuilder = - new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(signedLicense); + new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(signedLicense) + .setAcknowledge(true); PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get(); assertThat(putLicenseResponse.isAcknowledged(), equalTo(true)); assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID)); @@ -63,7 +87,8 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTestCase // put license source PutLicenseRequestBuilder putLicenseRequestBuilder = - new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(licenseString); + new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(licenseString) + .setAcknowledge(true); PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get(); assertThat(putLicenseResponse.isAcknowledged(), equalTo(true)); assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID)); @@ -97,25 +122,20 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTestCase public void testPutExpiredLicense() throws Exception { License expiredLicense = generateSignedLicense(dateMath("now-10d/d", System.currentTimeMillis()), TimeValue.timeValueMinutes(2)); - License signedLicense = generateSignedLicense(TimeValue.timeValueMinutes(2)); - PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE); - builder.setLicense(signedLicense); - // put license should return valid (as there is one valid license) - PutLicenseResponse putLicenseResponse = builder.get(); - assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID)); builder.setLicense(expiredLicense); - putLicenseResponse = builder.get(); + PutLicenseResponse putLicenseResponse = builder.get(); assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.EXPIRED)); // get license should not return the expired license GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get(); - assertThat(getLicenseResponse.license(), equalTo(signedLicense)); + assertThat(getLicenseResponse.license(), not(expiredLicense)); } public void testPutLicensesSimple() throws Exception { License basicSignedLicense = generateSignedLicense("basic", TimeValue.timeValueMinutes(5)); PutLicenseRequestBuilder putLicenseRequestBuilder = - new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(basicSignedLicense); + new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(basicSignedLicense) + .setAcknowledge(true); PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get(); assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID)); GetLicenseResponse getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get(); @@ -133,7 +153,8 @@ public class LicensesTransportTests extends AbstractLicensesIntegrationTestCase public void testRemoveLicensesSimple() throws Exception { License goldLicense = generateSignedLicense("gold", TimeValue.timeValueMinutes(5)); PutLicenseRequestBuilder putLicenseRequestBuilder = - new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(goldLicense); + new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(goldLicense) + .setAcknowledge(true); PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get(); assertThat(putLicenseResponse.isAcknowledged(), equalTo(true)); assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID)); From f808b251b5ce6b822ad641f62a45c7e64448ecb2 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Mon, 2 May 2016 17:45:16 -0400 Subject: [PATCH 03/13] Disable monitoring transport and rest actions on tribe node Original commit: elastic/x-pack-elasticsearch@a9d97b4f648972117a5e7a3d66f2ff02ff22868d --- .../java/org/elasticsearch/marvel/Monitoring.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java index c4725e523c9..bc41c277e00 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java @@ -42,11 +42,13 @@ public class Monitoring { private final Settings settings; private final boolean enabled; private final boolean transportClientMode; + private final boolean tribeNode; public Monitoring(Settings settings) { this.settings = settings; this.enabled = MonitoringSettings.ENABLED.get(settings); this.transportClientMode = XPackPlugin.transportClientMode(settings); + this.tribeNode = XPackPlugin.isTribeNode(settings); } boolean isEnabled() { @@ -60,7 +62,7 @@ public class Monitoring { public Collection nodeModules() { List modules = new ArrayList<>(); modules.add(new MonitoringModule(enabled, transportClientMode)); - if (enabled && transportClientMode == false) { + if (enabled && transportClientMode == false && tribeNode == false) { modules.add(new CollectorModule()); modules.add(new ExporterModule(settings)); modules.add(new MonitoringClientModule()); @@ -69,7 +71,7 @@ public class Monitoring { } public Collection> nodeServices() { - if (enabled == false || transportClientMode) { + if (enabled == false || transportClientMode || tribeNode) { return Collections.emptyList(); } return Arrays.>asList(MonitoringLicensee.class, @@ -82,19 +84,19 @@ public class Monitoring { } public void onModule(ActionModule module) { - if (enabled) { + if (enabled && tribeNode == false) { module.registerAction(MonitoringBulkAction.INSTANCE, TransportMonitoringBulkAction.class); } } public void onModule(NetworkModule module) { - if (enabled && transportClientMode == false) { + if (enabled && transportClientMode == false && tribeNode == false) { module.registerRestHandler(RestMonitoringBulkAction.class); } } public void onModule(LazyInitializationModule module) { - if (enabled) { + if (enabled && tribeNode == false) { module.registerLazyInitializable(MonitoringClientProxy.class); } } From 3f0acdd70e0c597bc6e38c8aca439bdb808ddd31 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Tue, 3 May 2016 13:52:46 -0400 Subject: [PATCH 04/13] refactor tribe integ tests to test monitoring transport actions Original commit: elastic/x-pack-elasticsearch@4c8735d4a8c4dce6e059afd9a30eb53925f0f326 --- .../license/plugin/LicenseTribeTests.java | 204 +--------------- .../xpack/TribeTransportTestCase.java | 226 ++++++++++++++++++ .../marvel/MonitoringTribeTests.java | 37 +++ 3 files changed, 266 insertions(+), 201 deletions(-) create mode 100644 elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/xpack/TribeTransportTestCase.java create mode 100644 elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MonitoringTribeTests.java diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java index 7a8fe75f639..51709949de4 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java @@ -5,167 +5,21 @@ */ package org.elasticsearch.license.plugin; -import org.elasticsearch.action.Action; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; -import org.elasticsearch.client.Requests; -import org.elasticsearch.client.transport.NoNodeAvailableException; -import org.elasticsearch.cluster.health.ClusterHealthStatus; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.common.Priority; -import org.elasticsearch.common.UUIDs; -import org.elasticsearch.common.network.NetworkModule; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; -import org.elasticsearch.graph.Graph; import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction; import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest; import org.elasticsearch.license.plugin.action.get.GetLicenseAction; import org.elasticsearch.license.plugin.action.get.GetLicenseRequest; import org.elasticsearch.license.plugin.action.put.PutLicenseAction; import org.elasticsearch.license.plugin.action.put.PutLicenseRequest; -import org.elasticsearch.marvel.Monitoring; -import org.elasticsearch.node.Node; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.shield.Security; -import org.elasticsearch.test.ESIntegTestCase; -import org.elasticsearch.test.ESIntegTestCase.ClusterScope; -import org.elasticsearch.test.ESIntegTestCase.Scope; -import org.elasticsearch.test.InternalTestCluster; -import org.elasticsearch.test.NodeConfigurationSource; -import org.elasticsearch.test.TestCluster; -import org.elasticsearch.xpack.XPackPlugin; -import org.elasticsearch.xpack.watcher.Watcher; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; +import org.elasticsearch.xpack.TribeTransportTestCase; import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -@ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 0, numDataNodes = 0) -public class LicenseTribeTests extends ESIntegTestCase { +public class LicenseTribeTests extends TribeTransportTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder() - .put(XPackPlugin.featureEnabledSetting(Security.NAME), false) - .put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) - .put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) - .put(XPackPlugin.featureEnabledSetting(Graph.NAME), false) - .put(NetworkModule.HTTP_ENABLED.getKey(), false) - .put(Node.NODE_LOCAL_SETTING.getKey(), true) - .build(); - } - - @Override - protected Collection> nodePlugins() { - return Collections.>singletonList(XPackPlugin.class); - } - - @Override - protected Collection> transportClientPlugins() { - return nodePlugins(); - } - - public void testTribeSetup() throws Exception { - NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() { - @Override - public Settings nodeSettings(int nodeOrdinal) { - return LicenseTribeTests.this.nodeSettings(nodeOrdinal); - } - - @Override - public Collection> nodePlugins() { - return LicenseTribeTests.this.nodePlugins(); - } - - @Override - public Settings transportClientSettings() { - return LicenseTribeTests.this.transportClientSettings(); - } - - @Override - public Collection> transportClientPlugins() { - return LicenseTribeTests.this.transportClientPlugins(); - } - }; - final InternalTestCluster cluster2 = new InternalTestCluster(InternalTestCluster.configuredNodeMode(), - randomLong(), createTempDir(), 2, 2, - UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 0, false, "tribe_node2", - getMockPlugins(), getClientWrapper()); - - cluster2.beforeTest(random(), 0.0); - cluster2.ensureAtLeastNumDataNodes(2); - - logger.info("create 2 indices, test1 on t1, and test2 on t2"); - assertAcked(internalCluster().client().admin().indices().prepareCreate("test1").get()); - assertAcked(cluster2.client().admin().indices().prepareCreate("test2").get()); - ensureYellow(internalCluster()); - ensureYellow(cluster2); - Map asMap = internalCluster().getDefaultSettings().getAsMap(); - Settings.Builder tribe1Defaults = Settings.builder(); - Settings.Builder tribe2Defaults = Settings.builder(); - for (Map.Entry entry : asMap.entrySet()) { - if (entry.getKey().startsWith("path.")) { - continue; - } - tribe1Defaults.put("tribe.t1." + entry.getKey(), entry.getValue()); - tribe2Defaults.put("tribe.t2." + entry.getKey(), entry.getValue()); - } - // give each tribe it's unicast hosts to connect to - tribe1Defaults.putArray("tribe.t1." + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), - getUnicastHosts(internalCluster().client())); - tribe1Defaults.putArray("tribe.t2." + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), - getUnicastHosts(cluster2.client())); - - Settings merged = Settings.builder() - .put("tribe.t1.cluster.name", internalCluster().getClusterName()) - .put("tribe.t2.cluster.name", cluster2.getClusterName()) - .put("tribe.blocks.write", false) - .put(tribe1Defaults.build()) - .put(tribe2Defaults.build()) - .put(internalCluster().getDefaultSettings()) - .put("node.name", "tribe_node") // make sure we can identify threads from this node - .put(Node.NODE_LOCAL_SETTING.getKey(), true) - .build(); - - final Node tribeNode = new Node(merged).start(); - Client tribeClient = tribeNode.client(); - - logger.info("wait till tribe has the same nodes as the 2 clusters"); - assertBusy(() -> { - DiscoveryNodes tribeNodes = tribeNode.client().admin().cluster().prepareState().get().getState().getNodes(); - assertThat(countDataNodesForTribe("t1", tribeNodes), - equalTo(internalCluster().client().admin().cluster().prepareState().get().getState() - .getNodes().getDataNodes().size())); - assertThat(countDataNodesForTribe("t2", tribeNodes), - equalTo(cluster2.client().admin().cluster().prepareState().get().getState() - .getNodes().getDataNodes().size())); - }); - verifyActionOnTribeNode(tribeClient); - verifyActionOnDataNode((randomBoolean() ? internalCluster() : cluster2).dataNodeClient()); - verifyActionOnDataNode((randomBoolean() ? internalCluster() : cluster2).masterClient()); - try { - cluster2.wipe(Collections.emptySet()); - } catch (NoNodeAvailableException ignored) { - } finally { - cluster2.afterTest(); - } - tribeNode.close(); - cluster2.close(); - } - protected void verifyActionOnDataNode(Client dataNodeClient) throws Exception { dataNodeClient.execute(GetLicenseAction.INSTANCE, new GetLicenseRequest()).get(); dataNodeClient.execute(PutLicenseAction.INSTANCE, new PutLicenseRequest() @@ -173,62 +27,10 @@ public class LicenseTribeTests extends ESIntegTestCase { dataNodeClient.execute(DeleteLicenseAction.INSTANCE, new DeleteLicenseRequest()); } + @Override protected void verifyActionOnTribeNode(Client tribeClient) { failAction(tribeClient, GetLicenseAction.INSTANCE); failAction(tribeClient, PutLicenseAction.INSTANCE); failAction(tribeClient, DeleteLicenseAction.INSTANCE); } - - protected void failAction(Client client, Action action) { - try { - client.execute(action, action.newRequestBuilder(client).request()); - fail("expected [" + action.name() + "] to fail"); - } catch (IllegalStateException e) { - assertThat(e.getMessage(), containsString("failed to find action")); - } - } - - private void ensureYellow(TestCluster testCluster) { - ClusterHealthResponse actionGet; - while (true) { - try { - actionGet = testCluster.client().admin().cluster() - .health(Requests.clusterHealthRequest().waitForYellowStatus() - .waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet(); - break; - } catch (NoNodeAvailableException ignored) { - } - } - if (actionGet.isTimedOut()) { - logger.info("ensureGreen timed out, cluster state:\n{}\n{}", testCluster.client().admin().cluster() - .prepareState().get().getState().prettyPrint(), - testCluster.client().admin().cluster().preparePendingClusterTasks().get().prettyPrint()); - assertThat("timed out waiting for yellow state", actionGet.isTimedOut(), equalTo(false)); - } - assertThat(actionGet.getStatus(), anyOf(equalTo(ClusterHealthStatus.YELLOW), equalTo(ClusterHealthStatus.GREEN))); - } - - private int countDataNodesForTribe(String tribeName, DiscoveryNodes nodes) { - int count = 0; - for (DiscoveryNode node : nodes) { - if (!node.isDataNode()) { - continue; - } - if (tribeName.equals(node.getAttributes().get("tribe.name"))) { - count++; - } - } - return count; - } - - public static String[] getUnicastHosts(Client client) { - ArrayList unicastHosts = new ArrayList<>(); - NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setTransport(true).get(); - for (NodeInfo info : nodeInfos.getNodes()) { - TransportAddress address = info.getTransport().getAddress().publishAddress(); - unicastHosts.add(address.getAddress() + ":" + address.getPort()); - } - return unicastHosts.toArray(new String[unicastHosts.size()]); - } - } diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/xpack/TribeTransportTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/xpack/TribeTransportTestCase.java new file mode 100644 index 00000000000..8fdb4fae563 --- /dev/null +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/xpack/TribeTransportTestCase.java @@ -0,0 +1,226 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.xpack; + +import org.elasticsearch.action.Action; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.Requests; +import org.elasticsearch.client.transport.NoNodeAvailableException; +import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.Priority; +import org.elasticsearch.common.UUIDs; +import org.elasticsearch.common.network.NetworkModule; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; +import org.elasticsearch.graph.Graph; +import org.elasticsearch.marvel.Monitoring; +import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.shield.Security; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import org.elasticsearch.test.ESIntegTestCase.Scope; +import org.elasticsearch.test.InternalTestCluster; +import org.elasticsearch.test.NodeConfigurationSource; +import org.elasticsearch.test.TestCluster; +import org.elasticsearch.xpack.watcher.Watcher; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; + +@ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 0, numDataNodes = 0) +public abstract class TribeTransportTestCase extends ESIntegTestCase { + + private static final Collection ALL_FEATURES = Arrays.asList(Security.NAME, Monitoring.NAME, + Watcher.NAME, Graph.NAME); + + protected List enabledFeatures() { + return Collections.emptyList(); + } + + @Override + protected final Settings nodeSettings(int nodeOrdinal) { + final Settings.Builder builder = Settings.builder() + .put(NetworkModule.HTTP_ENABLED.getKey(), false) + .put(Node.NODE_LOCAL_SETTING.getKey(), true); + List enabledFeatures = enabledFeatures(); + for (String feature : ALL_FEATURES) { + builder.put(XPackPlugin.featureEnabledSetting(feature), enabledFeatures.contains(feature)); + } + return builder.build(); + } + + @Override + protected final Collection> nodePlugins() { + return Collections.>singletonList(XPackPlugin.class); + } + + @Override + protected final Collection> transportClientPlugins() { + return nodePlugins(); + } + + public void testTribeSetup() throws Exception { + NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() { + @Override + public Settings nodeSettings(int nodeOrdinal) { + return TribeTransportTestCase.this.nodeSettings(nodeOrdinal); + } + + @Override + public Collection> nodePlugins() { + return TribeTransportTestCase.this.nodePlugins(); + } + + @Override + public Settings transportClientSettings() { + return TribeTransportTestCase.this.transportClientSettings(); + } + + @Override + public Collection> transportClientPlugins() { + return TribeTransportTestCase.this.transportClientPlugins(); + } + }; + final InternalTestCluster cluster2 = new InternalTestCluster(InternalTestCluster.configuredNodeMode(), + randomLong(), createTempDir(), 2, 2, + UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 0, false, "tribe_node2", + getMockPlugins(), getClientWrapper()); + + cluster2.beforeTest(random(), 0.0); + cluster2.ensureAtLeastNumDataNodes(2); + + logger.info("create 2 indices, test1 on t1, and test2 on t2"); + assertAcked(internalCluster().client().admin().indices().prepareCreate("test1").get()); + assertAcked(cluster2.client().admin().indices().prepareCreate("test2").get()); + ensureYellow(internalCluster()); + ensureYellow(cluster2); + Map asMap = internalCluster().getDefaultSettings().getAsMap(); + Settings.Builder tribe1Defaults = Settings.builder(); + Settings.Builder tribe2Defaults = Settings.builder(); + for (Map.Entry entry : asMap.entrySet()) { + if (entry.getKey().startsWith("path.")) { + continue; + } + tribe1Defaults.put("tribe.t1." + entry.getKey(), entry.getValue()); + tribe2Defaults.put("tribe.t2." + entry.getKey(), entry.getValue()); + } + // give each tribe it's unicast hosts to connect to + tribe1Defaults.putArray("tribe.t1." + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), + getUnicastHosts(internalCluster().client())); + tribe1Defaults.putArray("tribe.t2." + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), + getUnicastHosts(cluster2.client())); + + Settings merged = Settings.builder() + .put("tribe.t1.cluster.name", internalCluster().getClusterName()) + .put("tribe.t2.cluster.name", cluster2.getClusterName()) + .put("tribe.blocks.write", false) + .put(tribe1Defaults.build()) + .put(tribe2Defaults.build()) + .put(internalCluster().getDefaultSettings()) + .put("node.name", "tribe_node") // make sure we can identify threads from this node + .put(Node.NODE_LOCAL_SETTING.getKey(), true) + .build(); + + final Node tribeNode = new Node(merged).start(); + Client tribeClient = tribeNode.client(); + + logger.info("wait till tribe has the same nodes as the 2 clusters"); + assertBusy(() -> { + DiscoveryNodes tribeNodes = tribeNode.client().admin().cluster().prepareState().get().getState().getNodes(); + assertThat(countDataNodesForTribe("t1", tribeNodes), + equalTo(internalCluster().client().admin().cluster().prepareState().get().getState() + .getNodes().getDataNodes().size())); + assertThat(countDataNodesForTribe("t2", tribeNodes), + equalTo(cluster2.client().admin().cluster().prepareState().get().getState() + .getNodes().getDataNodes().size())); + }); + logger.info(" --> verify transport actions for tribe node"); + verifyActionOnTribeNode(tribeClient); + logger.info(" --> verify transport actions for data and master node"); + verifyActionOnDataNode((randomBoolean() ? internalCluster() : cluster2).dataNodeClient()); + verifyActionOnDataNode((randomBoolean() ? internalCluster() : cluster2).masterClient()); + try { + cluster2.wipe(Collections.emptySet()); + } catch (NoNodeAvailableException ignored) { + } finally { + cluster2.afterTest(); + } + tribeNode.close(); + cluster2.close(); + } + + /** + * Verify transport action behaviour on data node + */ + protected abstract void verifyActionOnDataNode(Client dataNodeClient) throws Exception; + + /** + * Verify transport action behaviour on tribe node + */ + protected abstract void verifyActionOnTribeNode(Client tribeClient); + + protected void failAction(Client client, Action action) { + try { + client.execute(action, action.newRequestBuilder(client).request()); + fail("expected [" + action.name() + "] to fail"); + } catch (IllegalStateException e) { + assertThat(e.getMessage(), containsString("failed to find action")); + } + } + + private void ensureYellow(TestCluster testCluster) { + ClusterHealthResponse actionGet = testCluster.client().admin().cluster() + .health(Requests.clusterHealthRequest().waitForYellowStatus() + .waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet(); + if (actionGet.isTimedOut()) { + logger.info("ensureGreen timed out, cluster state:\n{}\n{}", testCluster.client().admin().cluster() + .prepareState().get().getState().prettyPrint(), + testCluster.client().admin().cluster().preparePendingClusterTasks().get().prettyPrint()); + assertThat("timed out waiting for yellow state", actionGet.isTimedOut(), equalTo(false)); + } + assertThat(actionGet.getStatus(), anyOf(equalTo(ClusterHealthStatus.YELLOW), equalTo(ClusterHealthStatus.GREEN))); + } + + private int countDataNodesForTribe(String tribeName, DiscoveryNodes nodes) { + int count = 0; + for (DiscoveryNode node : nodes) { + if (!node.isDataNode()) { + continue; + } + if (tribeName.equals(node.getAttributes().get("tribe.name"))) { + count++; + } + } + return count; + } + + private static String[] getUnicastHosts(Client client) { + ArrayList unicastHosts = new ArrayList<>(); + NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setTransport(true).get(); + for (NodeInfo info : nodeInfos.getNodes()) { + TransportAddress address = info.getTransport().getAddress().publishAddress(); + unicastHosts.add(address.getAddress() + ":" + address.getPort()); + } + return unicastHosts.toArray(new String[unicastHosts.size()]); + } + +} diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MonitoringTribeTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MonitoringTribeTests.java new file mode 100644 index 00000000000..d9b5204a3f9 --- /dev/null +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MonitoringTribeTests.java @@ -0,0 +1,37 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.marvel; + +import org.elasticsearch.client.Client; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.marvel.action.MonitoringBulkAction; +import org.elasticsearch.marvel.action.MonitoringBulkDoc; +import org.elasticsearch.marvel.action.MonitoringBulkRequest; +import org.elasticsearch.xpack.TribeTransportTestCase; + +import java.util.Collections; +import java.util.List; + +public class MonitoringTribeTests extends TribeTransportTestCase { + + @Override + protected List enabledFeatures() { + return Collections.singletonList(Monitoring.NAME); + } + + @Override + protected void verifyActionOnDataNode(Client dataNodeClient) throws Exception { + MonitoringBulkDoc doc = new MonitoringBulkDoc(randomAsciiOfLength(2), randomAsciiOfLength(2)); + doc.setType(randomAsciiOfLength(5)); + doc.setSource(new BytesArray("{\"key\" : \"value\"}")); + dataNodeClient.execute(MonitoringBulkAction.INSTANCE, new MonitoringBulkRequest()); + } + + @Override + protected void verifyActionOnTribeNode(Client tribeClient) { + failAction(tribeClient, MonitoringBulkAction.INSTANCE); + } +} From bd04cc9d1feacebd2d497d863522cd054647b341 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Tue, 3 May 2016 14:43:43 -0400 Subject: [PATCH 05/13] Extend tribe integ test infra to test on master and client nodes Original commit: elastic/x-pack-elasticsearch@5826fb4161082942546141faf86b228053b31a03 --- .../license/plugin/LicenseTribeTests.java | 20 +++++++++++++--- .../xpack/TribeTransportTestCase.java | 23 ++++++++++++++----- .../marvel/MonitoringTribeTests.java | 16 ++++++++++++- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java index 51709949de4..29d0f7766b5 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicenseTribeTests.java @@ -19,12 +19,26 @@ import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense; public class LicenseTribeTests extends TribeTransportTestCase { + @Override + protected void verifyActionOnClientNode(Client client) throws Exception { + assertLicenseTransportActionsWorks(client); + } + + @Override + protected void verifyActionOnMasterNode(Client masterClient) throws Exception { + assertLicenseTransportActionsWorks(masterClient); + } + @Override protected void verifyActionOnDataNode(Client dataNodeClient) throws Exception { - dataNodeClient.execute(GetLicenseAction.INSTANCE, new GetLicenseRequest()).get(); - dataNodeClient.execute(PutLicenseAction.INSTANCE, new PutLicenseRequest() + assertLicenseTransportActionsWorks(dataNodeClient); + } + + private static void assertLicenseTransportActionsWorks(Client client) throws Exception { + client.execute(GetLicenseAction.INSTANCE, new GetLicenseRequest()).get(); + client.execute(PutLicenseAction.INSTANCE, new PutLicenseRequest() .license(generateSignedLicense(TimeValue.timeValueHours(1)))); - dataNodeClient.execute(DeleteLicenseAction.INSTANCE, new DeleteLicenseRequest()); + client.execute(DeleteLicenseAction.INSTANCE, new DeleteLicenseRequest()); } @Override diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/xpack/TribeTransportTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/xpack/TribeTransportTestCase.java index 8fdb4fae563..deb1c6456e4 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/xpack/TribeTransportTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/xpack/TribeTransportTestCase.java @@ -11,7 +11,6 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; -import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; @@ -46,7 +45,7 @@ import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -@ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 0, numDataNodes = 0) +@ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 1, numDataNodes = 0) public abstract class TribeTransportTestCase extends ESIntegTestCase { private static final Collection ALL_FEATURES = Arrays.asList(Security.NAME, Monitoring.NAME, @@ -102,7 +101,7 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { }; final InternalTestCluster cluster2 = new InternalTestCluster(InternalTestCluster.configuredNodeMode(), randomLong(), createTempDir(), 2, 2, - UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 0, false, "tribe_node2", + UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 1, false, "tribe_node2", getMockPlugins(), getClientWrapper()); cluster2.beforeTest(random(), 0.0); @@ -155,12 +154,14 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { }); logger.info(" --> verify transport actions for tribe node"); verifyActionOnTribeNode(tribeClient); - logger.info(" --> verify transport actions for data and master node"); + logger.info(" --> verify transport actions for data node"); verifyActionOnDataNode((randomBoolean() ? internalCluster() : cluster2).dataNodeClient()); - verifyActionOnDataNode((randomBoolean() ? internalCluster() : cluster2).masterClient()); + logger.info(" --> verify transport actions for master node"); + verifyActionOnMasterNode((randomBoolean() ? internalCluster() : cluster2).masterClient()); + logger.info(" --> verify transport actions for client node"); + verifyActionOnClientNode((randomBoolean() ? internalCluster() : cluster2).coordOnlyNodeClient()); try { cluster2.wipe(Collections.emptySet()); - } catch (NoNodeAvailableException ignored) { } finally { cluster2.afterTest(); } @@ -168,6 +169,16 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { cluster2.close(); } + /** + * Verify transport action behaviour on client node + */ + protected abstract void verifyActionOnClientNode(Client client) throws Exception; + + /** + * Verify transport action behaviour on master node + */ + protected abstract void verifyActionOnMasterNode(Client masterClient) throws Exception; + /** * Verify transport action behaviour on data node */ diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MonitoringTribeTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MonitoringTribeTests.java index d9b5204a3f9..df11eaae87e 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MonitoringTribeTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MonitoringTribeTests.java @@ -22,12 +22,26 @@ public class MonitoringTribeTests extends TribeTransportTestCase { return Collections.singletonList(Monitoring.NAME); } + @Override + protected void verifyActionOnClientNode(Client client) throws Exception { + assertMonitoringTransportActionsWorks(client); + } + + @Override + protected void verifyActionOnMasterNode(Client masterClient) throws Exception { + assertMonitoringTransportActionsWorks(masterClient); + } + @Override protected void verifyActionOnDataNode(Client dataNodeClient) throws Exception { + assertMonitoringTransportActionsWorks(dataNodeClient); + } + + private static void assertMonitoringTransportActionsWorks(Client client) throws Exception { MonitoringBulkDoc doc = new MonitoringBulkDoc(randomAsciiOfLength(2), randomAsciiOfLength(2)); doc.setType(randomAsciiOfLength(5)); doc.setSource(new BytesArray("{\"key\" : \"value\"}")); - dataNodeClient.execute(MonitoringBulkAction.INSTANCE, new MonitoringBulkRequest()); + client.execute(MonitoringBulkAction.INSTANCE, new MonitoringBulkRequest()); } @Override From 22c4fb9a325b95959cec3c4ea62d3ec9e64501a6 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Fri, 6 May 2016 09:05:45 +0200 Subject: [PATCH 06/13] Make compilation pass. Note: tests are still failing. Original commit: elastic/x-pack-elasticsearch@827d129876b215d1998130f1bef6a147d6afe76e --- .../marvel/action/TransportMonitoringBulkActionTests.java | 2 +- .../shield/transport/ShieldClientTransportService.java | 6 ++++-- .../shield/transport/ShieldServerTransportService.java | 4 +++- .../shield/transport/TransportFilterTests.java | 7 ++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/TransportMonitoringBulkActionTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/TransportMonitoringBulkActionTests.java index 4dc0f3d7d11..f9876038b73 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/TransportMonitoringBulkActionTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/action/TransportMonitoringBulkActionTests.java @@ -105,7 +105,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase { clusterService.setClusterStatePublisher((event, ackListener) -> {}); clusterService.start(); - transportService = new TransportService(transport, threadPool); + transportService = new TransportService(Settings.EMPTY, transport, threadPool, clusterService.state().getClusterName()); transportService.start(); transportService.acceptIncomingRequests(); exportService = new CapturingExporters(); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldClientTransportService.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldClientTransportService.java index efe014c74c8..c4320ab973e 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldClientTransportService.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldClientTransportService.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.shield.transport; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -22,8 +23,9 @@ public class ShieldClientTransportService extends TransportService { private final ClientTransportFilter clientFilter; @Inject - public ShieldClientTransportService(Settings settings, Transport transport, ThreadPool threadPool, ClientTransportFilter clientFilter) { - super(settings, transport, threadPool); + public ShieldClientTransportService(Settings settings, Transport transport, ThreadPool threadPool, + ClusterName clusterName, ClientTransportFilter clientFilter) { + super(settings, transport, threadPool, clusterName); this.clientFilter = clientFilter; } diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldServerTransportService.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldServerTransportService.java index 55aa96a4cf6..33a7ae27cb1 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldServerTransportService.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/transport/ShieldServerTransportService.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.shield.transport; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -55,12 +56,13 @@ public class ShieldServerTransportService extends TransportService { @Inject public ShieldServerTransportService(Settings settings, Transport transport, ThreadPool threadPool, + ClusterName clusterName, AuthenticationService authcService, AuthorizationService authzService, ShieldActionMapper actionMapper, ClientTransportFilter clientTransportFilter, SecurityLicenseState licenseState) { - super(settings, transport, threadPool); + super(settings, transport, threadPool, clusterName); this.authcService = authcService; this.authzService = authzService; this.actionMapper = actionMapper; diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java index 4eca2456082..f46f7ab8c41 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.shield.transport; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; @@ -307,9 +308,9 @@ public class TransportFilterTests extends ESIntegTestCase { @Inject public InternalPluginServerTransportService(Settings settings, Transport transport, ThreadPool threadPool, - AuthenticationService authcService, AuthorizationService authzService, ShieldActionMapper actionMapper, - ClientTransportFilter clientTransportFilter) { - super(settings, transport, threadPool, authcService, authzService, actionMapper, clientTransportFilter, + ClusterName clusterName, AuthenticationService authcService, AuthorizationService authzService, + ShieldActionMapper actionMapper, ClientTransportFilter clientTransportFilter) { + super(settings, transport, threadPool, clusterName, authcService, authzService, actionMapper, clientTransportFilter, mock(SecurityLicenseState.class)); when(licenseState.authenticationAndAuthorizationEnabled()).thenReturn(true); } From 5db861d14b9eb273ffcf2a3536a08284eec1c316 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Fri, 6 May 2016 09:06:30 +0200 Subject: [PATCH 07/13] Remove generics from QueryBuilder. Related to elastic/elasticsearchelastic/elasticsearch#18133. Original commit: elastic/x-pack-elasticsearch@bd8ca4f061351705fb572ca6c590157d9e107f85 --- .../org/elasticsearch/graph/action/GraphExploreRequest.java | 2 +- .../graph/action/GraphExploreRequestBuilder.java | 2 +- .../src/main/java/org/elasticsearch/graph/action/Hop.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreRequest.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreRequest.java index f39bfdda84b..62c02ed360c 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreRequest.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreRequest.java @@ -278,7 +278,7 @@ public class GraphExploreRequest extends ActionRequest impl * are considered in this stage * @return a {@link Hop} object that holds settings for a stage in the graph exploration */ - public Hop createNextHop(QueryBuilder guidingQuery) { + public Hop createNextHop(QueryBuilder guidingQuery) { Hop parent = null; if (hops.size() > 0) { parent = hops.get(hops.size() - 1); diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreRequestBuilder.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreRequestBuilder.java index 090ac3c3ab8..dee78a445dc 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreRequestBuilder.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/GraphExploreRequestBuilder.java @@ -120,7 +120,7 @@ public class GraphExploreRequestBuilder extends ActionRequestBuilder guidingQuery) { + public Hop createNextHop(@Nullable QueryBuilder guidingQuery) { return request.createNextHop(guidingQuery); } diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/Hop.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/Hop.java index 598d0cfc792..3ae01c472c4 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/Hop.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/action/Hop.java @@ -44,7 +44,7 @@ import java.util.List; public class Hop { final Hop parentHop; List vertices = null; - QueryBuilder guidingQuery = null; + QueryBuilder guidingQuery = null; Hop(Hop parent) { this.parentHop = parent; @@ -88,7 +88,7 @@ public class Hop { } } - public QueryBuilder guidingQuery() { + public QueryBuilder guidingQuery() { if (guidingQuery != null) { return guidingQuery; } @@ -117,7 +117,7 @@ public class Hop { * * @param queryBuilder any query */ - public void guidingQuery(QueryBuilder queryBuilder) { + public void guidingQuery(QueryBuilder queryBuilder) { guidingQuery = queryBuilder; } From 330e427f405702e030e079dc6437d3c62034efe4 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Mon, 25 Apr 2016 14:23:40 +0200 Subject: [PATCH 08/13] Monitoring: Add Points stats to node and index segments stats Original commit: elastic/x-pack-elasticsearch@7df2538068f175752e49303a29e526362d3a3b9b --- .../marvel/agent/resolver/indices/IndexStatsResolver.java | 2 ++ .../marvel/agent/resolver/node/NodeStatsResolver.java | 1 + 2 files changed, 3 insertions(+) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsResolver.java index c64e900d9fd..21b66c51924 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/indices/IndexStatsResolver.java @@ -37,6 +37,7 @@ public class IndexStatsResolver extends MonitoringIndexNameResolver.Timestamped< "index_stats.primaries.segments.stored_fields_memory_in_bytes", "index_stats.primaries.segments.term_vectors_memory_in_bytes", "index_stats.primaries.segments.norms_memory_in_bytes", + "index_stats.primaries.segments.points_memory_in_bytes", "index_stats.primaries.segments.doc_values_memory_in_bytes", "index_stats.primaries.segments.index_writer_memory_in_bytes", "index_stats.primaries.segments.version_map_memory_in_bytes", @@ -57,6 +58,7 @@ public class IndexStatsResolver extends MonitoringIndexNameResolver.Timestamped< "index_stats.total.segments.stored_fields_memory_in_bytes", "index_stats.total.segments.term_vectors_memory_in_bytes", "index_stats.total.segments.norms_memory_in_bytes", + "index_stats.total.segments.points_memory_in_bytes", "index_stats.total.segments.doc_values_memory_in_bytes", "index_stats.total.segments.index_writer_memory_in_bytes", "index_stats.total.segments.version_map_memory_in_bytes", diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsResolver.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsResolver.java index da8ec4a50a7..861d8764e43 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsResolver.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/resolver/node/NodeStatsResolver.java @@ -45,6 +45,7 @@ public class NodeStatsResolver extends MonitoringIndexNameResolver.Timestamped Date: Fri, 6 May 2016 09:15:44 -0400 Subject: [PATCH 09/13] Add handshake to list of known handlers for tests This commit adds internal:transport/handshake to the list of known handlers for tests. Closes elastic/elasticsearch#2183 Original commit: elastic/x-pack-elasticsearch@c4b415367b7ab1fd24246a6a658cdc51144c4844 --- .../src/test/resources/org/elasticsearch/transport/handlers | 1 + 1 file changed, 1 insertion(+) diff --git a/elasticsearch/x-pack/shield/src/test/resources/org/elasticsearch/transport/handlers b/elasticsearch/x-pack/shield/src/test/resources/org/elasticsearch/transport/handlers index 5fc61b4d1a4..0212f6e4b64 100644 --- a/elasticsearch/x-pack/shield/src/test/resources/org/elasticsearch/transport/handlers +++ b/elasticsearch/x-pack/shield/src/test/resources/org/elasticsearch/transport/handlers @@ -110,3 +110,4 @@ internal:indices/flush/synced/pre internal:indices/flush/synced/sync internal:admin/repository/verify internal:plugin/license/cluster/register_trial_license +internal:transport/handshake From ec0a4646ead3d0e0771bb2f801563e298cbe8574 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Wed, 27 Apr 2016 02:48:10 -0400 Subject: [PATCH 10/13] Add Failure Details to every NodesResponse (x-plugins side) Original commit: elastic/x-pack-elasticsearch@9ffb88caaf547356543a37987b7939a9a0e4acb9 --- .../collector/node/NodeStatsCollector.java | 14 +++++------ .../cluster/ClusterInfoResolverTests.java | 3 ++- .../cluster/ClusterStatsResolverTests.java | 4 +++- .../action/realm/ClearRealmCacheResponse.java | 22 +++++++---------- .../realm/TransportClearRealmCacheAction.java | 23 +++++------------- .../action/role/ClearRolesCacheResponse.java | 22 +++++++---------- .../role/TransportClearRolesCacheAction.java | 24 +++++-------------- .../realm/RestClearRealmCacheAction.java | 3 +++ .../role/RestClearRolesCacheAction.java | 3 +++ 9 files changed, 47 insertions(+), 71 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java index 72e6cf6ff83..4a9784bcea8 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java @@ -5,9 +5,9 @@ */ package org.elasticsearch.marvel.agent.collector.node; - import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; import org.elasticsearch.bootstrap.BootstrapInfo; import org.elasticsearch.client.Client; @@ -72,16 +72,14 @@ public class NodeStatsCollector extends AbstractCollector { request.threadPool(true); request.fs(true); - NodeStats[] nodesStatsResponses = client.admin().cluster().nodesStats(request).actionGet().getNodes(); + NodesStatsResponse response = client.admin().cluster().nodesStats(request).actionGet(); - // In unusual scenarios, node stats can be empty (e.g., closing an index in the middle of the request) - // Note: NodesStatsResponse does not currently override failures, so we cannot log the actual reason - if (nodesStatsResponses.length == 0) { - logger.debug("_local NodesStatsResponse is empty"); - return null; + // if there's a failure, then we failed to work with the _local node (guaranteed a single exception) + if (response.hasFailures()) { + throw response.failures()[0]; } - NodeStats nodeStats = nodesStatsResponses[0]; + NodeStats nodeStats = response.getAt(0); // Here we are calling directly the DiskThresholdDecider to retrieve the high watermark value // It would be nicer to use a settings API like documented in #6732 diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolverTests.java index 9d98b85643d..c9c4e412ed7 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolverTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.marvel.agent.resolver.cluster; import org.elasticsearch.Version; +import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodeResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.cluster.ClusterName; @@ -46,7 +47,7 @@ public class ClusterInfoResolverTests extends MonitoringIndexNameResolverTestCas doc.setLicense(licenseBuilder.build()); doc.setClusterName(randomAsciiOfLength(5)); doc.setClusterStats(new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, - randomAsciiOfLength(5), new ClusterStatsNodeResponse[]{})); + randomAsciiOfLength(5), new ClusterStatsNodeResponse[]{}, new FailedNodeException[0])); return doc; } catch (Exception e) { throw new IllegalStateException("Failed to generated random ClusterInfoMarvelDoc", e); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java index 1937ab9a410..fe5479891b7 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.marvel.agent.resolver.cluster; import org.elasticsearch.Version; +import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; @@ -97,7 +98,8 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa emptyMap(), emptySet(), Version.CURRENT), ClusterHealthStatus.GREEN, randomNodeInfo(), randomNodeStats(), randomShardStats()) }; - return new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, UUID.randomUUID().toString(), responses); + return new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, UUID.randomUUID().toString(), responses, + new FailedNodeException[0]); } /** diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java index 7684e5d2b33..37b4143b498 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.shield.action.realm; +import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.support.nodes.BaseNodeResponse; import org.elasticsearch.action.support.nodes.BaseNodesResponse; import org.elasticsearch.cluster.ClusterName; @@ -25,32 +26,26 @@ public class ClearRealmCacheResponse extends BaseNodesResponse nodes = new ArrayList<>(); - for (int i = 0; i < responses.length(); i++) { - Object resp = responses.get(i); - if (resp instanceof ClearRealmCacheResponse.Node) { - nodes.add((ClearRealmCacheResponse.Node) resp); - } else if (resp != null) { - // null is possible if there is an error and we do not accumulate exceptions... - throw new IllegalArgumentException("node response [" + resp.getClass() + "] is not the correct type"); - } - } - return new ClearRealmCacheResponse(clusterName, nodes.toArray(new ClearRealmCacheResponse.Node[nodes.size()])); + protected ClearRealmCacheResponse newResponse(ClearRealmCacheRequest request, + ClearRealmCacheResponse.Node[] responses, FailedNodeException[] failures) { + return new ClearRealmCacheResponse(clusterName, responses, failures); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java index 30abd43f46c..011cf5d5951 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.shield.action.role; +import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.support.nodes.BaseNodeResponse; import org.elasticsearch.action.support.nodes.BaseNodesResponse; import org.elasticsearch.cluster.ClusterName; @@ -25,32 +26,26 @@ public class ClearRolesCacheResponse extends BaseNodesResponse responses = new ArrayList<>(nodesResponses.length()); - for (int i = 0; i < nodesResponses.length(); i++) { - Object resp = nodesResponses.get(i); - if (resp instanceof ClearRolesCacheResponse.Node) { - responses.add((ClearRolesCacheResponse.Node) resp); - } else if (resp == null) { - // null is possible if there is an error and we do not accumulate exceptions... - throw new IllegalArgumentException("node response [" + resp.getClass() + "] is not the correct type"); - } - } - return new ClearRolesCacheResponse(clusterName, responses.toArray(new ClearRolesCacheResponse.Node[responses.size()])); + protected ClearRolesCacheResponse newResponse(ClearRolesCacheRequest request, + ClearRolesCacheResponse.Node[] responses, FailedNodeException[] failures) { + return new ClearRolesCacheResponse(clusterName, responses, failures); } @Override diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java index dce0470f94b..111bcd9c0fa 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java @@ -44,7 +44,10 @@ public class RestClearRealmCacheAction extends BaseRestHandler { new SecurityClient(client).clearRealmCache(req, new RestBuilderListener(channel) { @Override public RestResponse buildResponse(ClearRealmCacheResponse response, XContentBuilder builder) throws Exception { + builder.startObject(); response.toXContent(builder, ToXContent.EMPTY_PARAMS); + builder.endObject(); + return new BytesRestResponse(RestStatus.OK, builder); } }); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java index 7432dc8c0e0..b3b8f959560 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java @@ -45,7 +45,10 @@ public class RestClearRolesCacheAction extends BaseRestHandler { new SecurityClient(client).clearRolesCache(req, new RestBuilderListener(channel) { @Override public RestResponse buildResponse(ClearRolesCacheResponse response, XContentBuilder builder) throws Exception { + builder.startObject(); response.toXContent(builder, ToXContent.EMPTY_PARAMS); + builder.endObject(); + return new BytesRestResponse(RestStatus.OK, builder); } }); From 080000a5953771eb4d2058ef4a8f30e5080cf275 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Thu, 28 Apr 2016 02:18:23 -0400 Subject: [PATCH 11/13] Updating with array changed to list. Original commit: elastic/x-pack-elasticsearch@552227458f15c9193895d71e8b2cd39f07680794 --- .../shield/qa/ShieldTransportClientIT.java | 7 ++++--- .../example/realm/CustomRealmIT.java | 13 +++++++------ .../SmokeTestMonitoringWithShieldIT.java | 11 ++++++----- .../collector/node/NodeStatsCollector.java | 4 ++-- .../marvel/MarvelPluginTests.java | 4 ++-- .../cluster/ClusterStatsCollectorTests.java | 2 +- .../cluster/ClusterInfoResolverTests.java | 5 ++--- .../cluster/ClusterStatsResolverTests.java | 9 ++++----- .../action/realm/ClearRealmCacheResponse.java | 11 +++++------ .../realm/TransportClearRealmCacheAction.java | 4 +++- .../action/role/ClearRolesCacheResponse.java | 9 ++++----- .../role/TransportClearRolesCacheAction.java | 4 +++- .../realm/RestClearRealmCacheAction.java | 19 ++----------------- .../role/RestClearRolesCacheAction.java | 19 ++----------------- .../integration/ClearRealmsCacheTests.java | 2 +- .../RemoteIndexAuditTrailStartingTests.java | 2 +- .../shield/authc/RunAsIntegTests.java | 7 ++++--- .../test/ShieldIntegTestCase.java | 2 +- .../watcher/WatcherPluginDisableTests.java | 2 +- .../bench/WatcherScheduleEngineBenchmark.java | 4 ++-- 20 files changed, 57 insertions(+), 83 deletions(-) diff --git a/elasticsearch/qa/shield-client-tests/src/test/java/org/elasticsearch/shield/qa/ShieldTransportClientIT.java b/elasticsearch/qa/shield-client-tests/src/test/java/org/elasticsearch/shield/qa/ShieldTransportClientIT.java index b0522871545..bc8cb9aa510 100644 --- a/elasticsearch/qa/shield-client-tests/src/test/java/org/elasticsearch/shield/qa/ShieldTransportClientIT.java +++ b/elasticsearch/qa/shield-client-tests/src/test/java/org/elasticsearch/shield/qa/ShieldTransportClientIT.java @@ -20,6 +20,7 @@ import org.elasticsearch.xpack.XPackPlugin; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.concurrent.TimeUnit; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; @@ -104,10 +105,10 @@ public class ShieldTransportClientIT extends ESIntegTestCase { TransportClient transportClient(Settings extraSettings) { NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get(); - NodeInfo[] nodes = nodeInfos.getNodes(); - assertTrue(nodes.length > 0); + List nodes = nodeInfos.getNodes(); + assertTrue(nodes.isEmpty() == false); TransportAddress publishAddress = randomFrom(nodes).getTransport().address().publishAddress(); - String clusterName = nodeInfos.getClusterNameAsString(); + String clusterName = nodeInfos.getClusterName().value(); Settings settings = Settings.builder() .put(extraSettings) diff --git a/elasticsearch/qa/shield-example-realm/src/test/java/org/elasticsearch/example/realm/CustomRealmIT.java b/elasticsearch/qa/shield-example-realm/src/test/java/org/elasticsearch/example/realm/CustomRealmIT.java index 2c6b60b7b8f..0e46268b2a2 100644 --- a/elasticsearch/qa/shield-example-realm/src/test/java/org/elasticsearch/example/realm/CustomRealmIT.java +++ b/elasticsearch/qa/shield-example-realm/src/test/java/org/elasticsearch/example/realm/CustomRealmIT.java @@ -21,6 +21,7 @@ import org.elasticsearch.xpack.XPackPlugin; import java.util.Collection; import java.util.Collections; +import java.util.List; import static org.hamcrest.Matchers.is; @@ -58,10 +59,10 @@ public class CustomRealmIT extends ESIntegTestCase { public void testTransportClient() throws Exception { NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get(); - NodeInfo[] nodes = nodeInfos.getNodes(); - assertTrue(nodes.length > 0); + List nodes = nodeInfos.getNodes(); + assertTrue(nodes.isEmpty() == false); TransportAddress publishAddress = randomFrom(nodes).getTransport().address().publishAddress(); - String clusterName = nodeInfos.getClusterNameAsString(); + String clusterName = nodeInfos.getClusterName().value(); Settings settings = Settings.builder() .put("cluster.name", clusterName) @@ -78,10 +79,10 @@ public class CustomRealmIT extends ESIntegTestCase { public void testTransportClientWrongAuthentication() throws Exception { NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get(); - NodeInfo[] nodes = nodeInfos.getNodes(); - assertTrue(nodes.length > 0); + List nodes = nodeInfos.getNodes(); + assertTrue(nodes.isEmpty() == false); TransportAddress publishAddress = randomFrom(nodes).getTransport().address().publishAddress(); - String clusterName = nodeInfos.getClusterNameAsString(); + String clusterName = nodeInfos.getClusterName().value(); Settings settings = Settings.builder() .put("cluster.name", clusterName) diff --git a/elasticsearch/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithShieldIT.java b/elasticsearch/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithShieldIT.java index f4f74d20c3f..23dc1b4a34a 100644 --- a/elasticsearch/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithShieldIT.java +++ b/elasticsearch/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithShieldIT.java @@ -28,6 +28,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; import java.util.Collections; +import java.util.List; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @@ -117,12 +118,12 @@ public class SmokeTestMonitoringWithShieldIT extends ESIntegTestCase { } private InetSocketAddress[] httpAddresses() { - NodeInfo[] nodes = client().admin().cluster().prepareNodesInfo().clear().setHttp(true).get().getNodes(); - assertThat(nodes.length, greaterThan(0)); + List nodes = client().admin().cluster().prepareNodesInfo().clear().setHttp(true).get().getNodes(); + assertThat(nodes.size(), greaterThan(0)); - InetSocketAddress[] httpAddresses = new InetSocketAddress[nodes.length]; - for (int i = 0; i < nodes.length; i++) { - httpAddresses[i] = ((InetSocketTransportAddress) nodes[i].getHttp().address().publishAddress()).address(); + InetSocketAddress[] httpAddresses = new InetSocketAddress[nodes.size()]; + for (int i = 0; i < nodes.size(); i++) { + httpAddresses[i] = ((InetSocketTransportAddress) nodes.get(i).getHttp().address().publishAddress()).address(); } return httpAddresses; } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java index 4a9784bcea8..680596fdf1c 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/node/NodeStatsCollector.java @@ -76,10 +76,10 @@ public class NodeStatsCollector extends AbstractCollector { // if there's a failure, then we failed to work with the _local node (guaranteed a single exception) if (response.hasFailures()) { - throw response.failures()[0]; + throw response.failures().get(0); } - NodeStats nodeStats = response.getAt(0); + NodeStats nodeStats = response.getNodes().get(0); // Here we are calling directly the DiskThresholdDecider to retrieve the high watermark value // It would be nicer to use a settings API like documented in #6732 diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginTests.java index 63b4753e673..9e7d39fd542 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginTests.java @@ -72,7 +72,7 @@ public class MarvelPluginTests extends MarvelIntegTestCase { private void assertPluginIsLoaded() { NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().setPlugins(true).get(); - for (NodeInfo nodeInfo : response) { + for (NodeInfo nodeInfo : response.getNodes()) { assertNotNull(nodeInfo.getPlugins()); boolean found = false; @@ -103,7 +103,7 @@ public class MarvelPluginTests extends MarvelIntegTestCase { internalCluster().getDataNodeInstance(klass); fail("should have thrown an exception about missing implementation"); } catch (Exception ce) { - assertThat("message contains error about missing implemention: " + ce.getMessage(), + assertThat("message contains error about missing implementation: " + ce.getMessage(), ce.getMessage().contains("No implementation"), equalTo(true)); } } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStatsCollectorTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStatsCollectorTests.java index 8d6c4120677..84d2bbe2e5f 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStatsCollectorTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/cluster/ClusterStatsCollectorTests.java @@ -50,7 +50,7 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase { assertThat(clusterInfoMarvelDoc.getClusterName(), equalTo(client().admin().cluster().prepareState().setMetaData(true).get().getClusterName().value())); assertThat(clusterInfoMarvelDoc.getVersion(), - equalTo(client().admin().cluster().prepareNodesInfo().get().getNodes()[0].getVersion().toString())); + equalTo(client().admin().cluster().prepareNodesInfo().get().getNodes().get(0).getVersion().toString())); assertThat(clusterInfoMarvelDoc.getLicense(), notNullValue()); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolverTests.java index c9c4e412ed7..514f75351fa 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterInfoResolverTests.java @@ -6,8 +6,6 @@ package org.elasticsearch.marvel.agent.resolver.cluster; import org.elasticsearch.Version; -import org.elasticsearch.action.FailedNodeException; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodeResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -19,6 +17,7 @@ import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoMonitoringDoc import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolverTestCase; +import java.util.Collections; import java.util.UUID; import static java.util.Collections.emptyMap; @@ -47,7 +46,7 @@ public class ClusterInfoResolverTests extends MonitoringIndexNameResolverTestCas doc.setLicense(licenseBuilder.build()); doc.setClusterName(randomAsciiOfLength(5)); doc.setClusterStats(new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, - randomAsciiOfLength(5), new ClusterStatsNodeResponse[]{}, new FailedNodeException[0])); + randomAsciiOfLength(5), Collections.emptyList(), Collections.emptyList())); return doc; } catch (Exception e) { throw new IllegalStateException("Failed to generated random ClusterInfoMarvelDoc", e); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java index fe5479891b7..dc470d63388 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.marvel.agent.resolver.cluster; import org.elasticsearch.Version; -import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; @@ -93,13 +92,13 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa * @return a testing {@link ClusterStatsResponse} used to resolve a marvel document. */ private ClusterStatsResponse randomClusterStats() { - ClusterStatsNodeResponse[] responses = { + List responses = Collections.singletonList( new ClusterStatsNodeResponse(new DiscoveryNode("node_0", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT), ClusterHealthStatus.GREEN, randomNodeInfo(), randomNodeStats(), randomShardStats()) - }; - return new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, UUID.randomUUID().toString(), responses, - new FailedNodeException[0]); + ); + return new ClusterStatsResponse(Math.abs(randomLong()), ClusterName.DEFAULT, UUID.randomUUID().toString(), + responses, Collections.emptyList()); } /** diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java index 37b4143b498..04dc2a26e34 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java @@ -17,6 +17,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import java.io.IOException; +import java.util.List; /** * @@ -26,28 +27,26 @@ public class ClearRealmCacheResponse extends BaseNodesResponse nodes, List failures) { super(clusterName, nodes, failures); } @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - nodes = in.readArray(Node[]::new, Node::readNodeResponse); + nodes = in.readList(Node::readNodeResponse); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeArray(nodes); + out.writeStreamableList(nodes); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - super.toInnerXContent(builder, params); - builder.startObject("nodes"); - for (ClearRealmCacheResponse.Node node: getNodes()) { + for (ClearRealmCacheResponse.Node node : getNodes()) { builder.startObject(node.getNode().getId()); builder.field("name", node.getNode().getName()); builder.endObject(); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/TransportClearRealmCacheAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/TransportClearRealmCacheAction.java index 5085be2d18d..c2a4c81a63b 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/TransportClearRealmCacheAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/TransportClearRealmCacheAction.java @@ -20,6 +20,8 @@ import org.elasticsearch.shield.authc.support.CachingRealm; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import java.util.List; + /** * */ @@ -41,7 +43,7 @@ public class TransportClearRealmCacheAction extends TransportNodesAction responses, List failures) { return new ClearRealmCacheResponse(clusterName, responses, failures); } diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java index 011cf5d5951..88cd1477689 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java @@ -17,6 +17,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import java.io.IOException; +import java.util.List; /** * The response object that will be returned when clearing the cache of native roles @@ -26,26 +27,24 @@ public class ClearRolesCacheResponse extends BaseNodesResponse nodes, List failures) { super(clusterName, nodes, failures); } @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - nodes = in.readArray(Node[]::new, Node::readNodeResponse); + nodes = in.readList(Node::readNodeResponse); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeArray(nodes); + out.writeStreamableList(nodes); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - super.toInnerXContent(builder, params); - builder.startObject("nodes"); for (ClearRolesCacheResponse.Node node: getNodes()) { builder.startObject(node.getNode().getId()); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/TransportClearRolesCacheAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/TransportClearRolesCacheAction.java index a02fc372831..0d1498ac9ff 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/TransportClearRolesCacheAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/TransportClearRolesCacheAction.java @@ -17,6 +17,8 @@ import org.elasticsearch.shield.authz.store.NativeRolesStore; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import java.util.List; + /** * */ @@ -37,7 +39,7 @@ public class TransportClearRolesCacheAction extends TransportNodesAction responses, List failures) { return new ClearRolesCacheResponse(clusterName, responses, failures); } diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java index 111bcd9c0fa..a33ded253fb 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/realm/RestClearRealmCacheAction.java @@ -8,18 +8,12 @@ package org.elasticsearch.shield.rest.action.realm; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.action.support.RestBuilderListener; +import org.elasticsearch.rest.action.support.RestActions.NodesResponseRestListener; import org.elasticsearch.shield.action.realm.ClearRealmCacheRequest; -import org.elasticsearch.shield.action.realm.ClearRealmCacheResponse; import org.elasticsearch.shield.client.SecurityClient; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -41,16 +35,7 @@ public class RestClearRealmCacheAction extends BaseRestHandler { ClearRealmCacheRequest req = new ClearRealmCacheRequest().realms(realms).usernames(usernames); - new SecurityClient(client).clearRealmCache(req, new RestBuilderListener(channel) { - @Override - public RestResponse buildResponse(ClearRealmCacheResponse response, XContentBuilder builder) throws Exception { - builder.startObject(); - response.toXContent(builder, ToXContent.EMPTY_PARAMS); - builder.endObject(); - - return new BytesRestResponse(RestStatus.OK, builder); - } - }); + new SecurityClient(client).clearRealmCache(req, new NodesResponseRestListener<>(channel)); } } diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java index b3b8f959560..1c142f6f90a 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/rest/action/role/RestClearRolesCacheAction.java @@ -8,18 +8,12 @@ package org.elasticsearch.shield.rest.action.role; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.action.support.RestBuilderListener; +import org.elasticsearch.rest.action.support.RestActions.NodesResponseRestListener; import org.elasticsearch.shield.action.role.ClearRolesCacheRequest; -import org.elasticsearch.shield.action.role.ClearRolesCacheResponse; import org.elasticsearch.shield.client.SecurityClient; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -42,15 +36,6 @@ public class RestClearRolesCacheAction extends BaseRestHandler { ClearRolesCacheRequest req = new ClearRolesCacheRequest().names(roles); - new SecurityClient(client).clearRolesCache(req, new RestBuilderListener(channel) { - @Override - public RestResponse buildResponse(ClearRolesCacheResponse response, XContentBuilder builder) throws Exception { - builder.startObject(); - response.toXContent(builder, ToXContent.EMPTY_PARAMS); - builder.endObject(); - - return new BytesRestResponse(RestStatus.OK, builder); - } - }); + new SecurityClient(client).clearRolesCache(req, new NodesResponseRestListener<>(channel)); } } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRealmsCacheTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRealmsCacheTests.java index 070f7c7eb44..303b3e90ca0 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRealmsCacheTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/ClearRealmsCacheTests.java @@ -147,7 +147,7 @@ public class ClearRealmsCacheTests extends ShieldIntegTestCase { securityClient.clearRealmCache(request, new ActionListener() { @Override public void onResponse(ClearRealmCacheResponse response) { - assertThat(response.getNodes().length, equalTo(internalCluster().getNodeNames().length)); + assertThat(response.getNodes().size(), equalTo(internalCluster().getNodeNames().length)); latch.countDown(); } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/RemoteIndexAuditTrailStartingTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/RemoteIndexAuditTrailStartingTests.java index 5f7df4fbe55..d0bc8f7bb5a 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/RemoteIndexAuditTrailStartingTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/RemoteIndexAuditTrailStartingTests.java @@ -82,7 +82,7 @@ public class RemoteIndexAuditTrailStartingTests extends ShieldIntegTestCase { final List addresses = new ArrayList<>(); // get addresses for current cluster NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().execute().actionGet(); - final String clusterName = response.getClusterNameAsString(); + final String clusterName = response.getClusterName().value(); for (NodeInfo nodeInfo : response.getNodes()) { InetSocketTransportAddress address = (InetSocketTransportAddress) nodeInfo.getTransport().address().publishAddress(); addresses.add(address.address().getHostString() + ":" + address.address().getPort()); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/RunAsIntegTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/RunAsIntegTests.java index b43a7465b17..5da10e734b3 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/RunAsIntegTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/RunAsIntegTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.xpack.XPackPlugin; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import static org.hamcrest.Matchers.containsString; @@ -207,10 +208,10 @@ public class RunAsIntegTests extends ShieldIntegTestCase { // build our own here to better mimic an actual client... TransportClient getTransportClient(Settings extraSettings) { NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get(); - NodeInfo[] nodes = nodeInfos.getNodes(); - assertTrue(nodes.length > 0); + List nodes = nodeInfos.getNodes(); + assertTrue(nodes.isEmpty() == false); TransportAddress publishAddress = randomFrom(nodes).getTransport().address().publishAddress(); - String clusterName = nodeInfos.getClusterNameAsString(); + String clusterName = nodeInfos.getClusterName().value(); Settings settings = Settings.builder() .put(extraSettings) diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldIntegTestCase.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldIntegTestCase.java index 8e137009f49..0b7f24a04ff 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldIntegTestCase.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldIntegTestCase.java @@ -140,7 +140,7 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase { //before methods from the superclass are run before this, which means that the current cluster is ready to go public void assertShieldIsInstalled() { NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().setPlugins(true).get(); - for (NodeInfo nodeInfo : nodeInfos) { + for (NodeInfo nodeInfo : nodeInfos.getNodes()) { // TODO: disable this assertion for now, due to random runs with mock plugins. perhaps run without mock plugins? // assertThat(nodeInfo.getPlugins().getInfos(), hasSize(2)); Collection pluginNames = diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginDisableTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginDisableTests.java index 005786d48e8..54d266b47fa 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginDisableTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginDisableTests.java @@ -81,7 +81,7 @@ public class WatcherPluginDisableTests extends ESIntegTestCase { public void testThreadPools() throws Exception { NodesInfoResponse nodesInfo = client().admin().cluster().prepareNodesInfo().setThreadPool(true).get(); - for (NodeInfo nodeInfo : nodesInfo) { + for (NodeInfo nodeInfo : nodesInfo.getNodes()) { ThreadPoolInfo threadPoolInfo = nodeInfo.getThreadPool(); for (ThreadPool.Info info : threadPoolInfo) { assertThat(info.getName(), not(is(InternalWatchExecutor.THREAD_POOL_NAME))); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java index 379fcd91f8a..ff75b1bf78a 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java @@ -165,7 +165,7 @@ public class WatcherScheduleEngineBenchmark { try { while (start.get()) { NodesStatsResponse response = client.admin().cluster().prepareNodesStats("_master").setJvm(true).get(); - ByteSizeValue heapUsed = response.getNodes()[0].getJvm().getMem().getHeapUsed(); + ByteSizeValue heapUsed = response.getNodes().get(0).getJvm().getMem().getHeapUsed(); jvmUsedHeapSpace.inc(heapUsed.bytes()); Thread.sleep(1000); } @@ -179,7 +179,7 @@ public class WatcherScheduleEngineBenchmark { sampleThread.join(); NodesStatsResponse response = client.admin().cluster().prepareNodesStats().setThreadPool(true).get(); - for (NodeStats nodeStats : response) { + for (NodeStats nodeStats : response.getNodes()) { for (ThreadPoolStats.Stats threadPoolStats : nodeStats.getThreadPool()) { if ("watcher".equals(threadPoolStats.getName())) { stats.setWatcherThreadPoolStats(threadPoolStats); From fd62b2308e76512a1499e2542b98969b16439666 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Thu, 5 May 2016 19:01:03 -0400 Subject: [PATCH 12/13] Updating with ES-side abstract method addition Original commit: elastic/x-pack-elasticsearch@0d075b433bc8ba66ebe5e6fd322c9b2beaac3208 --- .../shield/action/realm/ClearRealmCacheResponse.java | 8 +++----- .../shield/action/role/ClearRolesCacheResponse.java | 8 +++----- .../shield/audit/index/IndexAuditTrailTests.java | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java index 04dc2a26e34..6060fae653a 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/realm/ClearRealmCacheResponse.java @@ -32,14 +32,12 @@ public class ClearRealmCacheResponse extends BaseNodesResponse readNodesFrom(StreamInput in) throws IOException { + return in.readList(Node::readNodeResponse); } @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); + protected void writeNodesTo(StreamOutput out, List nodes) throws IOException { out.writeStreamableList(nodes); } diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java index 88cd1477689..9b2c1d92e5b 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/role/ClearRolesCacheResponse.java @@ -32,14 +32,12 @@ public class ClearRolesCacheResponse extends BaseNodesResponse readNodesFrom(StreamInput in) throws IOException { + return in.readList(Node::readNodeResponse); } @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); + protected void writeNodesTo(StreamOutput out, List nodes) throws IOException { out.writeStreamableList(nodes); } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java index ecb6cb00ea4..c75a3487fd2 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java @@ -146,7 +146,7 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase { remoteCluster.beforeTest(random(), 0.5); NodesInfoResponse response = remoteCluster.client().admin().cluster().prepareNodesInfo().execute().actionGet(); - TransportInfo info = response.getNodes()[0].getTransport(); + TransportInfo info = response.getNodes().get(0).getTransport(); InetSocketTransportAddress inet = (InetSocketTransportAddress) info.address().publishAddress(); Settings.Builder builder = Settings.builder() From 68728e6bee779371cf0ba9d1c782bd6e6fc2b927 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Fri, 6 May 2016 15:08:40 -0400 Subject: [PATCH 13/13] Use Strict version check for VersionCompatibilityTests This changes the loose usage of onOrBefore to equals so that when we add beta1, this test fails again. Original commit: elastic/x-pack-elasticsearch@fe4f2cbdf0e8658833dd945a3049bb1bd9737b73 --- .../org/elasticsearch/shield/VersionCompatibilityTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/VersionCompatibilityTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/VersionCompatibilityTests.java index 6117701d4a8..b7ddf644024 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/VersionCompatibilityTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/VersionCompatibilityTests.java @@ -37,6 +37,6 @@ public class VersionCompatibilityTests extends ESTestCase { * */ assertThat("Remove workaround in LicenseService class when es core supports merging cluster level custom metadata", - Version.CURRENT.onOrBefore(Version.V_5_0_0_alpha2), is(true)); + Version.CURRENT.equals(Version.V_5_0_0), is(true)); } }