Package org.ejbca.core.model.services

Examples of org.ejbca.core.model.services.ServiceConfiguration


        if (log.isTraceEnabled()) {
            log.trace(">activateServiceTimer(name: " + name + ")");
        }
        ServiceData htp = serviceDataSession.findByName(name);
        if (htp != null) {
            ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
            if (isAuthorizedToEditService(admin, serviceConfiguration)) {
                IWorker worker = getWorker(serviceConfiguration, name, htp.getRunTimeStamp(), htp.getNextRunTimeStamp());
                if (worker != null) {
                    serviceSession.cancelTimer(htp.getId());
                    if (serviceConfiguration.isActive() && worker.getNextInterval() != IInterval.DONT_EXECUTE) {
                        addTimer(worker.getNextInterval() * 1000, htp.getId());
                    }
                }
            } else {
                logSession.log(admin, admin.getCaId(), LogConstants.MODULE_SERVICES, new Date(), null, null, LogConstants.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,
View Full Code Here


    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    @Override
    public IWorker getWorkerIfItShouldRun(Integer serviceId, long nextTimeout) {
      IWorker worker = null;
        ServiceData serviceData = serviceDataSession.findById(serviceId);
        ServiceConfiguration serviceConfiguration = serviceData.getServiceConfiguration();
        if (!serviceConfiguration.isActive()) {
            if (log.isDebugEnabled()) {
              log.debug("Service " + serviceId + " is inactive.");
            }
          return null// Don't return an inactive worker to run
        }
        String serviceName = serviceData.getName();
        final String hostname = getHostName();
        if (shouldRunOnThisNode(hostname, Arrays.asList(serviceConfiguration.getPinToNodes()))) {
          long oldRunTimeStamp = serviceData.getRunTimeStamp();
          long oldNextRunTimeStamp = serviceData.getNextRunTimeStamp();
          worker = getWorker(serviceConfiguration, serviceName, oldRunTimeStamp, oldNextRunTimeStamp);
          if (worker.getNextInterval() == IInterval.DONT_EXECUTE) {
              if (log.isDebugEnabled()) {
                log.debug("Service has interval IInterval.DONT_EXECUTE.");
              }
            return null// Don't return an inactive worker to run
          }
          Date runDateCheck = new Date(oldNextRunTimeStamp); // nextRunDateCheck will typically be the same (or just a millisecond earlier) as now here
          Date currentDate = new Date();
          if (log.isDebugEnabled()) {
            Date nextRunDate = new Date(nextTimeout);
            log.debug("nextRunDate is:  " + nextRunDate);
            log.debug("runDateCheck is: " + runDateCheck);
            log.debug("currentDate is:  " + currentDate);
          }
          /*
           * Check if the current date is after when the service should run. If a
           * service on another cluster node has updated this timestamp already,
           * then it will return false and this service will not run. This is a
           * semaphore (not the best one admitted) so that services in a cluster
           * only runs on one node and don't compete with each other. If a worker
           * on one node for instance runs for a very long time, there is a chance
           * that another worker on another node will break this semaphore and run
           * as well.
           */
          if (currentDate.after(runDateCheck)) {
              /*
               * We only update the nextRunTimeStamp if the service is allowed to run on this node.
               *
               * However, we need to make sure that no other node has already acquired the semaphore
               * if our current database allows non-repeatable reads.
               */
            if (!serviceDataSession.updateTimestamps(serviceId, oldRunTimeStamp, oldNextRunTimeStamp, runDateCheck.getTime(), nextTimeout)) {
              log.debug("Another node had already updated the database at this point. This node will not run.");
              worker = null// Failed to update the database.
            }
          } else {
            worker = null// Don't return a worker, since this node should not run
          }
        } else {
          worker = null;
      if (log.isDebugEnabled()) {
        log.debug("Service " + serviceName + " will not run on this node: \"" + hostname + "\", Pinned to: " + Arrays.toString(serviceConfiguration.getPinToNodes()));
      }
        }
        return worker;
    }
View Full Code Here

        while (iter2.hasNext()) {
            Integer id = iter2.next();
            ServiceData htp = serviceDataSession.findById(id);
            if (htp != null) {
                if (!existingTimers.contains(id)) {
                  ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
                    IWorker worker = getWorker(serviceConfiguration, idToNameMap.get(id), htp.getRunTimeStamp(), htp.getNextRunTimeStamp());
                    if (worker != null && serviceConfiguration.isActive() && worker.getNextInterval() != IInterval.DONT_EXECUTE) {
                      ret.put(id, Long.valueOf((worker.getNextInterval()) * 1000));
                    }
                }             
            } else {
          // Service does not exist, strange, but no panic.
View Full Code Here

    @Override
    public long getServiceInterval(Integer serviceId) {
      long ret = IInterval.DONT_EXECUTE;
        ServiceData htp = serviceDataSession.findById(serviceId);
        if (htp != null) {
          ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
            if (serviceConfiguration.isActive()) {
                IWorker worker = getWorker(serviceConfiguration, "temp", 0, 0)// A bit dirty, but it works..
                if (worker!=null) {
                    ret = worker.getNextInterval();
                }
            } else {
View Full Code Here

    @Override
    public ServiceConfiguration getServiceConfiguration(Admin admin, int id) {
        if (log.isTraceEnabled()) {
            log.trace(">getServiceConfiguration: " + id);
        }
        ServiceConfiguration returnval = null;
        try {
            ServiceData serviceData = serviceDataSession.findById(Integer.valueOf(id));
            if (serviceData != null) {
                returnval = serviceData.getServiceConfiguration();
            } else {
View Full Code Here

TOP

Related Classes of org.ejbca.core.model.services.ServiceConfiguration

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.