All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.resourcemanager.automation.implementation.WatcherImpl Maven / Gradle / Ivy

Go to download

This package contains Microsoft Azure SDK for Automation Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. Automation Client. Package tag package-2019-06.

There is a newer version: 1.0.0
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.automation.implementation;

import com.azure.core.management.Region;
import com.azure.core.util.Context;
import com.azure.resourcemanager.automation.fluent.models.WatcherInner;
import com.azure.resourcemanager.automation.models.Watcher;
import com.azure.resourcemanager.automation.models.WatcherUpdateParameters;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.Map;

public final class WatcherImpl implements Watcher, Watcher.Definition, Watcher.Update {
    private WatcherInner innerObject;

    private final com.azure.resourcemanager.automation.AutomationManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public String etag() {
        return this.innerModel().etag();
    }

    public Map tags() {
        Map inner = this.innerModel().tags();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

    public String location() {
        return this.innerModel().location();
    }

    public Long executionFrequencyInSeconds() {
        return this.innerModel().executionFrequencyInSeconds();
    }

    public String scriptName() {
        return this.innerModel().scriptName();
    }

    public Map scriptParameters() {
        Map inner = this.innerModel().scriptParameters();
        if (inner != null) {
            return Collections.unmodifiableMap(inner);
        } else {
            return Collections.emptyMap();
        }
    }

    public String scriptRunOn() {
        return this.innerModel().scriptRunOn();
    }

    public String status() {
        return this.innerModel().status();
    }

    public OffsetDateTime creationTime() {
        return this.innerModel().creationTime();
    }

    public OffsetDateTime lastModifiedTime() {
        return this.innerModel().lastModifiedTime();
    }

    public String lastModifiedBy() {
        return this.innerModel().lastModifiedBy();
    }

    public String description() {
        return this.innerModel().description();
    }

    public Region region() {
        return Region.fromName(this.regionName());
    }

    public String regionName() {
        return this.location();
    }

    public WatcherInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.automation.AutomationManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String automationAccountName;

    private String watcherName;

    private WatcherUpdateParameters updateParameters;

    public WatcherImpl withExistingAutomationAccount(String resourceGroupName, String automationAccountName) {
        this.resourceGroupName = resourceGroupName;
        this.automationAccountName = automationAccountName;
        return this;
    }

    public Watcher create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchers()
                .createOrUpdateWithResponse(
                    resourceGroupName, automationAccountName, watcherName, this.innerModel(), Context.NONE)
                .getValue();
        return this;
    }

    public Watcher create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchers()
                .createOrUpdateWithResponse(
                    resourceGroupName, automationAccountName, watcherName, this.innerModel(), context)
                .getValue();
        return this;
    }

    WatcherImpl(String name, com.azure.resourcemanager.automation.AutomationManager serviceManager) {
        this.innerObject = new WatcherInner();
        this.serviceManager = serviceManager;
        this.watcherName = name;
    }

    public WatcherImpl update() {
        this.updateParameters = new WatcherUpdateParameters();
        return this;
    }

    public Watcher apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchers()
                .updateWithResponse(
                    resourceGroupName, automationAccountName, watcherName, updateParameters, Context.NONE)
                .getValue();
        return this;
    }

    public Watcher apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchers()
                .updateWithResponse(resourceGroupName, automationAccountName, watcherName, updateParameters, context)
                .getValue();
        return this;
    }

    WatcherImpl(WatcherInner innerObject, com.azure.resourcemanager.automation.AutomationManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.automationAccountName = Utils.getValueFromIdByName(innerObject.id(), "automationAccounts");
        this.watcherName = Utils.getValueFromIdByName(innerObject.id(), "watchers");
    }

    public Watcher refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchers()
                .getWithResponse(resourceGroupName, automationAccountName, watcherName, Context.NONE)
                .getValue();
        return this;
    }

    public Watcher refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getWatchers()
                .getWithResponse(resourceGroupName, automationAccountName, watcherName, context)
                .getValue();
        return this;
    }

    public WatcherImpl withRegion(Region location) {
        this.innerModel().withLocation(location.toString());
        return this;
    }

    public WatcherImpl withRegion(String location) {
        this.innerModel().withLocation(location);
        return this;
    }

    public WatcherImpl withTags(Map tags) {
        this.innerModel().withTags(tags);
        return this;
    }

    public WatcherImpl withEtag(String etag) {
        this.innerModel().withEtag(etag);
        return this;
    }

    public WatcherImpl withExecutionFrequencyInSeconds(Long executionFrequencyInSeconds) {
        if (isInCreateMode()) {
            this.innerModel().withExecutionFrequencyInSeconds(executionFrequencyInSeconds);
            return this;
        } else {
            this.updateParameters.withExecutionFrequencyInSeconds(executionFrequencyInSeconds);
            return this;
        }
    }

    public WatcherImpl withScriptName(String scriptName) {
        this.innerModel().withScriptName(scriptName);
        return this;
    }

    public WatcherImpl withScriptParameters(Map scriptParameters) {
        this.innerModel().withScriptParameters(scriptParameters);
        return this;
    }

    public WatcherImpl withScriptRunOn(String scriptRunOn) {
        this.innerModel().withScriptRunOn(scriptRunOn);
        return this;
    }

    public WatcherImpl withDescription(String description) {
        this.innerModel().withDescription(description);
        return this;
    }

    public WatcherImpl withName(String name) {
        this.updateParameters.withName(name);
        return this;
    }

    private boolean isInCreateMode() {
        return this.innerModel().id() == null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy