|
| 1 | +# Code snippets and samples |
| 2 | + |
| 3 | + |
| 4 | +## Operations |
| 5 | + |
| 6 | +- [List](#operations_list) |
| 7 | + |
| 8 | +## ResourceProvider |
| 9 | + |
| 10 | +- [Resources](#resourceprovider_resources) |
| 11 | +- [ResourcesHistory](#resourceprovider_resourceshistory) |
| 12 | +### Operations_List |
| 13 | + |
| 14 | +```java |
| 15 | +import com.azure.core.util.Context; |
| 16 | + |
| 17 | +/** Samples for Operations List. */ |
| 18 | +public final class OperationsListSamples { |
| 19 | + /* |
| 20 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/OperationsList.json |
| 21 | + */ |
| 22 | + /** |
| 23 | + * Sample code: OperationsList. |
| 24 | + * |
| 25 | + * @param manager Entry point to ResourceGraphManager. |
| 26 | + */ |
| 27 | + public static void operationsList(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 28 | + manager.operations().list(Context.NONE); |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +### ResourceProvider_Resources |
| 34 | + |
| 35 | +```java |
| 36 | +import com.azure.core.util.Context; |
| 37 | +import com.azure.resourcemanager.resourcegraph.models.FacetRequest; |
| 38 | +import com.azure.resourcemanager.resourcegraph.models.FacetRequestOptions; |
| 39 | +import com.azure.resourcemanager.resourcegraph.models.FacetSortOrder; |
| 40 | +import com.azure.resourcemanager.resourcegraph.models.QueryRequest; |
| 41 | +import com.azure.resourcemanager.resourcegraph.models.QueryRequestOptions; |
| 42 | +import java.util.Arrays; |
| 43 | + |
| 44 | +/** Samples for ResourceProvider Resources. */ |
| 45 | +public final class ResourceProviderResourcesSamples { |
| 46 | + /* |
| 47 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesMgBasicQuery.json |
| 48 | + */ |
| 49 | + /** |
| 50 | + * Sample code: Basic management group query. |
| 51 | + * |
| 52 | + * @param manager Entry point to ResourceGraphManager. |
| 53 | + */ |
| 54 | + public static void basicManagementGroupQuery(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 55 | + manager |
| 56 | + .resourceProviders() |
| 57 | + .resourcesWithResponse( |
| 58 | + new QueryRequest() |
| 59 | + .withManagementGroups(Arrays.asList("e927f598-c1d4-4f72-8541-95d83a6a4ac8", "ProductionMG")) |
| 60 | + .withQuery("Resources | project id, name, type, location, tags | limit 3"), |
| 61 | + Context.NONE); |
| 62 | + } |
| 63 | + |
| 64 | + /* |
| 65 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesBasicQuery.json |
| 66 | + */ |
| 67 | + /** |
| 68 | + * Sample code: Basic query. |
| 69 | + * |
| 70 | + * @param manager Entry point to ResourceGraphManager. |
| 71 | + */ |
| 72 | + public static void basicQuery(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 73 | + manager |
| 74 | + .resourceProviders() |
| 75 | + .resourcesWithResponse( |
| 76 | + new QueryRequest() |
| 77 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 78 | + .withQuery("Resources | project id, name, type, location, tags | limit 3"), |
| 79 | + Context.NONE); |
| 80 | + } |
| 81 | + |
| 82 | + /* |
| 83 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesFacetQuery.json |
| 84 | + */ |
| 85 | + /** |
| 86 | + * Sample code: Query with a facet request. |
| 87 | + * |
| 88 | + * @param manager Entry point to ResourceGraphManager. |
| 89 | + */ |
| 90 | + public static void queryWithAFacetRequest(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 91 | + manager |
| 92 | + .resourceProviders() |
| 93 | + .resourcesWithResponse( |
| 94 | + new QueryRequest() |
| 95 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 96 | + .withQuery( |
| 97 | + "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project id, name, location," |
| 98 | + + " resourceGroup, properties.storageProfile.osDisk.osType | limit 5") |
| 99 | + .withFacets( |
| 100 | + Arrays |
| 101 | + .asList( |
| 102 | + new FacetRequest() |
| 103 | + .withExpression("location") |
| 104 | + .withOptions( |
| 105 | + new FacetRequestOptions().withSortOrder(FacetSortOrder.DESC).withTop(3)), |
| 106 | + new FacetRequest() |
| 107 | + .withExpression("properties.storageProfile.osDisk.osType") |
| 108 | + .withOptions( |
| 109 | + new FacetRequestOptions().withSortOrder(FacetSortOrder.DESC).withTop(3)), |
| 110 | + new FacetRequest() |
| 111 | + .withExpression("nonExistingColumn") |
| 112 | + .withOptions( |
| 113 | + new FacetRequestOptions().withSortOrder(FacetSortOrder.DESC).withTop(3)), |
| 114 | + new FacetRequest() |
| 115 | + .withExpression("resourceGroup") |
| 116 | + .withOptions( |
| 117 | + new FacetRequestOptions() |
| 118 | + .withSortBy("tolower(resourceGroup)") |
| 119 | + .withSortOrder(FacetSortOrder.ASC) |
| 120 | + .withTop(3)), |
| 121 | + new FacetRequest() |
| 122 | + .withExpression("resourceGroup") |
| 123 | + .withOptions( |
| 124 | + new FacetRequestOptions() |
| 125 | + .withFilter("resourceGroup contains 'test'") |
| 126 | + .withTop(3)))), |
| 127 | + Context.NONE); |
| 128 | + } |
| 129 | + |
| 130 | + /* |
| 131 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesFilterQuery.json |
| 132 | + */ |
| 133 | + /** |
| 134 | + * Sample code: Filter resources. |
| 135 | + * |
| 136 | + * @param manager Entry point to ResourceGraphManager. |
| 137 | + */ |
| 138 | + public static void filterResources(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 139 | + manager |
| 140 | + .resourceProviders() |
| 141 | + .resourcesWithResponse( |
| 142 | + new QueryRequest() |
| 143 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 144 | + .withQuery( |
| 145 | + "Resources | project id, name, type, location | where type =~" |
| 146 | + + " 'Microsoft.Compute/virtualMachines' | limit 3"), |
| 147 | + Context.NONE); |
| 148 | + } |
| 149 | + |
| 150 | + /* |
| 151 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesSummarizeQuery.json |
| 152 | + */ |
| 153 | + /** |
| 154 | + * Sample code: Summarize resources by location. |
| 155 | + * |
| 156 | + * @param manager Entry point to ResourceGraphManager. |
| 157 | + */ |
| 158 | + public static void summarizeResourcesByLocation( |
| 159 | + com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 160 | + manager |
| 161 | + .resourceProviders() |
| 162 | + .resourcesWithResponse( |
| 163 | + new QueryRequest() |
| 164 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 165 | + .withQuery("Resources | project id, name, type, location | summarize by location"), |
| 166 | + Context.NONE); |
| 167 | + } |
| 168 | + |
| 169 | + /* |
| 170 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesPropertiesQuery.json |
| 171 | + */ |
| 172 | + /** |
| 173 | + * Sample code: Access a properties field. |
| 174 | + * |
| 175 | + * @param manager Entry point to ResourceGraphManager. |
| 176 | + */ |
| 177 | + public static void accessAPropertiesField(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 178 | + manager |
| 179 | + .resourceProviders() |
| 180 | + .resourcesWithResponse( |
| 181 | + new QueryRequest() |
| 182 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 183 | + .withQuery( |
| 184 | + "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by" |
| 185 | + + " tostring(properties.storageProfile.osDisk.osType)"), |
| 186 | + Context.NONE); |
| 187 | + } |
| 188 | + |
| 189 | + /* |
| 190 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesComplexQuery.json |
| 191 | + */ |
| 192 | + /** |
| 193 | + * Sample code: Complex query. |
| 194 | + * |
| 195 | + * @param manager Entry point to ResourceGraphManager. |
| 196 | + */ |
| 197 | + public static void complexQuery(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 198 | + manager |
| 199 | + .resourceProviders() |
| 200 | + .resourcesWithResponse( |
| 201 | + new QueryRequest() |
| 202 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 203 | + .withQuery( |
| 204 | + "Resources | project id, name, type, location | where type =~" |
| 205 | + + " 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_"), |
| 206 | + Context.NONE); |
| 207 | + } |
| 208 | + |
| 209 | + /* |
| 210 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesNextPageQuery.json |
| 211 | + */ |
| 212 | + /** |
| 213 | + * Sample code: Next page query. |
| 214 | + * |
| 215 | + * @param manager Entry point to ResourceGraphManager. |
| 216 | + */ |
| 217 | + public static void nextPageQuery(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 218 | + manager |
| 219 | + .resourceProviders() |
| 220 | + .resourcesWithResponse( |
| 221 | + new QueryRequest() |
| 222 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 223 | + .withQuery("Resources | where name contains 'test' | project id, name, type, location") |
| 224 | + .withOptions( |
| 225 | + new QueryRequestOptions() |
| 226 | + .withSkipToken("eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ==")), |
| 227 | + Context.NONE); |
| 228 | + } |
| 229 | + |
| 230 | + /* |
| 231 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesFirstPageQuery.json |
| 232 | + */ |
| 233 | + /** |
| 234 | + * Sample code: First page query. |
| 235 | + * |
| 236 | + * @param manager Entry point to ResourceGraphManager. |
| 237 | + */ |
| 238 | + public static void firstPageQuery(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 239 | + manager |
| 240 | + .resourceProviders() |
| 241 | + .resourcesWithResponse( |
| 242 | + new QueryRequest() |
| 243 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 244 | + .withQuery("Resources | where name contains 'test' | project id, name, type, location") |
| 245 | + .withOptions(new QueryRequestOptions().withTop(3).withSkip(0)), |
| 246 | + Context.NONE); |
| 247 | + } |
| 248 | + |
| 249 | + /* |
| 250 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesTenantBasicQuery.json |
| 251 | + */ |
| 252 | + /** |
| 253 | + * Sample code: Basic tenant query. |
| 254 | + * |
| 255 | + * @param manager Entry point to ResourceGraphManager. |
| 256 | + */ |
| 257 | + public static void basicTenantQuery(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 258 | + manager |
| 259 | + .resourceProviders() |
| 260 | + .resourcesWithResponse( |
| 261 | + new QueryRequest().withQuery("Resources | project id, name, type, location, tags | limit 3"), |
| 262 | + Context.NONE); |
| 263 | + } |
| 264 | + |
| 265 | + /* |
| 266 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesRandomPageQuery.json |
| 267 | + */ |
| 268 | + /** |
| 269 | + * Sample code: Random page query. |
| 270 | + * |
| 271 | + * @param manager Entry point to ResourceGraphManager. |
| 272 | + */ |
| 273 | + public static void randomPageQuery(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 274 | + manager |
| 275 | + .resourceProviders() |
| 276 | + .resourcesWithResponse( |
| 277 | + new QueryRequest() |
| 278 | + .withSubscriptions(Arrays.asList("cfbbd179-59d2-4052-aa06-9270a38aa9d6")) |
| 279 | + .withQuery("Resources | where name contains 'test' | project id, name, type, location") |
| 280 | + .withOptions(new QueryRequestOptions().withTop(2).withSkip(10)), |
| 281 | + Context.NONE); |
| 282 | + } |
| 283 | +} |
| 284 | +``` |
| 285 | + |
| 286 | +### ResourceProvider_ResourcesHistory |
| 287 | + |
| 288 | +```java |
| 289 | +import com.azure.core.util.Context; |
| 290 | +import com.azure.resourcemanager.resourcegraph.models.DateTimeInterval; |
| 291 | +import com.azure.resourcemanager.resourcegraph.models.ResourcesHistoryRequest; |
| 292 | +import com.azure.resourcemanager.resourcegraph.models.ResourcesHistoryRequestOptions; |
| 293 | +import java.time.OffsetDateTime; |
| 294 | +import java.util.Arrays; |
| 295 | + |
| 296 | +/** Samples for ResourceProvider ResourcesHistory. */ |
| 297 | +public final class ResourceProviderResourcesHistorySamples { |
| 298 | + /* |
| 299 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesHistoryMgsGet.json |
| 300 | + */ |
| 301 | + /** |
| 302 | + * Sample code: Resource History Management Group scope Query. |
| 303 | + * |
| 304 | + * @param manager Entry point to ResourceGraphManager. |
| 305 | + */ |
| 306 | + public static void resourceHistoryManagementGroupScopeQuery( |
| 307 | + com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 308 | + manager |
| 309 | + .resourceProviders() |
| 310 | + .resourcesHistoryWithResponse( |
| 311 | + new ResourcesHistoryRequest() |
| 312 | + .withQuery("where name =~ 'cpu-utilization' | project id, name, properties") |
| 313 | + .withOptions( |
| 314 | + new ResourcesHistoryRequestOptions() |
| 315 | + .withInterval( |
| 316 | + new DateTimeInterval() |
| 317 | + .withStart(OffsetDateTime.parse("2020-11-12T01:00:00.0000000Z")) |
| 318 | + .withEnd(OffsetDateTime.parse("2020-11-12T01:25:00.0000000Z")))) |
| 319 | + .withManagementGroups(Arrays.asList("e927f598-c1d4-4f72-8541-95d83a6a4ac8", "ProductionMG")), |
| 320 | + Context.NONE); |
| 321 | + } |
| 322 | + |
| 323 | + /* |
| 324 | + * x-ms-original-file: specification/resourcegraph/resource-manager/Microsoft.ResourceGraph/preview/2021-06-01-preview/examples/ResourcesHistoryGet.json |
| 325 | + */ |
| 326 | + /** |
| 327 | + * Sample code: Resource History Query. |
| 328 | + * |
| 329 | + * @param manager Entry point to ResourceGraphManager. |
| 330 | + */ |
| 331 | + public static void resourceHistoryQuery(com.azure.resourcemanager.resourcegraph.ResourceGraphManager manager) { |
| 332 | + manager |
| 333 | + .resourceProviders() |
| 334 | + .resourcesHistoryWithResponse( |
| 335 | + new ResourcesHistoryRequest() |
| 336 | + .withSubscriptions(Arrays.asList("a7f33fdb-e646-4f15-89aa-3a360210861e")) |
| 337 | + .withQuery("where name =~ 'cpu-utilization' | project id, name, properties") |
| 338 | + .withOptions( |
| 339 | + new ResourcesHistoryRequestOptions() |
| 340 | + .withInterval( |
| 341 | + new DateTimeInterval() |
| 342 | + .withStart(OffsetDateTime.parse("2020-11-12T01:00:00.0000000Z")) |
| 343 | + .withEnd(OffsetDateTime.parse("2020-11-12T01:25:00.0000000Z")))), |
| 344 | + Context.NONE); |
| 345 | + } |
| 346 | +} |
| 347 | +``` |
| 348 | + |
0 commit comments