Search in sources :

Example 16 with LongRange

use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.

the class RangeTest method testRangeCanContainOnlyIntSizeNumberOfElements.

@Test
public void testRangeCanContainOnlyIntSizeNumberOfElements() throws Exception {
    LongRange longRange = MacAddressRangeUtils.clipRange(new LongRange(0, Long.MAX_VALUE));
    Range range = new Range(longRange.getMinimumLong(), longRange.getMaximumLong());
    assertThat(range.getAvailableCount(), is(Integer.MAX_VALUE));
}
Also used : LongRange(org.apache.commons.lang.math.LongRange) LongRange(org.apache.commons.lang.math.LongRange) Test(org.junit.Test)

Example 17 with LongRange

use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.

the class DisjointRanges method addRange.

/**
 * add range to process and add it (potentially altered) to result list of ranges.
 *
 * @param from range left boundary
 * @param to range right boundary
 */
public void addRange(long from, long to) {
    LongRange addedRange = new LongRange(from, to);
    Iterator<LongRange> it = disjointRanges.iterator();
    while (it.hasNext()) {
        LongRange existingRange = it.next();
        if (existingRange.overlapsRange(addedRange)) {
            it.remove();
            addedRange = new LongRange(Math.min(addedRange.getMinimumLong(), existingRange.getMinimumLong()), Math.max(addedRange.getMaximumLong(), existingRange.getMaximumLong()));
        }
    }
    disjointRanges.add(addedRange);
}
Also used : LongRange(org.apache.commons.lang.math.LongRange)

Example 18 with LongRange

use of org.apache.commons.lang.math.LongRange in project ovirt-engine by oVirt.

the class MacAddressRangeUtils method clipRange.

public static LongRange clipRange(Range range) {
    long rangeEnd = range.getMaximumLong();
    long rangeStart = range.getMinimumLong();
    boolean trimmingOccurred = false;
    if (MacAddressRangeUtils.macIsMulticast(rangeStart)) {
        rangeStart = (rangeStart | 0x00FFFFFFFFFFL) + 1;
        trimmingOccurred = true;
    }
    final long trimmedRangeEnd = Math.min(rangeStart + Integer.MAX_VALUE - 1, rangeEnd);
    if (rangeEnd != trimmedRangeEnd) {
        rangeEnd = trimmedRangeEnd;
        trimmingOccurred = true;
    }
    if (MacAddressRangeUtils.macIsMulticast(rangeEnd)) {
        rangeEnd = (rangeEnd & 0xFF0000000000L) - 1;
        trimmingOccurred = true;
    }
    if (rangeStart > rangeEnd) {
        log.warn("User supplied range({}) contains only multicast addresses, so this range is not usable.", range);
        return null;
    }
    final LongRange result = new LongRange(rangeStart, rangeEnd);
    if (trimmingOccurred) {
        log.warn("User supplied range({}) need to be trimmed to {}.", range, result);
    }
    return result;
}
Also used : LongRange(org.apache.commons.lang.math.LongRange)

Aggregations

LongRange (org.apache.commons.lang.math.LongRange)18 Test (org.junit.Test)6 Date (java.util.Date)3 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)3 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)3 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)3 IOException (java.io.IOException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 ApplicationsRequestScope (org.apache.hadoop.yarn.api.protocolrecords.ApplicationsRequestScope)2 GetApplicationsRequestProtoOrBuilder (org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationsRequestProtoOrBuilder)2 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)2 Event (com.google.api.services.calendar.model.Event)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Private (org.apache.hadoop.classification.InterfaceAudience.Private)1