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/02 20:55:59 UTC
svn commit: r1427983 [1/4] - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src: main/ main/java/
main/java/org/ main/java/org/apache/ main/java/org/apache/uima/
main/java/org/apache/uima/ducc/ main/java/org/apache/uima/ducc/ws/
main/java/org/apache/ui...
Author: cwiklik
Date: Wed Jan 2 19:55:58 2013
New Revision: 1427983
URL: http://svn.apache.org/viewvc?rev=1427983&view=rev
Log:
UIMA-2491
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccBoot.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccDaemonsData.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccData.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccMachinesData.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccNodes.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/IWebServer.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/JobInfo.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineInfo.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineSummaryInfo.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/ReservationInfo.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/WebServerComponent.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/config/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/config/WebServerConfiguration.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/event/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/event/WebServerEventListener.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAsUser.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccConstants.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebJobSpecificationProperties.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebProperties.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebSchedulerClasses.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebUtil.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Ip.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/NodeId.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Pid.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/UserId.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/DatedNodeMetricsUpdateDuccEvent.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/resources/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/webapp/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/resources/
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccBoot.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccBoot.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccBoot.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccBoot.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,206 @@
+/*
+ * 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.ws;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.TreeMap;
+
+import org.apache.uima.ducc.common.IDuccEnv;
+import org.apache.uima.ducc.common.config.CommonConfiguration;
+import org.apache.uima.ducc.common.internationalization.Messages;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.common.IDuccWorkJob;
+import org.apache.uima.ducc.transport.event.common.IDuccWorkReservation;
+import org.apache.uima.ducc.transport.event.common.IDuccWorkService;
+import org.apache.uima.ducc.transport.event.common.history.HistoryPersistenceManager;
+
+
+public class DuccBoot extends Thread {
+
+ private static DuccLogger logger = DuccLoggerComponents.getWsLogger(DuccBoot.class.getName());
+ private static Messages messages = Messages.getInstance();
+
+ private static DuccId jobid = null;
+
+ private static long maxJobs = 4096;
+ private static long maxReservations = 4096;
+ private static long maxServices = 4096;
+
+ public static void boot(CommonConfiguration commonConfiguration) {
+ DuccBoot duccBoot = new DuccBoot();
+ duccBoot.initialize(commonConfiguration);
+ duccBoot.start();
+ }
+
+ public void run() {
+ String location = "run";
+ try {
+ logger.info(location, jobid, "booting...");
+ restore();
+ logger.info(location, jobid, "ready.");
+ }
+ catch(Throwable t) {
+ logger.error(location, jobid, t);
+ }
+
+ }
+
+ private static long getLimit() {
+ long limit = 0;
+ try {
+ String p_limit = DuccPropertiesResolver.getInstance().getProperty(DuccPropertiesResolver.ducc_ws_max_history_entries);
+ if(p_limit != null) {
+ p_limit = p_limit.trim();
+ if(!p_limit.equals("unlimited")) {
+ limit = Long.parseLong(p_limit);
+ }
+ }
+ }
+ catch(Throwable t) {
+ t.printStackTrace();
+ }
+ // limit = 0;
+ return limit;
+ }
+
+ private static TreeMap<Integer,String> sort(ArrayList<String> list) {
+ String location = "sort";
+ TreeMap<Integer,String> map = new TreeMap<Integer,String>();
+ ListIterator<String> listIterator = list.listIterator();
+ while(listIterator.hasNext()) {
+ try {
+ String value = listIterator.next().trim();
+ int index = value.indexOf('.');
+ Integer key = Integer.parseInt(value.substring(0,index));
+ map.put(key, value);
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ }
+ return map;
+ }
+
+ private void restoreReservations(HistoryPersistenceManager hpm, DuccData duccData) {
+ String location = "restoreReservations";
+ ArrayList<String> duccWorkReservations = hpm.reservationList();
+ logger.info(location, jobid, messages.fetchLabel("Number of Reservations to restore")+duccWorkReservations.size());
+ TreeMap<Integer,String> map = sort(duccWorkReservations);
+ Iterator<Integer> iterator = map.descendingKeySet().iterator();
+ int i = 0;
+ int restored = 0;
+ while(iterator.hasNext() && (++i < maxReservations)) {
+ try {
+ Integer key = iterator.next();
+ logger.debug(location, jobid, messages.fetchLabel("restore")+key);
+ String fileName = map.get(key);
+ IDuccWorkReservation duccWorkReservation;
+ duccWorkReservation = hpm.reservationRestore(fileName);
+ if(duccWorkReservation != null) {
+ duccData.putIfNotPresent(duccWorkReservation);
+ restored++;
+ }
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ }
+ logger.info(location, jobid, messages.fetch("Reservations restored: "+restored));
+ }
+
+ private void restoreJobs(HistoryPersistenceManager hpm, DuccData duccData) {
+ String location = "restoreJobs";
+ ArrayList<String> duccWorkJobs = hpm.jobList();
+ logger.info(location, jobid, messages.fetchLabel("Number of Jobs to restore")+duccWorkJobs.size());
+ TreeMap<Integer,String> map = sort(duccWorkJobs);
+ Iterator<Integer> iterator = map.descendingKeySet().iterator();
+ int i = 0;
+ int restored = 0;
+ while(iterator.hasNext() && (++i < maxJobs)) {
+ try {
+ Integer key = iterator.next();
+ logger.debug(location, jobid, messages.fetchLabel("restore")+key);
+ String fileName = map.get(key);
+ IDuccWorkJob duccWorkJob;
+ duccWorkJob = hpm.jobRestore(fileName);
+ if(duccWorkJob != null) {
+ duccData.putIfNotPresent(duccWorkJob);
+ restored++;
+ }
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ }
+ logger.info(location, jobid, messages.fetch("Jobs restored: "+restored));
+ }
+
+ private void restoreServices(HistoryPersistenceManager hpm, DuccData duccData) {
+ String location = "restoreServices";
+ ArrayList<String> duccWorkServices = hpm.serviceList();
+ logger.info(location, jobid, messages.fetchLabel("Number of Services to restore")+duccWorkServices.size());
+ TreeMap<Integer,String> map = sort(duccWorkServices);
+ Iterator<Integer> iterator = map.descendingKeySet().iterator();
+ int i = 0;
+ int restored = 0;
+ while(iterator.hasNext() && (++i < maxServices)) {
+ try {
+ Integer key = iterator.next();
+ logger.debug(location, jobid, messages.fetchLabel("restore")+key);
+ String fileName = map.get(key);
+ IDuccWorkService duccWorkService;
+ duccWorkService = hpm.serviceRestore(fileName);
+ if(duccWorkService != null) {
+ duccData.putIfNotPresent(duccWorkService);
+ restored++;
+ }
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ }
+ logger.info(location, jobid, messages.fetch("Services restored: "+restored));
+ }
+
+ private void initialize(CommonConfiguration commonConfiguration) {
+ String location = "initialize";
+ long limit = getLimit();
+ if(limit > 0) {
+ logger.info(location, jobid, messages.fetchLabel("max history limit")+limit);
+ maxJobs = limit;
+ maxReservations = limit;
+ maxServices = limit;
+ }
+ }
+
+ private void restore() {
+ String location = "restore";
+ logger.info(location, jobid, messages.fetchLabel("History directory")+IDuccEnv.DUCC_HISTORY_DIR);
+ HistoryPersistenceManager hpm = HistoryPersistenceManager.getInstance();
+ DuccData duccData = DuccData.getInstance();
+ restoreReservations(hpm, duccData);
+ restoreJobs(hpm, duccData);
+ restoreServices(hpm, duccData);
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccBoot.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccDaemonsData.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccDaemonsData.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccDaemonsData.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccDaemonsData.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,163 @@
+/*
+ * 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.ws;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.uima.ducc.common.boot.DuccDaemonRuntimeProperties.DaemonName;
+import org.apache.uima.ducc.common.utils.TimeStamp;
+import org.apache.uima.ducc.transport.event.AbstractDuccEvent;
+import org.apache.uima.ducc.transport.event.DuccEvent.EventType;
+
+
+public class DuccDaemonsData {
+
+ private static DuccDaemonsData duccDaemonsData = new DuccDaemonsData();
+ private static ConcurrentHashMap<DaemonName,String> mapCurr = new ConcurrentHashMap<DaemonName,String>();
+ private static ConcurrentHashMap<DaemonName,String> mapPrev = new ConcurrentHashMap<DaemonName,String>();
+ private static ConcurrentHashMap<DaemonName,String> mapMax = new ConcurrentHashMap<DaemonName,String>();
+ private static ConcurrentHashMap<DaemonName,String> mapMaxTOD = new ConcurrentHashMap<DaemonName,String>();
+ private static ConcurrentHashMap<DaemonName,Long> eventSize = new ConcurrentHashMap<DaemonName,Long>();
+ private static ConcurrentHashMap<DaemonName,Long> eventSizeMax = new ConcurrentHashMap<DaemonName,Long>();
+ private static ConcurrentHashMap<DaemonName,String> eventSizeMaxTOD = new ConcurrentHashMap<DaemonName,String>();
+
+ public static DuccDaemonsData getInstance() {
+ return duccDaemonsData;
+ }
+
+ public void put(AbstractDuccEvent duccEvent) {
+ EventType eventType = duccEvent.getEventType();
+ DaemonName key;
+ switch(eventType) {
+ case ORCHESTRATOR_STATE:
+ key = DaemonName.Orchestrator;
+ putHeartbeat(key);
+ putEventSize(key, duccEvent);
+ break;
+ case PM_STATE:
+ key = DaemonName.ProcessManager;
+ putHeartbeat(key);
+ putEventSize(key, duccEvent);
+ break;
+ case RM_STATE:
+ key = DaemonName.ResourceManager;
+ putHeartbeat(key);
+ putEventSize(key, duccEvent);
+ break;
+ case SM_STATE:
+ key = DaemonName.ServiceManager;
+ putHeartbeat(key);
+ putEventSize(key, duccEvent);
+ break;
+ }
+ }
+
+ public void putEventSize(DaemonName key, AbstractDuccEvent duccEvent) {
+ Long size = duccEvent.getEventSize();
+ eventSize.put(key, size);
+ Long prev;
+ if(eventSizeMax.containsKey(key)) {
+ prev = eventSizeMax.get(key);
+ }
+ else {
+ prev = new Long(0);
+ }
+ if(size > prev) {
+ eventSizeMax.put(key, size);
+ String timestamp = TimeStamp.getCurrentMillis();
+ eventSizeMaxTOD.put(key, timestamp);
+ }
+ }
+
+ public Long getEventSize(DaemonName key) {
+ Long retVal = new Long(0);
+ if(eventSize.containsKey(key)) {
+ retVal = eventSize.get(key);
+ }
+ return retVal;
+ }
+
+ public Long getEventSizeMax(DaemonName key) {
+ Long retVal = new Long(0);
+ if(eventSizeMax.containsKey(key)) {
+ retVal = eventSizeMax.get(key);
+ }
+ return retVal;
+ }
+
+ public String getEventSizeMaxTOD(DaemonName key) {
+ String retVal = "";
+ if(mapMaxTOD.containsKey(key)) {
+ retVal = eventSizeMaxTOD.get(key);
+ }
+ return retVal;
+ }
+
+ public void putHeartbeat(DaemonName key) {
+ String timestamp = TimeStamp.getCurrentMillis();
+ if(mapPrev.containsKey(key)) {
+ String t0 = mapPrev.get(key);
+ String t1 = timestamp;
+ long millis = TimeStamp.diffMillis(t1, t0);
+ if(mapMax.containsKey(key)) {
+ long max = Long.parseLong(mapMax.get(key));
+ if(millis > max) {
+ mapMax.put(key, ""+millis);
+ mapMaxTOD.put(key, t1);
+ }
+ }
+ else {
+ mapMax.put(key, ""+millis);
+ mapMaxTOD.put(key, t1);
+ }
+ }
+ if(mapCurr.containsKey(key)) {
+ mapPrev.put(key, mapCurr.get(key));
+ }
+ mapCurr.put(key, timestamp);
+ }
+
+ public String getHeartbeat(DaemonName key) {
+ String retVal = "";
+ if(mapCurr.containsKey(key)) {
+ String t1 = TimeStamp.getCurrentMillis();
+ String t0 = mapCurr.get(key);
+ long millis = TimeStamp.diffMillis(t1, t0);
+ retVal = ""+millis/1000;
+ }
+ return retVal;
+ }
+
+ public String getMaxHeartbeat(DaemonName key) {
+ String retVal = "";
+ if(mapMax.containsKey(key)) {
+ long max = Long.parseLong(mapMax.get(key));
+ retVal = ""+(max/1000);
+ }
+ return retVal;
+ }
+
+ public String getMaxHeartbeatTOD(DaemonName key) {
+ String retVal = "";
+ if(mapMaxTOD.containsKey(key)) {
+ retVal = mapMaxTOD.get(key);
+ }
+ return retVal;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccDaemonsData.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccData.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccData.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccData.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccData.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,184 @@
+/*
+ * 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.ws;
+
+import java.util.Iterator;
+import java.util.concurrent.ConcurrentSkipListMap;
+
+import org.apache.uima.ducc.common.utils.TimeStamp;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.common.DuccWorkJob;
+import org.apache.uima.ducc.transport.event.common.DuccWorkMap;
+import org.apache.uima.ducc.transport.event.common.DuccWorkReservation;
+import org.apache.uima.ducc.transport.event.common.IDuccWork;
+import org.apache.uima.ducc.transport.event.common.history.HistoryPersistenceManager;
+import org.apache.uima.ducc.transport.event.common.history.IHistoryPersistenceManager;
+
+
+public class DuccData {
+
+ private static DuccWorkMap duccWorkMap = new DuccWorkMap();
+ private static DuccWorkMap duccWorkLive = new DuccWorkMap();
+
+ private static ConcurrentSkipListMap<JobInfo,JobInfo> sortedJobs = new ConcurrentSkipListMap<JobInfo,JobInfo>();
+ private static ConcurrentSkipListMap<ReservationInfo,ReservationInfo> sortedReservations = new ConcurrentSkipListMap<ReservationInfo,ReservationInfo>();
+ private static ConcurrentSkipListMap<JobInfo,JobInfo> sortedServices = new ConcurrentSkipListMap<JobInfo,JobInfo>();
+
+ private static ConcurrentSkipListMap<DuccId,Object> keyMap = new ConcurrentSkipListMap<DuccId,Object>();
+
+ private static DuccData duccData = new DuccData();
+
+ public static DuccData getInstance() {
+ return duccData;
+ }
+
+ private volatile String published = null;
+
+ private IHistoryPersistenceManager hpm = HistoryPersistenceManager.getInstance();
+
+ public boolean isPublished() {
+ return published != null;
+ }
+
+ public void setPublished() {
+ published = TimeStamp.getCurrentMillis();
+ }
+
+ public String getPublished() {
+ return published;
+ }
+
+ public void putIfNotPresent(IDuccWork duccWork) {
+ synchronized(this) {
+ DuccId duccId = duccWork.getDuccId();
+ if(duccWorkMap.findDuccWork(duccId) == null) {
+ duccWorkMap.addDuccWork(duccWork);
+ updateSortedMaps(duccWork);
+ }
+ }
+ }
+
+ private void mergeHistory(DuccWorkMap map) {
+ Iterator<DuccId> iterator = duccWorkLive.keySet().iterator();
+ while(iterator.hasNext()) {
+ DuccId duccId = iterator.next();
+ IDuccWork duccWork = duccWorkLive.findDuccWork(duccId);
+ IDuccWork history = null;
+ switch(duccWork.getDuccType()) {
+ case Job:
+ history = hpm.jobRestore(duccId);
+ break;
+ case Reservation:
+ history = hpm.reservationRestore(duccId);
+ break;
+ case Service:
+ history = hpm.serviceRestore(duccId);
+ break;
+ }
+ if(history != null) {
+ map.put(duccId, history);
+ }
+ }
+ }
+
+ public void put(DuccWorkMap map) {
+ synchronized(this) {
+ DuccWorkMap mapCopy = map.deepCopy();
+ mergeHistory(map);
+ duccWorkLive = mapCopy;
+ Iterator<DuccId> iterator = map.keySet().iterator();
+ while(iterator.hasNext()) {
+ DuccId duccId = iterator.next();
+ IDuccWork duccWork = map.findDuccWork(duccId);
+ duccWorkMap.addDuccWork(duccWork);
+ updateSortedMaps(duccWork);
+ }
+ }
+ setPublished();
+ }
+
+ public DuccWorkMap get() {
+ return duccWorkMap;
+ }
+
+ public DuccWorkMap getLive() {
+ return duccWorkLive;
+ }
+
+ private void cacheManager(IDuccWork duccWork, Object cacheKey) {
+ DuccId duccId = duccWork.getDuccId();
+ if(keyMap.containsKey(duccId)) {
+ switch(duccWork.getDuccType()) {
+ case Job:
+ sortedJobs.remove(keyMap.get(duccId));
+ break;
+ case Reservation:
+ sortedReservations.remove(keyMap.get(duccId));
+ break;
+ case Service:
+ sortedServices.remove(keyMap.get(duccId));
+ break;
+ }
+ keyMap.remove(duccId);
+ }
+ if(!duccWork.isCompleted()) {
+ keyMap.put(duccId, cacheKey);
+ }
+ }
+
+ private void updateSortedMaps(IDuccWork duccWork) {
+ switch(duccWork.getDuccType()) {
+ case Job:
+ DuccWorkJob job = (DuccWorkJob)duccWork;
+ JobInfo jobInfo = new JobInfo(job);
+ cacheManager(job, jobInfo);
+ sortedJobs.put(jobInfo, jobInfo);
+ break;
+ case Reservation:
+ DuccWorkReservation reservation = (DuccWorkReservation)duccWork;
+ ReservationInfo reservationInfo = new ReservationInfo(reservation);
+ cacheManager(reservation, reservationInfo);
+ sortedReservations.put(reservationInfo, reservationInfo);
+ break;
+ case Service:
+ DuccWorkJob service = (DuccWorkJob)duccWork;
+ JobInfo serviceInfo = new JobInfo(service);
+ cacheManager(service, serviceInfo);
+ sortedServices.put(serviceInfo, serviceInfo);
+ break;
+ }
+ }
+
+ public ConcurrentSkipListMap<JobInfo,JobInfo> getSortedJobs() {
+ return sortedJobs;
+ }
+
+ public ConcurrentSkipListMap<ReservationInfo,ReservationInfo> getSortedReservations() {
+ return sortedReservations;
+ }
+
+ public ConcurrentSkipListMap<JobInfo,JobInfo> getSortedServices() {
+ return sortedServices;
+ }
+
+ public boolean isLive(DuccId duccId) {
+ return duccWorkLive.containsKey(duccId);
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccData.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccMachinesData.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccMachinesData.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccMachinesData.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccMachinesData.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,433 @@
+/*
+ * 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.ws;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.uima.ducc.common.IDuccEnv;
+import org.apache.uima.ducc.common.NodeIdentity;
+import org.apache.uima.ducc.common.node.metrics.NodeUsersInfo;
+import org.apache.uima.ducc.common.node.metrics.NodeUsersInfo.NodeProcess;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.TimeStamp;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.NodeMetricsUpdateDuccEvent;
+import org.apache.uima.ducc.transport.event.ProcessInfo;
+import org.apache.uima.ducc.transport.event.common.DuccWorkMap;
+import org.apache.uima.ducc.transport.event.common.IDuccProcess;
+import org.apache.uima.ducc.transport.event.common.IDuccProcessMap;
+import org.apache.uima.ducc.transport.event.common.IDuccReservation;
+import org.apache.uima.ducc.transport.event.common.IDuccReservationMap;
+import org.apache.uima.ducc.transport.event.common.IDuccWorkJob;
+import org.apache.uima.ducc.transport.event.common.IDuccWorkReservation;
+import org.apache.uima.ducc.transport.event.common.IProcessState.ProcessState;
+import org.apache.uima.ducc.ws.server.DuccConstants;
+import org.apache.uima.ducc.ws.server.DuccWebProperties;
+import org.apache.uima.ducc.ws.types.Ip;
+import org.apache.uima.ducc.ws.types.NodeId;
+import org.apache.uima.ducc.ws.types.UserId;
+import org.apache.uima.ducc.ws.utils.DatedNodeMetricsUpdateDuccEvent;
+
+
+public class DuccMachinesData {
+
+ private static DuccLogger logger = DuccLoggerComponents.getWsLogger(DuccMachinesData.class.getName());
+ private static DuccId jobid = null;
+
+ private static ConcurrentSkipListMap<String,MachineInfo> unsortedMachines = new ConcurrentSkipListMap<String,MachineInfo>();
+ private static ConcurrentSkipListMap<String,MachineSummaryInfo> summaryMachines = new ConcurrentSkipListMap<String,MachineSummaryInfo>();
+
+ private static AtomicLong memoryTotal = new AtomicLong(0);
+ private static AtomicLong memorySwapped = new AtomicLong(0);
+ private static AtomicLong sharesTotal = new AtomicLong(0);
+ private static AtomicLong sharesInuse = new AtomicLong(0);
+
+ private int shareSize = DuccConstants.defaultShareSize;
+
+ private String domain = "";
+
+ private static DuccMachinesData duccMachinesData = new DuccMachinesData();
+
+ private static ConcurrentSkipListMap<String,String> ipToNameMap = new ConcurrentSkipListMap<String,String>();
+ private static ConcurrentSkipListMap<String,String> nameToIpMap = new ConcurrentSkipListMap<String,String>();
+ private static ConcurrentSkipListMap<String,String> isSwapping = new ConcurrentSkipListMap<String,String>();
+
+ private static ConcurrentSkipListMap<String,TreeMap<String,NodeUsersInfo>> ipToNodeUsersInfoMap = new ConcurrentSkipListMap<String,TreeMap<String,NodeUsersInfo>>();
+
+ public static DuccMachinesData getInstance() {
+ return duccMachinesData;
+ }
+
+ public boolean isMachineSwapping(String ip) {
+ return isSwapping.containsKey(ip);
+ }
+
+ public ConcurrentSkipListMap<MachineInfo,String> getSortedMachines() {
+ ConcurrentSkipListMap<MachineInfo,String> sortedMachines = new ConcurrentSkipListMap<MachineInfo,String>();
+ Iterator<Entry<String, MachineInfo>> iterator = unsortedMachines.entrySet().iterator();
+ while(iterator.hasNext()) {
+ Entry<String, MachineInfo> next = iterator.next();
+ MachineInfo machineInfo = next.getValue();
+ String name = next.getKey();
+ sortedMachines.put(machineInfo, name);
+ }
+ return sortedMachines;
+ }
+
+ private volatile String published = null;
+
+ private DuccMachinesData() {
+ initialize();
+ }
+
+ private void initialize() {
+ String location = "initialize";
+ try {
+ String fileName = IDuccEnv.DUCC_NODES_FILE_NAME;
+ String dirResources = IDuccEnv.DUCC_RESOURCES_DIR;
+ ArrayList<String> nodes = DuccNodes.getInstance().get(dirResources,fileName);
+ Iterator<String> iterator = nodes.iterator();
+ while(iterator.hasNext()) {
+ String nodeName = (String) iterator.next();
+ MachineInfo machineInfo = new MachineInfo(IDuccEnv.DUCC_NODES_FILE_PATH, "", nodeName, "", "", null, "", "", -1);
+ unsortedMachines.put(machineInfo.getName(),machineInfo);
+ }
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ Properties properties = DuccWebProperties.get();
+ String key_share_size = "ducc.rm.default.memory";
+ if(properties.containsKey(key_share_size)) {
+ try {
+ shareSize = Integer.parseInt(properties.getProperty(key_share_size).trim());
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ }
+ try {
+ InetAddress ia = InetAddress.getLocalHost();
+ String chn = ia.getCanonicalHostName();
+ int index = chn.indexOf(".");
+ if(index > 0) {
+ domain = chn.substring(index);
+ }
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ }
+
+ public boolean isPublished() {
+ return published != null;
+ }
+
+ public void setPublished() {
+ published = TimeStamp.getCurrentMillis();
+ }
+
+ public MachineSummaryInfo getTotals() {
+ MachineSummaryInfo totals = new MachineSummaryInfo();
+ totals.memoryTotal = memoryTotal.get();
+ totals.memorySwapped = memorySwapped.get();
+ totals.sharesTotal = sharesTotal.get();
+ totals.sharesInuse = sharesInuse.get();
+ return totals;
+ }
+
+ private void updateTotals(Ip ip, MachineSummaryInfo newInfo) {
+ if(summaryMachines.containsKey(ip.toString())) {
+ MachineSummaryInfo oldInfo = summaryMachines.get(ip.toString());
+ summaryMachines.put(ip.toString(), newInfo);
+ memoryTotal.addAndGet(newInfo.memoryTotal-oldInfo.memoryTotal);
+ memorySwapped.addAndGet(newInfo.memorySwapped-oldInfo.memorySwapped);
+ sharesTotal.addAndGet(newInfo.sharesTotal-oldInfo.sharesTotal);
+ sharesInuse.addAndGet(newInfo.sharesInuse-oldInfo.sharesInuse);
+ }
+ else {
+ summaryMachines.put(ip.toString(), newInfo);
+ memoryTotal.addAndGet(newInfo.memoryTotal);
+ memorySwapped.addAndGet(newInfo.memorySwapped);
+ sharesTotal.addAndGet(newInfo.sharesTotal);
+ sharesInuse.addAndGet(newInfo.sharesInuse);
+ }
+ }
+
+ private String normalizeMachineName(String machineName) {
+ String retVal = machineName;
+ try {
+ if(!unsortedMachines.containsKey(machineName)) {
+ if(machineName.contains(".")) {
+ int index = machineName.indexOf(".");
+ String domainlessMachineName = machineName.substring(0,index);
+ if(unsortedMachines.containsKey(domainlessMachineName)) {
+ retVal = domainlessMachineName;
+ }
+ }
+ else {
+ String domainfullMachineName = machineName+domain;
+ if(unsortedMachines.containsKey(domainfullMachineName)) {
+ retVal = domainfullMachineName;
+ }
+ }
+ }
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ public void put(DatedNodeMetricsUpdateDuccEvent duccEvent) {
+ String location = "put";
+ MachineSummaryInfo msi = new MachineSummaryInfo();
+ NodeMetricsUpdateDuccEvent nodeMetrics = duccEvent.getNodeMetricsUpdateDuccEvent();
+ Ip ip = new Ip(nodeMetrics.getNodeIdentity().getIp().trim());
+ TreeMap<String, NodeUsersInfo> map = nodeMetrics.getNodeUsersMap();
+ if(map != null) {
+ ipToNodeUsersInfoMap.put(ip.toString(), map);
+ }
+ String machineName = nodeMetrics.getNodeIdentity().getName().trim();
+ ipToNameMap.put(ip.toString(),machineName);
+ nameToIpMap.put(machineName,ip.toString());
+ double dval = nodeMetrics.getNodeMemory().getMemTotal();
+ long lval = (long) (dval/(1024*1024)+0.5);
+ msi.memoryTotal = lval;
+ msi.sharesTotal = lval/shareSize;
+ String memTotal = ""+lval/*+memUnits*/;
+ String sharesTotal = ""+lval/shareSize;
+ // swap: in-use
+ double dvalT = nodeMetrics.getNodeMemory().getSwapTotal();
+ long lvalT = (long) (dvalT/(1024*1024)+0.5);
+ double dvalF= nodeMetrics.getNodeMemory().getSwapFree();
+ long lvalF = (long) (dvalF/(1024*1024)+0.5);
+ lval = lvalT - lvalF;
+ String memSwap = ""+lval/*+memUnits*/;
+ msi.memorySwapped = lval;
+ String swapKey = ip.toString();
+ String swapVal = ip.toString();
+ if(msi.memorySwapped > 0) {
+ isSwapping.put(swapKey, swapVal);
+ }
+ else {
+ isSwapping.remove(swapKey);
+ }
+ String sharesInuse = "0";
+ Properties shareMap = getShareMap(shareSize);
+ try {
+ if(shareMap.containsKey(ip.toString())) {
+ msi.sharesInuse += (Integer)shareMap.get(ip.toString());
+ sharesInuse = ""+msi.sharesInuse;
+ }
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ List<ProcessInfo> alienPids = nodeMetrics.getRogueProcessInfoList();
+ MachineInfo machineInfo = new MachineInfo("", ip.toString(), machineName, memTotal, memSwap, alienPids, sharesTotal, sharesInuse, duccEvent.getMillis());
+ unsortedMachines.put(normalizeMachineName(machineName),machineInfo);
+ updateTotals(ip,msi);
+ setPublished();
+ }
+
+ public List<String> getPids(Ip ip, UserId user) {
+ String location = "getPids";
+ List<String> retVal = new ArrayList<String>();
+ if(ip == null) {
+ }
+ else if(ip.toString() == null) {
+ }
+ else if(user == null) {
+ }
+ else if(user.toString() == null) {
+ }
+ else {
+ try {
+ TreeMap<String, NodeUsersInfo> map = ipToNodeUsersInfoMap.get(ip.toString());
+ if(map != null) {
+ NodeUsersInfo nodeUsersInfo = map.get(user.toString());
+ if(nodeUsersInfo != null) {
+ for( NodeProcess process : nodeUsersInfo.getReserveProcesses() ) {
+ retVal.add(process.getPid());
+ }
+// retVal = nodeUsersInfo.getPids();
+ }
+ }
+ }
+ catch(Exception e) {
+ logger.error(location, jobid, e);
+ }
+ }
+ return retVal;
+ }
+
+ public List<String> getPids(NodeId nodeId, UserId user) {
+ Ip ip = new Ip(getIpForName(nodeId.toString()));
+ return getPids(ip, user);
+ }
+
+ public int getPidCount(Ip ip, UserId user) {
+ int retVal = 0;
+ try {
+ List<String> pidList = getPids(ip, user);
+ if(pidList != null) {
+ return pidList.size();
+ }
+ }
+ catch(Exception e) {
+ retVal = -1;
+ }
+ return retVal;
+ }
+
+ public int getPidCount(NodeId nodeId, UserId user) {
+ Ip ip = new Ip(getIpForName(nodeId.toString()));
+ return getPidCount(ip, user);
+ }
+
+ public String getNameForIp(String ip) {
+ String retVal = null;
+ try {
+ retVal = ipToNameMap.get(ip);
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ public String getIpForName(String name) {
+ String retVal = null;
+ try {
+ retVal = nameToIpMap.get(name);
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ private int toInt(String s, int deflt)
+ {
+ int retVal;
+ try {
+ retVal = Integer.parseInt(s);
+ }
+ catch(Throwable t) {
+ retVal = deflt;
+ }
+ return retVal;
+ }
+
+ private Properties getShareMapJobs(Properties properties, int shareSize) {
+ String location = "getShareMapJobs";
+ try {
+ DuccData duccData = DuccData.getInstance();
+ DuccWorkMap duccWorkMap = duccData.getLive();
+ Iterator<DuccId> iteratorJ = duccWorkMap.getJobKeySet().iterator();
+ while(iteratorJ.hasNext()) {
+ DuccId jobid = iteratorJ.next();
+ IDuccWorkJob job = (IDuccWorkJob)duccWorkMap.findDuccWork(jobid);
+ if(job.isOperational()) {
+ int pMemSize = toInt(job.getSchedulingInfo().getShareMemorySize(),1*shareSize);
+ long pShareSize = pMemSize/shareSize;
+ if(pShareSize <= 0) {
+ pShareSize = 1;
+ }
+ IDuccProcessMap processMap = job.getProcessMap();
+ Iterator<DuccId> iteratorP = processMap.keySet().iterator();
+ while(iteratorP.hasNext()) {
+ DuccId jpid = iteratorP.next();
+ IDuccProcess jp = processMap.get(jpid);
+ ProcessState processState = jp.getProcessState();
+ switch(processState) {
+ case Starting:
+ case Initializing:
+ case Running:
+ NodeIdentity nodeIdentity = jp.getNodeIdentity();
+ String key = nodeIdentity.getIp().trim();
+ Integer value = new Integer(0);
+ if(!properties.containsKey(key)) {
+ properties.put(key, value);
+ }
+ value = (Integer)properties.get(key) + (int)pShareSize;
+ properties.put(key,value);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ return properties;
+ }
+
+ private Properties getShareMapReservations(Properties properties, int shareSize) {
+ String location = "getShareMapReservations";
+ try {
+ DuccData duccData = DuccData.getInstance();
+ DuccWorkMap duccWorkMap = duccData.getLive();
+ Iterator<DuccId> iteratorR = duccWorkMap.getReservationKeySet().iterator();
+ while(iteratorR.hasNext()) {
+ DuccId reservationId = iteratorR.next();
+ IDuccWorkReservation reservation = (IDuccWorkReservation)duccWorkMap.findDuccWork(reservationId);
+ if(reservation.isOperational()) {
+ IDuccReservationMap reservationMap = reservation.getReservationMap();
+ Iterator<DuccId> iteratorS = reservationMap.keySet().iterator();
+ while(iteratorS.hasNext()) {
+ DuccId spid = iteratorS.next();
+ IDuccReservation rs = reservationMap.get(spid);
+ NodeIdentity nodeIdentity = rs.getNodeIdentity();
+ String key = nodeIdentity.getIp().trim();
+ Integer value = new Integer(0);
+ if(!properties.containsKey(key)) {
+ properties.put(key, value);
+ }
+ int shares = rs.getShares();
+ value = (Integer)properties.get(key) + shares;
+ properties.put(key,value);
+ }
+ }
+ }
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ return properties;
+ }
+
+ private Properties getShareMap(int shareSize) {
+ Properties properties = new Properties();
+ properties = getShareMapJobs(properties, shareSize);
+ properties = getShareMapReservations(properties, shareSize);
+ return properties;
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccMachinesData.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccNodes.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccNodes.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccNodes.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccNodes.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,184 @@
+/*
+ * 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.ws;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.uima.ducc.common.IDuccEnv;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+
+
+public class DuccNodes {
+
+ private static DuccLogger logger = DuccLoggerComponents.getWsLogger(DuccNodes.class.getName());
+ private static DuccId jobid = null;
+
+ private static DuccNodes duccNodes = new DuccNodes();
+
+ private boolean sysout = false;
+
+ public static DuccNodes getInstance() {
+ return duccNodes;
+ }
+
+ public static DuccNodes getSysOutInstance() {
+ DuccNodes retVal = new DuccNodes();
+ retVal.sysout = true;
+ return retVal;
+ }
+
+ private class NodeSet {
+ public ArrayList<String> nodes = new ArrayList<String>();
+ public ArrayList<String> imports = new ArrayList<String>();
+ }
+
+ private void warn(String location, DuccId jobid, String text) {
+ if(sysout) {
+ System.out.println(location+" "+text);
+ }
+ else {
+ logger.warn(location, jobid, text);
+ }
+ }
+
+ private void trace(String location, DuccId jobid, String text) {
+ if(sysout) {
+ System.out.println(location+" "+text);
+ }
+ else {
+ logger.trace(location, jobid, text);
+ }
+ }
+
+ private void ignore(String fileName, String reason) {
+ String location = "ignore";
+ String text = "file:"+fileName+" "+"reason:"+reason;
+ warn(location, jobid, text);
+ }
+
+ private void ignore(String fileName, int lineno, String line, String reason) {
+ String location = "ignore";
+ String text = "file:"+fileName+" "+"#"+lineno+" "+line+" "+"reason:"+reason;
+ warn(location, jobid, text);
+ }
+
+ private void duplicate(String fileName, int lineno, String line) {
+ String location = "duplicate";
+ String text = "file:"+fileName+" "+"#"+lineno+" "+line;
+ trace(location, jobid, text);
+ }
+
+ private NodeSet get(String dirResources, String fileName, NodeSet nodeSet) {
+ String filePath = fileName;
+ if(!fileName.startsWith(File.separator)) {
+ filePath = dirResources+fileName;
+ }
+ try {
+ BufferedReader in = new BufferedReader(new FileReader(filePath));
+ String line;
+ int lineno = 0;
+ while ((line = in.readLine()) != null) {
+ lineno++;
+ line = line.trim();
+ if(line.length() == 0) {
+ }
+ else if(line.startsWith("#")) {
+ }
+ else {
+ String[] nvp = line.split(" ");
+ if(nvp.length == 1) {
+ String value = nvp[0].trim();
+ if(value.equals("import")) {
+ ignore(filePath, lineno, line, "import file missing");
+ }
+ else {
+ if(nodeSet.nodes.contains(value)) {
+ duplicate(filePath, lineno, line);
+ }
+ else {
+ nodeSet.nodes.add(value);
+ }
+ }
+ }
+ else if(nvp.length == 2) {
+ String key = nvp[0].trim();
+ String value = nvp[1].trim();
+ if(key.equals("import")) {
+ if(!value.startsWith(File.separator)) {
+ value = dirResources+value;
+ }
+ if(nodeSet.imports.contains(value)) {
+ duplicate(filePath, lineno, line);
+ }
+ else {
+ get(dirResources, value, nodeSet);
+ }
+ }
+ else {
+ ignore(filePath, lineno, line, "expected import");
+ }
+ }
+ // sim node
+ else if(nvp.length == 3) {
+ String value = nvp[1].trim()+"-"+nvp[0].trim();
+ if(nodeSet.nodes.contains(value)) {
+ duplicate(filePath, lineno, line);
+ }
+ else {
+ nodeSet.nodes.add(value);
+ }
+ }
+ else {
+ ignore(filePath, lineno, line, "too many items on line");
+ }
+ }
+ }
+ in.close();
+ }
+ catch (IOException e) {
+ ignore(filePath, "file not found");
+ }
+ return nodeSet;
+ }
+
+ public ArrayList<String> get(String resourcesDir, String fileName) {
+ NodeSet nodeSet = new NodeSet();
+ get(resourcesDir, fileName, nodeSet);
+ return nodeSet.nodes;
+ }
+
+ public static void main(String[] args) {
+ String fileName = IDuccEnv.DUCC_NODES_FILE_NAME;
+ String dirResources = IDuccEnv.DUCC_RESOURCES_DIR;
+ ArrayList<String> nodes = DuccNodes.getSysOutInstance().get(dirResources,fileName);
+ Iterator<String> iterator = nodes.iterator();
+ while(iterator.hasNext()) {
+ String value = iterator.next();
+ System.out.println(value);
+ }
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccNodes.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/IWebServer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/IWebServer.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/IWebServer.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/IWebServer.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.ws;
+
+import org.apache.uima.ducc.transport.event.NodeMetricsUpdateDuccEvent;
+import org.apache.uima.ducc.transport.event.OrchestratorStateDuccEvent;
+import org.apache.uima.ducc.transport.event.PmStateDuccEvent;
+import org.apache.uima.ducc.transport.event.RmStateDuccEvent;
+import org.apache.uima.ducc.transport.event.SmStateDuccEvent;
+
+public interface IWebServer {
+ public void update(OrchestratorStateDuccEvent duccEvent);
+ public void update(NodeMetricsUpdateDuccEvent duccEvent);
+ public void update(RmStateDuccEvent duccEvent);
+ public void update(SmStateDuccEvent duccEvent);
+ public void update(PmStateDuccEvent duccEvent);
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/IWebServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/JobInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/JobInfo.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/JobInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/JobInfo.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,86 @@
+/*
+ * 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.ws;
+
+import org.apache.uima.ducc.transport.event.common.DuccWorkJob;
+
+public class JobInfo implements Comparable<JobInfo> {
+
+ private DuccWorkJob _job;
+
+ public JobInfo(DuccWorkJob job) {
+ _job = job;
+ }
+
+ public DuccWorkJob getJob() {
+ return _job;
+ }
+
+ public boolean isOperational() {
+ return _job.isOperational();
+ }
+
+ public int compareTo(JobInfo job) {
+ int retVal = 0;
+ JobInfo j1 = this;
+ JobInfo j2 = job;
+ long f1 = j1.getJob().getDuccId().getFriendly();
+ long f2 = j2.getJob().getDuccId().getFriendly();
+ if(f1 != f2) {
+ if(!j1.isOperational() && j2.isOperational()) {
+ retVal = 1;
+ }
+ else if(j1.isOperational() && !j2.isOperational()) {
+ retVal = -1;
+ }
+ else if(f1 > f2) {
+ retVal = -1;
+ }
+ else if(f1 < f2) {
+ retVal = 1;
+ }
+ }
+ return retVal;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ boolean retVal = false;
+ try {
+ JobInfo i1 = this;
+ JobInfo i2 = (JobInfo)object;
+ DuccWorkJob j1 = i1.getJob();
+ DuccWorkJob j2 = i2.getJob();
+ String s1 = j1.getDuccId().toString();
+ String s2 = j2.getDuccId().toString();
+ retVal = s1.equals(s2);
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ @Override
+ public int hashCode() {
+ JobInfo i1 = this;
+ DuccWorkJob j1 = i1.getJob();
+ String s1 = j1.getDuccId().toString();
+ return s1.hashCode();
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/JobInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineInfo.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineInfo.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,332 @@
+/*
+ * 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.ws;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.ProcessInfo;
+import org.apache.uima.ducc.ws.server.DuccWebProperties;
+
+
+public class MachineInfo implements Comparable<MachineInfo> {
+
+ private static DuccLogger logger = DuccLoggerComponents.getWsLogger(MachineInfo.class.getName());
+ private static DuccId jobid = null;
+
+ private static final int SECONDS_PER_MILLI = 1000;
+ private static final int DOWN_AFTER_SECONDS = 65;
+
+ private String fileDef;
+ private String ip;
+ private String name;
+ private String memTotal;
+ private String memSwap;
+ private List<ProcessInfo> alienPids;
+ private String sharesTotal;
+ private String sharesInuse;
+ private long heartbeat;
+
+ public MachineInfo(String fileDef, String ip, String name, String memTotal, String memSwap, List<ProcessInfo> alienPids, String sharesTotal, String sharesInuse, long heartbeat) {
+ this.fileDef = fileDef;
+ this.ip = ip;
+ this.name = name;
+ this.memTotal = memTotal;
+ this.memSwap = memSwap;
+ this.alienPids = alienPids;
+ this.sharesTotal = sharesTotal;
+ this.sharesInuse = sharesInuse;
+ this.heartbeat = heartbeat;
+ }
+
+ private long getAgentMillisMIA() {
+ String location = "getAgentMillisMIA";
+ long secondsMIA = DOWN_AFTER_SECONDS*SECONDS_PER_MILLI;
+ Properties properties = DuccWebProperties.get();
+ String s_tolerance = properties.getProperty("ducc.rm.node.stability");
+ String s_rate = properties.getProperty("ducc.agent.node.metrics.publish.rate");
+ try {
+ long tolerance = Long.parseLong(s_tolerance.trim());
+ long rate = Long.parseLong(s_rate.trim());
+ secondsMIA = (tolerance * rate) / 1000;
+ }
+ catch(Throwable t) {
+ logger.warn(location, jobid, t);
+ }
+ return secondsMIA;
+ }
+
+ private String calculateStatus() {
+ String status = "";
+ if(getElapsedMillis() < 0) {
+ status = "defined";
+ }
+ else if(isExpired(getAgentMillisMIA())) {
+ status = "down";
+ }
+ else {
+ status = "up";
+ }
+ return status;
+ }
+
+ public String getStatus() {
+ return calculateStatus();
+ }
+
+ public String getFileDef() {
+ return this.fileDef;
+ }
+
+ public String getIp() {
+ return this.ip;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getMemTotal() {
+ return this.memTotal;
+ }
+
+ public String getMemSwap() {
+ return this.memSwap;
+ }
+
+ public List<ProcessInfo> getAlienPids() {
+ return this.alienPids;
+ }
+
+ public long getAlienPidsCount() {
+ long retVal = 0;
+ if(this.alienPids != null) {
+ retVal = this.alienPids.size();
+ }
+ return retVal;
+ }
+
+ public String getSharesTotal() {
+ return this.sharesTotal;
+ }
+
+ public String getSharesInuse() {
+ return this.sharesInuse;
+ }
+
+ public long getHeartbeat() {
+ return this.heartbeat;
+ }
+
+ public boolean isExpired(long millis) {
+ return getElapsedMillis() > millis;
+ }
+
+ public long getElapsedMillis() {
+ long retVal = -1;
+ if(heartbeat >= 0) {
+ retVal = (System.currentTimeMillis()-heartbeat)/1000;
+ }
+ return retVal;
+ }
+
+ public String getElapsed() {
+ String retVal = "";
+ long elapsedMillis = getElapsedMillis();
+ if(elapsedMillis >= 0) {
+ retVal = ""+elapsedMillis;
+ }
+ return retVal;
+ }
+
+ public int compareTo(MachineInfo machine) {
+ int retVal = 0;
+ MachineInfo m1 = this;
+ MachineInfo m2 = machine;
+ String s1 = m1.name;
+ String s2 = m2.name;
+ if(s1 != null) {
+ if(s2 != null) {
+ if(s1.trim().equals(s2.trim()))
+ return retVal;
+ }
+ }
+ retVal = compareStatus(m1, m2);
+ if(retVal != 0) {
+ return retVal;
+ }
+ retVal = compareSwapInuse(m1, m2);
+ if(retVal != 0) {
+ return retVal;
+ }
+ retVal = compareAlienPids(m1, m2);
+ if(retVal != 0) {
+ return retVal;
+ }
+ retVal = compareSharesInuse(m1, m2);
+ if(retVal != 0) {
+ return retVal;
+ }
+ retVal = compareSharesTotal(m1, m2);
+ if(retVal != 0) {
+ return retVal;
+ }
+ /*
+ retVal = compareHeartbeat(m1, m2);
+ if(retVal != 0) {
+ return retVal;
+ }
+ */
+ retVal = compareIp(m1, m2);
+ if(retVal != 0) {
+ return retVal;
+ }
+ retVal = compareName(m1, m2);
+ return retVal;
+ }
+
+ private int compareStatus(MachineInfo m1, MachineInfo m2) {
+ int retVal = 0;
+ try {
+ String v1 = m1.getStatus();
+ String v2 = m2.getStatus();
+ if(!v1.equals(v2)) {
+ if(v1.equals("defined")) {
+ return -1;
+ }
+ if(v2.equals("defined")) {
+ return 1;
+ }
+ if(v1.equals("down")) {
+ return -1;
+ }
+ if(v2.equals("down")) {
+ return 1;
+ }
+ if(v1.equals("up")) {
+ return 1;
+ }
+ if(v2.equals("up")) {
+ return -1;
+ }
+ }
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ private int compareSwapInuse(MachineInfo m1, MachineInfo m2) {
+ int retVal = 0;
+ try {
+ long v1 = Long.parseLong(m1.getMemSwap());
+ long v2 = Long.parseLong(m2.getMemSwap());
+ if(v1 > v2) {
+ return -1;
+ }
+ if(v1 < v2) {
+ return 1;
+ }
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ private int compareAlienPids(MachineInfo m1, MachineInfo m2) {
+ int retVal = 0;
+ try {
+ long v1 = m1.getAlienPidsCount();
+ long v2 = m2.getAlienPidsCount();
+ if(v1 > v2) {
+ return -1;
+ }
+ if(v1 < v2) {
+ return 1;
+ }
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ private int compareSharesInuse(MachineInfo m1, MachineInfo m2) {
+ int retVal = 0;
+ try {
+ long v1 = Long.parseLong(m1.getSharesInuse());
+ long v2 = Long.parseLong(m2.getSharesInuse());
+ if(v1 > v2) {
+ return -1;
+ }
+ if(v1 < v2) {
+ return 1;
+ }
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ private int compareSharesTotal(MachineInfo m1, MachineInfo m2) {
+ int retVal = 0;
+ try {
+ long v1 = Long.parseLong(m1.getSharesTotal());
+ long v2 = Long.parseLong(m2.getSharesTotal());
+ if(v1 > v2) {
+ return -1;
+ }
+ if(v1 < v2) {
+ return 1;
+ }
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+/*
+ private int compareHeartbeat(MachineInfo m1, MachineInfo m2) {
+ int retVal = 0;
+ try {
+ long v1 = m1.getHeartbeat();
+ long v2 = m2.getHeartbeat();
+ if(v1 > v2) {
+ return 1;
+ }
+ if(v1 < v2) {
+ return -1;
+ }
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+*/
+ private int compareIp(MachineInfo m1, MachineInfo m2) {
+ return m1.ip.compareTo(m2.ip);
+ }
+
+ private int compareName(MachineInfo m1, MachineInfo m2) {
+ return m1.name.compareTo(m2.name);
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineSummaryInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineSummaryInfo.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineSummaryInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineSummaryInfo.java Wed Jan 2 19:55:58 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.ws;
+
+public class MachineSummaryInfo {
+
+ public long memoryTotal = 0;
+ public long memorySwapped = 0;
+ public long sharesTotal = 0;
+ public long sharesInuse = 0;
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/MachineSummaryInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/ReservationInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/ReservationInfo.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/ReservationInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/ReservationInfo.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,86 @@
+/*
+ * 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.ws;
+
+import org.apache.uima.ducc.transport.event.common.DuccWorkReservation;
+
+public class ReservationInfo implements Comparable<ReservationInfo> {
+
+ private DuccWorkReservation _reservation;
+
+ public ReservationInfo(DuccWorkReservation reservation) {
+ _reservation = reservation;
+ }
+
+ public DuccWorkReservation getReservation() {
+ return _reservation;
+ }
+
+ public boolean isOperational() {
+ return _reservation.isOperational();
+ }
+
+ public int compareTo(ReservationInfo reservation) {
+ int retVal = 0;
+ ReservationInfo r1 = this;
+ ReservationInfo r2 = reservation;
+ long f1 = r1.getReservation().getDuccId().getFriendly();
+ long f2 = r2.getReservation().getDuccId().getFriendly();
+ if(f1 != f2) {
+ if(!r1.isOperational() && r2.isOperational()) {
+ retVal = 1;
+ }
+ else if(r1.isOperational() && !r2.isOperational()) {
+ retVal = -1;
+ }
+ else if(f1 > f2) {
+ retVal = -1;
+ }
+ else if(f1 < f2) {
+ retVal = 1;
+ }
+ }
+ return retVal;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ boolean retVal = false;
+ try {
+ ReservationInfo i1 = this;
+ ReservationInfo i2 = (ReservationInfo)object;
+ DuccWorkReservation j1 = i1.getReservation();
+ DuccWorkReservation j2 = i2.getReservation();
+ String s1 = j1.getDuccId().toString();
+ String s2 = j2.getDuccId().toString();
+ retVal = s1.equals(s2);
+ }
+ catch(Throwable t) {
+ }
+ return retVal;
+ }
+
+ @Override
+ public int hashCode() {
+ ReservationInfo i1 = this;
+ DuccWorkReservation j1 = i1.getReservation();
+ String s1 = j1.getDuccId().toString();
+ return s1.hashCode();
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/ReservationInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/WebServerComponent.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/WebServerComponent.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/WebServerComponent.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/WebServerComponent.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,168 @@
+/*
+ * 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.ws;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.CamelContext;
+import org.apache.uima.ducc.common.boot.DuccDaemonRuntimeProperties;
+import org.apache.uima.ducc.common.boot.DuccDaemonRuntimeProperties.DaemonName;
+import org.apache.uima.ducc.common.component.AbstractDuccComponent;
+import org.apache.uima.ducc.common.config.CommonConfiguration;
+import org.apache.uima.ducc.common.internationalization.Messages;
+import org.apache.uima.ducc.common.main.DuccService;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.NodeMetricsUpdateDuccEvent;
+import org.apache.uima.ducc.transport.event.OrchestratorStateDuccEvent;
+import org.apache.uima.ducc.transport.event.PmStateDuccEvent;
+import org.apache.uima.ducc.transport.event.RmStateDuccEvent;
+import org.apache.uima.ducc.transport.event.SmStateDuccEvent;
+import org.apache.uima.ducc.transport.event.common.DuccWorkMap;
+import org.apache.uima.ducc.ws.server.DuccWebServer;
+import org.apache.uima.ducc.ws.utils.DatedNodeMetricsUpdateDuccEvent;
+
+
+public class WebServerComponent extends AbstractDuccComponent
+implements IWebServer {
+
+ private static DuccLogger duccLogger = DuccLoggerComponents.getWsLogger(WebServerComponent.class.getName());
+
+ private static DuccId jobid = null;
+
+ private DuccWebServer duccWebServer = null;
+ private Messages duccMsg= Messages.getInstance();
+
+ private static AtomicInteger jobCount = new AtomicInteger(0);
+ private static AtomicInteger serviceCount = new AtomicInteger(0);
+ private static AtomicInteger reservationCount = new AtomicInteger(0);
+
+ public WebServerComponent(CamelContext context, CommonConfiguration common) {
+ super("WebServer",context);
+ String methodName = "WebServerComponent";
+ duccLogger.info(methodName, jobid, "##### boot #####");
+ String[] propertyNames = { "ducc.broker.url" };
+ for(String property : propertyNames) {
+ duccLogger.info(methodName, jobid, property+"="+System.getProperty(property));
+ }
+ duccLogger.info(methodName, jobid, System.getProperty("ducc.broker.url"));
+ duccWebServer = new DuccWebServer(common);
+ init();
+ }
+
+ public void start(DuccService service, String[] args) throws Exception {
+ super.start(service, args);
+ DuccDaemonRuntimeProperties.getInstance().boot(DaemonName.Webserver,getProcessJmxUrl());
+ }
+
+ public void webServerStart() {
+ String methodName = "webServerStart";
+ try {
+ duccWebServer.start();
+ duccLogger.info(methodName, jobid, "webserver started");
+ } catch (Exception e) {
+ duccLogger.error(methodName, jobid, e);
+ }
+ }
+
+ public void webServerStop() {
+ String methodName = "webServerStop";
+ try {
+ duccWebServer.stop();
+ duccLogger.info(methodName, jobid, "webserver stopped");
+ } catch (Exception e) {
+ duccLogger.error(methodName, jobid, e);
+ }
+ }
+
+ private void init() {
+ String methodName = "init";
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("enter"));
+ webServerStart();
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("exit"));
+ }
+
+
+ public void update(OrchestratorStateDuccEvent duccEvent) {
+ String methodName = "update";
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("enter"));
+ duccLogger.debug(methodName, jobid, duccMsg.fetchLabel("received")+"OrchestratorStateDuccEvent");
+ DuccDaemonsData.getInstance().put(duccEvent);
+ DuccWorkMap wm = duccEvent.getWorkMap();
+ boolean change = false;
+ int count;
+ count = wm.getJobCount();
+ if(count != jobCount.get()) {
+ jobCount.set(count);
+ change = true;
+ }
+ count = wm.getReservationCount();
+ if(count != reservationCount.get()) {
+ reservationCount.set(count);
+ change = true;
+ }
+ count = wm.getServiceCount();
+ if(count !=serviceCount.get()) {
+ serviceCount.set(count);
+ change = true;
+ }
+ if(change) {
+ duccLogger.info(methodName, jobid, duccMsg.fetchLabel("jobs")+jobCount.get()+" "+duccMsg.fetchLabel("reservations")+reservationCount.get()+" "+duccMsg.fetchLabel("services")+serviceCount.get());
+ }
+ DuccData.getInstance().put(wm);
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("exit"));
+ }
+
+
+ public void update(NodeMetricsUpdateDuccEvent duccEvent) {
+ String methodName = "update";
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("enter"));
+ duccLogger.trace(methodName, jobid, duccMsg.fetchLabel("received")+"NodeMetricsUpdateDuccEvent");
+ DuccMachinesData.getInstance().put(new DatedNodeMetricsUpdateDuccEvent(duccEvent));
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("exit"));
+ }
+
+
+ public void update(RmStateDuccEvent duccEvent) {
+ String methodName = "update";
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("enter"));
+ duccLogger.debug(methodName, jobid, duccMsg.fetchLabel("received")+"RmStateDuccEvent");
+ DuccDaemonsData.getInstance().put(duccEvent);
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("exit"));
+ }
+
+
+ public void update(SmStateDuccEvent duccEvent) {
+ String methodName = "update";
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("enter"));
+ duccLogger.debug(methodName, jobid, duccMsg.fetchLabel("received")+"SmStateDuccEvent");
+ DuccDaemonsData.getInstance().put(duccEvent);
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("exit"));
+ }
+
+
+ public void update(PmStateDuccEvent duccEvent) {
+ String methodName = "update";
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("enter"));
+ duccLogger.debug(methodName, jobid, duccMsg.fetchLabel("received")+"PmStateDuccEvent");
+ DuccDaemonsData.getInstance().put(duccEvent);
+ duccLogger.trace(methodName, jobid, duccMsg.fetch("exit"));
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/WebServerComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/config/WebServerConfiguration.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/config/WebServerConfiguration.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/config/WebServerConfiguration.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/config/WebServerConfiguration.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,157 @@
+/*
+ * 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.ws.config;
+
+import javax.jms.ObjectMessage;
+
+import org.apache.activemq.command.ActiveMQMessage;
+import org.apache.activemq.util.ByteSequence;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.JmsMessage;
+import org.apache.uima.ducc.common.config.CommonConfiguration;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.DuccTransportConfiguration;
+import org.apache.uima.ducc.ws.DuccBoot;
+import org.apache.uima.ducc.ws.WebServerComponent;
+import org.apache.uima.ducc.ws.event.WebServerEventListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+
+/**
+ * A {@link WebServerConfiguration} to configure JobDriver component. Depends on
+ * properties loaded by a main program into System properties.
+ *
+ */
+@Configuration
+@Import({DuccTransportConfiguration.class,CommonConfiguration.class})
+public class WebServerConfiguration {
+ // use Spring magic to autowire (instantiate and bind) CommonConfiguration to a local variable
+ @Autowired CommonConfiguration common;
+ // use Spring magic to autowire (instantiate and bind) DuccTransportConfiguration to a local variable
+ @Autowired DuccTransportConfiguration webServerTransport;
+
+ private DuccLogger duccLogger = DuccLoggerComponents.getWsLogger(WebServerConfiguration.class.getName());
+ private DuccId jobid = null;
+
+ /**
+ * Instantiate {@link WebServerEventListener} which will handle incoming messages.
+ *
+ * @param ws - {@link WebServerComponent} instance
+ * @return - {@link WebServerEventListener}
+ */
+ public WebServerEventListener webServerDelegateListener(WebServerComponent ws) {
+ WebServerEventListener wsel = new WebServerEventListener(ws);
+ return wsel;
+ }
+ /**
+ * Create a Router to handle incoming messages from a given endpoint. All messages are delegated
+ * to a provided listener. Note: Camel uses introspection to determine which method to call when
+ * delegating a message. The name of the method doesnt matter it is the argument that needs
+ * to match the type of object in the message. If there is no method with a matching argument
+ * type the message will not be delegated.
+ *
+ * @param endpoint - endpoint where messages are expected
+ * @param delegate - {@link WebServerEventListener} instance
+ * @return - initialized {@link RouteBuilder} instance
+ *
+ */
+ public synchronized RouteBuilder routeBuilderForIncomingRequests(final String endpoint, final WebServerEventListener delegate) {
+ return new RouteBuilder() {
+ Processor p = new AccessJmsBody();
+ public void configure() {
+ from(endpoint)
+ .process(p)
+ //from("activemq:topic:tmp-jm-state")
+ .bean(delegate);
+ }
+ };
+ }
+
+ /**
+ * Creates and initializes {@link WebServerComponent} instance. @Bean annotation identifies {@link WebServerComponent}
+ * as a Spring framework Bean which will be managed by Spring container.
+ *
+ * @return {@link WebServerComponent} instance
+ *
+ * @throws Exception
+ */
+ @Bean
+ public WebServerComponent webServer() throws Exception {
+ String methodName = "webServer";
+ WebServerComponent ws = null;
+ try {
+ ws = new WebServerComponent(common.camelContext(), common);
+ DuccBoot.boot(common);
+ // Instantiate delegate listener to receive incoming messages.
+ WebServerEventListener delegateListener = this.webServerDelegateListener(ws);
+ // Inject a dispatcher into the listener in case it needs to send
+ // a message to another component
+ delegateListener.setDuccEventDispatcher(webServerTransport.duccEventDispatcher(common.orchestratorStateUpdateEndpoint, ws.getContext()));
+ // Inject Camel Router that will delegate messages to WebServer delegate listener
+ ws.getContext().addRoutes(this.routeBuilderForIncomingRequests(common.orchestratorStateUpdateEndpoint, delegateListener));
+ ws.getContext().addRoutes(this.routeBuilderForIncomingRequests(common.nodeMetricsEndpoint, delegateListener));
+ ws.getContext().addRoutes(this.routeBuilderForIncomingRequests(common.rmStateUpdateEndpoint, delegateListener));
+ ws.getContext().addRoutes(this.routeBuilderForIncomingRequests(common.smStateUpdateEndpoint, delegateListener));
+ ws.getContext().addRoutes(this.routeBuilderForIncomingRequests(common.pmStateUpdateEndpoint, delegateListener));
+ }
+ catch(Throwable t) {
+ duccLogger.error(methodName, jobid, t);
+ }
+ return ws;
+ }
+ public class AccessJmsBody implements Processor
+ {
+ int msglen = 0;
+ String objectName = "unknown";
+ public void process(Exchange exchange) throws Exception {
+ String location = "AccessJmsBody:process";
+ try {
+ Object o = exchange.getIn();
+ if ( o instanceof JmsMessage ) {
+ JmsMessage msg = (JmsMessage) o;
+ o = msg.getJmsMessage();
+ if ( o instanceof ActiveMQMessage ) {
+ ActiveMQMessage amqMessage = (ActiveMQMessage) o;
+ if ( amqMessage instanceof ObjectMessage ) {
+ Object body = ((ObjectMessage)amqMessage).getObject();
+ ByteSequence bs = amqMessage.getContent();
+ msglen = bs.getLength();
+ objectName = body.getClass().getName();
+ }
+ }
+ }
+ Long pubSize = new Long(msglen);
+ exchange.getIn().setHeader("pubSize", pubSize);
+ String text = "Message length is " + msglen + " for " + objectName;
+ duccLogger.debug(location, jobid, text);
+ }
+ catch (Throwable t) {
+ duccLogger.error(location, jobid, t);
+ }
+ }
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/config/WebServerConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/event/WebServerEventListener.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/event/WebServerEventListener.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/event/WebServerEventListener.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/event/WebServerEventListener.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,107 @@
+/*
+ * 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.ws.event;
+
+import org.apache.camel.Body;
+import org.apache.camel.Header;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.dispatcher.DuccEventDispatcher;
+import org.apache.uima.ducc.transport.event.NodeMetricsUpdateDuccEvent;
+import org.apache.uima.ducc.transport.event.OrchestratorStateDuccEvent;
+import org.apache.uima.ducc.transport.event.PmStateDuccEvent;
+import org.apache.uima.ducc.transport.event.RmStateDuccEvent;
+import org.apache.uima.ducc.transport.event.SmStateDuccEvent;
+import org.apache.uima.ducc.transport.event.delegate.DuccEventDelegateListener;
+import org.apache.uima.ducc.ws.IWebServer;
+
+
+public class WebServerEventListener implements DuccEventDelegateListener {
+
+ private DuccLogger duccLogger = DuccLoggerComponents.getWsLogger(WebServerEventListener.class.getName());
+ private DuccId jobid = null;
+
+ private IWebServer webServer;
+
+ public WebServerEventListener(IWebServer webServer) {
+ this.webServer = webServer;
+ }
+
+ public void setDuccEventDispatcher( DuccEventDispatcher eventDispatcher ) {
+ }
+
+ public void setEndpoint( String endpoint ) {
+ }
+
+ public void onOrchestratorStateDuccEvent(@Body OrchestratorStateDuccEvent duccEvent, @Header("pubSize")Long pubSize) {
+ String location = "onOrchestratorStateDuccEvent";
+ try {
+ duccEvent.setEventSize(pubSize);
+ webServer.update(duccEvent);
+ }
+ catch(Throwable t) {
+ duccLogger.error(location, jobid, t);
+ }
+ }
+
+ public void onNodeMetricsUpdateDuccEvent(@Body NodeMetricsUpdateDuccEvent duccEvent, @Header("pubSize")Long pubSize) throws Exception {
+ String location = "onNodeMetricsUpdateDuccEvent";
+ try {
+ duccEvent.setEventSize(pubSize);
+ webServer.update(duccEvent);
+ }
+ catch(Throwable t) {
+ duccLogger.error(location, jobid, t);
+ }
+ }
+
+ public void onRmStateDuccEvent(@Body RmStateDuccEvent duccEvent, @Header("pubSize")Long pubSize) {
+ String location = "onRmStateDuccEvent";
+ try {
+ duccEvent.setEventSize(pubSize);
+ webServer.update(duccEvent);
+ }
+ catch(Throwable t) {
+ duccLogger.error(location, jobid, t);
+ }
+ }
+
+ public void onSmStateDuccEvent(@Body SmStateDuccEvent duccEvent, @Header("pubSize")Long pubSize) {
+ String location = "onSmStateDuccEvent";
+ try {
+ duccEvent.setEventSize(pubSize);
+ webServer.update(duccEvent);
+ }
+ catch(Throwable t) {
+ duccLogger.error(location, jobid, t);
+ }
+ }
+
+ public void onPmStateDuccEvent(@Body PmStateDuccEvent duccEvent, @Header("pubSize")Long pubSize) {
+ String location = "onPmStateDuccEvent";
+ try {
+ duccEvent.setEventSize(pubSize);
+ webServer.update(duccEvent);
+ }
+ catch(Throwable t) {
+ duccLogger.error(location, jobid, t);
+ }
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/event/WebServerEventListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAsUser.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAsUser.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAsUser.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAsUser.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,78 @@
+/*
+ * 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.ws.server;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.apache.uima.ducc.common.internationalization.Messages;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.Utils;
+
+
+public class DuccAsUser {
+
+ private static DuccLogger duccLogger = DuccLoggerComponents.getWsLogger(DuccAsUser.class.getName());
+ private static Messages messages = Messages.getInstance();
+
+ public static boolean duckling(String[] args) {
+
+ String methodName = "duckling";
+
+ String c_launcher_path =
+ Utils.resolvePlaceholderIfExists(
+ System.getProperty("ducc.agent.launcher.ducc_spawn_path"),System.getProperties());
+
+ duccLogger.debug(methodName, null, messages.fetchLabel("the duckling launcher")+c_launcher_path);
+
+ ArrayList<String> cmd = new ArrayList<String>();
+
+ cmd.add(c_launcher_path);
+
+ for( String arg : args ) {
+ cmd.add(arg);
+ }
+
+ StringBuffer sb = new StringBuffer();
+
+ for( String c : cmd ) {
+ sb.append(c);
+ sb.append(" ");
+ }
+
+ duccLogger.info(methodName, null, sb.toString().trim());
+
+ ProcessBuilder pb = new ProcessBuilder(cmd);
+
+ Map<String, String> env = pb.environment();
+
+ env.put("JobId", "webserver");
+
+ try {
+ Process process = pb.start();
+ process.waitFor();
+ }
+ catch(Exception e) {
+ duccLogger.info(methodName, null, e);
+ }
+
+ return true;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAsUser.java
------------------------------------------------------------------------------
svn:eol-style = native