Skip to content

Conversation

@XiaofeiCao
Copy link
Contributor

@XiaofeiCao XiaofeiCao commented Jun 5, 2025

Description

customer request: https://stackoverflow.microsoft.com/questions/459001

co-related resources, e.g. resourceGroup, disks, networkInterface, will also share the Context.

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@github-actions github-actions bot added the Mgmt This issue is related to a management-plane library. label Jun 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

com.azure.resourcemanager:azure-resourcemanager-compute

@XiaofeiCao XiaofeiCao marked this pull request as ready for review June 5, 2025 06:40
Copilot AI review requested due to automatic review settings June 5, 2025 06:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for beginning a VirtualMachine creation operation with a Context, propagates that context through async calls, and includes a test to verify context propagation.

  • Introduced beginCreate(Context) overload in VirtualMachine interface and implementation
  • Propagated context via Reactor’s contextWrite in VirtualMachineImpl
  • Added a unit test canBeginCreateWithContext to validate context in HTTP pipeline policies

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
VirtualMachineOperationsTests.java Added test canBeginCreateWithContext and support methods to inject and verify context through pipeline policies
VirtualMachine.java Added beginCreate(Context) method signature and Javadoc
VirtualMachineImpl.java Implemented beginCreate(Context) to propagate Reactor context to service calls and dependency tasks
pom.xml Opened additional modules for reflective access in tests
assets.json Updated asset tag reference
CHANGELOG.md Documented the new beginCreate(Context) feature
Comments suppressed due to low confidence (2)

sdk/resourcemanager/azure-resourcemanager-compute/src/main/java/com/azure/resourcemanager/compute/models/VirtualMachine.java:2200

  • The Javadoc references WithCreate#create(Context) which does not exist; this should link to WithCreate#beginCreate(Context).
* Please use {@link WithCreate#create(Context)} if virtual machine extensions is configured.

sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineOperationsTests.java:2352

  • [nitpick] Using reflection to access a private HttpPipeline constructor is brittle; consider using a supported builder or a pipeline customization hook instead of direct reflection.
Constructor<HttpPipeline> pipelineConstructor = HttpPipeline.class.getDeclaredConstructor(HttpClient.class, List.class, Tracer.class);

Copy link
Member

@weidongxu-microsoft weidongxu-microsoft left a comment

Choose a reason for hiding this comment

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

Code should be fine.

@XiaofeiCao XiaofeiCao merged commit abb3459 into Azure:main Jun 6, 2025
31 checks passed
@sfc-gh-krank
Copy link

@XiaofeiCao Thank you for doing this!

Is it possible to add Context to following methods too?

com.azure.resourcemanager.compute.models.VirtualMachines#beginDeleteByResourceGroup(java.lang.String, java.lang.String, boolean)
com.azure.resourcemanager.compute.models.Disks#beginDeleteByResourceGroup
com.azure.resourcemanager.network.models.NetworkInterfaces#beginDeleteByResourceGroup

@XiaofeiCao
Copy link
Contributor Author

XiaofeiCao commented Jun 9, 2025

@XiaofeiCao Thank you for doing this!

Is it possible to add Context to following methods too?

com.azure.resourcemanager.compute.models.VirtualMachines#beginDeleteByResourceGroup(java.lang.String, java.lang.String, boolean) com.azure.resourcemanager.compute.models.Disks#beginDeleteByResourceGroup com.azure.resourcemanager.network.models.NetworkInterfaces#beginDeleteByResourceGroup

@sfc-gh-krank Yeah, we could. Wonder if you also need com.azure.resourcemanager.compute.models.Disk#beginCreate(Context).
My guess is no, since I'm assuming your workflow is create VM with related resources -> delete related disk/nic -> delete VM.

Also, what about com.azure.resourcemanager.network.models.PublicIpAddresses#beginDeleteByResourceGroup?

@sfc-gh-krank
Copy link

We don't create disks separately. It's all part off ARM template.

But we do plan to support individual disks management (create, snapshots etc...) in the future. So when you are touching these APIs now, it makes sense to add Context to other methods too...

com.azure.resourcemanager.network.models.PublicIpAddresses#beginDeleteByResourceGroup - not used. Only NetworkInterfaces

@XiaofeiCao
Copy link
Contributor Author

XiaofeiCao commented Jun 11, 2025

@sfc-gh-krank Got it. Here's a list of methods we plan to support:

  • com.azure.resourcemanager.compute.models.VirtualMachines#beginDeleteByResourceGroup(Context)
  • com.azure.resourcemanager.compute.models.Disks#beginCreate(Context)
  • com.azure.resourcemanager.compute.models.Disks#beginDeleteByResourceGroup(Context)
  • com.azure.resourcemanager.network.models.Snapshots#beginCreate(Context)
  • com.azure.resourcemanager.network.models.Snapshots#beginDeleteByResourceGroup(Context)
  • com.azure.resourcemanager.network.models.NetworkInterfaces#beginDeleteByResourceGroup(Context)

Let us know if you need more. /cc @weidongxu-microsoft

@sfc-gh-hsong
Copy link

sfc-gh-hsong commented Jun 11, 2025

@sfc-gh-krank Got it. Here's a list of methods we plan to support:

  • com.azure.resourcemanager.compute.models.VirtualMachines#beginDeleteByResourceGroup(Context)
  • com.azure.resourcemanager.compute.models.Disks#beginCreate(Context)
  • com.azure.resourcemanager.compute.models.Disks#beginDeleteByResourceGroup(Context)
  • com.azure.resourcemanager.network.models.Snapshots#beginCreate(Context)
  • com.azure.resourcemanager.network.models.Snapshots#beginDeleteByResourceGroup(Context)
  • com.azure.resourcemanager.network.models.NetworkInterfaces#beginDeleteByResourceGroup(Context)

Let us know if you need more. /cc @weidongxu-microsoft

Thanks @XiaofeiCao

Here are some more methods we are using today on top of the ones you have listed

- com.azure.resourcemanager.compute.models.VirtualMachines#getPrimaryNetworkInterface
- com.azure.resourcemanager.network.models.ApplicationSecurityGroups#getById
- com.azure.resourcemanager.network.models.Networks#getById
- com.azure.resourcemanager.network.models.NetworkInterfaces#listByResourceGroup
- com.azure.resourcemanager.network.models.NetworkSecurityGroups#getById
- com.azure.resourcemanager.network.models.NicIpConfiguration#listAssociatedApplicationSecurityGroups

- com.azure.resourcemanager.resources.models.Deployment#beginDeployment
- com.azure.resourcemanager.resources.models.Deployment#beginDelete
- com.azure.resourcemanager.resources.models.ResourceGroups#beginDeleteByName

Not sure if it's possible to add context to those list/get calls. It would be very helpful if they can get supported.

@XiaofeiCao
Copy link
Contributor Author

Thanks @XiaofeiCao

Here are some more methods we are using today on top of the ones you have listed

- com.azure.resourcemanager.compute.models.VirtualMachines#getPrimaryNetworkInterface
- com.azure.resourcemanager.network.models.ApplicationSecurityGroups#getById
- com.azure.resourcemanager.network.models.Networks#getById
- com.azure.resourcemanager.network.models.NetworkInterfaces#listByResourceGroup
- com.azure.resourcemanager.network.models.NetworkSecurityGroups#getById
- com.azure.resourcemanager.network.models.NicIpConfiguration#listAssociatedApplicationSecurityGroups

- com.azure.resourcemanager.resources.models.Deployment#beginDeployment
- com.azure.resourcemanager.resources.models.ResourceGroups#beginDeleteByName

Not sure if it's possible to add context to those list/get calls. It would be very helpful if they can get supported.

@sfc-gh-hsong Sure, we'll add them.

For

  • com.azure.resourcemanager.resources.models.Deployment#beginDeployment

Do you mean com.azure.resourcemanager.resources.models.Deployment#beginDelete?

@sfc-gh-hsong
Copy link

Thanks @XiaofeiCao

Below is our current implementation to begin a deployment given a template

      return this.azureResourceManager
          .deployments()
          .define(deploymentName)
          .withExistingResourceGroup(rgName)
          .withTemplate(templateJson)
          .withParameters("{}")
          .withMode(DeploymentMode.INCREMENTAL)
          .beginCreate();

But yes, let's add com.azure.resourcemanager.resources.models.Deployment#beginDelete as well. I updated the original message as well

@XiaofeiCao
Copy link
Contributor Author

Hi @sfc-gh-hsong

We should already have beginCreate(Context) in Deployment.

Would you help check again?

@sfc-gh-hsong
Copy link

Hi @sfc-gh-hsong

We should already have beginCreate(Context) in Deployment.

Would you help check again?

Thanks @XiaofeiCao

You are right, it's there for Accepted<Deployment> beginCreate(Context context); we can skip that. Thanks

        interface WithCreate extends Creatable<Deployment> {
            /**
             * Begins creating the deployment resource.
             *
             * @return the accepted create operation
             */
            Accepted<Deployment> beginCreate();

            /**
             * Begins creating the deployment resource.
             *
             * @param context the {@link Context} of the request
             * @return the accepted create operation
             */
            Accepted<Deployment> beginCreate(Context context);

            /**
             * Begins creating the deployment resource.
             *
             * @return the publisher of the accepted create operation
             */
            Mono<Deployment> beginCreateAsync();
        }

Can you please keep us posted once the PR is out so that we can follow up on the SDK version upgrade? Thanks

@XiaofeiCao
Copy link
Contributor Author

@sfc-gh-hsong Sure, here's the PR:
#45725

Feel free to leave any comments.

@XiaofeiCao
Copy link
Contributor Author

Hi @sfc-gh-hsong , 2.52.0 has released with these features!

@sfc-gh-hsong
Copy link

Thanks @XiaofeiCao !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Mgmt This issue is related to a management-plane library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants