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

com.microsoft.azure.management.eventhub.implementation.EventHubNamespaceImpl 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.EventHub;
import com.microsoft.azure.management.eventhub.EventHubNamespace;
import com.microsoft.azure.management.eventhub.EventHubNamespaceAuthorizationRule;
import com.microsoft.azure.management.eventhub.EventHubNamespaceSkuType;
import com.microsoft.azure.management.eventhub.Sku;
import com.microsoft.azure.management.eventhub.SkuName;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.microsoft.azure.management.resources.fluentcore.dag.FunctionalTaskItem;
import com.microsoft.azure.management.resources.fluentcore.model.Indexable;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import org.joda.time.DateTime;
import rx.Observable;

/**
 * Implementation for {@link EventHubNamespace}.
 */
@LangDefinition
class EventHubNamespaceImpl
        extends GroupableResourceImpl
        implements
        EventHubNamespace,
        EventHubNamespace.Definition,
        EventHubNamespace.Update {

    protected EventHubNamespaceImpl(String name, EHNamespaceInner innerObject, EventHubManager manager) {
        super(name, innerObject, manager);
    }

    @Override
    public EventHubNamespaceSkuType sku() {
        return new EventHubNamespaceSkuType(this.inner().sku());
    }

    @Override
    public String azureInsightMetricId() {
        return this.inner().metricId();
    }

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

    @Override
    public DateTime createdAt() {
        return this.inner().createdAt();
    }

    @Override
    public DateTime updatedAt() {
        return this.inner().updatedAt();
    }

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

    @Override
    public boolean isAutoScaleEnabled() {
        return Utils.toPrimitiveBoolean(this.inner().isAutoInflateEnabled());
    }

    @Override
    public int currentThroughputUnits() {
        return Utils.toPrimitiveInt(this.inner().sku().capacity());
    }

    @Override
    public int throughputUnitsUpperLimit() {
        return Utils.toPrimitiveInt(this.inner().maximumThroughputUnits());
    }

    @Override
    public EventHubNamespaceImpl withNewEventHub(final String eventHubName) {
        addPostRunDependent(new FunctionalTaskItem() {
            @Override
            public Observable call(final Context context) {
                return manager().eventHubs()
                        .define(eventHubName)
                        .withExistingNamespace(resourceGroupName(), name())
                        .createAsync();
            }
        });
        return this;
    }

    @Override
    public EventHubNamespaceImpl withNewEventHub(final String eventHubName, final int partitionCount) {
        addPostRunDependent(new FunctionalTaskItem() {
            @Override
            public Observable call(final Context context) {
               return  manager().eventHubs()
                        .define(eventHubName)
                        .withExistingNamespace(resourceGroupName(), name())
                        .withPartitionCount(partitionCount)
                        .createAsync();
            }
        });
        return this;
    }

    @Override
    public EventHubNamespaceImpl withNewEventHub(final String eventHubName, final int partitionCount, final int retentionPeriodInDays) {
        addPostRunDependent(new FunctionalTaskItem() {
            @Override
            public Observable call(final Context context) {
                return  manager().eventHubs()
                        .define(eventHubName)
                        .withExistingNamespace(resourceGroupName(), name())
                        .withPartitionCount(partitionCount)
                        .withRetentionPeriodInDays(retentionPeriodInDays)
                        .createAsync();
            }
        });
        return this;
    }

    @Override
    public Update withoutEventHub(final String eventHubName) {
        addPostRunDependent(new FunctionalTaskItem() {
            @Override
            public Observable call(Context context) {
                return manager().eventHubs()
                        .deleteByNameAsync(resourceGroupName(), name(), eventHubName)
                        .toObservable()
                        .concatWith(context.voidObservable());
            }
        });
        return this;
    }

    @Override
    public EventHubNamespaceImpl withNewSendRule(final String ruleName) {
        addPostRunDependent(new FunctionalTaskItem() {
            @Override
            public Observable call(Context context) {
                return manager().namespaceAuthorizationRules()
                        .define(ruleName)
                        .withExistingNamespace(resourceGroupName(), name())
                        .withSendAccess()
                        .createAsync();
            }
        });
        return this;
    }

    @Override
    public EventHubNamespaceImpl withNewListenRule(final String ruleName) {
        addPostRunDependent(new FunctionalTaskItem() {
            @Override
            public Observable call(Context context) {
                return manager().namespaceAuthorizationRules()
                        .define(ruleName)
                        .withExistingNamespace(resourceGroupName(), name())
                        .withListenAccess()
                        .createAsync();
            }
        });
        return this;
    }

    @Override
    public EventHubNamespaceImpl withNewManageRule(final String ruleName) {
        addPostRunDependent(new FunctionalTaskItem() {
            @Override
            public Observable call(Context context) {
                return manager().namespaceAuthorizationRules()
                        .define(ruleName)
                        .withExistingNamespace(resourceGroupName(), name())
                        .withManageAccess()
                        .createAsync();
            }
        });
        return this;
    }

    @Override
    public EventHubNamespaceImpl withoutAuthorizationRule(final String ruleName) {
        addPostRunDependent(new FunctionalTaskItem() {
            @Override
            public Observable call(Context context) {
                return manager().namespaceAuthorizationRules()
                        .deleteByNameAsync(resourceGroupName(), name(), ruleName)
                        .toObservable()
                        .concatWith(context.voidObservable());
            }
        });
        return this;
    }

    @Override
    public EventHubNamespaceImpl withAutoScaling() {
        // Auto-inflate requires a Sku > 'Basic' with capacity.
        this.setDefaultSkuIfNotSet();
        this.inner().withIsAutoInflateEnabled(true);
        if (this.inner().maximumThroughputUnits() == null) {
            // Required when auto-inflate is set & use portal default.
            this.withThroughputUnitsUpperLimit(20);
        }
        return this;
    }

    @Override
    public EventHubNamespaceImpl withSku(EventHubNamespaceSkuType namespaceSku) {
        Sku newSkuInner = new Sku()
                .withName(namespaceSku.name())
                .withTier(namespaceSku.tier())
                .withCapacity(null);
        Sku currentSkuInner = this.inner().sku();

        boolean isDifferent = currentSkuInner == null || !currentSkuInner.name().equals(newSkuInner.name());
        if (isDifferent) {
            this.inner().withSku(newSkuInner);
            if (newSkuInner.name().equals(SkuName.STANDARD)) {
                newSkuInner.withCapacity(1);
            }
        }
        return this;
    }

    @Override
    public EventHubNamespaceImpl withCurrentThroughputUnits(int units) {
        this.setDefaultSkuIfNotSet();
        this.inner().sku().withCapacity(units);
        return this;
    }

    @Override
    public EventHubNamespaceImpl withThroughputUnitsUpperLimit(int units) {
        this.inner().withMaximumThroughputUnits(units);
        return this;
    }

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

    @Override
    public Observable listEventHubsAsync() {
        return this.manager().eventHubs().listByNamespaceAsync(resourceGroupName(), name());
    }

    @Override
    public Observable listAuthorizationRulesAsync() {
        return this.manager().namespaceAuthorizationRules().listByNamespaceAsync(this.resourceGroupName(), this.name());
    }

    @Override
    public PagedList listEventHubs() {
        return this.manager().eventHubs().listByNamespace(resourceGroupName(), name());
    }

    @Override
    public PagedList listAuthorizationRules() {
        return this.manager().namespaceAuthorizationRules()
                .listByNamespace(this.resourceGroupName(), this.name());
    }

    @Override
    protected Observable getInnerAsync() {
        return this.manager().inner().namespaces().getByResourceGroupAsync(this.resourceGroupName(), this.name());
    }

    private void setDefaultSkuIfNotSet() {
        if (this.inner().sku() == null) {
            this.withSku(EventHubNamespaceSkuType.STANDARD);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy