Package org.fluxtream.core.domain

Examples of org.fluxtream.core.domain.UpdateWorkerTask


        try{
            long guestId = AuthHelper.getGuestId();
            final Connector connector = Connector.getConnector(connectorName);
            final ObjectType objectType = ObjectType.getObjectType(connector, objectTypeName);
            ApiKey apiKey = guestService.getApiKey(guestId, Connector.getConnector(connectorName));
            final UpdateWorkerTask scheduledUpdate =
                    connectorUpdateService.getUpdateWorkerTask(apiKey, objectType.value());
            return Response.ok(scheduledUpdate!=null?toJSON(scheduledUpdate).toString():"{}").build();
        }
        catch (Exception e){
            return Response.serverError().entity("Failed to get update tasks: " + e.getMessage()).build();
View Full Code Here


            // This connector is not in Connector info; skip it
        }
        if (connectorInfo == null || !connectorInfo.supportsSync)
            return;

        UpdateWorkerTask updateWorkerTask = getUpdateWorkerTask(apiKey, objectTypes);
        if (updateWorkerTask != null)
            scheduleResults.add(new ScheduleResult(apiKey.getId(), apiKey.getConnector().getName(), objectTypes, ScheduleResult.ResultType.ALREADY_SCHEDULED, updateWorkerTask.timeScheduled));
        else {
            final ScheduleResult scheduleResult = scheduleUpdate(apiKey, objectTypes, updateType, timeScheduled);
            scheduleResults.add(scheduleResult);
View Full Code Here

    @Transactional(readOnly = false)
    @Override
    public ScheduleResult reScheduleUpdateTask(long updateWorkerTaskId, long time, boolean incrementRetries,
                                               UpdateWorkerTask.AuditTrailEntry auditTrailEntry) {
        UpdateWorkerTask updt = em
                .find(UpdateWorkerTask.class, updateWorkerTaskId);

        // Check if updt is null.  This can happen if we were in the process of updating a
        // connector instance which was subsequently deleted.  In that case, print a message
        // and return
        if(updt==null) {
            StringBuilder sb = new StringBuilder("module=updateQueue component=connectorUpdateService action=reScheduleUpdateTask")
                        .append(" updateWorkerTaskId="+updateWorkerTaskId)
                        .append(" message=\"Ignoring reschedule of an update task which is no longer in the system (deleted connector?)");
            logger.info(sb);
            return null;
        }

        // Set the audit trail according to what just happened if a non-null auditTrailEntry is provided
        if(auditTrailEntry!=null)
            updt.addAuditTrailEntry(auditTrailEntry);

        // Spawn a duplicate entry in the UpdateWorker table to record this failure and the reason for it
        if (!incrementRetries) {
            UpdateWorkerTask failed = new UpdateWorkerTask(updt);
            failed.workerThreadName = updt.workerThreadName;
            failed.startTime = updt.startTime;
            failed.endTime = DateTimeUtils.currentTimeMillis();
            failed.auditTrail = updt.auditTrail;
            failed.apiKeyId = updt.apiKeyId;
View Full Code Here

        // Please note that WorkerDispatchService's methods have a @Transactional annotation with a propagation=Propagation.REQUIRES_NEW attribute

        final List<UpdateWorkerTask> updateWorkerTasks = workerDispatchService.claimTasksForDispatch(availableThreads, SERVER_UUID);

        for (int i=0; i<updateWorkerTasks.size(); i++) {
            UpdateWorkerTask updateWorkerTask = updateWorkerTasks.get(i);
            logger.info("module=updateQueue component=connectorUpdateService action=pollScheduledUpdateWorkerTasks" +
                        " message=\"Executing update: " +
                        " \"" + updateWorkerTask);

            UpdateWorker updateWorker = beanFactory.getBean(UpdateWorker.class);
            updateWorker.task = updateWorkerTask;
            try {
                executor.execute(updateWorker);
            } catch (Throwable t) {
                workerDispatchService.unclaimTask(updateWorkerTask.getId());
                logger.warn("executor.execute failed. activeCount=" + executor.getActiveCount() + " maxPoolSize=" + executor.getMaxPoolSize());
                t.printStackTrace();
            }
        }
View Full Code Here

    @Override
    @Transactional(readOnly = false)
    public ScheduleResult scheduleUpdate(final ApiKey apiKey,
                                         int objectTypes, UpdateType updateType, long timeScheduled,
                                         String... jsonParams) {
        UpdateWorkerTask updateScheduled = getUpdateWorkerTask(apiKey, objectTypes);
        ScheduleResult scheduleResult = null;
        if (updateScheduled==null) {
            UpdateWorkerTask updateWorkerTask = new UpdateWorkerTask();
            updateWorkerTask.guestId = apiKey.getGuestId();
            updateWorkerTask.connectorName = apiKey.getConnector().getName();
            updateWorkerTask.apiKeyId = apiKey.getId();
            updateWorkerTask.objectTypes = objectTypes;
            updateWorkerTask.updateType = updateType;
View Full Code Here

        return updateWorkerTasks;
    }

    @Override
    public UpdateWorkerTask getUpdateWorkerTask(final ApiKey apiKey, int objectTypes) {
        UpdateWorkerTask updateWorkerTask = JPAUtils.findUnique(em, UpdateWorkerTask.class, "updateWorkerTasks.withObjectTypes.isScheduled", getLiveServerUUIDs(), objectTypes, apiKey.getId());
        return updateWorkerTask;
    }
View Full Code Here

    @Override
    @Transactional(readOnly = false)
    public UpdateWorkerTask setUpdateWorkerTaskStatus(long updateWorkerTaskId, Status status)
            throws RuntimeException {
        UpdateWorkerTask updt = em
                .find(UpdateWorkerTask.class, updateWorkerTaskId);
        // Check if updt is null.  This can happen if we were in the process of updating a
        // connector instance which was subsequently deleted.  In that case, print a message
        // and return
        if (updt == null) {
View Full Code Here

    }

    @Override
    @Transactional(readOnly=false)
    public UpdateWorkerTask claimForExecution(final long taskId, final String workerThreadName) {
        UpdateWorkerTask task = em.find(UpdateWorkerTask.class, taskId);

        // Check if task is null.  This can happen if we were in the process of updating a
        // connector instance which was subsequently deleted.  In that case, print a message
        // and return
        if(task==null) {
View Full Code Here

    }

    @Override
    @Transactional(readOnly=false)
    public void addAuditTrail(final long updateWorkerTaskId, final UpdateWorkerTask.AuditTrailEntry auditTrailEntry) {
        UpdateWorkerTask task = em.find(UpdateWorkerTask.class, updateWorkerTaskId);

        // Check if task is null.  This can happen if we were in the process of updating a
        // connector instance which was subsequently deleted.  In that case, print a message
        // and return
        if(task==null) {
            StringBuilder sb = new StringBuilder("module=updateQueue component=connectorUpdateService action=addAuditTrail")
                        .append(" updateWorkerTaskId="+updateWorkerTaskId)
                        .append(" message=\"Ignoring addAuditTrail request for an update task which is no longer in the system (deleted connector?)");
            logger.info(sb);
        }
        else {
            task.addAuditTrailEntry(auditTrailEntry);
        }
    }
View Full Code Here

        } else {
            StringBuilder sb = new StringBuilder("claiming tasks for dispatch, ").append(" availableThreads=" + availableThreads).append(" message=\"adding " + updateWorkerTasks.size() + " update worker tasks\"").append(" activeCount=" + executor.getActiveCount() + " maxPoolSize=" + executor.getMaxPoolSize());
            logger.info(sb);

            for (int i = 0; i < updateWorkerTasks.size(); i++) {
                UpdateWorkerTask task = updateWorkerTasks.get(i);
                task.startTime = null;
                task.endTime = null;
                task.workerThreadName = null;
                task.serverUUID = serverUUID;
                task.status = UpdateWorkerTask.Status.IN_PROGRESS;
                task.addAuditTrailEntry(new UpdateWorkerTask.AuditTrailEntry(new java.util.Date(), serverUUID));
            }
        }
        return updateWorkerTasks;
    }
View Full Code Here

TOP

Related Classes of org.fluxtream.core.domain.UpdateWorkerTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.