Commit c2bc2e55 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor code that searchs a free Slave Partition and remove transation to update a Slave Partition

parent ec61f6b4
...@@ -58,7 +58,6 @@ import random\n ...@@ -58,7 +58,6 @@ import random\n
software_instance = state_change[\'object\']\n software_instance = state_change[\'object\']\n
software_release_url_string = state_change.kwargs[\'software_release\']\n software_release_url_string = state_change.kwargs[\'software_release\']\n
hosting_subscription_uid = state_change.kwargs[\'hosting_subscription_uid\']\n hosting_subscription_uid = state_change.kwargs[\'hosting_subscription_uid\']\n
shared = state_change.kwargs[\'shared\']\n
software_type = state_change.kwargs["software_type"]\n software_type = state_change.kwargs["software_type"]\n
tag = state_change.kwargs[\'tag\']\n tag = state_change.kwargs[\'tag\']\n
filter_kw = software_instance.getSlaXmlAsDict()\n filter_kw = software_instance.getSlaXmlAsDict()\n
...@@ -84,65 +83,27 @@ if "computer_guid" in filter_kw:\n ...@@ -84,65 +83,27 @@ if "computer_guid" in filter_kw:\n
\n \n
# fetch at mot 50 random Computer Partitions, and check if they are ok\n # fetch at mot 50 random Computer Partitions, and check if they are ok\n
isTransitionPossible = software_instance.getPortalObject().portal_workflow.isTransitionPossible\n isTransitionPossible = software_instance.getPortalObject().portal_workflow.isTransitionPossible\n
if shared:\n query_kw.update(free_for_request=1) # is free\n
query_kw.update(\n result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n
software_type=software_type,\n offset = max(0, result_count-1)\n
available_slave=1, # has slave\n if offset >= SQL_WINDOW_SIZE:\n
free_for_request=0, # is not available for normal request\n limit = (random.randint(0, offset), SQL_WINDOW_SIZE)\n
)\n
result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n
\n
offset = max(0, result_count-1)\n
if offset >= SQL_WINDOW_SIZE:\n
limit = (random.randint(0, offset), SQL_WINDOW_SIZE)\n
else:\n
limit = (0, SQL_WINDOW_SIZE)\n
for computer_partition_candidate in software_instance.portal_catalog(\n
limit=limit, **query_kw):\n
computer_partition_candidate = computer_partition_candidate.getObject()\n
# Check if the computer partition can be marked as busy (done by an interaction workflow on sale packing list level)\n
if computer_partition_candidate.getSlapState() == \'busy\' and computer_partition_candidate.ComputerPartition_isSlaveAvailable():\n
computer_partition = computer_partition_candidate\n
break\n
\n
if computer_partition is None:\n
raise ValueError(\'It was not possible to find Computer Partition with free slave\')\n
\n
# find free slave\n
slave_partition = None\n
for slave_partition_candidate in computer_partition.contentValues(portal_type=\'Slave Partition\'):\n
if isTransitionPossible(slave_partition_candidate, \'mark_busy\'):\n
slave_partition = slave_partition_candidate\n
slave_partition.serialize()\n
break\n
\n
if slave_partition is None:\n
slave_partition = computer_partition.newContent(portal_type=\'Slave Partition\')\n
slave_partition.markFree()\n
computer_partition = slave_partition\n
else:\n else:\n
query_kw.update(free_for_request=1) # is free\n limit = (0, SQL_WINDOW_SIZE)\n
result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n
\n
offset = max(0, result_count-1)\n
if offset >= SQL_WINDOW_SIZE:\n
limit = (random.randint(0, offset), SQL_WINDOW_SIZE)\n
else:\n
limit = (0, SQL_WINDOW_SIZE)\n
\n \n
for computer_partition_candidate in software_instance.portal_catalog(\n for computer_partition_candidate in software_instance.portal_catalog(\n
limit=limit, **query_kw):\n limit=limit, **query_kw):\n
computer_partition_candidate = computer_partition_candidate.getObject()\n computer_partition_candidate = computer_partition_candidate.getObject()\n
# Check if the computer partition can be marked as busy (done by an interaction workflow on sale packing list level)\n # Check if the computer partition can be marked as busy (done by an interaction workflow on sale packing list level)\n
if isTransitionPossible(computer_partition_candidate, \'mark_busy\'):\n if isTransitionPossible(computer_partition_candidate, \'mark_busy\'):\n
computer_partition = computer_partition_candidate\n computer_partition = computer_partition_candidate\n
break\n break\n
\n \n
if computer_partition is None:\n if computer_partition is None:\n
raise ValueError(\'It was not possible to find free Computer Partition\')\n raise ValueError(\'It was not possible to find free Computer Partition\')\n
\n \n
# lock computer partition\n # lock computer partition\n
computer_partition.serialize()\n computer_partition.serialize()\n
\n \n
software_release_document = context.portal_catalog.getResultValue(\n software_release_document = context.portal_catalog.getResultValue(\n
portal_type=\'Software Release\',\n portal_type=\'Software Release\',\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>software_instance = state_change[\'object\']\n
slave_partition_count = state_change.kwargs[\'slave_partition_count\']\n
\n
packing_list_line = context.SoftwareInstance_getInstanceHostingPackingListLine(state_change)\n
computer_partition = packing_list_line.getAggregateValue(portal_type="Computer Partition")\n
\n
# Update number of slave partitions\n
computer_partition.edit(quantity=slave_partition_count)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstance_updateSlavePartitionList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string>SoftwareInstance_updateSlavePartitionList</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>update_slave_partition_list</string> </value>
</item>
<item>
<key> <string>new_state_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>script_name</string> </key>
<value> <string>SoftwareInstance_checkConsistency</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Update Slave Partition</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
253 254
\ 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