Search in sources :

Example 1 with User

use of org.vcell.util.document.User in project vcell by virtualcell.

the class RunRefSimulationFastOp method createNewExternalDataInfo.

private ExternalDataInfo createNewExternalDataInfo(LocalContext localWorkspace, String extDataIDName) {
    File targetDir = new File(localWorkspace.getDefaultSimDataDirectory());
    KeyValue key = LocalWorkspace.createNewKeyValue();
    User owner = LocalWorkspace.getDefaultOwner();
    ExternalDataIdentifier newImageDataExtDataID = new ExternalDataIdentifier(key, owner, extDataIDName);
    String filename = new File(targetDir, newImageDataExtDataID.getID() + SimDataConstants.LOGFILE_EXTENSION).getAbsolutePath();
    ExternalDataInfo newImageDataExtDataInfo = new ExternalDataInfo(newImageDataExtDataID, filename);
    return newImageDataExtDataInfo;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) ExternalDataInfo(org.vcell.vmicro.workflow.data.ExternalDataInfo) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) File(java.io.File)

Example 2 with User

use of org.vcell.util.document.User in project vcell by virtualcell.

the class RunRefSimulationOp method createNewExternalDataInfo.

private static ExternalDataInfo createNewExternalDataInfo(LocalWorkspace localWorkspace, String extDataIDName) {
    File targetDir = new File(localWorkspace.getDefaultSimDataDirectory());
    KeyValue key = LocalWorkspace.createNewKeyValue();
    User owner = LocalWorkspace.getDefaultOwner();
    ExternalDataIdentifier newImageDataExtDataID = new ExternalDataIdentifier(key, owner, extDataIDName);
    String filename = new File(targetDir, newImageDataExtDataID.getID() + SimDataConstants.LOGFILE_EXTENSION).getAbsolutePath();
    ExternalDataInfo newImageDataExtDataInfo = new ExternalDataInfo(newImageDataExtDataID, filename);
    return newImageDataExtDataInfo;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) ExternalDataInfo(org.vcell.vmicro.workflow.data.ExternalDataInfo) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) File(java.io.File)

Example 3 with User

use of org.vcell.util.document.User in project vcell by virtualcell.

the class AccessTokenServerResource method get_json.

@Override
public AccessTokenRepresentation get_json() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    String clientId = getQueryValue(PARAM_CLIENT_ID);
    String userId = getQueryValue(PARAM_USER_ID);
    String userPassword = getQueryValue(PARAM_USER_PASSWORD);
    try {
        ApiClient apiClient = application.getUserVerifier().getApiClient(clientId);
        if (apiClient == null) {
            throw new RuntimeException("client not found");
        }
        User authenticatedUser = application.getUserVerifier().authenticateUser(userId, userPassword.toCharArray());
        if (authenticatedUser == null) {
            throw new RuntimeException("unable to authenticate user");
        }
        ApiAccessToken apiAccessToken = application.getUserVerifier().generateApiAccessToken(apiClient.getKey(), authenticatedUser);
        AccessTokenRepresentation tokenRep = new AccessTokenRepresentation(apiAccessToken);
        // 
        // indicate no caching of response.
        // 
        ArrayList<CacheDirective> cacheDirectives = new ArrayList<CacheDirective>();
        cacheDirectives.add(CacheDirective.noCache());
        getResponse().setCacheDirectives(cacheDirectives);
        return tokenRep;
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : User(org.vcell.util.document.User) CacheDirective(org.restlet.data.CacheDirective) ApiAccessToken(cbit.vcell.modeldb.ApiAccessToken) ArrayList(java.util.ArrayList) VCellApiApplication(org.vcell.rest.VCellApiApplication) ApiClient(cbit.vcell.modeldb.ApiClient) AccessTokenRepresentation(org.vcell.rest.common.AccessTokenRepresentation) ResourceException(org.restlet.resource.ResourceException)

Example 4 with User

use of org.vcell.util.document.User in project vcell by virtualcell.

the class BatchScheduler method schedule.

/**
 * Insert the method's description here.
 * Creation date: (5/11/2006 9:32:58 AM)
 */
public static WaitingJob[] schedule(SimulationJobStatus[] activeJobsThisSite, Map<KeyValue, SimulationRequirements> simulationRequirementsMap, int siteJobQuota, int userQuotaOde, int userQuotaPde, VCellServerID systemID) {
    Hashtable<User, Integer> userPdeRunningJobsThisSite = new Hashtable<User, Integer>();
    Hashtable<User, Integer> userOdeRunningJobsThisSite = new Hashtable<User, Integer>();
    cbit.vcell.server.SimulationJobStatus jobStatus = null;
    int numRunningJobsThisSite = 0;
    for (int i = 0; i < activeJobsThisSite.length; i++) {
        jobStatus = activeJobsThisSite[i];
        if (!jobStatus.getSchedulerStatus().isActive()) {
            continue;
        }
        if (jobStatus.getSchedulerStatus().isWaiting()) {
            // we only do statistics on running jobs;
            continue;
        }
        numRunningJobsThisSite++;
        if (jobStatus.getServerID().equals(systemID)) {
            // the number of running jobs on this site
            User user = activeJobsThisSite[i].getVCSimulationIdentifier().getOwner();
            SimulationRequirements simRequirements = simulationRequirementsMap.get(jobStatus.getVCSimulationIdentifier().getSimulationKey());
            if (simRequirements != null && simRequirements.isPDE()) {
                Integer numUserPdeJobs = userPdeRunningJobsThisSite.get(user);
                if (numUserPdeJobs == null) {
                    userPdeRunningJobsThisSite.put(user, 1);
                } else {
                    userPdeRunningJobsThisSite.put(user, numUserPdeJobs.intValue() + 1);
                }
            } else {
                Integer numUserOdeJobs = userOdeRunningJobsThisSite.get(user);
                if (numUserOdeJobs == null) {
                    userOdeRunningJobsThisSite.put(user, 1);
                } else {
                    userOdeRunningJobsThisSite.put(user, numUserOdeJobs.intValue() + 1);
                }
            }
        }
    }
    ArrayList<WaitingJob> waitingJobs = new ArrayList<WaitingJob>();
    for (int i = 0; i < activeJobsThisSite.length; i++) {
        jobStatus = activeJobsThisSite[i];
        if (!jobStatus.getSchedulerStatus().isWaiting()) {
            // ignore non-waiting job
            continue;
        }
        if (!jobStatus.getServerID().equals(systemID)) {
            // doesn't belong
            continue;
        }
        User user = activeJobsThisSite[i].getVCSimulationIdentifier().getOwner();
        Integer numRunningPDEsThisSite = userPdeRunningJobsThisSite.get(user);
        if (numRunningPDEsThisSite == null) {
            numRunningPDEsThisSite = new Integer(0);
        }
        Integer numRunningODEsThisSite = userOdeRunningJobsThisSite.get(user);
        if (numRunningODEsThisSite == null) {
            numRunningODEsThisSite = new Integer(0);
        }
        long waitingTimeStamp = jobStatus.getSimulationQueueEntryStatus().getQueueDate().getTime();
        KeyValue simKey = jobStatus.getVCSimulationIdentifier().getSimulationKey();
        waitingJobs.add(new WaitingJob(user, numRunningPDEsThisSite, numRunningODEsThisSite, waitingTimeStamp, jobStatus, simulationRequirementsMap.get(simKey)));
    }
    Collections.sort(waitingJobs, new Comparator<WaitingJob>() {

        @Override
        public int compare(WaitingJob o1, WaitingJob o2) {
            // 
            if (!o1.getNumRunningJobs().equals(o2.getNumRunningJobs())) {
                return o1.getNumRunningJobs().compareTo(o2.getNumRunningJobs());
            }
            // 
            if (o1.simRequirements.isPDE() != o2.simRequirements.isPDE()) {
                if (o1.simRequirements.isPDE()) {
                    return 1;
                } else {
                    return -1;
                }
            }
            // 
            return o1.waitingTimeStamp.compareTo(o2.waitingTimeStamp);
        }
    });
    // 
    // enforce quota for each user
    // 
    HashSet<User> users = new HashSet<User>();
    users.addAll(userPdeRunningJobsThisSite.keySet());
    users.addAll(userOdeRunningJobsThisSite.keySet());
    for (User user : users) {
        Integer numRunningPDEsThisSite = userPdeRunningJobsThisSite.get(user);
        int numRunningPDEs = 0;
        if (numRunningPDEsThisSite != null) {
            numRunningPDEs = numRunningPDEsThisSite;
        }
        Integer numRunningODEsThisSite = userOdeRunningJobsThisSite.get(user);
        int numRunningODEs = 0;
        if (numRunningODEsThisSite != null) {
            numRunningODEs = numRunningODEsThisSite;
        }
        // 
        // go full list and remove any jobs that would exceed this users quota
        // 
        Iterator<WaitingJob> waitingJobIter = waitingJobs.iterator();
        while (waitingJobIter.hasNext()) {
            WaitingJob waitingJob = waitingJobIter.next();
            if (waitingJob.user.equals(user)) {
                if (waitingJob.simRequirements.isPDE()) {
                    if (numRunningPDEs < userQuotaPde) {
                        numRunningPDEs++;
                    } else {
                        waitingJobIter.remove();
                    }
                } else {
                    if (numRunningODEs < userQuotaOde) {
                        numRunningODEs++;
                    } else {
                        waitingJobIter.remove();
                    }
                }
            }
        }
    }
    // 
    // enforce site quota (keep only first N jobs) where currentRunning + N <= quota
    // 
    int numJobsSlotsAvailable = Math.max(0, siteJobQuota - numRunningJobsThisSite);
    int numJobsEligible = waitingJobs.size();
    int numJobsToDispatch = Math.min(numJobsSlotsAvailable, numJobsEligible);
    if (numJobsToDispatch == 0) {
        return new WaitingJob[0];
    } else {
        return waitingJobs.subList(0, numJobsToDispatch).toArray(new WaitingJob[0]);
    }
}
Also used : User(org.vcell.util.document.User) SimulationRequirements(cbit.vcell.messaging.db.SimulationRequirements) KeyValue(org.vcell.util.document.KeyValue) Hashtable(java.util.Hashtable) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 5 with User

use of org.vcell.util.document.User in project vcell by virtualcell.

the class SolverPostprocessor method main.

public static void main(java.lang.String[] args) {
    if (args.length < NUM_STD_ARGS) {
        System.out.println("Usage: " + SolverPostprocessor.class.getName() + " simKey username userKey jobindex taskid solverExitCode [postProcessorCommandFile]");
        System.exit(1);
    }
    Logging.init();
    Log4jSessionLog log = new Log4jSessionLog(LOG_NAME);
    Logger lg = log.getLogger();
    VCMessagingService vcMessagingService = null;
    try {
        PropertyLoader.loadProperties(POST_PROCESSOR_PROPERTIES);
        ResourceUtil.setNativeLibraryDirectory();
        NativeLoader.setOsType(OsType.LINUX);
        KeyValue simKey = new KeyValue(args[0]);
        String userName = args[1];
        KeyValue userKey = new KeyValue(args[2]);
        int jobIndex = Integer.parseInt(args[3]);
        int taskID = Integer.parseInt(args[4]);
        int solverExitCode = Integer.parseInt(args[5]);
        User owner = new User(userName, userKey);
        VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
        String hostName = ManageUtils.getHostName();
        VCMongoMessage.serviceStartup(ServiceName.solverPostprocessor, Integer.valueOf(simKey.toString()), args);
        // 
        // JMX registration
        // 
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new ServerMessagingDelegate());
        VCMessageSession session = vcMessagingService.createProducerSession();
        WorkerEventMessage workerEventMessage;
        if (solverExitCode == 0) {
            Exception postProcessingException = null;
            if (args.length > NUM_STD_ARGS) {
                String fname = args[NUM_STD_ARGS];
                if (lg.isDebugEnabled()) {
                    lg.debug("processing " + fname);
                }
                postProcessingException = runPostprocessingCommands(fname, lg);
            }
            if (lg.isDebugEnabled()) {
                lg.debug("postProcessingException is " + postProcessingException);
            }
            if (postProcessingException == null) {
                lg.debug("sendWorkerExitNormal");
                workerEventMessage = WorkerEventMessage.sendWorkerExitNormal(session, SolverPostprocessor.class.getName(), hostName, vcSimID, jobIndex, taskID, solverExitCode);
            } else {
                lg.debug("sendWorkerExitError postprocessing");
                workerEventMessage = WorkerEventMessage.sendWorkerExitError(session, postProcessingException, hostName, vcSimID, jobIndex, taskID, SimulationMessage.WorkerExited(postProcessingException));
            }
        } else {
            // solverExitCode != 0
            lg.debug("sendWorkerExitError solverExitCode");
            workerEventMessage = WorkerEventMessage.sendWorkerExitError(session, SolverPostprocessor.class.getName(), hostName, vcSimID, jobIndex, taskID, solverExitCode);
        }
        lg.debug(workerEventMessage);
        VCMongoMessage.sendWorkerEvent(workerEventMessage);
    } catch (Throwable e) {
        log.exception(e);
    } finally {
        if (vcMessagingService != null) {
            try {
                vcMessagingService.close();
            } catch (VCMessagingException e) {
                e.printStackTrace();
            }
        }
        ApplicationTerminator.beginCountdown(TimeUnit.SECONDS, 10, 0);
        VCMongoMessage.shutdown();
        System.exit(0);
    }
}
Also used : ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) Log4jSessionLog(org.vcell.util.logging.Log4jSessionLog) VCMessageSession(cbit.vcell.message.VCMessageSession) VCMessagingService(cbit.vcell.message.VCMessagingService) Logger(org.apache.log4j.Logger) VCMessagingException(cbit.vcell.message.VCMessagingException) ObjectName(javax.management.ObjectName) VCellServiceMXBeanImpl(cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl) VCMessagingException(cbit.vcell.message.VCMessagingException) WorkerEventMessage(cbit.vcell.message.messages.WorkerEventMessage) MBeanServer(javax.management.MBeanServer)

Aggregations

User (org.vcell.util.document.User)192 KeyValue (org.vcell.util.document.KeyValue)89 DataAccessException (org.vcell.util.DataAccessException)60 SQLException (java.sql.SQLException)39 VCellApiApplication (org.vcell.rest.VCellApiApplication)34 File (java.io.File)32 ArrayList (java.util.ArrayList)28 BioModel (cbit.vcell.biomodel.BioModel)27 BigString (org.vcell.util.BigString)27 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)26 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)26 ResultSet (java.sql.ResultSet)21 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)20 Simulation (cbit.vcell.solver.Simulation)19 XMLSource (cbit.vcell.xml.XMLSource)18 XmlParseException (cbit.vcell.xml.XmlParseException)18 BioModelInfo (org.vcell.util.document.BioModelInfo)16 SimulationContext (cbit.vcell.mapping.SimulationContext)15 BigDecimal (java.math.BigDecimal)15 Date (java.util.Date)15