-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable service discovery in controller too #8193
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.pinot.controller.api.resources; | ||
|
||
import io.swagger.annotations.Api; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import org.apache.pinot.core.api.AutoLoadedServiceForTest; | ||
|
||
|
||
/** | ||
* This class is a typical "echo" service that will return whatever string you call GET with a path. | ||
* It is both an integration test and a demonstration of how to dynamically add an endpoint to broker, | ||
* create auto-service discovery | ||
*/ | ||
@Api(tags = "Test") | ||
@Path("/test") | ||
public class ControllerEchoWithAutoDiscovery { | ||
@Inject | ||
public AutoLoadedServiceForTest _injectedService; | ||
@GET | ||
@Path("/echo/{table}") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String echo(@PathParam("table") String table) { | ||
return _injectedService.echo(table); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.integration.tests; | ||
|
||
import java.util.Map; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.pinot.spi.env.PinotConfiguration; | ||
import org.apache.pinot.spi.utils.CommonConstants; | ||
import org.apache.pinot.util.TestUtils; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
/** | ||
* Integration test that starts one broker with auto-discovered echo service and test it | ||
*/ | ||
public class ControllerServiceDiscoveryIntegrationTest extends BaseClusterIntegrationTestSet { | ||
private static final String TENANT_NAME = "TestTenant"; | ||
|
||
@Override | ||
protected String getBrokerTenant() { | ||
return TENANT_NAME; | ||
} | ||
|
||
@Override | ||
protected String getServerTenant() { | ||
return TENANT_NAME; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getDefaultControllerConfiguration() { | ||
Map<String, Object> retVal = super.getDefaultControllerConfiguration(); | ||
retVal.put(CommonConstants.Controller.CONTROLLER_SERVICE_AUTO_DISCOVERY, true); | ||
return retVal; | ||
} | ||
|
||
@Override | ||
protected PinotConfiguration getDefaultBrokerConfiguration() { | ||
PinotConfiguration config = new PinotConfiguration(); | ||
config.setProperty(CommonConstants.Broker.BROKER_SERVICE_AUTO_DISCOVERY, true); | ||
return config; | ||
} | ||
|
||
@BeforeClass | ||
public void setUp() | ||
throws Exception { | ||
TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir); | ||
|
||
// Start the Pinot cluster | ||
startZk(); | ||
startController(); | ||
startBrokers(1); | ||
startServers(1); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m surprised the linter passed, there should be a blank line here. We will need to check if checkstyle can catch this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You triggered my OCD... |
||
@AfterClass | ||
public void tearDown() | ||
throws Exception { | ||
|
||
// Brokers and servers has been stopped | ||
stopBroker(); | ||
stopController(); | ||
stopZk(); | ||
FileUtils.deleteDirectory(_tempDir); | ||
} | ||
|
||
@Test | ||
public void testControllerExtraEndpointsAutoLoaded() | ||
throws Exception { | ||
String response = sendGetRequest(_controllerBaseApiUrl + "/test/echo/doge"); | ||
Assert.assertEquals(response, "doge"); | ||
response = sendGetRequest(_brokerBaseApiUrl + "/test/echo/doge"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xiangfu0 the test here will fail if we do initialization only once |
||
Assert.assertEquals(response, "doge"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if we have PinotServiceManager deploying controller/broker/server in the same JVM and all of them trying to load this
ServiceAutoDiscoveryFeature
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very good point. I added some code (static boolean) to make sure discovery is done once per JVM, and did the integration test that starts Broker+Controller in the same test.
The result shows that only one of the Broker/Controller can find service properly.
It seems that based on Jersey, Services/Features are isolated per
Application
(tied to ResourceConfig) level, so if there are two applications, the discovery has to be done twice.