org.apache.pulsar.common.policies.NamespaceIsolationPolicy Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.common.policies;
import java.net.URL;
import java.util.List;
import java.util.SortedSet;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.policies.data.BrokerStatus;
import org.apache.pulsar.common.policies.data.NamespaceIsolationPolicyUnloadScope;
/**
* Namespace isolation policy.
*/
public interface NamespaceIsolationPolicy {
/**
* Get the list of regex for the set of primary brokers.
*
* @return
*/
List getPrimaryBrokers();
/**
* Get the list of regex for the set of secondary brokers.
*
* @return
*/
List getSecondaryBrokers();
/**
* Get the unload scope for the policy set call.
*/
NamespaceIsolationPolicyUnloadScope getUnloadScope();
/**
* Get the list of primary brokers for the namespace according to the policy.
*
* @param availableBrokers brokers identified by service URL.
* @param namespace the namespace
* @return a list brokers by service URL.
*/
List findPrimaryBrokers(List availableBrokers, NamespaceName namespace);
/**
* Get the list of secondary brokers for the namespace according to the policy.
*
* @param availableBrokers brokers identified by service URL.
* @param namespace the namespace
* @return a list brokers by service URL.
*/
List findSecondaryBrokers(List availableBrokers, NamespaceName namespace);
/**
* Check to see whether the primary brokers can still handle a new namespace or has to failover.
*
* @param primaryCandidates
* @return
*/
boolean shouldFailover(SortedSet primaryCandidates);
/**
* Check to see whether the primary brokers can still handle a new namespace or has to failover.
*
* @param totalPrimaryCandidates
* @return
*/
boolean shouldFailover(int totalPrimaryCandidates);
/**
* Check to see whether the namespace ownership should fallback to the primary brokers.
*
* @param primaryBrokers
* @return
*/
boolean shouldFallback(SortedSet primaryBrokers);
/**
* Check to see whether the specific host is a primary broker.
*
* @param brokerAddress
* @return
*/
boolean isPrimaryBroker(String brokerAddress);
/**
* Check to see whether the specific host is a secondary broker.
*
* @param brokerAddress
* @return
*/
boolean isSecondaryBroker(String brokerAddress);
/**
* According to the namespace isolation policy, find the allowed available primary brokers.
*
* @param primaryCandidates
* @return
*/
SortedSet getAvailablePrimaryBrokers(SortedSet primaryCandidates);
boolean isPrimaryBrokerAvailable(BrokerStatus brkStatus);
}