You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by "Jacques Le Roux (JIRA)" <ji...@apache.org> on 2017/04/11 13:26:41 UTC
[jira] [Commented] (OFBIZ-9233) Enable a service to run by a
specific service engine
[ https://issues.apache.org/jira/browse/OFBIZ-9233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15964360#comment-15964360 ]
Jacques Le Roux commented on OFBIZ-9233:
----------------------------------------
Hi Jinghai,
I began to review and decided to apply on trunk for easier review and test, but stumbled upon an issue. This hunk, and only this one, does not apply
{code}
@@ -371,163 +372,165 @@
}
public static Map<String, Object> purgeOldJobs(DispatchContext dctx, Map<String, ? extends Object> context) {
- Locale locale = (Locale)context.get("locale");
+ Locale locale = (Locale)context.get("locale");
Debug.logWarning("purgeOldJobs service invoked. This service is obsolete - the Job Scheduler will purge old jobs automatically.", module);
String sendPool = null;
- Calendar cal = Calendar.getInstance();
try {
- sendPool = ServiceConfigUtil.getServiceEngine().getThreadPool().getSendToPool();
- int daysToKeep = ServiceConfigUtil.getServiceEngine().getThreadPool().getPurgeJobDays();
- cal.add(Calendar.DAY_OF_YEAR, -daysToKeep);
- } catch (GenericConfigException e) {
- Debug.logWarning(e, "Exception thrown while getting service configuration: ", module);
- return returnError(UtilProperties.getMessage(ServiceUtil.resource, "ServiceExceptionThrownWhileGettingServiceConfiguration", UtilMisc.toMap("errorString", e), locale));
- }
- Delegator delegator = dctx.getDelegator();
+ for (ServiceEngine engine : ServiceConfigUtil.getServiceConfig().getServiceEngines()) {
+ Calendar cal = Calendar.getInstance();
+ sendPool = engine.getThreadPool().getSendToPool();
+ int daysToKeep = engine.getThreadPool().getPurgeJobDays();
+ cal.add(Calendar.DAY_OF_YEAR, -daysToKeep);
+ Delegator delegator = dctx.getDelegator();
- Timestamp purgeTime = new Timestamp(cal.getTimeInMillis());
+ Timestamp purgeTime = new Timestamp(cal.getTimeInMillis());
- // create the conditions to query
- EntityCondition pool = EntityCondition.makeCondition("poolId", sendPool);
+ // create the conditions to query
+ EntityCondition pool = EntityCondition.makeCondition("poolId", sendPool);
- List<EntityExpr> finExp = UtilMisc.toList(EntityCondition.makeCondition("finishDateTime", EntityOperator.NOT_EQUAL, null));
- finExp.add(EntityCondition.makeCondition("finishDateTime", EntityOperator.LESS_THAN, purgeTime));
+ List<EntityExpr> finExp = UtilMisc.toList(EntityCondition.makeCondition("finishDateTime", EntityOperator.NOT_EQUAL, null));
+ finExp.add(EntityCondition.makeCondition("finishDateTime", EntityOperator.LESS_THAN, purgeTime));
- List<EntityExpr> canExp = UtilMisc.toList(EntityCondition.makeCondition("cancelDateTime", EntityOperator.NOT_EQUAL, null));
- canExp.add(EntityCondition.makeCondition("cancelDateTime", EntityOperator.LESS_THAN, purgeTime));
+ List<EntityExpr> canExp = UtilMisc.toList(EntityCondition.makeCondition("cancelDateTime", EntityOperator.NOT_EQUAL, null));
+ canExp.add(EntityCondition.makeCondition("cancelDateTime", EntityOperator.LESS_THAN, purgeTime));
- EntityCondition cancelled = EntityCondition.makeCondition(canExp);
- EntityCondition finished = EntityCondition.makeCondition(finExp);
+ EntityCondition cancelled = EntityCondition.makeCondition(canExp);
+ EntityCondition finished = EntityCondition.makeCondition(finExp);
- EntityCondition doneCond = EntityCondition.makeCondition(UtilMisc.toList(cancelled, finished), EntityOperator.OR);
+ EntityCondition doneCond = EntityCondition.makeCondition(UtilMisc.toList(cancelled, finished), EntityOperator.OR);
- // always suspend the current transaction; use the one internally
- Transaction parent = null;
- try {
- if (TransactionUtil.getStatus() != TransactionUtil.STATUS_NO_TRANSACTION) {
- parent = TransactionUtil.suspend();
- }
-
- // lookup the jobs - looping 1000 at a time to avoid problems with cursors
- // also, using unique transaction to delete as many as possible even with errors
- boolean noMoreResults = false;
- boolean beganTx1 = false;
- while (!noMoreResults) {
- // current list of records
- List<GenericValue> curList = null;
+ // always suspend the current transaction; use the one internally
+ Transaction parent = null;
try {
- // begin this transaction
- beganTx1 = TransactionUtil.begin();
+ if (TransactionUtil.getStatus() != TransactionUtil.STATUS_NO_TRANSACTION) {
+ parent = TransactionUtil.suspend();
+ }
- EntityListIterator foundJobs = null;
- try {
- foundJobs = EntityQuery.use(delegator)
- .select("jobId")
- .from("JobSandbox")
- .where(EntityCondition.makeCondition(UtilMisc.toList(doneCond, pool)))
- .cursorScrollInsensitive()
- .maxRows(1000)
- .queryIterator();
- curList = foundJobs.getPartialList(1, 1000);
- } finally {
- if (foundJobs != null) {
- foundJobs.close();
- }
- }
- } catch (GenericEntityException e) {
- Debug.logError(e, "Cannot obtain job data from datasource", module);
- try {
- TransactionUtil.rollback(beganTx1, e.getMessage(), e);
- } catch (GenericTransactionException e1) {
- Debug.logWarning(e1, module);
- }
- return ServiceUtil.returnError(e.getMessage());
- } finally {
- try {
- TransactionUtil.commit(beganTx1);
- } catch (GenericTransactionException e) {
- Debug.logWarning(e, module);
- }
- }
- // remove each from the list in its own transaction
- if (UtilValidate.isNotEmpty(curList)) {
- for (GenericValue job: curList) {
- String jobId = job.getString("jobId");
- boolean beganTx2 = false;
+ // lookup the jobs - looping 1000 at a time to avoid problems with cursors
+ // also, using unique transaction to delete as many as possible even with errors
+ boolean noMoreResults = false;
+ boolean beganTx1 = false;
+ while (!noMoreResults) {
+ // current list of records
+ List<GenericValue> curList = null;
try {
- beganTx2 = TransactionUtil.begin();
- job.remove();
+ // begin this transaction
+ beganTx1 = TransactionUtil.begin();
+
+ EntityListIterator foundJobs = null;
+ try {
+ foundJobs = EntityQuery.use(delegator)
+ .select("jobId")
+ .from("JobSandbox")
+ .where(EntityCondition.makeCondition(UtilMisc.toList(doneCond, pool)))
+ .cursorScrollInsensitive()
+ .maxRows(1000)
+ .queryIterator();
+ curList = foundJobs.getPartialList(1, 1000);
+ } finally {
+ if (foundJobs != null) {
+ foundJobs.close();
+ }
+ }
} catch (GenericEntityException e) {
- Debug.logInfo("Cannot remove job data for ID: " + jobId, module);
+ Debug.logError(e, "Cannot obtain job data from datasource", module);
try {
- TransactionUtil.rollback(beganTx2, e.getMessage(), e);
+ TransactionUtil.rollback(beganTx1, e.getMessage(), e);
} catch (GenericTransactionException e1) {
Debug.logWarning(e1, module);
}
+ return ServiceUtil.returnError(e.getMessage());
} finally {
try {
- TransactionUtil.commit(beganTx2);
+ TransactionUtil.commit(beganTx1);
} catch (GenericTransactionException e) {
Debug.logWarning(e, module);
}
}
+ // remove each from the list in its own transaction
+ if (UtilValidate.isNotEmpty(curList)) {
+ for (GenericValue job: curList) {
+ String jobId = job.getString("jobId");
+ boolean beganTx2 = false;
+ try {
+ beganTx2 = TransactionUtil.begin();
+ job.remove();
+ } catch (GenericEntityException e) {
+ Debug.logInfo("Cannot remove job data for ID: " + jobId, module);
+ try {
+ TransactionUtil.rollback(beganTx2, e.getMessage(), e);
+ } catch (GenericTransactionException e1) {
+ Debug.logWarning(e1, module);
+ }
+ } finally {
+ try {
+ TransactionUtil.commit(beganTx2);
+ } catch (GenericTransactionException e) {
+ Debug.logWarning(e, module);
+ }
+ }
+ }
+ } else {
+ noMoreResults = true;
+ }
}
- } else {
- noMoreResults = true;
- }
- }
- // Now JobSandbox data is cleaned up. Now process Runtime data and remove the whole data in single shot that is of no need.
- boolean beganTx3 = false;
- GenericValue runtimeData = null;
- EntityListIterator runTimeDataIt = null;
- List<GenericValue> runtimeDataToDelete = new LinkedList<GenericValue>();
- long jobsandBoxCount = 0;
- try {
- // begin this transaction
- beganTx3 = TransactionUtil.begin();
+ // Now JobSandbox data is cleaned up. Now process Runtime data and remove the whole data in single shot that is of no need.
+ boolean beganTx3 = false;
+ GenericValue runtimeData = null;
+ EntityListIterator runTimeDataIt = null;
+ List<GenericValue> runtimeDataToDelete = new LinkedList<GenericValue>();
+ long jobsandBoxCount = 0;
+ try {
+ // begin this transaction
+ beganTx3 = TransactionUtil.begin();
- runTimeDataIt = EntityQuery.use(delegator).select("runtimeDataId").from("RuntimeData").queryIterator();
- try {
- while ((runtimeData = runTimeDataIt.next()) != null) {
- EntityCondition whereCondition = EntityCondition.makeCondition(UtilMisc.toList(EntityCondition.makeCondition("runtimeDataId", EntityOperator.NOT_EQUAL, null),
- EntityCondition.makeCondition("runtimeDataId", EntityOperator.EQUALS, runtimeData.getString("runtimeDataId"))), EntityOperator.AND);
- jobsandBoxCount = EntityQuery.use(delegator).from("JobSandbox").where(whereCondition).queryCount();
- if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(jobsandBoxCount)) == 0) {
- runtimeDataToDelete.add(runtimeData);
+ runTimeDataIt = EntityQuery.use(delegator).select("runtimeDataId").from("RuntimeData").queryIterator();
+ try {
+ while ((runtimeData = runTimeDataIt.next()) != null) {
+ EntityCondition whereCondition = EntityCondition.makeCondition(UtilMisc.toList(EntityCondition.makeCondition("runtimeDataId", EntityOperator.NOT_EQUAL, null),
+ EntityCondition.makeCondition("runtimeDataId", EntityOperator.EQUALS, runtimeData.getString("runtimeDataId"))), EntityOperator.AND);
+ jobsandBoxCount = EntityQuery.use(delegator).from("JobSandbox").where(whereCondition).queryCount();
+ if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(jobsandBoxCount)) == 0) {
+ runtimeDataToDelete.add(runtimeData);
+ }
+ }
+ } finally {
+ runTimeDataIt.close();
}
+ // Now we are ready to delete runtimeData, we can safely delete complete list that we have recently fetched i.e runtimeDataToDelete.
+ delegator.removeAll(runtimeDataToDelete);
+ } catch (GenericEntityException e) {
+ Debug.logError(e, "Cannot obtain runtime data from datasource", module);
+ try {
+ TransactionUtil.rollback(beganTx3, e.getMessage(), e);
+ } catch (GenericTransactionException e1) {
+ Debug.logWarning(e1, module);
+ }
+ return ServiceUtil.returnError(e.getMessage());
+ } finally {
+ try {
+ TransactionUtil.commit(beganTx3);
+ } catch (GenericTransactionException e) {
+ Debug.logWarning(e, module);
+ }
}
+ } catch (GenericTransactionException e) {
+ Debug.logError(e, "Unable to suspend transaction; cannot purge jobs!", module);
+ return ServiceUtil.returnError(e.getMessage());
} finally {
- runTimeDataIt.close();
+ if (parent != null) {
+ try {
+ TransactionUtil.resume(parent);
+ } catch (GenericTransactionException e) {
+ Debug.logWarning(e, module);
+ }
+ }
}
- // Now we are ready to delete runtimeData, we can safely delete complete list that we have recently fetched i.e runtimeDataToDelete.
- delegator.removeAll(runtimeDataToDelete);
- } catch (GenericEntityException e) {
- Debug.logError(e, "Cannot obtain runtime data from datasource", module);
- try {
- TransactionUtil.rollback(beganTx3, e.getMessage(), e);
- } catch (GenericTransactionException e1) {
- Debug.logWarning(e1, module);
- }
- return ServiceUtil.returnError(e.getMessage());
- } finally {
- try {
- TransactionUtil.commit(beganTx3);
- } catch (GenericTransactionException e) {
- Debug.logWarning(e, module);
- }
}
- } catch (GenericTransactionException e) {
- Debug.logError(e, "Unable to suspend transaction; cannot purge jobs!", module);
- return ServiceUtil.returnError(e.getMessage());
- } finally {
- if (parent != null) {
- try {
- TransactionUtil.resume(parent);
- } catch (GenericTransactionException e) {
- Debug.logWarning(e, module);
- }
- }
+ } catch (GenericConfigException e) {
+ Debug.logWarning(e, "Exception thrown while getting service configuration: ", module);
+ return returnError(UtilProperties.getMessage(ServiceUtil.resource, "ServiceExceptionThrownWhileGettingServiceConfiguration", UtilMisc.toMap("errorString", e), locale));
}
return ServiceUtil.returnSuccess();
{code}
This file did not change since September 2016, please recreate the patch against the trunk HEAD, thanks.
> Enable a service to run by a specific service engine
> ----------------------------------------------------
>
> Key: OFBIZ-9233
> URL: https://issues.apache.org/jira/browse/OFBIZ-9233
> Project: OFBiz
> Issue Type: Improvement
> Components: framework
> Affects Versions: Trunk
> Reporter: Shi Jinghai
> Assignee: Shi Jinghai
> Priority: Minor
> Fix For: Trunk
>
> Attachments: OFBIZ-9233-20170301.patch, OFBIZ-9233-MultiServiceEnginesEnv.png
>
>
> Currently, all of the services of OFBiz are run by the 'default' service engine.
> In a project, we have to make a service run by different service engines rather than the 'default' one, i.e. order services run by 'order' service engine and 'orderpool', shipment services run by 'shipment' service engine and 'shipmentpool'.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)