Skip to content

Commit

Permalink
Merge pull request #1 from amplab/ui
Browse files Browse the repository at this point in the history
Merge UI Branch
  • Loading branch information
haoyuan committed Feb 25, 2013
2 parents 271c0cc + 143a18e commit 17b2f0e
Show file tree
Hide file tree
Showing 23 changed files with 655 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ data/
logs/
src/main/java/tachyon/thrift
tachyon.iml
target/
target/
52 changes: 41 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,53 @@
<hadoop.version>0.20.205.0</hadoop.version>
<libthrift.version>0.7.0</libthrift.version>
<cxf.version>2.7.0</cxf.version>
<jetty.version>7.5.3.v20111011</jetty.version>
<jetty.version>8.1.9.v20130131</jetty.version>
</properties>

<repositories>
</repositories>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp-2.1</artifactId>
<version>7.5.4.v20111024</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jsp-impl</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -45,16 +85,6 @@
<artifactId>hadoop-core</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/tachyon/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import tachyon.thrift.InvalidPathException;

/**
* Utility class shared by all components of the system.
*
Expand Down Expand Up @@ -55,13 +57,13 @@ public static String cleanPath(String path) {
return path;
}

public static String convertMillis(long Millis) {
public static String convertMsToClockTime(long Millis) {
return String.format("%d hour(s), %d minute(s), and %d second(s)",
Millis / (1000L * 60 * 60), (Millis % (1000L * 60 * 60)) / (1000 * 60),
(Millis % (1000L * 60)) / 1000);
}

public static String convertMillisToDate(long Millis) {
public static String convertMsToDate(long Millis) {
DateFormat formatter = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss:SSS");
return formatter.format(new Date(Millis));
}
Expand Down Expand Up @@ -274,4 +276,11 @@ public static String[] toStringArray(ArrayList<String> src) {
String[] ret = new String[src.size()];
return src.toArray(ret);
}

public static void validatePath(String path) throws InvalidPathException {
if (path == null || !path.startsWith(Config.SEPARATOR) ||
(path.length() > 1 && path.endsWith(Config.SEPARATOR))) {
throw new InvalidPathException("Path " + path + " is invalid.");
}
}
}
1 change: 1 addition & 0 deletions src/main/java/tachyon/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class Config {
public static final boolean USING_HDFS;

public static final int MAX_COLUMNS = 100;
public static final String SEPARATOR = "/";

public static final ArrayList<String> WHITELIST = new ArrayList<String>();
public static final ArrayList<String> PINLIST = new ArrayList<String>();
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/tachyon/Master.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tachyon;

import java.io.File;
import java.net.InetSocketAddress;

import org.apache.thrift.server.THsHaServer;
Expand All @@ -9,6 +10,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;

import tachyon.thrift.MasterService;

/**
Expand All @@ -30,12 +37,26 @@ private Master(InetSocketAddress address, int selectorThreads, int acceptQueueSi
int workerThreads) {
try {
mMasterInfo = new MasterInfo(address);

mWebServer = new WebServer("Tachyon Master Server",
new InetSocketAddress(address.getHostName(), Config.MASTER_WEB_PORT));
mWebServer.setHandler(new WebServerMasterHandler(mMasterInfo));

WebAppContext webappcontext = new WebAppContext();

webappcontext.setContextPath("/");
File warPath = new File(new File("").getAbsolutePath(), "src/main/java/tachyon/webapps");
webappcontext.setWar(warPath.getAbsolutePath());
HandlerList handlers = new HandlerList();
webappcontext.addServlet(
new ServletHolder(new WebInterfaceGeneralServlet(mMasterInfo)), "/home");
webappcontext.addServlet(
new ServletHolder(new WebInterfaceBrowseServlet(mMasterInfo)), "/browse");

handlers.setHandlers(new Handler[] { webappcontext, new DefaultHandler() });
mWebServer.setHandler(handlers);

mWebServer.startWebServer();

mMasterServiceHandler = new MasterServiceHandler(mMasterInfo);
MasterService.Processor<MasterServiceHandler> processor =
new MasterService.Processor<MasterServiceHandler>(mMasterServiceHandler);
Expand Down
40 changes: 23 additions & 17 deletions src/main/java/tachyon/MasterInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
* @author Haoyuan Li [email protected]
*/
public class MasterInfo {
public static final String SEPARATOR = "/";
public static final String COL = "COL_";

private final Logger LOG = LoggerFactory.getLogger(MasterInfo.class);
Expand Down Expand Up @@ -226,7 +225,7 @@ public int createRawTable(String path, int columns, List<Byte> metadata)
int id = createFile(path, true, columns, metadata);

for (int k = 0; k < columns; k ++) {
createFile(path + SEPARATOR + COL + k, true);
createFile(path + Config.SEPARATOR + COL + k, true);
}

return id;
Expand Down Expand Up @@ -272,7 +271,6 @@ public List<ClientFileInfo> getFilesInfo(String path)
throw new FileDoesNotExistException(path);
}

ret.add(getClientFileInfo(inode.getId()));
if (inode.isDirectory()) {
List<Integer> childernIds = ((InodeFolder) inode).getChildrenIds();

Expand All @@ -284,11 +282,22 @@ public List<ClientFileInfo> getFilesInfo(String path)
ret.add(getClientFileInfo(k));
}
}
} else {
ret.add(getClientFileInfo(inode.getId()));
}

return ret;
}

public ClientFileInfo getFileInfo(String path)
throws FileDoesNotExistException, InvalidPathException {
Inode inode = getInode(path);
if (inode == null) {
throw new FileDoesNotExistException(path);
}
return getClientFileInfo(inode.getId());
}

public void delete(int id) {
LOG.info("delete(" + id + ")");
// Only remove meta data from master. The data in workers will be evicted since no further
Expand Down Expand Up @@ -367,21 +376,14 @@ private Inode getInode(String[] pathNames) throws InvalidPathException {
}
}

private static void validatePath(String path) throws InvalidPathException {
if (path == null || !path.startsWith(SEPARATOR) ||
(path.length() > 1 && path.endsWith(SEPARATOR))) {
throw new InvalidPathException("Path " + path + " is invalid.");
}
}

private static String[] getPathNames(String path) throws InvalidPathException {
validatePath(path);
if (path.length() == 1 && path.equals(SEPARATOR)) {
CommonUtils.validatePath(path);
if (path.length() == 1 && path.equals(Config.SEPARATOR)) {
String[] ret = new String[1];
ret[0] = "";
return ret;
}
return path.split(SEPARATOR);
return path.split(Config.SEPARATOR);
}

private void writeCheckpoint() {
Expand Down Expand Up @@ -472,7 +474,7 @@ private void recoveryFromLog() {
public String toHtml() {
long timeMs = System.currentTimeMillis() - START_TIME_MS;
StringBuilder sb = new StringBuilder("<h1> Tachyon has been running @ " + MASTER_ADDRESS +
" for " + CommonUtils.convertMillis(timeMs) + " </h1> \n");
" for " + CommonUtils.convertMsToClockTime(timeMs) + " </h1> \n");

sb.append(mWhiteList.toHtml("WhiteList"));

Expand Down Expand Up @@ -513,7 +515,7 @@ private int generateFileNamesForHtml(String curPath, Inode inode, StringBuilder
if (inode.isDirectory()) {
List<Integer> childrenIds = ((InodeFolder) inode).getChildrenIds();
if (inode.getId() != 1) {
curPath += SEPARATOR;
curPath += Config.SEPARATOR;
}
for (int id : childrenIds) {
int t = generateFileNamesForHtml(curPath, mInodes.get(id), sb, cnt);
Expand Down Expand Up @@ -715,9 +717,9 @@ private String getPath(Inode inode) {
return "/";
}
if (inode.getParentId() == 1) {
return SEPARATOR + inode.getName();
return Config.SEPARATOR + inode.getName();
}
return getPath(mInodes.get(inode.getParentId())) + SEPARATOR + inode.getName();
return getPath(mInodes.get(inode.getParentId())) + Config.SEPARATOR + inode.getName();
}
}

Expand Down Expand Up @@ -897,6 +899,10 @@ public long registerWorker(NetAddress workerNetAddress, long totalBytes,
return id;
}

public long getStarttimeMs() {
return START_TIME_MS;
}

public int getNumberOfFiles(String path) throws InvalidPathException, FileDoesNotExistException {
Inode inode = getInode(path);
if (inode == null) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/tachyon/MasterServiceHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tachyon;

import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -199,4 +198,4 @@ public long worker_register(NetAddress workerNetAddress, long totalBytes, long u
List<Integer> currentFileIds) throws TException {
return mMasterInfo.registerWorker(workerNetAddress, totalBytes, usedBytes, currentFileIds);
}
}
}
Loading

0 comments on commit 17b2f0e

Please sign in to comment.