List of usage examples for java.time Instant now
public static Instant now()
From source file:org.lendingclub.mercator.bind.BindScanner.java
@SuppressWarnings("unchecked") private void scanRecordSetByZone() { Instant startTime = Instant.now(); List<String> zones = getBindClient().getZones(); Preconditions.checkNotNull(getProjector().getNeoRxClient(), "neorx client must be set"); zones.forEach(zone -> {/*from www. j a v a 2 s . co m*/ logger.info("Scanning the zone {}", zone); Optional<List> recordsStream = getBindClient().getRecordsbyZone(zone); if (!recordsStream.get().isEmpty()) { logger.info("Found {} records in {} zone", recordsStream.get().size(), zone); recordsStream.get().forEach(record -> { String line = record.toString(); if (!line.startsWith(";")) { ResourceRecordSet<Map<String, Object>> dnsRecord = getRecord(line); ObjectNode recordNode = dnsRecord.toJson(); String cypher = "MATCH (z:BindHostedZone {zoneName:{zone}}) " + "MERGE (m:BindHostedZoneRecord {domainName:{dn}, type:{type}, zoneName:{zone}}) " + "ON CREATE SET m.ttl={ttl}, m.class={class}, m+={props}, m.createTs = timestamp(), m.updateTs=timestamp() " + "ON MATCH SET m+={props}, m.updateTs=timestamp() " + "MERGE (z)-[:CONTAINS]->(m);"; getProjector().getNeoRxClient().execCypher(cypher, "dn", recordNode.get("name").asText(), "type", recordNode.get("type").asText(), "ttl", recordNode.get("ttl").asText(), "class", recordNode.get("class").asText(), "props", recordNode.get("rData"), "zone", zone); } }); } else { logger.error("Failed to obtain any records in {} zone", zone); } }); Instant endTime = Instant.now(); logger.info(" Took {} secs to project Bind records to Neo4j", Duration.between(startTime, endTime).getSeconds()); }
From source file:org.eclipse.hono.util.SpringBasedExpiringValueCache.java
@Override public void put(K key, V value, Duration maxAge) { Objects.requireNonNull(key);//from w w w .ja v a2 s.co m Objects.requireNonNull(value); Objects.requireNonNull(maxAge); put(key, value, Instant.now().plus(maxAge)); }
From source file:org.sakuli.services.common.LogCleanUpResultServiceImpl.java
/** * Cleans the {@link Path} from files, which are older then {@link SakuliProperties#logMaxAge}. * On error no exception will be thrown, du to the facts, that`s only a optional cleanup. * * @param path root folder of files to clean *///from w w w. j ava 2 s . c o m void cleanUpDirectory(Path path) { try { Instant maxDate = Instant.now().minus(sakuliProperties.getLogMaxAge(), ChronoUnit.DAYS); Files.newDirectoryStream(path).forEach(e -> { if (Files.isDirectory(e)) { cleanUpDirectory(e); } else if (Files.isRegularFile(e)) { try { if (Files.getLastModifiedTime(e).toInstant().isBefore(maxDate)) { LOGGER.info("cleanup to old log file '{}'", e); Files.deleteIfExists(e); } } catch (IOException e1) { LOGGER.error("can`t delete file", e1); } } }); } catch (IOException e) { LOGGER.error("couldn`t access log file directory '" + path + "'", e); } }
From source file:org.apache.aurora.scheduler.events.Webhook.java
private HttpPost createPostRequest(TaskStateChange stateChange) throws UnsupportedEncodingException { String eventJson = stateChange.toJson(); HttpPost post = new HttpPost(); post.setURI(webhookInfo.getTargetURI()); post.setHeader("Timestamp", Long.toString(Instant.now().toEpochMilli())); post.setEntity(new StringEntity(eventJson)); webhookInfo.getHeaders().entrySet().forEach(e -> post.setHeader(e.getKey(), e.getValue())); return post;/*from w w w .j a va2 s . c o m*/ }
From source file:org.lendingclub.mercator.dynect.DynectScanner.java
private void scanAllRecordsByZone(List<String> zones) { Instant startTime = Instant.now(); logger.info("Scanning all records in each available zones"); for (String zone : zones) { logger.debug("Scanning all records in Dynect zone {} ", zone); ObjectNode response = getDynectClient().get("REST/AllRecord/" + zone); JsonNode recordsData = response.path("data"); if (recordsData.isArray()) { recordsData.forEach(record -> { String recordFullName = record.asText(); logger.debug("Scanning {} record for more information in {} zone", recordFullName, zone); ObjectNode recordResponse = getDynectClient().get(recordFullName); ObjectNode data = toRecordJson(recordResponse.get("data")); String recordId = Splitter.on("/").splitToList(recordFullName).get(5); String cypher = "MATCH (z:DynHostedZone {zoneName:{zone}})" + "MERGE (m:DynHostedZoneRecord {recordId:{recordId}}) " + "ON CREATE SET m+={props}, m.createTs = timestamp(), m.updateTs=timestamp() " + "ON MATCH SET m+={props}, m.updateTs=timestamp() " + "MERGE (z)-[:CONTAINS]->(m);"; getProjector().getNeoRxClient().execCypher(cypher, "recordId", recordId, "props", data, "zone", zone);/*from w w w . ja v a 2 s . com*/ }); } } Instant endTime = Instant.now(); logger.info("Updating neo4j with the latest information of all records from zones in Dynect took {} secs", Duration.between(startTime, endTime).getSeconds()); }
From source file:com.vmware.photon.controller.api.client.resource.ImagesApiTest.java
@Test public void testUploadImage() throws IOException { File temp = File.createTempFile("temp-image", ".vmdk"); (new File(temp.getAbsolutePath())).deleteOnExit(); Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ImagesApi imagesApi = new ImagesApi(this.restClient); Task task = imagesApi.uploadImage(temp.getAbsolutePath()); assertEquals(task, responseTask);// www .j a v a2 s.c om }
From source file:nl.ctrlaltdev.harbinger.response.BlacklistIpActionTest.java
@Test public void shouldCleanEvidenceAfterBlacklisting() { Evidence src = new Evidence(request); Evidence trigger = new Evidence(src, new RuntimeException()); ctx.getEvidenceCollector().store(trigger); assertEquals(1, ctx.getEvidenceCollector().findByIp(trigger).getExceptions()); assertTrue(action.perform(ctx));//from w ww. j a v a2 s. c o m assertTrue(ctx.isBlacklisted("8.8.8.8", Instant.now())); assertEquals(0, ctx.getEvidenceCollector().findByIp(src).getExceptions()); }
From source file:com.vmware.photon.controller.api.client.resource.ImagesRestApiTest.java
@Test public void testUploadImage() throws IOException { File temp = File.createTempFile("temp-image", ".vmdk"); (new File(temp.getAbsolutePath())).deleteOnExit(); Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ImagesApi imagesApi = new ImagesRestApi(this.restClient); Task task = imagesApi.uploadImage(temp.getAbsolutePath()); assertEquals(task, responseTask);//from w w w .j ava 2 s . c o m }
From source file:com.pw.ism.heartbeat.InMemoryHeartbeatRepositoryTest.java
@Test public void shouldRemoveHeartbeats() { Heartbeat hb1 = new Heartbeat(); hb1.setCustomer("TEST1"); hb1.setNetwork("NETWORK1"); repo.addHeartbeat(hb1, Instant.now().minusSeconds(5)); List<Heartbeat> list = repo.getExpiredHeartbeats(3); Assert.isTrue(list.contains(hb1));//from w ww. j a v a 2 s . c om Heartbeat hb2 = new Heartbeat(); hb2.setCustomer("TEST1"); hb2.setNetwork("NETWORK1"); Assert.isTrue(hb1.equals(hb2)); repo.removeHeartbeat(hb2); list = repo.getExpiredHeartbeats(3); //Assert.isTrue(list.contains(hb1)); Assert.isTrue(list.isEmpty()); }
From source file:com.vmware.photon.controller.api.client.resource.TasksApiTest.java
@Test public void testGetTaskAsync() throws Throwable { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_OK); TasksApi tasksApi = new TasksApi(this.restClient); tasksApi.getTaskAsync("foo", new FutureCallback<Task>() { @Override//from w w w . j a v a2 s .c o m public void onSuccess(@Nullable Task task) { assertEquals(task, responseTask); } @Override public void onFailure(Throwable t) { fail(t.toString()); } }); }