List of usage examples for java.util.concurrent TimeUnit NANOSECONDS
TimeUnit NANOSECONDS
To view the source code for java.util.concurrent TimeUnit NANOSECONDS.
Click Source Link
From source file:com.netflix.genie.web.jobs.workflow.impl.ClusterTask.java
/** * {@inheritDoc}//w w w . j a v a 2 s. com */ @Override public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException { final Set<Tag> tags = Sets.newHashSet(); final long start = System.nanoTime(); try { final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context .get(JobConstants.JOB_EXECUTION_ENV_KEY); final Cluster cluster = jobExecEnv.getCluster(); tags.add(Tag.of(MetricsConstants.TagKeys.CLUSTER_NAME, cluster.getMetadata().getName())); tags.add(Tag.of(MetricsConstants.TagKeys.CLUSTER_ID, cluster.getId())); final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath(); final String genieDir = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + JobConstants.GENIE_PATH_VAR; final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY); log.info("Starting Cluster Task for job {}", jobExecEnv.getJobRequest().getId().orElse(NO_ID_FOUND)); final String clusterId = cluster.getId(); // Create the directory for this application under applications in the cwd createEntityInstanceDirectory(genieDir, clusterId, AdminResources.CLUSTER); // Create the config directory for this id createEntityInstanceConfigDirectory(genieDir, clusterId, AdminResources.CLUSTER); // Create the dependencies directory for this id createEntityInstanceDependenciesDirectory(genieDir, clusterId, AdminResources.CLUSTER); // Get the set up file for cluster and add it to source in launcher script final Optional<String> setupFile = cluster.getResources().getSetupFile(); if (setupFile.isPresent()) { final String clusterSetupFile = setupFile.get(); if (StringUtils.isNotBlank(clusterSetupFile)) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, clusterId, clusterSetupFile, FileType.SETUP, AdminResources.CLUSTER); this.fts.getFile(clusterSetupFile, localPath); super.generateSetupFileSourceSnippet(clusterId, "Cluster:", localPath, writer, jobWorkingDirectory); } } // Iterate over and get all configuration files for (final String configFile : cluster.getResources().getConfigs()) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, clusterId, configFile, FileType.CONFIG, AdminResources.CLUSTER); this.fts.getFile(configFile, localPath); } // Iterate over and get all dependencies for (final String dependencyFile : cluster.getResources().getDependencies()) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, clusterId, dependencyFile, FileType.DEPENDENCIES, AdminResources.CLUSTER); this.fts.getFile(dependencyFile, localPath); } log.info("Finished Cluster Task for job {}", jobExecEnv.getJobRequest().getId().orElse(NO_ID_FOUND)); MetricsUtils.addSuccessTags(tags); } catch (final Throwable t) { MetricsUtils.addFailureTagsWithException(tags, t); throw t; } finally { this.getRegistry().timer(CLUSTER_TASK_TIMER_NAME, tags).record(System.nanoTime() - start, TimeUnit.NANOSECONDS); } }
From source file:org.agatom.springatom.cmp.wizards.core.AbstractWizardProcessor.java
/** * Executes actual binding. Provider {@link org.springframework.validation.DataBinder} is used to verify * if {@link org.springframework.validation.DataBinder#getTarget()} is valid in context of raw field to actual field mapping. * For instance {@code params.get(anAttribute)} must have corresponding property in {@code binder.getTargetObject()}. * Type mismatches are resolved via supplied {@link java.beans.PropertyEditorSupport} instances available through {@code binder} and * registered before this method executes * * @param binder binder to use, must be initialized prior this method calling * @param step current step, may be null if {@code binder} binds entire wizard * @param params supplied params to be set in {@link org.springframework.validation.DataBinder#getTarget()} * @param locale current locale/*ww w . j a v a 2s .com*/ * * @return local {@link org.agatom.springatom.cmp.wizards.data.result.WizardResult} * * @throws Exception if any */ protected WizardResult bind(final DataBinder binder, final String step, final ModelMap params, final Locale locale) throws Exception { final WizardResult localResult = new WizardResult().setStepId(step).setWizardId(this.getWizardID()); final long startTime = System.nanoTime(); try { this.doBind(binder, params); } catch (Exception exp) { LOGGER.error("Binding error detected", exp); localResult.addError(exp); } this.addErrorsToResultIfAny(binder, locale, localResult); final long endTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime); localResult.addDebugData(WizardDebugDataKeys.BINDING_TIME, endTime); localResult.addDebugData(WizardDebugDataKeys.IS_STEP_BINDING, StringUtils.hasText(step)); localResult.addDebugData(WizardDebugDataKeys.DATA_SIZE, params.size()); if ((this.isValidationEnabled() || this.isValidationEnabledForStep(step))) { // Do not validate if bindingErrors this.doValidate(localResult, binder, step, params, locale); } return localResult; }
From source file:rmblworx.tools.timey.SimpleTimerTest.java
/** * Test method for {@link SimpleTimer#toggleTimeModeInStopwatch()}. * * @throws InterruptedException/*from w ww . j a v a 2s . c om*/ * wenn beim schlafenlegen des Threads eine Ausnahme auftrat */ @Test public final void testToggleTimeModeInStopwatchSimpleCase() throws InterruptedException { TimeDescriptor td = new TimeDescriptor(0L); this.timer = new SimpleTimer(td); this.timer.setApplicationContext(this.springContext); td = this.timer.startStopwatch(1, TimeUnit.NANOSECONDS); Thread.sleep(DELAY); assertTrue("Stoppuhr luft nicht!", td.getMilliSeconds() > 0); // TIME-Mode ein this.timer.toggleTimeModeInStopwatch(); long expected = td.getMilliSeconds(); Thread.sleep(DELAY); long actual = td.getMilliSeconds(); assertEquals("Stoppuhr zhlt weiter obwohl TIME-Mode aktiv!", expected, actual); // TIME-Mode aus this.timer.toggleTimeModeInStopwatch(); expected = td.getMilliSeconds(); Thread.sleep(DELAY); actual = td.getMilliSeconds(); assertNotEquals("Stoppuhr hat den TIME-Modus nicht deaktiviert!", expected, actual); this.timer.stopStopwatch(); }
From source file:org.apache.hadoop.mapred.gridmix.GridmixJob.java
public long getDelay(TimeUnit unit) { return unit.convert(submissionTimeNanos - System.nanoTime(), TimeUnit.NANOSECONDS); }
From source file:com.netflix.genie.web.security.saml.SAMLUserDetailsServiceImplUnitTests.java
/** * Make sure if user logs in and has admin group they get admin rights. *//*from w ww . j av a 2 s .co m*/ @Test public void canLoadUserWithAdminGroup() { final SAMLCredential credential = Mockito.mock(SAMLCredential.class); Mockito.when(credential.getAttributeAsString(Mockito.eq(USER_ATTRIBUTE_NAME))).thenReturn(USER_ID); Mockito.when(credential.getAttributeAsStringArray(Mockito.eq(GROUP_ATTRIBUTE_NAME))).thenReturn(GROUPS); final Object result = this.service.loadUserBySAML(credential); Assert.assertThat(result, Matchers.notNullValue()); Assert.assertTrue(result instanceof User); final User user = (User) result; Assert.assertThat(user.getUsername(), Matchers.is(USER_ID)); Assert.assertThat(user.getAuthorities(), Matchers.hasItems(new SimpleGrantedAuthority("ROLE_USER"), new SimpleGrantedAuthority("ROLE_ADMIN"))); Mockito.verify(this.loadAuthenticationTimer, Mockito.times(1)).record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); }
From source file:org.apache.hadoop.hbase.client.AsyncSingleRequestRpcRetryingCaller.java
private void onError(Throwable error, Supplier<String> errMsg, Consumer<Throwable> updateCachedLocation) { error = translateException(error);//from w w w . j a v a 2 s. com if (tries > startLogErrorsCnt) { LOG.warn(errMsg.get(), error); } RetriesExhaustedException.ThrowableWithExtraContext qt = new RetriesExhaustedException.ThrowableWithExtraContext( error, EnvironmentEdgeManager.currentTime(), ""); exceptions.add(qt); if (error instanceof DoNotRetryIOException || tries >= maxAttempts) { completeExceptionally(); return; } long delayNs; if (operationTimeoutNs > 0) { long maxDelayNs = operationTimeoutNs - (System.nanoTime() - startNs); if (maxDelayNs <= 0) { completeExceptionally(); return; } delayNs = Math.min(maxDelayNs, getPauseTime(pauseNs, tries - 1)); } else { delayNs = getPauseTime(pauseNs, tries - 1); } updateCachedLocation.accept(error); tries++; retryTimer.newTimeout(new TimerTask() { @Override public void run(Timeout timeout) throws Exception { // always restart from beginning. locateThenCall(); } }, delayNs, TimeUnit.NANOSECONDS); }
From source file:com.netflix.genie.web.services.impl.HttpFileTransferImplTest.java
/** * Make sure we can actually get a file. * * @throws GenieException On error/*from w w w .ja v a 2 s . c o m*/ * @throws IOException On error */ @Test public void canGet() throws GenieException, IOException { final File output = this.temporaryFolder.newFile(); final String contents = UUID.randomUUID().toString(); this.server.expect(MockRestRequestMatchers.requestTo(TEST_URL)) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) .andRespond(MockRestResponseCreators.withSuccess(contents.getBytes(Charset.forName("UTF-8")), MediaType.APPLICATION_OCTET_STREAM)); this.httpFileTransfer.getFile(TEST_URL, output.getCanonicalPath()); this.server.verify(); Mockito.verify(this.downloadTimerId, Mockito.times(1)).withTags(MetricsUtils.newSuccessTagsMap()); Mockito.verify(this.downloadTimer, Mockito.times(1)).record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); }
From source file:org.apache.bookkeeper.bookie.InterleavedStorageRegenerateIndexOp.java
public void initiate(boolean dryRun) throws IOException { LOG.info("Starting index rebuilding"); DiskChecker diskChecker = Bookie.createDiskChecker(conf); LedgerDirsManager ledgerDirsManager = Bookie.createLedgerDirsManager(conf, diskChecker, NullStatsLogger.INSTANCE);// w w w . j a v a 2s . co m LedgerDirsManager indexDirsManager = Bookie.createIndexDirsManager(conf, diskChecker, NullStatsLogger.INSTANCE, ledgerDirsManager); EntryLogger entryLogger = new EntryLogger(conf, ledgerDirsManager); final LedgerCache ledgerCache; if (dryRun) { ledgerCache = new DryRunLedgerCache(); } else { ledgerCache = new LedgerCacheImpl(conf, new SnapshotMap<Long, Boolean>(), indexDirsManager, NullStatsLogger.INSTANCE); } Set<Long> entryLogs = entryLogger.getEntryLogsSet(); int totalEntryLogs = entryLogs.size(); int completedEntryLogs = 0; long startTime = System.nanoTime(); LOG.info("Scanning {} entry logs", totalEntryLogs); Map<Long, RecoveryStats> stats = new HashMap<>(); for (long entryLogId : entryLogs) { LOG.info("Scanning {}", entryLogId); entryLogger.scanEntryLog(entryLogId, new EntryLogScanner() { @Override public void process(long ledgerId, long offset, ByteBuf entry) throws IOException { long entryId = entry.getLong(8); stats.computeIfAbsent(ledgerId, (ignore) -> new RecoveryStats()).registerEntry(entryId); // Actual location indexed is pointing past the entry size long location = (entryLogId << 32L) | (offset + 4); if (LOG.isDebugEnabled()) { LOG.debug("Rebuilding {}:{} at location {} / {}", ledgerId, entryId, location >> 32, location & (Integer.MAX_VALUE - 1)); } if (!ledgerCache.ledgerExists(ledgerId)) { ledgerCache.setMasterKey(ledgerId, masterKey); ledgerCache.setFenced(ledgerId); } ledgerCache.putEntryOffset(ledgerId, entryId, location); } @Override public boolean accept(long ledgerId) { return ledgerIds.contains(ledgerId); } }); ledgerCache.flushLedger(true); ++completedEntryLogs; LOG.info("Completed scanning of log {}.log -- {} / {}", Long.toHexString(entryLogId), completedEntryLogs, totalEntryLogs); } LOG.info("Rebuilding indices done"); for (long ledgerId : ledgerIds) { RecoveryStats ledgerStats = stats.get(ledgerId); if (ledgerStats == null || ledgerStats.getNumEntries() == 0) { LOG.info(" {} - No entries found", ledgerId); } else { LOG.info(" {} - Found {} entries, from {} to {}", ledgerId, ledgerStats.getNumEntries(), ledgerStats.getFirstEntry(), ledgerStats.getLastEntry()); } } LOG.info("Total time: {}", DurationFormatUtils .formatDurationHMS(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime))); }
From source file:org.apache.hadoop.hbase.client.AsyncSingleRequestRpcRetryingCaller.java
private void resetController() { controller.reset();/* w ww. j av a 2 s. c o m*/ if (rpcTimeoutNs >= 0) { controller .setCallTimeout((int) Math.min(Integer.MAX_VALUE, TimeUnit.NANOSECONDS.toMillis(rpcTimeoutNs))); } }
From source file:org.agatom.springatom.cmp.wizards.validation.ValidationServiceImpl.java
@Override public void validate(final ValidationBean validationBean) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("validate(validationBean=%s)", validationBean)); }//from ww w . j a v a 2 s . co m final long startTime = System.nanoTime(); { final String commandBeanName = validationBean.getCommandBeanName(); if (!StringUtils.hasText(commandBeanName) || WizardProcessor.DEFAULT_FORM_OBJECT_NAME.equals(commandBeanName)) { LOGGER.warn(String.format("Validation is not possible because commandBeanName(name=%s) is invalid", commandBeanName)); return; } final Object validator = this.repository.getValidator(commandBeanName); if (validator == null) { LOGGER.debug( String.format("For commandBeanName=%s there is no associated validator", commandBeanName)); return; } final String stepId = validationBean.getStepId(); WizardResult partialResult = validationBean.getPartialResult(); MessageContext messageContext; if (StringUtils.hasText(stepId)) { messageContext = this.validateStep(validator, stepId, validationBean); } else { messageContext = this.validateGlobal(validator, validationBean); } partialResult = this.applyMessages(messageContext, partialResult); partialResult.addDebugData(WizardDebugDataKeys.VALIDATOR, ClassUtils.getShortName(validator.getClass())); validationBean.setPartialResult(partialResult); } final long endTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime); validationBean.getPartialResult().addDebugData(VALIDATION_TIME, endTime); LOGGER.debug(String.format("validate(validationBean=%s) took %d ms", validationBean, endTime)); }