-
Notifications
You must be signed in to change notification settings - Fork 2k
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 convenience layer to generated code for Event Grid Track 2 #14442
Conversation
Autorest regenerated using up to date version for track 2 pom file incorporated to jacoco and dependencies for module handled issue around capitalization of etag discrepancy fixed no test coverage yet
Autorest regenerated using up to date version for track 2 pom file incorporated to jacoco and dependencies for module handled issue around capitalization of etag discrepancy fixed no test coverage yet
Autogenerate EventGrid track 2 classes using the swagger. All files except EventGridPublisherImplTests.java, pom.xml, and the swagger readme.md are autogenerated.
Convenience layer for EventGrid Track 2 on top of autogenerated code.
Add a few missing javadoc comments and remove a few comments from private methods.
test and pom edits mostly
52dcaf8
to
ecb6fe2
Compare
Drop explicit support for non-JSON data. Modify/fix tests slightly.
SharedAccessSignature -> SAS, refactor methods and classes
/azp run |
You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list. |
/azp run java - eventgrid - ci, java - eventgrid - ci (Build Test Windows - Java 11) |
Azure Pipelines successfully started running 1 pipeline(s). |
conforms to live test expected custom event properties
In order to start sending events, we need an `EventGridPublisherClient`. Here is code to | ||
create the synchronous and the asynchronous versions. Note that a shared access signature can | ||
be used instead of a key in any of these samples by calling the `sharedAccessSignatureCredential` | ||
method instead of `keyCredential'. |
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.
method instead of `keyCredential'. | |
method instead of `keyCredential`. |
public <T> T getData(Class<T> clazz, JsonSerializer dataDeserializer) { | ||
if (!parsed) { | ||
// data was set instead of parsed, throw exception because we don't know how the data relates to clazz | ||
throw new IllegalStateException("This method should only be called on events created through the parse method"); | ||
} | ||
|
||
return dataDeserializer.deserialize(new ByteArrayInputStream((byte[]) this.event.getData()), | ||
TypeReference.createInstance(clazz)); | ||
} |
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.
We should consider adding async overloads for these since dataDeserializer
supports async deserialization.
public EventGridServiceVersion getServiceVersion() { | ||
return EventGridServiceVersion.V2018_01_01; | ||
} |
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.
Instead of hardcoding the version here, the builder (since the builder should have a setter for service version) should pass this to the constructor and the client should use that as an instance variable that will be returned here.
return withContext(context -> publishEvents(events, context)); | ||
} | ||
|
||
Mono<Void> publishEvents(Iterable<EventGridEvent> events, Context context) { |
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.
Why is this called publish
? It's better to use the same terminology even for non-public methods.
List<com.azure.messaging.eventgrid.implementation.models.CloudEvent> implList = new ArrayList<>(); | ||
for (CloudEvent event : events) { | ||
implList.add(event.toImpl()); | ||
} |
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.
Converting to inner types should happen lazily when the Mono
is subscribed. Do the same at other places too where the list operations are performed eagerly.
* | ||
* @return the builder itself. | ||
*/ | ||
public EventGridPublisherClientBuilder keyCredential(AzureKeyCredential credential) { |
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.
The method should be named credential
to be consistent with other SDK builders.
return String.format("%s&%s=%s", unsignedSas, signKey, encodedSignature); | ||
|
||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) { | ||
e.printStackTrace(); |
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.
Use logs instead of e.printStackTrace()
.
*/ | ||
public EventGridSasCredential(String sas) { | ||
if (CoreUtils.isNullOrEmpty(sas)) { | ||
throw new IllegalArgumentException("the access signature cannot be null or empty"); |
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.
Log and throw.
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
public final class SystemEventMappings { |
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.
Missing javadoc.
import java.time.ZoneOffset; | ||
import java.util.Random; | ||
|
||
public class ClassTime { |
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.
Add javadocs for all samples to explain what the sample does.
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.
Overall, looks great and it's good to see all design guidelines being followed! Thanks @Soreloser2
import com.azure.core.annotation.Fluent; | ||
import com.azure.core.serializer.json.jackson.JacksonJsonSerializerBuilder; | ||
import com.azure.core.util.CoreUtils; | ||
import com.azure.core.util.serializer.*; |
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.
Generally I think we try to avoid * imports, I know I had to go dive into IntelliJ settings to make it stop doing this by default:
Settings > Editor > Code Style > Java > set both count to use import with '*' settings to 99.
public Object getData() { | ||
if (!parsed) { | ||
// data was set instead of parsed, throw error | ||
throw new IllegalStateException("This method should only be called on events created through the parse method"); |
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.
I think Srikanta already called this out, but instead of throwing directly, we should get a ClientLogger
instance and call throw logger.logExceptionAsWarning/Error(...)
instead.
@@ -0,0 +1,55 @@ | |||
package com.azure.messaging.eventgrid; |
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.
Make sure all source files have the copyright & license header.
Variety of changes, major ones include: - Async methods on generic getData - Lazy list creation for send methods - Credential methods both renamed to `credential` - Logging errors instead of throwing - Additional missing javadoc comments
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.
LGTM! Some minor cosmetic changes required before merging.
import java.io.ByteArrayOutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.time.OffsetDateTime; | ||
import java.util.*; |
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.
Enumerate all imports instead of using *
. Wonder why this is happening on generated code though. Is this how autorest generated? If that's the case, let me know. I will take a look.
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.
I believe this has to do with my IntelliJ settings, because this is code written over the autogenerated model in implementation. Brandon mentioned this in a different file as well but my settings should be fixed now.
public <T> Mono<T> getDataAsync(Class<T> clazz, JsonSerializer dataDeserializer) { | ||
if (!parsed) { | ||
// data was set instead of parsed, throw exception because we don't know how the data relates to clazz | ||
throw logger.logExceptionAsError(new IllegalStateException( |
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.
For async methods, exceptions should be passed through the publisher. Use FluxUtil.monoError()
.
return Flux.fromIterable(events) | ||
.collectList() | ||
.flatMap(list -> this.impl.publishCustomEventEventsAsync(this.hostname, list, context)); |
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.
Unfortunately, we'll have to iterate through the collection twice - once to convert Iterable to list and then when serializing. This impacts performance. Not sure, if we can avoid this without changing the API to take a List
instead.
return String.format("%s&%s=%s", unsignedSas, signKey, encodedSignature); | ||
|
||
} catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) { | ||
throw new RuntimeException(logger.logThrowableAsError(e)); |
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.
throw new RuntimeException(logger.logThrowableAsError(e)); | |
throw logger.logThrowableAsError(new RuntimeException(e)); |
if (CoreUtils.isNullOrEmpty(sas)) { | ||
throw logger.logExceptionAsError(new IllegalArgumentException("the access signature cannot be null or empty")); | ||
} |
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.
https://azure.github.io/azure-sdk/java_implementation.html#java-errors-system-errors
Split the exception into NPE and IllegalArgumentException when the input is null and empty respectively.
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for | ||
// license information. |
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.
License headers should be the following in all Java files:
https://docs.opensource.microsoft.com/content/releasing/copyright-headers.html#java
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
mostly minor changes, except a small license change to all source files, including generated ones.
Mitryakh/network march (Azure#15709) * Adds base for updating Microsoft.Network from version stable/2021-02-01 to version 2021-03-01 * Updates readme * Updates API version in new specs and examples * Add new parameter to enable/disable BGP route translation for NAT VirtualWan VpnGateway (Azure#14462) * Adding Bastion Host Configuration Features (Azure#14442) Co-authored-by: Abhishek Shah <shabhis@microsoft.com> * Add PL ASG (Azure#14620) * Add PL ASG * Prettier * [Private Link] Private Endpoint Ipconfigurations swagger for 2021-03-01 (Azure#14662) * Ipconfigurations swagger * Ran prettier check * fixing conflicting files * fixing lint * Fixing linter diff * Lint diff * resolving comments * fixing conflict * Fioxing * running prettier * Fixing linter comment Co-authored-by: Shane Baden <shbaden@microsoft.com> * Add missing properties of ServiceEndpointPolicy (Azure#14948) * Add missing 'type' and 'serviceAlias' for ServiceEndpointPolicy related API response * Add missing 'contextualServiceEndpointPolicies' * fix bug * fix type * Add missing properties to ServiceEndpointPolicy * Revert "fix type" This reverts commit 3a49beb66d9bbb288fa0d3baaeaf5aaf2bbc6ee9. * Revert "fix bug" This reverts commit a4fff4ae925b01ed0cfb07b1594fb95e2c6649c7. * Revert "Add missing 'contextualServiceEndpointPolicies'" This reverts commit ccf19167abc61b90bce6b5204dc3b2a64fdf4ca4. * Revert "Add missing 'type' and 'serviceAlias' for ServiceEndpointPolicy related API response" This reverts commit e532cc1118241a74902e4362c32c25c11a764933. Co-authored-by: Xu Wang <wax@microsoft.com> * add new service tag details api (Azure#14958) * add new service tag details api * prettier check fixes * fixing lint issue, additional properties issue * Add Load distribution policy and global configuration to AppGW (Azure#14790) * add Load distribution policy and global configuration to Application Gateway resource * prettify * remove provisioning state * add public ssh key to network virtual appliance (Azure#14988) * Changes needed for BgpEndpoint (Azure#14800) * changes needed for BgpEndpoint * prettier check * model validation fix * fix description * update again * Multi QoS support for DSCP configuration (Azure#15120) * Updating the DSCP jsons to reflect the multi-qos support * Adding support to multi-qos * adding the type object to NrpQos * fixing the prettier removing my update to the settings * fixing the missing type object error. seeing if this also fixes the additional attributes exception * fixing the prettier exception * almost forgot this, it was refactor from NrpQos to QosDefinition. NRPQos is already being used in Networking repo * copying what I did with my other objects * names didn't match with what I have in NRP's src * forgot to update the examples with the updates in the specification. updating it * fixing the merge exceptions * Add SQL Setting to Firewall Policy (Azure#15110) * Add SQL Setting to Firewall Policy * fix lint check except for object type * resolve linter error * network: fix newly added targets field to an array and missing sub-resource properties in applicationGateways.json (Azure#15318) * fix: change target to an array and add subresource properties * fix target examples * Support to update tags for BastionHost resource (Azure#15446) * Initial commit * Validation fixes * Update bastionHost.json Co-authored-by: Abhishek Shah <shabhis@microsoft.com> * Azure FW - Explicit Proxy feature swagger change (Azure#15017) * explicit proxy swagger change * prettier check fix * lint check * prettier fix * revert unnecessary file change * Add kind to virtual hub (Azure#15562) * Adding customnetworkinterfacename attribute to Private Endpoint (Azure#15574) Co-authored-by: Shane Baden <shbaden@microsoft.com> * Added 3 new properties to InboundNatRule resource (Azure#15611) * Added the missins properties to fix the change breaking update (Azure#15732) Co-authored-by: Nilambari <nilamd@microsoft.com> Co-authored-by: Abhishek Shah <shah.abhi7860@gmail.com> Co-authored-by: Abhishek Shah <shabhis@microsoft.com> Co-authored-by: Yang Shi <yangshi93@gmail.com> Co-authored-by: Shane Baden <naruto.shane@gmail.com> Co-authored-by: Shane Baden <shbaden@microsoft.com> Co-authored-by: Xu Wang <wangxu724@gmail.com> Co-authored-by: Xu Wang <wax@microsoft.com> Co-authored-by: guptas14 <71726901+guptas14@users.noreply.github.com> Co-authored-by: Akshay Gupta <aksgupta@microsoft.com> Co-authored-by: litchiyangMSFT <64560090+litchiyangMSFT@users.noreply.github.com> Co-authored-by: Ritvika Reddy Nagula <rinagula@microsoft.com> Co-authored-by: David Velasco <davelasc@microsoft.com> Co-authored-by: Jiejiong Wu <b564518128@users.noreply.github.com> Co-authored-by: tinawu6 <78238424+tinawu6@users.noreply.github.com> Co-authored-by: irrogozh <irrogozh@microsoft.com>
This PR is based on #14440, and new commits start at 51b5908.