-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Verify management client #11106
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
Verify management client #11106
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 |
|---|---|---|
|
|
@@ -3,22 +3,15 @@ | |
|
|
||
| package com.microsoft.azure.servicebus.management; | ||
|
|
||
| import com.microsoft.azure.servicebus.ClientSettings; | ||
| import com.microsoft.azure.servicebus.Utils; | ||
| import com.microsoft.azure.servicebus.primitives.AuthorizationFailedException; | ||
| import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder; | ||
| import com.microsoft.azure.servicebus.primitives.MessagingEntityAlreadyExistsException; | ||
| import com.microsoft.azure.servicebus.primitives.MessagingEntityNotFoundException; | ||
| import com.microsoft.azure.servicebus.primitives.QuotaExceededException; | ||
| import com.microsoft.azure.servicebus.primitives.ServerBusyException; | ||
| import com.microsoft.azure.servicebus.primitives.ServiceBusException; | ||
| import com.microsoft.azure.servicebus.primitives.TimeoutException; | ||
| import com.microsoft.azure.servicebus.primitives.Util; | ||
| import com.microsoft.azure.servicebus.*; | ||
|
Member
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. Star imports are not allowed. You may have to update IntelliJ to not change it to a star import. |
||
| import com.microsoft.azure.servicebus.primitives.*; | ||
| import com.microsoft.azure.servicebus.rules.RuleDescription; | ||
|
|
||
| import java.io.IOException; | ||
| import org.asynchttpclient.DefaultAsyncHttpClientConfig; | ||
| import java.net.URI; | ||
| import java.util.List; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| /** | ||
| * Synchronous client to perform management operations on Service Bus entities. | ||
|
|
@@ -27,14 +20,18 @@ | |
| public class ManagementClient { | ||
| private ManagementClientAsync asyncClient; | ||
|
|
||
| public ManagementClient(ConnectionStringBuilder connectionStringBuilder) { | ||
| public ManagementClient(ConnectionStringBuilder connectionStringBuilder) throws InterruptedException, ServiceBusException { | ||
|
Member
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. Since this is an existing public-facing API, this will break existing customers. You could catch the checked exceptions and throw an unchecked one to main compat. |
||
| this(connectionStringBuilder.getEndpoint(), Util.getClientSettingsFromConnectionStringBuilder(connectionStringBuilder)); | ||
| } | ||
|
|
||
| public ManagementClient(URI namespaceEndpointURI, ClientSettings clientSettings) { | ||
| public ManagementClient(URI namespaceEndpointURI, ClientSettings clientSettings) throws InterruptedException, ServiceBusException { | ||
| this.asyncClient = new ManagementClientAsync(namespaceEndpointURI, clientSettings); | ||
| } | ||
|
|
||
| public ManagementClient(URI namespaceEndpointURI, ClientSettings clientSettings, DefaultAsyncHttpClientConfig.Builder httpClientBuilder) { | ||
| this.asyncClient = new ManagementClientAsync(namespaceEndpointURI, clientSettings, httpClientBuilder); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves information related to the namespace. | ||
| * Works with any claim (Send/Listen/Manage). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,17 +3,8 @@ | |
|
|
||
| package com.microsoft.azure.servicebus.management; | ||
|
|
||
| import com.microsoft.azure.servicebus.ClientSettings; | ||
| import com.microsoft.azure.servicebus.primitives.AuthorizationFailedException; | ||
| import com.microsoft.azure.servicebus.primitives.ClientConstants; | ||
| import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder; | ||
| import com.microsoft.azure.servicebus.primitives.MessagingEntityAlreadyExistsException; | ||
| import com.microsoft.azure.servicebus.primitives.MessagingEntityNotFoundException; | ||
| import com.microsoft.azure.servicebus.primitives.MessagingFactory; | ||
| import com.microsoft.azure.servicebus.primitives.QuotaExceededException; | ||
| import com.microsoft.azure.servicebus.primitives.ServerBusyException; | ||
| import com.microsoft.azure.servicebus.primitives.ServiceBusException; | ||
| import com.microsoft.azure.servicebus.primitives.Util; | ||
| import com.microsoft.azure.servicebus.*; | ||
| import com.microsoft.azure.servicebus.primitives.*; | ||
| import com.microsoft.azure.servicebus.rules.RuleDescription; | ||
| import com.microsoft.azure.servicebus.security.SecurityToken; | ||
| import com.microsoft.azure.servicebus.security.TokenProvider; | ||
|
|
@@ -24,6 +15,7 @@ | |
| import org.asynchttpclient.Request; | ||
| import org.asynchttpclient.RequestBuilder; | ||
| import org.asynchttpclient.Response; | ||
| import org.asynchttpclient.proxy.ProxyServer; | ||
| import org.asynchttpclient.util.HttpConstants; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -38,10 +30,7 @@ | |
| import javax.xml.parsers.ParserConfigurationException; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.io.IOException; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.net.URL; | ||
| import java.net.*; | ||
|
Member
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. Remove star imports. |
||
| import java.time.Duration; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
|
|
@@ -68,15 +57,18 @@ public class ManagementClientAsync { | |
| private static final String USER_AGENT = String.format("%s/%s(%s)", ClientConstants.PRODUCT_NAME, ClientConstants.CURRENT_JAVACLIENT_VERSION, ClientConstants.PLATFORM_INFO); | ||
|
|
||
| private ClientSettings clientSettings; | ||
| private MessagingFactory factory; | ||
| private URI namespaceEndpointURI; | ||
| private AsyncHttpClient asyncHttpClient; | ||
| private MiscRequestResponseOperationHandler miscRequestResponseHandler; | ||
| private List<Proxy> proxies; | ||
|
|
||
| /** | ||
| * Creates a new {@link ManagementClientAsync}. | ||
| * User should call {@link ManagementClientAsync#close()} at the end of life of the client. | ||
| * @param connectionStringBuilder - connectionStringBuilder containing namespace information and client settings. | ||
| */ | ||
| public ManagementClientAsync(ConnectionStringBuilder connectionStringBuilder) { | ||
| public ManagementClientAsync(ConnectionStringBuilder connectionStringBuilder) throws InterruptedException, ServiceBusException { | ||
| this(connectionStringBuilder.getEndpoint(), Util.getClientSettingsFromConnectionStringBuilder(connectionStringBuilder)); | ||
| } | ||
|
|
||
|
|
@@ -86,14 +78,93 @@ public ManagementClientAsync(ConnectionStringBuilder connectionStringBuilder) { | |
| * @param namespaceEndpointURI - URI of the namespace connecting to. | ||
| * @param clientSettings - client settings. | ||
| */ | ||
| public ManagementClientAsync(URI namespaceEndpointURI, ClientSettings clientSettings) { | ||
| // public ManagementClientAsync(URI namespaceEndpointURI, ClientSettings clientSettings) { | ||
|
Member
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. Remove dead code. |
||
| // this.namespaceEndpointURI = namespaceEndpointURI; | ||
| // this.clientSettings = clientSettings; | ||
| // DefaultAsyncHttpClientConfig.Builder clientBuilder = Dsl.config() | ||
| // .setConnectTimeout((int) CONNECTION_TIMEOUT.toMillis()) | ||
| // .setRequestTimeout((int) this.clientSettings.getOperationTimeout().toMillis()); | ||
| // this.asyncHttpClient = asyncHttpClient(clientBuilder); | ||
| // } | ||
|
|
||
| public ManagementClientAsync(URI namespaceEndpointURI, ClientSettings clientSettings, DefaultAsyncHttpClientConfig.Builder httpClientBuilder) { | ||
| this.namespaceEndpointURI = namespaceEndpointURI; | ||
|
Member
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. Should we consider any null checks to avoid inadvertent NPEs? (ie. Objects.requireNotNull)
Member
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. Same with the other public constructors. |
||
| this.clientSettings = clientSettings; | ||
| this.asyncHttpClient = asyncHttpClient(httpClientBuilder); | ||
| } | ||
|
|
||
| public ManagementClientAsync(URI namespaceEndpointURI, ClientSettings clientSettings) throws InterruptedException, ServiceBusException { | ||
| this.namespaceEndpointURI = namespaceEndpointURI; | ||
| this.clientSettings = clientSettings; | ||
| DefaultAsyncHttpClientConfig.Builder clientBuilder = Dsl.config() | ||
| .setConnectTimeout((int) CONNECTION_TIMEOUT.toMillis()) | ||
| .setRequestTimeout((int) this.clientSettings.getOperationTimeout().toMillis()); | ||
| .setConnectTimeout((int) CONNECTION_TIMEOUT.toMillis()) | ||
| .setRequestTimeout((int) this.clientSettings.getOperationTimeout().toMillis()); | ||
|
|
||
| if(shouldUseProxy(this.namespaceEndpointURI.getHost())){ | ||
| InetSocketAddress address = (InetSocketAddress)this.proxies.get(0).address(); | ||
| String proxyHostName = address.getHostName(); | ||
| int proxyPort = address.getPort(); | ||
| clientBuilder.setProxyServer(new ProxyServer.Builder(proxyHostName, proxyPort)); | ||
| } | ||
|
|
||
| this.asyncHttpClient = asyncHttpClient(clientBuilder); | ||
| // CompletableFuture<MessagingFactory> factoryFuture = MessagingFactory.createFromNamespaceEndpointURIAsync(namespaceEndpointURI, clientSettings); | ||
|
Member
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. Please remove all commented out code. It'll keep the code base clean. |
||
| // Utils.completeFuture(factoryFuture.thenComposeAsync((f) -> this.createInternals(f), MessagingFactory.INTERNAL_THREAD_POOL)); | ||
| // if (TRACE_LOGGER.isInfoEnabled()) { | ||
| // TRACE_LOGGER.info("Created management client '{}'", namespaceEndpointURI.toString()); | ||
| // } | ||
| } | ||
|
|
||
| public boolean shouldUseProxy(final String hostName) { | ||
| final URI uri = createURIFromHostNamePort(hostName, ClientConstants.HTTPS_PORT); | ||
| final ProxySelector proxySelector = ProxySelector.getDefault(); | ||
| if (proxySelector == null) { | ||
| return false; | ||
| } | ||
|
|
||
| final List<Proxy> proxies = proxySelector.select(uri); | ||
| if (isProxyAddressLegal(proxies)) { | ||
| this.proxies = proxies; | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private static URI createURIFromHostNamePort(final String hostName, final int port) { | ||
| return URI.create(String.format(ClientConstants.HTTPS_URI_FORMAT, hostName, port)); | ||
| } | ||
|
|
||
| private static boolean isProxyAddressLegal(final List<Proxy> proxies) { | ||
| // only checks the first proxy in the list | ||
| // returns true if it is an InetSocketAddress, which is required for qpid-proton-j library | ||
| return proxies != null | ||
| && !proxies.isEmpty() | ||
| && proxies.get(0).type() == Proxy.Type.HTTP | ||
| && proxies.get(0).address() != null | ||
| && proxies.get(0).address() instanceof InetSocketAddress; | ||
| } | ||
| private CompletableFuture<Void> createInternals(MessagingFactory factory) { | ||
| this.factory = factory; | ||
|
|
||
| CompletableFuture<Void> postSessionBrowserFuture = MiscRequestResponseOperationHandler.create(factory).thenAcceptAsync((msoh) -> { | ||
| this.miscRequestResponseHandler = msoh; | ||
| //this.sessionBrowser = new SessionBrowser(factory, queuePath, MessagingEntityType.QUEUE, msoh); | ||
| }, MessagingFactory.INTERNAL_THREAD_POOL); | ||
|
|
||
| return CompletableFuture.allOf(postSessionBrowserFuture); | ||
| } | ||
|
|
||
| // No op now | ||
| // @Override | ||
|
Member
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. Remove ded code |
||
| // CompletableFuture<Void> initializeAsync() { | ||
| // return CompletableFuture.completedFuture(null); | ||
| // } | ||
| // | ||
| // @Override | ||
| // protected CompletableFuture<Void> onClose() { | ||
| // return this.miscRequestResponseHandler.closeAsync().thenCompose((w) -> this.factory.closeAsync()); | ||
| // } | ||
|
|
||
| /** | ||
| * Retrieves information related to the namespace. | ||
|
|
||
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.
Hey, our versioning story is managed by a series of scripts to keep dependency versions aligned. Can you add this annotation and follow the instructions to update to the proper version?
https://github.com/Azure/azure-sdk-for-java/blob/master/CONTRIBUTING.md#versions-and-versioning
<!-- {x-version-update;org.apache.httpcomponents:httpclient;external_dependency} -->