Comments (14)
Azure Resource Graph may able to return the state on batch, e.g. (that sample is in VM of Compute) https://learn.microsoft.com/en-us/azure/virtual-machines/resource-graph-samples?tabs=azure-cli#count-of-virtual-machines-by-power-state
Though it be possible that similar query not work on ContainerGroup.
Azure Resource Graph query work on ContainerGroup
.
QueryResponse queryResponse = resourceGraphManager.resourceProviders()
.resources(new QueryRequest()
.withQuery("resources | where type == \"microsoft.containerinstance/containergroups\"")
.withOptions(new QueryRequestOptions().withResultFormat(ResultFormat.OBJECT_ARRAY)));
Assertions.assertTrue(queryResponse.totalRecords() > 0L);
((ArrayList<LinkedHashMap>) queryResponse.data()).forEach(dataItem -> {
ContainerGroupInner innerModel = BinaryData.fromObject(dataItem).toObject(ContainerGroupInner.class);
Assertions.assertNotNull(innerModel);
Assertions.assertNotNull(innerModel.instanceView());
Assertions.assertNotNull(innerModel.instanceView().state());
});
You can choose to use Azure Resource Graph query or ContainerGroup via get according to your needs.
from azure-sdk-for-java.
Thank you for your feedback. Tagging and routing to the team member best able to assist.
from azure-sdk-for-java.
@v-hongli1 Please take a look.
@XiaofeiCao for awareness.
from azure-sdk-for-java.
@arballesteros
Which version were you using before migrating to the new Azure Resource Management Library ?
In addition, If you can provide code snippets for creating ContainerGroup
and getting status, it will be helpful for us to analyze the issue, thank you !
from azure-sdk-for-java.
Hello @v-hongli1.
We used com.microsoft.azure:azure-mgmt-containerinstance:1.41.4
before the migration.
For the ContainerGroup
creation, I can provide you a sample Azure CLI command that we are using.
az container create --name my-container-group --resource-group My-Resource-Group --sku Standard --image mcr.microsoft.com/azuredocs/aci-helloworld:latest --os-type Linux --vnet My-Group-vnet --subnet mysubnet-1
On how we get the status, we just use the state() that is provided by the ContainerGroup interface.
protected Map<String, String> getAttributes(ContainerGroup resource) {
final Map<String, String> attributes = new LinkedHashMap<>();
attributes.put("state", resource.state());
...
}
I hope these information can help you with your investigation.
from azure-sdk-for-java.
@arballesteros
Track1 test case code snippet using com.microsoft.azure:azure-mgmt-containerinstance:1.41.4
// The existing container group was created by portal
ContainerGroup existingContainerGroup = azure.containerGroups()
.getByResourceGroup("rg-hongli", "containergroup4lh001");
Assert.assertNotNull(existingContainerGroup.inner());
Assert.assertNotNull(existingContainerGroup.inner().instanceView());
Assert.assertNotNull(existingContainerGroup.inner().instanceView().state());
// The existing container group was created by AZ CLI
// AZ command: az container create --name my-container-group --resource-group My-Resource-Group --sku Standard --image mcr.microsoft.com/azuredocs/aci-helloworld:latest --os-type Linux --vnet My-Group-vnet --subnet mysubnet-1
existingContainerGroup = azure.containerGroups()
.getByResourceGroup("rg-hongli", "container777777");
Assert.assertNotNull(existingContainerGroup.inner());
Assert.assertNotNull(existingContainerGroup.inner().instanceView());
Assert.assertNotNull(existingContainerGroup.inner().instanceView().state());
// Create and getter container group by sdk
resourceGroup = azure.resourceGroups().define("rg123456").withRegion(Region.US_EAST).create();
createdContainerGroup = azure.containerGroups()
.define("container123456")
.withRegion(Region.US_EAST)
.withExistingResourceGroup("rg123456")
.withLinux()
.withPublicImageRegistryOnly()
.withoutVolume()
.withContainerInstance("nginx", 80)
.withDnsPrefix("nginx")
.create();
Assert.assertNotNull(createdContainerGroup.inner());
Assert.assertNotNull(createdContainerGroup.inner().instanceView());
Assert.assertNotNull(createdContainerGroup.inner().instanceView().state());
Track2 test case code snippet using com.azure.resourcemanager/[email protected]
// The existing container group was created by portal
ContainerGroup existingContainerGroup = manager
.containerGroups().getByResourceGroup("rg-hongli", "containergroup4lh001");
Assertions.assertNotNull(existingContainerGroup.innerModel());
Assertions.assertNotNull(existingContainerGroup.innerModel().instanceView());
Assertions.assertNotNull(existingContainerGroup.innerModel().instanceView().state());
// The existing container group was created by AZ CLI
// AZ command: az container create --name my-container-group --resource-group My-Resource-Group --sku Standard --image mcr.microsoft.com/azuredocs/aci-helloworld:latest --os-type Linux --vnet My-Group-vnet --subnet mysubnet-1
existingContainerGroup = manager.containerGroups()
.getByResourceGroup("rg-hongli", "container777777");
Assertions.assertNotNull(existingContainerGroup.innerModel());
Assertions.assertNotNull(existingContainerGroup.innerModel().instanceView());
Assertions.assertNotNull(existingContainerGroup.innerModel().instanceView().state());
// Create and getter container group by sdk
resourceGroup = resourceManager.resourceGroups().define(rgName).withRegion(Region.US_EAST).create();
createdContainerGroup = manager
.containerGroups()
.define(containerGroupName)
.withRegion(region)
.withExistingResourceGroup(rgName)
.withLinux()
.withPublicImageRegistryOnly()
.withoutVolume()
.withContainerInstance("nginx", 80)
.withDnsPrefix("nginx")
.create();
Assertions.assertNotNull(createdContainerGroup.innerModel());
Assertions.assertNotNull(createdContainerGroup.innerModel().instanceView());
Assertions.assertNotNull(createdContainerGroup.innerModel().instanceView().state());
The above test cases all work fine. Can you provide the detail code snippets for create/getter ContainerGroup
and call state() function?
from azure-sdk-for-java.
Is createdContainerGroup.state()
be correct? Is it still correct after .refresh()
?
from azure-sdk-for-java.
@v-hongli1
This is how we acquire our ContainerGroup.
azureApi.getAzure().containerGroups().list().stream().toList()
I noticed that you directly acquire the ContainerGroup using getByResourceGroup()
and so, I also tried it.
// This is how we get our ContainerGroup
List<ContainerGroup> getByList = azureApi.getAzure().containerGroups().list().stream().toList();
//Based on your example, I tried to directly acquire the ContainerGroup by using getByResourceGroup()
ContainerGroup getByResourceGroup = azureApi.getAzure().containerGroups().getByResourceGroup("Azure-Monitoring-Test-Resource-Group", "it-container-group");
Please see below the result.
As you can see, the ContainerGroup that was returned via the list().stream().toList()
has a null instanceView which lead to an invalid state().
However, the ContainerGroup that was returned by getByResourceGroup()
has a valid instanceView and the state() can be acquired.
What do you think? Is this an expected behavior?
from azure-sdk-for-java.
It is possible that instanceView
is not returned in List (this was seen on some other RPs). It may only return in Get.
from azure-sdk-for-java.
I see. So in our implementation, using List is not reliable.
Is there a plan in the future to include the instanceView
in List?
from azure-sdk-for-java.
For Compute RP, it got an expand
query param on the List that request backend to include the instanceView data. https://github.com/Azure/azure-rest-api-specs/blob/main/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2024-03-01/virtualMachine.json#L1152-L1165
However, I checked the containerGroup, they don't have this in their API spec
https://github.com/Azure/azure-rest-api-specs/blob/main/specification/containerinstance/resource-manager/Microsoft.ContainerInstance/stable/2023-05-01/containerInstance.json#L75
It had to be supported in backend, before SDK can do anything about it.
from azure-sdk-for-java.
Azure Resource Graph may able to return the state on batch, e.g. (that sample is in VM of Compute)
https://learn.microsoft.com/en-us/azure/virtual-machines/resource-graph-samples?tabs=azure-cli#count-of-virtual-machines-by-power-state
Though it be possible that similar query not work on ContainerGroup.
from azure-sdk-for-java.
However, I checked the containerGroup, they don't have this in their API spec
https://github.com/Azure/azure-rest-api-specs/blob/main/specification/containerinstance/resource-manager/Microsoft.ContainerInstance/stable/2023-05-01/containerInstance.json#L75
It had to be supported in backend, before SDK can do anything about it.
Thank you for the assistance and I understand the circumstances.
For now, we will refrain from acquiring the ContainerGroup
via List and instead, we shall be using the Get.
from azure-sdk-for-java.
Thanks for testing this out.
We will consider these options you have presented.
from azure-sdk-for-java.
Related Issues (20)
- [QUERY] How to fetch the private key from Azure Keyvault Secret and convert it to a "java.security.PrivateKey" Java object? HOT 2
- [Key Vault] Re-generate libraries and release first beta for service version `7.6-preview.1`
- [BUG]DiagnosticsReplicaStatusList improvement
- Port WorkloadIdentityCredential to use ClientAssertionCredential.
- Revisit shared singleton `HttpClient` mechanism
- More HTTP client support (with SSE support)
- Ensure private methods don't throw `UnhandledIOException` and instead throw `IOException`
- [OpenAI-Assistants] Support Assistant v2 API version
- Revisit default constants in `RequestOptions`, `Context`, `BinaryData` and similar classes HOT 1
- Refactor `ServerSentEventUtils`
- [OpenAI] Add support for Batch API
- [BUG] azure-storage rename takes over 2 minutes to fail (because the target file already exists) in concurrent context HOT 2
- [BUG]DiagnosticsImprovement: Adding CurrentReplicaSetSize and quorumAckedLSN
- [QUERY] Is there a way to set config for CosmosClientBuilder HOT 3
- [BUG] Azure Toolkit for IntelliJ - IntelliJCredential does not find logged in creds in keychain on Mac HOT 2
- [BUG] pom_file_version_scanner.ps1 needs better errors around misformed lines
- [BUG] container registry lisrepository names only returns 109 max HOT 1
- [BUG] ServiceBus SessionProcessorClient with negative session idle timeout throws incorrect validation error message HOT 6
- [BUG] Frequent cases with Starting lock renewal messages in log and messages are not delivered HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-sdk-for-java.