use of org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl in project carbon-business-process by wso2.
the class BPELPackageManagementServiceSkeleton method listProcessesInPackage.
public PackageType listProcessesInPackage(String packageName) throws PackageManagementException {
TenantProcessStoreImpl tenantProcessStore = getTenantProcessStore();
BPELPackageRepository packageRepo = tenantProcessStore.getBPELPackageRepository();
try {
return getPackageInfo(packageRepo.getBPELPackageInfoForPackage(packageName.substring(0, packageName.lastIndexOf("-"))));
} catch (Exception e) {
String errMsg = "BPEL package: " + packageName + " failed to load from registry.";
log.error(errMsg, e);
throw new PackageManagementException(errMsg, e);
}
}
use of org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl in project carbon-business-process by wso2.
the class BPELPackageManagementServiceSkeleton method listDeployedPackagesPaginated.
public DeployedPackagesPaginated listDeployedPackagesPaginated(int page) throws PackageManagementException {
int tPage = page;
List<BPELPackageInfo> packages;
DeployedPackagesPaginated paginatedPackages = new DeployedPackagesPaginated();
TenantProcessStoreImpl tenantProcessStore = getTenantProcessStore();
BPELPackageRepository packageRepo = tenantProcessStore.getBPELPackageRepository();
try {
// Can return null and we should handle that
packages = packageRepo.getBPELPackages();
} catch (Exception e) {
String errorMessage = "Cannot get the BPEL Package list from repository.";
log.error(errorMessage, e);
throw new PackageManagementException(errorMessage, e);
}
if (packages != null) {
// Calculating pagination information
if (tPage < 0 || tPage == Integer.MAX_VALUE) {
tPage = 0;
}
int startIndex = tPage * BPELConstants.ITEMS_PER_PAGE;
int endIndex = (tPage + 1) * BPELConstants.ITEMS_PER_PAGE;
int numberOfPackages = packages.size();
int totalPackages = 0;
BPELPackageInfo[] packagesArray = packages.toArray(new BPELPackageInfo[numberOfPackages]);
for (int i = 0; i < numberOfPackages; i++) {
int count = getPackageVersionCount(packagesArray[i]);
if (totalPackages + count > startIndex && totalPackages < endIndex) {
// In-order to get the total number of packages count
// if (totalPackages >= endIndex) {
// break;
// }
int maxRemainingPackages = totalPackages < startIndex && (totalPackages + count) > startIndex ? startIndex - (totalPackages + count) : endIndex - totalPackages;
PackageType packageType = getPackageInfo(packagesArray[i], maxRemainingPackages);
paginatedPackages.add_package(packageType);
}
totalPackages += count;
}
int pages = (int) Math.ceil((double) totalPackages / BPELConstants.ITEMS_PER_PAGE);
paginatedPackages.setPages(pages);
} else {
// Returning empty result set with pages equal to zero for cases where null is returned from
// BPEL repo.
paginatedPackages.setPages(0);
}
return paginatedPackages;
}
use of org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl in project carbon-business-process by wso2.
the class BPELPackageManagementServiceSkeleton method getLatestVersionInPackage.
/**
* This method will return the latest version of the BPEL package
* @param packageName BPEL package name
* @return Latest package version
* @throws PackageManagementException
*/
public String getLatestVersionInPackage(String packageName) throws PackageManagementException {
TenantProcessStoreImpl tenantProcessStore = getTenantProcessStore();
BPELPackageRepository packageRepo = tenantProcessStore.getBPELPackageRepository();
try {
return packageRepo.getBPELPackageInfoForPackage(packageName).getLatestVersion();
} catch (Exception e) {
String errMsg = "BPEL package: " + packageName + " failed to get latest version.";
log.error(errMsg, e);
throw new PackageManagementException(errMsg, e);
}
}
use of org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method getPaginatedInstanceList.
/**
* Get paginated instance list
*
* @param filter Instance tFilter
* @param order The field on which to be ordered
* @param limit The maximum number of instances to be fetched
* @param page The page number
* @return Instances that are filtered through "tFilter", ordered by "order" that fits into
* 'page'th page
* @throws InstanceManagementException When an error occurs
*/
public PaginatedInstanceList getPaginatedInstanceList(String filter, final String order, final int limit, final int page) throws InstanceManagementException {
String tFilter = filter;
final PaginatedInstanceList instanceList = new PaginatedInstanceList();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
if (tenantProcessStore.getProcessConfigMap().size() <= 0) {
instanceList.setPages(0);
return instanceList;
}
if (!tFilter.contains(" pid=")) {
tFilter = tFilter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
}
if (log.isDebugEnabled()) {
log.debug("Instance Filter:" + tFilter);
}
final InstanceFilter instanceFilter = new InstanceFilter(tFilter, order, limit);
try {
BpelDatabase bpelDb = bpelServer.getODEBPELServer().getBpelDb();
bpelDb.exec(new BpelDatabase.Callable<Object>() {
public Object run(BpelDAOConnection conn) throws InstanceManagementException {
Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
int pageNum = page;
if (pageNum < 0 || pageNum == Integer.MAX_VALUE) {
pageNum = 0;
}
int startIndexOfCurrentPage = pageNum * BPELConstants.ITEMS_PER_PAGE;
int endIndexOfCurrentPage = (pageNum + 1) * BPELConstants.ITEMS_PER_PAGE;
int instanceListSize = instances.size();
int pages = (int) Math.ceil((double) instanceListSize / BPELConstants.ITEMS_PER_PAGE);
instanceList.setPages(pages);
ProcessInstanceDAO[] instanceArray = instances.toArray(new ProcessInstanceDAO[instanceListSize]);
for (int i = startIndexOfCurrentPage; (i < endIndexOfCurrentPage && i < instanceListSize); i++) {
instanceList.addInstance(createLimitedInstanceInfoObject(instanceArray[i]));
}
return null;
}
});
} catch (Exception e) {
String errMsg = "Error querying instances from database. Instance Filter:" + instanceFilter.toString();
log.error(errMsg, e);
throw new InstanceManagementException(errMsg, e);
}
return instanceList;
}
use of org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method deleteInstances.
/**
* Delete Instances that matches the filter
*
* @param filter Instance filter
* @return Number of instances deleted
* @throws InstanceManagementException If the filter is invalid or an exception occurred during
* instance deletion
*/
public int deleteInstances(String filter, final boolean deleteMessageExchanges) throws InstanceManagementException {
String tFilter = filter;
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
if (isInvalidFilter(tFilter)) {
String errMsg = "Invalid instance filter: " + tFilter;
log.error(errMsg);
throw new InstanceManagementException(errMsg);
}
if (!isSecureFilter(new InstanceFilter(tFilter), tenantProcessStore.getProcessConfigMap().keySet())) {
String errMsg = "Instance deletion operation not permitted due to insecure filter: " + tFilter;
log.error(errMsg);
throw new InstanceManagementException(errMsg);
}
if (!tFilter.contains(" pid=")) {
tFilter = tFilter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
}
final InstanceFilter instanceFilter = new InstanceFilter(tFilter);
final List<Long> ret = new LinkedList<Long>();
try {
final int deletionBatchSize = BPELServerImpl.getInstance().getBpelServerConfiguration().getBpelInstanceDeletionLimit();
dbexec(new BpelDatabase.Callable<Object>() {
public Object run(BpelDAOConnection conn) throws IllegalAccessException {
Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
// not delete other instances also.
for (ProcessInstanceDAO instance : instances) {
isOperationIsValidForTheCurrentTenant(instance.getProcess().getProcessId());
}
int count = 1;
for (ProcessInstanceDAO instance : instances) {
instance.delete(EnumSet.allOf(ProcessConf.CLEANUP_CATEGORY.class), deleteMessageExchanges);
ret.add(instance.getInstanceId());
count++;
// limiting number of instances that can be deleted to avoid timeout exceptions
if (count > deletionBatchSize) {
break;
}
}
return null;
}
});
} catch (Exception e) {
String errMsg = "Exception during instance deletion. Filter: " + instanceFilter.toString();
log.error(errMsg, e);
throw new InstanceManagementException(errMsg, e);
}
return ret.size();
}
Aggregations