List of usage examples for java.time Instant now
public static Instant now()
From source file:org.lendingclub.mercator.newrelic.NewRelicScanner.java
/** * Scans all the servers ( reporting and non-reporting ) in NewRelic. * /*from w w w .j av a2s. c om*/ */ private void scanServers() { Instant startTime = Instant.now(); ObjectNode servers = getNewRelicClient().getServers(); Preconditions.checkNotNull(getProjector().getNeoRxClient(), "neorx client must be set"); String cypher = "WITH {json} as data " + "UNWIND data.servers as server " + "MERGE ( s:NewRelicServer { nr_serverId: toString(server.id), nr_accountId:{accountId} } ) " + "ON CREATE SET s.name = server.name, s.host = server.host, s.healthStatus = server.health_status, s.reporting = server.reporting, " + "s.lastReportedAt = server.last_reported_at, s.createTs = timestamp(), s.updateTs = timestamp() " + "ON MATCH SET s.name = server.name, s.host = server.host, s.healthStatus = server.health_status, s.reporting = server.reporting, " + "s.lastReportedAt = server.last_reported_at, s.updateTs = timestamp()"; getProjector().getNeoRxClient().execCypher(cypher, "json", servers, "accountId", clientSupplier.get().getAccountId()); Instant endTime = Instant.now(); logger.info("Updating neo4j with the latest information about {} NewRelic Servers took {} secs", servers.get("servers").size(), Duration.between(startTime, endTime).getSeconds()); }
From source file:org.createnet.raptor.models.auth.Token.java
public boolean isExpired() { return getExpiresInstant() != null && getExpiresInstant().isBefore(Instant.now()); }
From source file:ai.grakn.engine.tasks.manager.StandaloneTaskManager.java
@Override public void addTask(TaskState taskState) { stateStorage.newState(taskState);/*from www.j av a 2 s . c om*/ // Schedule task to run. Instant now = Instant.now(); TaskSchedule schedule = taskState.schedule(); long delay = Duration.between(now, schedule.runAt()).toMillis(); try { stateStorage.updateState(taskState.markScheduled()); // Instantiate task. BackgroundTask task = taskState.taskClass().newInstance(); ScheduledFuture<?> future = schedule.interval() .map(interval -> schedulingService.scheduleAtFixedRate(runTask(taskState.getId(), task, true), delay, interval.toMillis(), MILLISECONDS)) .orElseGet(() -> (ScheduledFuture) schedulingService .schedule(runTask(taskState.getId(), task, false), delay, MILLISECONDS)); instantiatedTasks.put(taskState.getId(), new Pair<>(future, task)); } catch (Throwable throwable) { LOG.error(getFullStackTrace(throwable)); stateStorage.updateState(taskState.markFailed(throwable)); instantiatedTasks.remove(taskState.getId()); } }
From source file:cloudfoundry.norouter.f5.Agent.java
public void removeStalePools() { LOGGER.info("Checking for stale pools prefixed with {}", poolNamePrefix); client.getAllPools(true).stream().filter(pool -> pool.getName().startsWith(poolNamePrefix)) .filter(pool -> !pool.getMembers().isPresent() || pool.getMembers().get().size() == 0) .filter(pool -> {// ww w .j av a 2 s .c o m // Filter out non stale pools. final Optional<PoolDescription> description = PoolDescription .fromJsonish(pool.getDescription()); if (description.isPresent()) { final Duration timeSinceModified = Duration.between(description.get().getModified(), Instant.now()); return POOL_STALE_TIME.compareTo(timeSinceModified) < 0; } return false; }).forEach(pool -> safeDeletePool(pool.getName())); }
From source file:eu.hansolo.tilesfx.tools.Location.java
public Location(final double LATITUDE, final double LONGITUDE, final String NAME, final String INFO, final TileColor COLOR) { this(LATITUDE, LONGITUDE, 0, Instant.now(), NAME, INFO, COLOR); }
From source file:co.runrightfast.component.events.impl.ComponentEventImpl.java
public ComponentEventImpl(@NonNull final ComponentId componentId, @NonNull final Event<DATA> event, @NonNull final DATA data) { this(componentId, UUID.randomUUID(), Instant.now(), AppUtils.JVM_ID, event, Optional.of(data), Optional.empty(), Optional.empty()); }
From source file:org.lendingclub.mercator.dynect.DynectScanner.java
private List<String> scanZones() { Instant startTime = Instant.now(); logger.info("Scanning all zones in Dynect"); ObjectNode response = getDynectClient().get("REST/Zone/"); JsonNode zoneData = response.path("data"); List<String> zonesList = new ArrayList<String>(); if (zoneData.isArray()) { zoneData.forEach(zone -> {//w w w . j av a 2 s. c om String zoneNode = zone.asText(); String zoneName = Splitter.on("/").splitToList(zoneNode).get(3); zonesList.add(zoneName); }); } logger.info("Scanning {} zones in Dynect to get more details", zonesList.size()); for (String zone : zonesList) { response = getDynectClient().get("REST/Zone/" + zone); logger.debug("Scanning {} zone", zone); ObjectNode n = toZoneJson(response.get("data")); Preconditions.checkNotNull(getProjector().getNeoRxClient(), "neorx client must be set"); String cypher = "MERGE (m:DynHostedZone {zoneName:{zone}}) " + "ON CREATE SET m+={props}, m.createTs = timestamp(), m.updateTs=timestamp() " + "ON MATCH SET m+={props}, m.updateTs=timestamp();"; getProjector().getNeoRxClient().execCypher(cypher, "zone", zone, "props", n); } Instant endTime = Instant.now(); logger.info("Updating neo4j with the latest information of all {} zones from Dynect took {} secs", zonesList.size(), Duration.between(startTime, endTime).getSeconds()); return zonesList; }
From source file:edu.usu.sdl.openstorefront.report.SubmissionsReport.java
private void updateReportTimeRange() { if (report.getReportOption().getPreviousDays() != null) { Instant instant = Instant.now(); instant = instant.minus(1, ChronoUnit.DAYS); report.getReportOption().setStartDts(TimeUtil.beginningOfDay(new Date(instant.toEpochMilli()))); report.getReportOption().setEndDts(TimeUtil.endOfDay(new Date(instant.toEpochMilli()))); }/*from w ww . j a va 2 s.c o m*/ if (report.getReportOption().getStartDts() == null) { report.getReportOption().setStartDts(TimeUtil.beginningOfDay(new Date())); } if (report.getReportOption().getEndDts() == null) { report.getReportOption().setEndDts(TimeUtil.endOfDay(new Date())); } }
From source file:com.muk.services.util.GoogleOAuthService.java
private String createClaim(String scope, String privateKeyAlias, String account) { final Instant issued = Instant.now(); final Instant expirePlusHour = issued.plus(50, ChronoUnit.MINUTES); final StringBuilder sb = new StringBuilder(); sb.append("{\"iss\":\"").append(account).append("\",\"scope\":\"").append(scope).append("\",\"aud\":\"") .append(JWT_AUD).append("\",\"exp\":").append(expirePlusHour.getEpochSecond()).append(",\"iat\":") .append(issued.getEpochSecond()).append(",\"sub\":\"").append(JWT_SUB).append("\"}"); /*//from ww w .jav a 2 s. c o m * sb.append("{\"iss\":\"").append(account).append("\",\"scope\":\"").append(scope).append("\",\"aud\":\"") * .append(JWT_AUD).append("\",\"exp\":").append(expirePlusHour.getEpochSecond()).append(",\"iat\":") * .append(issued.getEpochSecond()).append("}"); */ String jwt = JWT_HEADER + "." + cryptoService.encodeUrlSafe(sb.toString().getBytes(StandardCharsets.UTF_8)); try { jwt = jwt + "." + cryptoService.signature("SHA256withRSA", jwt, keystoreService.getPrivateKey(privateKeyAlias)); } catch (final IOException ioEx) { LOG.error("Failed to access keystore.", ioEx); } catch (final GeneralSecurityException secEx) { LOG.error("Failed to sign jwt.", secEx); } return jwt; }
From source file:com.orange.cepheus.broker.persistence.SubscriptionsRepositoryTest.java
@Test public void saveSubscriptionWithDuplicateKeyExceptionTest() throws URISyntaxException, SubscriptionPersistenceException { thrown.expect(SubscriptionPersistenceException.class); SubscribeContext subscribeContext = createSubscribeContextTemperature(); Subscription subscription = new Subscription("12345", Instant.now().plus(1, ChronoUnit.DAYS), subscribeContext);// w w w .j a v a2 s . co m subscriptionsRepository.saveSubscription(subscription); subscriptionsRepository.saveSubscription(subscription); }