Commit 737a4d06 authored by Łukasz Nowak's avatar Łukasz Nowak

Continue migration implemnetation.

parent 8d8a4d69
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>context.getPortalObject().portal_catalog.searchAndActivate(\n <value> <string>context.getPortalObject().portal_catalog.searchAndActivate(\n
portal_type=\'Hosting Subscription\',\n portal_type=[\'Hosting Subscription\', \'Software Instance\', \'Slave Instance\'],\n
method_id=\'HostingSubscription_migrateSlapState\'\n method_id=\'SlapDocument_migrateSlapState\'\n
)\n )\n
</string> </value> </string> </value>
</item> </item>
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ERP5Site_migrateHostingSubscriptionSlapState</string> </value> <value> <string>ERP5Site_migrateSlapState</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -50,29 +50,123 @@ ...@@ -50,29 +50,123 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>hosting_subscription = context\n <value> <string>from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery\n
assert(context.getPortalType() == \'Hosting Subscription\')\n
\n \n
sale_order_line_list = context.getAggregateRelatedValueList(portal_type=\'Sale Order Line\')\n slap_document = context\n
sale_order_line = sale_order_line_list[0]\n portal = context.getPortalObject()\n
\n \n
# Person is now directly associated on the HS\n portal_type_list = (\'Hosting Subscription\', \'Software Instance\', \'Slave Instance\')\n
hosting_subscription.edit(\n portal_type = slap_document.getPortalType()\n
if portal_type not in portal_type_list:\n
raise TypeError(\'%s is not %s\' % (slap_document.getPath(), portal_type_list))\n
\n
sale_order_line = slap_document.getAggregateRelatedValue(portal_type=\'Sale Order Line\')\n
\n
\n
if portal_type == \'Hosting Subscription\':\n
# Person is now directly associated on the HS\n
slap_document.edit(\n
destination_section_value=sale_order_line.getDestinationSectionValue(portal_type="Person"),\n destination_section_value=sale_order_line.getDestinationSectionValue(portal_type="Person"),\n
)\n )\n
assert(hosting_subscription.getDestinationSection() == sale_order_line.getDestinationSectionValue().getRelativeUrl())\n assert(slap_document.getDestinationSection() == sale_order_line.getDestinationSectionValue().getRelativeUrl())\n
else:\n
hosting_subscription = sale_order_line.getAggregateValue(portal_type=\'Hosting Subscription\')\n
slap_document.edit(\n
specialise_value=hosting_subscription\n
)\n
assert(slap_document.getSpecialise() == hosting_subscription.getRelativeUrl())\n
\n
\n \n
# Migrate slap state\n # Migrate slap state\n
state = hosting_subscription.getRootState()\n if portal_type == \'Hosting Subscription\':\n
assert(hosting_subscription.getSlapState() == \'draft\')\n state = slap_document.getRootState()\n
if state == "started":\n promise_kw = {\n
hosting_subscription.requestStarted()\n \'instance_xml\': context.getTextContent(),\n
elif state == "stopped":\n \'software_type\': context.getSourceReference(),\n
hosting_subscription.requestStopped()\n \'sla_xml\': context.getSlaXml(),\n
elif state == "destroyed":\n \'software_release\': context.getRootSoftwareReleaseUrl(),\n
hosting_subscription.requestDestroyed()\n \'shared\': slap_document.isRootSlave()\n
}\n
else:\n
explanation_delivery_line = portal.portal_catalog.getResultValue(\n
portal_type=\'Sale Packing List Line\',\n
query=ComplexQuery(\n
Query(default_aggregate_uid=slap_document.getUid()),\n
Query(default_resource_uid=[\n
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceSetupResource()).getUid(),\n
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceHostingResource()).getUid(),\n
portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceCleanupResource()).getUid(),\n
]),\n
operator=\'AND\',\n
),\n
sort_on=((\'movement.start_date\', \'DESC\'),)\n
)\n
if explanation_delivery_line is None:\n
explanation_delivery_line = sale_order_line\n
\n
if explanation_delivery_line.getPortalType() == \'Sale Packing List Line\':\n
resource = explanation_delivery_line.getResource()\n
if resource == portal.portal_preferences.getPreferredInstanceSetupResource():\n
state = \'stopped\'\n
elif resource == portal.portal_preferences.getPreferredInstanceCleanupResource():\n
state = \'destroyed\'\n
elif resource == portal.portal_preferences.getPreferredInstanceHostingResource():\n
if explanation_delivery_line.getSimulationState() in (\'confirmed\', \'started\'):\n
state = \'started\'\n
else:\n
state = \'stopped\'\n
pass\n
else:\n
raise TypeError(\'Bad resource %s\' % resource)\n
pass\n
else:\n
if explanation_delivery_line.getSimulationState() == \'cancelled\':\n
state = \'destoyed\'\n
else:\n
raise NotImplementedError\n
promise_kw = {\n
\'instance_xml\': context.getTextContent(),\n
\'software_type\': context.getSourceReference(),\n
\'sla_xml\': context.getSlaXml(),\n
\'software_release\': context.getRootSoftwareReleaseUrl(),\n
\'shared\': slap_document.getPortalType() == \'Slave Instance\'\n
}\n
\n
slap_document.setCausalityValue(explanation_delivery_line.getParentValue())\n
state_map = {\n
\'started\': \'start_requested\',\n
\'stopped\': \'stop_requested\',\n
\'destroyed\': \'destroy_requested\'\n
}\n
\n
if slap_document.getSlapState() == \'draft\':\n
if state == "started":\n
slap_document.requestStart(comment=\'Migration.\', **promise_kw)\n
elif state == "stopped":\n
slap_document.requestStop(comment=\'Migration.\', **promise_kw)\n
elif state == "destroyed":\n
slap_document.requestStop(comment=\'Migration, in order to reach destroy.\', **promise_kw)\n
slap_document.requestDestroy(comment=\'Migration.\', **promise_kw)\n
else:\n
raise ValueError("Unknown state %s for %s" % (state, slap_document.getRelativeUrl()))\n
if not(slap_document.getSlapState() == state_map[state]):\n
raise ValueError(\'%s: %s != %s\' % (state, slap_document.getSlapState(), state_map[state]))\n
\n
# Migrate validation state\n
if portal_type == \'Hosting Subscription\':\n
if state == \'destroyed\':\n
slap_document.validate()\n
slap_document.archive()\n
assert(slap_document.getValidationState() == \'archived\')\n
else:\n
assert(slap_document.getValidationState() == \'validated\')\n
else:\n else:\n
raise NotImplementedError, "Unknown state %s for %s" % (state, hosting_subscription.getRelativeUrl())\n if state == \'destroyed\' and \\\n
(explanation_delivery_line.getPortalType() == \'Sale Order Line\' or \\\n
explanation_delivery_line.getSimulationState() == \'delivered\'):\n
slap_document.invalidate()\n
else:\n
assert(slap_document.getValidationState() == \'validated\')\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -81,7 +175,7 @@ else:\n ...@@ -81,7 +175,7 @@ else:\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>HostingSubscription_migrateSlapState</string> </value> <value> <string>SlapDocument_migrateSlapState</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
85 86
\ 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