Commit 8c5e7a42 authored by Vincent Pelletier's avatar Vincent Pelletier

CMFActivity: Allow defining node identifier in zope configuration file.

Allows giving more compact and user-meaningful names if desired.
If used, makes in-ZODB data (processing/validation roles) independent
from process' network binding, removing the need to re-configure
CMFActivity after changing network.
Also, update AlarmTool usage of getCurrentNode (and related).
Also, replace AlarmTool's manageAlarmNode input field with a select for
convenience.
parent 9b8e76e5
......@@ -31,7 +31,6 @@ import urllib
import threading
import sys
from types import StringType
import re
from collections import defaultdict
from cPickle import dumps, loads
from Products.CMFCore import permissions as CMFCorePermissions
......@@ -57,6 +56,7 @@ from Zope2 import app
from Products.ERP5Type.UnrestrictedMethod import PrivilegedUser
from zope.site.hooks import setSite
import transaction
from App.config import getConfiguration
import Products.Localizer.patches
localizer_lock = Products.Localizer.patches._requests_lock
......@@ -68,7 +68,7 @@ from ZODB.POSException import ConflictError
from Products.MailHost.MailHost import MailHostError
from zLOG import LOG, INFO, WARNING, ERROR
from warnings import warn
import warnings
from time import time
try:
......@@ -79,9 +79,6 @@ except ImportError:
from traceback import format_list, extract_stack
# minimal IP:Port regexp
NODE_RE = re.compile('^\d+\.\d+\.\d+\.\d+:\d+$')
# Using a RAM property (not a property of an instance) allows
# to prevent from storing a state in the ZODB (and allows to restart...)
active_threads = 0
......@@ -790,9 +787,22 @@ class ActivityTool (Folder, UniqueObject):
Folder.inheritedAttribute('manage_afterAdd')(self, item, container)
def getCurrentNode(self):
""" Return current node in form ip:port """
""" Return current node identifier """
global currentNode
if currentNode is None:
currentNode = getattr(
getConfiguration(),
'product_config',
{},
).get('cmfactivity', {}).get('node-id')
if currentNode is None:
warnings.warn('Node name auto-generation is deprecated, please add a'
'\n'
'<product-config CMFAcvtivity>\n'
' node-id = ...\n'
'</product-config>\n'
'section in your zope.conf, replacing "..." with a cluster-unique '
'node identifier.', DeprecationWarning)
ip = port = ''
from asyncore import socket_map
for k, v in socket_map.items():
......@@ -855,7 +865,7 @@ class ActivityTool (Folder, UniqueObject):
def _isValidNodeName(self, node_name) :
"""Check we have been provided a good node name"""
return isinstance(node_name, str) and NODE_RE.match(node_name)
return isinstance(node_name, str)
security.declarePublic('manage_setDistributingNode')
def manage_setDistributingNode(self, distributingNode, REQUEST=None):
......
......@@ -190,6 +190,10 @@ class AlarmTool(TimerServiceMixin, BaseTool):
else:
self.alarmNode = None
security.declarePublic('getNodeList')
def getNodeList(self):
return self.getPortalObject().portal_activities.getNodeList()
security.declareProtected(Permissions.ManageProperties, 'manage_setAlarmNode')
def manage_setAlarmNode(self, alarmNode, REQUEST=None):
""" set the alarm node """
......
......@@ -34,9 +34,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
To provide high performance, alarms should start a script wich only start
some activities. Like this, the activity tool will be in charge to distribute
the work on many nodes.
The format to adress a node in this configuration is therfore
<code>IP-Address</code>:<code>Port-Number</code>.
</p>
<p class="form-help">
......@@ -62,11 +59,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</tr>
<tr>
<td>
<div class="form-label">IP:Port</div>
<div class="form-label">Node identifier</div>
</td>
<td align="left">
<div class="form-item">
<input type="text" name="alarmNode" value="&dtml-getAlarmNode;" size="19" />
<select name="alarmNode">
<option value="">(disabled)</option>
<dtml-in getNodeList prefix="node">
<dtml-if expr="node_item == getAlarmNode()">
<option selected="selected" value="<dtml-var sequence-item>">
<dtml-var sequence-item>
</option>
<dtml-else>
<option value="<dtml-var sequence-item>">
<dtml-var sequence-item>
</option>
</dtml-if>
</dtml-in>
</select>
</div>
</td>
</tr>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment