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

com.azure.resourcemanager.servicefabricmanagedclusters.implementation.ServiceResourceImpl Maven / Gradle / Ivy

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

package com.azure.resourcemanager.servicefabricmanagedclusters.implementation;

import com.azure.core.management.Region;
import com.azure.core.management.SystemData;
import com.azure.core.util.Context;
import com.azure.resourcemanager.servicefabricmanagedclusters.fluent.models.ServiceResourceInner;
import com.azure.resourcemanager.servicefabricmanagedclusters.models.ServiceResource;
import com.azure.resourcemanager.servicefabricmanagedclusters.models.ServiceResourceProperties;
import com.azure.resourcemanager.servicefabricmanagedclusters.models.ServiceUpdateParameters;
import java.util.Collections;
import java.util.Map;

public final class ServiceResourceImpl implements ServiceResource, ServiceResource.Definition, ServiceResource.Update {
    private ServiceResourceInner innerObject;

    private final com.azure.resourcemanager.servicefabricmanagedclusters.ServiceFabricManagedClustersManager serviceManager;

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

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

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

    public ServiceResourceProperties properties() {
        return this.innerModel().properties();
    }

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

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

    public SystemData systemData() {
        return this.innerModel().systemData();
    }

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

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

    public String resourceGroupName() {
        return resourceGroupName;
    }

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

    private com.azure.resourcemanager.servicefabricmanagedclusters.ServiceFabricManagedClustersManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String clusterName;

    private String applicationName;

    private String serviceName;

    private ServiceUpdateParameters updateParameters;

    public ServiceResourceImpl withExistingApplication(String resourceGroupName, String clusterName,
        String applicationName) {
        this.resourceGroupName = resourceGroupName;
        this.clusterName = clusterName;
        this.applicationName = applicationName;
        return this;
    }

    public ServiceResource create() {
        this.innerObject = serviceManager.serviceClient()
            .getServices()
            .createOrUpdate(resourceGroupName, clusterName, applicationName, serviceName, this.innerModel(),
                Context.NONE);
        return this;
    }

    public ServiceResource create(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getServices()
            .createOrUpdate(resourceGroupName, clusterName, applicationName, serviceName, this.innerModel(), context);
        return this;
    }

    ServiceResourceImpl(String name,
        com.azure.resourcemanager.servicefabricmanagedclusters.ServiceFabricManagedClustersManager serviceManager) {
        this.innerObject = new ServiceResourceInner();
        this.serviceManager = serviceManager;
        this.serviceName = name;
    }

    public ServiceResourceImpl update() {
        this.updateParameters = new ServiceUpdateParameters();
        return this;
    }

    public ServiceResource apply() {
        this.innerObject = serviceManager.serviceClient()
            .getServices()
            .updateWithResponse(resourceGroupName, clusterName, applicationName, serviceName, updateParameters,
                Context.NONE)
            .getValue();
        return this;
    }

    public ServiceResource apply(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getServices()
            .updateWithResponse(resourceGroupName, clusterName, applicationName, serviceName, updateParameters, context)
            .getValue();
        return this;
    }

    ServiceResourceImpl(ServiceResourceInner innerObject,
        com.azure.resourcemanager.servicefabricmanagedclusters.ServiceFabricManagedClustersManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.clusterName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "managedclusters");
        this.applicationName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "applications");
        this.serviceName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "services");
    }

    public ServiceResource refresh() {
        this.innerObject = serviceManager.serviceClient()
            .getServices()
            .getWithResponse(resourceGroupName, clusterName, applicationName, serviceName, Context.NONE)
            .getValue();
        return this;
    }

    public ServiceResource refresh(Context context) {
        this.innerObject = serviceManager.serviceClient()
            .getServices()
            .getWithResponse(resourceGroupName, clusterName, applicationName, serviceName, context)
            .getValue();
        return this;
    }

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

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

    public ServiceResourceImpl withTags(Map tags) {
        if (isInCreateMode()) {
            this.innerModel().withTags(tags);
            return this;
        } else {
            this.updateParameters.withTags(tags);
            return this;
        }
    }

    public ServiceResourceImpl withProperties(ServiceResourceProperties properties) {
        this.innerModel().withProperties(properties);
        return this;
    }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy