示例#1
0
 def create_extractor(self, extractor_name, environment):
     self._log.info(self.__class__.__name__, 'Starting to create extractor %s for environment %s',
                    extractor_name, environment)
     '''
     Each extractor depends on the metric to extract and the environment in which the simulation is running. In
     general, each environment has its own way for extracting data, so there will be more implementation for
     the same metric. By convention, a class that models an extractor for a specific environment is called as follow:
     Environment+Metric. For example, to extract device-load metric from mininet, the class will be called
     MininetDeviceLoad. So, for instantiating the extractor, just concatenate the parameter environment to the
     last part of extractor name
     '''
     self._log.debug(self.__class__.__name__, 'Splitting class module.')
     # Split into a list [module, module, module, ..., class_name]
     parts = extractor_name.split('.')
     self._log.debug(self.__class__.__name__, 'Isolating class name.')
     # Take the last one, namely the class_name
     class_name = parts[len(parts) - 1]
     self._log.debug(self.__class__.__name__, 'Extractor to load: %s.', environment + class_name)
     # Concat the environment name, obtaining EnvironmentClassName (e.g. MininetLoadDevice)
     parts[len(parts) - 1] = environment + class_name
     # Join the list into a class with modules (e.g. module.module.module.ClassName)
     extractor_class_name = '.'.join(parts)
     self._log.debug(self.__class__.__name__, 'Creating a new instance for %s', extractor_class_name)
     # Load an instance
     self._extractor = Class.for_name(extractor_class_name)
     self._log.info(self.__class__.__name__, 'Extractor %s has been created.', extractor_class_name)
     return self._extractor
示例#2
0
 def create_alternative(self, alternative_name, alternative_adapter, scenario_parameters):
     self._log.info(self.__class__.__name__, 'Creating alternative %s.', alternative_name)
     # The pattern of params for the for_name method is: adapter, name of the alternative and all parameters defined
     # in the configuration file
     alternative = Class.for_name(alternative_adapter, name=alternative_name, scenario=scenario_parameters)
     # Add the alternative to the list of alternatives
     self._alternatives.append(alternative)
     self._log.debug(self.__class__.__name__, 'Adding alternative %s to the list of alternatives of service %s.',
                     alternative_name, self._name)
     self._log.info(self.__class__.__name__, 'Alternative %s has been correctly created.', alternative_name)
     return alternative
示例#3
0
 def create_service_parser(self, service_adapter, service_name):
     self._service_parser = Class.for_name(service_adapter, service_name)
     return self._service_parser