Commit f45eb3f0 authored by Rafael Monnerat's avatar Rafael Monnerat

Update disaster recovery related code

See merge request nexedi/slapos.core!614
parents 2caa6eca d43aa37e
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_disaster_recovery</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
document_list = portal.portal_catalog(
limit=limit,
uid={'query': min_uid, 'range': 'nlt'},
sort_on=(('uid', 'ASC'),),
)
result_count = len(document_list)
if result_count:
if result_count == limit:
portal.portal_activities.activate(activity='SQLQueue', priority=3).ERP5Site_checkDeletedDocumentList(document_list[-1].uid, limit, packet_size)
column_list = [(x.path, x.uid) for x in document_list]
for i in xrange(0, result_count, packet_size):
portal.portal_activities.activate(activity='SQLQueue').ERP5Site_unindexDeletedDocumentList(column_list[i:i+packet_size])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>_params</string> </key>
<value> <string>min_uid, limit, packet_size</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_checkDeletedDocumentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from Products.ZSQLCatalog.SQLCatalog import Query
portal = context.getPortalObject()
document_list = portal.portal_catalog(
limit=limit,
uid={'query': min_uid, 'range': 'nlt'},
indexation_timestamp=Query(**{'indexation_timestamp': (before, now), 'range': 'minngt'}),
sort_on=(('uid', 'ASC'),),
)
result_count = len(document_list)
if result_count:
if result_count == limit:
portal.portal_activities.activate(activity='SQLQueue', priority=3).ERP5Site_checkLatestModifiedDocumentList(document_list[-1].uid, limit, packet_size, before, now)
column_list = [(x.path, x.uid) for x in document_list]
for i in xrange(0, result_count, packet_size):
portal.portal_activities.activate(activity='SQLQueue').ERP5Site_reindexOrUnindexDocumentList(column_list[i:i+packet_size])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>_params</string> </key>
<value> <string>min_uid, limit, packet_size, before, now</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_checkLatestModifiedDocumentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
now = DateTime()
before = now - int(days_before)
strfstring = '%Y-%m-%d %H:%M:%S'
portal.ERP5Site_checkLatestModifiedDocumentList(0, 1000, 100,
before.strftime(strfstring), now.strftime(strfstring))
# Force reindexation of recently created document
# This expect module to use HBTree
# The following category could be consider as "non-optimistic", but
# it is minimal compared to a whole reindex and it is safe to prevent
# Minor inconsistencies.
for module_id in portal.objectIds(("ERP5 Folder",)):
if module_id.endswith("_module"):
portal[module_id].recurseCallMethod(
'recursiveReindexObject',
max_depth=1,
min_depth=1,
max_retry=0,
activity_count=100,
min_id=before.strftime("%Y%m%d"),
)
portal.ERP5Site_checkDeletedDocumentList(0, 1000, 100)
# Whenever we trust that the catalog is consistent and more recent them the
# ZODB, it isn't required to trigger the whole reindexation of the site.
# If the Mariadb is eventually inconsitent or older them the current ZODB,
# It's required reindex the whole site.
if not optimistic:
for module_id in [
'portal_preferences',
'portal_categories',
'portal_alarms',
'portal_simulation']+portal.objectIds(("ERP5 Folder",)):
portal[module_id].recurseCallMethod(
'immediateReindexObject',
min_depth=1,
max_depth=10000,
activate_kw=dict(
group_method_id='portal_catalog/catalogObjectList',
alternate_method_id='alternateReindexObject',
group_method_cost=1,
priority=6,
),
max_retry=0,
activity_count=100,
)
return "OK"
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>_params</string> </key>
<value> <string>optimistic=True, days_before=1</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_recoverFromRestoration</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from erp5.component.module.Log import log
for path, uid in column_list:
try:
ob = context.restrictedTraverse(path)
except KeyError:
log("object not found", path)
context.portal_catalog.activate(activity='SQLQueue').uncatalog_object(uid=uid)
else:
ob.reindexObject()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>_params</string> </key>
<value> <string>column_list</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_reindexOrUnindexDocumentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from erp5.component.module.Log import log
for path, uid in column_list:
try:
_ = context.restrictedTraverse(path)
except KeyError:
log("object not found", path)
context.portal_catalog.activate(activity='SQLQueue').uncatalog_object(uid=uid)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>_params</string> </key>
<value> <string>column_list</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_unindexDeletedDocumentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -290,11 +290,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_core/ERP5Type_getSecurityCategoryFromAggregateRelatedSoftwareInstanceInstanceTree',
'slapos_core/ERP5Type_getSecurityCategoryMapping',
'slapos_core/SlaveInstance_getSecurityCategoryFromSoftwareInstance',
'slapos_disaster_recovery/ERP5Site_checkDeletedDocumentList',
'slapos_disaster_recovery/ERP5Site_checkLatestModifiedDocumentList',
'slapos_disaster_recovery/ERP5Site_recoverFromRestoration',
'slapos_disaster_recovery/ERP5Site_reindexOrUnindexDocumentList',
'slapos_disaster_recovery/ERP5Site_unindexDeletedDocumentList',
'slapos_base/Login_getFastExpirationReferenceList',
'slapos_base/Login_isLoginBlocked',
'slapos_base/Login_isPasswordExpired',
......
......@@ -201,7 +201,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -252,7 +251,6 @@ erp5_integration
erp5_invoicing
%(common_folder_list)s
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -290,7 +288,6 @@ erp5_integration
erp5_invoicing
%(common_folder_list)s
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -330,7 +327,6 @@ erp5_jquery
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -372,7 +368,6 @@ erp5_km_widget_library
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : '\n'.join(common_folder_list.split('\n')[3:]),
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -408,7 +403,6 @@ erp5_integration
erp5_invoicing
%(common_folder_list)s
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -445,7 +439,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -481,7 +474,6 @@ erp5_integration
erp5_invoicing
%(common_folder_list)s
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -517,7 +509,6 @@ erp5_integration
erp5_invoicing
%(common_folder_list)s
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -554,7 +545,6 @@ erp5_integration
erp5_invoicing
%(common_folder_list)s
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -592,7 +582,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -630,7 +619,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -668,7 +656,6 @@ erp5_integration
erp5_invoicing
%(common_folder_list)s
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -707,7 +694,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -744,7 +730,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -779,7 +764,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -814,7 +798,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -849,7 +832,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -901,7 +883,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -936,7 +917,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -971,7 +951,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -1006,7 +985,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -1041,7 +1019,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......@@ -1079,7 +1056,6 @@ erp5_invoicing
%(common_folder_list)s
erp5_xhtml_style
external_method
slapos_disaster_recovery
""" % {'common_folder_list' : common_folder_list,
'common2_folder_list' : common2_folder_list,
'common3_folder_list' : common3_folder_list,
......
slapos_administration
slapos_base
slapos_core
slapos_disaster_recovery
slapos_erp5
\ 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