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