X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fcore%2Fexecute.py;h=cf32e6a43898a8909878d90ac288e8803e66c491;hb=67a5d232414a375c224e06058fbef0ae63be58c9;hp=e333940c52222f74b9d0cef1ca55cb7ecfefc1dc;hpb=1e4e1b47a3a76be0fdf7d229ad0952ea2feb4095;p=nepi.git diff --git a/src/nepi/core/execute.py b/src/nepi/core/execute.py index e333940c..cf32e6a4 100644 --- a/src/nepi/core/execute.py +++ b/src/nepi/core/execute.py @@ -2,197 +2,90 @@ # -*- coding: utf-8 -*- from nepi.core.attributes import Attribute, AttributesMap -from nepi.util.constants import STATUS_FINISHED -from nepi.util.parser._xml import XmlExperimentParser from nepi.util import validation +from nepi.util.constants import ApplicationStatus as AS, TestbedStatus as TS, TIME_NOW, DeploymentConfiguration as DC +from nepi.util.parser._xml import XmlExperimentParser import sys +import re +import threading +import ConfigParser +import os +import collections +import functools +import time +import logging +logging.basicConfig() -class ConnectorType(object): - def __init__(self, testbed_id, factory_id, name, max = -1, min = 0): - super(ConnectorType, self).__init__() - if max == -1: - max = sys.maxint - elif max <= 0: - raise RuntimeError( - "The maximum number of connections allowed need to be more than 0") - if min < 0: - raise RuntimeError( - "The minimum number of connections allowed needs to be at least 0") - # connector_type_id -- univoquely identifies a connector type - # across testbeds - self._connector_type_id = (testbed_id.lower(), factory_id.lower(), - name.lower()) - # name -- display name for the connector type - self._name = name - # max -- maximum amount of connections that this type support, - # -1 for no limit - self._max = max - # min -- minimum amount of connections required by this type of connector - self._min = min - # from_connections -- connections where the other connector is the "From" - # to_connections -- connections where the other connector is the "To" - # keys in the dictionary correspond to the - # connector_type_id for possible connections. The value is a tuple: - # (can_cross, connect) - # can_cross: indicates if the connection is allowed accros different - # testbed instances - # code: is the connection function to be invoked when the elements - # are connected - self._from_connections = dict() - self._to_connections = dict() - - @property - def connector_type_id(self): - return self._connector_type_id - - @property - def name(self): - return self._name - - @property - def max(self): - return self._max - - @property - def min(self): - return self._min - - def add_from_connection(self, testbed_id, factory_id, name, can_cross, code): - self._from_connections[(testbed_id.lower(), factory_id.lower(), - name.lower())] = (can_cross, code) - - def add_to_connection(self, testbed_id, factory_id, name, can_cross, code): - self._to_connections[(testbed_id.lower(), factory_id.lower(), - name.lower())] = (can_cross, code) - - def can_connect(self, testbed_id, factory_id, name, count, - must_cross = False): - connector_type_id = (testbed_id.lower(), factory_id.lower(), - name.lower()) - if connector_type_id in self._from_connections: - (can_cross, code) = self._from_connections[connector_type_id] - elif connector_type_id in self._to_connections: - (can_cross, code) = self._to_connections[connector_type_id] - else: - return False - return not must_cross or can_cross - - def code_to_connect(self, testbed_id, factory_id, name): - connector_type_id = (testbed_id.lower(), factory_id.lower(), - name.lower()) - if not connector_type_id in self._to_connections.keys(): - return False - (can_cross, code) = self._to_connections[connector_type_id] - return code - -# TODO: create_function, start_function, stop_function, status_function -# need a definition! -class Factory(AttributesMap): - def __init__(self, factory_id, create_function, start_function, - stop_function, status_function, allow_addresses = False, - allow_routes = False): - super(Factory, self).__init__() - self._factory_id = factory_id - self._allow_addresses = (allow_addresses == True) - self._allow_routes = (allow_routes == True) - self._create_function = create_function - self._start_function = start_function - self._stop_function = stop_function - self._status_function = status_function - self._connector_types = dict() - self._traces = list() - self._box_attributes = AttributesMap() - - @property - def factory_id(self): - return self._factory_id - - @property - def allow_addresses(self): - return self._allow_addresses - - @property - def allow_routes(self): - return self._allow_routes +ATTRIBUTE_PATTERN_BASE = re.compile(r"\{#\[(?P