You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by de...@apache.org on 2013/02/16 12:23:52 UTC
svn commit: r1446873 - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main:
java/org/apache/uima/ducc/ws/registry/ java/org/apache/uima/ducc/ws/server/
webapp/root/ webapp/root/js/
Author: degenaro
Date: Sat Feb 16 11:23:51 2013
New Revision: 1446873
URL: http://svn.apache.org/r1446873
Log:
UIMA-2676 DUCC webserver (WS) Services presentation improvements...Start/Stop buttons
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerLegacy.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/js/ducc.js
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/services.jsp
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java?rev=1446873&r1=1446872&r2=1446873&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java Sat Feb 16 11:23:51 2013
@@ -109,6 +109,29 @@ public class ServicesRegistry {
return retVal;
}
+ public String findServiceUser(String id) {
+ String retVal = null;
+ try {
+ for(Integer key : map.keySet()) {
+ ServicesRegistryMapPayload payload = map.get(key);
+ Properties meta = payload.meta;
+ if(meta != null) {
+ if(meta.containsKey(IServicesRegistry.numeric_id)) {
+ String sid = meta.getProperty(IServicesRegistry.numeric_id);
+ if(id.equals(sid)) {
+ retVal = meta.getProperty(IServicesRegistry.user).trim();
+ break;
+ }
+ }
+ }
+ }
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ return retVal;
+ }
+
public String findServiceName(DuccId duccId) {
String retVal = null;
try {
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java?rev=1446873&r1=1446872&r2=1446873&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java Sat Feb 16 11:23:51 2013
@@ -45,6 +45,8 @@ import org.apache.uima.ducc.transport.ev
import org.apache.uima.ducc.transport.event.common.IDuccWork;
import org.apache.uima.ducc.transport.event.common.IDuccWorkJob;
import org.apache.uima.ducc.ws.DuccMachinesData;
+import org.apache.uima.ducc.ws.registry.IServicesRegistry;
+import org.apache.uima.ducc.ws.registry.ServicesRegistry;
import org.eclipse.jetty.server.handler.AbstractHandler;
public abstract class DuccAbstractHandler extends AbstractHandler {
@@ -81,6 +83,7 @@ public abstract class DuccAbstractHandle
public String dir_resources = "resources";
protected boolean terminateEnabled = true;
+ protected boolean buttonsEnabled = true;
public static final String valueStateTypeAll = "all";
public static final String valueStateTypeActive = "active";
@@ -559,7 +562,19 @@ public abstract class DuccAbstractHandle
retVal = properties.getProperty(key, defaultValue);
}
}
- return retVal;
+ return retVal.trim();
+ }
+
+ public String getDeployments(ServicesRegistry servicesRegistry, Properties propertiesMeta) {
+ String deployments = "0";
+ if(propertiesMeta != null) {
+ if(propertiesMeta.containsKey(IServicesRegistry.implementors)) {
+ String value = propertiesMeta.getProperty(IServicesRegistry.implementors);
+ String[] implementors = servicesRegistry.getList(value);
+ deployments = ""+implementors.length;
+ }
+ }
+ return deployments;
}
public ArrayList<String> getSwappingMachines(IDuccWorkJob job) {
@@ -670,6 +685,10 @@ public abstract class DuccAbstractHandle
public String getDisabled(HttpServletRequest request, IDuccWork duccWork) {
String resourceOwnerUserId = duccWork.getStandardInfo().getUser();
+ return getDisabled(request, resourceOwnerUserId);
+ }
+
+ public String getDisabled(HttpServletRequest request, String resourceOwnerUserId) {
String disabled = "disabled=\"disabled\"";
if(isAuthorized(request, resourceOwnerUserId)) {
disabled = "";
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java?rev=1446873&r1=1446872&r2=1446873&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java Sat Feb 16 11:23:51 2013
@@ -127,6 +127,8 @@ public class DuccHandler extends DuccAbs
private String duccReservationCancel = duccContext+"/reservation-cancel-request";
private String duccServiceSubmit = duccContext+"/service-submit-request";
private String duccServiceCancel = duccContext+"/service-cancel-request";
+ private String duccServiceStart = duccContext+"/service-start-request";
+ private String duccServiceStop = duccContext+"/service-stop-request";
private String jsonMachinesData = duccContext+"/json-machines-data";
private String jsonSystemClassesData = duccContext+"/json-system-classes-data";
@@ -2486,6 +2488,80 @@ public class DuccHandler extends DuccAbs
duccLogger.trace(methodName, null, messages.fetch("exit"));
}
+ private void duccServletServiceCommand(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response, String command)
+ {
+ String methodName = "duccServletServiceCommand";
+ duccLogger.trace(methodName, null, messages.fetch("enter"));
+ try {
+ String name = "id";
+ String value = request.getParameter(name).trim();
+ duccLogger.info(methodName, null, command+" "+messages.fetchLabel("id:")+value);
+ String text;
+ String result;
+ String id = value.trim();
+ ServicesRegistry servicesRegistry = new ServicesRegistry();
+ String resourceOwnerUserId = servicesRegistry.findServiceUser(id);
+ if(resourceOwnerUserId != null) {
+ if(isAuthorized(request,resourceOwnerUserId)) {
+ String arg1 = "--"+command;
+ String arg2 = id;
+ String userId = duccWebSessionManager.getUserId(request);
+ String cp = System.getProperty("java.class.path");
+ String java = "/bin/java";
+ String jclass = "org.apache.uima.ducc.cli.DuccServiceApi";
+ String jhome = System.getProperty("java.home");
+ RequestRole requestRole = getRole(request);
+ switch(requestRole) {
+ /*
+ case Administrator:
+ String arg3 = "--"+SpecificationProperties.key_role_administrator;
+ String[] arglistAdministrator = { "-u", userId, "--", jhome+java, "-cp", cp, jclass, arg1, arg2, arg3 };
+ result = DuccAsUser.duckling(userId, arglistAdministrator);
+ response.getWriter().println(result);
+ break;
+ case User:
+ */
+ default:
+ String[] arglistUser = { "-u", userId, "--", jhome+java, "-cp", cp, jclass, arg1, arg2 };
+ result = DuccAsUser.duckling(userId, arglistUser);
+ response.getWriter().println(result);
+ break;
+ }
+ }
+ }
+ else {
+ text = "id "+value+" not found";
+ duccLogger.debug(methodName, null, messages.fetch(text));
+ }
+ }
+ catch(Exception e) {
+ duccLogger.error(methodName, null, e);
+ }
+ duccLogger.trace(methodName, null, messages.fetch("exit"));
+ }
+
+ private void handleDuccServletServiceStart(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ String methodName = "handleDuccServletServiceStart";
+ duccLogger.trace(methodName, null, messages.fetch("enter"));
+
+ duccServletServiceCommand(target,baseRequest,request,response,"start");
+
+ duccLogger.trace(methodName, null, messages.fetch("exit"));
+ }
+
+ private void handleDuccServletServiceStop(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ String methodName = "handleDuccServletServiceStop";
+ duccLogger.trace(methodName, null, messages.fetch("enter"));
+
+ duccServletServiceCommand(target,baseRequest,request,response,"stop");
+
+ duccLogger.trace(methodName, null, messages.fetch("exit"));
+ }
+
private void handleDuccRequest(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException
{
@@ -2616,6 +2692,16 @@ public class DuccHandler extends DuccAbs
handleDuccServletServiceCancel(target, baseRequest, request, response);
DuccWebUtil.noCache(response);
}
+ else if(reqURI.startsWith(duccServiceStart)) {
+ duccLogger.info(methodName, null,"getRequestURI():"+request.getRequestURI());
+ handleDuccServletServiceStart(target, baseRequest, request, response);
+ DuccWebUtil.noCache(response);
+ }
+ else if(reqURI.startsWith(duccServiceStop)) {
+ duccLogger.info(methodName, null,"getRequestURI():"+request.getRequestURI());
+ handleDuccServletServiceStop(target, baseRequest, request, response);
+ DuccWebUtil.noCache(response);
+ }
else if(reqURI.startsWith(duccReservationSchedulingClasses)) {
handleDuccServletReservationSchedulingClasses(target, baseRequest, request, response);
DuccWebUtil.noCache(response);
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java?rev=1446873&r1=1446872&r2=1446873&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java Sat Feb 16 11:23:51 2013
@@ -850,7 +850,34 @@ public class DuccHandlerJsonFormat exten
Properties propertiesSvc = entry.get(IStateServices.svc);
Properties propertiesMeta = entry.get(IStateServices.meta);
String name = getValue(propertiesMeta,IServicesRegistry.endpoint,"");
+ String user = getValue(propertiesMeta,IServicesRegistry.user,"");
+ String sid = getValue(propertiesMeta,IServicesRegistry.numeric_id,"");
+ String instances = getValue(propertiesMeta,IStateServices.instances,"");
+ String deployments = getDeployments(servicesRegistry,propertiesMeta);
JsonArray row = new JsonArray();
+
+ StringBuffer col;
+ // Start
+ col = new StringBuffer();
+ col.append("<span class=\"ducc-col-start\">");
+ if(buttonsEnabled) {
+ if(!deployments.equals(instances)) {
+ col.append("<input type=\"button\" onclick=\"ducc_confirm_service_start("+sid+")\" value=\"Start\" "+getDisabled(request,user)+"/>");
+ }
+ }
+ col.append("</span>");
+ row.add(new JsonPrimitive(col.toString()));
+ // Stop
+ col = new StringBuffer();
+ col.append("<span class=\"ducc-col-stop\">");
+ if(buttonsEnabled) {
+ if(!deployments.equals("0")) {
+ col.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabled(request,user)+"/>");
+ }
+ }
+ col.append("</span>");
+ row.add(new JsonPrimitive(col.toString()));
+
// Id
String id = "<a href=\"service.details.html?name="+name+"\">"+key+"</a>";
row.add(new JsonPrimitive(id));
@@ -909,16 +936,8 @@ public class DuccHandlerJsonFormat exten
}
row.add(new JsonPrimitive(health));
// Instances
- row.add(new JsonPrimitive(getValue(propertiesMeta,IStateServices.instances,"")));
+ row.add(new JsonPrimitive(instances));
// Deployments
- String deployments = "0";
- if(propertiesMeta != null) {
- if(propertiesMeta.containsKey(IServicesRegistry.implementors)) {
- String value = propertiesMeta.getProperty(IServicesRegistry.implementors);
- String[] implementors = servicesRegistry.getList(value);
- deployments = ""+implementors.length;
- }
- }
row.add(new JsonPrimitive(deployments));
// Owning User
row.add(new JsonPrimitive(getValue(propertiesMeta,IStateServices.user,"")));
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerLegacy.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerLegacy.java?rev=1446873&r1=1446872&r2=1446873&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerLegacy.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerLegacy.java Sat Feb 16 11:23:51 2013
@@ -37,6 +37,7 @@ import org.apache.uima.ducc.common.boot.
import org.apache.uima.ducc.common.boot.DuccDaemonRuntimeProperties.DaemonName;
import org.apache.uima.ducc.common.internationalization.Messages;
import org.apache.uima.ducc.common.jd.JdConstants;
+import org.apache.uima.ducc.common.persistence.services.IStateServices;
import org.apache.uima.ducc.common.utils.DuccLogger;
import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
import org.apache.uima.ducc.common.utils.DuccProperties;
@@ -727,14 +728,37 @@ public class DuccHandlerLegacy extends D
ServicesRegistry servicesRegistry = new ServicesRegistry();
ServicesRegistryMap map = servicesRegistry.getMap();
if(!map.isEmpty()) {
+ int counter = 0;
for(Integer key : map.getDescendingKeySet()) {
ServicesRegistryMapPayload entry = map.get(key);
Properties propertiesSvc = entry.get(IServicesRegistry.svc);
Properties propertiesMeta = entry.get(IServicesRegistry.meta);
String name = getValue(propertiesMeta,IServicesRegistry.endpoint,"");
- sb.append("<tr>");
+ String user = getValue(propertiesMeta,IServicesRegistry.user,"");
+ String sid = getValue(propertiesMeta,IServicesRegistry.numeric_id,"");
+ String instances = getValue(propertiesMeta,IStateServices.instances,"");
+ String deployments = getDeployments(servicesRegistry,propertiesMeta);
+ sb.append(trGet(++counter));
+
+ // Start
+ sb.append("<td valign=\"bottom\" class=\"ducc-col-start\">");
+ if(buttonsEnabled) {
+ if(!deployments.equals(instances)) {
+ sb.append("<input type=\"button\" onclick=\"ducc_confirm_service_start("+sid+")\" value=\"Start\" "+getDisabled(request,user)+"/>");
+ }
+ }
+ sb.append("</td>");
+ // Stop
+ sb.append("<td valign=\"bottom\" class=\"ducc-col-stop\">");
+ if(buttonsEnabled) {
+ if(!deployments.equals("0")) {
+ sb.append("<input type=\"button\" onclick=\"ducc_confirm_service_stop("+sid+")\" value=\"Stop\" "+getDisabled(request,user)+"/>");
+ }
+ }
+ sb.append("</td>");
+
// Service Id
- sb.append("<td>");
+ sb.append("<td align=\"right\">");
String id = "<a href=\"service.details.html?name="+name+"\">"+key+"</a>";
sb.append(id);
sb.append("</td>");
@@ -801,19 +825,11 @@ public class DuccHandlerLegacy extends D
sb.append(health);
sb.append("</td>");
// No. of Instances
- sb.append("<td>");
- sb.append(getValue(propertiesMeta,IServicesRegistry.instances,""));
+ sb.append("<td align=\"right\">");
+ sb.append(instances);
sb.append("</td>");
// No. of Deployments
- sb.append("<td>");
- String deployments = "0";
- if(propertiesMeta != null) {
- if(propertiesMeta.containsKey(IServicesRegistry.implementors)) {
- String value = propertiesMeta.getProperty(IServicesRegistry.implementors);
- String[] implementors = servicesRegistry.getList(value);
- deployments = ""+implementors.length;
- }
- }
+ sb.append("<td align=\"right\">");
sb.append(deployments);
sb.append("</td>");
// Owning User
@@ -825,7 +841,7 @@ public class DuccHandlerLegacy extends D
sb.append(getValue(propertiesSvc,IServicesRegistry.scheduling_class,""));
sb.append("</td>");
// Process Memory Size
- sb.append("<td>");
+ sb.append("<td align=\"right\">");
sb.append(getValue(propertiesSvc,IServicesRegistry.process_memory_size,""));
sb.append("</td>");
// Description
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/js/ducc.js
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/js/ducc.js?rev=1446873&r1=1446872&r2=1446873&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/js/ducc.js (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/js/ducc.js Sat Feb 16 11:23:51 2013
@@ -1753,6 +1753,50 @@ function ducc_terminate_service(id)
return false;
}
+function ducc_service_start(id)
+{
+ try {
+ $.jGrowl(" Pending start...");
+ $.ajax(
+ {
+ type: 'POST',
+ url : "/ducc-servlet/service-start-request"+"?id="+id,
+ success : function (data)
+ {
+ $.jGrowl(data, { life: 6000 });
+ setTimeout(function(){window.close();}, 5000);
+ }
+ });
+ setTimeout(function(){window.close();}, 5000);
+ }
+ catch(err) {
+ ducc_error("ducc_service_start",err);
+ }
+ return false;
+}
+
+function ducc_service_stop(id)
+{
+ try {
+ $.jGrowl(" Pending stop...");
+ $.ajax(
+ {
+ type: 'POST',
+ url : "/ducc-servlet/service-stop-request"+"?id="+id,
+ success : function (data)
+ {
+ $.jGrowl(data, { life: 6000 });
+ setTimeout(function(){window.close();}, 5000);
+ }
+ });
+ setTimeout(function(){window.close();}, 5000);
+ }
+ catch(err) {
+ ducc_error("ducc_service_stop",err);
+ }
+ return false;
+}
+
function ducc_terminate_reservation(id)
{
try {
@@ -1864,6 +1908,32 @@ function ducc_confirm_terminate_service(
}
}
+function ducc_confirm_service_start(id)
+{
+ try {
+ var result=confirm("Start service "+id+"?");
+ if (result==true) {
+ ducc_service_start(id);
+ }
+ }
+ catch(err) {
+ ducc_error("ducc_confirm_service_start",err);
+ }
+}
+
+function ducc_confirm_service_stop(id)
+{
+ try {
+ var result=confirm("Stop service "+id+"?");
+ if (result==true) {
+ ducc_service_stop(id);
+ }
+ }
+ catch(err) {
+ ducc_error("ducc_confirm_service_stop",err);
+ }
+}
+
function ducc_confirm_terminate_reservation(id)
{
try {
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/services.jsp
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/services.jsp?rev=1446873&r1=1446872&r2=1446873&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/services.jsp (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/root/services.jsp Sat Feb 16 11:23:51 2013
@@ -43,11 +43,12 @@ if (table_style.equals("scroll")) {
"bInfo": false,
"sAjaxSource": "ducc-servlet/json-format-aaData-services",
"aaSorting": [],
+ "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0, 1 ] } ],
"fnRowCallback" : function(nRow,aData,iDisplayIndex) {
- $('td:eq(0)', nRow).css( "text-align", "right" );
- $('td:eq(5)', nRow).css( "text-align", "right" );
- $('td:eq(6)', nRow).css( "text-align", "right" );
- $('td:eq(9)', nRow).css( "text-align", "right" );
+ $('td:eq(2)', nRow).css( "text-align", "right" );
+ $('td:eq(7)', nRow).css( "text-align", "right" );
+ $('td:eq(8)', nRow).css( "text-align", "right" );
+ $('td:eq(11)', nRow).css( "text-align", "right" );
return nRow;
},
} );
@@ -98,6 +99,8 @@ if (table_style.equals("scroll")) {
<caption><b>Services Definitions List</b><br><i><small>click column heading to sort</small></i></caption>
<thead>
<tr class="ducc-header">
+ <th class="ducc-col-button"></th>
+ <th class="ducc-col-button"></th>
<th title="The service Id">Id</th>
<th title="The service name">Name</th>
<th title="The service type">Type</th>
@@ -127,6 +130,8 @@ if (table_style.equals("classic")) {
<table class="sortable">
<thead>
<tr class="ducc-head">
+ <th class="ducc-col-button"></th>
+ <th class="ducc-col-button"></th>
<th title="The service Id">Id</th>
<th title="The service name">Name</th>
<th title="The service type">Type</th>