Commit 82c79247 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Drop direct access to memcache by using proper API

parent 61d57f57
Pipeline #19491 failed with stage
in 0 seconds
......@@ -19,26 +19,11 @@ show_all = False
if "show_all" in kw:
show_all = kw.pop("omit_zero_ticket")
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
def checkForError(reference):
try:
d = memcached_dict[reference]
except KeyError:
return 1
d = json.loads(d)
result = d['text']
#last_contact = DateTime(d.get('created_at'))
# Optimise by checking memcache information first.
result = context.getAccessStatusText()
if result.startswith('#error '):
return 1
for compute_node in portal.portal_catalog(
default_allocation_scope_uid = [personal_category_uid, public_category_uid, friend_category_uid],
select_list={"reference": None},
......
from DateTime import DateTime
import json
portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed():
......@@ -22,7 +20,6 @@ compute_node_reference = context.getReference()
compute_node_title = context.getTitle()
should_notify = True
memcached_dict = context.Base_getSlapToolMemcachedDict()
tolerance = DateTime()-0.5
for software_installation in software_installation_list:
should_notify = False
......@@ -31,9 +28,12 @@ for software_installation in software_installation_list:
continue
reference = software_installation.getReference()
try:
d = memcached_dict[reference]
d = json.loads(d)
d = software_installation.getAccessStatus()
if d.get("no_data", None) == 1:
ticket_title = "[MONITORING] No information for %s on %s" % (reference, compute_node_reference)
description = "The software release %s did not started to build on %s since %s" % \
(software_installation.getUrlString(), compute_node_title, software_installation.getCreationDate())
else:
last_contact = DateTime(d.get('created_at'))
if d.get("text").startswith("building"):
should_notify = True
......@@ -49,13 +49,7 @@ for software_installation in software_installation_list:
description = "The software release %s is failing to build for too long on %s, started on %s" % \
(software_installation.getUrlString(), compute_node_title, software_installation.getCreationDate())
except KeyError:
ticket_title = "[MONITORING] No information for %s on %s" % (reference, compute_node_reference)
description = "The software release %s did not started to build on %s since %s" % \
(software_installation.getUrlString(), compute_node_title, software_installation.getCreationDate())
if should_notify:
support_request = context.Base_generateSupportRequestForSlapOS(
ticket_title,
description,
......
from DateTime import DateTime
import json
portal = context.getPortalObject()
if portal.ERP5Site_isSupportRequestCreationClosed():
......@@ -18,50 +16,49 @@ reference = context.getReference()
compute_node_title = context.getTitle()
ticket_title = "[MONITORING] Lost contact with compute_node %s" % reference
description = ""
should_notify = True
last_contact = "No Contact Information"
memcached_dict = context.Base_getSlapToolMemcachedDict()
try:
d = memcached_dict[reference]
d = json.loads(d)
d = context.getAccessStatus()
# Ignore if data isn't present.
if d.get("no_data") == 1:
description = "The Compute Node %s (%s) has not contacted the server (No Contact Information)" % (
compute_node_title, reference)
else:
last_contact = DateTime(d.get('created_at'))
if (DateTime() - last_contact) > 0.01:
description = "The Compute Node %s (%s) has not contacted the server for more than 30 minutes" \
"(last contact date: %s)" % (compute_node_title, reference, last_contact)
else:
should_notify = False
except KeyError:
description = "The Compute Node %s (%s) has not contacted the server (No Contact Information)" % (
compute_node_title, reference)
# Nothing to notify.
return
if should_notify:
support_request = context.Base_generateSupportRequestForSlapOS(
ticket_title,
description,
context.getRelativeUrl()
)
support_request = context.Base_generateSupportRequestForSlapOS(
ticket_title,
description,
context.getRelativeUrl()
)
person = context.getSourceAdministrationValue(portal_type="Person")
if not person:
return support_request
person = context.getSourceAdministrationValue(portal_type="Person")
if not person:
return support_request
# Send Notification message
notification_reference = 'slapos-crm-compute_node_check_state.notification'
notification_message = portal.portal_notifications.getDocumentValue(
reference=notification_reference)
# Send Notification message
notification_reference = 'slapos-crm-compute_node_check_state.notification'
notification_message = portal.portal_notifications.getDocumentValue(
reference=notification_reference)
if notification_message is None:
message = """%s""" % description
else:
mapping_dict = {'compute_node_title':context.getTitle(),
'compute_node_id':reference,
'last_contact':last_contact}
message = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':mapping_dict})
if notification_message is None:
message = """%s""" % description
else:
mapping_dict = {'compute_node_title':context.getTitle(),
'compute_node_id':reference,
'last_contact':last_contact}
message = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':mapping_dict})
support_request.SupportRequest_trySendNotificationMessage(
ticket_title,
message, person.getRelativeUrl())
support_request.SupportRequest_trySendNotificationMessage(
ticket_title,
message, person.getRelativeUrl())
return support_request
return support_request
import json
portal = context.getPortalObject()
compute_node = context
now_date = DateTime()
......@@ -7,20 +6,16 @@ if (now_date - compute_node.getCreationDate()) < maximum_days:
# This compute_node was created recently skip
return True
memcached_dict = context.Base_getSlapToolMemcachedDict()
# Check if there is some information in memcached
try:
d = memcached_dict[compute_node.getReference()]
except KeyError:
message_dict = context.getAccessStatus()
# Ignore if data isn't present.
if message_dict.get("no_data", None) == 1:
message_dict = {}
else:
message_dict = json.loads(d)
if message_dict.has_key('created_at'):
contact_date = DateTime(message_dict.get('created_at').encode('utf-8'))
return (now_date - contact_date) < maximum_days
# If no memcached, check in consumption report
# If no access status information, check in consumption report
for sale_packing_list in portal.portal_catalog(
portal_type="Sale Packing List Line",
simulation_state="delivered",
......
from DateTime import DateTime
import json
memcached_dict = context.Base_getSlapToolMemcachedDict()
try:
d = memcached_dict[context.getReference()]
except KeyError:
# Information not available
return None
d = context.getAccessStatus()
# Ignore if data isn't present.
if d.get("no_data", None) == 1:
return
d = json.loads(d)
result = d['text']
last_contact = DateTime(d.get('created_at'))
# Optimise by checking memcache information first.
if result.startswith('#error '):
return last_contact
return None
if d['text'].startswith('#error '):
return DateTime(d.get('created_at'))
from DateTime import DateTime
import json
if context.getAggregateValue(portal_type="Compute Partition") is not None:
memcached_dict = context.Base_getSlapToolMemcachedDict()
try:
d = memcached_dict[context.getReference()]
except KeyError:
d = context.getAccessStatus()
# Ignore if data isn't present.
if d.get("no_data", None) == 1:
if include_message:
return "Not possible to connect"
return
d = json.loads(d)
result = d['text']
last_contact = DateTime(d.get('created_at'))
since = DateTime(d.get('since'))
# Optimise by checking memcache information first.
if result.startswith('#error '):
if ((DateTime()-since)*24*60) > tolerance:
if include_created_at and not include_since:
......@@ -24,7 +20,6 @@ if context.getAggregateValue(portal_type="Compute Partition") is not None:
return result, last_contact, since
return result
# XXX time limit of 48 hours for run at least once.
if include_message and include_created_at and not include_since:
return result, last_contact
elif include_message and include_created_at and include_since:
......
......@@ -6,7 +6,6 @@
#
from DateTime import DateTime
import json
if context.getSimulationState() == "invalidated":
return "Closed Ticket"
......@@ -18,22 +17,20 @@ if document is None:
aggregate_portal_type = document.getPortalType()
memcached_dict = context.Base_getSlapToolMemcachedDict()
if aggregate_portal_type == "Compute Node":
if document.getMonitorScope() == "disabled":
return "Monitor is disabled to the related %s." % document.getPortalType()
try:
d = memcached_dict[document.getReference()]
d = json.loads(d)
last_contact = DateTime(d.get('created_at'))
if (DateTime() - last_contact) < 0.01:
return "All OK, latest contact: %s " % last_contact
else:
return "Problem, latest contact: %s" % last_contact
except KeyError:
return "No Contact Information"
d = context.getAccessStatus()
if d.get("no_data", None) == 1:
return "No Contact Information"
last_contact = DateTime(d.get('created_at'))
if (DateTime() - last_contact) < 0.01:
return "All OK, latest contact: %s " % last_contact
else:
return "Problem, latest contact: %s" % last_contact
if aggregate_portal_type == "Software Installation":
compute_node_title = document.getAggregateTitle()
if document.getAggregateValue().getMonitorScope() == "disabled":
......@@ -42,23 +39,20 @@ if aggregate_portal_type == "Software Installation":
if document.getSlapState() not in ["start_requested", "stop_requested"]:
return "Software Installation is Destroyed."
try:
d = memcached_dict[document.getReference()]
d = json.loads(d)
last_contact = DateTime(d.get('created_at'))
if d.get("text").startswith("building"):
return "The software release %s is building for mode them 12 hours on %s, started on %s" % \
(document.getUrlString(), compute_node_title, document.getCreationDate())
elif d.get("text").startswith("#access"):
return "All OK, software built."
elif d.get("text").startswith("#error"):
return "The software release %s is failing to build for too long on %s, started on %s" % \
(document.getUrlString(), compute_node_title, document.getCreationDate())
except KeyError:
d = context.getAccessStatus()
if d.get("no_data", None) == 1:
return "The software release %s did not started to build on %s since %s" % \
(document.getUrlString(), compute_node_title, document.getCreationDate())
last_contact = DateTime(d.get('created_at'))
if d.get("text").startswith("building"):
return "The software release %s is building for mode them 12 hours on %s, started on %s" % \
(document.getUrlString(), compute_node_title, document.getCreationDate())
elif d.get("text").startswith("#access"):
return "All OK, software built."
elif d.get("text").startswith("#error"):
return "The software release %s is failing to build for too long on %s, started on %s" % \
(document.getUrlString(), compute_node_title, document.getCreationDate())
if aggregate_portal_type == "Instance Tree":
if document.getMonitorScope() == "disabled":
......
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