diff --git a/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceInstancesServiceImpl.java b/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceInstancesServiceImpl.java index c91797761e9..5ec4b18e910 100644 --- a/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceInstancesServiceImpl.java +++ b/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceInstancesServiceImpl.java @@ -148,7 +148,7 @@ public class GceInstancesServiceImpl extends AbstractLifecycleComponent implemen // Forcing Google Token API URL as set in GCE SDK to // http://metadata/computeMetadata/v1/instance/service-accounts/default/token // See https://developers.google.com/compute/docs/metadata#metadataserver - String tokenServerEncodedUrl = GceMetadataServiceImpl.GCE_HOST.get(settings) + + String tokenServerEncodedUrl = GceMetadataService.GCE_HOST.get(settings) + "/computeMetadata/v1/instance/service-accounts/default/token"; ComputeCredential credential = new ComputeCredential.Builder(getGceHttpTransport(), gceJsonFactory) .setTokenServerEncodedUrl(tokenServerEncodedUrl) diff --git a/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceMetadataServiceImpl.java b/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceMetadataService.java similarity index 97% rename from plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceMetadataServiceImpl.java rename to plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceMetadataService.java index 3babedd7b68..25b7cf72c92 100644 --- a/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceMetadataServiceImpl.java +++ b/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceMetadataService.java @@ -41,7 +41,7 @@ import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; import java.util.function.Function; -public class GceMetadataServiceImpl extends AbstractLifecycleComponent { +public class GceMetadataService extends AbstractLifecycleComponent { // Forcing Google Token API URL as set in GCE SDK to // http://metadata/computeMetadata/v1/instance/service-accounts/default/token @@ -54,7 +54,7 @@ public class GceMetadataServiceImpl extends AbstractLifecycleComponent { private HttpTransport gceHttpTransport; @Inject - public GceMetadataServiceImpl(Settings settings) { + public GceMetadataService(Settings settings) { super(settings); } diff --git a/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/network/GceNameResolver.java b/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/network/GceNameResolver.java index a244b7f57de..54f96a971ca 100644 --- a/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/network/GceNameResolver.java +++ b/plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/network/GceNameResolver.java @@ -19,7 +19,7 @@ package org.elasticsearch.cloud.gce.network; -import org.elasticsearch.cloud.gce.GceMetadataServiceImpl; +import org.elasticsearch.cloud.gce.GceMetadataService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.network.NetworkService.CustomNameResolver; @@ -41,7 +41,7 @@ import java.net.URISyntaxException; */ public class GceNameResolver extends AbstractComponent implements CustomNameResolver { - private final GceMetadataServiceImpl gceMetadataService; + private final GceMetadataService gceMetadataService; /** * enum that can be added to over time with more meta-data types @@ -73,7 +73,7 @@ public class GceNameResolver extends AbstractComponent implements CustomNameReso /** * Construct a {@link CustomNameResolver}. */ - public GceNameResolver(Settings settings, GceMetadataServiceImpl gceMetadataService) { + public GceNameResolver(Settings settings, GceMetadataService gceMetadataService) { super(settings); this.gceMetadataService = gceMetadataService; } diff --git a/plugins/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java b/plugins/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java index 801ca906b13..031f7eaf10f 100644 --- a/plugins/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java +++ b/plugins/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java @@ -23,18 +23,16 @@ import com.google.api.client.http.HttpHeaders; import com.google.api.client.util.ClassInfo; import org.elasticsearch.SpecialPermission; import org.elasticsearch.cloud.gce.GceInstancesService; -import org.elasticsearch.cloud.gce.GceMetadataServiceImpl; +import org.elasticsearch.cloud.gce.GceMetadataService; import org.elasticsearch.cloud.gce.GceModule; import org.elasticsearch.cloud.gce.network.GceNameResolver; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.gce.GceUnicastHostsProvider; import org.elasticsearch.discovery.zen.ZenDiscovery; @@ -105,7 +103,7 @@ public class GceDiscoveryPlugin extends Plugin implements DiscoveryPlugin { @Override public NetworkService.CustomNameResolver getCustomNameResolver(Settings settings) { logger.debug("Register _gce_, _gce:xxx network names"); - return new GceNameResolver(settings, new GceMetadataServiceImpl(settings)); + return new GceNameResolver(settings, new GceMetadataService(settings)); } @Override diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java index a1d8b3e4397..ef308ac886b 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java @@ -24,14 +24,13 @@ import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsServer; import org.elasticsearch.cloud.gce.GceInstancesServiceImpl; -import org.elasticsearch.cloud.gce.GceMetadataServiceImpl; +import org.elasticsearch.cloud.gce.GceMetadataService; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.plugin.discovery.gce.GceDiscoveryPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; @@ -68,7 +67,7 @@ public class GceDiscoverTests extends ESIntegTestCase { public static class TestPlugin extends Plugin { @Override public List> getSettings() { - return Arrays.asList(GceMetadataServiceImpl.GCE_HOST, GceInstancesServiceImpl.GCE_ROOT_URL, + return Arrays.asList(GceMetadataService.GCE_HOST, GceInstancesServiceImpl.GCE_ROOT_URL, GceInstancesServiceImpl.GCE_VALIDATE_CERTIFICATES); } } diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java index 3cc99cb8c23..08e7ee963d3 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java @@ -20,8 +20,7 @@ package org.elasticsearch.discovery.gce; import org.elasticsearch.Version; -import org.elasticsearch.cloud.gce.GceInstancesService; -import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.cloud.gce.GceInstancesServiceImpl; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; @@ -68,7 +67,7 @@ public class GceDiscoveryTests extends ESTestCase { protected static ThreadPool threadPool; protected MockTransportService transportService; - protected GceInstancesService mock; + protected GceInstancesServiceMock mock; protected String projectName; @BeforeClass @@ -105,7 +104,7 @@ public class GceDiscoveryTests extends ESTestCase { } } - protected List buildDynamicNodes(GceInstancesService gceInstancesService, Settings nodeSettings) { + protected List buildDynamicNodes(GceInstancesServiceImpl gceInstancesService, Settings nodeSettings) { GceUnicastHostsProvider provider = new GceUnicastHostsProvider(nodeSettings, gceInstancesService, transportService, new NetworkService(Settings.EMPTY, Collections.emptyList())); @@ -116,8 +115,8 @@ public class GceDiscoveryTests extends ESTestCase { public void testNodesWithDifferentTagsAndNoTagSet() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .put(GceInstancesService.ZONE_SETTING.getKey(), "europe-west1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b") .build(); mock = new GceInstancesServiceMock(nodeSettings); List discoveryNodes = buildDynamicNodes(mock, nodeSettings); @@ -126,8 +125,8 @@ public class GceDiscoveryTests extends ESTestCase { public void testNodesWithDifferentTagsAndOneTagSet() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .put(GceInstancesService.ZONE_SETTING.getKey(), "europe-west1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b") .putArray(GceUnicastHostsProvider.TAGS_SETTING.getKey(), "elasticsearch") .build(); mock = new GceInstancesServiceMock(nodeSettings); @@ -138,8 +137,8 @@ public class GceDiscoveryTests extends ESTestCase { public void testNodesWithDifferentTagsAndTwoTagSet() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .put(GceInstancesService.ZONE_SETTING.getKey(), "europe-west1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b") .putArray(GceUnicastHostsProvider.TAGS_SETTING.getKey(), "elasticsearch", "dev") .build(); mock = new GceInstancesServiceMock(nodeSettings); @@ -150,8 +149,8 @@ public class GceDiscoveryTests extends ESTestCase { public void testNodesWithSameTagsAndNoTagSet() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .put(GceInstancesService.ZONE_SETTING.getKey(), "europe-west1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b") .build(); mock = new GceInstancesServiceMock(nodeSettings); List discoveryNodes = buildDynamicNodes(mock, nodeSettings); @@ -160,8 +159,8 @@ public class GceDiscoveryTests extends ESTestCase { public void testNodesWithSameTagsAndOneTagSet() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .put(GceInstancesService.ZONE_SETTING.getKey(), "europe-west1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b") .putArray(GceUnicastHostsProvider.TAGS_SETTING.getKey(), "elasticsearch") .build(); mock = new GceInstancesServiceMock(nodeSettings); @@ -171,8 +170,8 @@ public class GceDiscoveryTests extends ESTestCase { public void testNodesWithSameTagsAndTwoTagsSet() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .put(GceInstancesService.ZONE_SETTING.getKey(), "europe-west1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .put(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b") .putArray(GceUnicastHostsProvider.TAGS_SETTING.getKey(), "elasticsearch", "dev") .build(); mock = new GceInstancesServiceMock(nodeSettings); @@ -182,8 +181,8 @@ public class GceDiscoveryTests extends ESTestCase { public void testMultipleZonesAndTwoNodesInSameZone() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .putArray(GceInstancesService.ZONE_SETTING.getKey(), "us-central1-a", "europe-west1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .putArray(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "us-central1-a", "europe-west1-b") .build(); mock = new GceInstancesServiceMock(nodeSettings); List discoveryNodes = buildDynamicNodes(mock, nodeSettings); @@ -192,8 +191,8 @@ public class GceDiscoveryTests extends ESTestCase { public void testMultipleZonesAndTwoNodesInDifferentZones() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .putArray(GceInstancesService.ZONE_SETTING.getKey(), "us-central1-a", "europe-west1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .putArray(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "us-central1-a", "europe-west1-b") .build(); mock = new GceInstancesServiceMock(nodeSettings); List discoveryNodes = buildDynamicNodes(mock, nodeSettings); @@ -205,8 +204,8 @@ public class GceDiscoveryTests extends ESTestCase { */ public void testZeroNode43() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .putArray(GceInstancesService.ZONE_SETTING.getKey(), "us-central1-a", "us-central1-b") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .putArray(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "us-central1-a", "us-central1-b") .build(); mock = new GceInstancesServiceMock(nodeSettings); List discoveryNodes = buildDynamicNodes(mock, nodeSettings); @@ -226,7 +225,7 @@ public class GceDiscoveryTests extends ESTestCase { public void testIllegalSettingsMissingProject() { Settings nodeSettings = Settings.builder() - .putArray(GceInstancesService.ZONE_SETTING.getKey(), "us-central1-a", "us-central1-b") + .putArray(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "us-central1-a", "us-central1-b") .build(); mock = new GceInstancesServiceMock(nodeSettings); try { @@ -239,7 +238,7 @@ public class GceDiscoveryTests extends ESTestCase { public void testIllegalSettingsMissingZone() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) .build(); mock = new GceInstancesServiceMock(nodeSettings); try { @@ -257,8 +256,8 @@ public class GceDiscoveryTests extends ESTestCase { */ public void testNoRegionReturnsEmptyList() { Settings nodeSettings = Settings.builder() - .put(GceInstancesService.PROJECT_SETTING.getKey(), projectName) - .putArray(GceInstancesService.ZONE_SETTING.getKey(), "europe-west1-b", "us-central1-a") + .put(GceInstancesServiceImpl.PROJECT_SETTING.getKey(), projectName) + .putArray(GceInstancesServiceImpl.ZONE_SETTING.getKey(), "europe-west1-b", "us-central1-a") .build(); mock = new GceInstancesServiceMock(nodeSettings); List discoveryNodes = buildDynamicNodes(mock, nodeSettings); diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceMetadataServiceMock.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceMetadataServiceMock.java index dec0531801a..58c50f47a1f 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceMetadataServiceMock.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceMetadataServiceMock.java @@ -20,8 +20,7 @@ package org.elasticsearch.discovery.gce; import com.google.api.client.http.HttpTransport; -import org.elasticsearch.cloud.gce.GceMetadataServiceImpl; -import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.cloud.gce.GceMetadataService; import org.elasticsearch.common.settings.Settings; import java.io.IOException; @@ -30,7 +29,7 @@ import java.security.GeneralSecurityException; /** * Mock for GCE Metadata Service */ -public class GceMetadataServiceMock extends GceMetadataServiceImpl { +public class GceMetadataServiceMock extends GceMetadataService { protected HttpTransport mockHttpTransport;