diff --git a/sdk/resourcemanager/azure-resourcemanager-containerinstance/CHANGELOG.md b/sdk/resourcemanager/azure-resourcemanager-containerinstance/CHANGELOG.md index dd9e510a58414..6e870831d7730 100644 --- a/sdk/resourcemanager/azure-resourcemanager-containerinstance/CHANGELOG.md +++ b/sdk/resourcemanager/azure-resourcemanager-containerinstance/CHANGELOG.md @@ -4,11 +4,7 @@ ### Features Added -### Breaking Changes - -### Bugs Fixed - -### Other Changes +- Supported `beginCreate` method for `ContainerGroup`. ## 2.44.0-beta.1 (2024-10-08) diff --git a/sdk/resourcemanager/azure-resourcemanager-containerinstance/assets.json b/sdk/resourcemanager/azure-resourcemanager-containerinstance/assets.json index 09d87b70614c1..be763ec9c21cb 100644 --- a/sdk/resourcemanager/azure-resourcemanager-containerinstance/assets.json +++ b/sdk/resourcemanager/azure-resourcemanager-containerinstance/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/resourcemanager/azure-resourcemanager-containerinstance", - "Tag": "java/resourcemanager/azure-resourcemanager-containerinstance_b66810ce1f" + "Tag": "java/resourcemanager/azure-resourcemanager-containerinstance_67378ea46f" } diff --git a/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/implementation/ContainerGroupImpl.java b/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/implementation/ContainerGroupImpl.java index 4a049e47b9b22..b6931dc0fbfe8 100644 --- a/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/implementation/ContainerGroupImpl.java +++ b/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/implementation/ContainerGroupImpl.java @@ -4,6 +4,9 @@ package com.azure.resourcemanager.containerinstance.implementation; import com.azure.core.management.Resource; +import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; import com.azure.resourcemanager.authorization.utils.RoleAssignmentHelper; import com.azure.resourcemanager.authorization.models.BuiltInRole; import com.azure.resourcemanager.containerinstance.ContainerInstanceManager; @@ -36,7 +39,10 @@ import com.azure.resourcemanager.network.models.Subnet; import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils; import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl; +import com.azure.resourcemanager.resources.fluentcore.model.Accepted; import com.azure.resourcemanager.resources.fluentcore.model.Creatable; +import com.azure.resourcemanager.resources.fluentcore.model.Indexable; +import com.azure.resourcemanager.resources.fluentcore.model.implementation.AcceptedImpl; import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; import com.azure.resourcemanager.storage.models.StorageAccount; import com.azure.storage.file.share.ShareServiceAsyncClient; @@ -60,6 +66,8 @@ public class ContainerGroupImpl ContainerGroup, ContainerGroupInner, ContainerGroupImpl, ContainerInstanceManager> implements ContainerGroup, ContainerGroup.Definition, ContainerGroup.Update { + private final ClientLogger logger = new ClientLogger(ContainerGroupImpl.class); + private String creatableStorageAccountKey; private Creatable creatableVirtualNetwork; private Map newFileShares; @@ -133,10 +141,58 @@ protected Mono createInner() { } } - private static class VolumeParameters { - private String volumeName; - private String fileShareName; - private String storageAccountKey; + @Override + public Accepted beginCreate() { + return AcceptedImpl + .newAccepted( + logger, + this.manager().serviceClient().getHttpPipeline(), + this.manager().serviceClient().getDefaultPollInterval(), + () -> + this + .manager() + .serviceClient() + .getContainerGroups() + .createOrUpdateWithResponseAsync(resourceGroupName(), name(), innerModel()) + .block(), + inner -> + new ContainerGroupImpl( + inner.name(), + inner, + this.manager()), + ContainerGroupInner.class, + () -> { + Flux dependencyTasksAsync = + taskGroup().invokeDependencyAsync(taskGroup().newInvocationContext()); + dependencyTasksAsync.blockLast(); + + // same as createInner + beforeCreation().block(); + // msi + this.containerGroupMsiHandler.processCreatedExternalIdentities(); + this.containerGroupMsiHandler.handleExternalIdentities(); + // storage account + if (!(newFileShares == null || creatableStorageAccountKey == null)) { + final StorageAccount storageAccount = this.taskResult(this.creatableStorageAccountKey); + List volumeParametersList = createFileShareAsync(storageAccount).collectList().block(); + if (!CoreUtils.isNullOrEmpty(volumeParametersList)) { + for (VolumeParameters volumeParameters : volumeParametersList) { + this.defineVolume(volumeParameters.volumeName) + .withExistingReadWriteAzureFileShare(volumeParameters.fileShareName) + .withStorageAccountName(storageAccount.name()) + .withStorageAccountKey(volumeParameters.storageAccountKey) + .attach(); + } + } + } + }, + Context.NONE); + } + + private static final class VolumeParameters { + private final String volumeName; + private final String fileShareName; + private final String storageAccountKey; VolumeParameters(String volumeName, String fileShareName, String storageAccountKey) { this.volumeName = volumeName; diff --git a/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/models/ContainerGroup.java b/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/models/ContainerGroup.java index 6348834e9d372..13be5b4b4257f 100644 --- a/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/models/ContainerGroup.java +++ b/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/main/java/com/azure/resourcemanager/containerinstance/models/ContainerGroup.java @@ -11,6 +11,7 @@ import com.azure.resourcemanager.network.models.Subnet; import com.azure.resourcemanager.resources.fluentcore.arm.models.GroupableResource; import com.azure.resourcemanager.resources.fluentcore.arm.models.Resource; +import com.azure.resourcemanager.resources.fluentcore.model.Accepted; import com.azure.resourcemanager.resources.fluentcore.model.Appliable; import com.azure.resourcemanager.resources.fluentcore.model.Attachable; import com.azure.resourcemanager.resources.fluentcore.model.Creatable; @@ -20,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Set; + import reactor.core.publisher.Mono; /** An immutable client-side representation of an Azure Container Group. */ @@ -1309,6 +1311,13 @@ interface WithCreate WithLogAnalytics, Creatable, Resource.DefinitionWithTags { + + /** + * Begins creating the deployment resource. + * + * @return the accepted create operation + */ + Accepted beginCreate(); } } diff --git a/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/test/java/com/azure/resourcemanager/containerinstance/ContainerGroupTest.java b/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/test/java/com/azure/resourcemanager/containerinstance/ContainerGroupTest.java index 908fee0f3fa46..fe12cae4f617b 100644 --- a/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/test/java/com/azure/resourcemanager/containerinstance/ContainerGroupTest.java +++ b/sdk/resourcemanager/azure-resourcemanager-containerinstance/src/test/java/com/azure/resourcemanager/containerinstance/ContainerGroupTest.java @@ -15,6 +15,7 @@ import com.azure.resourcemanager.containerinstance.models.ContainerState; import com.azure.resourcemanager.containerinstance.models.Scheme; import com.azure.resourcemanager.network.models.Network; +import com.azure.resourcemanager.resources.fluentcore.model.Accepted; import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -26,7 +27,7 @@ public class ContainerGroupTest extends ContainerInstanceManagementTest { @Test public void testContainerGroupWithVirtualNetwork() { String containerGroupName = generateRandomResourceName("container", 20); - Region region = Region.US_EAST; + Region region = Region.US_WEST3; ContainerGroup containerGroup = containerInstanceManager @@ -180,4 +181,56 @@ public void testCreateWithLivenessAndReadiness() { Assertions.assertTrue(durationBeforeRestart.compareTo(Duration.ofSeconds(healthySeconds + probePeriodSeconds * (failureThreshold - 1))) > 0); Assertions.assertTrue(durationBeforeRestart.compareTo(Duration.ofSeconds(healthySeconds + probePeriodSeconds * failureThreshold)) <= 0); } + + @Test + public void testBeginCreate() { + final String succeededState = "Succeeded"; + String containerGroupName = generateRandomResourceName("container", 20); + Region region = Region.US_WEST3; + + // create resource group and virtual network, but no storage account, before create container group + Accepted acceptedContainerGroup = + containerInstanceManager + .containerGroups() + .define(containerGroupName) + .withRegion(region) + .withNewResourceGroup(rgName) + .withLinux() + .withPublicImageRegistryOnly() + .withoutVolume() + .withContainerInstance("nginx", 80) + .withNewVirtualNetwork("10.0.0.0/24") + .beginCreate(); + + ContainerGroup createdContainerGroup = acceptedContainerGroup.getActivationResponse().getValue(); + Assertions.assertNotEquals(succeededState, createdContainerGroup.provisioningState()); + + ContainerGroup containerGroup = acceptedContainerGroup.getSyncPoller().getFinalResult(); + Assertions.assertEquals(succeededState, containerGroup.provisioningState()); + } + + // test contains a data-plane call + @DoNotRecord(skipInPlayback = true) + @Test + public void testBeginCreateWithFileShareVolume() { + String containerGroupName = generateRandomResourceName("container", 20); + Region region = Region.US_WEST3; + + // create storage account (and virtual network), before create container group + Accepted acceptedContainerGroup = + containerInstanceManager + .containerGroups() + .define(containerGroupName) + .withRegion(region) + .withNewResourceGroup(rgName) + .withLinux() + .withPublicImageRegistryOnly() + // definition step only allow creating one file share volume + .withNewAzureFileShareVolume("vol1", "share1") + .withContainerInstance("nginx", 80) + .withNewVirtualNetwork("10.0.0.0/24") + .beginCreate(); + ContainerGroup containerGroup = acceptedContainerGroup.getSyncPoller().getFinalResult(); + Assertions.assertEquals(1, containerGroup.volumes().size()); + } } diff --git a/sdk/resourcemanager/azure-resourcemanager-test/src/main/java/com/azure/resourcemanager/test/ResourceManagerTestProxyTestBase.java b/sdk/resourcemanager/azure-resourcemanager-test/src/main/java/com/azure/resourcemanager/test/ResourceManagerTestProxyTestBase.java index ceae08804f3ec..8dc780c3decc7 100644 --- a/sdk/resourcemanager/azure-resourcemanager-test/src/main/java/com/azure/resourcemanager/test/ResourceManagerTestProxyTestBase.java +++ b/sdk/resourcemanager/azure-resourcemanager-test/src/main/java/com/azure/resourcemanager/test/ResourceManagerTestProxyTestBase.java @@ -602,6 +602,8 @@ private void addSanitizers() { new TestProxySanitizer("$..passwords[*].value", null, REDACTED_VALUE, TestProxySanitizerType.BODY_KEY), // ContainerService new TestProxySanitizer("$..secret", null, REDACTED_VALUE, TestProxySanitizerType.BODY_KEY), + // ContainerInstance + new TestProxySanitizer("$..storageAccountKey", null, REDACTED_VALUE, TestProxySanitizerType.BODY_KEY), // AppService new TestProxySanitizer("$.properties.siteConfig.machineKey.decryptionKey", null, REDACTED_VALUE, TestProxySanitizerType.BODY_KEY), // Replace "AccountKey=;" with "AccountKey=REDACTED;"