use of java.util.regex.Pattern in project zeppelin by apache.
the class NotebookServer method restoreFolder.
private void restoreFolder(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws SchedulerException, IOException {
String folderId = (String) fromMessage.get("id");
if (folderId == null) {
return;
}
Folder folder = notebook.getFolder(folderId);
if (folder != null && folder.isTrash()) {
String restoreName = folder.getId().replaceFirst(Folder.TRASH_FOLDER_ID + "/", "").trim();
// if the folder had conflict when it had moved to trash before
Pattern p = Pattern.compile("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
Matcher m = p.matcher(restoreName);
restoreName = m.replaceAll("").trim();
fromMessage.put("name", restoreName);
renameFolder(conn, userAndRoles, notebook, fromMessage, "restore");
}
}
use of java.util.regex.Pattern in project zeppelin by apache.
the class MongoNotebookRepo method printDuplicatedException.
/**
* MongoBulkWriteException contains error messages that inform
* which documents were duplicated. This method catches those ID and print them.
* @param e
*/
private void printDuplicatedException(MongoBulkWriteException e) {
List<BulkWriteError> errors = e.getWriteErrors();
for (BulkWriteError error : errors) {
String msg = error.getMessage();
// regex for note ID
Pattern pattern = Pattern.compile("[A-Z0-9]{9}");
Matcher matcher = pattern.matcher(msg);
if (matcher.find()) {
// if there were a note ID
String noteId = matcher.group();
LOG.warn("Note " + noteId + " not inserted since already exists in MongoDB");
}
}
}
use of java.util.regex.Pattern in project zeppelin by apache.
the class InstallInterpreter method readAvailableInterpreters.
private void readAvailableInterpreters() throws IOException {
if (!interpreterListFile.isFile()) {
System.err.println("Can't find interpreter list " + interpreterListFile.getAbsolutePath());
return;
}
String text = FileUtils.readFileToString(interpreterListFile);
String[] lines = text.split("\n");
Pattern pattern = Pattern.compile("(\\S+)\\s+(\\S+)\\s+(.*)");
int lineNo = 0;
for (String line : lines) {
lineNo++;
if (line == null || line.length() == 0 || line.startsWith("#")) {
continue;
}
Matcher match = pattern.matcher(line);
if (match.groupCount() != 3) {
System.err.println("Error on line " + lineNo + ", " + line);
continue;
}
match.find();
String name = match.group(1);
String artifact = match.group(2);
String description = match.group(3);
availableInterpreters.add(new AvailableInterpreterInfo(name, artifact, description));
}
}
use of java.util.regex.Pattern in project zookeeper by apache.
the class Log4JSource method init.
private void init() throws IOException {
File f = new File(file);
RandomAccessFileReader in = new RandomAccessFileReader(f);
SimpleDateFormat dateformat = new SimpleDateFormat(DATE_FORMAT);
Pattern idp = Pattern.compile("\\[myid:(\\d+)\\]");
long lastFp = in.getPosition();
String line = in.readLine();
Matcher m = null;
// if we have read data from the file, and it matchs the timep pattern
if ((line != null) && (m = timep.matcher(line)).lookingAt()) {
starttime = timestampFromText(dateformat, m.group(1));
} else {
throw new IOException("Invalid log4j format. First line doesn't start with time");
}
/*
Count number of log entries. Any line starting with a timestamp counts as an entry
*/
String lastentry = line;
try {
while (line != null) {
m = timep.matcher(line);
if (m.lookingAt()) {
if (size % skipN == 0) {
long time = timestampFromText(dateformat, m.group(1));
skiplist.addMark(time, lastFp, size);
}
size++;
lastentry = line;
}
if (serverid == 0 && (m = idp.matcher(line)).find()) {
serverid = Integer.valueOf(m.group(1));
}
lastFp = in.getPosition();
line = in.readLine();
}
} catch (EOFException eof) {
// ignore, simply end of file, though really (line!=null) should have caught this
} finally {
in.close();
}
m = timep.matcher(lastentry);
if (m.lookingAt()) {
endtime = timestampFromText(dateformat, m.group(1));
} else {
throw new IOException("Invalid log4j format. Last line doesn't start with time");
}
}
use of java.util.regex.Pattern in project zookeeper by apache.
the class QuorumPeerMainTest method testBadPeerAddressInQuorum.
/**
* Verify handling of bad quorum address
*/
@Test
public void testBadPeerAddressInQuorum() throws Exception {
ClientBase.setupTestEnv();
// setup the logger to capture all logs
Layout layout = Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setThreshold(Level.WARN);
Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
qlogger.addAppender(appender);
try {
final int CLIENT_PORT_QP1 = PortAssignment.unique();
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection = "server.1=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2;
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
q1.start();
boolean isup = ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, 30000);
Assert.assertFalse("Server never came up", isup);
q1.shutdown();
Assert.assertTrue("waiting for server 1 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, ClientBase.CONNECTION_TIMEOUT));
} finally {
qlogger.removeAppender(appender);
}
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
boolean found = false;
Pattern p = Pattern.compile(".*Cannot open channel to .* at election address .*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
break;
}
}
Assert.assertTrue("complains about host", found);
}
Aggregations