private static String getFactoryLinkFieldValue(Class<? extends StatefulService> type) { try { Field f = type.getField(UriUtils.FIELD_NAME_FACTORY_LINK); return (String) f.get(null); } catch (Exception e) { logger.severe(String.format("%s field not found in class %s: %s", UriUtils.FIELD_NAME_FACTORY_LINK, type.getSimpleName(), Utils.toString(e))); } return null; }
@Override protected void handshakeFailure(ChannelHandlerContext ctx, Throwable cause) throws Exception { log(Level.WARNING, "TLS handshake failed: %s", Utils.toString(cause)); ctx.close(); }
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; }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { log(Level.WARNING, "ALPN protocol negotiation failed: %s", Utils.toString(cause)); ctx.close(); }
private void executeRunnableSafe(Runnable task) { try { task.run(); } catch (Exception e) { log(Level.SEVERE, "Unhandled exception executing task: %s", Utils.toString(e)); } }
@Override protected void handshakeFailure(ChannelHandlerContext ctx, Throwable cause) throws Exception { log(Level.WARNING, "TLS handshake failed: %s", Utils.toString(cause)); ctx.close(); }
public static <T> T instantiate(Class<T> clazz) { try { Constructor<T> ctor = clazz.getDeclaredConstructor(); if (!ctor.isAccessible()) { ctor.setAccessible(true); } return ctor.newInstance(); } catch (Exception e) { Utils.logWarning("Reflection error: %s", Utils.toString(e)); } return null; }
public static URI buildPublicUri(ServiceHost host, String path, String query) { URI baseUri = host.getPublicUri(); try { return new URI(baseUri.getScheme(), baseUri.getUserInfo(), baseUri.getHost(), baseUri.getPort(), path, query, null); } catch (Exception e) { Utils.log(Utils.class, Utils.class.getSimpleName(), Level.SEVERE, "Failure building uri %s, %s, %s: %s", baseUri, path, query, Utils.toString(e)); } return null; }
private String buildSelfLink(Closure closureRequest) { try { return UriUtils.buildUriPath(ClosureFactoryService.FACTORY_LINK, UriUtils.getLastPathSegment(new URI(closureRequest.documentSelfLink))); } catch (URISyntaxException e) { logError("Exception while building self link: %s", Utils.toString(e)); throw new RuntimeException("Wrong URI provided"); } }
private void doLog(Level lvl, FormattingTuple tuple) { if (tuple.getThrowable() == null) { Utils.log(this.logger, 5, this.name, lvl, "%s", tuple.getMessage()); } else { Utils.log(this.logger, 5, this.name, lvl, "%s: %s", tuple.getMessage(), Utils.toString(tuple.getThrowable())); } }
@Override public void failed(Throwable ex, Operation op) { logWarning("Backup Failed %s", Utils.toString(ex)); try { channel.close(); } catch (IOException e) { } // fail the put op, sender can retry sending the same range put.fail(ex); } });
private DeferredResult<Void> freeProjectIndex(int index) { if (index < 0) { return DeferredResult.completed(null); } return UniquePropertiesUtil.freeProperty(this, UniquePropertiesService.PROJECT_INDEXES_ID, Integer.toString(index)) .exceptionally(ex -> { logWarning("Unable to free project index %d: %s", index, Utils.toString(ex)); return null; }); }
private DeferredResult<ComputeState> requestComputeState(String selfLink) { URI uri = UriUtils.buildUri(host, selfLink); Operation op = Operation.createGet(uri) .setCompletion((o, e) -> { if (e != null) { logger.warning(String.format("Failed to retrieve compute state: [%s]", Utils.toString(e))); return; } }); prepareRequest(op, false); return host.sendWithDeferredResult(op, ComputeState.class); }
private DeferredResult<Void> freeProjectName(String name) { return UniquePropertiesUtil.freeProperty(this, UniquePropertiesService.PROJECT_NAMES_ID, name) .exceptionally(ex -> { logWarning("Unable to free name %s: %s", name, Utils.toString(ex)); return null; }); }
private void sendResponse(ChannelHandlerContext ctx, Operation request, Integer streamId, String originalPath, double startTime) { try { applyRateLimit(ctx, request); writeResponseUnsafe(ctx, request, streamId, originalPath, startTime); } catch (Exception e1) { this.host.log(Level.SEVERE, "%s", Utils.toString(e1)); } }
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)); }
private void performIOMaintenance(Operation post, long now, MaintenanceStage nextStage, long deadline) { try { this.operationTracker.performMaintenance(now); performMaintenanceStage(post, nextStage, deadline); } catch (Exception e) { log(Level.WARNING, "Exception: %s", Utils.toString(e)); performMaintenanceStage(post, nextStage, deadline); } }
private void verifyDocumentExists(String documentLink) throws Throwable { ServiceDocument document = getDocumentNoWait(ServiceDocument.class, documentLink); try { assertNotNull(String.format("Expected document [%s] to exist.", documentLink), document); } catch (AssertionError e) { host.log(Level.SEVERE, Utils.toString(e)); throw e; } }
private void sendSelfPatch(DockerImage body) { sendRequest(Operation .createPatch(getUri()) .setBody(body) .setCompletion((o, ex) -> { if (ex != null) { logWarning("Self patch failed: %s", Utils.toString(ex)); } })); }
protected void sendSelfPatch(Closure body) { sendRequest(Operation .createPatch(getUri()) .setBody(body) .setCompletion((o, ex) -> { if (ex != null) { logWarning("Self patch failed: %s", Utils.toString(ex)); } })); }