Exemple #1
0
def try_load_representation(representation, timestamp=timestamper.now()):
    if __debug__: logging.debug('timestamp = %s, representation = %s', timestamp, representation)
    try:
        configuration = Configuration(representation, timestamp)
        return configuration
    except ValidationError, e:
        logging.error('Configuration is not valid: %s', e)
        return None
Exemple #2
0
 def __init__(self, representation=None, timestamp=timestamper.now()):
     super(Configuration, self).__init__()
     self.timestamp = timestamp
     if representation:
         validate_representation(representation)
         self.original_representation = representation
         self.deployments = dict((name, Deployment(name, deployment_representation)) for name, deployment_representation in representation.get('deployments', {}).iteritems())
         self.active_deployment_name = representation['active_deployment']
         self.active_deployment = self.deployments[self.active_deployment_name]
         self.target_deployment_name = representation.get('target_deployment', None)
         self.target_deployment = self.deployments[self.target_deployment_name] if self.target_deployment_name else None
         self.coordinators = dict((coordinator_id, Coordinator(coordinator_id, address, port)) for coordinator_id, (address, port) in representation.get('coordinators', {}).iteritems())
         self.master_coordinator_id = representation.get('master_coordinator', None)
         self.master_coordinator = self.coordinators.get(self.master_coordinator_id, None)
Exemple #3
0
 def __get_timestamp(self, env):
     try:
         return timestamper.try_loads(env.get('HTTP_X_TIMESTAMP', None)) or timestamper.now()
     except ValueError:
         raise httpserver.BadRequest()
Exemple #4
0
def try_load_json(s, timestamp=timestamper.now()):
    try:
        representation = json.loads(s)
    except Exception, e:
        logging.error('Failed to parse JSON configuration: %s', e)
        return None