Examples of DuccWorkJob


Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

        submitError(properties, error_message);
      }
      else {
        logger.debug(methodName, null, messages.fetch("job driver host")+" "+messages.fetchLabel("IP")+nodeIdentity.getIp()+" "+messages.fetchLabel("name")+nodeIdentity.getName());
        if(Validate.request(duccEvent)) {
          DuccWorkJob duccWorkJob = jobFactory.create(common,properties);
          long t0 = System.currentTimeMillis();
          workMap.addDuccWork(duccWorkJob);
          long t1 = System.currentTimeMillis();
          long elapsed = t1 - t0;
          if(elapsed > Constants.SYNC_LIMIT) {
            logger.debug(methodName, null, "elapsed msecs: "+elapsed);
          }
          // state: Received
          stateJobAccounting.stateChange(duccWorkJob, JobState.Received);
          OrchestratorCheckpoint.getInstance().saveState();
          // state: WaitingForServices
          JobState nextState = JobState.WaitingForServices;
          if(duccWorkJob.getServiceDependencies() == null) {
            String message = messages.fetch("bypass")+" "+nextState;
            logger.debug(methodName, duccWorkJob.getDuccId(), message);
            nextState = JobState.WaitingForResources;
          }
          stateJobAccounting.stateChange(duccWorkJob, nextState);
          OrchestratorCheckpoint.getInstance().saveState();
          // prepare for reply to submitter
          properties.put(JobRequestProperties.key_id, duccWorkJob.getId());
          duccEvent.setProperties(properties);
        }
        else {
          logger.info(methodName, null, messages.fetch("TODO")+" prepare error reply");
          //TODO
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

    }
    else if(Validate.request(duccEvent)) {
      // update state
      String jobId = properties.getProperty(JobRequestProperties.key_id);
      long t0 = System.currentTimeMillis();
      DuccWorkJob duccWorkJob = (DuccWorkJob) workMap.findDuccWork(DuccType.Service,jobId);
      long t1 = System.currentTimeMillis();
      long elapsed = t1 - t0;
      if(elapsed > Constants.SYNC_LIMIT) {
        logger.debug(methodName, dwid, "elapsed msecs: "+elapsed);
      }
      DuccContext context = duccEvent.getContext();
      if(duccWorkJob != null) {
        dwid = duccWorkJob.getDuccId();
        String reqUser = properties.getProperty(JobRequestProperties.key_user).trim();
        String reqRole = getRole(properties);
        String tgtUser = duccWorkJob.getStandardInfo().getUser().trim();
        if(isAuthorized(dwid, reqUser, tgtUser, reqRole)) {
          logger.debug(methodName, dwid, "reqUser:"+reqUser+" "+"reqRole:"+reqRole+" "+"tgtUser:"+tgtUser);
          String type;
          switch(context) {
          case ManagedReservation:
            type = "managed reservation";
            break;
          default:
            type = "service";
            break;
          }
          IRationale rationale = new Rationale(type+" canceled by "+reqUser);
          JobCompletionType jobCompletionType = JobCompletionType.CanceledByUser;
          if(reqRole.equals(SpecificationProperties.key_role_administrator)) {
            jobCompletionType = JobCompletionType.CanceledByAdministrator;
          }
          stateManager.jobTerminate(duccWorkJob, jobCompletionType, rationale, ProcessDeallocationType.JobCanceled);
          OrchestratorCheckpoint.getInstance().saveState();
          // prepare for reply to canceler
          properties.put(JobReplyProperties.key_message, JobReplyProperties.msg_canceled);
          duccEvent.setProperties(properties);
          logger.info(methodName, dwid, messages.fetchLabel(type+" state")+duccWorkJob.getJobState());
        }
        else {
          // prepare not authorized reply
          properties.put(JobReplyProperties.key_message, JobReplyProperties.msg_user_not_authorized);
          duccEvent.setProperties(properties);
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

    protected void handleDeletedJobs(Map<DuccId, IDuccWork> work)
    {
        String methodName = "handleCompletedJobs";

        for ( DuccId id : work.keySet() ) {
            DuccWorkJob w = (DuccWorkJob) work.get(id);
           
            String[] deps = w.getServiceDependencies();
            if ( deps == null ) {   // no deps, just mark it running and move on
                logger.info(methodName, id, "No service dependencies, no updates made.");
                continue;
            }
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

        //
        // Everything is already in the service map so we just update the state.
        //
        for ( DuccId id : work.keySet() ) {
           
            DuccWorkJob j = (DuccWorkJob) work.get(id);
            String[] deps = j.getServiceDependencies();
            if ( deps == null ) {   // no deps, just mark it running and move on
                logger.info(methodName, id, "No service dependencies, no updates made.");
                continue;
            }

            ServiceDependency s = serviceMap.get(id);
            if ( j.isFinished() ) {
                stopDependentServices(id);
                s.setState(ServiceState.NotAvailable);
                s.clearMessages();
            } else  if ( j.isActive() ) {
                resolveState(id, s);
            }
        }

    }
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

        String methodName = "handleNewServices";

        Map<DuccId, ServiceDependency>  updates = new HashMap<DuccId, ServiceDependency>();   // to be added to the service map sent to OR
        Map<String, ServiceSet>     newservices = new HashMap<String, ServiceSet>();          // to be added to our internal maps in serviceState
        for ( DuccId id : work.keySet() ) {
            DuccWorkJob w = (DuccWorkJob) work.get(id);

            //
            // On restart we sometimes get stale stuff that we just ignore.
            // What else? Is the the right thing to do?
            // 
            if ( !w.isActive() ) {
                logger.info(methodName, id, "Bypassing inactive service, state=", w.getStateObject());
                continue;
            }

            ServiceDependency s = new ServiceDependency();
            updates.put(id, s);

            String endpoint = w.getServiceEndpoint();
            if ( endpoint == null ) {                                     // the job is damaged if this happens
                String msg = "No service endpoint.  Service cannot be validated.";
                logger.warn(methodName, id, msg);
                s.addMessage("null", msg);                                // this is a fatal state always
                s.setState(ServiceState.NotAvailable);
                continue;
            }

            String[] deps = w.getServiceDependencies();                  // other services this svc depends on
            ServiceSet sset = serviceStateHandler.getServiceByName(endpoint);
            if ( sset == null ) {
                // submitted, we just track but not much else
                try {
                    sset = new ServiceSet(serviceManager.newId(), id, endpoint, deps);             // creates a "submitted" service
                    sset.addImplementor(id, w.getJobState());
                    serviceStateHandler.putServiceByName(endpoint, sset);
                } catch ( Exception e ) {
                    s.addMessage(endpoint, e.getMessage());
                    s.setState(ServiceState.NotAvailable);
                    continue;
                }
            } else if ( sset.isDeregistered() ) {
                s.addMessage(endpoint, "Duplicate endpoint: terminating deregistered service.");
                s.setState(ServiceState.NotAvailable);
                continue;
            } else if ( sset.matches(id) ) {
                // TODO: not clear we have to do anything here since establish() below will
                //       add to the implementors.  Be sure to update the check so the
                //       code in the following 'else' clause is executed correctly though.

                // and instance/implementor of our own registered services
                sset.addImplementor(id, w.getJobState());
            } else {
                //
                // If the new service is not a registered service, and it is a duplicate of another service
                // which isn't registered, we allow it to join the party.
                //
                // When it joins, it needs to "propmote" the ServiceSet to "Submitted".
                //
                // a) in the case of "implicit" we don't know enough to many any moral judgements at all
                // b) in the case of "submitted" it could be the user is increasing the pool of servers by
                //    submitting more jobs.  Perhaps we would better handle this via modify but for the moment,
                //    just allow it.
                // c) in the case of "registered" we know and manage everything and don't allow it.  users must
                //    use the services modify api to increase or decrease instances.
                //

                if ( !sset.isRegistered() ) {
                    sset.addImplementor(id, w.getJobState());
                    sset.promote();          // we'll do this explicitly as a reminder that it's happening and
                                             // to insure we NEVER promote a registered service (which is actually
                                             // a demotion!).
                } else {
                    String msg = "Duplicate endpoint: Registered service.";
                    logger.warn(methodName, id, msg);
                    s.addMessage(endpoint, msg);
                    s.setState(ServiceState.NotAvailable);
                    continue;
                }
            }

            // The service is new and unique if we get this far

            //
            // No deps.  Put it in the map and move on.
            //
            if ( deps == null ) {               
                logger.info(methodName, id, "Added service to map, no service dependencies. ");
                s.setState(ServiceState.Available);                        // good to go in the OR (the state of things i'm dependent upon)
                sset.establish(id, w.getJobState());                       // sets my own state based entirely on state of w
                continue;
            }

            Map<String, ServiceSet> jobServices = resolveDependencies(w, s); //
            for ( ServiceSet depset : jobServices.values() ) {
                depset.establish();
            }
            resolveState(id, s);
            sset.establish(id, w.getJobState());
            logger.info(methodName, id, "Added to map, with service dependencies,", s.getState());
        }

        serviceStateHandler.recordNewServices(newservices);
        serviceMap.putAll(updates);
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

    protected void handleDeletedServices(Map<DuccId, IDuccWork> work)
    {
        String methodName = "handleDeletedServices";

        for ( DuccId id : work.keySet() ) {
          DuccWorkJob w = (DuccWorkJob) work.get(id);
          String endpoint = w.getServiceEndpoint();
            logger.info(methodName, id, "Deleted service:", endpoint);
           
            //
            // Dereference and maybe stop the services I'm dependent upon
            //
            if ( w.getServiceDependencies() == null ) {
                logger.info(methodName, id, "No service dependencies to update on removal.");
            } else {
                stopDependentServices(id);        // update references, remove implicit services if any
            }
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

       
        //
        // This is a specific service process, but not necessarily the whole service.
        //
        for ( DuccId id : work.keySet() ) {
            DuccWorkJob w = (DuccWorkJob) work.get(id);
            String endpoint = w.getServiceEndpoint();

            if (endpoint == null ) {              // probably impossible but lets not chance NPE
                logger.info(methodName, id, "Missing service endpoint, ignoring.");
                continue;
            }

            ServiceSet sset = serviceStateHandler.getServiceByName(endpoint);
            if ( sset == null ) {
                // may have already died and this is just leftover OR publications.
                if ( w.isActive() ) {             // or maybe we just screwed up!
                    logger.info(methodName, id, "Got update for active service instance", id.toString(), "but no ServiceSet! Job state:", w.getJobState());
                    continue;
                }
                continue;
            }
           
            if ( !sset.containsImplementor(id) ) {
                logger.info(methodName, id, "Bypassing removed service instance for", endpoint);
                continue;
            }
       
            ServiceDependency s = serviceMap.get(id);
            if ( w.isFinished() ) {              // nothing more, just dereference and maybe stop stuff I'm dependent upon
                stopDependentServices(id);
                s.setState(ServiceState.NotAvailable);              // tell orchestrator
            } else  if ( w.getServiceDependencies() != null ) {     // update state from things I'm dependent upon
                resolveState(id, s);
            }

            // See what happened to the instance ...
            if w.isActive() ) {
                // Hard to know for sure, if there are a bunch of instances, some working and some not, how to manage this.
                // But this is a state *change* of something, and the something is active, so probably the service is OK now
                // if it hadn't been before.
               
                // Need to be cautious here - this will get reset if ANYthing is running.  So we could have a bunch
                // of live instances and some new ones, where the live ones are ok but for some reason we can't start
                // new ones, in which case this gets set too often.
                //
                // This seems like it would be rare and since we aren't actually pounding restarts (only attempts every
                // SM cycle) maybe its ok.  The alternative is to track state changes which is added complexity - for
                // waht gain, we need to determine with experience.
                //
                // I suppose the ServiceManagerHandler could easily track the per-process state change - we'd have to
                // modify the thing in the map it passes in to show 'before' and 'after' states instead of just passing
                // in the DuccWork thing.
                //
                JobState          state = w.getJobState();
                if ( state == JobState.Running ) {         // only if we confirm it's alive
                    sset.resetRunFailures();
                }
            } else {
                JobState          state = w.getJobState();
               
                if ( state == JobState.Completed ) {
                    sset.removeImplementor(id);
                    JobCompletionType jct = w.getCompletionType();
                       
                    logger.info(methodName, id, "Removing stopped instance from maps: state[", state, "] completion[", jct, "]");
                    switch ( jct ) {
                        case EndOfJob:
                        case CanceledByUser:
                        case CanceledByAdministrator:
                        case Undefined:
                            break;
                        default:
                            logger.debug(methodName, id, "RECORDING FAILURE");
                            // all other cases are errors that contribute to the error count
                            if ( sset.excessiveRunFailures() ) {    // if true, the count is exceeeded, but reset
                                logger.warn(methodName, null, "Process Failure: " + jct + " Maximum consecutive failures[" + sset.failure_run + "] max [" + sset.failure_max + "]");
                            } else {
                                sset.start();
                            }
                            break;
                    }
                }
            }

            // Now factor in cumulative state of the implementors and manage the ping thread as needed
            sset.establish(id, w.getJobState());

            if ( (sset.getServiceState() == ServiceState.NotAvailable) && (sset.countReferences() == 0) && (sset.countImplementors() == 0) ) {
                // this service is now toast.  remove from our maps asap to avoid clashes if it gets
                // resubmitted before the OR can purge it.
                if ( ! sset.isRegistered() ) {
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

  public IDuccWork getDuccWork() {
    return _dw;
  }
 
  public DuccWorkJob getJob() {
    DuccWorkJob retVal = null;
    if(_dw instanceof DuccWorkJob) {
      retVal = (DuccWorkJob) _dw;
    }
    return retVal;
  }
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

    public synchronized void synchronizeHandler(DuccWorkMap work)
    {
        Map<DuccId, JobState> ids = new HashMap<DuccId, JobState>();
        for ( IDuccWork w : work.values() ) {
            if ( w.getDuccType() != DuccType.Service ) continue;
            DuccWorkJob j = (DuccWorkJob) w;
            if ( !j.isActive() ) continue;
            ids.put(j.getDuccId(), j.getJobState());
        }
        handler.synchronizeImplementors(ids);
    }
View Full Code Here

Examples of org.apache.uima.ducc.transport.event.common.DuccWorkJob

    po.remove(id);
    id = new DuccId(0);
    po.remove(id);
    PagingInfo pi = new PagingInfo();
    pi.display();
    IDuccWorkJob job = new DuccWorkJob();
    pi = new PagingInfo(job);
    pi.display();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.