Skip to content

[Service Bus] [core-http] Implement ATOM based management API#4880

Closed
ramya0820 wants to merge 2 commits intoAzure:masterfrom
ramya0820:sb-atom-p4
Closed

[Service Bus] [core-http] Implement ATOM based management API#4880
ramya0820 wants to merge 2 commits intoAzure:masterfrom
ramya0820:sb-atom-p4

Conversation

@ramya0820
Copy link
Copy Markdown
Member

This PR includes end to end implementation of the ATOM management API and set of tests for CRUD operations on Queues.
Can be considered as a draft, as working on straightening out few more things - mostly code organization, simplifications.

cc @ramya-rao-a @AlexGhiondea

@ramya0820
Copy link
Copy Markdown
Member Author

@amarzavery @ramya-rao-a @nemakam @bterlson @daviwil
Let me know if you have any comments (mostly on high level things)

@ramya0820 ramya0820 requested a review from amarzavery August 23, 2019 18:32
@ramya0820
Copy link
Copy Markdown
Member Author

Build successful but blocked on some other unrelated changes

SUCCESS (12)
================================
@azure/abort-controller (4.23 seconds)
@azure/core-auth (10.62 seconds)
@azure/core-http (18.85 seconds)
@azure/core-arm (10.59 seconds)
@azure/core-asynciterator-polyfill (4.43 seconds)
@azure/core-paging (2.20 seconds)
@azure/core-tracing (11.58 seconds)
@azure/event-processor-host (24.33 seconds)
@azure/service-bus (31.54 seconds)
@azure/storage-blob (22.70 seconds)
@azure/storage-file (19.05 seconds)
@azure/storage-queue (15.96 seconds)
================================

BLOCKED (5)
================================
@azure/core-amqp
@azure/keyvault-certificates
@azure/keyvault-keys
@azure/keyvault-secrets
@azure/event-hubs
================================

Copy link
Copy Markdown
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramya0820 I have left a few high level comments, please take a look at them.

Once #4863 is merged, please rebase/merge from master, after which @bterlson will help in reviewing the changes specific to the http request/response code paths.

Also, please update the PR description with

  • pointers to the old code base from which this feature has been picked from. Especially the libraries which you have taken as a reference. Preferably, in a format which gives a 1:1 mapping between libraries and the files in this PR
  • any docs around the ATOM based management apis


const HeaderConstants = Constants.HeaderConstants;

export class ServiceBusSASServiceClientCredentials implements ServiceClientCredentials {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this credential is specific to a particular Azure service, it should live in the library for that service and not core-http.
Please move this to the Service Bus library.

* - serialize HTTP requests with input in JSON to ATOM based XML requests, and
* - deserialize the ATOM based XML responses as they pass through the HTTP pipeline.
*/
export class ServiceBusAtomSerializationPolicy extends BaseRequestPolicy {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this policy make any assumptions on how Azure Service Bus expects requests and returns responses? If yes, then this should move to the Service Bus library. If this policy is service agnostic, then it can stay in core-http

}

// @public
export class ServiceBusAtomManagementClient extends ServiceClient {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Customers will not be aware of the existence of a separate client in order to carry out the crud operations. They are aware of the existing ServiceBusClient and would expect all the crud operations to exist on it.

Below is what I would recommend:

  • Do not expose ServiceBusAtomManagementClient to customer, instead have it as property on ServiceBusClient.
    When user creates a ServiceBusClient, you instantiate ServiceBusAtomManagementClient internally
  • Replicate all the crud operations on ServiceBusClient. These will call the corresponding counterparts in the ServiceBusAtomManagementClient

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this, and since we establish AMQP connection at time of client instantiation, woukd this be a good design decision? cc @bterlson @chradek

* @param credentials Credentials needed for the client to connect to Azure.
* @param options The parameter options
*/
constructor(connectionString: any, options?: ServiceClientOptions) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the ATOM based management apis only work with Shared Access Keys?
Do they not work with AAD?

"uuid": "^3.3.2",
"xml2js": "^0.4.19"
"xml2js": "^0.4.19",
"underscore": "1.4.x",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"underscore": "1.4.x",
"underscore": "^1.4.x",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there is an exception, all dependencies should use caret ^ to float to latest within major.

@bterlson, do you think this is a runtime dependency worth taking? I know we wanted to minimize the number of runtime deps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not. Please remove underscore dependency.

"xml2js": "^0.4.19"
"xml2js": "^0.4.19",
"underscore": "1.4.x",
"xmlbuilder": "0.4.3"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"xmlbuilder": "0.4.3"
"xmlbuilder": "^0.4.3"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there is an exception, all dependencies should use caret ^ to float to latest within major.

@bterlson, do you think this is a runtime dependency worth taking? I know we wanted to minimize the number of runtime deps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xmlbuilder I'm less sure about. Looking at the usage it seems fairly simple and could maybe be replaced with string templates instead. @ramya0820 let me know any thoughts on this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought having a utility in place to work with serializing to / building XML docs seemed useful / preferable generally speaking.
Hence brought over the js2xml utility from azure-sb that uses both xmlbuilder and underscore. Would prefer if we could come up with an alternative library, like using https://www.npmjs.com/package/fast-xml-parser maybe?

I'll take another pass at the code to see if I can remove the dependencies and simplify / uniformize the XML handling bits in core-http (specifically the serialization bits).

I just worry that building these handlers from scratch, apart from incurring some more efforts and time, may

  • miss out any specific usage / corner cases that were being handled by the underlying libraries (xmlbuilder, underscore, etc.)(and probably why these were chosen in implementation in azure-sb?)
  • not be that easily extendable, scalable should any other XML related use-cases come in

Copy link
Copy Markdown
Member Author

@ramya0820 ramya0820 Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I'll take another look into minimizing / removing these 2 dependencies.

import { stringIsEmpty, stringStartsWith } from "./util/utils";
import { Constants } from "./util/constants";
import { AtomHandler } from "./util/atomHandler";
import { each, isUndefined, isArray, isObject, isDate } from "./util/utils";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import can be combined with the line 17.

@@ -0,0 +1,14 @@
import { ResourceSerializer } from "./resourceSerializer";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright text is missing in this file.

if (
sharedAccessKeyName === null ||
sharedAccessKeyName === undefined ||
typeof sharedAccessKeyName.valueOf() !== "string"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to add separate checks for null and undefined. We can combine these 2 checks.
Something like:

if(!(typeof sharedAccessKeyName ==="string" && sharedAccessKeyName )){
      throw new Error("sharedAccessKeyName is missing.");
    }

if (
sharedAccessKey === null ||
sharedAccessKey === undefined ||
typeof sharedAccessKey.valueOf() !== "string"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to add separate checks for null and undefined. We can combine these 2 checks.
Something like:

if(!(typeof sharedAccessKey==="string" && sharedAccessKey)){
      throw new Error("sharedAccessKey is missing.");
    }

@ramya0820
Copy link
Copy Markdown
Member Author

Thanks for the comments so far! @mikeharder @ramya-rao-a @ShivangiReja @bterlson
As we had discussed offline earlier, this PR has been split into following two

This PR will be closed in favor of other 2 PRs where the requested changes will be made at.

@ramya0820 ramya0820 closed this Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants