Search in sources :

Example 11 with Calendar

use of java.util.Calendar in project jetty.project by eclipse.

the class RFC2616BaseTest method test3_3.

/**
     * Test Date/Time format Specs.
     * 
     * @see <a href="http://tools.ietf.org/html/rfc2616#section-3.3">RFC 2616 (section 3.3)</a>
     */
@Test
public void test3_3() {
    Calendar expected = Calendar.getInstance();
    expected.set(Calendar.YEAR, 1994);
    expected.set(Calendar.MONTH, Calendar.NOVEMBER);
    expected.set(Calendar.DAY_OF_MONTH, 6);
    expected.set(Calendar.HOUR_OF_DAY, 8);
    expected.set(Calendar.MINUTE, 49);
    expected.set(Calendar.SECOND, 37);
    // Milliseconds is not compared
    expected.set(Calendar.MILLISECOND, 0);
    // Use GMT+0:00
    expected.set(Calendar.ZONE_OFFSET, 0);
    // No Daylight Savings Offset
    expected.set(Calendar.DST_OFFSET, 0);
    HttpFields fields = new HttpFields();
    // RFC 822 Preferred Format
    fields.put("D1", "Sun, 6 Nov 1994 08:49:37 GMT");
    // RFC 822 / RFC 850 Format
    fields.put("D2", "Sunday, 6-Nov-94 08:49:37 GMT");
    // RFC 850 / ANSIC C Format
    fields.put("D3", "Sun Nov  6 08:49:37 1994");
    // Test parsing
    assertDate("3.3.1 RFC 822 Preferred", expected, fields.getDateField("D1"));
    assertDate("3.3.1 RFC 822 / RFC 850", expected, fields.getDateField("D2"));
    assertDate("3.3.1 RFC 850 / ANSI C", expected, fields.getDateField("D3"));
    // Test formatting
    fields.putDateField("Date", expected.getTime().getTime());
    Assert.assertEquals("3.3.1 RFC 822 preferred", "Sun, 06 Nov 1994 08:49:37 GMT", fields.get("Date"));
}
Also used : Calendar(java.util.Calendar) HttpFields(org.eclipse.jetty.http.HttpFields) Test(org.junit.Test)

Example 12 with Calendar

use of java.util.Calendar in project hbase by apache.

the class MobUtils method cleanExpiredMobFiles.

/**
   * Cleans the expired mob files.
   * Cleans the files whose creation date is older than (current - columnFamily.ttl), and
   * the minVersions of that column family is 0.
   * @param fs The current file system.
   * @param conf The current configuration.
   * @param tableName The current table name.
   * @param columnDescriptor The descriptor of the current column family.
   * @param cacheConfig The cacheConfig that disables the block cache.
   * @param current The current time.
   * @throws IOException
   */
public static void cleanExpiredMobFiles(FileSystem fs, Configuration conf, TableName tableName, HColumnDescriptor columnDescriptor, CacheConfig cacheConfig, long current) throws IOException {
    long timeToLive = columnDescriptor.getTimeToLive();
    if (Integer.MAX_VALUE == timeToLive) {
        // no need to clean, because the TTL is not set.
        return;
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(current - timeToLive * 1000);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date expireDate = calendar.getTime();
    LOG.info("MOB HFiles older than " + expireDate.toGMTString() + " will be deleted!");
    FileStatus[] stats = null;
    Path mobTableDir = FSUtils.getTableDir(getMobHome(conf), tableName);
    Path path = getMobFamilyPath(conf, tableName, columnDescriptor.getNameAsString());
    try {
        stats = fs.listStatus(path);
    } catch (FileNotFoundException e) {
        LOG.warn("Failed to find the mob file " + path, e);
    }
    if (null == stats) {
        // no file found
        return;
    }
    List<StoreFile> filesToClean = new ArrayList<>();
    int deletedFileCount = 0;
    for (FileStatus file : stats) {
        String fileName = file.getPath().getName();
        try {
            if (HFileLink.isHFileLink(file.getPath())) {
                HFileLink hfileLink = HFileLink.buildFromHFileLinkPattern(conf, file.getPath());
                fileName = hfileLink.getOriginPath().getName();
            }
            Date fileDate = parseDate(MobFileName.getDateFromName(fileName));
            if (LOG.isDebugEnabled()) {
                LOG.debug("Checking file " + fileName);
            }
            if (fileDate.getTime() < expireDate.getTime()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(fileName + " is an expired file");
                }
                filesToClean.add(new StoreFile(fs, file.getPath(), conf, cacheConfig, BloomType.NONE));
            }
        } catch (Exception e) {
            LOG.error("Cannot parse the fileName " + fileName, e);
        }
    }
    if (!filesToClean.isEmpty()) {
        try {
            removeMobFiles(conf, fs, tableName, mobTableDir, columnDescriptor.getName(), filesToClean);
            deletedFileCount = filesToClean.size();
        } catch (IOException e) {
            LOG.error("Failed to delete the mob files " + filesToClean, e);
        }
    }
    LOG.info(deletedFileCount + " expired mob files are deleted");
}
Also used : Path(org.apache.hadoop.fs.Path) HFileLink(org.apache.hadoop.hbase.io.HFileLink) FileStatus(org.apache.hadoop.fs.FileStatus) Calendar(java.util.Calendar) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) StoreFile(org.apache.hadoop.hbase.regionserver.StoreFile)

Example 13 with Calendar

use of java.util.Calendar in project hbase by apache.

the class TestMobCompactor method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.getConfiguration().setLong(MobConstants.MOB_COMPACTION_MERGEABLE_THRESHOLD, 5000);
    TEST_UTIL.getConfiguration().set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
    TEST_UTIL.getConfiguration().set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
    TEST_UTIL.getConfiguration().setLong(TimeToLiveHFileCleaner.TTL_CONF_KEY, 0);
    TEST_UTIL.getConfiguration().setInt("hbase.client.retries.number", 1);
    TEST_UTIL.getConfiguration().setInt("hbase.hfile.compaction.discharger.interval", 100);
    TEST_UTIL.getConfiguration().setBoolean("hbase.online.schema.update.enable", true);
    TEST_UTIL.startMiniCluster(1);
    pool = createThreadPool(TEST_UTIL.getConfiguration());
    conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration(), pool);
    fs = TEST_UTIL.getTestFileSystem();
    conf = TEST_UTIL.getConfiguration();
    admin = TEST_UTIL.getAdmin();
    // Initialize timestamps for these days
    Calendar calendar = Calendar.getInstance();
    calendar.set(2015, 8, 7, 10, 20);
    tsFor20150907Monday = calendar.getTimeInMillis();
    calendar.set(2015, 10, 20, 10, 20);
    tsFor20151120Sunday = calendar.getTimeInMillis();
    calendar.set(2015, 10, 28, 10, 20);
    tsFor20151128Saturday = calendar.getTimeInMillis();
    calendar.set(2015, 10, 30, 10, 20);
    tsFor20151130Monday = calendar.getTimeInMillis();
    calendar.set(2015, 11, 1, 10, 20);
    tsFor20151201Tuesday = calendar.getTimeInMillis();
    calendar.set(2015, 11, 5, 10, 20);
    tsFor20151205Saturday = calendar.getTimeInMillis();
    calendar.set(2015, 11, 28, 10, 20);
    tsFor20151228Monday = calendar.getTimeInMillis();
    calendar.set(2015, 11, 31, 10, 20);
    tsFor20151231Thursday = calendar.getTimeInMillis();
    calendar.set(2016, 0, 1, 10, 20);
    tsFor20160101Friday = calendar.getTimeInMillis();
    calendar.set(2016, 0, 3, 10, 20);
    tsFor20160103Sunday = calendar.getTimeInMillis();
}
Also used : Calendar(java.util.Calendar) KeyProviderForTesting(org.apache.hadoop.hbase.io.crypto.KeyProviderForTesting) BeforeClass(org.junit.BeforeClass)

Example 14 with Calendar

use of java.util.Calendar in project lucida by claritylab.

the class TextProcessor method getDateFromWeek.

/** 
	 *  Returns the date string represented by week_num. 
	 *
	 *  @param week_num int indicating the index of the week in the current year
	 */
private String getDateFromWeek(int week_num) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.WEEK_OF_YEAR, week_num);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    return sdf.format(cal.getTime()).toString() + "T00:00:00";
}
Also used : Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 15 with Calendar

use of java.util.Calendar in project cdk-examples by cloudera.

the class StagingToPersistentSerial method run.

@Override
public int run(String[] args) throws Exception {
    // open the repository
    final DatasetRepository repo = DatasetRepositories.open("repo:file:/tmp/data");
    final Calendar now = Calendar.getInstance();
    final long yesterdayTimestamp = now.getTimeInMillis() - DAY_IN_MILLIS;
    // the destination dataset
    final Dataset<GenericRecord> persistent = repo.load("logs");
    final DatasetWriter<GenericRecord> writer = persistent.newWriter();
    writer.open();
    // the source dataset: yesterday's partition in the staging area
    final Dataset<GenericRecord> staging = repo.load("logs-staging");
    final PartitionKey yesterday = getPartitionKey(staging, yesterdayTimestamp);
    final DatasetReader<GenericRecord> reader = staging.getPartition(yesterday, false).newReader();
    try {
        reader.open();
        // yep, it's that easy.
        for (GenericRecord record : reader) {
            writer.write(record);
        }
    } finally {
        reader.close();
        writer.flush();
    }
    // remove the source data partition from staging
    staging.dropPartition(yesterday);
    // if the above didn't throw an exception, commit the data
    writer.close();
    return 0;
}
Also used : DatasetRepository(com.cloudera.cdk.data.DatasetRepository) Calendar(java.util.Calendar) PartitionKey(com.cloudera.cdk.data.PartitionKey) GenericRecord(org.apache.avro.generic.GenericRecord)

Aggregations

Calendar (java.util.Calendar)9441 Date (java.util.Date)2433 GregorianCalendar (java.util.GregorianCalendar)2129 Test (org.junit.Test)1734 SimpleDateFormat (java.text.SimpleDateFormat)889 ArrayList (java.util.ArrayList)476 ParseException (java.text.ParseException)352 HashMap (java.util.HashMap)270 TimeZone (java.util.TimeZone)270 IOException (java.io.IOException)235 DateFormat (java.text.DateFormat)224 Timestamp (java.sql.Timestamp)192 List (java.util.List)187 File (java.io.File)167 Map (java.util.Map)149 BigDecimal (java.math.BigDecimal)134 Locale (java.util.Locale)134 Test (org.testng.annotations.Test)118 Identity (org.olat.core.id.Identity)112 Date (java.sql.Date)110