-
Notifications
You must be signed in to change notification settings - Fork 4.5k
SolaceIO: refactor to allow inheritance of BasicAuthSempClient #32400
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
Merged
Abacn
merged 5 commits into
apache:master
from
bzablocki:multiple-semp-refactor-and-example
Nov 27, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
262b6df
Refactored to allow inheritance and overriding of BasicAuthSempClient
bzablocki 94af14f
Fix docs and use Map#computeIfAbsent with a lambda.
bzablocki eba116e
Fix integration test
bzablocki a0a4d3d
Remove 'serializable'
bzablocki 78f04ba
Revert 'Remove 'serializable''
bzablocki 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 hidden or 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 hidden or 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 hidden or 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
62 changes: 62 additions & 0 deletions
62
...io/solace/src/test/java/org/apache/beam/sdk/io/solace/it/BasicAuthMultipleSempClient.java
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * 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.beam.sdk.io.solace.it; | ||
|
|
||
| import com.google.api.client.http.HttpRequestFactory; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.beam.sdk.io.solace.broker.BasicAuthSempClient; | ||
| import org.apache.beam.sdk.io.solace.broker.SempBasicAuthClientExecutor; | ||
| import org.apache.beam.sdk.util.SerializableSupplier; | ||
|
|
||
| /** | ||
| * Example class showing how the {@link BasicAuthSempClient} can be extended or have functionalities | ||
| * overridden. In this case, the modified method is {@link | ||
| * BasicAuthSempClient#getBacklogBytes(String)}, which queries multiple SEMP endpoints to collect | ||
| * accurate backlog metrics. For usage, see {@link SolaceIOMultipleSempIT}. | ||
| */ | ||
| public class BasicAuthMultipleSempClient extends BasicAuthSempClient { | ||
| private final List<SempBasicAuthClientExecutor> sempBacklogBasicAuthClientExecutors; | ||
|
|
||
| public BasicAuthMultipleSempClient( | ||
| String mainHost, | ||
| List<String> backlogHosts, | ||
| String username, | ||
| String password, | ||
| String vpnName, | ||
| SerializableSupplier<HttpRequestFactory> httpRequestFactorySupplier) { | ||
| super(mainHost, username, password, vpnName, httpRequestFactorySupplier); | ||
| sempBacklogBasicAuthClientExecutors = | ||
| backlogHosts.stream() | ||
| .map( | ||
| host -> | ||
| new SempBasicAuthClientExecutor( | ||
| host, username, password, vpnName, httpRequestFactorySupplier.get())) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| @Override | ||
| public long getBacklogBytes(String queueName) throws IOException { | ||
| long backlog = 0; | ||
| for (SempBasicAuthClientExecutor client : sempBacklogBasicAuthClientExecutors) { | ||
| backlog += client.getBacklogBytes(queueName); | ||
| } | ||
| return backlog; | ||
| } | ||
| } |
92 changes: 92 additions & 0 deletions
92
...ce/src/test/java/org/apache/beam/sdk/io/solace/it/BasicAuthMultipleSempClientFactory.java
This file contains hidden or 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,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.beam.sdk.io.solace.it; | ||
|
|
||
| import com.google.api.client.http.HttpRequestFactory; | ||
| import com.google.api.client.http.javanet.NetHttpTransport; | ||
| import com.google.auto.value.AutoValue; | ||
| import java.util.List; | ||
| import org.apache.beam.sdk.io.solace.broker.SempClient; | ||
| import org.apache.beam.sdk.io.solace.broker.SempClientFactory; | ||
| import org.apache.beam.sdk.util.SerializableSupplier; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| /** | ||
| * Example class showing how to implement a custom {@link SempClientFactory} with custom client. For | ||
| * usage, see {@link SolaceIOMultipleSempIT}. | ||
| */ | ||
| @AutoValue | ||
| public abstract class BasicAuthMultipleSempClientFactory implements SempClientFactory { | ||
|
|
||
| public abstract String mainHost(); | ||
|
|
||
| public abstract List<String> backlogHosts(); | ||
|
|
||
| public abstract String username(); | ||
|
|
||
| public abstract String password(); | ||
|
|
||
| public abstract String vpnName(); | ||
|
|
||
| public abstract @Nullable SerializableSupplier<HttpRequestFactory> httpRequestFactorySupplier(); | ||
|
|
||
| public static Builder builder() { | ||
| return new AutoValue_BasicAuthMultipleSempClientFactory.Builder(); | ||
| } | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| /** Set Solace host, format: [Protocol://]Host[:Port]. */ | ||
| public abstract Builder mainHost(String host); | ||
|
|
||
| public abstract Builder backlogHosts(List<String> hosts); | ||
|
|
||
| /** Set Solace username. */ | ||
| public abstract Builder username(String username); | ||
| /** Set Solace password. */ | ||
| public abstract Builder password(String password); | ||
|
|
||
| /** Set Solace vpn name. */ | ||
| public abstract Builder vpnName(String vpnName); | ||
|
|
||
| abstract Builder httpRequestFactorySupplier( | ||
| SerializableSupplier<HttpRequestFactory> httpRequestFactorySupplier); | ||
|
|
||
| public abstract BasicAuthMultipleSempClientFactory build(); | ||
| } | ||
|
|
||
| @Override | ||
| public SempClient create() { | ||
| return new BasicAuthMultipleSempClient( | ||
| mainHost(), | ||
| backlogHosts(), | ||
| username(), | ||
| password(), | ||
| vpnName(), | ||
| getHttpRequestFactorySupplier()); | ||
| } | ||
|
|
||
| @SuppressWarnings("return") | ||
| private @NonNull SerializableSupplier<HttpRequestFactory> getHttpRequestFactorySupplier() { | ||
| SerializableSupplier<HttpRequestFactory> httpRequestSupplier = httpRequestFactorySupplier(); | ||
| return httpRequestSupplier != null | ||
| ? httpRequestSupplier | ||
| : () -> new NetHttpTransport().createRequestFactory(); | ||
| } | ||
| } |
Oops, something went wrong.
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.
This class doesn't need to be serialized, right?
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.
Can we leave it out for a separate PR?
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.
That's fine if this class isn't part of the public API, otherwise I'd fix it right now before users somehow introduce a dependency on the premise of serializability of this class.
Uh oh!
There was an error while loading. Please reload this page.
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.
Removed, done.
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.
Edit, the tests are failing now. I think it has to be serializable, as this is a field in SempClient, which has to be serializable. I'll revert the changes
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.
Ack, LGTM then.