Skip to content

Commit

Permalink
Merge pull request #1 from haoyuan/variable
Browse files Browse the repository at this point in the history
Variable
  • Loading branch information
haoyuan committed Dec 16, 2013
2 parents 85609b7 + 21fa09d commit 3a2c8d9
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bin/tachyon
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ else
exit 1
fi

$JAVA -cp $TACHYON_JAR -Dtachyon.home=$TACHYON_HOME -Dtachyon.master.hostname=$TACHYON_MASTER_ADDRESS -Dtachyon.logger.type=USER_LOGGER $TACHYON_JAVA_OPTS $CLASS $@
$JAVA -cp $TACHYON_JAR -Dtachyon.home=$TACHYON_HOME -Dtachyon.master.hostname=$TACHYON_MASTER_ADDRESS -Dtachyon.logger.type=USER_LOGGER $TACHYON_JAVA_OPTS $CLASS $@
10 changes: 9 additions & 1 deletion src/main/java/tachyon/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public String toString() {
public synchronized String getCommand() {
// TODO In future, we should support different types of command;
// For now, assume there is only one command model.
StringBuilder sb = new StringBuilder(COMMAND_PREFIX);
StringBuilder sb = new StringBuilder(parseCommandPrefix());
sb.append(" ").append(DependencyVariables.MASTER_HOSTNAME);
sb.append(":").append(DependencyVariables.MASTER_PORT);
sb.append(" ").append(ID);
Expand All @@ -93,6 +93,14 @@ public synchronized String getCommand() {
return sb.toString();
}

public String parseCommandPrefix() {
String rtn = COMMAND_PREFIX;
for (String s : RecomputeVariables.sRecomputeVars.keySet()) {
rtn = rtn.replace("$" + s, RecomputeVariables.sRecomputeVars.get(s));
}
return rtn;
}

public ClientDependencyInfo generateClientDependencyInfo() {
ClientDependencyInfo ret = new ClientDependencyInfo();
ret.id = ID;
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/tachyon/RecomputeVariables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tachyon;

import java.util.Hashtable;

public class RecomputeVariables {
public static Hashtable<String, String> sRecomputeVars = new Hashtable<String, String>();
}
31 changes: 23 additions & 8 deletions src/main/java/tachyon/web/WebInterfaceGeneralServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package tachyon.web;

import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand All @@ -27,6 +28,7 @@
import tachyon.CommonUtils;
import tachyon.Constants;
import tachyon.MasterInfo;
import tachyon.RecomputeVariables;
import tachyon.Version;
import tachyon.thrift.ClientWorkerInfo;

Expand Down Expand Up @@ -82,7 +84,7 @@ public int getUsedSpacePercent() {

public String getUptimeClockTime() {
return UPTIME_CLOCK_TIME;
}
}
}

public WebInterfaceGeneralServlet(MasterInfo masterInfo) {
Expand All @@ -93,23 +95,34 @@ public WebInterfaceGeneralServlet(MasterInfo masterInfo) {
* Redirects the request to a jsp after populating attributes via populateValues.
* @param request The HttpServletRequest object
* @param response The HttpServletResponse object
*/
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
populateValues(request);
getServletContext().getRequestDispatcher("/general.jsp").forward(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
return;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RecomputeVariables.sRecomputeVars.clear();
for (String key : (Set<String>) request.getParameterMap().keySet()) {
if (key.startsWith("varName")) {
String value = request.getParameter("varVal" + key.substring(7));
if (value != null) {
RecomputeVariables.sRecomputeVars.put(request.getParameter(key), value);
}
}
}
populateValues(request);
getServletContext().getRequestDispatcher("/general.jsp").forward(request, response);
}

/**
* Populates key, value pairs for UI display
* @param request The HttpServletRequest object
* @throws IOException
* @throws IOException
*/
private void populateValues(HttpServletRequest request) throws IOException {
request.setAttribute("debug", Constants.DEBUG);
Expand All @@ -128,7 +141,7 @@ private void populateValues(HttpServletRequest request) throws IOException {
request.setAttribute("capacity", CommonUtils.getSizeFromBytes(mMasterInfo.getCapacityBytes()));

request.setAttribute("usedCapacity", CommonUtils.getSizeFromBytes(mMasterInfo.getUsedBytes()));

request.setAttribute("freeCapacity", CommonUtils.getSizeFromBytes(
(mMasterInfo.getCapacityBytes() - mMasterInfo.getUsedBytes())));

Expand All @@ -151,7 +164,9 @@ private void populateValues(HttpServletRequest request) throws IOException {
request.setAttribute("diskFreeCapacity", CommonUtils.getSizeFromBytes(sizeBytes));
} else {
request.setAttribute("diskFreeCapacity", "UNKNOWN");
}
}

request.setAttribute("recomputeVariables", RecomputeVariables.sRecomputeVars);

List<ClientWorkerInfo> workerInfos = mMasterInfo.getWorkersInfo();
for (int i = 0; i < workerInfos.size(); i ++) {
Expand Down
63 changes: 57 additions & 6 deletions src/main/java/tachyon/web/resources/general.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<th><%= request.getAttribute("uptime") %></th>
</tr>
<tr>
<th>Version:</th>
<th>Version:</th>
<!-- <th>${version}</th> -->
<th><%= request.getAttribute("version") %></th>
</tr>
Expand Down Expand Up @@ -102,7 +102,7 @@
</div>
</div>
</div>
</div>
</div>
</div>
<div class ="row-fluid">
<div class="accordion span6" id="accordion3">
Expand All @@ -123,7 +123,7 @@
</c:forEach>
-->
<% for (String file : ((List<String>) request.getAttribute("pinlist"))) { %>
<tr>
<tr>
<th><%= file %></th>
</tr>
<% } %>
Expand All @@ -133,7 +133,7 @@
</div>
</div>
</div>
</div>
</div>
<div class="accordion span6" id="accordion4">
<div class="accordion-group">
<div class="accordion-heading">
Expand Down Expand Up @@ -162,17 +162,55 @@
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="accordion span14" id="accordion5">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion5" href="#data5">
<h4>Detailed Nodes Summary</h4>
<h4>Recomputation Variables</h4>
</a>
</div>
<div id="data5" class="accordion-body collapse in">
<div class="accordion-inner">
<form class="form" method="post" action="/home">
<div id="recomputationVars">
<% int i = 0; %>
<% for (String key : ((Hashtable<String, String>) request.getAttribute("recomputeVariables")).keySet()) { %>
<div id="varDiv<%= i %>">
<div class="input-prepend">
<span class="add-on">Name</span>
<input class="span8" name="varName<%= i %>" type="text" value="<%= key %>">
</div>
<div class="input-prepend">
<span class="add-on">Value</span>
<input class="span8" type="text" name="varVal<%= i %>" value="<%= ((Hashtable<String, String>) request.getAttribute("recomputeVariables")).get(key) %>">
<input style="margin-left:10px" class="btn btn-danger" type="button" value="Delete" onclick="deleteVar(varDiv<%= i++ %>)"/>
</div>
</br>
</div>
<% } %>
</div>
<div class="form-actions">
<input class="btn btn-primary" type="submit" value="Submit" id="submit"/>
<input class="btn" type="button" value="Add Variable" id="addVariable"/>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="accordion span14" id="accordion6">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion6" href="#data6">
<h4>Detailed Nodes Summary</h4>
</a>
</div>
<div id="data6" class="accordion-body collapse in">
<div class="accordion-inner">
<table class="table table-hover table-condensed">
<thead>
Expand Down Expand Up @@ -252,5 +290,18 @@
</p>
</footer>
</div>
<script>
var id = ($("#recomputationVars").children().length).toString();
$(document).ready(function () {
$("#addVariable").click(function () {
$("#recomputationVars").append('<div id="varDiv' + id + '"><div class="input-prepend" style="padding-right: 4px"><span class="add-on">Name</span><input class="span8" name="varName' + id + '" type="text" value="Variable Name"></div><div class="input-prepend"><span class="add-on">Value</span><input class="span8" type="text" name="varVal' + id + '" value="Value"><input style="margin-left:10px" class="btn btn-danger" type="button" value="Delete" onclick="deleteVar(varDiv' + id + ')"/></div></br></div>');
id ++;
});
});
function deleteVar(value) {
value.remove();
}
</script>
</body>
</html>
63 changes: 63 additions & 0 deletions src/test/java/tachyon/DependencyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tachyon;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import tachyon.conf.MasterConf;

public class DependencyTest {
private LocalTachyonCluster mLocalTachyonCluster = null;
private String mMasterValue = "localhost";
private String mPortValue = "8080";

@Before
public final void before() throws IOException {
mLocalTachyonCluster = new LocalTachyonCluster(10000);
mLocalTachyonCluster.start();
RecomputeVariables.sRecomputeVars.put("master", mMasterValue);
RecomputeVariables.sRecomputeVars.put("port", mPortValue);
}

@After
public final void after() throws Exception {
RecomputeVariables.sRecomputeVars.clear();
mLocalTachyonCluster.stop();
}

@Test
public void ParseCommandPrefixTest() {
String cmd = "java test.jar $master:$port";
String parsedCmd = "java test.jar localhost:8080";
List<Integer> parents = new ArrayList<Integer>();
List<Integer> children = new ArrayList<Integer>();
List<ByteBuffer> data = new ArrayList<ByteBuffer>();
Collection<Integer> parentDependencies = new ArrayList<Integer>();
Dependency dep = new Dependency(0, parents, children, cmd, data, "Dependency Test",
"Tachyon Tests", "0.4", DependencyType.Narrow, parentDependencies, 0L);
Assert.assertEquals(parsedCmd, dep.parseCommandPrefix());
}
}

0 comments on commit 3a2c8d9

Please sign in to comment.