use of org.wso2.carbon.registry.api.Collection 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.registry.api.Collection 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();
}
use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method getActivities.
private Activities_type0 getActivities(ScopeDAO scope) {
Activities_type0 activities = new Activities_type0();
Collection<ActivityRecoveryDAO> recoveries = scope.getProcessInstance().getActivityRecoveries();
/*List<BpelEvent> events = scope.listEvents();*/
Set<EventDAOImpl> eventsEntities = ((ScopeDAOImpl) scope).getEvents();
List<BpelEvent> events = new ArrayList<BpelEvent>();
for (EventDAOImpl event : eventsEntities) {
events.add(event.getEvent());
}
ActivityStateDocumentBuilder b = new ActivityStateDocumentBuilder();
for (BpelEvent e : events) {
b.onEvent(e);
}
for (ActivityInfoDocument ai : b.getActivities()) {
for (ActivityRecoveryDAO recovery : recoveries) {
if (String.valueOf(recovery.getActivityId()).equals(ai.getActivityInfo().getAiid())) {
TFailureInfo failure = ai.getActivityInfo().addNewFailure();
failure.setReason(recovery.getReason());
failure.setDtFailure(toCalendar(recovery.getDateTime()));
failure.setActions(recovery.getActions());
failure.setRetries(recovery.getRetries());
ai.getActivityInfo().setStatus(TActivityStatus.FAILURE);
}
}
ActivityInfoType activity = new ActivityInfoType();
fillActivityInfo(activity, ai.getActivityInfo());
activities.addActivityInfo(activity);
}
return activities;
}
use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method getLongRunningInstances.
/**
* Get long running instances with duration
*
* @param limit The maximum number of instances to be fetched
* @return Long running instances
* @throws InstanceManagementException When an error occurs
*/
public LimitedInstanceInfoType[] getLongRunningInstances(int limit) throws InstanceManagementException {
final List<LimitedInstanceInfoType> longRunningInstances = new ArrayList<LimitedInstanceInfoType>();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
if (tenantProcessStore.getProcessConfigMap().size() <= 0) {
return longRunningInstances.toArray(new LimitedInstanceInfoType[longRunningInstances.size()]);
}
String filter = "status=ACTIVE";
if (!filter.contains(" pid=")) {
filter = filter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
}
if (log.isDebugEnabled()) {
log.debug("Instance Filter:" + filter);
}
String orderBy = "started";
final InstanceFilter instanceFilter = new InstanceFilter(filter, orderBy, 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);
for (ProcessInstanceDAO piDAO : instances) {
longRunningInstances.add(createLimitedInstanceInfoObject(piDAO));
}
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 longRunningInstances.toArray(new LimitedInstanceInfoType[longRunningInstances.size()]);
}
use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.
the class BPELPackageRepository method createBPELPackageParentCollectionWithProperties.
/**
* Create parent collection to persisting BPEL package information. For example, if you deploy
* a BPEL archive called 'HelloWorld.zip', we store information of that package in collection
* named 'HelloWorld'. This will be the root for 'HelloWorld' BPEL package information and
* there will several versions of this BPEL package in this registry collection which relates
* to the versions deployed in BPEL engine.
*
* @param deploymentContext containing information on current deployment
* @throws RegistryException when there is a error accessing registry
* @throws IOException if file access error occurred during MD5 checksum generation
* @throws NoSuchAlgorithmException when there is a error during MD5 generation
*/
private void createBPELPackageParentCollectionWithProperties(BPELDeploymentContext deploymentContext) throws RegistryException, IOException, NoSuchAlgorithmException {
Collection bpelPackage = configRegistry.newCollection();
bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_LATEST_CHECKSUM, Utils.getMD5Checksum(deploymentContext.getBpelArchive()));
if (log.isDebugEnabled()) {
log.debug(deploymentContext.getBpelPackageName() + " updating checksum: " + Utils.getMD5Checksum(deploymentContext.getBpelArchive()) + " in registry");
}
if (deploymentContext.isFailed()) {
bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_STATUS, BPELConstants.STATUS_FAILED);
bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_DEPLOYMENT_ERROR_LOG, deploymentContext.getDeploymentFailureCause());
// bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_DEPLOYMENT_STACK_TRACE,
// ExceptionUtils.getStackTrace(deploymentContext.getStackTrace()));
} else {
bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_STATUS, BPELConstants.STATUS_DEPLOYED);
}
bpelPackage.setProperty(BPELConstants.BPEL_PACKAGE_PROP_LATEST_VERSION, Long.toString(deploymentContext.getVersion()));
configRegistry.put(BPELPackageRepositoryUtils.getResourcePathForBPELPackage(deploymentContext), bpelPackage);
}
Aggregations