本文整理汇总了Java中org.apache.zeppelin.interpreter.InterpreterResult.Code.ERROR属性的典型用法代码示例。如果您正苦于以下问题:Java Code.ERROR属性的具体用法?Java Code.ERROR怎么用?Java Code.ERROR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.zeppelin.interpreter.InterpreterResult.Code
的用法示例。
在下文中一共展示了Code.ERROR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeSql
private InterpreterResult executeSql(String sql) {
try {
Either<String, Either<Joiner4All, Mapper4All>> result = dDriver.query(sql, null);
if (result.isLeft()) {
return new InterpreterResult(Code.ERROR, result.left().get().toString());
}
Either<Joiner4All, Mapper4All> goodResult =
(Either<Joiner4All, Mapper4All>) result.right().get();
if (goodResult.isLeft()) {
return new InterpreterResult(Code.SUCCESS, goodResult.left().get().toString());
} else {
return new InterpreterResult(Code.SUCCESS,
mapper4All2Zeppelin((Mapper4All) goodResult.right().get()));
}
} catch (Exception e) {
return new InterpreterResult(Code.ERROR, e.getMessage());
}
}
示例2: HandleHelp
private InterpreterResult HandleHelp(JLineShell shell, String st) {
java.util.logging.StreamHandler sh = null;
java.util.logging.Logger springLogger = null;
java.util.logging.Formatter formatter = new java.util.logging.Formatter() {
public String format(java.util.logging.LogRecord record) {
return record.getMessage();
}
};
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
sh = new java.util.logging.StreamHandler(baos, formatter);
springLogger = HandlerUtils.getLogger(org.springframework.shell.core.SimpleParser.class);
springLogger.addHandler(sh);
shell.executeCommand(st);
} catch (Exception e) {
s_logger.error(e.getMessage(), e);
return new InterpreterResult(Code.ERROR, e.getMessage());
}
finally {
sh.flush();
springLogger.removeHandler(sh);
sh.close();
}
return new InterpreterResult(Code.SUCCESS, baos.toString());
}
示例3: interpret
@Override
public InterpreterResult interpret(String st, InterpreterContext interpreterContext) {
String html;
try {
html = md.process(st);
} catch (IOException | java.lang.RuntimeException e) {
return new InterpreterResult(Code.ERROR, InterpreterUtils.getMostRelevantMessage(e));
}
return new InterpreterResult(Code.SUCCESS, "%html " + html);
}
示例4: afterStatusChange
@Override
public void afterStatusChange(Job job, Status before, Status after) {
if (after == null) { // unknown. maybe before sumitted remotely, maybe already finished.
if (jobExecuted) {
jobSubmittedRemotely = true;
Object jobResult = job.getReturn();
if (job.isAborted()) {
job.setStatus(Status.ABORT);
} else if (job.getException() != null) {
job.setStatus(Status.ERROR);
} else if (jobResult != null && jobResult instanceof InterpreterResult
&& ((InterpreterResult) jobResult).code() == Code.ERROR) {
job.setStatus(Status.ERROR);
} else {
job.setStatus(Status.FINISHED);
}
}
return;
}
// Update remoteStatus
if (jobExecuted == false) {
if (after == Status.FINISHED || after == Status.ABORT
|| after == Status.ERROR) {
// it can be status of last run.
// so not updating the remoteStatus
return;
} else if (after == Status.RUNNING) {
jobSubmittedRemotely = true;
}
} else {
jobSubmittedRemotely = true;
}
// status polled by status poller
if (job.getStatus() != after) {
job.setStatus(after);
}
}
示例5: interpret
/**
* Interpret a single line.
*/
@Override
public InterpreterResult interpret(String line, InterpreterContext context) {
if (sparkVersion.isUnsupportedVersion()) {
return new InterpreterResult(Code.ERROR, "Spark " + sparkVersion.toString()
+ " is not supported");
}
z.setInterpreterContext(context);
if (line == null || line.trim().length() == 0) {
return new InterpreterResult(Code.SUCCESS);
}
return interpret(line.split("\n"), context);
}
示例6: getResultCode
private Code getResultCode(scala.tools.nsc.interpreter.Results.Result r) {
if (r instanceof scala.tools.nsc.interpreter.Results.Success$) {
return Code.SUCCESS;
} else if (r instanceof scala.tools.nsc.interpreter.Results.Incomplete$) {
return Code.INCOMPLETE;
} else {
return Code.ERROR;
}
}
示例7: interpret
@Override
public InterpreterResult interpret(String markdownText, InterpreterContext interpreterContext) {
String html;
try {
html = parser.render(markdownText);
} catch (RuntimeException e) {
LOGGER.error("Exception in MarkdownInterpreter while interpret ", e);
return new InterpreterResult(Code.ERROR, InterpreterUtils.getMostRelevantMessage(e));
}
return new InterpreterResult(Code.SUCCESS, "%html " + html);
}
示例8: getResultCode
private Code getResultCode(Result res) {
if (res instanceof scala.tools.nsc.interpreter.Results.Success$) {
return Code.SUCCESS;
} else if (res instanceof scala.tools.nsc.interpreter.Results.Incomplete$) {
return Code.INCOMPLETE;
} else {
return Code.ERROR;
}
}
示例9: runCondaActivate
private InterpreterResult runCondaActivate(String envName)
throws IOException, InterruptedException, InterpreterException {
if (null == envName || envName.isEmpty()) {
return new InterpreterResult(Code.ERROR, "Env name should be specified");
}
changePythonEnvironment(envName);
restartPythonProcess();
return new InterpreterResult(Code.SUCCESS, "'" + envName + "' is activated");
}
示例10: interpret
/**
* Interpret a single line.
*/
@Override
public InterpreterResult interpret(String line, InterpreterContext context) {
if (isUnsupportedSparkVersion()) {
return new InterpreterResult(Code.ERROR, "Spark " + sparkVersion.toString()
+ " is not supported");
}
populateSparkWebUrl(context);
z.setInterpreterContext(context);
if (line == null || line.trim().length() == 0) {
return new InterpreterResult(Code.SUCCESS);
}
return interpret(line.split("\n"), context);
}
示例11: interpret
@Override
public InterpreterResult interpret(String st, InterpreterContext context) {
PrintStream printStream = new PrintStream(out);
Console.setOut(printStream);
out.reset();
SparkInterpreter sparkInterpreter = getSparkInterpreter();
if (sparkInterpreter != null && sparkInterpreter.isSparkContextInitialized()) {
return new InterpreterResult(Code.ERROR,
"Must be used before SparkInterpreter (%spark) initialized\n" +
"Hint: put this paragraph before any Spark code and " +
"restart Zeppelin/Interpreter" );
}
scala.tools.nsc.interpreter.Results.Result ret = interpret(st);
Code code = getResultCode(ret);
try {
depc.fetch();
} catch (MalformedURLException | DependencyResolutionException
| ArtifactResolutionException e) {
LOGGER.error("Exception in DepInterpreter while interpret ", e);
return new InterpreterResult(Code.ERROR, e.toString());
}
if (code == Code.INCOMPLETE) {
return new InterpreterResult(code, "Incomplete expression");
} else if (code == Code.ERROR) {
return new InterpreterResult(code, out.toString());
} else {
return new InterpreterResult(code, out.toString());
}
}
示例12: interpret
@Override
@SuppressWarnings("unchecked")
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) {
try {
Script script = getGroovyScript(contextInterpreter.getParagraphId(), cmd);
Job runningJob = getRunningJob(contextInterpreter.getParagraphId());
runningJob.info()
.put("CURRENT_THREAD", Thread.currentThread()); //to be able to terminate thread
Map<String, Object> bindings = script.getBinding().getVariables();
bindings.clear();
StringWriter out = new StringWriter((int) (cmd.length() * 1.75));
//put shared bindings evaluated in this interpreter
bindings.putAll(sharedBindings);
//put predefined bindings
bindings.put("g", new GObject(log, out, this.getProperties(), contextInterpreter, bindings));
bindings.put("out", new PrintWriter(out, true));
script.run();
//let's get shared variables defined in current script and store them in shared map
for (Map.Entry<String, Object> e : bindings.entrySet()) {
if (!predefinedBindings.contains(e.getKey())) {
if (log.isTraceEnabled()) {
log.trace("groovy script variable " + e); //let's see what we have...
}
sharedBindings.put(e.getKey(), e.getValue());
}
}
bindings.clear();
InterpreterResult result = new InterpreterResult(Code.SUCCESS, out.toString());
return result;
} catch (Throwable t) {
t = StackTraceUtils.deepSanitize(t);
String msg = t.toString() + "\n at " + t.getStackTrace()[0];
log.error("Failed to run script: " + t + "\n" + cmd + "\n", t);
return new InterpreterResult(Code.ERROR, msg);
}
}
示例13: interpret
private InterpreterResult interpret(String[] commands, InterpreterContext context) {
boolean isSuccess = true;
totalCommands = commands.length;
completedCommands = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
System.setOut(ps);
for (String command : commands) {
int commandResult = 1;
String[] args = splitAndRemoveEmpty(command, " ");
if (args.length > 0 && args[0].equals("help")) {
System.out.println(getCommandList());
} else {
commandResult = fs.run(args);
}
if (commandResult != 0) {
isSuccess = false;
break;
} else {
completedCommands += 1;
}
System.out.println();
}
System.out.flush();
System.setOut(old);
if (isSuccess) {
return new InterpreterResult(Code.SUCCESS, baos.toString());
} else {
return new InterpreterResult(Code.ERROR, baos.toString());
}
}
示例14: executeSql
public InterpreterResult executeSql(String propertyKey, String sql,
InterpreterContext interpreterContext) {
String paragraphId = interpreterContext.getParagraphId();
try {
Statement statement = getStatement(propertyKey, paragraphId);
statement.setMaxRows(getMaxResult());
StringBuilder msg;
if (containsIgnoreCase(sql, EXPLAIN_PREDICATE)) {
msg = new StringBuilder();
} else {
msg = new StringBuilder(TABLE_MAGIC_TAG);
}
ResultSet resultSet = null;
try {
boolean isResultSetAvailable = statement.execute(sql);
if (isResultSetAvailable) {
resultSet = statement.getResultSet();
ResultSetMetaData md = resultSet.getMetaData();
for (int i = 1; i < md.getColumnCount() + 1; i++) {
if (i > 1) {
msg.append(TAB);
}
msg.append(md.getColumnName(i));
}
msg.append(NEWLINE);
int displayRowCount = 0;
while (resultSet.next() && displayRowCount < getMaxResult()) {
for (int i = 1; i < md.getColumnCount() + 1; i++) {
msg.append(resultSet.getString(i));
if (i != md.getColumnCount()) {
msg.append(TAB);
}
}
msg.append(NEWLINE);
displayRowCount++;
}
} else {
// Response contains either an update count or there are no results.
int updateCount = statement.getUpdateCount();
msg.append(UPDATE_COUNT_HEADER).append(NEWLINE);
msg.append(updateCount).append(NEWLINE);
}
} finally {
try {
if (resultSet != null) {
resultSet.close();
}
statement.close();
} finally {
moveConnectionToUnused(propertyKey, paragraphId);
}
}
return new InterpreterResult(Code.SUCCESS, msg.toString());
} catch (SQLException | ClassNotFoundException ex) {
logger.error("Cannot run " + sql, ex);
return new InterpreterResult(Code.ERROR, ex.getMessage());
}
}
示例15: interpret
private InterpreterResult interpret(String[] lines) {
String[] linesToRun = new String[lines.length + 1];
System.arraycopy(lines, 0, linesToRun, 0, lines.length);
linesToRun[lines.length] = "print(\"\")";
Console.setOut(out);
out.reset();
Code code = null;
String incomplete = "";
for (int l = 0; l < linesToRun.length; l++) {
String s = linesToRun[l];
// check if next line starts with "." (but not ".." or "./") it is treated as an invocation
if (l + 1 < linesToRun.length) {
String nextLine = linesToRun[l + 1].trim();
if (nextLine.startsWith(".") && !nextLine.startsWith("..") && !nextLine.startsWith("./")) {
incomplete += s + "\n";
continue;
}
}
try {
code = getResultCode(imain.interpret(incomplete + s));
} catch (Exception e) {
logger.info("Interpreter exception", e);
return new InterpreterResult(Code.ERROR, InterpreterUtils.getMostRelevantMessage(e));
}
if (code == Code.ERROR) {
return new InterpreterResult(code, out.toString());
} else if (code == Code.INCOMPLETE) {
incomplete += s + '\n';
} else {
incomplete = "";
}
}
if (code == Code.INCOMPLETE) {
return new InterpreterResult(code, "Incomplete expression");
} else {
return new InterpreterResult(code, out.toString());
}
}