use of org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method getInstanceSummary.
public InstanceSummaryE getInstanceSummary() throws InstanceManagementException {
InstanceSummaryE instanceSummary = new InstanceSummaryE();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
instanceSummary.setActive(getInstanceCountByState(getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet()), INSTANCE_STATUS_ACTIVE).intValue());
instanceSummary.setCompleted(getInstanceCountByState(getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet()), INSTANCE_STATUS_COMPLETED).intValue());
instanceSummary.setFailed(getInstanceCountByState(getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet()), INSTANCE_STATUS_FAILED).intValue());
instanceSummary.setSuspended(getInstanceCountByState(getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet()), INSTANCE_STATUS_SUSPENDED).intValue());
instanceSummary.setTerminated(getInstanceCountByState(getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet()), INSTANCE_STATUS_TERMINATED).intValue());
return instanceSummary;
}
use of org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl 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.bpel.core.ode.integration.store.TenantProcessStoreImpl in project carbon-business-process by wso2.
the class Instance method getPaginatedInstanceList.
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;
}
Aggregations