You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2013/01/15 18:24:38 UTC
svn commit: r1433537 [2/2] - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc:
api/ api/test/ cli/ cli/ws/ cli/ws/json/
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IServiceApi.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IServiceApi.java?rev=1433537&r1=1433536&r2=1433537&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IServiceApi.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IServiceApi.java Tue Jan 15 17:24:37 2013
@@ -18,6 +18,8 @@
*/
package org.apache.uima.ducc.cli;
+import org.apache.uima.ducc.transport.event.cli.ServiceRequestProperties;
+
/**
* These are the constants supported by the 'not-using-a-props-file' form of registration in DuccServiceApi.
*
@@ -33,8 +35,46 @@ public interface IServiceApi
// description() is a short description of the option for the commons cli parser
// argname() is a name for the argument for the usage() part of cli parser
//
+
+ public enum ClasspathOrderParms
+ {
+ UserBeforeDucc {
+ public String decode() { return DuccUiConstants.classpath_order_user_before_ducc; }
+ public String description() { return "Start process with uer's classpath ahead of DUCC's"; }
+ public String argname() { return "none"; }
+ },
+ DuccBeforeUser {
+ public String decode() { return DuccUiConstants.classpath_order_ducc_before_user; }
+ public String description() { return "Start process with DUCC's classpath ahead of user's"; }
+ public String argname() { return "none"; }
+ },
+ Unknown {
+ public String decode() { return "unknown"; }
+ public String description() { return "Illegal argument"; }
+ public String argname() { return "none"; }
+ },
+ ;
+
+ public abstract String decode();
+ public abstract String description();
+ public abstract String argname();
+
+ public static ClasspathOrderParms encode(String value)
+ {
+ if ( value.equals(UserBeforeDucc.decode()) ) return UserBeforeDucc;
+ if ( value.equals(DuccBeforeUser.decode()) ) return DuccBeforeUser;
+ return Unknown;
+ }
+ };
+
public enum RegistrationOption
{
+ ClasspathOrder {
+ public String decode() { return "classpath_order"; }
+ public String description() { return "Specify user-supplied classpath before DUCC-supplied classpath, or the reverse."; }
+ public String argname() { return ClasspathOrderParms.UserBeforeDucc.decode() + " or " + ClasspathOrderParms.DuccBeforeUser.decode(); }
+ },
+
Description {
public String decode() { return "description"; }
public String description() { return "Description of the run"; }
@@ -83,30 +123,42 @@ public interface IServiceApi
public String argname() { return "scheduling-class"; }
},
- ServiceCustomPing {
- public String decode() { return "service_custom_ping"; }
- public String description() { return "Class to ping custom service, must extend AServicePing.java"; }
- public String argname() { return "classname"; }
+ ServiceRequestEndpoint {
+ public String decode() { return ServiceRequestProperties.key_service_request_endpoint; }
+ public String description() { return "Unique id for this service. Usually inferred for UIMA-AS services."; }
+ public String argname() { return "string"; }
},
- ServiceCustomEndpoint {
- public String decode() { return "service_custom_endpoint"; }
- public String description() { return "Unique id for this service, starting with CUSTOM:"; }
- public String argname() { return "string"; }
+ ServicePingClass {
+ public String decode() { return "service_ping_class"; }
+ public String description() { return "Class to ping ervice, must extend AServicePing.java"; }
+ public String argname() { return "classname"; }
},
- ServiceCustomClasspath {
- public String decode() { return "service_custom_classpath"; }
+ ServicePingClasspath {
+ public String decode() { return "service_ping_classpath"; }
public String description() { return "Classpath containing service_custom_ping class and dependencies."; }
public String argname() { return "classpath"; }
},
- ServiceCustomJvmArgs {
- public String decode() { return "service_custom_jvm_args"; }
+ ServicePingJvmArgs {
+ public String decode() { return "service_ping_jvm_args"; }
public String description() { return "-D jvm system property assignments to pass to jvm"; }
public String argname() { return "java-system-property-assignments"; }
},
+ ServicePingTimeout {
+ public String decode() { return "service_ping_timeout"; }
+ public String description() { return "Time in milliseconds to wait for a ping to the service."; }
+ public String argname() { return "time-in-ms"; }
+ },
+
+ ServicePingDoLog {
+ public String decode() { return "service_ping_do_log"; }
+ public String description() { return "If specified, log the pinger, else suppress the log."; }
+ public String argname() { return "none"; }
+ },
+
WorkingDirectory {
public String decode() { return "working_directory"; }
public String description() { return "The working directory set in each process."; }
@@ -163,19 +215,20 @@ public interface IServiceApi
public static RegistrationOption encode(String value)
{
- if ( value.equals("description") ) return Description;
- if ( value.equals("process_DD") ) return ProcessDD;
- if ( value.equals("process_memory_size") ) return ProcessMemorySize;
- if ( value.equals("process_classpath") ) return ProcessClasspath;
- if ( value.equals("process_jvm_args") ) return ProcessJvmArgs;
- if ( value.equals("process_environment") ) return ProcessEnvironment;
- if ( value.equals("process_failures_limit") ) return ProcessFailuresLimit;
- if ( value.equals("scheduling_class") ) return SchedulingClass;
- if ( value.equals("working_directory") ) return WorkingDirectory;
- if ( value.equals("log_directory") ) return LogDirectory;
- if ( value.equals("jvm") ) return Jvm;
- if ( value.equals("service_dependency") ) return ServiceDependency;
- if ( value.equals("service_linger") ) return ServiceDependency;
+ if ( value.equals(Description.decode()) ) return Description;
+ if ( value.equals(ProcessDD.decode()) ) return ProcessDD;
+ if ( value.equals(ProcessMemorySize.decode()) ) return ProcessMemorySize;
+ if ( value.equals(ProcessClasspath.decode()) ) return ProcessClasspath;
+ if ( value.equals(ProcessJvmArgs.decode()) ) return ProcessJvmArgs;
+ if ( value.equals(ProcessEnvironment.decode()) ) return ProcessEnvironment;
+ if ( value.equals(ProcessFailuresLimit.decode()) ) return ProcessFailuresLimit;
+ if ( value.equals(SchedulingClass.decode()) ) return SchedulingClass;
+ if ( value.equals(WorkingDirectory.decode()) ) return WorkingDirectory;
+ if ( value.equals(LogDirectory.decode()) ) return LogDirectory;
+ if ( value.equals(ClasspathOrder.decode()) ) return ClasspathOrder;
+ if ( value.equals(Jvm.decode()) ) return Jvm;
+ if ( value.equals(ServiceDependency.decode()) ) return ServiceDependency;
+ if ( value.equals(ServiceDependency.decode()) ) return ServiceDependency;
return Unknown;
}
@@ -209,7 +262,7 @@ public interface IServiceApi
Update {
public String decode() { return "update"; }
- public String description() { return "Update registry with start or stap."; }
+ public String description() { return "Update registry with start or stop."; }
public String argname() { return "none"; }
},
@@ -226,11 +279,11 @@ public interface IServiceApi
public static ServiceOptions encode(String value)
{
- if ( value.equals("activate") ) return Activate;
- if ( value.equals("autostart") ) return Autostart;
- if ( value.equals("instances") ) return Instances;
- if ( value.equals("monitor-port") ) return MonitorPort;
- if ( value.equals("update") ) return Update;
+ if ( value.equals(Activate.decode()) ) return Activate;
+ if ( value.equals(Autostart.decode()) ) return Autostart;
+ if ( value.equals(Instances.decode()) ) return Instances;
+ if ( value.equals(MonitorPort.decode()) ) return MonitorPort;
+ if ( value.equals(Update.decode()) ) return Update;
return Unknown;
}
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQuery.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQuery.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQuery.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQuery.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,74 @@
+package org.apache.uima.ducc.cli.ws;
+
+import java.net.InetAddress;
+
+import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
+
+public class DuccWebQuery {
+
+ protected DuccPropertiesResolver dpr = DuccPropertiesResolver.getInstance();
+
+ protected String DUCC_HOME = System.getenv().get("DUCC_HOME");
+ protected String ws_scheme = "http";
+ protected String ws_host = "localhost";
+ protected String ws_port = "42133";
+ protected String ws_servlet = null;;
+
+ protected boolean showURL = true;
+
+ protected DuccWebQuery(String servlet) {
+ assert_ducc_home();
+ determine_host();
+ determine_port();
+ ws_servlet = servlet;
+ }
+
+ protected void assert_ducc_home() {
+ if(DUCC_HOME == null) {
+ throw new RuntimeException("DUCC_HOME not specified");
+ }
+ }
+
+ protected void determine_host() {
+ try {
+ ws_host = java.net.InetAddress.getLocalHost().getHostName();
+ }
+ catch(Exception e) {
+ }
+ String host = dpr.getProperty(DuccPropertiesResolver.ducc_ws_host);
+ if(host != null) {
+ ws_host = host;
+ }
+ if(ws_host != null) {
+ if(ws_host.length() > 0) {
+ if(!ws_host.contains(".")) {
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ String canonicalHostName = addr.getCanonicalHostName();
+ if(canonicalHostName.startsWith(ws_host)) {
+ ws_host = canonicalHostName;
+ }
+ }
+ catch(Exception e) {
+
+ }
+ }
+ }
+ }
+ }
+
+ protected void determine_port() {
+ String port = dpr.getProperty(DuccPropertiesResolver.ducc_ws_port);
+ if(port != null) {
+ ws_port = port;
+ }
+ }
+
+ protected String getUrlString() {
+ String urlString = ws_scheme+"://"+ws_host+":"+ws_port+ws_servlet;
+ if(showURL) {
+ System.out.println(urlString);
+ }
+ return urlString;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQuery.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryMachines.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryMachines.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryMachines.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryMachines.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,79 @@
+package org.apache.uima.ducc.cli.ws;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.ducc.cli.ws.json.MachineFacts;
+import org.apache.uima.ducc.cli.ws.json.MachineFactsList;
+
+import com.google.gson.Gson;
+
+public class DuccWebQueryMachines extends DuccWebQuery {
+
+ private DuccWebQueryMachines() {
+ super("/ducc-servlet/json-format-machines");
+ }
+
+ private MachineFactsList get() throws Exception {
+ URL url = new URL(getUrlString());
+ URLConnection ucon = url.openConnection();
+ BufferedReader br = new BufferedReader(new InputStreamReader(ucon.getInputStream()));
+ String jSon = br.readLine();
+ Gson gson = new Gson();
+ MachineFactsList fl = gson.fromJson(jSon, MachineFactsList.class);
+ br.close();
+ return fl;
+ }
+
+ private String stringify(List<String> list) {
+ StringBuffer sb = new StringBuffer();
+ for(String item : list) {
+ if(sb.length() > 0) {
+ sb.append(",");
+ }
+ sb.append(item);
+ }
+ return "["+sb.toString()+"]";
+ }
+
+ private void display(MachineFactsList fl) {
+ if(fl != null) {
+ Iterator<MachineFacts> fIterator = fl.iterator();
+ while(fIterator.hasNext()) {
+ MachineFacts f = fIterator.next();
+ System.out.println(f.name);
+ System.out.println(" "+"status: "+f.status);
+ System.out.println(" "+"aliens: "+ stringify(f.aliens));
+ System.out.println(" "+"swap: "+ f.swap);
+ System.out.println(" "+"memory: "+ f.memory);
+ System.out.println(" "+"sharesTotal: "+ f.sharesTotal);
+ System.out.println(" "+"sharesInuse: "+ f.sharesInuse);
+ System.out.println(" "+"ip: "+ f.ip);
+ System.out.println(" "+"memory: "+ f.memory);
+ System.out.println(" "+"heartbeat: "+ f.heartbeat);
+ }
+ }
+ else {
+ System.out.println("?");
+ }
+ }
+
+ private void main_instance(String[] args) throws Exception {
+ MachineFactsList fl = get();
+ display(fl);
+ }
+
+ public static void main(String[] args) {
+ try {
+ DuccWebQueryMachines dwq = new DuccWebQueryMachines();
+ dwq.main_instance(args);
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryMachines.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryReservations.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryReservations.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryReservations.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryReservations.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,93 @@
+package org.apache.uima.ducc.cli.ws;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.ducc.cli.ws.json.NodePidList;
+import org.apache.uima.ducc.cli.ws.json.ReservationFacts;
+import org.apache.uima.ducc.cli.ws.json.ReservationFactsList;
+
+import com.google.gson.Gson;
+
+public class DuccWebQueryReservations extends DuccWebQuery {
+
+ private DuccWebQueryReservations() {
+ super("/ducc-servlet/json-format-reservations");
+ }
+
+ private ReservationFactsList get() throws Exception {
+ URL url = new URL(getUrlString());
+ URLConnection ucon = url.openConnection();
+ BufferedReader br = new BufferedReader(new InputStreamReader(ucon.getInputStream()));
+ String jSon = br.readLine();
+ Gson gson = new Gson();
+ ReservationFactsList fl = gson.fromJson(jSon, ReservationFactsList.class);
+ br.close();
+ return fl;
+ }
+
+ private String stringify(List<NodePidList> list) {
+ StringBuffer sb = new StringBuffer();
+ for(NodePidList nodePids : list) {
+ String node = nodePids.node;
+ StringBuffer pb = new StringBuffer();
+ for(String pid : nodePids.pids) {
+ if(pb.length() > 0) {
+ pb.append(",");
+ }
+ pb.append(pid);
+ }
+ String pids = pb.toString();
+ if(sb.length() > 0) {
+ sb.append(",");
+ }
+ sb.append(node+"{"+pids+"}");
+ }
+ return "["+sb.toString()+"]";
+ }
+
+ private void display(ReservationFactsList fl) {
+ if(fl != null) {
+ Iterator<ReservationFacts> fIterator = fl.iterator();
+ while(fIterator.hasNext()) {
+ ReservationFacts f = fIterator.next();
+ System.out.println(f.id);
+ System.out.println(" "+"start: "+f.start);
+ System.out.println(" "+"end: "+ f.end);
+ System.out.println(" "+"user: "+ f.user);
+ System.out.println(" "+"clas: "+ f.rclass);
+ System.out.println(" "+"state: "+ f.state);
+ System.out.println(" "+"reason: "+ f.reason);
+ System.out.println(" "+"allocation: "+ f.allocation);
+ System.out.println(" "+"processes: "+ stringify(f.userProcesses));
+ System.out.println(" "+"size: "+ f.size);
+ System.out.println(" "+"list: "+ f.list);
+ System.out.println(" "+"description: "+ f.description);
+ }
+ }
+ else {
+ System.out.println("?");
+ }
+ }
+
+ private void main_instance(String[] args) throws Exception {
+ ReservationFactsList fl = get();
+ display(fl);
+ }
+
+ // TODO: Add support for maxRecords=<n> query parameter
+
+ public static void main(String[] args) {
+ try {
+ DuccWebQueryReservations dwq = new DuccWebQueryReservations();
+ dwq.main_instance(args);
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/DuccWebQueryReservations.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFacts.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFacts.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFacts.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFacts.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.uima.ducc.cli.ws.json;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class MachineFacts implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public String status;
+ public String ip;
+ public String name;
+ public String memory;
+ public String swap;
+ public List<String> aliens;
+ public String sharesTotal;
+ public String sharesInuse;
+ public String heartbeat;
+
+ public MachineFacts(String status,
+ String ip,
+ String name,
+ String memory,
+ String swap,
+ List<String> aliens,
+ String sharesTotal,
+ String sharesInuse,
+ String heartbeat
+ )
+ {
+ this.status = status;
+ this.ip = ip;
+ this.name = name;
+ this.memory = memory;
+ this.swap = swap;
+ this.aliens = aliens;
+ this.sharesTotal = sharesTotal;
+ this.sharesInuse = sharesInuse;
+ this.heartbeat = heartbeat;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFacts.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsList.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsList.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsList.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsList.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.uima.ducc.cli.ws.json;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class MachineFactsList extends ArrayList<MachineFacts> implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsList.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsTest.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsTest.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsTest.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,155 @@
+/*
+ * 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 org.apache.uima.ducc.cli.ws.json;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import com.google.gson.Gson;
+
+public class MachineFactsTest {
+
+ private long shareSize = 15;
+
+ private Random random = new Random();
+
+ private String[] statusSet = { "defined", "down", "up" };
+ private String[] memorySet = { "", "24", "31", "39", "43", "47", "79" };
+
+ private String createStatus() {
+ int index = random.nextInt(statusSet.length);
+ String status = statusSet[index];
+ return status;
+ }
+
+ private String createIP() {
+ String ip = "";
+ int type = random.nextInt(10);
+ if(type > 2) {
+ int index = random.nextInt(256);
+ ip = "192.168.5."+index;
+ }
+ return ip;
+ }
+
+ private String createName() {
+ String name = "bluej"+random.nextInt(801);
+ return name;
+ }
+
+ private String createMemory() {
+ int index = random.nextInt(memorySet.length);
+ String memory = memorySet[index];
+ return memory;
+ }
+
+ private String createSwap() {
+ String swap = "";
+ int type = random.nextInt(10);
+ if(type > 2) {
+ int index = random.nextInt(10);
+ swap = ""+index;
+ }
+ return swap;
+ }
+
+ private List<String> createAliens() {
+ List<String> aliens = new ArrayList<String>();
+ int count = random.nextInt(10);
+ for(int i=0;i<count;i++) {
+ aliens.add(""+random.nextInt(99999));
+ }
+ return aliens;
+ }
+
+ private String createSharesTotal(String memory) {
+ String sharesTotal = "";
+ try {
+ Integer integer = new Integer(memory);
+ long shares = integer / shareSize;
+ sharesTotal = ""+shares;
+ }
+ catch(Exception e) {
+ }
+ return sharesTotal;
+ }
+
+ private String createSharesInuse(String total) {
+ String sharesInuse = "";
+ try {
+ Integer integer = new Integer(total);
+ long shares = random.nextInt(integer+1);
+ sharesInuse = ""+shares;
+ }
+ catch(Exception e) {
+ }
+ return sharesInuse;
+ }
+
+ private String createHeartbeat() {
+ String heartbeat = "";
+ int type = random.nextInt(100);
+ int beat = random.nextInt(60);
+ if(type > 5) {
+ if(type > 15) {
+ heartbeat = ""+beat;
+ }
+ else {
+ heartbeat = ""+random.nextInt(600)+60;
+ }
+ }
+ return heartbeat;
+ }
+
+ private MachineFacts createMachineFacts() {
+ String status = createStatus();
+ String ip = createIP();
+ String name = createName();
+ String memory = createMemory();
+ String swap = createSwap();
+ List<String> aliens = createAliens();
+ String sharesTotal = createSharesTotal(memory);
+ String sharesInuse = createSharesInuse(sharesTotal);
+ String heartbeat = createHeartbeat();
+ MachineFacts machineFacts = new MachineFacts(status,ip,name, memory, swap, aliens, sharesTotal, sharesInuse, heartbeat);
+ return machineFacts;
+ }
+
+ private MachineFactsList createMachineFactsList() {
+ MachineFactsList machineFactsList = new MachineFactsList();
+ for(int i=0; i<10; i++) {
+ machineFactsList.add(createMachineFacts());
+ }
+ return machineFactsList;
+ }
+
+ public static void main(String[] args) {
+ MachineFactsTest machineFactsTest = new MachineFactsTest();
+ MachineFactsList machineFactsList = machineFactsTest.createMachineFactsList();
+ Gson gson = new Gson();
+ String jSon = gson.toJson(machineFactsList);
+ System.out.println(jSon);
+ MachineFactsList reconstituted = gson.fromJson(jSon, MachineFactsList.class);
+ for(MachineFacts machine : reconstituted) {
+ System.out.println(machine.name);
+ }
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/MachineFactsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/NodePidList.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/NodePidList.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/NodePidList.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/NodePidList.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.uima.ducc.cli.ws.json;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class NodePidList implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public String node;
+ public List<String> pids;
+
+ public NodePidList(String node, List<String> pids) {
+ this.node = node;
+ this.pids = pids;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/NodePidList.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFacts.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFacts.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFacts.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFacts.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,69 @@
+/*
+ * 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 org.apache.uima.ducc.cli.ws.json;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class ReservationFacts implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public String id;
+ public String start;
+ public String end;
+ public String user;
+ public String rclass;
+ public String state;
+ public String reason;
+ public String allocation;
+ public List<NodePidList> userProcesses;
+ public String size;
+ public List<String> list;
+ public String description;
+
+ public ReservationFacts(
+ String id,
+ String start,
+ String end,
+ String user,
+ String rclass,
+ String state,
+ String reason,
+ String allocation,
+ List<NodePidList> userProcesses,
+ String size,
+ List<String> list,
+ String description
+ )
+ {
+ this.id = id;
+ this.start = start;
+ this.end = end;
+ this.user = user;
+ this.rclass = rclass;
+ this.state = state;
+ this.reason = reason;
+ this.allocation = allocation;
+ this.userProcesses = userProcesses;
+ this.size = size;
+ this.list = list;
+ this.description = description;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFacts.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsList.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsList.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsList.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsList.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.uima.ducc.cli.ws.json;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class ReservationFactsList extends ArrayList<ReservationFacts> implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsList.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsTest.java?rev=1433537&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsTest.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsTest.java Tue Jan 15 17:24:37 2013
@@ -0,0 +1,144 @@
+/*
+ * 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 org.apache.uima.ducc.cli.ws.json;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+import com.google.gson.Gson;
+
+public class ReservationFactsTest {
+
+ private Random random = new Random();
+
+ private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss EEE");
+
+ private String[] rClassSet = { "fixed", "reserve", "reserve-p7", "JobDriver" };
+ private String[] stateSet = { "Assigned", "Completed", "WaitingForResources" };
+ private String[] reasonSet = { "", "CanceledByUser", "CanceledBySystem", "ResourcesUnavailable" };
+ private String[] descriptionSet = { "", "java-remote2", "Trainer:BlueJTrain", "ducc!", "Job Driver", "DistributionalSimilaritySemanticAccessServer1", "wics" };
+
+ private String createId() {
+ return ""+random.nextInt(10000);
+ }
+
+ private String createStart() {
+ return simpleDateFormat.format(new Date());
+ }
+
+ private String createEnd() {
+ return simpleDateFormat.format(new Date());
+ }
+
+ private String createUser() {
+ return "user"+random.nextInt(10);
+ }
+
+ private String createRclass() {
+ int index = random.nextInt(rClassSet.length);
+ return rClassSet[index];
+ }
+
+ private String createState() {
+ int index = random.nextInt(stateSet.length);
+ return stateSet[index];
+ }
+
+ private String createReason() {
+ int index = random.nextInt(reasonSet.length);
+ return reasonSet[index];
+ }
+
+ private String createAllocation() {
+ return ""+random.nextInt(4);
+ }
+
+ private String createSize() {
+ return ""+(1+random.nextInt(50))+".0";
+ }
+
+ private List<NodePidList> createUserProcesses() {
+ ArrayList<NodePidList> list = new ArrayList<NodePidList>();
+ int nodeCount = random.nextInt(5);
+ for(int i=0; i<nodeCount; i++) {
+ String node = "bluej"+random.nextInt(801);
+ int pidCount = random.nextInt(10);
+ ArrayList<String> pidList = new ArrayList<String>();
+ for(int j=0; j<pidCount; j++) {
+ String pid = ""+random.nextInt(99999);
+ pidList.add(pid);
+ }
+ NodePidList npl = new NodePidList(node,pidList);
+ list.add(npl);
+ }
+ return list;
+ }
+
+ private List<String> createList() {
+ List<String> list = new ArrayList<String>();
+ return list;
+ }
+
+ private String createDescription() {
+ int index = random.nextInt(descriptionSet.length);
+ return descriptionSet[index];
+ }
+
+ private ReservationFacts createReservationFacts() {
+ String id = createId();
+ String start = createStart();
+ String end = createEnd();
+ String user = createUser();
+ String rclass = createRclass();
+ String state = createState();
+ String reason = createReason();
+ String allocation = createAllocation();
+ List<NodePidList> userProcesses = createUserProcesses();
+ String size = createSize();
+ List<String> list = createList();
+ String description = createDescription();
+
+ ReservationFacts reservationFacts = new ReservationFacts(id,start,end,user,rclass,state,reason,allocation,userProcesses,size,list,description);
+ return reservationFacts;
+ }
+
+ private ReservationFactsList createReservationFactsList() {
+ ReservationFactsList reservationFactsList = new ReservationFactsList();
+ for(int i=0; i<10; i++) {
+ reservationFactsList.add(createReservationFacts());
+ }
+ return reservationFactsList;
+ }
+
+ public static void main(String[] args) {
+ ReservationFactsTest reservationFactsTest = new ReservationFactsTest();
+ ReservationFactsList reservationFactsList = reservationFactsTest.createReservationFactsList();
+ Gson gson = new Gson();
+ String jSon = gson.toJson(reservationFactsList);
+ System.out.println(jSon);
+ ReservationFactsList reconstituted = gson.fromJson(jSon, ReservationFactsList.class);
+ for(ReservationFacts reservation : reconstituted) {
+ System.out.println(reservation.id);
+ }
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ws/json/ReservationFactsTest.java
------------------------------------------------------------------------------
svn:eol-style = native