org.apache.commons.lang.math.LongRange Java Examples

The following examples show how to use org.apache.commons.lang.math.LongRange. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlagMakerTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Test of time stamps of the flag files using folders instead of file timestamps
 */
@Test
public void testFolderTimeStamps() throws Exception {
    log.info("-----  testFolderTimeStamps  -----");
    File f = setUpFlagDir();
    // two days, 5 files each day, two folders in fmc = 20 flags
    LongRange range = createTestFiles(2, 5, true);
    fmc.setSetFlagFileTimestamp(true);
    fmc.setUseFolderTimestamp(true);
    FlagMaker instance = new TestWrappedFlagMaker(fmc);
    instance.processFlags();
    assertEquals("Incorrect files.  Expected 2 but got " + f.listFiles().length + ": " + Arrays.toString(f.listFiles()), 2, f.listFiles().length);
    
    // ensure the flag files have appropriate dates
    for (File file : f.listFiles()) {
        if (file.getName().endsWith(".flag")) {
            assertTrue(range.containsLong(file.lastModified()));
        }
    }
}
 
Example #2
Source File: TimeRangeCalendarTest.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testIsTimeIncluded() throws ParseException {
    Date startTime = DATE_FORMATTER.parse("04.04.2012 16:00:00:000");
    Date endTime = DATE_FORMATTER.parse("04.04.2012 19:15:00:000");

    Date included = DATE_FORMATTER.parse("04.04.2012 19:00:00:000");
    Date excluded_before = DATE_FORMATTER.parse("04.04.2012 15:59:59:999");
    Date excluded_after = DATE_FORMATTER.parse("04.04.2012 19:15:00:001");

    LongRange timeRange = new LongRange(startTime.getTime(), endTime.getTime());
    calendar.addTimeRange(timeRange);

    Assert.assertEquals(true, calendar.isTimeIncluded(included.getTime()));
    Assert.assertEquals(false, calendar.isTimeIncluded(excluded_before.getTime()));
    Assert.assertEquals(false, calendar.isTimeIncluded(excluded_after.getTime()));
}
 
Example #3
Source File: TimeRangeCalendar.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Determine the next time (in milliseconds) that is 'included' by the
 * Calendar after the given time.
 */
@Override
public long getNextIncludedTime(long timeStamp) {
    long nextIncludedTime = timeStamp + ONE_MILLI;

    while (isTimeIncluded(nextIncludedTime)) {
        LongRange timeRange = findTimeRange(timeStamp);
        if (nextIncludedTime >= timeRange.getMinimumLong() && nextIncludedTime <= timeRange.getMaximumLong()) {

            nextIncludedTime = timeRange.getMaximumLong() + ONE_MILLI;
        } else if ((getBaseCalendar() != null) && (!getBaseCalendar().isTimeIncluded(nextIncludedTime))) {
            nextIncludedTime = getBaseCalendar().getNextIncludedTime(nextIncludedTime);
        } else {
            nextIncludedTime++;
        }
    }

    return nextIncludedTime;
}
 
Example #4
Source File: FlagMakerTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlagFileMarker() throws Exception {
    log.info("-----  testFlagFileMarker  -----");
    File f = setUpFlagDir();
    // two days, 5 files each day, two folders in fmc = 20 flags
    LongRange range = createTestFiles(2, 5);
    // fmc.setSetFlagFileTimestamp(true);
    List<FlagDataTypeConfig> cfgs = fmc.getFlagConfigs();
    FlagDataTypeConfig cfg = cfgs.get(0);
    cfg.setFileListMarker("XXXX--test-marker--XXXX");
    FlagMaker instance = new TestWrappedFlagMaker(fmc);
    instance.processFlags();
    // ensure the flag files have appropriate dates
    for (File file : f.listFiles()) {
        if (file.getName().endsWith(".flag")) {
            assertTrue(range.containsLong(file.lastModified()));
        }
    }
    assertEquals("Incorrect files.  Expected 2 but got " + f.listFiles().length + ": " + Arrays.toString(f.listFiles()), 2, f.listFiles().length);
}
 
Example #5
Source File: FlagMakerTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlagFileMarkerError() throws Exception {
    log.info("-----  testFlagFileMarkerError  -----");
    File f = setUpFlagDir();
    // two days, 5 files each day, two folders in fmc = 20 flags
    LongRange range = createTestFiles(2, 5);
    fmc.setSetFlagFileTimestamp(true);
    List<FlagDataTypeConfig> cfgs = fmc.getFlagConfigs();
    FlagDataTypeConfig cfg = cfgs.get(0);
    cfg.setFileListMarker(INVALID_MARKER);
    try {
        FlagMaker instance = new TestWrappedFlagMaker(fmc);
        Assert.fail("invalid marker expected");
    } catch (IllegalArgumentException ie) {
        // expected
    }
}
 
Example #6
Source File: FlagMakerTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Test
public void testCounterLimitExceeded() throws Exception {
    log.info("-----  testCounterLimitExceeded  -----");
    int expectedMax = (COUNTER_LIMIT - 2) / 2;
    File f = setUpFlagDir();
    // two days, expectedMax + 20 files each day
    LongRange range = createTestFiles(2, expectedMax + 20, true);
    int total = 2 * 2 * (expectedMax + 20);
    fmc.setSetFlagFileTimestamp(true);
    fmc.setUseFolderTimestamp(true);
    // set the max flags to something larger than the expected limit based on the counters
    fmc.getDefaultCfg().setMaxFlags(expectedMax + 15);
    FlagMaker instance = new TestWrappedFlagMaker(fmc);
    instance.processFlags();
    // ensure the flag files have appropriate sizes
    int a = f.listFiles().length;
    int expectedFlagCount = 0;
    for (File file : f.listFiles()) {
        if (file.getName().endsWith("+" + expectedMax + ".flag")) {
            expectedFlagCount++;
        }
    }
    assertEquals("Unexpected number of flag files with size " + expectedMax, (total / expectedMax), expectedFlagCount);
}
 
Example #7
Source File: FlagMakerTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Test not setting the time stamps of the flag files
 */
@Test
public void testUnsetFlagFileTimeStamps() throws Exception {
    log.info("-----  testUnsetFlagFileTimeStamps  -----");
    File f = setUpFlagDir();
    // two days, 5 files each day, two folders in fmc = 20 flags
    LongRange range = createTestFiles(2, 5);
    fmc.setSetFlagFileTimestamp(false);
    FlagMaker instance = new TestWrappedFlagMaker(fmc);
    instance.processFlags();
    assertEquals("Incorrect files.  Expected 2 but got " + f.listFiles().length + ": " + Arrays.toString(f.listFiles()), 2, f.listFiles().length);
    
    // ensure the flag files have appropriate dates
    for (File file : f.listFiles()) {
        if (file.getName().endsWith(".flag")) {
            assertFalse(range.containsLong(file.lastModified()));
        }
    }
}
 
Example #8
Source File: FlagMakerTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Test of time stamps of the flag files
 */
@Test
public void testFlagFileTimeStamps() throws Exception {
    log.info("-----  testFlagFileTimeStamps  -----");
    File f = setUpFlagDir();
    // two days, 5 files each day, two folders in fmc = 20 flags
    LongRange range = createTestFiles(2, 5);
    fmc.setSetFlagFileTimestamp(true);
    FlagMaker instance = new TestWrappedFlagMaker(fmc);
    instance.processFlags();
    assertEquals("Incorrect files.  Expected 2 but got " + f.listFiles().length + ": " + Arrays.toString(f.listFiles()), 2, f.listFiles().length);
    // ensure the flag files have appropriate dates
    for (File file : f.listFiles()) {
        if (file.getName().endsWith(".flag")) {
            assertTrue(range.containsLong(file.lastModified()));
        }
    }
}
 
Example #9
Source File: FlagMakerTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Test of processFlags method, of class FlagMaker.
 */
@Test
public void testProcessFlags() throws Exception {
    log.info("-----  testProcessFlags  -----");
    File f = setUpFlagDir();
    // two days, 5 files each day, two folders in fmc = 20 flags
    LongRange range = createTestFiles(2, 5);
    FlagMaker instance = new TestWrappedFlagMaker(fmc);
    instance.processFlags();
    
    // ensure the flag files endings
    int flagCnt = 0;
    int cleanCnt = 0;
    for (File file : f.listFiles()) {
        if (file.getName().endsWith(".cleanup")) {
            cleanCnt++;
        } else if (file.getName().endsWith(".flag")) {
            flagCnt++;
        }
    }
    assertEquals(2, flagCnt);
    // no longer have cleanup files
    assertEquals(0, cleanCnt);
}
 
Example #10
Source File: RequestHandlerImplTest.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Tests that a request is split into bunches of 500 and results are gathered in the correct way.
 * @throws JMSException 
 */
@Test
public void getManyTags() throws JMSException {
  Collection<ClientRequestResult> returnCollection = Arrays.asList(new TagConfigImpl(1), new TagConfigImpl(1));
  EasyMock.expect(jmsProxy.sendRequest(EasyMock.isA(JsonRequest.class), 
      EasyMock.eq("c2mon.client.request"), EasyMock.eq(10000), //10000 is timeout
      (ClientRequestReportListener) EasyMock.isNull()
          )).andReturn(returnCollection).times(20);

  EasyMock.replay(jmsProxy);

  LongRange range = new LongRange(1, 10000);

  long[] arrayRange = range.toArray();
  Collection<Long> ids = Arrays.asList(ArrayUtils.toObject(arrayRange));    
  Collection result = requestHandlerImpl.requestTags(ids);
  Assert.assertEquals(40,result.size()); //each request for 500 tags returns 2 objects (faked list back)

  EasyMock.verify(jmsProxy);
}
 
Example #11
Source File: TimeRangeCalendarTest.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAddRemoveExcludedDate() throws ParseException {
    Date startTime = DATE_FORMATTER.parse("04.04.2012 16:00:00:000");
    Date endTime = DATE_FORMATTER.parse("04.04.2012 19:15:00:000");

    LongRange timeRange_1 = new LongRange(startTime.getTime(), endTime.getTime());
    LongRange timeRange_2 = new LongRange(startTime.getTime(), endTime.getTime());

    calendar.addTimeRange(timeRange_2);
    calendar.addTimeRange(timeRange_1);

    Assert.assertEquals(2, calendar.getExcludedRanges().size());
    Assert.assertEquals(timeRange_1, calendar.getExcludedRanges().get(1));
    Assert.assertEquals(timeRange_2, calendar.getExcludedRanges().get(0));

    calendar.removeExcludedDate(timeRange_1);
    Assert.assertEquals(1, calendar.getExcludedRanges().size());
    Assert.assertEquals(timeRange_2, calendar.getExcludedRanges().get(0));
}
 
Example #12
Source File: GlobalIndexDateRangeFilter.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException {
    super.init(source, options, env);
    
    if (options.containsKey(Constants.START_DATE) && options.containsKey(Constants.END_DATE)) {
        long start = Long.parseLong(options.get(Constants.START_DATE));
        long end = Long.parseLong(options.get(Constants.END_DATE));
        
        // The begin date from the query may be down to the second, for doing lookups in the index we want to use the day because
        // the times in the index table have been truncated to the day.
        start = DateUtils.truncate(new Date(start), Calendar.DAY_OF_MONTH).getTime();
        
        if (start > end)
            throw new IllegalArgumentException("Start date comes after end date");
        
        range = new LongRange(start, end);
        if (log.isDebugEnabled()) {
            log.debug("Set the date range to " + new Date(range.getMinimumLong()) + " to " + new Date(range.getMaximumLong()));
        }
    } else {
        throw new IllegalArgumentException("Both options must be set: " + Constants.START_DATE + " and " + Constants.END_DATE);
    }
}
 
Example #13
Source File: AbstractFlagConfig.java    From datawave with Apache License 2.0 5 votes vote down vote up
private LongRange writeTestFiles(File f, int count, long time, boolean folderRange, String postfix) throws IOException {
    if (!f.exists()) {
        f.mkdirs();
    }
    for (int i = 0; i < count; i++) {
        File testFile = new File(f.getAbsolutePath() + File.separator + UUID.randomUUID() + postfix);
        if (testFile.exists()) {
            testFile.delete();
        }
        try (FileOutputStream fos = new FileOutputStream(testFile)) {
            fos.write(("" + System.currentTimeMillis()).getBytes());
        }
        testFile.setLastModified(time + (i * 1000));
    }
    if (folderRange) {
        Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        String[] dir = StringUtils.split(f.getAbsolutePath(), File.separatorChar);
        c.set(Calendar.YEAR, Integer.parseInt(dir[dir.length - 3]));
        c.set(Calendar.MONTH, Integer.parseInt(dir[dir.length - 2]) - 1);
        c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dir[dir.length - 1]));
        return new LongRange(c.getTimeInMillis(), c.getTimeInMillis());
    } else {
        return new LongRange(time, time + ((count - 1) * 1000));
    }
}
 
Example #14
Source File: GetApplicationsRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public LongRange getStartRange() {
  if (this.start == null) {
    GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder;
    if (p.hasStartBegin() || p.hasStartEnd()) {
      long begin = p.hasStartBegin() ? p.getStartBegin() : 0L;
      long end = p.hasStartEnd() ? p.getStartEnd() : Long.MAX_VALUE;
      this.start = new LongRange(begin, end);
    }
  }
  return this.start;
}
 
Example #15
Source File: TimeRangeCalendarTest.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetNextIncludedTime() throws ParseException {
    Date startTime = DATE_FORMATTER.parse("04.04.2012 16:00:00:000");
    Date endTime = DATE_FORMATTER.parse("04.04.2012 19:15:00:000");

    Date included = DATE_FORMATTER.parse("04.04.2012 17:23:21:000");
    Date expected = DATE_FORMATTER.parse("04.04.2012 19:15:00:001");

    LongRange timeRange = new LongRange(startTime.getTime(), endTime.getTime());
    calendar.addTimeRange(timeRange);

    Assert.assertEquals(expected.getTime(), calendar.getNextIncludedTime(included.getTime()));
}
 
Example #16
Source File: FieldIndexCountingIteratorPerVisibility.java    From datawave with Apache License 2.0 5 votes vote down vote up
public FieldIndexCountingIteratorPerVisibility(FieldIndexCountingIteratorPerVisibility other, IteratorEnvironment env) {
    this();
    this.source = other.getSource().deepCopy(env);
    this.seekColumnFamilies = new TreeSet<>(other.seekColumnFamilies);
    this.parentRange = new Range(other.parentRange);
    
    this.stamp_start = other.stamp_start;
    this.stamp_end = other.stamp_end;
    this.stampRange = new LongRange(stamp_start, stamp_end);
    
    this.uniqByDataTypeOption = other.uniqByDataTypeOption;
    this.uniqByVisibilityOption = other.uniqByVisibilityOption;
    if (null != other.fieldNameFilter && !other.fieldNameFilter.isEmpty()) {
        this.fieldNameFilter = new TreeSet<>(other.fieldNameFilter);
    }
    if (null != other.fieldValueFilter && !other.fieldValueFilter.isEmpty()) {
        this.fieldValueFilter = new TreeSet<>(other.fieldValueFilter);
    }
    if (null != other.dataTypeFilter && !other.dataTypeFilter.isEmpty()) {
        this.dataTypeFilter = new TreeSet<>(other.dataTypeFilter);
    }
    
    if (log.isTraceEnabled()) {
        for (ByteSequence bs : this.seekColumnFamilies) {
            log.trace("seekColumnFamilies for this iterator: " + (new String(bs.toArray())).replaceAll("\u0000", "%00"));
        }
    }
    
    this.keyCache.putAll(other.keyCache);
}
 
Example #17
Source File: GetApplicationsRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void setStartRange(long begin, long end)
    throws IllegalArgumentException {
  if (begin > end) {
    throw new IllegalArgumentException("begin > end in range (begin, " +
        "end): (" + begin + ", " + end + ")");
  }
  this.start = new LongRange(begin, end);
}
 
Example #18
Source File: FlagMakerTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Test of the flag count exceeded mechanism
 */
@Test
public void testFlagCountExceeded() throws Exception {
    log.info("-----  testFlagCountExceeded  -----");
    File f = setUpFlagDir();
    
    fmc.setTimeoutMilliSecs(0);
    
    // two days, 5 files each day, two folders in fmc = 20 flags
    LongRange range = createTestFiles(2, 5);
    FlagMaker instance = new TestWrappedFlagMaker(fmc);
    instance.processFlags();
    
    // should have made 2 flag files
    assertEquals("Incorrect files.  Expected 2 but got " + f.listFiles().length + ": " + Arrays.toString(f.listFiles()), 2, f.listFiles().length);
    
    fmc.setFlagCountThreshold(2);
    for (FlagDataTypeConfig fc : fmc.getFlagConfigs()) {
        fc.setFlagCountThreshold(2);
    }
    range = createTestFiles(2, 2);
    
    for (int i = 0; i < 10; i++) {
        instance.processFlags();
        
        // should have not make anymore flag files despite timeout of 0 ms
        assertEquals("Incorrect files.  Expected 2 but got " + f.listFiles().length + ": " + Arrays.toString(f.listFiles()), 2, f.listFiles().length);
    }
    
    range = createTestFiles(2, 1);
    instance.processFlags();
    
    // should have made one more flag file
    assertEquals("Incorrect files.  Expected 3 but got " + f.listFiles().length + ": " + Arrays.toString(f.listFiles()), 3, f.listFiles().length);
}
 
Example #19
Source File: GetApplicationsRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public LongRange getFinishRange() {
  if (this.finish == null) {
    GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder;
    if (p.hasFinishBegin() || p.hasFinishEnd()) {
      long begin = p.hasFinishBegin() ? p.getFinishBegin() : 0L;
      long end = p.hasFinishEnd() ? p.getFinishEnd() : Long.MAX_VALUE;
      this.finish = new LongRange(begin, end);
    }
  }
  return this.finish;
}
 
Example #20
Source File: ShardIndexQueryTable.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static BatchScanner configureBatchScannerForDiscovery(ShardQueryConfiguration config, ScannerFactory scannerFactory, String tableName,
                Collection<Range> ranges, Collection<String> literals, Collection<String> patterns, boolean reverseIndex, boolean uniqueTermsOnly,
                Collection<String> expansionFields) throws TableNotFoundException {
    
    // if we have no ranges, then nothing to scan
    if (ranges.isEmpty()) {
        return null;
    }
    
    BatchScanner bs = scannerFactory.newScanner(tableName, config.getAuthorizations(), config.getNumQueryThreads(), config.getQuery());
    
    bs.setRanges(ranges);
    
    // The begin date from the query may be down to the second, for doing lookups in the index we want to use the day because
    // the times in the index table have been truncated to the day.
    Date begin = DateUtils.truncate(config.getBeginDate(), Calendar.DAY_OF_MONTH);
    // we don't need to bump up the end date any more because it's not apart of the range set on the scanner
    Date end = config.getEndDate();
    
    LongRange dateRange = new LongRange(begin.getTime(), end.getTime());
    
    ShardIndexQueryTableStaticMethods.configureGlobalIndexDateRangeFilter(config, bs, dateRange);
    ShardIndexQueryTableStaticMethods.configureGlobalIndexDataTypeFilter(config, bs, config.getDatatypeFilter());
    
    ShardIndexQueryTableStaticMethods.configureGlobalIndexTermMatchingIterator(config, bs, literals, patterns, reverseIndex, uniqueTermsOnly,
                    expansionFields);
    
    bs.addScanIterator(new IteratorSetting(config.getBaseIteratorPriority() + 50, DiscoveryIterator.class));
    
    return bs;
}
 
Example #21
Source File: GetApplicationsRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void setFinishRange(long begin, long end) {
  if (begin > end) {
    throw new IllegalArgumentException("begin > end in range (begin, " +
        "end): (" + begin + ", " + end + ")");
  }
  this.finish = new LongRange(begin, end);
}
 
Example #22
Source File: FileUtilsTest.java    From webarchive-commons with Apache License 2.0 5 votes vote down vote up
private List<String> getTestHeadLines(File file, int count, int estimate) throws IOException {
    long pos = 0;
    List<String> testLines = new LinkedList<String>();
    do {
        LongRange range = FileUtils.pagedLines(file,pos,count,testLines,estimate);
        pos = range.getMaximumLong();
    } while (pos<file.length());
    return testLines;
}
 
Example #23
Source File: FileUtilsTest.java    From webarchive-commons with Apache License 2.0 5 votes vote down vote up
private List<String> getTestTailLines(File file, int count, int estimate) throws IOException {
    long pos = -1;
    List<String> testLines = new LinkedList<String>();
    do {
        List<String> returnedLines = new LinkedList<String>();
        LongRange range = FileUtils.pagedLines(file,pos,-count,returnedLines,estimate);
        Collections.reverse(returnedLines); 
        testLines.addAll(returnedLines);
        pos = range.getMinimumLong()-1;
    } while (pos>=0);
    Collections.reverse(testLines); 
    return testLines;
}
 
Example #24
Source File: GetApplicationsRequest.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * The request from clients to get a report of Applications matching the
 * giving application types in the cluster from the
 * <code>ResourceManager</code>.
 * </p>
 *
 * @see ApplicationClientProtocol#getApplications(GetApplicationsRequest)
 *
 * <p>Setting any of the parameters to null, would just disable that
 * filter</p>
 *
 * @param scope {@link ApplicationsRequestScope} to filter by
 * @param users list of users to filter by
 * @param queues list of scheduler queues to filter by
 * @param applicationTypes types of applications
 * @param applicationTags application tags to filter by
 * @param applicationStates application states to filter by
 * @param startRange range of application start times to filter by
 * @param finishRange range of application finish times to filter by
 * @param limit number of applications to limit to
 * @return {@link GetApplicationsRequest} to be used with
 * {@link ApplicationClientProtocol#getApplications(GetApplicationsRequest)}
 */
@Public
@Stable
public static GetApplicationsRequest newInstance(
    ApplicationsRequestScope scope,
    Set<String> users,
    Set<String> queues,
    Set<String> applicationTypes,
    Set<String> applicationTags,
    EnumSet<YarnApplicationState> applicationStates,
    LongRange startRange,
    LongRange finishRange,
    Long limit) {
  GetApplicationsRequest request =
      Records.newRecord(GetApplicationsRequest.class);
  if (scope != null) {
    request.setScope(scope);
  }
  request.setUsers(users);
  request.setQueues(queues);
  request.setApplicationTypes(applicationTypes);
  request.setApplicationTags(applicationTags);
  request.setApplicationStates(applicationStates);
  if (startRange != null) {
    request.setStartRange(
        startRange.getMinimumLong(), startRange.getMaximumLong());
  }
  if (finishRange != null) {
    request.setFinishRange(
        finishRange.getMinimumLong(), finishRange.getMaximumLong());
  }
  if (limit != null) {
    request.setLimit(limit);
  }
  return request;
}
 
Example #25
Source File: RMCommunicator.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get list of all applications known to RM according to time range provided.
 *@param set of application types
 * @return list of application report
 * @throws YarnException the yarn exception
 * @throws IOException Signals that an I/O exception has occurred.
 */

public List<ApplicationReport> getApplications(ApplicationsRequestScope scope, Set<String> users,
		Set<String> queues, Set<String> applicationTypes, Set<String> applicationTags,
		EnumSet<YarnApplicationState> applicationStates, Long finishFrom, Long finishTo, Long limit)
				throws YarnException, IOException {
	return proxy
			.getApplications(GetApplicationsRequest.newInstance(scope, users, queues, applicationTypes,
					applicationTags, applicationStates, null, new LongRange(finishFrom, finishTo), limit))
			.getApplicationList();
}
 
Example #26
Source File: GetApplicationsRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public LongRange getStartRange() {
  if (this.start == null) {
    GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder;
    if (p.hasStartBegin() || p.hasStartEnd()) {
      long begin = p.hasStartBegin() ? p.getStartBegin() : 0L;
      long end = p.hasStartEnd() ? p.getStartEnd() : Long.MAX_VALUE;
      this.start = new LongRange(begin, end);
    }
  }
  return this.start;
}
 
Example #27
Source File: GetApplicationsRequest.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * The request from clients to get a report of Applications matching the
 * giving application types in the cluster from the
 * <code>ResourceManager</code>.
 * </p>
 *
 * @see ApplicationClientProtocol#getApplications(GetApplicationsRequest)
 *
 * <p>Setting any of the parameters to null, would just disable that
 * filter</p>
 *
 * @param scope {@link ApplicationsRequestScope} to filter by
 * @param users list of users to filter by
 * @param queues list of scheduler queues to filter by
 * @param applicationTypes types of applications
 * @param applicationTags application tags to filter by
 * @param applicationStates application states to filter by
 * @param startRange range of application start times to filter by
 * @param finishRange range of application finish times to filter by
 * @param limit number of applications to limit to
 * @return {@link GetApplicationsRequest} to be used with
 * {@link ApplicationClientProtocol#getApplications(GetApplicationsRequest)}
 */
@Public
@Stable
public static GetApplicationsRequest newInstance(
    ApplicationsRequestScope scope,
    Set<String> users,
    Set<String> queues,
    Set<String> applicationTypes,
    Set<String> applicationTags,
    EnumSet<YarnApplicationState> applicationStates,
    LongRange startRange,
    LongRange finishRange,
    Long limit) {
  GetApplicationsRequest request =
      Records.newRecord(GetApplicationsRequest.class);
  if (scope != null) {
    request.setScope(scope);
  }
  request.setUsers(users);
  request.setQueues(queues);
  request.setApplicationTypes(applicationTypes);
  request.setApplicationTags(applicationTags);
  request.setApplicationStates(applicationStates);
  if (startRange != null) {
    request.setStartRange(
        startRange.getMinimumLong(), startRange.getMaximumLong());
  }
  if (finishRange != null) {
    request.setFinishRange(
        finishRange.getMinimumLong(), finishRange.getMaximumLong());
  }
  if (limit != null) {
    request.setLimit(limit);
  }
  return request;
}
 
Example #28
Source File: GetApplicationsRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setStartRange(long begin, long end)
    throws IllegalArgumentException {
  if (begin > end) {
    throw new IllegalArgumentException("begin > end in range (begin, " +
        "end): (" + begin + ", " + end + ")");
  }
  this.start = new LongRange(begin, end);
}
 
Example #29
Source File: GetApplicationsRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public LongRange getFinishRange() {
  if (this.finish == null) {
    GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder;
    if (p.hasFinishBegin() || p.hasFinishEnd()) {
      long begin = p.hasFinishBegin() ? p.getFinishBegin() : 0L;
      long end = p.hasFinishEnd() ? p.getFinishEnd() : Long.MAX_VALUE;
      this.finish = new LongRange(begin, end);
    }
  }
  return this.finish;
}
 
Example #30
Source File: GetApplicationsRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setFinishRange(long begin, long end) {
  if (begin > end) {
    throw new IllegalArgumentException("begin > end in range (begin, " +
        "end): (" + begin + ", " + end + ")");
  }
  this.finish = new LongRange(begin, end);
}