List of usage examples for java.time Instant now
public static Instant now()
From source file:org.lendingclub.mercator.newrelic.NewRelicScanner.java
private void scanAlertConditions() { Instant startTime = Instant.now(); String cypher = "MATCH ( p: NewRelicAlertPolicy { nr_accountId:{accountId} }) return p;"; List<JsonNode> alertPolicies = getProjector().getNeoRxClient().execCypherAsList(cypher, "accountId", clientSupplier.get().getAccountId()); // for each policy get the alert conditions attached alertPolicies.forEach(alert -> {//from w w w . j a v a 2 s . c o m String policyId = alert.path("nr_policyId").asText(); if (!Strings.isNullOrEmpty(policyId)) { ObjectNode alertConditions = clientSupplier.get().getAlertConditionForPolicy(policyId); // create relationship between policy and conditions // create relationship betwen condition and entities ( servers / apm ) String conditionsCypher = "WITH {json} as data " + "UNWIND data.conditions as condition " + "MATCH (p: NewRelicAlertPolicy {nr_policyId: {policyId}, nr_accountId:{accountId}}) " + "MERGE ( c:NewRelicAlertCondition { nr_conditionId: toString(condition.id), nr_accountId: {accountId} }) " + "ON CREATE SET c.type = condition.type, c.name = condition.name, c.enabled = condition.enabled, " + "c.metricType = condition.metric, c.createTs = timestamp(), c.updateTs = timestamp() " + "ON MATCH SET c.updateTs = timestamp(), c.enabled = condition.enabled, c.type = condition.type " + "MERGE (c)-[:BELONGS_TO]->(p) " + "with c,condition, CASE WHEN c.type = 'servers_metric' then [1] ELSE [] END AS aps_var, " + "CASE WHEN c.type = 'apm_app_metric' then [1] ELSE [] END AS apm_var " + "FOREACH ( s IN aps_var | FOREACH(sid in condition.entities | MERGE (s:NewRelicServer { nr_serverId:sid, nr_accountId:{accountId} }) MERGE (s)-[:ATTACHED_TO]->(c))) " + "FOREACH ( m IN apm_var | FOREACH(mid in condition.entities | MERGE (m:NewRelicApplication { nr_appId:mid, nr_accountId:{accountId} }) MERGE (m)-[:ATTACHED_TO]->(c))) "; getProjector().getNeoRxClient().execCypher(conditionsCypher, "json", alertConditions, "policyId", policyId, "accountId", clientSupplier.get().getAccountId()); } }); Instant endTime = Instant.now(); logger.info("Updating neo4j with the latest information about NewRelic alert conditions took {} secs", Duration.between(startTime, endTime).getSeconds()); }
From source file:co.runrightfast.vertx.core.eventbus.ProtobufMessageProducer.java
public void publish(@NonNull final A msg) { eventBus.publish(address, msg, addRunRightFastHeaders(new DeliveryOptions())); this.messagePublished.mark(); this.messageLastPublished = Instant.now(); }
From source file:com.orange.cepheus.broker.persistence.RegistrationsRepositoryTest.java
@Test public void getAllRegistrationsTest() throws URISyntaxException, RegistrationPersistenceException { RegisterContext registerContext = createRegisterContextTemperature(); registerContext.setRegistrationId("12345"); Registration registration = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext); registrationsRepository.saveRegistration(registration); RegisterContext registerContext2 = createRegisterContextTemperature(); registerContext2.setRegistrationId("12346"); Registration registration2 = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext2); registrationsRepository.saveRegistration(registration2); RegisterContext registerContext3 = createRegisterContextTemperature(); registerContext3.setRegistrationId("12347"); Registration registration3 = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext3); registrationsRepository.saveRegistration(registration3); Assert.assertEquals(3, registrationsRepository.getAllRegistrations().size()); }
From source file:com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanPathsUtility.java
public File createSpecificRunOutputDirectory(final File generalOutputDirectory) throws BlackDuckIntegrationException { final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss-SSS") .withZone(ZoneOffset.UTC); final String timeStringPrefix = Instant.now().atZone(ZoneOffset.UTC).format(dateTimeFormatter); final int uniqueThreadIdSuffix = defaultMultiThreadingId.incrementAndGet(); return createRunOutputDirectory(generalOutputDirectory, timeStringPrefix, Integer.toString(uniqueThreadIdSuffix)); }
From source file:com.orange.cepheus.broker.persistence.SubscriptionsRepositoryTest.java
@Test public void getAllSubscriptionsTest() throws URISyntaxException, SubscriptionPersistenceException { SubscribeContext subscribeContext = createSubscribeContextTemperature(); Subscription subscription = new Subscription("12345", Instant.now().plus(1, ChronoUnit.DAYS), subscribeContext);// w w w . j a v a 2 s . c o m subscriptionsRepository.saveSubscription(subscription); SubscribeContext subscribeContext2 = createSubscribeContextTemperature(); Subscription subscription2 = new Subscription("12346", Instant.now().plus(1, ChronoUnit.DAYS), subscribeContext2); subscriptionsRepository.saveSubscription(subscription2); SubscribeContext subscribeContext3 = createSubscribeContextTemperature(); Subscription subscription3 = new Subscription("12347", Instant.now().plus(1, ChronoUnit.DAYS), subscribeContext3); subscriptionsRepository.saveSubscription(subscription3); Assert.assertEquals(3, subscriptionsRepository.getAllSubscriptions().size()); }
From source file:co.runrightfast.vertx.core.eventbus.ProtobufMessageProducer.java
public void publish(@NonNull final A msg, @NonNull final DeliveryOptions options) { eventBus.publish(address, msg, addRunRightFastHeaders(options)); this.messagePublished.mark(); this.messageLastPublished = Instant.now(); }
From source file:com.derpgroup.echodebugger.resource.EchoDebuggerResource.java
/** * This is the primary endpoint used for saving responses * @param body/*from w w w . j a v a2s. c om*/ * @param userId * @param intentName * @return */ @Path("/users/{userId}/intents/{intentName}") @POST public Map<String, Object> saveResponseForUserId(Map<String, Object> body, @PathParam("userId") String userId, @PathParam("intentName") String intentName) { if (StringUtils.isEmpty(userId)) { throw new ResponderException("A userId is required for this endpoint.", ExceptionType.UNRECOGNIZED_ID); } if (StringUtils.isEmpty(intentName)) { throw new ResponderException("An intent name is required for this endpoint.", ExceptionType.UNRECOGNIZED_ID); } User user = (userDao.getUserById(userId) != null) ? userDao.getUserById(userId) : userDao.getUserByEchoId(userId); boolean requestIsAllowed = debugMode || user != null; EchoDebuggerLogger.logSaveNewResponse(body, userId, requestIsAllowed); // TODO: Update this to store the intentName if (user == null) { // DebugMode let's us register responses for accounts that don't exist if (debugMode) { userDao.createUser(userId); user = userDao.getUserByEchoId(userId); } // If the request is for an ID that we haven't seen before, refuse it else { throw new ResponderException( "This is not a known id. Please access this skill through your Echo to automatically register your Echo and obtain an id.", ExceptionType.UNRECOGNIZED_ID); } } user.setLastUploadTime(Instant.now()); user.setNumContentUploads(user.getNumContentUploads() + 1); // Abort storing it if the request is too long int responseLength = ResponderUtils.getLengthOfContent(body); user.setNumCharactersUploaded(user.getNumCharactersUploaded() + responseLength); if (responseLength > maxAllowedResponseLength) { user.setNumUploadsTooLarge(user.getNumUploadsTooLarge() + 1); userDao.saveUser(user); throw new ResponderException("The response is too long. Alexa limits response sizes to 8000 characters." + "This response was " + responseLength + " characters long. Please see their restrictions here: " + "https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference#Response%20Format", ExceptionType.RESPONSE_TOO_LONG); } IntentResponses intentResponses = user.getIntents().get(intentName); if (intentResponses == null) { intentResponses = new IntentResponses(); intentResponses.setIntentName(intentName); } intentResponses.setData(body); user.getIntents().put(intentName, intentResponses); userDao.saveUser(user); Map<String, Object> responseMap = new HashMap<>(); responseMap.put("Response path", "/responder/users/" + userId + "/intents/" + intentName); return responseMap; }
From source file:io.dropwizard.revolver.persistence.AeroSpikePersistenceProvider.java
@Override public void setRequestState(String requestId, RevolverRequestState state) { final Key key = new Key(mailBoxConfig.getNamespace(), MAILBOX_SET_NAME, requestId); final Record record = AerospikeConnectionManager.getClient().get(null, key, BinNames.STATE); final RevolverRequestState requestState = RevolverRequestState.valueOf(record.getString(BinNames.STATE)); switch (requestState) { case RESPONDED: break;/*from w w w.j a v a 2 s . co m*/ default: final Bin binState = new Bin(BinNames.STATE, state.name()); final Bin updated = new Bin(BinNames.UPDATED, Instant.now().toEpochMilli()); AerospikeConnectionManager.getClient().operate(null, key, Operation.put(binState), Operation.put(updated)); } }
From source file:com.joyent.manta.client.MantaClientSigningIT.java
@Test public final void testCanCreateSignedOPTIONSUriFromPath() throws IOException, InterruptedException { if (config.isClientEncryptionEnabled()) { throw new SkipException("Signed URLs are not decrypted by the client"); }//from w w w .j a v a2 s . c o m final String name = UUID.randomUUID().toString(); final String path = testPathPrefix + name; mantaClient.put(path, TEST_DATA); // This will throw an error if the newly inserted object isn't present mantaClient.head(path); Assert.assertEquals(mantaClient.getAsString(path), TEST_DATA); Instant expires = Instant.now().plus(1, ChronoUnit.HOURS); URI uri = mantaClient.getAsSignedURI(path, "OPTIONS", expires); HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); try { connection.setReadTimeout(3000); connection.setRequestMethod("OPTIONS"); connection.connect(); Map<String, List<String>> headers = connection.getHeaderFields(); if (connection.getResponseCode() != 200) { String errorText = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset()); if (config.getMantaUser().contains("/")) { String msg = String.format("This fails due to an outstanding bug: MANTA-2839.\n%s", errorText); throw new SkipException(msg); } Assert.fail(errorText); } Assert.assertNotNull(headers); Assert.assertEquals(headers.get("Server").get(0), "Manta"); } finally { connection.disconnect(); } }