(Azure SDK java) How to Enable/Disable each Functions using Java program

273 Views Asked by At

I am using AzureResourceManager(java).

I am able to start/stop Functions by following.

FunctionApp app = azureResourceManager.functionApps().getById(id);
app.start();

FunctionApp app = azureResourceManager.functionApps().getById(id);
app.stop();

pom.xml

<dependency>
    <groupId>com.azure.resourcemanager</groupId>
    <artifactId>azure-resourcemanager</artifactId>
    <version>2.1.0</version>
</dependency>

I know we can enable/disable them from Azure portal. see Azure Portal Image. I would like to manage it for each function of Functions using java program.

1

There are 1 best solutions below

0
On BEST ANSWER

The API is not documented. So if you really need to do this in Java (likely same for SDK of another language), you had to call it directly.

var response = azure.functionApps().manager().httpPipeline().send(
        new HttpRequest(HttpMethod.PUT, "https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Web/sites/<site>/functions/<function>/properties/state?api-version=2021-02-01")
            .setHeader("content-type", "application/json")
            .setBody("{\"properties\":\"disabled\"}"))
    .block();

<subscription_id> can be get via azure.subscriptionId() (anyway user provided this when initializing the azure object).

As this is undocumented API (Portal calls this API, if you check the browser dev tool), it could be unstable. I couldn't find a documented equivalent.

PS, you might want to upgrade the SDK version to 2.10.0 (2.1.0 is pretty early version and contains some known minor bugs)