from sfa.util.xrn import Xrn, urn_to_hrn
from sfa.util.version import version_core
from sfa.util.callids import Callids
+from sfa.util.cache import Cache
+
from sfa.server.threadmanager import ThreadManager
+
from sfa.rspecs.rspec_converter import RSpecConverter
from sfa.rspecs.version_manager import VersionManager
from sfa.rspecs.rspec import RSpec
+
from sfa.client.client_helper import sfa_to_pg_users_arg
from sfa.client.return_value import ReturnValue
class SliceManager:
- def __init__ (self):
- # xxx todo should be configurable
- # self.caching=False
- self.caching=True
+
+ # the cache instance is a class member so it survives across incoming requests
+ cache = None
+
+ def __init__ (self, config):
+ self.cache=None
+ if config.SFA_SM_CACHING:
+ if SliceManager.cache is None:
+ SliceManager.cache = Cache()
+ self.cache = SliceManager.cache
- def GetVersion(self, api):
+ def GetVersion(self, api, options):
# peers explicitly in aggregates.xml
peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems()
if peername != api.hrn])
request_rspec_versions.append(rspec_version.to_dict())
xrn=Xrn(api.hrn, 'authority+sa')
version_more = {'interface':'slicemgr',
- 'sfa': 1,
- 'geni_api': api.config.SFA_AGGREGATE_API_VERSION,
+ 'sfa': 2,
+ 'geni_api': 2,
'hrn' : xrn.get_hrn(),
'urn' : xrn.get_urn(),
'peers': peers,
version_string = "rspec_%s" % (rspec_version)
# look in cache first
- if self.caching and api.cache and not xrn:
- rspec = api.cache.get(version_string)
+ if self.cache and not xrn:
+ rspec = self.cache.get(version_string)
if rspec:
+ api.logger.debug("SliceManager.ListResources returns cached advertisement")
return rspec
# get the callers hrn
api.logger.log_exc("SM.ListResources: Failed to merge aggregate rspec")
# cache the result
- if self.caching and api.cache and not xrn:
- api.cache.add(version_string, rspec.toxml())
+ if self.cache and not xrn:
+ api.logger.debug("SliceManager.ListResources caches advertisement")
+ self.cache.add(version_string, rspec.toxml())
return rspec.toxml()
return server.ListSlices(creds, options)
# look in cache first
- if self.caching and api.cache:
- slices = api.cache.get('slices')
+ # xxx is this really frequent enough that it is worth being cached ?
+ if self.cache:
+ slices = self.cache.get('slices')
if slices:
+ api.logger.debug("SliceManager.ListSlices returns from cache")
return slices
# get the callers hrn
slices.extend(result)
# cache the result
- if self.caching and api.cache:
- api.cache.add('slices', slices)
+ if self.cache:
+ api.logger.debug("SliceManager.ListSlices caches value")
+ self.cache.add('slices', slices)
return slices