Commit 969ce20b authored by Rafael Monnerat's avatar Rafael Monnerat

[slapos_crm] Improve Support Request Generation to prevent fload

Only generate a limited number of Support Requests per time (For now hardcoded in 3).
Drop duplicated cases when computer is not contacting already.
Don't generate SR for recently created instances.
parent f6cf5a31
...@@ -54,11 +54,17 @@ ...@@ -54,11 +54,17 @@
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
if portal.ERP5Site_isSupportRequestCreationClosed():\n
# Stop ticket creation\n
return\n
\n
source_project_value = portal.restrictedTraverse(source_relative_url)\n
\n
support_request_in_progress = portal.portal_catalog.getResultValue(\n support_request_in_progress = portal.portal_catalog.getResultValue(\n
portal_type = \'Support Request\',\n portal_type = \'Support Request\',\n
title = title,\n title = title,\n
simulation_state = ["validated","submitted","suspended"],\n simulation_state = ["validated","submitted","suspended"],\n
source_project_value = source_relative_url\n source_project_uid = source_project_value.getUid()\n
)\n )\n
\n \n
if support_request_in_progress is None:\n if support_request_in_progress is None:\n
......
...@@ -57,15 +57,24 @@ import json\n ...@@ -57,15 +57,24 @@ import json\n
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
if portal.ERP5Site_isSupportRequestCreationClosed():\n
# Stop ticket creation\n
return\n
\n
reference = context.getReference()\n reference = context.getReference()\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n plugin_path=\'portal_memcached/default_memcached_plugin\')\n
\n \n
try:\n try:\n
d = memcached_dict[reference]\n d = memcached_dict[reference]\n
except KeyError:\n except KeyError:\n
return\n return context.Base_generateSupportRequestForSlapOS(\n
"No information about %s" % reference,\n
"%s has not contacted the server (No Contact Information)" % reference,\n
context.getRelativeUrl()\n
)\n
\n
\n \n
d = json.loads(d)\n d = json.loads(d)\n
last_contact = DateTime(d.get(\'created_at\'))\n last_contact = DateTime(d.get(\'created_at\'))\n
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string># HARDCODED LIMIT TO BE MOVED TO GLOBAL PREFERENCES\n
limit = 3\n
\n
support_request_list = context.portal_catalog(\n
portal_type = \'Support Request\',\n
simulation_state = ["validated","submitted", "suspended"],\n
limit=limit\n
)\n
\n
return len(support_request_list) == limit\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_isSupportRequestCreationClosed</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -55,11 +55,21 @@ ...@@ -55,11 +55,21 @@
from DateTime import DateTime\n from DateTime import DateTime\n
import json\n import json\n
\n \n
portal = context.getPortalObject()\n
\n
if portal.ERP5Site_isSupportRequestCreationClosed():\n
# Stop ticket creation\n
return\n
\n
if (DateTime() - context.getCreationDate()) < 1:\n
# Ignore recently created instances.\n
return\n
\n
reference = context.getReference()\n reference = context.getReference()\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n plugin_path=\'portal_memcached/default_memcached_plugin\')\n
\n \n
try:\n try:\n
d = memcached_dict[reference]\n d = memcached_dict[reference]\n
except KeyError:\n except KeyError:\n
...@@ -69,21 +79,13 @@ d = json.loads(d)\n ...@@ -69,21 +79,13 @@ d = json.loads(d)\n
result = d[\'text\']\n result = d[\'text\']\n
last_contact = DateTime(d.get(\'created_at\'))\n last_contact = DateTime(d.get(\'created_at\'))\n
now = DateTime()\n now = DateTime()\n
title = ""\n
\n \n
# Optimise by checking memcache information first.\n
if result.startswith(\'#error \'):\n if result.startswith(\'#error \'):\n
# If no change in the last 2 hours generate a support request\n
if (now - last_contact) > 0.08:\n
tag = "Support Request generation for %s" % reference\n
title = "Instance %s in error state" % reference\n
description = "%s has been in error state for more than 2 hours (last contact date: %s)" % (reference, last_contact)\n
\n
if title != "":\n
return context.Base_generateSupportRequestForSlapOS(\n return context.Base_generateSupportRequestForSlapOS(\n
title,\n "Instance %s in error state" % reference,\n
description,\n "%s has been in error state for more than 2 hours (last contact date: %s)" % (reference, last_contact),\n
context.getRelativeUrl()\n context.getRelativeUrl())\n
)\n
]]></string> </value> ]]></string> </value>
......
...@@ -38,6 +38,15 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -38,6 +38,15 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
def afterSetUp(self): def afterSetUp(self):
super(TestSlapOSCloudSupportRequestGeneration, self).afterSetUp() super(TestSlapOSCloudSupportRequestGeneration, self).afterSetUp()
self.new_id = self.generateNewId() self.new_id = self.generateNewId()
self._cancelTestSupportRequestList()
def _cancelTestSupportRequestList(self):
for support_request in self.portal.portal_catalog(
portal_type="Support Request",
title="Test Support Request %",
simulation_state="validated"):
support_request.invalidate()
self.tic()
def _makeComputer(self,new_id): def _makeComputer(self,new_id):
# Clone computer document # Clone computer document
...@@ -206,10 +215,10 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -206,10 +215,10 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS', self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result) result)
def test_SoftwareInstance_checkState_error_out_time(self): def test_SoftwareInstance_checkState_error_new_instance(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl()) self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue() instance = host_sub.getPredecessorValue()
...@@ -219,7 +228,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -219,7 +228,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
plugin_path='portal_memcached/default_memcached_plugin') plugin_path='portal_memcached/default_memcached_plugin')
memcached_dict[instance.getReference()] = json.dumps( memcached_dict[instance.getReference()] = json.dumps(
{"created_at":"%s" % (DateTime() - 0.1), "text":"#error "} {"created_at":"%s" % DateTime(), "text":"#error "}
) )
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
...@@ -229,20 +238,29 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -229,20 +238,29 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS', self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
result) result)
def test_SoftwareInstance_checkState_error_in_time(self): def test_SoftwareInstance_checkState_error_out_time(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl()) self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue() instance = host_sub.getPredecessorValue()
instance.workflow_history['edit_workflow'] = [{
'comment':'edit',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'state': 'current',
'time': DateTime('2012/11/30 11:11'),
'action': 'edit'
}]
memcached_dict = self.portal.portal_memcached.getMemcachedDict( memcached_dict = self.portal.portal_memcached.getMemcachedDict(
key_prefix='slap_tool', key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin') plugin_path='portal_memcached/default_memcached_plugin')
memcached_dict[instance.getReference()] = json.dumps( memcached_dict[instance.getReference()] = json.dumps(
{"created_at":"%s" % (DateTime()), "text":"#error "} {"created_at":"%s" % DateTime(), "text":"#error "}
) )
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
...@@ -252,10 +270,10 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -252,10 +270,10 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS', self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result) result)
def test_SoftwareInstance_checkState_access_out_time(self): def test_SoftwareInstance_checkState_error_in_time(self):
host_sub = self._makeHostingSubscription(self.new_id) host_sub = self._makeHostingSubscription(self.new_id)
self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl()) self._makeSoftwareInstance(host_sub,self.generateNewSoftwareReleaseUrl())
instance = host_sub.getPredecessorValue() instance = host_sub.getPredecessorValue()
...@@ -265,7 +283,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -265,7 +283,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
plugin_path='portal_memcached/default_memcached_plugin') plugin_path='portal_memcached/default_memcached_plugin')
memcached_dict[instance.getReference()] = json.dumps( memcached_dict[instance.getReference()] = json.dumps(
{"created_at":"%s" % (DateTime() - 1.1), "text":"#access "} {"created_at":"%s" % (DateTime()), "text":"#error "}
) )
self._simulateBase_generateSupportRequestForSlapOS() self._simulateBase_generateSupportRequestForSlapOS()
...@@ -275,7 +293,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -275,7 +293,7 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
finally: finally:
self._dropBase_generateSupportRequestForSlapOS() self._dropBase_generateSupportRequestForSlapOS()
self.assertEqual('Visited Base_generateSupportRequestForSlapOS', self.assertNotEqual('Visited Base_generateSupportRequestForSlapOS',
result) result)
def test_SoftwareInstance_checkState_access_in_time(self): def test_SoftwareInstance_checkState_access_in_time(self):
......
27 28
\ No newline at end of file \ No newline at end of file
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