public static async Task GetOrCreateBatchDeploymentAsync()

in sdk/dotnet/AzureML-Samples-CSharp/Endpoints/Batch/BatchEndpointOperations.cs [89:166]


    public static async Task<MachineLearningBatchDeploymentResource> GetOrCreateBatchDeploymentAsync(
        ResourceGroupResource resourceGroup,
        string workspaceName,
        string endpointName,
        string deploymentName,
        string modelId,
        string environmentId,
        string codeArtifactId,
        string computeId,
        string location)
    {
        Console.WriteLine("Creating a BatchDeployment...");
        MachineLearningWorkspaceResource ws = await resourceGroup.GetMachineLearningWorkspaces().GetAsync(workspaceName);
        MachineLearningBatchEndpointResource endpointResource = await ws.GetMachineLearningBatchEndpoints().GetAsync(endpointName);
        Console.WriteLine(endpointResource.Data.Id);

        bool exists = await endpointResource.GetMachineLearningBatchDeployments().ExistsAsync(deploymentName);


        MachineLearningBatchDeploymentResource deploymentResource;
        if (exists)
        {
            Console.WriteLine($"BatchDeployment {deploymentName} exists.");
            deploymentResource = await endpointResource.GetMachineLearningBatchDeployments().GetAsync(deploymentName);
            Console.WriteLine($"BatchDeploymentResource details: {deploymentResource.Data.Id}");
        }
        else
        {
            Console.WriteLine($"BatchDeployment {deploymentName} does not exist.");

            MachineLearningBatchDeploymentProperties properties = new MachineLearningBatchDeploymentProperties
            {
                Description = "This is a batch deployment",
                ErrorThreshold = 10,
                MaxConcurrencyPerInstance = 5,
                LoggingLevel = MachineLearningBatchLoggingLevel.Info,
                MiniBatchSize = 10,
                OutputFileName = "mypredictions.csv",
                OutputAction = MachineLearningBatchOutputAction.AppendRow,
                Properties = { { "additionalProp1", "value1" } },
                EnvironmentId = environmentId,
                Compute = computeId,
                Resources = new MachineLearningDeploymentResourceConfiguration { InstanceCount = 1, },
                EnvironmentVariables = new Dictionary<string, string>
                {
                    { "TestVariable", "TestValue" },
                },
                RetrySettings = new MachineLearningBatchRetrySettings
                {
                    MaxRetries = 4,
                    Timeout = new TimeSpan(0, 3, 0),
                },
                CodeConfiguration = new MachineLearningCodeConfiguration("main.py")
                {
                    CodeId = new ResourceIdentifier(codeArtifactId),
                },
                Model = new MachineLearningIdAssetReference(new ResourceIdentifier(modelId)),
            };

            MachineLearningBatchDeploymentData data = new MachineLearningBatchDeploymentData(location, properties)
            {
                Kind = "SampleBatchDeployment",
                Sku = new MachineLearningSku("Default")
                {
                    Tier = MachineLearningSkuTier.Standard,
                    Capacity = 2,
                    Family = "familyA",
                    Size = "Standard_F2s_v2",
                },
            };

            ArmOperation<MachineLearningBatchDeploymentResource> endpointResourceOperation = await endpointResource.GetMachineLearningBatchDeployments().CreateOrUpdateAsync(WaitUntil.Completed, deploymentName, data);
            deploymentResource = endpointResourceOperation.Value;
            Console.WriteLine($"BatchDeploymentResource {deploymentResource.Data.Id} created.");
        }

        return deploymentResource;
    }