From 0c5de17f41e2da31e3519d3a9ea4b79bb782cd12 Mon Sep 17 00:00:00 2001 From: Nicolas Malin Date: Fri, 29 Jan 2016 12:52:34 +0000 Subject: [PATCH] Add the possibility to set a blackout period for job manager service. During this time all async and scheduled service are put on hold. This improvement add a entity JobManagerLock, a new screen to add/edit job manager lock and an information for end user on FindJob and ScheduleJob screen. See more information on issue OFBIZ-6790. Thanks to Jacques for sharing on this improvement. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1727570 13f79535-47bb-0310-9956-ffa450edef68 --- framework/common/data/CommonTypeData.xml | 4 + framework/service/data/ServiceSeedData.xml | 6 + framework/service/entitydef/entitymodel.xml | 17 +++ framework/service/servicedef/services.xml | 16 +++ .../src/org/ofbiz/service/job/JobManager.java | 23 ++++ .../src/org/ofbiz/service/job/JobPoller.java | 4 + .../webtools/config/WebtoolsUiLabels.xml | 20 ++++ .../data/WebtoolsSecurityGroupDemoData.xml | 2 + .../WebtoolsSecurityPermissionSeedData.xml | 2 + .../webapp/webtools/WEB-INF/controller.xml | 16 +++ framework/webtools/webapp/webtools/main.ftl | 1 + framework/webtools/widget/CommonScreens.xml | 14 +++ framework/webtools/widget/Menus.xml | 3 + framework/webtools/widget/ServiceForms.xml | 88 +++++++++++++++ framework/webtools/widget/ServiceScreens.xml | 105 ++++++++++++++++++ 15 files changed, 321 insertions(+) diff --git a/framework/common/data/CommonTypeData.xml b/framework/common/data/CommonTypeData.xml index 26fbf1d6ff..821060408c 100644 --- a/framework/common/data/CommonTypeData.xml +++ b/framework/common/data/CommonTypeData.xml @@ -138,4 +138,8 @@ under the License. + + + + diff --git a/framework/service/data/ServiceSeedData.xml b/framework/service/data/ServiceSeedData.xml index c13d8cb097..6731db5163 100644 --- a/framework/service/data/ServiceSeedData.xml +++ b/framework/service/data/ServiceSeedData.xml @@ -198,4 +198,10 @@ under the License. [9] Integer: 0 to 59 --> + + + + + + diff --git a/framework/service/entitydef/entitymodel.xml b/framework/service/entitydef/entitymodel.xml index c628c18dc2..b6ace780e0 100644 --- a/framework/service/entitydef/entitymodel.xml +++ b/framework/service/entitydef/entitymodel.xml @@ -186,6 +186,23 @@ under the License. + + + + + + + + + + + + + + + + + diff --git a/framework/service/servicedef/services.xml b/framework/service/servicedef/services.xml index 6938f7ea47..23b1876d0e 100644 --- a/framework/service/servicedef/services.xml +++ b/framework/service/servicedef/services.xml @@ -128,4 +128,20 @@ under the License. + + + + Create a Job Manager Lock + + + + + + + Cancel a Job Sandbox Lock + + + + + diff --git a/framework/service/src/org/ofbiz/service/job/JobManager.java b/framework/service/src/org/ofbiz/service/job/JobManager.java index dab1335ca8..23e028ec80 100644 --- a/framework/service/src/org/ofbiz/service/job/JobManager.java +++ b/framework/service/src/org/ofbiz/service/job/JobManager.java @@ -40,6 +40,7 @@ import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityExpr; +import org.ofbiz.entity.condition.EntityJoinOperator; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.serialize.SerializeException; import org.ofbiz.entity.serialize.XmlSerializer; @@ -135,6 +136,28 @@ public final class JobManager { return JobPoller.getInstance().getPoolState(); } + /** + * Return true if the jobManager can run job. + * + * @return boolean. + */ + public boolean isAvailable() { + try { + //check if a lock is enable for the period on entity JobManagerLock + EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeConditionDate("fromDate", "thruDate"), + EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("instanceId", instanceId), + EntityCondition.makeCondition("instanceId", "_NA_")) + , EntityJoinOperator.OR) + ), EntityJoinOperator.AND); + return delegator.findCountByCondition("JobManagerLock", condition, null, null) == 0; + } catch (GenericEntityException e) { + Debug.logWarning(e, "Exception thrown while check lock on JobManager : " + instanceId, module); + return false; + } + } + private static List getRunPools() throws GenericConfigException { List runFromPools = ServiceConfigUtil.getServiceEngine().getThreadPool().getRunFromPools(); List readPools = new ArrayList(runFromPools.size()); diff --git a/framework/service/src/org/ofbiz/service/job/JobPoller.java b/framework/service/src/org/ofbiz/service/job/JobPoller.java index 7c9427312f..67c7deb417 100644 --- a/framework/service/src/org/ofbiz/service/job/JobPoller.java +++ b/framework/service/src/org/ofbiz/service/job/JobPoller.java @@ -220,6 +220,10 @@ public final class JobPoller implements ServiceConfigListener { Collection jmCollection = jobManagers.values(); List> pollResults = new ArrayList>(); for (JobManager jm : jmCollection) { + if (!jm.isAvailable()) { + if (Debug.infoOn()) Debug.logInfo("The job manager is locked.", module); + continue; + } jm.reloadCrashedJobs(); pollResults.add(jm.poll(remainingCapacity).iterator()); } diff --git a/framework/webtools/config/WebtoolsUiLabels.xml b/framework/webtools/config/WebtoolsUiLabels.xml index 76309e5fe5..1295806073 100644 --- a/framework/webtools/config/WebtoolsUiLabels.xml +++ b/framework/webtools/config/WebtoolsUiLabels.xml @@ -679,6 +679,10 @@ 运行服务 執行服務 + + Job manager locks list + Blocage du gestionnaire de service + Job anlegen Schedule Job @@ -1399,6 +1403,10 @@ 创建/删除主键 新建/刪除主鍵 + + Current job manager locks + Blocages actuels du gestionnaire de service + Daemon Daemon @@ -2878,6 +2886,10 @@ 日志文件 日誌檔 + + Job manager locks enabled + Blocages actifs sur le gestionnaire de service + Name der LHS-Map LHS map name @@ -3668,6 +3680,10 @@ 名称或角色 名稱或角色 + + Next job manager locks + Prochains blocages du gestionnaire de service + Keine Entität eingelesen No entities read @@ -4691,6 +4707,10 @@ 选择执行程序 選擇執行程式 + + Job manager locks List + Liste des blocages du gest. service + Statistik-Tools für Server-Besuche Server Hit Statistics Tools diff --git a/framework/webtools/data/WebtoolsSecurityGroupDemoData.xml b/framework/webtools/data/WebtoolsSecurityGroupDemoData.xml index 73980b3aa4..6fad6a2710 100644 --- a/framework/webtools/data/WebtoolsSecurityGroupDemoData.xml +++ b/framework/webtools/data/WebtoolsSecurityGroupDemoData.xml @@ -44,7 +44,9 @@ under the License. + + diff --git a/framework/webtools/data/WebtoolsSecurityPermissionSeedData.xml b/framework/webtools/data/WebtoolsSecurityPermissionSeedData.xml index d8c0f1f4f4..c2b411da2d 100644 --- a/framework/webtools/data/WebtoolsSecurityPermissionSeedData.xml +++ b/framework/webtools/data/WebtoolsSecurityPermissionSeedData.xml @@ -35,6 +35,7 @@ under the License. + @@ -64,6 +65,7 @@ under the License. + diff --git a/framework/webtools/webapp/webtools/WEB-INF/controller.xml b/framework/webtools/webapp/webtools/WEB-INF/controller.xml index e4b1920a48..67ff13bd1a 100644 --- a/framework/webtools/webapp/webtools/WEB-INF/controller.xml +++ b/framework/webtools/webapp/webtools/WEB-INF/controller.xml @@ -327,6 +327,20 @@ under the License. + + + + + + + + + + + + + + @@ -648,6 +662,8 @@ under the License. + + diff --git a/framework/webtools/webapp/webtools/main.ftl b/framework/webtools/webapp/webtools/main.ftl index c526a0cb53..b9b83886e9 100644 --- a/framework/webtools/webapp/webtools/main.ftl +++ b/framework/webtools/webapp/webtools/main.ftl @@ -88,6 +88,7 @@ under the License.
  • ${uiLabelMap.PageTitleRunService}
  • ${uiLabelMap.PageTitleJobList}
  • ${uiLabelMap.PageTitleThreadList}
  • +
  • ${uiLabelMap.PageTitleJobManagerLockList}
  • ${uiLabelMap.WebtoolsServiceLog}
  • <#if security.hasPermission("DATAFILE_MAINT", session)> diff --git a/framework/webtools/widget/CommonScreens.xml b/framework/webtools/widget/CommonScreens.xml index 0bcf401603..8b58bc3c2d 100644 --- a/framework/webtools/widget/CommonScreens.xml +++ b/framework/webtools/widget/CommonScreens.xml @@ -108,6 +108,20 @@ under the License. + +
    + + + + + + + + + +
    +
    +
    diff --git a/framework/webtools/widget/Menus.xml b/framework/webtools/widget/Menus.xml index 38a3e179da..d05ceae07f 100644 --- a/framework/webtools/widget/Menus.xml +++ b/framework/webtools/widget/Menus.xml @@ -111,6 +111,9 @@ under the License. + + + diff --git a/framework/webtools/widget/ServiceForms.xml b/framework/webtools/widget/ServiceForms.xml index 9450c5edd0..d13b649b5f 100644 --- a/framework/webtools/widget/ServiceForms.xml +++ b/framework/webtools/widget/ServiceForms.xml @@ -138,4 +138,92 @@ under the License. +
    + + + + + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/webtools/widget/ServiceScreens.xml b/framework/webtools/widget/ServiceScreens.xml index d92fadb356..4449e5fe1f 100644 --- a/framework/webtools/widget/ServiceScreens.xml +++ b/framework/webtools/widget/ServiceScreens.xml @@ -55,6 +55,7 @@ under the License. +
    @@ -130,6 +131,7 @@ under the License. + @@ -220,4 +222,107 @@ under the License.
    + + +
    + + + + + + + + +
    + + + + + + +
    + + + + + + + +
    +
    +
    +
    +
    + +
    + + + + + + + +
    +
    + +
    + + + + + + + + + + + + + + + + +
    + + + + + + + + +
    + + + + + + + + + + +
    +
    + + + + + + + + + + +
    +
    +
    +
    +
    +
    +