// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.hybridcompute.generated;

import com.azure.core.management.serializer.SerializerFactory;
import com.azure.core.util.serializer.SerializerEncoding;
import com.azure.resourcemanager.hybridcompute.models.MachineExtension;
import com.azure.resourcemanager.hybridcompute.models.MachineExtensionUpdateProperties;
import java.io.IOException;

/** Samples for MachineExtensions Update. */
public final class MachineExtensionsUpdateSamples {
    /*
     * x-ms-original-file: specification/hybridcompute/resource-manager/Microsoft.HybridCompute/preview/2021-03-25-preview/examples/UpdateExtension.json
     */
    /**
     * Sample code: Create or Update a Machine Extension.
     *
     * @param manager Entry point to HybridComputeManager.
     */
    public static void createOrUpdateAMachineExtension(
        com.azure.resourcemanager.hybridcompute.HybridComputeManager manager) throws IOException {
        MachineExtension resource =
            manager
                .machineExtensions()
                .getWithResponse(
                    "myResourceGroup", "myMachine", "CustomScriptExtension", com.azure.core.util.Context.NONE)
                .getValue();
        resource
            .update()
            .withProperties(
                new MachineExtensionUpdateProperties()
                    .withPublisher("Microsoft.Compute")
                    .withType("CustomScriptExtension")
                    .withTypeHandlerVersion("1.10")
                    .withSettings(
                        SerializerFactory
                            .createDefaultManagementSerializerAdapter()
                            .deserialize(
                                "{\"commandToExecute\":\"powershell.exe -c \\\"Get-Process | Where-Object { $_.CPU -lt"
                                    + " 100 }\\\"\"}",
                                Object.class,
                                SerializerEncoding.JSON)))
            .apply();
    }
}
