Exemplo n.º 1
0
 protected void initProcessStore(EndpointReferenceContext eprContext) {
   _store = createProcessStore(eprContext, _db.getDataSource());
   _store.registerListener(new ProcessStoreListenerImpl());
   _store.setDeployDir(
       _odeConfig.getDeployDir() != null
           ? new File(_odeConfig.getDeployDir())
           : new File(_workRoot, "processes"));
   _store.setConfigDir(_configRoot);
 }
Exemplo n.º 2
0
  public synchronized MyEndpointReference activateEndpoint(QName pid, Endpoint endpoint)
      throws Exception {
    if (__log.isDebugEnabled()) {
      __log.debug("Activate endpoint: " + endpoint);
    }

    OdeService service = _activeOdeServices.get(endpoint);
    if (service == null) service = new OdeService(this, endpoint);
    try {
      ProcessConf pc = _store.getProcessConfiguration(pid);
      InputStream is = pc.getCBPInputStream();
      OProcess compiledProcess = null;
      try {
        Serializer ofh = new Serializer(is);
        compiledProcess = ofh.readOProcess();
      } finally {
        is.close();
      }
      QName portType = null;
      for (Map.Entry<String, Endpoint> provide : pc.getProvideEndpoints().entrySet()) {
        if (provide.getValue().equals(endpoint)) {
          OPartnerLink plink = compiledProcess.getPartnerLink(provide.getKey());
          portType = plink.myRolePortType.getQName();
          break;
        }
      }
      if (portType == null) {
        if (__log.isDebugEnabled()) {
          __log.debug("Could not find PortType for endpoint");
        }
      } else {
        Definition def = pc.getDefinitionForService(endpoint.serviceName);
        if (def == null) {
          __log.debug("Could not find definition for service: " + endpoint.serviceName);
        } else {
          def = new WSDLFlattener(def).getDefinition(portType);
          Document doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(def);
          addEndpointDoc(endpoint.serviceName, doc);
        }
      }
    } catch (Exception e) {
      __log.warn("Exception during endpoint activation", e);
    }
    MyEndpointReference myepr = new MyEndpointReference(service);
    service.activate();
    _activeOdeServices.put(endpoint, service);
    _serviceEprMap.put(service, myepr);
    return myepr;
  }
Exemplo n.º 3
0
  @SuppressWarnings("unchecked")
  private DeploymentPoller getDeploymentPollerExt() {
    DeploymentPoller poller = null;

    InputStream is = null;
    try {
      is = ODEServer.class.getResourceAsStream("/deploy-ext.properties");
      if (is != null) {
        __log.info("A deploy-ext.properties found; will use the provided class if applicable.");
        try {
          Properties props = new Properties();
          props.load(is);
          String deploymentPollerClass = props.getProperty("deploymentPoller.class");
          if (deploymentPollerClass == null) {
            __log.warn(
                "deploy-ext.properties found in the class path; however, the file does not have 'deploymentPoller.class' as one of the properties!!");
          } else {
            Class pollerClass = Class.forName(deploymentPollerClass);
            poller =
                (DeploymentPoller)
                    pollerClass
                        .getConstructor(File.class, ODEServer.class)
                        .newInstance(_store.getDeployDir(), this);
            __log.info(
                "A custom deployment poller: " + deploymentPollerClass + " has been plugged in.");
          }
        } catch (Exception e) {
          __log.warn(
              "Deployment poller extension class is not loadable, falling back to the default DeploymentPoller.",
              e);
        }
      } else if (__log.isDebugEnabled()) __log.debug("No deploy-ext.properties found.");
    } finally {
      try {
        if (is != null) is.close();
      } catch (IOException ie) {
        // ignore
      }
    }

    return poller;
  }
Exemplo n.º 4
0
  private void handleEvent(ProcessStoreEvent pse) {
    if (__log.isDebugEnabled()) {
      __log.debug("Process store event: " + pse);
    }
    ProcessConf pconf = _store.getProcessConfiguration(pse.pid);
    switch (pse.type) {
      case DEPLOYED:
        if (pconf != null) {
          /*
           * If and only if an old process exists with the same pid, the old process is cleaned up.
           * The following line is IMPORTANT and used for the case when the deployment and store
           * do not have the process while the process itself exists in the BPEL_PROCESS table.
           * Notice that the new process is actually created on the 'ACTIVATED' event.
           */
          _bpelServer.cleanupProcess(pconf);
        }
        break;
      case ACTVIATED:
        // bounce the process
        _bpelServer.unregister(pse.pid);
        if (pconf != null) {
          _bpelServer.register(pconf);
        } else {
          __log.debug("slighly odd: recevied event " + pse + " for process not in store!");
        }
        break;
      case RETIRED:
        // are there are instances of this process running?
        boolean instantiated = _bpelServer.hasActiveInstances(pse.pid);
        // remove the process
        _bpelServer.unregister(pse.pid);
        // bounce the process if necessary
        if (instantiated) {
          if (pconf != null) {
            _bpelServer.register(pconf);
          } else {
            __log.debug("slighly odd: recevied event " + pse + " for process not in store!");
          }
        } else {
          // we may have potentially created a lot of garbage, so,
          // let's hope the garbage collector is configured properly.
          if (pconf != null) {
            _bpelServer.cleanupProcess(pconf);
          }
        }
        break;
      case DISABLED:
      case UNDEPLOYED:
        _bpelServer.unregister(pse.pid);
        if (pconf != null) {
          _bpelServer.cleanupProcess(pconf);
        }
        break;
      default:
        __log.debug("Ignoring store event: " + pse);
    }

    if (pconf != null) {
      if (pse.type == ProcessStoreEvent.Type.UNDEPLOYED) {
        __log.debug("Cancelling all cron scheduled jobs on store event: " + pse);
        _bpelServer.getContexts().cronScheduler.cancelProcessCronJobs(pse.pid, true);
      }

      // Except for undeploy event, we need to re-schedule process dependent jobs
      __log.debug("(Re)scheduling cron scheduled jobs on store event: " + pse);
      if (pse.type != ProcessStoreEvent.Type.UNDEPLOYED) {
        _bpelServer.getContexts().cronScheduler.scheduleProcessCronJobs(pse.pid, pconf);
      }
    }
  }
Exemplo n.º 5
0
  /**
   * Shutdown the service engine. This performs cleanup before the BPE is terminated. Once this
   * method has been called, init() must be called before the transformation engine can be started
   * again with a call to start().
   *
   * @throws AxisFault if the engine is unable to shut down.
   */
  public void shutDown() throws AxisFault {

    ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    try {
      if (_poller != null)
        try {
          __log.debug("shutting down poller");
          _poller.stop();
          _poller = null;
        } catch (Throwable t) {
          __log.debug("Error stopping poller.", t);
        }

      if (_bpelServer != null)
        try {
          __log.debug("shutting down ODE server.");
          _bpelServer.shutdown();
          _bpelServer = null;
        } catch (Throwable ex) {
          __log.debug("Error stopping services.", ex);
        }

      if (_cronScheduler != null) {
        try {
          __log.debug("shutting down cron scheduler.");
          _cronScheduler.shutdown();
          _cronScheduler = null;
        } catch (Exception ex) {
          __log.debug("Cron scheduler couldn't be shutdown.", ex);
        }
      }

      if (_scheduler != null)
        try {
          __log.debug("shutting down scheduler.");
          _scheduler.shutdown();
          _scheduler = null;
        } catch (Exception ex) {
          __log.debug("Scheduler couldn't be shutdown.", ex);
        }

      if (_store != null)
        try {
          _store.shutdown();
          _store = null;
        } catch (Throwable t) {
          __log.debug("Store could not be shutdown.", t);
        }

      if (_daoCF != null)
        try {
          _daoCF.shutdown();
        } catch (Throwable ex) {
          __log.debug("DOA shutdown failed.", ex);
        } finally {
          _daoCF = null;
        }

      if (_db != null)
        try {
          _db.shutdown();

        } catch (Throwable ex) {
          __log.debug("DB shutdown failed.", ex);
        } finally {
          _db = null;
        }

      if (_txMgr != null) {
        __log.debug("shutting down transaction manager.");
        _txMgr = null;
      }

      if (_connector != null) {
        try {
          __log.debug("shutdown BpelConnector");
          _connector.shutdown();
          _connector = null;
        } catch (Throwable t) {
          __log.error("Unable to cleanup temp files.", t);
        }
      }
      if (httpConnectionManager != null) {
        __log.debug("shutting down HTTP connection manager.");
        try {
          httpConnectionManager.shutdown();
          httpConnectionManager = null;
        } catch (Throwable t) {
          __log.error("Unable to shut down HTTP connection manager.", t);
        }
      }
      if (idleConnectionTimeoutThread != null) {
        __log.debug("shutting down Idle Connection Timeout Thread.");
        try {
          idleConnectionTimeoutThread.shutdown();
          idleConnectionTimeoutThread = null;
        } catch (Throwable t) {
          __log.error("Unable to shut down Idle Connection Timeout Thread.", t);
        }
      }
      try {
        __log.debug("cleaning up temporary files.");
        TempFileManager.cleanup();
      } catch (Throwable t) {
        __log.error("Unable to cleanup temp files.", t);
      }

      if (_executorService != null) {
        _executorService.shutdownNow();
        _executorService = null;
      }

      __log.info(__msgs.msgOdeShutdownCompleted());
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }
  }
Exemplo n.º 6
0
  public void init(
      String contextPath, ConfigurationContext configContext, ODEConfigProperties config)
      throws ServletException {
    _configContext = configContext;
    String rootDir = System.getProperty("org.apache.ode.rootDir");
    if (rootDir != null) _appRoot = new File(rootDir);
    else _appRoot = new File(contextPath);

    if (!_appRoot.isDirectory())
      throw new IllegalArgumentException(_appRoot + " does not exist or is not a directory");
    TempFileManager.setWorkingDirectory(_appRoot);

    __log.debug("Loading properties");
    String confDir = System.getProperty("org.apache.ode.configDir");
    _configRoot = confDir == null ? new File(_appRoot, "conf") : new File(confDir);
    if (!_configRoot.isDirectory())
      throw new IllegalArgumentException(_configRoot + " does not exist or is not a directory");

    try {
      if (config == null) {
        _odeConfig = new ODEConfigProperties(_configRoot);
        _odeConfig.load();
      } else {
        _odeConfig = config;
      }
    } catch (FileNotFoundException fnf) {
      String errmsg = __msgs.msgOdeInstallErrorCfgNotFound(_odeConfig.getFile());
      __log.warn(errmsg);
    } catch (Exception ex) {
      String errmsg = __msgs.msgOdeInstallErrorCfgReadError(_odeConfig.getFile());
      __log.error(errmsg, ex);
      throw new ServletException(errmsg, ex);
    }

    String wdir = _odeConfig.getWorkingDir();
    if (wdir == null) _workRoot = _appRoot;
    else _workRoot = new File(wdir.trim());
    if (!_workRoot.isDirectory())
      throw new IllegalArgumentException(_workRoot + " does not exist or is not a directory");

    __log.debug("Initializing transaction manager");
    initTxMgr();
    if (txMgrCreatedCallback != null) {
      txMgrCreatedCallback.run();
    }
    __log.debug("Creating data source.");
    initDataSource();
    __log.debug("Starting DAO.");
    initDAO();
    EndpointReferenceContextImpl eprContext = new EndpointReferenceContextImpl(this);
    __log.debug("Initializing BPEL process store.");
    initProcessStore(eprContext);
    __log.debug("Initializing BPEL server.");
    initBpelServer(eprContext);
    __log.debug("Initializing HTTP connection manager");
    initHttpConnectionManager();

    // Register BPEL event listeners configured in axis2.properties file.
    registerEventListeners();
    registerMexInterceptors();
    registerExternalVariableModules();

    _store.loadAll();

    try {
      _bpelServer.start();
    } catch (Exception ex) {
      String errmsg = __msgs.msgOdeBpelServerStartFailure();
      __log.error(errmsg, ex);
      throw new ServletException(errmsg, ex);
    }

    _poller = getDeploymentPollerExt();
    if (_poller == null) {
      _poller = new DeploymentPoller(_store.getDeployDir(), this);
    }

    _mgtService = new ManagementService();
    _mgtService.enableService(
        _configContext.getAxisConfiguration(), _bpelServer, _store, _appRoot.getAbsolutePath());

    try {
      __log.debug("Initializing Deployment Web Service");
      new DeploymentWebService()
          .enableService(
              _configContext.getAxisConfiguration(),
              _store,
              _poller,
              _appRoot.getAbsolutePath(),
              _workRoot.getAbsolutePath());
    } catch (Exception e) {
      throw new ServletException(e);
    }

    __log.debug("Starting scheduler");
    _scheduler.start();

    __log.debug("Initializing JCA adapter.");
    initConnector();

    _poller.start();
    __log.info(__msgs.msgPollingStarted(_store.getDeployDir().getAbsolutePath()));
    __log.info(__msgs.msgOdeStarted());
  }