Search in sources :

Example 1 with BrokerFilterBadVersionException

use of org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException in project incubator-pulsar by apache.

the class BrokerVersionFilter method filter.

/**
 * From the given set of available broker candidates, filter those using the version numbers.
 *
 * @param brokers
 *            The currently available brokers that have not already been filtered.
 * @param bundleToAssign
 *            The data for the bundle to assign.
 * @param loadData
 *            The load data from the leader broker.
 * @param conf
 *            The service configuration.
 */
public void filter(Set<String> brokers, BundleData bundleToAssign, LoadData loadData, ServiceConfiguration conf) throws BrokerFilterBadVersionException {
    if (!conf.isPreferLaterVersions()) {
        return;
    }
    com.github.zafarkhaja.semver.Version latestVersion = null;
    try {
        latestVersion = getLatestVersionNumber(brokers, loadData);
        LOG.info("Latest broker version found was [{}]", latestVersion);
    } catch (Exception x) {
        LOG.warn("Disabling PreferLaterVersions feature; reason: " + x.getMessage());
        throw new BrokerFilterBadVersionException("Cannot determine newest broker version: " + x.getMessage());
    }
    int numBrokersLatestVersion = 0;
    int numBrokersOlderVersion = 0;
    Iterator<String> brokerIterator = brokers.iterator();
    while (brokerIterator.hasNext()) {
        String broker = brokerIterator.next();
        BrokerData data = loadData.getBrokerData().get(broker);
        String brokerVersion = data.getLocalData().getBrokerVersionString();
        com.github.zafarkhaja.semver.Version brokerVersionVersion = Version.valueOf(brokerVersion);
        if (brokerVersionVersion.equals(latestVersion)) {
            LOG.debug("Broker [{}] is running the latest version ([{}])", broker, brokerVersion);
            ++numBrokersLatestVersion;
        } else {
            LOG.info("Broker [{}] is running an older version ([{}]); latest version is [{}]", broker, brokerVersion, latestVersion);
            ++numBrokersOlderVersion;
            brokerIterator.remove();
        }
    }
    if (numBrokersOlderVersion == 0) {
        LOG.info("All {} brokers are running the latest version [{}]", numBrokersLatestVersion, latestVersion);
    }
}
Also used : Version(com.github.zafarkhaja.semver.Version) BrokerFilterBadVersionException(org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException) BrokerData(org.apache.pulsar.broker.BrokerData) BrokerFilterBadVersionException(org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException)

Example 2 with BrokerFilterBadVersionException

use of org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException in project incubator-pulsar by apache.

the class BrokerVersionFilterTest method testLatestVersion.

@Test
public void testLatestVersion() {
    LoadData loadData = initLoadData();
    Set<String> brokers = new TreeSet<>();
    brokers.add("broker1");
    brokers.add("broker2");
    brokers.add("broker3");
    BrokerVersionFilter filter = new BrokerVersionFilter();
    try {
        Version latestVersion = filter.getLatestVersionNumber(brokers, loadData);
        Assert.assertEquals(latestVersion.getMajorVersion(), 1);
        Assert.assertEquals(latestVersion.getMinorVersion(), 2);
        Assert.assertEquals(latestVersion.getPatchVersion(), 0);
    } catch (BrokerFilterBadVersionException bad) {
        Assert.fail(bad.getMessage(), bad);
    }
    ServiceConfiguration configuration = new ServiceConfiguration();
    configuration.setPreferLaterVersions(true);
    try {
        filter.filter(brokers, null, loadData, configuration);
        // Only one broker is running the latest version
        Assert.assertEquals(brokers.size(), 1);
    } catch (BrokerFilterBadVersionException bad) {
        Assert.fail(bad.getMessage(), bad);
    }
}
Also used : BrokerFilterBadVersionException(org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException) BrokerVersionFilter(org.apache.pulsar.broker.loadbalance.impl.BrokerVersionFilter) LoadData(org.apache.pulsar.broker.loadbalance.LoadData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) Version(com.github.zafarkhaja.semver.Version) TreeSet(java.util.TreeSet) Test(org.testng.annotations.Test)

Example 3 with BrokerFilterBadVersionException

use of org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException in project incubator-pulsar by apache.

the class BrokerVersionFilter method getLatestVersionNumber.

/**
 * Get the most recent broker version number from the load reports of all the running brokers. The version
 * number is from the build artifact in the pom and got added to the package when it was built by Maven
 *
 * @param brokers
 *            The brokers to choose the latest version string from.
 * @param loadData
 *            The load data from the leader broker (contains the load reports which in turn contain the version string).
 * @return The most recent broker version
 * @throws BrokerFilterBadVersionException
 *            If the most recent version is undefined (e.g., a bad broker version was encountered or a broker
 *            does not have a version string in its load report.
 */
public Version getLatestVersionNumber(Set<String> brokers, LoadData loadData) throws BrokerFilterBadVersionException {
    if (null == brokers) {
        throw new BrokerFilterBadVersionException("Unable to determine latest version since broker set was null");
    }
    if (brokers.size() == 0) {
        throw new BrokerFilterBadVersionException("Unable to determine latest version since broker set was empty");
    }
    if (null == loadData) {
        throw new BrokerFilterBadVersionException("Unable to determine latest version since loadData was null");
    }
    Version latestVersion = null;
    for (String broker : brokers) {
        BrokerData data = loadData.getBrokerData().get(broker);
        if (null == data) {
            LOG.warn("No broker data for broker [{}]; disabling PreferLaterVersions feature", broker);
            // trigger the ModularLoadManager to reset all the brokers to the original set
            throw new BrokerFilterBadVersionException("No broker data for broker \"" + broker + "\"");
        }
        String brokerVersion = data.getLocalData().getBrokerVersionString();
        if (null == brokerVersion || brokerVersion.length() == 0) {
            LOG.warn("No version string in load report for broker [{}]; disabling PreferLaterVersions feature", broker);
            // trigger the ModularLoadManager to reset all the brokers to the original set
            throw new BrokerFilterBadVersionException("No version string in load report for broker \"" + broker + "\"");
        }
        Version brokerVersionVersion = null;
        try {
            brokerVersionVersion = Version.valueOf(brokerVersion);
        } catch (Exception x) {
            LOG.warn("Invalid version string in load report for broker [{}]: [{}]; disabling PreferLaterVersions feature", broker, brokerVersion);
            // trigger the ModularLoadManager to reset all the brokers to the original set
            throw new BrokerFilterBadVersionException("Invalid version string in load report for broker \"" + broker + "\": \"" + brokerVersion + "\")");
        }
        if (null == latestVersion) {
            latestVersion = brokerVersionVersion;
        } else if (Version.BUILD_AWARE_ORDER.compare(latestVersion, brokerVersionVersion) < 0) {
            latestVersion = brokerVersionVersion;
        }
    }
    if (null == latestVersion) {
        throw new BrokerFilterBadVersionException("Unable to determine latest broker version");
    }
    return latestVersion;
}
Also used : BrokerFilterBadVersionException(org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException) Version(com.github.zafarkhaja.semver.Version) BrokerData(org.apache.pulsar.broker.BrokerData) BrokerFilterBadVersionException(org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException)

Aggregations

Version (com.github.zafarkhaja.semver.Version)3 BrokerFilterBadVersionException (org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)2 BrokerData (org.apache.pulsar.broker.BrokerData)2 TreeSet (java.util.TreeSet)1 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)1 LoadData (org.apache.pulsar.broker.loadbalance.LoadData)1 BrokerVersionFilter (org.apache.pulsar.broker.loadbalance.impl.BrokerVersionFilter)1 Test (org.testng.annotations.Test)1