Skip to content

Instantly share code, notes, and snippets.

@jianghaolu
Last active January 27, 2020 19:02
Show Gist options
  • Save jianghaolu/f2b062a688978673316bcc9c0dfb37e3 to your computer and use it in GitHub Desktop.
Save jianghaolu/f2b062a688978673316bcc9c0dfb37e3 to your computer and use it in GitHub Desktop.
AutoRest Java & fluent v4 structural changes

Intro

In the past couple months we've made through most of the vanilla features in AutoRest.Java v4. At this point, we are planning for the next phase of work. We want to make a few changes in the AutoRest.Java structure according to

  • The changes in Track 2 azure-core & azure-core-mgmt structure
  • The long-term ownership changes

The goal is to define clear ownership in the long term and easy integration with azure-core, azure-core-mgmt, etc.

Current V2 Structure

The AutoRest Java in master branch is designed in 3 levels

Generator Argument Runtime Usage
Vanilla --java client-runtime None, for community
Azure --azure-arm azure-client-runtime Track 1 data plane
Fluent --fluent
--generate-interfaces
azure-client-runtime
azure-arm-client-runtime
Track 1 fluent premium
Track 1 fluent lite

Vanilla supports the basic operations defined in Swagger 2.0 spec. Azure overrides some behaviors to support Azure paging, HEAD operations, etc. It also has Azure ARM specific logic to support ARM LRO and to figure out what models should inherit from ARM base classes ( Resource, ProxyResource, or SubResource).

azure-arm

Fluent changes the name of these resources, and responses to XxxInner (which gives the best name Xxx to fluent premium and lite to be built on top).

azure-arm-fluent

Fluent lite then generates a simple form of the fluent convenience layer.

azure-arm-fluent-generate-interfaces

Changes proposed for V4

  1. Split the features in Azure gen to Vanilla gen and fluent gen - management library specific features will be moved to Fluent, for example, ARM specific LRO, base Resource classes; common features used also by data plane team will be moved vanilla, for example, paging, polling.
  2. Inner renaming can be moved to the front as an optional pre processing step.

New V4 Structure

The proposed structure looks like the following

Plugin Argument Runtime Usage
javanamer --java (or a new arg) N/A Java specific renamings & tweaks
fluentnamer --fluent (or a new arg) N/A Fluent specific renamings & tweaks
javagen (Vanilla) --java azure-core Track 2 data plane
fluentgen (Fluent) --fluent
--generate-interfaces
azure-core-mgmt Track 2 fluent premium
Track 2 fluent lite

The namers are a pre-processing step before the vanilla generator to pre-process the names. If --fluent is turned on, Inner will be appended to Resource types and response types. Also, types that should inherit from Resource/ProxyResource/SubResource but don't have the inheritance should also be fixed here.

For Vanilla, it will look similar to v2:

java

For Fluent, the vanilla generator no longer contains the code to add "Inner" or change the inheritance to Resource/ProxyResource/SubResource on models. The vanilla generator will only take care of the core generation. In order to add "Inner" and add inheritance, we will add a pre-processing step to feed the vanilla generator with a "fluent code model" with all the renamings and hierachies completed.

java-fluent

And finally for fluent lite, we generate the same interface as v2:

azure-arm-fluent-generate-interfaces

Ownership

In the long term, the ADP-Java team will own the vanilla generator, responsible for the core features in code generation. This will ensure the data plane libraries are getting all the scenarios/protocols supported. The management library team will own the pre-processing transformer and the fluent generator, with contributions welcome to the vanilla generator. This will allow the management libraries team to own more management specific features. This structure also better aligns with the azure-core and azure-core-mgmt structure.

Next steps

For ADP team, the next tasks are

  • Finish supporting all vanilla tests in test server
  • Support model flattening, payload flattening and grouping
  • Start building data plane SDKs with the new generator
  • Help management libraries team to set up the new structure
  • Help management libraries team with azure-core-mgmt readiness

For management libraries team, the next tasks are

  • Finish management specific features in azure-core-mgmt (maybe also merge in the fluent lite base classes?)
  • Build corresponding code generation in fluent generator (e.g. ARM specific LRO)
  • Build pre-processing transformer to add Inner suffixes and resource inheritance
  • Start building management SDKs with the new generator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment