Commit b2f5290c authored by Romain Courteaud's avatar Romain Courteaud

slapos_upgrader: create Remote Node and Remote Instances

parent a27807f1
......@@ -29,6 +29,18 @@ portal.portal_catalog.searchAndActivate(
**migrated_select_dict
)
############################################
# Gather instance tree informations
############################################
portal.portal_catalog.searchAndActivate(
method_id='InstanceTree_fixupSiteMigrationToVirtualMaster',
activate_kw={'tag': tag, 'priority': 1},
portal_type="Instance Tree",
**migrated_select_dict
)
if (run_count == 10):
context.activate(after_tag=tag).Base_triggerFullSiteMigrationToVirtualMasterStep2(run_count=run_count+1)
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
instance_tree = context.getObject()
instance_tree_virtual_master = instance_tree.getFollowUpValue()
instance_tree_virtual_master_relative_url = instance_tree_virtual_master.getRelativeUrl()
remote_virtual_master_dict = {}
is_consistent = True
for sql_result in portal.portal_catalog(specialise__uid=instance_tree.getUid()):
instance = sql_result.getObject()
partition = instance.getAggregateValue()
if partition is not None:
instance_virtual_master_relative_url = partition.getParentValue().getFollowUp(None)
if (instance_virtual_master_relative_url is not None) and (instance_virtual_master_relative_url != instance_tree_virtual_master_relative_url):
if instance_virtual_master_relative_url not in remote_virtual_master_dict:
remote_virtual_master_dict[instance_virtual_master_relative_url] = []
remote_virtual_master_dict[instance_virtual_master_relative_url].append(instance.getRelativeUrl())
is_consistent = False
if not is_consistent:
for instance_virtual_master_relative_url in remote_virtual_master_dict:
instance_tree_virtual_master.Project_checkSiteMigrationCreateRemoteNode(instance_virtual_master_relative_url, remote_virtual_master_dict[instance_virtual_master_relative_url])
<?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>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InstanceTree_fixupSiteMigrationToVirtualMaster</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
instance = context
instance_virtual_master_relative_url = instance.getFollowUp()
connection_xml = instance.getConnectionXml()
remote_node = portal.restrictedTraverse(remote_node_relative_url)
remote_partition = instance.getAggregateValue()
assert instance_virtual_master_relative_url == remote_node.getFollowUp()
assert instance_virtual_master_relative_url != remote_node.getDestinationProject()
assert remote_partition.getFollowUp() == remote_node.getDestinationProject()
#########################################################
# Move current instance to the remote node
#########################################################
if instance.getPortalType() == 'Slave Instance':
# All slave instances goes to this magic partition
new_partition = remote_node.restrictedTraverse('SHARED_REMOTE')
elif instance.getPortalType() == 'Software Instance':
new_partition = remote_node.newContent(
portal_type="Compute Partition",
title="slapmigration",
)
new_partition.markFree()
new_partition.validate()
new_partition.markBusy()
else:
raise NotImplementedError('Not supported instance type: %s' % instance.getPortalType())
portal.portal_workflow.doActionFor(instance, action='edit_action', comment="Migrated to a remote node")
instance.edit(aggregate_value=new_partition)
assert new_partition.getSlapState() == 'busy'
#########################################################
# Create a new instance tree on the remote project
#########################################################
new_partition.ComputePartition_propagateRemoteNode(local_instance_list=[instance.getRelativeUrl()])
remote_instance_tree = context.REQUEST.get('request_instance_tree')
requested_software_instance = context.REQUEST.get('request_instance')
if remote_instance_tree is None:
assert instance.getSlapState() == 'destroy_requested'
else:
requested_software_instance.edit(
# keep the previous allocation partition
aggregate_value=remote_partition,
# keep the original connection xml
connection_xml=connection_xml
)
instance.edit(connection_xml=connection_xml)
assert remote_partition.getSlapState() == 'busy'
# CDN compatibility
# invert the instance references, to ensure cdn keep the same domain name
# as we also want to keep subobject (login), change the instance from one tree into another
original_predecessor = instance.getSuccessorRelatedValue()
assert original_predecessor is not None
successor_list = original_predecessor.getSuccessorList()
successor_list = [x.replace(instance.getRelativeUrl(), requested_software_instance.getRelativeUrl()) for x in successor_list]
instance_title = instance.getTitle()
instance_tree = instance.getSpecialiseValue()
new_remote_title = '_remote_%s_%s' % (instance_tree.getFollowUpReference(), requested_software_instance.getReference())
remote_instance_tree.edit(
successor_value=instance,
title=new_remote_title
)
instance.edit(
title=remote_instance_tree.getTitle(),
specialise_value=remote_instance_tree,
aggregate_value=remote_partition,
follow_up_value=remote_instance_tree.getFollowUpValue()
)
original_predecessor.edit(
successor_list=successor_list
)
requested_software_instance.edit(
title=instance_title,
specialise_value=instance_tree,
aggregate_value=new_partition,
follow_up_value=instance_tree.getFollowUpValue()
)
<?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>remote_node_relative_url, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Instance_activateMigrationToRemoteProject</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
project = context
is_first_call = (tag is None)
tag = "%s_%s_%s" % (project.getUid(), script.id, remote_project_relative_url)
activate_kw = {
'tag': tag
}
wait_activate_kw = {
'activity': 'SQLQueue',
'serialization_tag': tag,
'after_tag': tag
}
remote_project = portal.restrictedTraverse(remote_project_relative_url)
# Search the existing virtual master
remote_node_title = 'Migrated remote to %s' % remote_project.getReference()
remote_node = portal.portal_catalog.getResultValue(
portal_type='Remote Node',
destination_project__uid=remote_project.getUid(),
follow_up__uid=project.getUid(),
title={'query': remote_node_title, 'key': 'ExactMatch'}
)
if remote_node is None:
# Delay the script to prevent conflict with serialize
# in the caller script
# Prevent concurrent activities
if is_first_call or (0 < portal.portal_activities.countMessageWithTag(tag)):
return project.activate(**wait_activate_kw).Project_checkSiteMigrationCreateRemoteNode(remote_project_relative_url, relative_url_to_migrate_list, tag=tag, *args, **kw)
project.serialize()
# No concurrent activity.
# Create it
# XXX copied from Project_addSlapOSRemoteNode
remote_node = portal.compute_node_module.newContent(
portal_type='Remote Node',
title=remote_node_title,
# Use the project owner
destination_section_value=remote_project.getDestinationValue(),
destination_project_value=remote_project,
follow_up_value=project,
allocation_scope='open',
activate_kw=activate_kw
)
remote_node.validate()
remote_node.reindexObject(activate_kw=activate_kw)
# XXX Then, migrate other documents linked to the virtual master
for relative_url_to_migrate in relative_url_to_migrate_list:
object_to_migrate = portal.restrictedTraverse(relative_url_to_migrate)
object_to_migrate.activate().Instance_activateMigrationToRemoteProject(remote_node.getRelativeUrl())
<?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>remote_project_relative_url, relative_url_to_migrate_list, REQUEST=None, tag=None, *args, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Project_checkSiteMigrationCreateRemoteNode</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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