protected RuntimeException logWithDetailsAndThrow(String message, Throwable optionalCause) { LOG.warn(message + " (throwing)"); int maxLength = 1024; LOG.warn(message + " (throwing)"); Streams.logStreamTail(LOG, "STDERR of problem in "+Tasks.current(), stderr, maxLength); Streams.logStreamTail(LOG, "STDOUT of problem in "+Tasks.current(), stdout, maxLength); Streams.logStreamTail(LOG, "STDIN of problem in "+Tasks.current(), Streams.byteArrayOfString(command != null ? command : psCommand), 4096); if (optionalCause!=null) throw new IllegalStateException(message, optionalCause); throw new IllegalStateException(message); }
protected RuntimeException logWithDetailsAndThrow(String message, Throwable optionalCause) { log.warn(message+" (throwing)"); Streams.logStreamTail(log, "STDERR of problem in "+Tasks.current(), stderr, 1024); Streams.logStreamTail(log, "STDOUT of problem in "+Tasks.current(), stdout, 1024); Streams.logStreamTail(log, "STDIN of problem in "+Tasks.current(), Streams.byteArrayOfString(Strings.join(getLines(),"\n")), 4096); if (optionalCause!=null) throw new IllegalStateException(message, optionalCause); throw new IllegalStateException(message); }
public void logTailOfPostgresLog() { try { File file = Os.newTempFile("postgresql-"+getEntity().getId(), "log"); int result = getMachine().copyFrom(getLogFile(), file.getAbsolutePath()); if (result != 0) throw new IllegalStateException("Could not access log file " + getLogFile()); log.info("Saving {} contents as {}", getLogFile(), file); Streams.logStreamTail(log, "postgresql.log", Streams.byteArrayOfString(Files.toString(file, Charsets.UTF_8)), 1024); file.delete(); } catch (IOException ioe) { log.debug("Error reading copied log file: {}", ioe); } }
Streams.logStreamTail(log, "STDERR of problem in "+Tasks.current(), Streams.byteArrayOfString(script.getResultStderr()), 1024); Streams.logStreamTail(log, "STDOUT of problem in "+Tasks.current(), Streams.byteArrayOfString(script.getResultStdout()), 1024);
.returning(new Function<ProcessTaskWrapper<?>,Boolean>() { @Override public Boolean apply(ProcessTaskWrapper<?> task) { if (task.getExitCode()==0 && task.getStdout().contains("sudo-is-working-"+id)) return true; Entity entity = BrooklynTaskTags.getTargetOrContextEntity(Tasks.current()); if (onFailingTask!=OnFailingTask.IGNORE) { // TODO if in a queueing context can we mark this task inessential and throw? // that way user sees the message... String message = "Error setting up sudo for "+task.getMachine().getUser()+"@"+task.getMachine().getAddress().getHostName()+" "+ " (exit code "+task.getExitCode()+(entity!=null ? ", entity "+entity : "")+")"; DynamicTasks.queueIfPossible(Tasks.warning(message, null)); } Streams.logStreamTail(log, "STDERR of sudo setup problem", Streams.byteArrayOfString(task.getStderr()), 1024); if (onFailingTask==OnFailingTask.WARN_OR_IF_DYNAMIC_FAIL_MARKING_INESSENTIAL) { Tasks.markInessential(); } if (onFailingTask==OnFailingTask.FAIL || onFailingTask==OnFailingTask.WARN_OR_IF_DYNAMIC_FAIL_MARKING_INESSENTIAL) { throw new IllegalStateException("Passwordless sudo is required for "+task.getMachine().getUser()+"@"+task.getMachine().getAddress().getHostName()+ (entity!=null ? " ("+entity+")" : "")); } return false; } }); }