-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add configuration for JMX base name #19
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
presto-hive/src/main/java/io/prestosql/plugin/hive/ConnectorObjectNameGeneratorModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Licensed 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 io.prestosql.plugin.hive; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.inject.Binder; | ||
import com.google.inject.Module; | ||
import com.google.inject.Provides; | ||
import io.airlift.configuration.Config; | ||
import org.weakref.jmx.ObjectNameBuilder; | ||
import org.weakref.jmx.ObjectNameGenerator; | ||
|
||
import java.util.Map; | ||
|
||
import static com.google.common.base.MoreObjects.firstNonNull; | ||
import static io.airlift.configuration.ConfigBinder.configBinder; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
// Note: There are multiple copies of this class in the codebase. If you change one you, should change them all. | ||
public class ConnectorObjectNameGeneratorModule | ||
implements Module | ||
{ | ||
private static final String CONNECTOR_PACKAGE_NAME = "io.prestosql.plugin.hive"; | ||
private static final String DEFAULT_DOMAIN_BASE = "presto.plugin.hive"; | ||
|
||
private final String catalogName; | ||
|
||
public ConnectorObjectNameGeneratorModule(String catalogName) | ||
{ | ||
this.catalogName = requireNonNull(catalogName, "catalogName is null"); | ||
} | ||
|
||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
configBinder(binder).bindConfig(ConnectorObjectNameGeneratorConfig.class); | ||
} | ||
|
||
@Provides | ||
ObjectNameGenerator createPrefixObjectNameGenerator(ConnectorObjectNameGeneratorConfig config) | ||
{ | ||
String domainBase = firstNonNull(config.getDomainBase(), DEFAULT_DOMAIN_BASE); | ||
return new ConnectorObjectNameGenerator(domainBase, catalogName); | ||
} | ||
|
||
public static class ConnectorObjectNameGeneratorConfig | ||
{ | ||
private String domainBase; | ||
|
||
public String getDomainBase() | ||
{ | ||
return domainBase; | ||
} | ||
|
||
@Config("jmx.base-name") | ||
public ConnectorObjectNameGeneratorConfig setDomainBase(String domainBase) | ||
{ | ||
this.domainBase = domainBase; | ||
return this; | ||
} | ||
} | ||
|
||
public static final class ConnectorObjectNameGenerator | ||
implements ObjectNameGenerator | ||
{ | ||
private final String domainBase; | ||
private final String catalogName; | ||
|
||
public ConnectorObjectNameGenerator(String domainBase, String catalogName) | ||
{ | ||
this.domainBase = domainBase; | ||
this.catalogName = catalogName; | ||
} | ||
|
||
@Override | ||
public String generatedNameOf(Class<?> type) | ||
{ | ||
return new ObjectNameBuilder(toDomain(type)) | ||
.withProperties(ImmutableMap.<String, String>builder() | ||
.put("type", type.getSimpleName()) | ||
.put("name", catalogName) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public String generatedNameOf(Class<?> type, Map<String, String> properties) | ||
{ | ||
return new ObjectNameBuilder(toDomain(type)) | ||
.withProperties(ImmutableMap.<String, String>builder() | ||
.putAll(properties) | ||
.put("catalog", catalogName) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
private String toDomain(Class<?> type) | ||
{ | ||
String domain = type.getPackage().getName(); | ||
if (domain.startsWith(CONNECTOR_PACKAGE_NAME)) { | ||
domain = domainBase + domain.substring(CONNECTOR_PACKAGE_NAME.length()); | ||
} | ||
return domain; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# WARNING | ||
# ^^^^^^^ | ||
# This configuration file is for development only and should NOT be used be | ||
# used in production. For example configuration, see the Presto documentation. | ||
# | ||
|
||
connector.name=presto-thrift | ||
presto.thrift.client.addresses=127.0.0.1:1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be based on, say, the package name of the Plugin class in this connector?