Search in sources :

Example 11 with WorkerEvent

use of cbit.rmi.event.WorkerEvent in project vcell by virtualcell.

the class WorkerEventMessage method parseMessage.

/**
 * Insert the method's description here.
 * Creation date: (2/5/2004 2:19:48 PM)
 * @param message javax.jms.Message
 * @throws DataAccessException
 * @throws SQLException
 */
private void parseMessage(UserResolver userResolver, VCMessage message) throws DataAccessException, SQLException {
    if (message == null) {
        throw new RuntimeException("Null message");
    }
    if (!message.propertyExists(VCMessagingConstants.MESSAGE_TYPE_PROPERTY)) {
        throw new RuntimeException("Wrong message: expecting property " + VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
    }
    String msgType = message.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
    if (msgType != null && !msgType.equals(MessageConstants.MESSAGE_TYPE_WORKEREVENT_VALUE)) {
        throw new RuntimeException("Wrong message type: " + msgType + ", expecting: " + MessageConstants.MESSAGE_TYPE_WORKEREVENT_VALUE);
    }
    Object obj = message.getObjectContent();
    if (obj != null) {
        if (obj instanceof WorkerEvent) {
            // from Java executable or htcWorker
            workerEvent = (WorkerEvent) obj;
        } else if (obj instanceof String) {
            // from c++ executable (REST API where message stored as a single JSON object)
            String jsonContent = (String) obj;
            System.out.println("received JSON from message: " + jsonContent);
        } else {
            throw new IllegalArgumentException("Expecting object message with object " + WorkerEvent.class.getName() + ", found object :" + obj.getClass().getName());
        }
    } else {
        // from c++ executable (activemq-cpp native protocol communication library)
        int status = message.getIntProperty(MessageConstants.WORKEREVENT_STATUS);
        String hostname = message.getStringProperty(MessageConstants.HOSTNAME_PROPERTY);
        String username = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
        int taskID = message.getIntProperty(MessageConstants.TASKID_PROPERTY);
        int jobIndex = message.getIntProperty(MessageConstants.JOBINDEX_PROPERTY);
        Long longkey = message.getLongProperty(MessageConstants.SIMKEY_PROPERTY);
        KeyValue simKey = new KeyValue(longkey + "");
        // Simulation sim = null;
        User user = userResolver.getUser(username);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, user);
        String statusMessage = null;
        Double progress = null;
        Double timepoint = null;
        if (message.propertyExists(MessageConstants.WORKEREVENT_STATUSMSG)) {
            statusMessage = message.getStringProperty(MessageConstants.WORKEREVENT_STATUSMSG);
        }
        if (message.propertyExists(MessageConstants.WORKEREVENT_PROGRESS)) {
            progress = message.getDoubleProperty(MessageConstants.WORKEREVENT_PROGRESS);
        }
        if (message.propertyExists(MessageConstants.WORKEREVENT_TIMEPOINT)) {
            timepoint = message.getDoubleProperty(MessageConstants.WORKEREVENT_TIMEPOINT);
        }
        SimulationMessage simulationMessage = SimulationMessage.fromSerializedMessage(statusMessage);
        if (simulationMessage == null) {
            switch(status) {
                case WorkerEvent.JOB_ACCEPTED:
                    throw new RuntimeException("unexpected job_accepted status");
                case WorkerEvent.JOB_STARTING:
                    if (statusMessage == null) {
                        simulationMessage = SimulationMessage.MESSAGE_WORKEREVENT_STARTING;
                    } else {
                        simulationMessage = SimulationMessage.workerStarting(statusMessage);
                    }
                    break;
                case WorkerEvent.JOB_DATA:
                    simulationMessage = SimulationMessage.workerData(timepoint);
                    break;
                case WorkerEvent.JOB_PROGRESS:
                    simulationMessage = SimulationMessage.workerProgress(progress);
                    break;
                case WorkerEvent.JOB_FAILURE:
                    if (statusMessage == null) {
                        simulationMessage = SimulationMessage.MESSAGE_WORKEREVENT_FAILURE;
                    } else {
                        simulationMessage = SimulationMessage.workerFailure(statusMessage);
                    }
                    break;
                case WorkerEvent.JOB_COMPLETED:
                    if (statusMessage == null) {
                        simulationMessage = SimulationMessage.MESSAGE_WORKEREVENT_COMPLETED;
                    } else {
                        simulationMessage = SimulationMessage.workerCompleted(statusMessage);
                    }
                    break;
                case WorkerEvent.JOB_WORKER_ALIVE:
                    simulationMessage = SimulationMessage.MESSAGE_WORKEREVENT_WORKERALIVE;
                    break;
                default:
                    throw new RuntimeException("unexpected worker event status : " + status);
            }
        }
        ServiceName serviceName = VCMongoMessage.getServiceName();
        workerEvent = new WorkerEvent(status, serviceName, vcSimID, jobIndex, hostname, taskID, progress, timepoint, simulationMessage);
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) WorkerEvent(cbit.rmi.event.WorkerEvent) ServiceName(cbit.vcell.mongodb.VCMongoMessage.ServiceName) SimulationMessage(cbit.vcell.solver.server.SimulationMessage)

Example 12 with WorkerEvent

use of cbit.rmi.event.WorkerEvent in project vcell by virtualcell.

the class WorkerEventMessage method sendAccepted.

/**
 * Insert the method's description here.
 * Creation date: (12/31/2003 12:53:34 PM)
 * @param param javax.jms.Message
 * @throws VCMessagingException
 */
public static WorkerEventMessage sendAccepted(VCMessageSession session, Object source, SimulationTask simTask, String hostName, HtcJobID htcJobID) throws VCMessagingException {
    WorkerEvent workerEvent = new WorkerEvent(WorkerEvent.JOB_ACCEPTED, source, simTask, hostName, SimulationMessage.MESSAGE_JOB_ACCEPTED);
    workerEvent.setHtcJobID(htcJobID);
    WorkerEventMessage workerEventMessage = new WorkerEventMessage(workerEvent);
    workerEventMessage.sendWorkerEvent(session);
    return workerEventMessage;
}
Also used : WorkerEvent(cbit.rmi.event.WorkerEvent)

Example 13 with WorkerEvent

use of cbit.rmi.event.WorkerEvent in project vcell by virtualcell.

the class WorkerEventMessage method sendFailed.

/**
 * Insert the method's description here.
 * Creation date: (12/31/2003 12:53:34 PM)
 * @param param javax.jms.Message
 */
public static WorkerEventMessage sendFailed(VCMessageSession session, Object source, SimulationTask simTask, String hostName, SimulationMessage failMessage) throws VCMessagingException {
    WorkerEvent workerEvent = new WorkerEvent(WorkerEvent.JOB_FAILURE, source, simTask, hostName, failMessage);
    WorkerEventMessage workerEventMessage = new WorkerEventMessage(workerEvent);
    workerEventMessage.sendWorkerEvent(session);
    return workerEventMessage;
}
Also used : WorkerEvent(cbit.rmi.event.WorkerEvent)

Example 14 with WorkerEvent

use of cbit.rmi.event.WorkerEvent in project vcell by virtualcell.

the class WorkerEventMessage method sendWorkerExitError.

/**
 * send ExitError with custom message
 * @param message describing the reason for the exit
 * @throws VCMessagingException
 */
public static WorkerEventMessage sendWorkerExitError(VCMessageSession session, Object source, String hostName, VCSimulationIdentifier vcSimID, int jobIndex, int taskID, SimulationMessage message) throws VCMessagingException {
    WorkerEvent workerEvent = new WorkerEvent(WorkerEvent.JOB_WORKER_EXIT_ERROR, source, vcSimID, jobIndex, hostName, taskID, null, null, message);
    WorkerEventMessage workerEventMessage = new WorkerEventMessage(workerEvent);
    workerEventMessage.sendWorkerEvent(session);
    return workerEventMessage;
}
Also used : WorkerEvent(cbit.rmi.event.WorkerEvent)

Example 15 with WorkerEvent

use of cbit.rmi.event.WorkerEvent in project vcell by virtualcell.

the class WorkerEventMessage method sendWorkerExitNormal.

public static WorkerEventMessage sendWorkerExitNormal(VCMessageSession session, Object source, String hostName, VCSimulationIdentifier vcSimID, int jobIndex, int taskID, int solverExitCode) throws VCMessagingException {
    WorkerEvent workerEvent = new WorkerEvent(WorkerEvent.JOB_WORKER_EXIT_NORMAL, source, vcSimID, jobIndex, hostName, taskID, null, null, SimulationMessage.WorkerExited(solverExitCode));
    WorkerEventMessage workerEventMessage = new WorkerEventMessage(workerEvent);
    workerEventMessage.sendWorkerEvent(session);
    return workerEventMessage;
}
Also used : WorkerEvent(cbit.rmi.event.WorkerEvent)

Aggregations

WorkerEvent (cbit.rmi.event.WorkerEvent)18 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 SimulationJob (cbit.vcell.solver.SimulationJob)4 DataJobEvent (cbit.rmi.event.DataJobEvent)1 ExportEvent (cbit.rmi.event.ExportEvent)1 PerformanceMonitorEvent (cbit.rmi.event.PerformanceMonitorEvent)1 SimulationJobStatusEvent (cbit.rmi.event.SimulationJobStatusEvent)1 VCellMessageEvent (cbit.rmi.event.VCellMessageEvent)1 RollbackException (cbit.vcell.message.RollbackException)1 VCMessagingException (cbit.vcell.message.VCMessagingException)1 WorkerEventMessage (cbit.vcell.message.messages.WorkerEventMessage)1 HtcException (cbit.vcell.message.server.htc.HtcException)1 HtcJobNotFoundException (cbit.vcell.message.server.htc.HtcJobNotFoundException)1 ServiceName (cbit.vcell.mongodb.VCMongoMessage.ServiceName)1 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)1 SimulationMessage (cbit.vcell.solver.server.SimulationMessage)1 Gson (com.google.gson.Gson)1 SQLException (java.sql.SQLException)1 DataJobEventRepresentation (org.vcell.api.common.events.DataJobEventRepresentation)1 ExportEventRepresentation (org.vcell.api.common.events.ExportEventRepresentation)1