Every catch should log error/info message or should throw an exception

This commit is contained in:
Prabhjyot Singh 2016-01-05 12:47:03 +05:30
parent 7f8b70c689
commit 6d927fc205
35 changed files with 209 additions and 132 deletions

View file

@ -211,6 +211,7 @@ public class IgniteInterpreter extends Interpreter {
initEx = null;
} catch (Exception e) {
logger.error("Error in IgniteInterpreter while getIgnite: " , e);
initEx = e;
}
}

View file

@ -154,6 +154,7 @@ public class IgniteSqlInterpreter extends Interpreter {
}
}
} catch (Exception e) {
logger.error("Exception in IgniteSqlInterpreter while InterpreterResult interpret: ", e);
return IgniteInterpreterUtils.buildErrorResult(e);
} finally {
curStmt = null;
@ -169,6 +170,7 @@ public class IgniteSqlInterpreter extends Interpreter {
curStmt.cancel();
} catch (SQLException e) {
// No-op.
logger.info("No-op while cancel in IgniteSqlInterpreter", e);
} finally {
curStmt = null;
}

View file

@ -375,6 +375,7 @@ public class LensInterpreter extends Interpreter {
closeShell(s_paraToQH.get(context.getParagraphId()).getShell());
} catch (Exception e) {
// ignore
s_logger.info("Exception in LensInterpreter while cancel finally, ignore", e);
}
s_paraToQH.remove(context.getParagraphId());
closeShell(shell);

View file

@ -29,12 +29,15 @@ import org.apache.zeppelin.interpreter.InterpreterUtils;
import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.scheduler.SchedulerFactory;
import org.markdown4j.Markdown4jProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Markdown interpreter for Zeppelin.
*/
public class Markdown extends Interpreter {
private Markdown4jProcessor md;
static final Logger LOGGER = LoggerFactory.getLogger(Markdown.class);
static {
Interpreter.register("md", Markdown.class.getName());
@ -58,6 +61,7 @@ public class Markdown extends Interpreter {
try {
html = md.process(st);
} catch (IOException | java.lang.RuntimeException e) {
LOGGER.error("Exception in Markdown while interpret ", e);
return new InterpreterResult(Code.ERROR, InterpreterUtils.getMostRelevantMessage(e));
}
return new InterpreterResult(Code.SUCCESS, "%html " + html);

View file

@ -297,6 +297,7 @@ public class PostgreSqlInterpreter extends Interpreter {
try {
currentStatement.cancel();
} catch (SQLException ex) {
logger.error("SQLException in PostgreSqlInterpreter while cancel ", ex);
} finally {
currentStatement = null;
}

View file

@ -41,6 +41,8 @@ import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.apache.zeppelin.interpreter.WrappedInterpreter;
import org.apache.zeppelin.scheduler.Scheduler;
import org.apache.zeppelin.spark.dep.DependencyContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.aether.resolution.ArtifactResolutionException;
import org.sonatype.aether.resolution.DependencyResolutionException;
@ -80,6 +82,7 @@ public class DepInterpreter extends Interpreter {
private DependencyContext depc;
private SparkJLineCompletion completor;
private SparkILoop interpreter;
static final Logger LOGGER = LoggerFactory.getLogger(DepInterpreter.class);
public DepInterpreter(Properties property) {
super(property);
@ -195,6 +198,7 @@ public class DepInterpreter extends Interpreter {
depc.fetch();
} catch (MalformedURLException | DependencyResolutionException
| ArtifactResolutionException e) {
LOGGER.error("Exception in DepInterpreter while interpret ", e);
return new InterpreterResult(Code.ERROR, e.toString());
}

View file

@ -38,12 +38,15 @@ import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SparkInterpreterTest {
public static SparkInterpreter repl;
private InterpreterContext context;
private File tmpDir;
public static Logger LOGGER = LoggerFactory.getLogger(SparkInterpreterTest.class);
/**
@ -177,7 +180,7 @@ public class SparkInterpreterTest {
for (Object oKey : intpProperty.keySet()) {
String key = (String) oKey;
String value = (String) intpProperty.get(key);
repl.logger.debug(String.format("[%s]: [%s]", key, value));
LOGGER.debug(String.format("[%s]: [%s]", key, value));
if (key.startsWith("spark.") && value.isEmpty()) {
assertTrue(String.format("configuration starting from 'spark.' should not be empty. [%s]", key), !sparkConf.contains(key) || !sparkConf.get(key).isEmpty());
}

View file

@ -33,6 +33,8 @@ import org.apache.zeppelin.interpreter.InterpreterResult.Type;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SparkSqlInterpreterTest {
@ -41,6 +43,8 @@ public class SparkSqlInterpreterTest {
private InterpreterContext context;
private InterpreterGroup intpGroup;
Logger LOGGER = LoggerFactory.getLogger(SparkSqlInterpreterTest.class);
@Before
public void setUp() throws Exception {
Properties p = new Properties();
@ -96,6 +100,7 @@ public class SparkSqlInterpreterTest {
fail("Exception not catched");
} catch (Exception e) {
// okay
LOGGER.info("Exception in SparkSqlInterpreterTest while test ", e);
}
assertEquals(InterpreterResult.Code.SUCCESS, sql.interpret("select case when name==\"aa\" then name else name end from test", context).code());
}

View file

@ -17,13 +17,16 @@
*/
package org.apache.zeppelin.tajo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.sql.*;
import java.util.Calendar;
import java.util.Map;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
/**
* This is borrowed from Apache Commons DBCP2.
@ -31,6 +34,9 @@ import java.io.UnsupportedEncodingException;
* A dummy {@link java.sql.ResultSet}, for testing purposes.
*/
public class TesterResultSet implements ResultSet {
Logger LOGGER = LoggerFactory.getLogger(TesterResultSet.class);
public TesterResultSet(Statement stmt) {
_statement = stmt;
}
@ -262,6 +268,8 @@ public class TesterResultSet implements ResultSet {
return columnName.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// Impossible. JVMs are required to support UTF-8
LOGGER.error("Exception in TesterResultSet while getBytes, Impossible. JVMs are required to" +
" support UTF-8", e);
return null;
}
}

View file

@ -131,7 +131,7 @@ public abstract class Interpreter {
static Logger logger = LoggerFactory.getLogger(Interpreter.class);
public static Logger logger = LoggerFactory.getLogger(Interpreter.class);
private InterpreterGroup interpreterGroup;
private URL [] classloaderUrls;
protected Properties property;

View file

@ -33,6 +33,8 @@ import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess;
public class InterpreterGroup extends LinkedList<Interpreter>{
String id;
Logger LOGGER = Logger.getLogger(InterpreterGroup.class);
AngularObjectRegistry angularObjectRegistry;
RemoteInterpreterProcess remoteInterpreterProcess; // attached remote interpreter process
@ -100,8 +102,7 @@ public class InterpreterGroup extends LinkedList<Interpreter>{
try {
t.join();
} catch (InterruptedException e) {
Logger logger = Logger.getLogger(InterpreterGroup.class);
logger.error("Can't close interpreter", e);
LOGGER.error("Can't close interpreter", e);
}
}
}
@ -124,8 +125,7 @@ public class InterpreterGroup extends LinkedList<Interpreter>{
try {
t.join();
} catch (InterruptedException e) {
Logger logger = Logger.getLogger(InterpreterGroup.class);
logger.error("Can't close interpreter", e);
LOGGER.error("Can't close interpreter", e);
}
}

View file

@ -96,7 +96,6 @@ public class RemoteAngularObjectRegistry extends AngularObjectRegistry {
* this method should be used instead of remove()
* @param name
* @param noteId
* @param emit
* @return
*/
public AngularObject removeAndNotifyRemoteProcess(String name, String noteId) {

View file

@ -122,6 +122,7 @@ public class RemoteInterpreterEventPoller extends Thread {
wait(1000);
}
} catch (InterruptedException ignored) {
logger.info("Error in RemoteInterpreterEventPoller while waitQuietly : ", ignored);
}
}

View file

@ -121,6 +121,8 @@ public class RemoteInterpreterProcess implements ExecuteResultHandler {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
logger.error("Exception in RemoteInterpreterProcess while synchronized reference " +
"Thread.sleep", e);
}
}
}
@ -157,6 +159,8 @@ public class RemoteInterpreterProcess implements ExecuteResultHandler {
client.shutdown();
} catch (Exception e) {
// safely ignore exception while client.shutdown() may terminates remote process
logger.info("Exception in RemoteInterpreterProcess while synchronized dereference, can " +
"safely ignore exception while client.shutdown() may terminates remote process", e);
} finally {
if (client != null) {
releaseClient(client);
@ -174,6 +178,8 @@ public class RemoteInterpreterProcess implements ExecuteResultHandler {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
logger.error("Exception in RemoteInterpreterProcess while synchronized dereference " +
"Thread.sleep", e);
}
} else {
break;
@ -245,6 +251,8 @@ public class RemoteInterpreterProcess implements ExecuteResultHandler {
client = getClient();
} catch (NullPointerException e) {
// remote process not started
logger.info("NullPointerException in RemoteInterpreterProcess while " +
"updateRemoteAngularObject getClient, remote process not started", e);
return;
} catch (Exception e) {
logger.error("Can't update angular object", e);

View file

@ -114,6 +114,7 @@ public class RemoteInterpreterServer
try {
Thread.sleep(300);
} catch (InterruptedException e) {
logger.info("Exception in RemoteInterpreterServer while shutdown, Thread.sleep", e);
}
}
@ -225,6 +226,7 @@ public class RemoteInterpreterServer
try {
jobListener.wait(1000);
} catch (InterruptedException e) {
logger.info("Exception in RemoteInterpreterServer while interpret, jobListener.wait", e);
}
}
}
@ -455,6 +457,7 @@ public class RemoteInterpreterServer
try {
eventQueue.wait(1000);
} catch (InterruptedException e) {
logger.info("Exception in RemoteInterpreterServer while getEvent, eventQueue.wait", e);
}
}
@ -468,7 +471,6 @@ public class RemoteInterpreterServer
/**
* called when object is updated in client (web) side.
* @param className
* @param name
* @param noteId noteId where the update issues
* @param object
@ -499,6 +501,7 @@ public class RemoteInterpreterServer
return;
} catch (Exception e) {
// no luck
logger.info("Exception in RemoteInterpreterServer while angularObjectUpdate, no luck", e);
}
}
@ -510,6 +513,7 @@ public class RemoteInterpreterServer
}.getType());
} catch (Exception e) {
// no lock
logger.info("Exception in RemoteInterpreterServer while angularObjectUpdate, no lock", e);
}
}
@ -544,6 +548,7 @@ public class RemoteInterpreterServer
}.getType());
} catch (Exception e) {
// nolock
logger.info("Exception in RemoteInterpreterServer while angularObjectAdd, nolock", e);
}
// try string object type at last

View file

@ -17,6 +17,9 @@
package org.apache.zeppelin.interpreter.remote;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
@ -26,6 +29,7 @@ import java.net.Socket;
*
*/
public class RemoteInterpreterUtils {
static Logger LOGGER = LoggerFactory.getLogger(RemoteInterpreterUtils.class);
public static int findRandomAvailablePortOnAllLocalInterfaces() throws IOException {
int port;
try (ServerSocket socket = new ServerSocket(0);) {
@ -43,6 +47,7 @@ public class RemoteInterpreterUtils {
discover.close();
return true;
} catch (IOException e) {
LOGGER.info("Exception in RemoteInterpreterUtils while checkIfRemoteEndpointAccessible", e);
return false;
}
}

View file

@ -24,6 +24,8 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import org.apache.zeppelin.scheduler.Job.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* FIFOScheduler runs submitted job sequentially
@ -36,6 +38,8 @@ public class FIFOScheduler implements Scheduler {
Job runningJob = null;
private String name;
static Logger LOGGER = LoggerFactory.getLogger(FIFOScheduler.class);
public FIFOScheduler(String name, ExecutorService executor, SchedulerListener listener) {
this.name = name;
this.executor = executor;
@ -107,6 +111,7 @@ public class FIFOScheduler implements Scheduler {
try {
queue.wait(500);
} catch (InterruptedException e) {
LOGGER.error("Exception in FIFOScheduler while run queue.wait", e);
}
continue;
}

View file

@ -78,6 +78,8 @@ public abstract class Job {
Date dateFinished;
Status status;
static Logger LOGGER = LoggerFactory.getLogger(Job.class);
transient boolean aborted = false;
String errorMessage;
@ -172,14 +174,14 @@ public abstract class Job {
dateFinished = new Date();
progressUpdator.terminate();
} catch (NullPointerException e) {
logger().error("Job failed", e);
LOGGER.error("Job failed", e);
progressUpdator.terminate();
this.exception = e;
result = e.getMessage();
errorMessage = getStack(e);
dateFinished = new Date();
} catch (Throwable e) {
logger().error("Job failed", e);
LOGGER.error("Job failed", e);
progressUpdator.terminate();
this.exception = e;
result = e.getMessage();
@ -248,10 +250,6 @@ public abstract class Job {
return dateFinished;
}
private Logger logger() {
return LoggerFactory.getLogger(Job.class);
}
protected void setResult(Object result) {
this.result = result;
}

View file

@ -57,6 +57,7 @@ public class JobProgressPoller extends Thread {
try {
Thread.sleep(intervalMs);
} catch (InterruptedException e) {
logger.error("Exception in JobProgressPoller while run Thread.sleep", e);
}
}
}

View file

@ -24,6 +24,8 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import org.apache.zeppelin.scheduler.Job.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Parallel scheduler runs submitted job concurrently.
@ -37,6 +39,8 @@ public class ParallelScheduler implements Scheduler {
private String name;
private int maxConcurrency;
static Logger LOGGER = LoggerFactory.getLogger(ParallelScheduler.class);
public ParallelScheduler(String name, ExecutorService executor, SchedulerListener listener,
int maxConcurrency) {
this.name = name;
@ -107,6 +111,7 @@ public class ParallelScheduler implements Scheduler {
try {
queue.wait(500);
} catch (InterruptedException e) {
LOGGER.error("Exception in MockInterpreterAngular while interpret queue.wait", e);
}
continue;
}

View file

@ -17,12 +17,6 @@
package org.apache.zeppelin.scheduler;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import org.apache.thrift.TException;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
@ -32,6 +26,12 @@ import org.apache.zeppelin.scheduler.Job.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
/**
* RemoteScheduler runs in ZeppelinServer and proxies Scheduler running on RemoteInterpreter
*/
@ -67,6 +67,7 @@ public class RemoteScheduler implements Scheduler {
try {
queue.wait(500);
} catch (InterruptedException e) {
logger.error("Exception in RemoteScheduler while run queue.wait", e);
}
continue;
}
@ -86,6 +87,8 @@ public class RemoteScheduler implements Scheduler {
try {
queue.wait(500);
} catch (InterruptedException e) {
logger.error("Exception in RemoteScheduler while jobRunner.isJobSubmittedInRemote " +
"queue.wait", e);
}
}
}
@ -194,6 +197,7 @@ public class RemoteScheduler implements Scheduler {
try {
this.wait(interval);
} catch (InterruptedException e) {
logger.error("Exception in RemoteScheduler while run this.wait", e);
}
}

View file

@ -90,6 +90,7 @@ public class MockInterpreterAngular extends Interpreter {
try {
Thread.sleep(500); // wait for watcher executed
} catch (InterruptedException e) {
logger.error("Exception in MockInterpreterAngular while interpret Thread.sleep", e);
}
String msg = registry.getAll(context.getNoteId()).size() + " " + Integer.toString(numWatch.get());

View file

@ -22,6 +22,8 @@ import java.util.Map;
import org.apache.zeppelin.scheduler.Job;
import org.apache.zeppelin.scheduler.JobListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SleepingJob extends Job{
@ -30,6 +32,8 @@ public class SleepingJob extends Job{
private long start;
private int count;
static Logger LOGGER = LoggerFactory.getLogger(SleepingJob.class);
public SleepingJob(String jobName, JobListener listener, int time){
super(jobName, listener);
@ -44,6 +48,7 @@ public class SleepingJob extends Job{
try {
Thread.sleep(10);
} catch (InterruptedException e) {
LOGGER.error("Exception in MockInterpreterAngular while interpret Thread.sleep", e);
}
if(System.currentTimeMillis() - start>time) break;
}

View file

@ -110,9 +110,11 @@ public class InterpreterRestApi {
interpreterFactory.setPropertyAndRestart(settingId,
new InterpreterOption(true), p.getProperties());
} catch (InterpreterException e) {
logger.error("Exception in InterpreterRestApi while updateSetting ", e);
return new JsonResponse(
Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
} catch (IOException e) {
logger.error("Exception in InterpreterRestApi while updateSetting ", e);
return new JsonResponse(
Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
}
@ -144,6 +146,7 @@ public class InterpreterRestApi {
try {
interpreterFactory.restart(settingId);
} catch (InterpreterException e) {
logger.error("Exception in InterpreterRestApi while restartSetting ", e);
return new JsonResponse(
Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
}

View file

@ -308,6 +308,7 @@ public class NotebookRestApi {
notebookServer.broadcastNote(note);
return new JsonResponse(Status.OK, "").build();
} catch (IndexOutOfBoundsException e) {
LOG.error("Exception in NotebookRestApi while moveParagraph ", e);
return new JsonResponse(Status.BAD_REQUEST, "paragraph's new index is out of bound").build();
}
}

View file

@ -135,6 +135,7 @@ public class ZeppelinServer extends Application {
try {
System.in.read();
} catch (IOException e) {
LOG.error("Exception in ZeppelinServer while main ", e);
}
System.exit(0);
}

View file

@ -50,6 +50,8 @@ import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* from https://code.google.com/p/selenium/issues/detail?id=1361
@ -63,6 +65,8 @@ public class ScreenCaptureHtmlUnitDriver extends HtmlUnitDriver implements Takes
// http://stackoverflow.com/questions/4652777/java-regex-to-get-the-urls-from-css
private final static Pattern cssUrlPattern = Pattern.compile("background(-image)?[\\s]*:[^url]*url[\\s]*\\([\\s]*([^\\)]*)[\\s]*\\)[\\s]*");// ?<url>
static Logger LOGGER = LoggerFactory.getLogger(ScreenCaptureHtmlUnitDriver.class);
public ScreenCaptureHtmlUnitDriver() {
super();
}
@ -88,6 +92,7 @@ public class ScreenCaptureHtmlUnitDriver extends HtmlUnitDriver implements Takes
try {
archive = downloadCssAndImages(getWebClient(), (HtmlPage) getCurrentWindow().getEnclosedPage());
} catch (Exception e) {
LOGGER.error("Exception in ScreenCaptureHtmlUnitDriver while getScreenshotAs ", e);
}
if(target.equals(OutputType.BASE64)){
return target.convertFromBase64Png(new Base64Encoder().encode(archive));
@ -116,6 +121,7 @@ public class ScreenCaptureHtmlUnitDriver extends HtmlUnitDriver implements Takes
window = webClient.getWebWindowByName(page.getUrl().toString()+"_screenshot");
webClient.getPage(window, new WebRequest(page.getUrl()));
} catch (Exception e) {
LOGGER.error("Exception in ScreenCaptureHtmlUnitDriver while downloadCssAndImages ", e);
window = webClient.openWindow(page.getUrl(), page.getUrl().toString()+"_screenshot");
}
@ -148,6 +154,7 @@ public class ScreenCaptureHtmlUnitDriver extends HtmlUnitDriver implements Takes
.replace("resources/", "./").getBytes());
}
} catch (Exception e) {
LOGGER.error("Exception in ScreenCaptureHtmlUnitDriver while resultList.iterator ", e);
}
}
String pagesrc = replaceRemoteUrlsWithLocal(page.getWebResponse().getContentAsString(), urlMapping);

View file

@ -233,6 +233,7 @@ public class ProcessData {
String exceptionAsString = sw.toString();
LOG.error(exceptionAsString);
} catch (Exception ignore) {
LOG.info("Exception in ProcessData while buildOutputAndErrorStreamData ", ignore);
}
break;
}

View file

@ -85,6 +85,7 @@ public class WebDriverManager {
driver = new FirefoxDriver(ffox, profile);
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
}
}
@ -92,6 +93,7 @@ public class WebDriverManager {
try {
driver = new ChromeDriver();
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
}
}
@ -99,6 +101,7 @@ public class WebDriverManager {
try {
driver = new SafariDriver();
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while SafariDriver ", e);
}
}
@ -126,6 +129,7 @@ public class WebDriverManager {
loaded = true;
break;
} catch (TimeoutException e) {
LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
driver.navigate().to(url);
}
}
@ -164,7 +168,6 @@ public class WebDriverManager {
} catch (IOException e) {
LOG.error("Download of firebug version: " + firefoxVersion + ", falied in path " + tempPath);
LOG.error(e.toString());
}
LOG.info("Download of firebug version: " + firefoxVersion + ", successful");
}

View file

@ -101,6 +101,7 @@ public class ZeppelinIT {
WebElement element = pollingWait(locator, MAX_BROWSER_TIMEOUT_SEC);
return txt.equals(element.getText());
} catch (TimeoutException e) {
LOG.error("Exception in ZeppelinIT while waitForText ", e);
return false;
}
}
@ -255,6 +256,7 @@ public class ZeppelinIT {
System.out.println("testCreateNotebook Test executed");
} catch (ElementNotVisibleException e) {
LOG.error("Exception in ZeppelinIT while testAngularDisplay ", e);
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
}
@ -279,6 +281,7 @@ public class ZeppelinIT {
try {
Thread.sleep(500); // wait for notebook list updated
} catch (InterruptedException e) {
LOG.error("Exception in ZeppelinIT while createNewNote Thread.sleep", e);
}
}
}

View file

@ -55,7 +55,7 @@ public abstract class AbstractTestRestApi {
static final String restApiUrl = "/api";
static final String url = getUrlToTest();
protected static final boolean wasRunning = checkIfServerIsRuning();
protected static final boolean wasRunning = checkIfServerIsRunning();
static boolean pySpark = false;
private String getUrl(String path) {
@ -101,7 +101,7 @@ public abstract class AbstractTestRestApi {
boolean started = false;
while (System.currentTimeMillis() - s < 1000 * 60 * 3) { // 3 minutes
Thread.sleep(2000);
started = checkIfServerIsRuning();
started = checkIfServerIsRunning();
if (started == true) {
break;
}
@ -218,7 +218,7 @@ public abstract class AbstractTestRestApi {
boolean started = true;
while (System.currentTimeMillis() - s < 1000 * 60 * 3) { // 3 minutes
Thread.sleep(2000);
started = checkIfServerIsRuning();
started = checkIfServerIsRunning();
if (started == false) {
break;
}
@ -231,13 +231,14 @@ public abstract class AbstractTestRestApi {
}
}
protected static boolean checkIfServerIsRuning() {
protected static boolean checkIfServerIsRunning() {
GetMethod request = null;
boolean isRunning = true;
try {
request = httpGet("/");
isRunning = request.getStatusCode() == 200;
} catch (IOException e) {
LOG.error("Exception in AbstractTestRestApi while checkIfServerIsRunning ", e);
isRunning = false;
} finally {
if (request != null) {
@ -343,6 +344,7 @@ public abstract class AbstractTestRestApi {
try {
new JsonParser().parse(body);
} catch (JsonParseException e) {
LOG.error("Exception in AbstractTestRestApi while matchesSafely ", e);
isValid = false;
}
return isValid;

View file

@ -19,10 +19,7 @@
*/
package org.apache.zeppelin.socket;
import static org.junit.Assert.*;
import java.io.IOException;
import com.google.gson.Gson;
import org.apache.zeppelin.interpreter.InterpreterGroup;
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.notebook.Note;
@ -34,14 +31,13 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.gson.Gson;
import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@ -149,6 +145,8 @@ public class NotebookServerTest extends AbstractTestRestApi {
note = notebookServer.importNote(null, notebook, messageReceived);
} catch (NullPointerException e) {
//broadcastNoteList(); failed nothing to worry.
LOG.error("Exception in NotebookServerTest while testImportNotebook, failed nothing to " +
"worry ", e);
}
assertNotEquals(null, notebook.getNote(note.getId()));

View file

@ -565,6 +565,7 @@ public class ZeppelinConfiguration extends XMLConfiguration {
try {
checkType(value);
} catch (Exception e) {
LOG.error("Exception in ZeppelinConfiguration while isType", e);
return false;
}
return true;

View file

@ -17,29 +17,8 @@
package org.apache.zeppelin.interpreter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.NullArgumentException;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
@ -54,8 +33,13 @@ import org.apache.zeppelin.scheduler.Job.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
/**
* Manage interpreters.
@ -135,6 +119,8 @@ public class InterpreterFactory {
}
} catch (ClassNotFoundException e) {
// nothing to do
logger.info("Exception in InterpreterFactory while init, nothing to do, " +
"ClassNotFoundException:", className);
}
}
}

View file

@ -17,6 +17,9 @@
package org.apache.zeppelin.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -27,13 +30,15 @@ import java.util.Map;
public class UtilsForTests {
public static File createTmpDir() throws Exception {
File tmpDir = new File(System.getProperty("java.io.tmpdir")+"/ZeppelinLTest_"+System.currentTimeMillis());
tmpDir.mkdir();
return tmpDir;
static Logger LOGGER = LoggerFactory.getLogger(UtilsForTests.class);
}
/*
public static File createTmpDir() throws Exception {
File tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis());
tmpDir.mkdir();
return tmpDir;
}
/*
private static final String HADOOP_DIST="http://apache.mirror.cdnetworks.com/hadoop/common/hadoop-1.2.1/hadoop-1.2.1-bin.tar.gz";
//private static final String HADOOP_DIST="http://www.us.apache.org/dist/hadoop/common/hadoop-1.2.1/hadoop-1.2.1-bin.tar.gz";
@ -48,72 +53,72 @@ public class UtilsForTests {
}
*/
public static void delete(File file){
if(file.isFile()) file.delete();
else if(file.isDirectory()){
File [] files = file.listFiles();
if(files!=null && files.length>0){
for(File f : files){
delete(f);
}
}
file.delete();
}
}
/**
* Utility method to create a file (if does not exist) and populate it the the given content
*
* @param path to file
* @param content of the file
* @throws IOException
*/
public static void createFileWithContent(String path, String content) throws IOException {
File f = new File(path);
if (!f.exists()) {
stringToFile(content, f);
public static void delete(File file) {
if (file.isFile()) file.delete();
else if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null && files.length > 0) {
for (File f : files) {
delete(f);
}
}
file.delete();
}
}
public static void stringToFile(String string, File file) throws IOException{
FileOutputStream out = new FileOutputStream(file);
out.write(string.getBytes());
out.close();
}
/**
* Utility method to create a file (if does not exist) and populate it the the given content
*
* @param path to file
* @param content of the file
* @throws IOException
*/
public static void createFileWithContent(String path, String content) throws IOException {
File f = new File(path);
if (!f.exists()) {
stringToFile(content, f);
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void setEnv(String k, String v) {
Map<String, String> newenv = new HashMap<String, String>();
newenv.put(k, v);
try {
Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
theEnvironmentField.setAccessible(true);
Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
env.putAll(newenv);
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
theCaseInsensitiveEnvironmentField.setAccessible(true);
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
cienv.putAll(newenv);
} catch (NoSuchFieldException e) {
try {
Class[] classes = Collections.class.getDeclaredClasses();
Map<String, String> env = System.getenv();
for(Class cl : classes) {
if("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
Field field = cl.getDeclaredField("m");
field.setAccessible(true);
Object obj = field.get(env);
Map<String, String> map = (Map<String, String>) obj;
map.clear();
map.putAll(newenv);
}
}
} catch (Exception e2) {
e2.printStackTrace();
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
public static void stringToFile(String string, File file) throws IOException {
FileOutputStream out = new FileOutputStream(file);
out.write(string.getBytes());
out.close();
}
@SuppressWarnings({"unchecked", "rawtypes"})
public static void setEnv(String k, String v) {
Map<String, String> newenv = new HashMap<String, String>();
newenv.put(k, v);
try {
Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
theEnvironmentField.setAccessible(true);
Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
env.putAll(newenv);
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
theCaseInsensitiveEnvironmentField.setAccessible(true);
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
cienv.putAll(newenv);
} catch (NoSuchFieldException e) {
try {
Class[] classes = Collections.class.getDeclaredClasses();
Map<String, String> env = System.getenv();
for (Class cl : classes) {
if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
Field field = cl.getDeclaredField("m");
field.setAccessible(true);
Object obj = field.get(env);
Map<String, String> map = (Map<String, String>) obj;
map.clear();
map.putAll(newenv);
}
}
} catch (Exception e2) {
LOGGER.error(e2.toString(), e2);
}
} catch (Exception e1) {
LOGGER.error(e1.toString(), e1);
}
}
}