Commit d211db1f authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Titouan Soulard

slapos_cloud: Add useRevision to SoftwareInstance

parent 7b81a5a2
...@@ -183,6 +183,9 @@ class SoftwareInstance(Item, JSONType): ...@@ -183,6 +183,9 @@ class SoftwareInstance(Item, JSONType):
def getSlapTimestamp(self): def getSlapTimestamp(self):
return self._getSlapTimestamp() return self._getSlapTimestamp()
def useRevision(self):
return getattr(self, "use_jio_api_revision", False)
@UnrestrictedMethod @UnrestrictedMethod
def _getSlapTimestamp(self): def _getSlapTimestamp(self):
compute_partition = self.getAggregateValue(portal_type="Compute Partition") compute_partition = self.getAggregateValue(portal_type="Compute Partition")
...@@ -198,22 +201,31 @@ class SoftwareInstance(Item, JSONType): ...@@ -198,22 +201,31 @@ class SoftwareInstance(Item, JSONType):
# XXX In the current what shared instances are processed, they cannot be reprocessed if the # XXX In the current what shared instances are processed, they cannot be reprocessed if the
# host instance is not processed # host instance is not processed
if (self.getPortalType() == "Software Instance"): if (self.getPortalType() == "Software Instance"):
shared_instance_sql_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults( shared_instance_sql_list = []
default_aggregate_uid=compute_partition.getUid(), if self.useRevision():
portal_type='Slave Instance', shared_instance_sql_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
validation_state="validated", default_aggregate_uid=compute_partition.getUid(),
sort_on=(("jio_api_revision.revision", "DESC"),), portal_type='Slave Instance',
select_list=('jio_api_revision.revision',), validation_state="validated",
limit=1, sort_on=(("jio_api_revision.revision", "DESC"),),
**{"slapos_item.slap_state": "start_requested"} select_list=('jio_api_revision.revision',),
) limit=1,
if shared_instance_sql_list: **{"slapos_item.slap_state": "start_requested"}
shared_instance = shared_instance_sql_list[0].getObject()
most_recent_hosted_instance_timestamp = int(
shared_instance.getBangTimestamp(int(shared_instance.getModificationDate()))
) )
if (most_recent_hosted_instance_timestamp > timestamp): else:
timestamp = most_recent_hosted_instance_timestamp shared_instance_sql_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
default_aggregate_uid=compute_partition.getUid(),
portal_type='Slave Instance',
validation_state="validated",
**{"slapos_item.slap_state": "start_requested"}
)
for shared_instance in shared_instance_sql_list:
shared_instance = _assertACI(shared_instance.getObject())
# XXX Use catalog to filter more efficiently
if shared_instance.getSlapState() == "start_requested":
newtimestamp = int(shared_instance.getBangTimestamp(int(shared_instance.getModificationDate())))
if (newtimestamp > timestamp):
timestamp = newtimestamp
return timestamp return timestamp
...@@ -397,10 +409,11 @@ class SoftwareInstance(Item, JSONType): ...@@ -397,10 +409,11 @@ class SoftwareInstance(Item, JSONType):
"access_status_message": self.getTextAccessStatus(), "access_status_message": self.getTextAccessStatus(),
"portal_type": self.getPortalType(), "portal_type": self.getPortalType(),
} }
web_section = self.getWebSectionValue() if self.useRevision():
web_section = web_section.getRelativeUrl() if web_section else self.REQUEST.get("web_section_relative_url", None) web_section = self.getWebSectionValue()
if web_section: web_section = web_section.getRelativeUrl() if web_section else self.REQUEST.get("web_section_relative_url", None)
result["api_revision"] = self.getJIOAPIRevision(web_section) if web_section:
result["api_revision"] = self.getJIOAPIRevision(web_section)
self.REQUEST.response.setHeader('Cache-Control', self.REQUEST.response.setHeader('Cache-Control',
'private, max-age=0, must-revalidate') 'private, max-age=0, must-revalidate')
......
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