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

com.microsoft.azure.management.eventhub.implementation.EventHubDisasterRecoveryPairingImpl Maven / Gradle / Ivy

Go to download

This package contains Microsoft EventHub Management SDK. This package has been deprecated. A replacement package com.azure.resourcemanager:azure-resourcemanager-eventhubs is available as of 31-March-2022. We strongly encourage you to upgrade to continue receiving updates. See Migration Guide https://aka.ms/java-track2-migration-guide for guidance on upgrading. Refer to our deprecation policy https://azure.github.io/azure-sdk/policies_support.html for more details.

There is a newer version: 1.41.4
Show newest version
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */

package com.microsoft.azure.management.eventhub.implementation;

import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.eventhub.DisasterRecoveryPairingAuthorizationRule;
import com.microsoft.azure.management.eventhub.EventHubDisasterRecoveryPairing;
import com.microsoft.azure.management.eventhub.EventHubNamespace;
import com.microsoft.azure.management.eventhub.ProvisioningStateDR;
import com.microsoft.azure.management.eventhub.RoleDisasterRecovery;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceId;
import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
import rx.Completable;
import rx.Observable;

import java.util.Objects;

/**
 * Implementation for {@link EventHubDisasterRecoveryPairing}.
 */
@LangDefinition
class EventHubDisasterRecoveryPairingImpl
        extends
        NestedResourceImpl
        implements
        EventHubDisasterRecoveryPairing,
        EventHubDisasterRecoveryPairing.Definition,
        EventHubDisasterRecoveryPairing.Update {

    private Ancestors.OneAncestor ancestor;

    EventHubDisasterRecoveryPairingImpl(String name, ArmDisasterRecoveryInner inner, EventHubManager manager) {
        super(name, inner, manager);
        this.ancestor = new Ancestors().new OneAncestor(inner.id());
    }

    EventHubDisasterRecoveryPairingImpl(String name, EventHubManager manager) {
        super(name, new ArmDisasterRecoveryInner(), manager);
    }

    @Override
    public String primaryNamespaceResourceGroupName() {
        return this.ancestor().resourceGroupName();
    }

    @Override
    public String primaryNamespaceName() {
        return this.ancestor().ancestor1Name();
    }

    @Override
    public String secondaryNamespaceId() {
        return this.inner().partnerNamespace();
    }

    @Override
    public RoleDisasterRecovery namespaceRole() {
        return this.inner().role();
    }

    @Override
    public ProvisioningStateDR provisioningState() {
        return this.inner().provisioningState();
    }

    @Override
    public EventHubDisasterRecoveryPairingImpl withNewPrimaryNamespace(Creatable namespaceCreatable) {
        this.addDependency(namespaceCreatable);
        EventHubNamespaceImpl namespace = ((EventHubNamespaceImpl) namespaceCreatable);
        this.ancestor = new Ancestors().new OneAncestor(namespace.resourceGroupName(), namespaceCreatable.name());
        return this;
    }

    @Override
    public EventHubDisasterRecoveryPairingImpl withExistingPrimaryNamespace(EventHubNamespace namespace) {
        this.ancestor = new Ancestors().new OneAncestor(selfId(namespace.id()));
        return this;
    }

    @Override
    public EventHubDisasterRecoveryPairingImpl withExistingPrimaryNamespace(String resourceGroupName, String primaryNamespaceName) {
        this.ancestor = new Ancestors().new OneAncestor(resourceGroupName, primaryNamespaceName);
        return this;
    }

    @Override
    public EventHubDisasterRecoveryPairingImpl withExistingPrimaryNamespaceId(String namespaceId) {
        this.ancestor = new Ancestors().new OneAncestor(selfId(namespaceId));
        return this;
    }

    @Override
    public EventHubDisasterRecoveryPairingImpl withNewSecondaryNamespace(Creatable namespaceCreatable) {
        this.addDependency(namespaceCreatable);
        EventHubNamespaceImpl namespace = ((EventHubNamespaceImpl) namespaceCreatable);
        this.inner().withPartnerNamespace(namespace.name());
        return this;
    }

    @Override
    public EventHubDisasterRecoveryPairingImpl withExistingSecondaryNamespace(EventHubNamespace namespace) {
        Objects.requireNonNull(namespace.id());
        this.inner().withPartnerNamespace(namespace.id());
        return this;
    }

    @Override
    public EventHubDisasterRecoveryPairingImpl withExistingSecondaryNamespaceId(String namespaceId) {
        Objects.requireNonNull(namespaceId);
        this.inner().withPartnerNamespace(namespaceId);
        return this;
    }

    @Override
    public Observable createResourceAsync() {
        return this.manager().inner().disasterRecoveryConfigs().createOrUpdateAsync(this.ancestor().resourceGroupName(),
                this.ancestor().ancestor1Name(),
                this.name(),
                this.inner())
                .map(innerToFluentMap(this));
    }

    @Override
    public Completable breakPairingAsync() {
        return this.manager().inner().disasterRecoveryConfigs().breakPairingAsync(this.ancestor().resourceGroupName(),
                    this.ancestor().ancestor1Name(),
                    this.name())
                .toCompletable()
                .concatWith(this.refreshAsync().toCompletable());
    }

    @Override
    public void breakPairing() {
        this.breakPairingAsync().await();
    }

    @Override
    public Completable failOverAsync() {
        // Fail over is run against secondary namespace (because primary might be down at time of failover)
        //
        ResourceId secondaryNs = ResourceId.fromString(this.inner().partnerNamespace());
        return this.manager().inner().disasterRecoveryConfigs().failOverAsync(secondaryNs.resourceGroupName(),
                secondaryNs.name(),
                this.name())
                .toCompletable()
                .concatWith(this.refreshAsync().toCompletable());
    }

    @Override
    public void failOver() {
        this.failOverAsync().await();
    }

    @Override
    public Observable listAuthorizationRulesAsync() {
        return this.manager().disasterRecoveryPairingAuthorizationRules().listByDisasterRecoveryPairingAsync(this.ancestor().resourceGroupName(),
                this.ancestor().ancestor1Name(),
                this.name());
    }

    @Override
    public PagedList listAuthorizationRules() {
        return this.manager().disasterRecoveryPairingAuthorizationRules().listByDisasterRecoveryPairing(this.ancestor().resourceGroupName(),
                this.ancestor().ancestor1Name(),
                this.name());
    }

    @Override
    protected Observable getInnerAsync() {
        return this.manager().inner().disasterRecoveryConfigs().getAsync(this.ancestor().resourceGroupName(),
                this.ancestor().ancestor1Name(),
                this.name());
    }

    private Ancestors.OneAncestor ancestor() {
        Objects.requireNonNull(this.ancestor);
        return this.ancestor;
    }

    private String selfId(String parentId) {
        return String.format("%s/disasterRecoveryConfig/%s", parentId, this.name());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy