use of org.wso2.carbon.bpel.stub.mgt.ProcessManagementException in project carbon-business-process by wso2.
the class ProcessManagementServiceSkeleton method getProcessDefinition.
private OMElement getProcessDefinition(ProcessConf pConf) throws ProcessManagementException {
if (pConf == null) {
String errMsg = "Process configuration cannot be null.";
log.error(errMsg);
throw new ProcessManagementException(errMsg);
}
String bpelDoc = pConf.getBpelDocument();
List<File> files = pConf.getFiles();
for (final File file : files) {
if (file.getPath().endsWith(bpelDoc) || file.getPath().endsWith(bpelDoc.replaceAll("/", "\\\\"))) {
XMLStreamReader reader;
FileInputStream fis = null;
OMElement bpelDefinition;
try {
fis = new FileInputStream(file);
XMLInputFactory xif = XMLInputFactory.newInstance();
reader = xif.createXMLStreamReader(fis);
StAXOMBuilder builder = new StAXOMBuilder(reader);
bpelDefinition = builder.getDocumentElement();
bpelDefinition.build();
} catch (XMLStreamException e) {
String errMsg = "XML stream reader exception: " + file.getAbsolutePath();
log.error(errMsg, e);
throw new ProcessManagementException(errMsg, e);
} catch (FileNotFoundException e) {
String errMsg = "BPEL File reading exception: " + file.getAbsolutePath();
log.error(errMsg, e);
throw new ProcessManagementException(errMsg, e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
log.warn("Cannot close file input stream.", e);
}
}
}
return bpelDefinition;
}
}
String errMsg = "Process Definition for: " + pConf.getProcessId() + " not found";
log.error(errMsg);
throw new ProcessManagementException(errMsg);
}
use of org.wso2.carbon.bpel.stub.mgt.ProcessManagementException in project carbon-business-process by wso2.
the class ProcessManagementServiceSkeleton method processQuery.
/**
* Query processes based on a {@link org.apache.ode.bpel.common.ProcessFilter} criteria. This is
* implemented in memory rather than via database calls since the processes
* are managed by the {@link org.apache.ode.bpel.iapi.ProcessStore} object and we don't want to make
* this needlessly complicated.
*
* @param filter process filter
* @param tenantsProcessStore Current Tenant's process store
* @return ProcessConf collection
* @throws ProcessManagementException if an error occurred while processing query
*/
private Collection<ProcessConf> processQuery(ProcessFilter filter, TenantProcessStoreImpl tenantsProcessStore) throws ProcessManagementException {
Map<QName, ProcessConfigurationImpl> processes = tenantsProcessStore.getProcessConfigMap();
if (log.isDebugEnabled()) {
for (Map.Entry<QName, ProcessConfigurationImpl> process : processes.entrySet()) {
log.debug("Process " + process.getKey() + " in state " + process.getValue());
}
}
Set<QName> pids = processes.keySet();
// Name filter can be implemented using only the PIDs.
if (filter != null && filter.getNameFilter() != null) {
// adding escape sequences to [\^$.|?*+(){} characters
String nameFilter = filter.getNameFilter().replace("\\", "\\\\").replace("]", "\\]").replace("[", "\\[").replace("^", "\\^").replace("$", "\\$").replace("|", "\\|").replace("?", "\\?").replace(".", "\\.").replace("+", "\\+").replace("(", "\\(").replace(")", "\\)").replace("{", "\\{").replace("}", "\\}").replace("*", ".*");
final Pattern pattern = Pattern.compile(nameFilter + "(-\\d*)?");
CollectionsX.remove_if(pids, new MemberOfFunction<QName>() {
@Override
public boolean isMember(QName o) {
return !pattern.matcher(o.getLocalPart()).matches();
}
});
}
if (filter != null && filter.getNamespaceFilter() != null) {
// adding escape sequences to [\^$.|?*+(){} characters
String namespaceFilter = filter.getNamespaceFilter().replace("\\", "\\\\").replace("]", "\\]").replace("[", "\\[").replace("^", "\\^").replace("$", "\\$").replace("|", "\\|").replace("?", "\\?").replace(".", "\\.").replace("+", "\\+").replace("(", "\\(").replace(")", "\\)").replace("{", "\\{").replace("}", "\\}").replace("*", ".*");
final Pattern pattern = Pattern.compile(namespaceFilter);
CollectionsX.remove_if(pids, new MemberOfFunction<QName>() {
@Override
public boolean isMember(QName o) {
String ns = o.getNamespaceURI() == null ? "" : o.getNamespaceURI();
return !pattern.matcher(ns).matches();
}
});
}
// Now we need the process conf objects, we need to be
// careful since someone could have deleted them by now
List<ProcessConf> confs = new LinkedList<ProcessConf>();
for (QName pid : pids) {
ProcessConf pConf = tenantsProcessStore.getProcessConfiguration(pid);
if (pConf != null) {
confs.add(pConf);
}
}
if (filter != null) {
// Specific filter for deployment date.
if (filter.getDeployedDateFilter() != null) {
for (final String ddf : filter.getDeployedDateFilter()) {
final Date dd;
try {
dd = ISO8601DateParser.parse(Filter.getDateWithoutOp(ddf));
} catch (ParseException e) {
// Should never happen.
String errMsg = "Exception while parsing date";
log.error(errMsg, e);
throw new ProcessManagementException(errMsg, e);
}
CollectionsX.remove_if(confs, new MemberOfFunction<ProcessConf>() {
@Override
public boolean isMember(ProcessConf o) {
if (ddf.startsWith("=")) {
return !o.getDeployDate().equals(dd);
}
if (ddf.startsWith("<=")) {
return o.getDeployDate().getTime() > dd.getTime();
}
if (ddf.startsWith(">=")) {
return o.getDeployDate().getTime() < dd.getTime();
}
if (ddf.startsWith("<")) {
return o.getDeployDate().getTime() >= dd.getTime();
}
return ddf.startsWith(">") && (o.getDeployDate().getTime() <= dd.getTime());
}
});
}
}
// Ordering
if (filter.getOrders() != null) {
ComparatorChain cChain = new ComparatorChain();
for (String key : filter.getOrders()) {
boolean ascending = true;
String orderKey = key;
if (key.startsWith("+") || key.startsWith("-")) {
orderKey = key.substring(1, key.length());
if (key.startsWith("-")) {
ascending = false;
}
}
Comparator c;
if ("name".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
return o1.getProcessId().getLocalPart().compareTo(o2.getProcessId().getLocalPart());
}
};
} else if ("namespace".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
String ns1 = o1.getProcessId().getNamespaceURI() == null ? "" : o1.getProcessId().getNamespaceURI();
String ns2 = o2.getProcessId().getNamespaceURI() == null ? "" : o2.getProcessId().getNamespaceURI();
return ns1.compareTo(ns2);
}
};
} else if ("version".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
return (int) (o1.getVersion() - o2.getVersion());
}
};
} else if ("deployed".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
return o1.getDeployDate().compareTo(o2.getDeployDate());
}
};
} else if ("status".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
return o1.getState().compareTo(o2.getState());
}
};
} else {
// unrecognized
if (log.isDebugEnabled()) {
log.debug("unrecognized order key" + orderKey);
}
continue;
}
cChain.addComparator(c, !ascending);
}
Collections.sort(confs, cChain);
}
}
return confs;
}
use of org.wso2.carbon.bpel.stub.mgt.ProcessManagementException in project carbon-business-process by wso2.
the class ProcessManagementServiceSkeleton method getProcessInfo.
public ProcessInfoType getProcessInfo(QName pid) throws ProcessManagementException {
ProcessInfoType processInfoType = new ProcessInfoType();
TenantProcessStoreImpl tenantProcessStore = AdminServiceUtils.getTenantProcessStore();
ProcessConf processConf = tenantProcessStore.getProcessConfiguration(pid);
fillProcessInfo(processInfoType, processConf, ProcessInfoCustomizer.ALL, tenantProcessStore);
return processInfoType;
}
use of org.wso2.carbon.bpel.stub.mgt.ProcessManagementException in project carbon-business-process by wso2.
the class BPELPackageRepository method readPropertiesOfUpdatedDeploymentInfo.
/**
* Reads the updated properties from registry and sets the process configuration fields
*
* @param processConfiguration - Process's configuration details after updated
* @param bpelPackageName - the relevant bpel package
* @throws RegistryException on registry rollback error case, we'll init the cause to the
* original exception we got when accessing registry
* @throws ProcessManagementException
*/
public void readPropertiesOfUpdatedDeploymentInfo(ProcessConfigurationImpl processConfiguration, String bpelPackageName) throws RegistryException, ProcessManagementException {
String versionlessPackageName = BPELPackageRepositoryUtils.getVersionlessPackageName(bpelPackageName);
String packageLocation = BPELPackageRepositoryUtils.getResourcePathForDeployInfoUpdatedBPELPackage(processConfiguration.getPackage(), versionlessPackageName);
Resource bpelPackage = configRegistry.get(packageLocation);
String stateInString = bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_STATE + processConfiguration.getProcessId());
String inMemoryInString = bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_INMEMORY + processConfiguration.getProcessId());
String processEventsInString = bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_EVENTS + processConfiguration.getProcessId());
String generateTypeString = bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_EVENT_GENERATE + processConfiguration.getProcessId());
String successCleanupsInString = bpelPackage.getProperty(BPELConstants.BPEL_INSTANCE_CLEANUP_SUCCESS + processConfiguration.getProcessId());
String failureCleanupsInString = bpelPackage.getProperty(BPELConstants.BPEL_INSTANCE_CLEANUP_FAILURE + processConfiguration.getProcessId());
// editor has been updated, read the updated fields
if (stateInString != null) {
ProcessState state = BPELPackageRepositoryUtils.getProcessState(stateInString);
processConfiguration.setState(state);
processConfiguration.setIsTransient(Boolean.parseBoolean(inMemoryInString));
ProcessEventsListType processEventsList = new ProcessEventsListType();
EnableEventListType enabledEventList = BPELPackageRepositoryUtils.getEnabledEventsListFromString(processEventsInString);
processEventsList.setEnableEventsList(enabledEventList);
Generate_type1 generateType = BPELPackageRepositoryUtils.getProcessGenerateTypeFromString(generateTypeString);
processEventsList.setGenerate(generateType);
ScopeEventListType scopeEventList = new ScopeEventListType();
int j = 0;
while (bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_SCOPE_EVENT + (j + 1) + processConfiguration.getProcessId()) != null) {
ScopeEventType scopeEvent = BPELPackageRepositoryUtils.getScopeEventFromString(bpelPackage.getProperty(BPELConstants.BPEL_PROCESS_SCOPE_EVENT + (j + 1) + processConfiguration.getProcessId()));
scopeEventList.addScopeEvent(scopeEvent);
j++;
}
processEventsList.setScopeEventsList(scopeEventList);
processConfiguration.setProcessEventsList(processEventsList);
CleanUpListType cleanUpList = new CleanUpListType();
CleanUpType successCleanUp = BPELPackageRepositoryUtils.getSuccessCleanUpType(successCleanupsInString);
cleanUpList.addCleanUp(successCleanUp);
CleanUpType failureCleanUp = BPELPackageRepositoryUtils.getFailureCleanUpType(failureCleanupsInString);
cleanUpList.addCleanUp(failureCleanUp);
processConfiguration.setProcessCleanupConfImpl(cleanUpList);
}
}
use of org.wso2.carbon.bpel.stub.mgt.ProcessManagementException in project carbon-business-process by wso2.
the class TenantProcessStoreImpl method reloadExistingVersionsOfBPELPackage.
/**
* Reload old versions of BPEL package. This is used to handle restart of BPS server.
* At restart based on the last modified time of the BPEL archives we'll reload all the versions
* of that BPEL archive.
*
* @param deploymentContext information about current deployment
* @throws RegistryException on error loading
* resources from registry.
* @throws org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.ProcessManagementException
*/
private void reloadExistingVersionsOfBPELPackage(BPELDeploymentContext deploymentContext) throws RegistryException, ProcessManagementException {
BPELPackageInfo bpelPackage = repository.getBPELPackageInfo(deploymentContext);
String lastActivePackageName = null;
for (String packageName : bpelPackage.getAvailableVersions()) {
if (deploymentUnits.containsKey(packageName)) {
lastActivePackageName = packageName;
} else {
// version of the package
if (null != lastActivePackageName && isConfigRegistryReadOnly()) {
loadExistingBPELPackage(lastActivePackageName);
}
loadExistingBPELPackage(packageName);
}
}
}
Aggregations