public void unregister(QName pid) throws BpelEngineException { if (__log.isTraceEnabled()) __log.trace("unregister: " + pid); try { ODEProcess p = _registeredProcesses.remove(pid); if (p == null) return; // TODO Looks like there are some possible bugs here, if a new version of a process gets // deployed, the service will be removed. p.deactivate(); // Remove the process from any services that might reference it. // However, don't remove the service itself from the map. for (List<ODEProcess> processes : _serviceMap.values()) { __log.debug( "removing process " + pid + "; handle " + p + "; exists " + processes.contains(p)); processes.remove(p); } __log.info(__msgs.msgProcessUnregistered(pid)); } catch (Exception ex) { __log.error(__msgs.msgProcessUnregisterFailed(pid), ex); throw new BpelEngineException(ex); } }
public void setProperty(final QName pid, final QName propName, final String value) { if (__log.isDebugEnabled()) __log.debug("Setting property " + propName + " on process " + pid); ProcessConfImpl pconf = _processes.get(pid); if (pconf == null) { String msg = __msgs.msgProcessNotFound(pid); __log.info(msg); throw new ContextException(msg); } final DeploymentUnitDir dudir = pconf.getDeploymentUnit(); exec( new ProcessStoreImpl.Callable<Object>() { public Object call(ConfStoreConnection conn) { DeploymentUnitDAO dudao = conn.getDeploymentUnit(dudir.getName()); if (dudao == null) return null; ProcessConfDAO proc = dudao.getProcess(pid); if (proc == null) return null; proc.setProperty(propName, value); return null; } }); fireEvent(new ProcessStoreEvent(ProcessStoreEvent.Type.PROPERTY_CHANGED, pid, dudir.getName())); }
public void stop() { if (!checkState(State.RUNNING, State.INIT)) { __log.debug("stop() ignored -- already stopped"); return; } __log.debug("BPEL SERVER STOPPING"); _contexts.scheduler.stop(); _state = State.INIT; __log.info(__msgs.msgServerStopped()); }
public void register(ProcessConf conf) { if (conf == null) throw new NullPointerException("must specify non-null process configuration."); __log.debug("register: " + conf.getProcessId()); // Ok, IO out of the way, we will mod the server state, so need to get a // lock. // If the process is already active, do nothing. if (_registeredProcesses.containsKey(conf.getProcessId())) { __log.debug( "skipping doRegister" + conf.getProcessId() + ") -- process is already registered"); return; } __log.debug("Registering process " + conf.getProcessId() + " with server."); ODEProcess process = new ODEProcess(this, conf, null, _myRoleMexCache); for (Endpoint e : process.getServiceNames()) { __log.debug("Register process: serviceId=" + e + ", process=" + process); // Get the list of processes associated with the given service List<ODEProcess> processes = _serviceMap.get(e.serviceName); if (processes == null) { // Create an empty list, if no processes were associated _serviceMap.put(e.serviceName, processes = new ArrayList<ODEProcess>()); } // Remove any older version of the process from the list for (int i = 0; i < processes.size(); i++) { ODEProcess cachedVersion = processes.get(i); __log.debug( "cached version " + cachedVersion.getPID() + " vs registering version " + process.getPID()); if (cachedVersion.getProcessType().equals(process.getProcessType())) { processes.remove(cachedVersion); } } // Add the given process to the list associated with the given service processes.add(process); } process.activate(_contexts); _registeredProcesses.put(process.getPID(), process); if (_dehydrationPolicy == null) process.hydrate(); __log.info(__msgs.msgProcessRegistered(conf.getProcessId())); }
public void start() { if (!checkState(State.INIT, State.RUNNING)) { __log.debug("start() ignored -- already started"); return; } __log.debug("BPEL SERVER starting."); if (_exec == null) { ThreadFactory threadFactory = new ThreadFactory() { int threadNumber = 0; public Thread newThread(Runnable r) { threadNumber += 1; Thread t = new Thread(r, "ODEServerImpl-" + threadNumber); t.setDaemon(true); return t; } }; _exec = Executors.newCachedThreadPool(threadFactory); } if (_contexts.txManager == null) { String errmsg = "Transaction manager not specified; call setTransactionManager(...)!"; __log.fatal(errmsg); throw new IllegalStateException(errmsg); } if (_contexts.scheduler == null) { String errmsg = "Scheduler not specified; call setScheduler(...)!"; __log.fatal(errmsg); throw new IllegalStateException(errmsg); } _contexts.scheduler.start(); _state = State.RUNNING; __log.info(__msgs.msgServerStarted()); if (_dehydrationPolicy != null) new Thread(new ProcessDefReaper()).start(); }
public Collection<QName> undeploy(final String duName) { try { exec( new Callable<Collection<QName>>() { public Collection<QName> call(ConfStoreConnection conn) { DeploymentUnitDAO dudao = conn.getDeploymentUnit(duName); if (dudao != null) dudao.delete(); return null; } }); } catch (Exception ex) { __log.error( "Error synchronizing with data store; " + duName + " may be reappear after restart!"); } Collection<QName> undeployed = Collections.emptyList(); DeploymentUnitDir du; _rw.writeLock().lock(); try { du = _deploymentUnits.remove(duName); if (du != null) { undeployed = toPids(du.getProcessNames(), du.getVersion()); } for (QName pn : undeployed) { fireEvent(new ProcessStoreEvent(ProcessStoreEvent.Type.UNDEPLOYED, pn, du.getName())); __log.info(__msgs.msgProcessUndeployed(pn)); } _processes.keySet().removeAll(undeployed); } finally { _rw.writeLock().unlock(); } return undeployed; }
public void setState(final QName pid, final ProcessState state) { __log.debug("Changing process state for " + pid + " to " + state); final ProcessConfImpl pconf; _rw.readLock().lock(); try { pconf = _processes.get(pid); if (pconf == null) { String msg = __msgs.msgProcessNotFound(pid); __log.info(msg); throw new ContextException(msg); } } finally { _rw.readLock().unlock(); } final DeploymentUnitDir dudir = pconf.getDeploymentUnit(); // Update in the database. ProcessState old = exec( new Callable<ProcessState>() { public ProcessState call(ConfStoreConnection conn) { DeploymentUnitDAO dudao = conn.getDeploymentUnit(dudir.getName()); if (dudao == null) { String errmsg = __msgs.msgProcessNotFound(pid); __log.error(errmsg); throw new ContextException(errmsg); } ProcessConfDAO dao = dudao.getProcess(pid); if (dao == null) { String errmsg = __msgs.msgProcessNotFound(pid); __log.error(errmsg); throw new ContextException(errmsg); } Set processKeys = _processes.keySet(); Iterator processConfQNameItr = processKeys.iterator(); while (processConfQNameItr.hasNext()) { ProcessConf cachedProcessConf = _processes.get(processConfQNameItr.next()); if (dao.getType().equals(cachedProcessConf.getType())) { if (ProcessState.ACTIVE == cachedProcessConf.getState() && ProcessState.RETIRED == dao.getState() && ProcessState.ACTIVE == state) { String errorMsg = "Can't activate the process with PID: " + dao.getPID() + " with version " + dao.getVersion() + ", as another version of the process with PID : " + cachedProcessConf.getProcessId() + " with version " + cachedProcessConf.getVersion() + " is already active."; __log.error(errorMsg); throw new ContextException(errorMsg); } } } ProcessState old = dao.getState(); dao.setState(state); pconf.setState(state); return old; } }); pconf.setState(state); if (old != null && old != state) fireStateChange(pid, state, pconf.getDeploymentUnit().getName()); }
/** Deploys a process. */ public Collection<QName> deploy( final File deploymentUnitDirectory, boolean activate, String duName, boolean autoincrementVersion) { __log.info(__msgs.msgDeployStarting(deploymentUnitDirectory)); final Date deployDate = new Date(); // Create the DU and compile/scan it before acquiring lock. final DeploymentUnitDir du = new DeploymentUnitDir(deploymentUnitDirectory); if (duName != null) { // Override the package name if given from the parameter du.setName(duName); } long version; if (autoincrementVersion || du.getStaticVersion() == -1) { // Process and DU use a monotonically increased single version number by default. try { version = getCurrentVersion(); } finally { // we need to reset the current version thread local value. _currentVersion.set(null); } } else { version = du.getStaticVersion(); } du.setVersion(version); try { du.compile(); } catch (CompilationException ce) { String errmsg = __msgs.msgDeployFailCompileErrors(ce); __log.error(errmsg, ce); throw new ContextException(errmsg, ce); } du.scan(); final DeployDocument dd = du.getDeploymentDescriptor(); final ArrayList<ProcessConfImpl> processes = new ArrayList<ProcessConfImpl>(); Collection<QName> deployed; _rw.writeLock().lock(); try { if (_deploymentUnits.containsKey(du.getName())) { String errmsg = __msgs.msgDeployFailDuplicateDU(du.getName()); __log.error(errmsg); throw new ContextException(errmsg); } retirePreviousPackageVersions(du); for (TDeployment.Process processDD : dd.getDeploy().getProcessArray()) { QName pid = toPid(processDD.getName(), version); if (_processes.containsKey(pid)) { String errmsg = __msgs.msgDeployFailDuplicatePID(processDD.getName(), du.getName()); __log.error(errmsg); throw new ContextException(errmsg); } QName type = processDD.getType() != null ? processDD.getType() : processDD.getName(); CBPInfo cbpInfo = du.getCBPInfo(type); if (cbpInfo == null) { String errmsg = __msgs.msgDeployFailedProcessNotFound(processDD.getName(), du.getName()); __log.error(errmsg); throw new ContextException(errmsg); } ProcessConfImpl pconf = new ProcessConfImpl( pid, processDD.getName(), version, du, processDD, deployDate, calcInitialProperties(du.getProperties(), processDD), calcInitialState(processDD), eprContext, _configDir, generateProcessEventsAll); processes.add(pconf); } _deploymentUnits.put(du.getName(), du); for (ProcessConfImpl process : processes) { __log.info(__msgs.msgProcessDeployed(du.getDeployDir(), process.getProcessId())); _processes.put(process.getProcessId(), process); } } finally { _rw.writeLock().unlock(); } // Do the deployment in the DB. We need this so that we remember deployments across system // shutdowns. // We don't fail if there is a DB error, simply print some errors. deployed = exec( new Callable<Collection<QName>>() { public Collection<QName> call(ConfStoreConnection conn) { // Check that this deployment unit is not deployed. DeploymentUnitDAO dudao = conn.getDeploymentUnit(du.getName()); if (dudao != null) { String errmsg = "Database out of synch for DU " + du.getName(); __log.warn(errmsg); dudao.delete(); } dudao = conn.createDeploymentUnit(du.getName()); try { dudao.setDeploymentUnitDir(deploymentUnitDirectory.getCanonicalPath()); } catch (IOException e1) { String errmsg = "Error getting canonical path for " + du.getName() + "; deployment unit will not be available after restart!"; __log.error(errmsg); } ArrayList<QName> deployed = new ArrayList<QName>(); // Going trough each process declared in the dd for (ProcessConfImpl pc : processes) { try { ProcessConfDAO newDao = dudao.createProcess(pc.getProcessId(), pc.getType(), pc.getVersion()); newDao.setState(pc.getState()); for (Map.Entry<QName, Node> prop : pc.getProcessProperties().entrySet()) { newDao.setProperty(prop.getKey(), DOMUtils.domToString(prop.getValue())); } deployed.add(pc.getProcessId()); } catch (Throwable e) { String errmsg = "Error persisting deployment record for " + pc.getProcessId() + "; process will not be available after restart!"; __log.error(errmsg, e); } } return deployed; } }); _rw.readLock().lock(); boolean readLockHeld = true; try { for (ProcessConfImpl process : processes) { fireEvent( new ProcessStoreEvent( ProcessStoreEvent.Type.DEPLOYED, process.getProcessId(), process.getDeploymentUnit().getName())); fireStateChange( process.getProcessId(), process.getState(), process.getDeploymentUnit().getName()); } } catch (Exception e) { // need to unlock as undeploy operation will need a writeLock _rw.readLock().unlock(); readLockHeld = false; // A problem at that point means that engine deployment failed, we don't want the store to // keep the du __log.warn("Deployment failed within the engine, store undeploying process.", e); undeploy(deploymentUnitDirectory); if (e instanceof ContextException) throw (ContextException) e; else throw new ContextException("Deployment failed within the engine. " + e.getMessage(), e); } finally { if (readLockHeld) _rw.readLock().unlock(); } return deployed; }