private static Map<String, JsonElement> parseStats(String statsJson) { Map<String, JsonElement> stats = null; try { stats = Utils.fromJson(statsJson, new TypeToken<Map<String, JsonElement>>() { }.getType()); } catch (Exception e) { Utils.logWarning("Error parsing container stats: [%s]. Error: %s", statsJson, Utils.toString(e)); } return stats; }
public TableDescription setStateType(Class<? extends ServiceDocument> stateType) { this.stateType = stateType; this.documentKind = Utils.buildKind(stateType); return this; }
public static Object getPropertyValue(PropertyDescription pd, Object instance) { try { return pd.accessor.get(instance); } catch (Exception e) { Utils.logWarning("Reflection error: %s", Utils.toString(e)); } return null; }
private boolean isInspectionNeeded(ContainerState container) { Long lastInspect = inspectCache.get(container.documentSelfLink); if (lastInspect == null || lastInspect < Utils.fromNowMicrosUtc(-INSPECT_INTERVAL)) { inspectCache.put(container.documentSelfLink, Utils.getNowMicrosUtc()); return true; } return false; }
public void registerCertificate(SslTrustCertificateState sslTrustCert) { String alias = sslTrustCert.getAlias(); try { this.putDelegate(alias, sslTrustCert.certificate); Utils.log(getClass(), "Self Signed Trust Store", Level.FINE, "Certificate with alias %s updated", alias); } catch (Throwable e) { Utils.logWarning( "Exception during certificate reload with alias: %s. Error: %s", alias, Utils.toString(e)); } }
@Ignore("https://www.pivotaltracker.com/story/show/151532080 Fail on windows") @Test public void testPathJsonSerialization() { Path p = Paths.get("test"); String jsonRepr = Utils.toJson(p); assertEquals("\"" + p.toAbsolutePath().toAbsolutePath() + "\"", jsonRepr); Arguments arguments = new Arguments(); Logger.getAnonymousLogger().info(Utils.toJsonHtml(arguments)); }
@Override protected void handshakeFailure(ChannelHandlerContext ctx, Throwable cause) throws Exception { log(Level.WARNING, "TLS handshake failed: %s", Utils.toString(cause)); ctx.close(); }
/** * Build new URI based on a canonical URL, i.e., "http://example.com/example") */ public static URI buildUri(String uri) { try { return new URI(uri); } catch (Exception e) { Utils.log(Utils.class, Utils.class.getSimpleName(), Level.SEVERE, "Failure building uri %s: %s", uri, Utils.toString(e)); } return null; }
private static void handleQueryCompletion(ServiceHost host, Operation o, Throwable e) { if (e != null) { host.log(Level.SEVERE, "Query task failed: %s", Utils.toString(e)); return; } QueryTask queryTask = o.getBody(QueryTask.class); if (queryTask.results.documentLinks.isEmpty()) { host.log(Level.INFO, "Query returned no results"); return; } host.log(Level.INFO, "Returned query results: %s", Utils.toJsonHtml(queryTask.results)); }
public QueryElementResult<T> result(Object json, long count) { QueryElementResult<T> r = new QueryElementResult<>(); r.result = Utils.fromJson(json, this.type); r.documentSelfLink = r.result.documentSelfLink; r.count = count; return r; }
/** * Adds the supplied argument to the value from * {@link com.vmware.xenon.common.Utils#getSystemNowMicrosUtc()} and returns an absolute * expiration time in the future */ public static long getExpirationTimeFromNowInMicros(long microsFromNow) { return Utils.fromNowMicrosUtc(microsFromNow); }
private void loadSslTrustCertServices() { // make sure first get the time, then issue the query not to miss an interval with updates long currentDocumentUpdateTimeMicros = Utils.getNowMicrosUtc(); sslTrustQuery.queryUpdatedSince(documentUpdateTimeMicros, queryHandler); this.documentUpdateTimeMicros = currentDocumentUpdateTimeMicros; }
private Object removeFactoryPathFromSelfLink(Object jsonObject, String factoryPath) { String selfLink = extractId(jsonObject, factoryPath); return Utils.toJson( Utils.setJsonProperty(jsonObject, ServiceDocument.FIELD_NAME_SELF_LINK, selfLink)); }
private void saveState(File sandboxDir) throws IOException, InterruptedException { File hostStateFile = new File(sandboxDir, SERVICE_HOST_STATE_FILE); this.state.documentUpdateTimeMicros = Utils.getNowMicrosUtc(); byte[] serializedState = Utils.toJsonHtml(this.state).getBytes(Utils.CHARSET); Files.write(hostStateFile.toPath(), serializedState, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); }
private void markServiceInConflict(ServiceDocument state, ServiceDocument bestPeerRsp) { logWarning("State in conflict. Local: %s, Among peers: %s", Utils.toJsonHtml(state), Utils.toJsonHtml(bestPeerRsp)); } }
private void log(Level level, String fmt, Object... args) { Utils.log(Http2NegotiationHandler.class, Http2NegotiationHandler.class.getSimpleName(), level, fmt, args); } }
private long calculatePKSTaskExpirationTime(RequestBrokerState state) { long t = (state.documentExpirationTimeMicros - Utils.getSystemNowMicrosUtc()) / 2; t = Utils.fromNowMicrosUtc(t) - TimeUnit.MINUTES.toMicros(5); return Math.max(t, Utils.fromNowMicrosUtc(TimeUnit.MINUTES.toMicros(5))); }
@Override public void inspectImage(String imageName, String computeStateLink, Consumer<Throwable> errorHandler) { Utils.logWarning("Not implemented"); errorHandler.accept(new Exception("Not implemented")); }
private void validateBinaryExampleServiceState(Object queryResult, String link, Long counter) { ServiceDocument serviceDocument = Utils.fromQueryBinaryDocument(link, queryResult); assertNotNull(serviceDocument); ExampleServiceState resultState = (ExampleServiceState) serviceDocument; assertEquals(counter, resultState.counter); assertEquals(Action.POST.toString(), resultState.documentUpdateAction); assertEquals(Utils.buildKind(ExampleServiceState.class), resultState.documentKind); assertNotNull(resultState.name); }