### Example Unreleased Dependency Entry (Azure SDK for Java) Source: https://github.com/azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md A specific example of an unreleased dependency entry for `azure-core` in the `version_client.txt` file. ```Text unreleased_com.azure:azure-core;1.2.0 ``` -------------------------------- ### Install Azure Communication Services Java Packages Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/communication/CONTRIBUTING.md Installs all local dependencies for the Azure Communication Services Java packages using Maven, skipping tests. This is the initial setup step required before running tests. ```Maven mvn verify -DskipTests ``` -------------------------------- ### Starting Virtual Machine Instances with Azure SCVMM SDK Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/scvmm/azure-resourcemanager-scvmm/SAMPLE.md This snippet provides Java sample code for starting a Virtual Machine Instance using the Azure SCVMM SDK. It includes examples demonstrating the minimum and maximum parameter sets for initiating the start operation. ```java /** * Samples for VirtualMachineInstances Start. */ public final class VirtualMachineInstancesStartSamples { /* * x-ms-original-file: specification/scvmm/resource-manager/Microsoft.ScVmm/stable/2023-10-07/examples/ * VirtualMachineInstances_Start_MinimumSet_Gen.json */ /** * Sample code: VirtualMachineInstances_Start_MinimumSet. * * @param manager Entry point to ScvmmManager. */ public static void virtualMachineInstancesStartMinimumSet(com.azure.resourcemanager.scvmm.ScvmmManager manager) { manager.virtualMachineInstances().start("gtgclehcbsyave", com.azure.core.util.Context.NONE); } /* * x-ms-original-file: specification/scvmm/resource-manager/Microsoft.ScVmm/stable/2023-10-07/examples/ * VirtualMachineInstances_Start_MaximumSet_Gen.json */ /** * Sample code: VirtualMachineInstances_Start_MaximumSet. * * @param manager Entry point to ScvmmManager. */ public static void virtualMachineInstancesStartMaximumSet(com.azure.resourcemanager.scvmm.ScvmmManager manager) { manager.virtualMachineInstances().start("gtgclehcbsyave", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Starting SAP Application Server Instances in Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/workloadssapvirtualinstance/azure-resourcemanager-workloadssapvirtualinstance/SAMPLE.md This snippet shows how to start an SAP Application Server Instance using the Azure SDK for Java. It includes two examples: one to start just the SAP instance and another to start both the instance and its underlying virtual machine. It requires the WorkloadsSapVirtualInstanceManager and the StartRequest model. ```Java import com.azure.resourcemanager.workloadssapvirtualinstance.models.StartRequest; /** * Samples for SapApplicationServerInstances Start. */ public final class SapApplicationServerInstancesStartSamples { /* * x-ms-original-file: 2024-09-01/SapApplicationServerInstances_StartInstanceVM.json */ /** * Sample code: Start Virtual Machine and the SAP Application Server Instance on it. * * @param manager Entry point to WorkloadsSapVirtualInstanceManager. */ public static void startVirtualMachineAndTheSAPApplicationServerInstanceOnIt( com.azure.resourcemanager.workloadssapvirtualinstance.WorkloadsSapVirtualInstanceManager manager) { manager.sapApplicationServerInstances() .start("test-rg", "X00", "app01", new StartRequest().withStartVm(true), com.azure.core.util.Context.NONE); } /* * x-ms-original-file: 2024-09-01/SapApplicationServerInstances_StartInstance.json */ /** * Sample code: Start the SAP Application Server Instance. * * @param manager Entry point to WorkloadsSapVirtualInstanceManager. */ public static void startTheSAPApplicationServerInstance( com.azure.resourcemanager.workloadssapvirtualinstance.WorkloadsSapVirtualInstanceManager manager) { manager.sapApplicationServerInstances() .start("test-rg", "X00", "app01", new StartRequest(), com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Install Code Quality Reports Maven Module Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/vision/azure-ai-vision-imageanalysis/src/test/java/com/azure/ai/vision/imageanalysis/README.md Runs the Maven install goal on the POM file for the engineering code quality reports module. This is a setup step required before running tests. ```Bash mvn install -f eng\code-quality-reports\pom.xml ``` -------------------------------- ### Install sdk-build-tools Locally with Maven Source: https://github.com/azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md Install the 'sdk-build-tools' project locally using Maven to resolve a Checkstyle error encountered during local builds. This is necessary because the project is not released to Maven Central and must be built from the local 'eng' folder. ```Shell mvn clean install -f eng/code-quality-reports/pom.xml ``` -------------------------------- ### Example Pre-Script for Creating Certificate (PowerShell) Source: https://github.com/azure/azure-sdk-for-java/blob/main/eng/common/TestResources/README.md Provides a snippet from a test-resources-pre.ps1 script, showing how to import a module and create an X.509 certificate. This demonstrates the use of pre-scripts to perform setup tasks or create artifacts needed before the main resource provisioning defined in test-resources.json. ```PowerShell Import-Module -Name ./eng/common/scripts/X509Certificate2 $cert = New-X509Certificate2 -SubjectName 'E=opensource@microsoft.com, CN=Azure SDK, OU=Azure SDK, O=Microsoft, L=Frisco, S=TX, C=US' -ValidDays 3652 ``` -------------------------------- ### Fetching Dev Center Resources (Catalogs, Definitions, Types) in Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/devcenter/azure-developer-devcenter/src/samples/README.md Example demonstrating how to list available catalogs, environment definitions within a specific catalog, and environment types using the `DeploymentEnvironmentsClient`. It iterates through the results and prints their names. ```Java // Fetch available environment definitions and environment types PagedIterable catalogs = environmentsClient.listCatalogs(projectName); for (DevCenterCatalog catalog: catalogs) { System.out.println(catalog.getName()); } // Use the first catalog in the list String catalogName = catalogs.iterator().next().getName(); PagedIterable environmentDefinitions = environmentsClient.listEnvironmentDefinitionsByCatalog(projectName, catalogName); for (EnvironmentDefinition environmentDefinition: environmentDefinitions) { System.out.println(environmentDefinition.getName()); } // Use the first environment definition in the list String envDefinitionName = environmentDefinitions.iterator().next().getName(); PagedIterable environmentTypes = environmentsClient.listEnvironmentTypes(projectName); for (DevCenterEnvironmentType envType: environmentTypes) { System.out.println(envType.getName()); } // Use the first environment type in the list String envTypeName = environmentTypes.iterator().next().getName(); ``` -------------------------------- ### Getting Queue Service Properties (V12 Async Minimum) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/storage/azure-storage-queue/migrationGuides/V8_V12.md Illustrates the minimum overload API in Azure SDK for Java V12 for retrieving queue service properties asynchronously. Note: The code signature shown is identical to the V8 sync example, which may be a documentation artifact, but represents the minimum async pattern described. ```Java public QueueServiceProperties getProperties() ``` -------------------------------- ### Run Maven Install Command Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai-realtime/README.md Executes the Maven install goal from the command line. This command downloads project dependencies from configured repositories (including the dev feed) and builds the project. ```commandline mvn install ``` -------------------------------- ### Starting Cosmos DB Emulator with Recommended Parameters - Shell Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-cosmos/docs/setup.md This shell command provides the recommended parameters for starting the Azure Cosmos DB Emulator for local development and testing, particularly for running SDK integration tests. The parameters enable preview features, the SQL compute endpoint, disable rate limiting, set a partition count of 50, and enforce strong consistency. ```shell /enablepreview /EnableSqlComputeEndpoint /disableratelimiting /partitioncount=50 /consistency=Strong ``` -------------------------------- ### Creating Azure WebPubSub Client from Access URL (Quick Start) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/webpubsub/azure-messaging-webpubsub-client/README.md This Java snippet demonstrates a quick way to instantiate the WebPubSubClient using a client access URL obtained directly from the Azure Portal. This method is suitable for testing or quick starts but typically not recommended for production environments. ```Java WebPubSubClient client = new WebPubSubClientBuilder() .clientAccessUrl("") .buildClient(); ``` -------------------------------- ### Start Test Proxy Server in @BeforeAll - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/core/azure-core-test/TestProxyMigrationGuide.md The `setupTestProxy` method, typically annotated with `@BeforeAll`, is responsible for initializing and starting the test proxy server before tests run. This method is provided by `TestProxyTestBase`. ```Java public class MyTest extends TestProxyTestBase { // method in TestProxyTestBase @BeforeAll public static void setupTestProxy(TestInfo testInfo) { // Start the test proxy server testProxyManager.startProxy(); } } ``` -------------------------------- ### Setup AutoRest Java Environment Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/servicebus/azure-messaging-servicebus/swagger/README.md Provides the necessary commands to fork, clone, and build the AutoRest Java repository, install npm dependencies, and install AutoRest globally using PowerShell. ```PowerShell Fork and clone https://github.com/Azure/autorest.java git checkout main git submodule update --init --recursive mvn package -Dlocal npm install npm install -g autorest ``` -------------------------------- ### JSON Example After Sanitizer Removal Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/core/azure-core-test/TestProxyMigrationGuide.md This JSON snippet shows the same example response body *after* the default sanitizer targeting the 'id' key has been removed. The 'id' field now contains its original, sensitive value ('1234-5678-9012-3456'). ```json { "id": "1234-5678-9012-3456", "name": "test" } ``` -------------------------------- ### List Configurations (Java) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/advisor/azure-resourcemanager-advisor/SAMPLE.md This sample demonstrates how to list all Advisor configurations available using the Azure SDK for Java. ```Java /** * Samples for Configurations List. */ public final class ConfigurationsListSamples { /* * x-ms-original-file: * specification/advisor/resource-manager/Microsoft.Advisor/stable/2020-01-01/examples/ListConfigurations.json */ /** * Sample code: GetConfigurations. * * @param manager Entry point to AdvisorManager. */ public static void getConfigurations(com.azure.resourcemanager.advisor.AdvisorManager manager) { manager.configurations().list(com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Installing Cluster Libraries using Azure HDInsight Containers SDK (Java) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/hdinsight/azure-resourcemanager-hdinsight-containers/SAMPLE.md This snippet shows how to install new libraries onto an HDInsight on AKS cluster using the Azure SDK for Java. It provides examples for installing PyPi and Maven packages with specific versions and remarks. ```java manager.clusterLibraries() .manageLibraries("hiloResourceGroup", "clusterPool", "cluster", new ClusterLibraryManagementOperation().withProperties( new ClusterLibraryManagementOperationProperties().withAction(LibraryManagementAction.INSTALL) .withLibraries(Arrays.asList( new ClusterLibraryInner() .withProperties(new PyPiLibraryProperties().withRemarks("PyPi packages.") .withName("requests") .withVersion("2.31.0")), new ClusterLibraryInner() .withProperties(new MavenLibraryProperties().withRemarks("Maven packages.") .withGroupId("org.apache.flink") .withName("flink-connector-kafka") .withVersion("3.0.2-1.18"))))), com.azure.core.util.Context.NONE); ``` -------------------------------- ### Starting VMware CloudSimple Virtual Machine - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/vmwarecloudsimple/azure-resourcemanager-vmwarecloudsimple/SAMPLE.md Samples for VirtualMachines Start. Sample code: StartVirtualMachine. Demonstrates starting a specific virtual machine using the Azure SDK for Java. ```Java /** * Samples for VirtualMachines Start. */ public final class VirtualMachinesStartSamples { /* * x-ms-original-file: * specification/vmwarecloudsimple/resource-manager/Microsoft.VMwareCloudSimple/stable/2019-04-01/examples/ * StartVirtualMachine.json */ /** * Sample code: StartVirtualMachine. * * @param manager Entry point to VMwareCloudSimpleManager. */ public static void startVirtualMachine(com.azure.resourcemanager.vmwarecloudsimple.VMwareCloudSimpleManager manager) { manager.virtualMachines() .start("myResourceGroup", "https://management.azure.com/", "myVirtualMachine", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Start Service - Azure Data Migration - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/datamigration/azure-resourcemanager-datamigration/SAMPLE.md This sample demonstrates how to start an existing Azure Data Migration Service resource using the Azure SDK for Java. It uses the `start` method. ```java /** * Samples for Services Start. */ public final class ServicesStartSamples { /* * x-ms-original-file: * specification/datamigration/resource-manager/Microsoft.DataMigration/stable/2018-04-19/examples/Services_Start. * json */ /** * Sample code: Services_Start. * * @param manager Entry point to DataMigrationManager. */ public static void servicesStart(com.azure.resourcemanager.datamigration.DataMigrationManager manager) { manager.services().start("DmsSdkRg", "DmsSdkService", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### JSON Example Before Sanitizer Removal Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/core/azure-core-test/TestProxyMigrationGuide.md This JSON snippet shows an example response body *before* a default sanitizer (specifically the one targeting the 'id' key) has been removed. The 'id' field's original value has been replaced with 'Sanitized'. ```json { "id": "Sanitized", "name": "test" } ``` -------------------------------- ### Installing Updates on Data Box Edge Device - Azure SDK for Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/databoxedge/azure-resourcemanager-databoxedge/SAMPLE.md Demonstrates how to initiate the installation of updates on an Azure Data Box Edge device using the Azure SDK for Java. It requires the device name, resource group name, and a context object to start the installation process. ```java /** * Samples for Devices InstallUpdates. */ public final class DevicesInstallUpdatesSamples { /* * x-ms-original-file: * specification/databoxedge/resource-manager/Microsoft.DataBoxEdge/stable/2019-08-01/examples/InstallUpdatesPost. * json */ /** * Sample code: InstallUpdatesPost. * * @param manager Entry point to DataBoxEdgeManager. */ public static void installUpdatesPost(com.azure.resourcemanager.databoxedge.DataBoxEdgeManager manager) { manager.devices().installUpdates("testedgedevice", "GroupForEdgeAutomation", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Creating a Dev Center Environment in Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/devcenter/azure-developer-devcenter/src/samples/README.md Shows the process of creating a new Dev Center environment using the `DeploymentEnvironmentsClient`. It requires specifying the project name, user ID, desired environment name, environment type, catalog, and environment definition. The example waits for the creation operation to complete. ```Java // Create an environment SyncPoller environmentCreateResponse = environmentsClient.beginCreateOrUpdateEnvironment(projectName, "me", new DevCenterEnvironment("myEnvironmentName", envTypeName, catalogName, envDefinitionName)); environmentCreateResponse.waitForCompletion(); DevCenterEnvironment environment = environmentCreateResponse.getFinalResult(); ``` -------------------------------- ### V8 Azure Storage Blob Minimum Overload Example Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/storage/azure-storage-blob/migrationGuides/V8_V12.md Example of a typical minimum overload API signature in Azure Storage Blob SDK V8, returning the value directly. ```Java public BlobContainerProperties getProperties() ``` -------------------------------- ### Run Setup Script (PowerShell) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/digitaltwins/azure-digitaltwins-core/src/test/resources/prerequisite/prerequisite readme.md Executes the PowerShell setup script to configure test resources, which outputs the test-resources.bicep file in the specified directory. ```PowerShell .\setup.ps1 ``` -------------------------------- ### Listing Products Azure Stack Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/azurestack/azure-resourcemanager-azurestack/SAMPLE.md Shows how to list Azure Stack products using the simpler `list` method. It takes the registration name and context as parameters. ```Java /** * Samples for Products List. */ public final class ProductsListSamples { /* * x-ms-original-file: * specification/azurestack/resource-manager/Microsoft.AzureStack/stable/2022-06-01/examples/Product/List.json */ /** * Sample code: Returns a list of products. * * @param manager Entry point to AzureStackManager. */ public static void returnsAListOfProducts(com.azure.resourcemanager.azurestack.AzureStackManager manager) { manager.products().list("azurestack", "testregistration", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### V12 Azure Storage Blob Minimum Overload Example (Async) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/storage/azure-storage-blob/migrationGuides/V8_V12.md Example of a minimum overload API signature in the asynchronous client of Azure Storage Blob SDK V12, returning the value directly. ```Java public BlobContainerProperties getProperties() ``` -------------------------------- ### SapDatabaseInstances_Get Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/workloadssapvirtualinstance/azure-resourcemanager-workloadssapvirtualinstance/SAMPLE.md Sample demonstrating how to start the virtual machine(s) and the SAP central services instance on it using the Azure Workloads SAP Virtual Instance manager. ```Java import com.azure.resourcemanager.workloadssapvirtualinstance.models.StartRequest; /** * Samples for SapCentralServerInstances Start. */ public final class SapCentralServerInstancesStartSamples { /* * x-ms-original-file: 2024-09-01/SapCentralInstances_StartInstanceVM.json */ /** * Sample code: Start the virtual machine(s) and the SAP central services instance on it. * * @param manager Entry point to WorkloadsSapVirtualInstanceManager. */ public static void startTheVirtualMachineSAndTheSAPCentralServicesInstanceOnIt( com.azure.resourcemanager.workloadssapvirtualinstance.WorkloadsSapVirtualInstanceManager manager) { manager.sapCentralServerInstances() .start("test-rg", "X00", "centralServer", new StartRequest().withStartVm(true), com.azure.core.util.Context.NONE); } /* * x-ms-original-file: 2024-09-01/SapCentralInstances_StartInstance.json */ /** * Sample code: Start the SAP Central Services Instance. * * @param manager Entry point to WorkloadsSapVirtualInstanceManager. */ public static void startTheSAPCentralServicesInstance( com.azure.resourcemanager.workloadssapvirtualinstance.WorkloadsSapVirtualInstanceManager manager) { manager.sapCentralServerInstances() .start("test-rg", "X00", "centralServer", new StartRequest(), com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Get Azure Storage Account Connection String using Azure CLI Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/tables/azure-data-tables/README.md Retrieves the connection string for an Azure Storage Account using the Azure Command-Line Interface (CLI). Requires specifying the resource group and account name. ```bash az storage account show-connection-string \ --resource-group \ --name ``` -------------------------------- ### Starting a Server - Azure MySQL - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/mysqlflexibleserver/azure-resourcemanager-mysqlflexibleserver/SAMPLE.md This sample code demonstrates how to start an Azure Database for MySQL Flexible Server using the Azure SDK for Java. It calls the `start` method on the `servers()` manager object, providing the resource group and server name. ```Java /** * Samples for Servers Start. */ public final class ServersStartSamples { /* * x-ms-original-file: * specification/mysql/resource-manager/Microsoft.DBforMySQL/legacy/stable/2021-05-01/examples/ServerStart.json */ /** * Sample code: Start a server. * * @param manager Entry point to MySqlManager. */ public static void startAServer(com.azure.resourcemanager.mysqlflexibleserver.MySqlManager manager) { manager.servers().start("TestGroup", "testserver", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Start Kafka Connect Distributed Worker - Bash Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-cosmos-kafka-connect/docs/Confluent_Cloud_Setup.md Changes directory to the unzipped Confluent Platform folder and starts the Kafka Connect distributed worker process using the specified properties file. This worker will host the Kafka connectors. ```Bash cd unzipped confluent folder ./bin/connect-distributed ./etc/distributed.properties ``` -------------------------------- ### Starting Azure MySQL Server - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/mysql/azure-resourcemanager-mysql/SAMPLE.md This sample demonstrates how to start an Azure MySQL server using the resource group name, server name, and context. ```Java import com.azure.core.util.Context; /** Samples for Servers Start. */ public final class ServersStartSamples { /* * x-ms-original-file: specification/mysql/resource-manager/Microsoft.DBforMySQL/stable/2020-01-01/examples/ServerStart.json */ /** * Sample code: ServerStart. * * @param manager Entry point to MySqlManager. */ public static void serverStart(com.azure.resourcemanager.mysql.MySqlManager manager) { manager.servers().start("TestGroup", "testserver", Context.NONE); } } ``` -------------------------------- ### Get ISP Cache Node Install Details - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/connectedcache/azure-resourcemanager-connectedcache/SAMPLE.md Provides a sample for retrieving the installation details of an ISP Cache Node resource using the Azure Connected Cache SDK for Java. It calls the `getCacheNodeInstallDetailsWithResponse` method with the necessary resource identifiers. ```java /** * Samples for IspCacheNodesOperations GetCacheNodeInstallDetails. */ public final class IspCacheNodesOperationsGetCacheNodeInstallDetailsSamples { /* * x-ms-original-file: 2023-05-01-preview/IspCacheNodesOperations_GetCacheNodeInstallDetails_MaximumSet_Gen.json */ /** * Sample code: ispCacheNode resource get install details - generated by [MaximumSet] rule. * * @param manager Entry point to ConnectedCacheManager. */ public static void ispCacheNodeResourceGetInstallDetailsGeneratedByMaximumSetRule( com.azure.resourcemanager.connectedcache.ConnectedCacheManager manager) { manager.ispCacheNodesOperations() .getCacheNodeInstallDetailsWithResponse("rgConnectedCache", "MccRPTest1", "MCCCachenode1", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Creating Azure MySQL Server and Helper Method - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/mysql/azure-resourcemanager-mysql/SAMPLE.md This snippet shows the final steps of creating an Azure MySQL server with specific configuration (restore point, tags, SKU) and includes a helper method for creating a map from varargs. ```Java .withRestorePointInTime(OffsetDateTime.parse("2017-12-14T00:00:37.467Z"))) .withTags(mapOf("ElasticServer", "1")) .withSku( new Sku().withName("GP_Gen5_2").withTier(SkuTier.GENERAL_PURPOSE).withCapacity(2).withFamily("Gen5")) .create(); } @SuppressWarnings("unchecked") private static Map mapOf(Object... inputs) { Map map = new HashMap<>(); for (int i = 0; i < inputs.length; i += 2) { String key = (String) inputs[i]; T value = (T) inputs[i + 1]; map.put(key, value); } return map; } } ``` -------------------------------- ### Getting Dapr Components using Azure SDK for Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/appcontainers/azure-resourcemanager-appcontainers/SAMPLE.md These samples illustrate how to retrieve details of a Dapr component in an Azure Container App environment using the Azure SDK for Java. They show examples of getting a component that uses a secret store and getting a component with associated secrets. The operation requires the resource group name, environment name, and the Dapr component name. ```Java /** * Samples for DaprComponents Get. */ public final class DaprComponentsGetSamples { /* * x-ms-original-file: specification/app/resource-manager/Microsoft.App/stable/2025-01-01/examples/ * DaprComponents_Get_SecretStoreComponent.json */ /** * Sample code: Get Dapr Component with secret store component. * * @param manager Entry point to ContainerAppsApiManager. */ public static void getDaprComponentWithSecretStoreComponent( com.azure.resourcemanager.appcontainers.ContainerAppsApiManager manager) { manager.daprComponents() .getWithResponse("examplerg", "myenvironment", "reddog", com.azure.core.util.Context.NONE); } /* * x-ms-original-file: * specification/app/resource-manager/Microsoft.App/stable/2025-01-01/examples/DaprComponents_Get_Secrets.json */ /** * Sample code: Get Dapr Component with secrets. * * @param manager Entry point to ContainerAppsApiManager. */ public static void getDaprComponentWithSecrets(com.azure.resourcemanager.appcontainers.ContainerAppsApiManager manager) { manager.daprComponents() .getWithResponse("examplerg", "myenvironment", "reddog", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Example File Share URL Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/storage/azure-storage-file-share/README.md Provides an example of a valid URL addressing a specific Azure File Share. ```URL https://myaccount.file.core.windows.net/images-to-download ``` -------------------------------- ### Getting Boundary Polygons with Azure Maps Search Client - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-search/README.md This Java example shows how to retrieve boundary polygons for a given geographic position using the getPolygons method of the MapsSearchClient. It includes examples for a simple call and a call that returns a Response object. ```Java System.out.println("Get Polygons:"); GeoPosition coordinates = new GeoPosition(-122.204141, 47.61256); Boundary result = client.getPolygons(coordinates, null, BoundaryResultTypeEnum.LOCALITY, ResolutionEnum.SMALL); //with response Response response = client.getPolygonsWithResponse(coordinates, null, BoundaryResultTypeEnum.LOCALITY, ResolutionEnum.SMALL, Context.NONE); ``` -------------------------------- ### Running generate-assets-json.ps1 with -InitialPush (Tool) Source: https://github.com/azure/azure-sdk-for-java/blob/main/eng/common/testproxy/onboarding/README.md Shows how to run the `generate-assets-json.ps1` script from a specific service directory (`sdk/attestation`) using the `-InitialPush` flag. This flag triggers the initial data movement to the assets repository. This example assumes the test proxy tool is being used directly. ```powershell # calling transition script against tool, given local clones of azure-sdk-for-java and azure-sdk-tools cd c:/src/azure-sdk-for-java/sdk/attestation /generate-assets-json.ps1 -InitialPush ``` -------------------------------- ### Getting Azure SCVMM Guest Agents (Java) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/scvmm/azure-resourcemanager-scvmm/SAMPLE.md This code snippet demonstrates how to retrieve Azure SCVMM Guest Agents using the Azure SDK for Java. It includes examples for both the maximum and minimum parameter sets required for the Get operation. The code requires an initialized ScvmmManager. ```Java /** * Samples for GuestAgents Get. */ public final class GuestAgentsGetSamples { /* * x-ms-original-file: * specification/scvmm/resource-manager/Microsoft.ScVmm/stable/2023-10-07/examples/GuestAgents_Get_MaximumSet_Gen. * json */ /** * Sample code: GuestAgents_Get_MaximumSet. * * @param manager Entry point to ScvmmManager. */ public static void guestAgentsGetMaximumSet(com.azure.resourcemanager.scvmm.ScvmmManager manager) { manager.guestAgents().getWithResponse("gtgclehcbsyave", com.azure.core.util.Context.NONE); } /* * x-ms-original-file: * specification/scvmm/resource-manager/Microsoft.ScVmm/stable/2023-10-07/examples/GuestAgents_Get_MinimumSet_Gen. * json */ /** * Sample code: GuestAgents_Get_MinimumSet. * * @param manager Entry point to ScvmmManager. */ public static void guestAgentsGetMinimumSet(com.azure.resourcemanager.scvmm.ScvmmManager manager) { manager.guestAgents().getWithResponse("gtgclehcbsyave", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Instantiating KeyVaultClient (Old SDK) - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/keyvault/azure-security-keyvault-certificates/migration_guide.md Shows how to create a `KeyVaultClient` instance in the older `azure-keyvault` library by passing a `KeyVaultCredentials` object directly to the constructor. This method was used for client instantiation before the introduction of client builders. ```Java import com.microsoft.azure.keyvault.KeyVaultClient; import com.microsoft.azure.keyvault.authentication.KeyVaultCredentials; KeyVaultCredentials keyVaultCredentials = new MyKeyVaultCredentials("", ""); KeyVaultClient keyVaultClient = new KeyVaultClient(keyVaultCredentials); ``` -------------------------------- ### Getting Enterprise MCC Cache Node Install Details with Azure SDK for Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/connectedcache/azure-resourcemanager-connectedcache/SAMPLE.md This sample demonstrates how to retrieve the installation details for an Enterprise MCC Cache Node using the Azure SDK for Java. It uses the getCacheNodeInstallDetailsWithResponse method to obtain necessary properties. ```Java /** * Samples for EnterpriseMccCacheNodesOperations GetCacheNodeInstallDetails. */ public final class EnterpriseMccCacheNodesOperationsGetCacheNodeInstallDetailsSamples { /* * x-ms-original-file: * 2023-05-01-preview/EnterpriseMccCacheNodesOperations_GetCacheNodeInstallDetails_MaximumSet_Gen.json */ /** * Sample code: Gets required properties for enterprise Mcc CacheNode resource install key details - generated by * [MaximumSet] rule. * * @param manager Entry point to ConnectedCacheManager. */ public static void getsRequiredPropertiesForEnterpriseMccCacheNodeResourceInstallKeyDetailsGeneratedByMaximumSetRule( com.azure.resourcemanager.connectedcache.ConnectedCacheManager manager) { manager.enterpriseMccCacheNodesOperations() .getCacheNodeInstallDetailsWithResponse("rgConnectedCache", "fzwxcjmdpxxzayecabqqlh", "ccexmqqttritxvtctivraso", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Start SAP Database Instance - Azure Workloads Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/workloadssapvirtualinstance/azure-resourcemanager-workloadssapvirtualinstance/SAMPLE.md Shows how to start an SAP database instance using the Azure Workloads SDK for Java. It calls the start method on the sapDatabaseInstances client, providing resource group, SAP Virtual Instance name, database instance name, an empty StartRequest, and context. ```Java import com.azure.resourcemanager.workloadssapvirtualinstance.models.StartRequest; /** * Samples for SapDatabaseInstances Start. */ public final class SapDatabaseInstancesStartSamples { /* * x-ms-original-file: 2024-09-01/SapDatabaseInstances_StartInstance.json */ /** * Sample code: Start the database instance of the SAP system. * * @param manager Entry point to WorkloadsSapVirtualInstanceManager. */ public static void startTheDatabaseInstanceOfTheSAPSystem( com.azure.resourcemanager.workloadssapvirtualinstance.WorkloadsSapVirtualInstanceManager manager) { manager.sapDatabaseInstances() .start("test-rg", "X00", "db0", new StartRequest(), com.azure.core.util.Context.NONE); } /* * x-ms-original-file: 2024-09-01/SapDatabaseInstances_StartInstanceVM.json */ /** * Sample code: Start Virtual Machine and the database instance of the SAP system on it. * * @param manager Entry point to WorkloadsSapVirtualInstanceManager. */ public static void startVirtualMachineAndTheDatabaseInstanceOfTheSAPSystemOnIt( com.azure.resourcemanager.workloadssapvirtualinstance.WorkloadsSapVirtualInstanceManager manager) { manager.sapDatabaseInstances() .start("test-rg", "X00", "db0", new StartRequest().withStartVm(true), com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Performing Cross-Entity Transaction (Newer Approach) - Azure Service Bus Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/servicebus/azure-messaging-servicebus/migration-guide.md This snippet demonstrates the current method for cross-entity transactions using ServiceBusClientBuilder with enableCrossEntityTransactions(). Clients for all involved entities are created using the same builder. The first entity an operation occurs on becomes the 'send-via'. The example shows sending a message, receiving it, starting a transaction using createTransaction(), completing the message with the transaction context, sending messages to destinations with the transaction context, and committing the transaction. ```java final String intermediateQueue = "intermediate-queue"; final String destination1 = "destination-1"; final String destination2 = "destination-2"; // Use same builder to create the client involved in cross entity transaction. ServiceBusClientBuilder builder = new ServiceBusClientBuilder().connectionString(connectionString) .enableCrossEntityTransactions(); // Initialize sender final ServiceBusSenderClient intermediateQueueSender = builder.sender().queueName(intermediateQueue).buildClient(); final ServiceBusReceiverClient intermediateQueueReceiver = builder.receiver().queueName(intermediateQueue).buildClient(); final ServiceBusSenderClient destination1Sender = builder.sender().queueName(destination1).buildClient(); final ServiceBusSenderClient destination2Sender = builder.sender().queueName(destination2).buildClient(); // send message intermediateQueueSender.sendMessage(new ServiceBusMessage("Message.")); intermediateQueueReceiver.receiveMessages(1).stream().forEach(message -> { // Process message. The message lock is renewed for up to 1 minute. System.out.printf("Sequence #: %s. Contents: %s%n", message.getSequenceNumber(), message.getBody()); //Start a cross entity transaction ServiceBusTransactionContext transactionId = destination1Sender.createTransaction(); intermediateQueueReceiver.complete(message, new CompleteOptions().setTransactionContext(transactionId)); destination1Sender.sendMessage(new ServiceBusMessage("Message Processed."), transactionId); destination2Sender.sendMessage(new ServiceBusMessage("Message Processed."), transactionId); destination1Sender.commitTransaction(transactionId); System.out.printf("Cross entity Transaction complete for Message id: %s.%n", message.getMessageId()); }); ``` -------------------------------- ### Get Route Directions - Azure Maps Route - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-route/README.md Illustrates how to get basic route directions between two points using the Azure Maps Route SDK for Java. It defines the start and end points and calls `getRouteDirections` to retrieve the route information and report. ```java System.out.println("Get route directions"); List routePoints = Arrays.asList( new GeoPosition(13.42936, 52.50931), new GeoPosition(13.43872, 52.50274)); RouteDirectionsOptions routeOptions = new RouteDirectionsOptions(routePoints); RouteDirections directions = client.getRouteDirections(routeOptions); RouteReport report = directions.getReport(); // get the report and use it ``` -------------------------------- ### Defining SAP Virtual Instance (Start) - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/workloadssapvirtualinstance/azure-resourcemanager-workloadssapvirtualinstance/SAMPLE.md Shows the initial steps in Java for defining a SAP Virtual Instance resource using the Azure SDK, including specifying name, region, resource group, tags, environment, product, and starting the infrastructure configuration. ```Java manager.sapVirtualInstances() .define("X00") .withRegion("eastus2") .withExistingResourceGroup("test-rg") .withTags(mapOf("created by", "azureuser")) .withProperties(new SapVirtualInstanceProperties().withEnvironment(SapEnvironmentType.PROD) .withSapProduct(SapProductType.S4HANA) .withConfiguration(new DeploymentWithOSConfiguration().withAppLocation("eastus") .withInfrastructureConfiguration(new ThreeTierConfiguration() ``` -------------------------------- ### List Things using Azure SDK for Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/template/azure-sdk-template-three/README.md Shows how to use the `listThings` method on the client to retrieve a list of Thing objects from the service. Note that a 404 exception is thrown if no Things are found. ```java List things = client.listThings(); ``` -------------------------------- ### Get Azure SCVMM Availability Set by Resource Group - Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/scvmm/azure-resourcemanager-scvmm/SAMPLE.md This sample class demonstrates how to retrieve a specific Azure SCVMM Availability Set by its resource group and name using the Azure SDK for Java. It includes examples for both minimum and maximum parameter sets for the get operation. ```java /** * Samples for AvailabilitySets GetByResourceGroup. */ public final class AvailabilitySetsGetByResourceGroupSamples { /* * x-ms-original-file: specification/scvmm/resource-manager/Microsoft.ScVmm/stable/2023-10-07/examples/ * AvailabilitySets_Get_MinimumSet_Gen.json */ /** * Sample code: AvailabilitySets_Get_MinimumSet. * * @param manager Entry point to ScvmmManager. */ public static void availabilitySetsGetMinimumSet(com.azure.resourcemanager.scvmm.ScvmmManager manager) { manager.availabilitySets().getByResourceGroupWithResponse("rgscvmm", "V", com.azure.core.util.Context.NONE); } /* * x-ms-original-file: specification/scvmm/resource-manager/Microsoft.ScVmm/stable/2023-10-07/examples/ * AvailabilitySets_Get_MaximumSet_Gen.json */ /** * Sample code: AvailabilitySets_Get_MaximumSet. * * @param manager Entry point to ScvmmManager. */ public static void availabilitySetsGetMaximumSet(com.azure.resourcemanager.scvmm.ScvmmManager manager) { manager.availabilitySets().getByResourceGroupWithResponse("rgscvmm", "-", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Listing Start Menu Items using Azure Desktop Virtualization SDK for Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/desktopvirtualization/azure-resourcemanager-desktopvirtualization/SAMPLE.md Provides an example of listing start menu items for an application group using the Azure Desktop Virtualization SDK for Java. Allows filtering and pagination parameters to control the results. ```Java /** * Samples for StartMenuItems List. */ public final class StartMenuItemsListSamples { /* * x-ms-original-file: * specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/stable/2024-04-03/examples/ * StartMenuItem_List.json */ /** * Sample code: StartMenuItem_List. * * @param manager Entry point to DesktopVirtualizationManager. */ public static void startMenuItemList(com.azure.resourcemanager.desktopvirtualization.DesktopVirtualizationManager manager) { manager.startMenuItems() .list("resourceGroup1", "applicationGroup1", null, null, null, com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Creating or Updating a Solution for Azure AgriFood Platform (Java) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/agrifood/azure-resourcemanager-agrifood/SAMPLE.md This sample demonstrates how to create or update a solution associated with an Azure AgriFood Platform resource using the Java SDK. It defines a new solution with specified properties like SaaS subscription details and marketplace information, then calls the `create` method. Includes a helper `mapOf` method. ```java import com.azure.resourcemanager.agrifood.models.SolutionProperties; import java.util.HashMap; import java.util.Map; /** * Samples for Solutions CreateOrUpdate. */ public final class SolutionsCreateOrUpdateSamples { /* * x-ms-original-file: * specification/agrifood/resource-manager/Microsoft.AgFoodPlatform/preview/2021-09-01-preview/examples/ * Solutions_CreateOrUpdate.json */ /** * Sample code: Solutions_CreateOrUpdate. * * @param manager Entry point to AgriFoodManager. */ public static void solutionsCreateOrUpdate(com.azure.resourcemanager.agrifood.AgriFoodManager manager) { manager.solutions() .define("abc.partner") .withExistingFarmBeat("examples-rg", "examples-farmbeatsResourceName") .withProperties(new SolutionProperties().withSaasSubscriptionId("123") .withSaasSubscriptionName("name") .withMarketplacePublisherId("publisherId") .withPlanId("planId") .withOfferId("offerId") .withTermId("termId") .withAdditionalProperties(mapOf())) .create(); } // Use "Map.of" if available @SuppressWarnings("unchecked") private static Map mapOf(Object... inputs) { Map map = new HashMap<>(); for (int i = 0; i < inputs.length; i += 2) { String key = (String) inputs[i]; T value = (T) inputs[i + 1]; map.put(key, value); } return map; } } ``` -------------------------------- ### Helper method for creating maps Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/mysqlflexibleserver/azure-resourcemanager-mysqlflexibleserver/SAMPLE.md This is a private helper method used within the sample code to easily create a Map from a list of key-value pairs. It is a utility for the examples. ```java @SuppressWarnings("unchecked") private static Map mapOf(Object... inputs) { Map map = new HashMap<>(); for (int i = 0; i < inputs.length; i += 2) { String key = (String) inputs[i]; T value = (T) inputs[i + 1]; map.put(key, value); } return map; } ``` -------------------------------- ### Get Azure Cosmos DB Table API Connection String using Azure CLI Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/tables/azure-data-tables/README.md Retrieves the connection strings for an Azure Cosmos DB Table API account using the Azure Command-Line Interface (CLI). Requires specifying the resource group and account name. ```bash az cosmosdb list-connection-strings \ --resource-group \ --name ``` -------------------------------- ### Starting Virtual Machine Azure NetworkCloud Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/networkcloud/azure-resourcemanager-networkcloud/SAMPLE.md Illustrates how to start a virtual machine resource using the Azure NetworkCloud SDK. Requires the resource group name and the virtual machine name. Uses com.azure.core.util.Context.NONE for the operation context. ```Java /** * Samples for VirtualMachines Start. */ public final class VirtualMachinesStartSamples { /* * x-ms-original-file: * specification/networkcloud/resource-manager/Microsoft.NetworkCloud/preview/2024-10-01-preview/examples/ * VirtualMachines_Start.json */ /** * Sample code: Start virtual machine. * * @param manager Entry point to NetworkCloudManager. */ public static void startVirtualMachine(com.azure.resourcemanager.networkcloud.NetworkCloudManager manager) { manager.virtualMachines().start("resourceGroupName", "virtualMachineName", com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Get Azure AD Object ID - Shell Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/keyvault/azure-security-keyvault-jca/README.md Retrieves the Azure Active Directory object ID for the currently signed-in user or provides a commented-out example for getting the object ID of a service principal using the Azure CLI. This ID is typically needed for role assignments. ```shell # Get your user object ID (if you're using a user account) USER_OBJECTID=$(az ad signed-in-user show --query id -o tsv) # Or if you're using a service principal, get its object ID # SP_OBJECTID=$(az ad sp show --id --query id -o tsv) ``` -------------------------------- ### V12 Azure Storage Blob Maximum Overload Example (Async) Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/storage/azure-storage-blob/migrationGuides/V8_V12.md Example of a maximum overload API signature in the asynchronous client of Azure Storage Blob SDK V12, returning a `Response` object containing value, headers, status code, etc. ```Java public Response getPropertiesWithResponse(String leaseId, Duration timeout, Context context) ``` -------------------------------- ### Executing Start on Virtual Machines using Azure Compute Schedule SDK for Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/computeschedule/azure-resourcemanager-computeschedule/SAMPLE.md This sample demonstrates how to execute a start action on a virtual machine using the Azure Compute Schedule SDK for Java. It uses the `virtualMachinesExecuteStartWithResponse` method, specifying the target virtual machine resource ID and configuring execution parameters like the retry policy. ```Java import com.azure.resourcemanager.computeschedule.models.ExecuteStartRequest; import com.azure.resourcemanager.computeschedule.models.ExecutionParameters; import com.azure.resourcemanager.computeschedule.models.Resources; import com.azure.resourcemanager.computeschedule.models.RetryPolicy; import java.util.Arrays; /** * Samples for ScheduledActions VirtualMachinesExecuteStart. */ public final class ScheduledActionsVirtualMachinesExecuteStartSamples { /* * x-ms-original-file: 2024-10-01/ScheduledActions_VirtualMachinesExecuteStart.json */ /** * Sample code: ScheduledActions_VirtualMachinesExecuteStart. * * @param manager Entry point to ComputeScheduleManager. */ public static void scheduledActionsVirtualMachinesExecuteStart( com.azure.resourcemanager.computeschedule.ComputeScheduleManager manager) { manager.scheduledActions() .virtualMachinesExecuteStartWithResponse("eastus2euap", new ExecuteStartRequest() .withExecutionParameters(new ExecutionParameters() .withRetryPolicy(new RetryPolicy().withRetryCount(2).withRetryWindowInMinutes(27))) .withResources(new Resources().withIds(Arrays.asList( "/subscriptions/YourSubscriptionId/resourceGroups/YourResourceGroupName/providers/Microsoft.Compute/virtualMachines/testResource3"))) .withCorrelationid("23480d2f-1dca-4610-afb4-dd25eec1f34r"), com.azure.core.util.Context.NONE); } } ``` -------------------------------- ### Delete Azure Table in Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/tables/azure-data-tables/README.md Shows how to delete an existing table by calling the `TableServiceClient`'s `deleteTable` method with the table name. ```Java tableServiceClient.deleteTable(tableName); ``` -------------------------------- ### Starting SAP Central Instances with Azure SDK for Java Source: https://github.com/azure/azure-sdk-for-java/blob/main/sdk/workloads/azure-resourcemanager-workloads/SAMPLE.md This sample demonstrates how to start an existing SAP Central Instance using the Azure SDK for Java. It requires the resource group name, the SAP Virtual Instance name, and the SAP Central Instance name. The `startInstance` method initiates the start operation for the specified central instance. ```Java /** * Samples for SapCentralInstances StartInstance. */ public final class SapCentralInstancesStartInstanceSamples { /* * x-ms-original-file: * specification/workloads/resource-manager/Microsoft.Workloads/stable/2023-04-01/examples/sapvirtualinstances/ * SAPCentralInstances_StartInstance.json */ /** * Sample code: Start the SAP Central Services Instance. * * @param manager Entry point to WorkloadsManager. */ public static void startTheSAPCentralServicesInstance(com.azure.resourcemanager.workloads.WorkloadsManager manager) { manager.sapCentralInstances() .startInstance("test-rg", "X00", "centralServer", com.azure.core.util.Context.NONE); } } ```