Commit dad13eb5 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactored workflow to be used by Slave Instance. The scripts were merged with...

refactored workflow to be used by Slave Instance. The scripts were merged with scripts from slave_instance_slap_instance_workflow.

Now, the script SoftwareInstance_requestComputerPartition is able to allocate a Slave Instance in the right Computer Partition
parent 34909b9a
...@@ -55,6 +55,37 @@ ...@@ -55,6 +55,37 @@
from DateTime import DateTime\n from DateTime import DateTime\n
import random\n import random\n
\n \n
def checkSoftwareInstanceIsInstalledOnComputerPartition(software_release,\n
computer_partition):\n
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery\n
resource_relative_url = (\n
portal.portal_preferences.getPreferredInstanceSetupResource(),\n
portal.portal_preferences.getPreferredInstanceHostingResource(),\n
)\n
query = ComplexQuery(Query(aggregate_relative_url=software_release.getRelativeUrl()),\n
Query(aggregate_relative_url=computer_partition.getRelativeUrl()),\n
operator="AND",\n
)\n
sale_packing_list_line_list = portal.portal_catalog(\n
portal_type=\'Sale Packing List Line\',\n
query=query,\n
resource_relative_url=resource_relative_url,\n
limit=1)\n
\n
if len(sale_packing_list_line_list) == 1:\n
resource_relative_url = (\n
portal.portal_preferences.getPreferredInstanceCleanupResource(),\n
)\n
sale_packing_list_line_list = portal.portal_catalog(\n
portal_type=\'Sale Packing List Line\',\n
query=query,\n
resource_relative_url=resource_relative_url,\n
limit=1)\n
if len(sale_packing_list_line_list) == 0:\n
return True\n
return False\n
\n
portal = context.getPortalObject()\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
...@@ -75,15 +106,19 @@ SQL_WINDOW_SIZE = 50\n ...@@ -75,15 +106,19 @@ SQL_WINDOW_SIZE = 50\n
computer_partition = None\n computer_partition = None\n
query_kw = {\n query_kw = {\n
\'software_release_url\': software_release_url_string,\n \'software_release_url\': software_release_url_string,\n
\'portal_type\': \'Computer Partition\'\n \'portal_type\': \'Computer Partition\',\n
\'free_for_request\': 1,\n
}\n }\n
\n
if software_instance.getPortalType() == "Slave Instance":\n
query_kw[\'free_for_request\'] = 0\n
\n
# support SLA\n # support SLA\n
if "computer_guid" in filter_kw:\n if "computer_guid" in filter_kw:\n
query_kw["parent_reference"] = filter_kw["computer_guid"]\n query_kw["parent_reference"] = filter_kw["computer_guid"]\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
query_kw.update(free_for_request=1) # is free\n
result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n
offset = max(0, result_count-1)\n offset = max(0, result_count-1)\n
if offset >= SQL_WINDOW_SIZE:\n if offset >= SQL_WINDOW_SIZE:\n
...@@ -91,11 +126,21 @@ if offset >= SQL_WINDOW_SIZE:\n ...@@ -91,11 +126,21 @@ if offset >= SQL_WINDOW_SIZE:\n
else:\n else:\n
limit = (0, SQL_WINDOW_SIZE)\n limit = (0, SQL_WINDOW_SIZE)\n
\n \n
software_release = context.portal_catalog.getResultValue(\n
portal_type=\'Software Release\',\n
url_string=software_release_url_string)\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 software_instance_portal_type = software_instance.getPortalType()\n
if isTransitionPossible(computer_partition_candidate, \'mark_busy\') and \\\n
software_instance_portal_type == "Software Instance":\n
computer_partition = computer_partition_candidate\n
break\n
elif software_instance_portal_type == "Slave Instance" and \\\n
checkSoftwareInstanceIsInstalledOnComputerPartition(software_release, computer_partition_candidate):\n
computer_partition = computer_partition_candidate\n computer_partition = computer_partition_candidate\n
break\n break\n
\n \n
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from Products.ERP5Type.Log import log\n <value> <string>from Products.ERP5Type.Log import log\n
packing_list_line = context.SoftwareInstance_getInstanceHostingPackingListLine(state_change)\n packing_list_line = context.SoftwareInstance_getInstanceHostingPackingListLine(state_change)\n
if packing_list_line.getSimulationState() != "started":\n if packing_list_line.getSimulationState() not in ("started", "delivered"):\n
packing_list_line.getParentValue().start()\n packing_list_line.getParentValue().start()\n
else:\n else:\n
software_instance = state_change["object"].getRelativeUrl()\n software_instance = state_change["object"].getRelativeUrl()\n
......
...@@ -54,8 +54,10 @@ ...@@ -54,8 +54,10 @@
packing_list_line = context.SoftwareInstance_getInstanceHostingPackingListLine(state_change)\n packing_list_line = context.SoftwareInstance_getInstanceHostingPackingListLine(state_change)\n
except ValueError:\n except ValueError:\n
return\n return\n
isTransitionPossible = context.portal_workflow.isTransitionPossible\n
packing_list = packing_list_line.getParentValue()\n packing_list = packing_list_line.getParentValue()\n
packing_list.deliver()\n if isTransitionPossible(packing_list, "deliver"):\n
packing_list.deliver()\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
Slave Instance | edit_workflow Slave Instance | edit_workflow
Slave Instance | item_workflow Slave Instance | item_workflow
Slave Instance | slave_instance_slap_interface_workflow Slave Instance | local_permission_vifib_interaction_workflow
Slave Instance | slap_interaction_workflow
Slave Instance | software_instance_slap_interface_workflow
Software Instance | edit_workflow Software Instance | edit_workflow
Software Instance | item_workflow Software Instance | item_workflow
Software Instance | local_permission_vifib_interaction_workflow
Software Instance | slap_interaction_workflow
Software Instance | software_instance_slap_interface_workflow Software Instance | software_instance_slap_interface_workflow
\ 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