Example #1
0
 def setUp(self):
     self.req = MagicMock()
     self.resp = MagicMock()
     self.db_handler = MagicMock()
     self.resource = WorkersStatusResource(self.db_handler)
     self.registration = WorkerRegistration('worker').format()
     self.worker = Worker(**self.registration)
     self.worker_dict = Worker(**self.registration).format()
Example #2
0
 def setUp(self):
     self.req = MagicMock()
     self.resp = MagicMock()
     self.db_handler = MagicMock()
     self.resource = WorkerStatusResource(self.db_handler)
     self.registration = WorkerRegistration('worker').format()
     self.worker = Worker(**self.registration)
     self.worker_dict = Worker(**self.registration).format()
     self.worker_id = '51375fc4eea50d53066292b6'
     self.worker_not_found = None
Example #3
0
    def on_put(self, req, resp, hostname, validated_body):
        """
        updates a worker's status or creates a new worker entry if not found
        """

        #load validated json payload in body
        body = validated_body['worker_status']

        #find the worker in db
        worker = worker_util.find_worker(hostname)

        if worker is None:
            #instantiate new worker object
            new_worker = Worker(**body)
            #persist the new worker
            worker_util.create_worker(new_worker)
            resp.status = falcon.HTTP_202
            return

        if 'status' in body:
            worker.status = body['status']

        if 'system_info' in body:
            worker.system_info = SystemInfo(**body['system_info'])

        worker_util.save_worker(worker)
        resp.status = falcon.HTTP_200
Example #4
0
    def before(self):
        self.status = 'online'
        self.system_info = SystemInfo().format()
        self.worker_status = {
            'worker_status': {
                'system_info': self.system_info,
                'status': self.status
            }
        }

        self.bad_status = 'bad_status'
        self.bad_system_info = SystemInfo()
        self.bad_worker_status = {
            'worker_status': {
                'system_info': self.system_info,
                'status': self.bad_status
            }
        }

        self.req = MagicMock()
        self.resp = MagicMock()
        self.registration = WorkerRegistration('worker').format()
        self.worker_dict = Worker(**self.registration).format()
        self.worker_not_found = None
        self.db_handler = MagicMock()
        self.resource = WorkerStatusResource(self.db_handler)
        self.worker_id = '51375fc4eea50d53066292b6'
        self.test_route = '/v1/worker/{worker_id}/status'
        self.api.add_route(self.test_route, self.resource)
Example #5
0
def find_worker(hostname):
    """
    returns worker object based on hostname
    """
    worker_dict = _db_handler.find_one('worker', {'hostname': hostname})
    if worker_dict:
        return Worker(**worker_dict)
    return None
Example #6
0
def retrieve_all_workers():
    """
    Retrieve all worker documents from the db and
    return a list of Worker objects
    """
    return [
        Worker(**worker_dict) for worker_dict in _db_handler.find('worker')
    ]
Example #7
0
def find_worker(db, worker_id):
    """
    returns worker object based on worker id
    """
    worker_dict = db.find_one('worker', {'worker_id': worker_id})
    if not worker_dict:
        error._worker_not_found()
    return Worker(**worker_dict)
Example #8
0
    def on_get(self, req, resp):

        workers = self.db.find('worker')

        workers_status = [Worker(**worker).get_status() for worker in workers]

        resp.status = falcon.HTTP_200
        resp.body = format_response_body({'status': workers_status})
Example #9
0
 def setUp(self):
     self.system_info = SystemInfo().format()
     self.worker = Worker(
         **{
             "hostname": "worker-01",
             "ip_address_v4": "192.168.100.101",
             "ip_address_v6": "::1",
             "personality": "worker",
             "status": "online",
             "system_info": self.system_info
         })
Example #10
0
    def on_get(self, req, resp, worker_id):
        #find the worker in db
        worker_dict = self.db.find_one('worker', {'worker_id': worker_id})

        if not worker_dict:
            _worker_not_found()

        worker = Worker(**worker_dict)

        resp.status = falcon.HTTP_200
        resp.body = format_response_body({'status': worker.get_status()})
Example #11
0
    def setUp(self):
        self.system_info = SystemInfo()

        self.test_worker = Worker(_id='010101',
                                  worker_token='9876543210',
                                  hostname='worker01',
                                  callback='172.22.15.25:8080/v1/config/',
                                  ip_address_v4='172.23.1.100',
                                  ip_address_v6='::1',
                                  personality='worker',
                                  status='new',
                                  system_info=self.system_info.format())
        self.test_worker_lite = Worker(hostname='worker01',
                                       callback='172.22.15.25:8080/v1/config/',
                                       ip_address_v4='172.23.1.100',
                                       ip_address_v6='::1',
                                       personality='worker',
                                       status='new',
                                       system_info=self.system_info.format())
        self.worker_status = self.test_worker.get_status()
Example #12
0
 def setUp(self):
     self.req = MagicMock()
     self.resp = MagicMock()
     self.hostname = 'worker01'
     self.resource = WorkersStatusResource()
     self.worker = Worker(_id='010101',
                          hostname=self.hostname,
                          ip_address_v4='172.23.1.100',
                          ip_address_v6='::1',
                          personality='worker01',
                          status='online',
                          system_info={})
Example #13
0
    def before(self):
        self.status = 'online'
        self.hostname = 'worker01'
        self.personality = 'worker'
        self.ip4 = "192.168.100.101",
        self.ip6 = "::1",
        self.system_info = SystemInfo().format()

        self.bad_status = 'bad_status'
        self.bad_system_info = SystemInfo()
        self.bad_worker_status = {
            'worker_status': {
                'hostname': self.hostname,
                'system_info': self.system_info,
                'status': self.bad_status,
                'personality': 'worker',
                'ip_address_v4': '192.168.100.101',
                'ip_address_v6': '::1'
            }
        }

        self.worker = {
            'worker_status': {
                'hostname': self.hostname,
                'system_info': self.system_info,
                'status': self.status,
                'personality': 'worker',
                'ip_address_v4': '192.168.100.101',
                'ip_address_v6': '::1'
            }
        }

        self.returned_worker = Worker(**{"hostname": "worker01",
                                         "ip_address_v4": "192.168.100.101",
                                         "ip_address_v6": "::1",
                                         "personality": "worker",
                                         "status": "online",
                                         "system_info": self.system_info})

        self.req = MagicMock()
        self.resp = MagicMock()
        self.resource = WorkerStatusResource()
        self.test_route = '/worker/{hostname}/status'
        self.api.add_route(self.test_route, self.resource)
Example #14
0
    def setUp(self):
        self.conf = MagicMock()
        self.conf.status_update.worker_status_interval = 60
        self.get_config = MagicMock(return_value=self.conf)
        self.config = WorkerConfiguration(
            personality='worker',
            hostname='worker01',
            coordinator_uri='http://192.168.1.2/v1')
        self.system_info = SystemInfo().format()
        self.request_uri = "{0}/worker/{1}/status".format(
            self.config.coordinator_uri, self.config.hostname)

        self.worker_status = {
            'worker_status': Worker(personality='worker').format()
        }
        self.worker_status['worker_status']['system_info'] = self.system_info
        self.req_body = jsonutils.dumps(self.worker_status)

        self.get_config = MagicMock(return_value=self.config)
        self.resp = requests.Response()
        self.http_request = MagicMock(return_value=self.resp)
Example #15
0
    def on_put(self, req, resp, worker_id, validated_body):
        """
        updates a worker's status
        """

        #load validated json payload in body
        body = validated_body['worker_status']

        #find the worker in db
        worker_dict = self.db.find_one('worker', {'worker_id': worker_id})

        if not worker_dict:
            _worker_not_found()

        worker = Worker(**worker_dict)

        if 'status' in body:
            worker.status = body['status']

        if 'system_info' in body:
            worker.system_info = SystemInfo(**body['system_info'])

        self.db.update('worker', worker.format_for_save())
        resp.status = falcon.HTTP_200
Example #16
0
 def setUp(self):
     self.db_handler = MagicMock()
     self.worker_id = "0123456789"
     self.req = MagicMock()
     self.resp = MagicMock()
     self.body_bad_header = {'worker':
                             WorkerRegistration('correlation').format()}
     self.body_bad_personality = {'worker_registration':
                                  WorkerRegistration(
                                      'bad_personality').format()}
     self.new_status = 'offline'
     self.new_bad_status = 'bad_status'
     self.system_info = SystemInfo()
     self.worker_dict = {"worker_id": self.worker_id,
                         "hostname": "worker-01",
                         "callback": "192.168.100.101:8080/v1/callback/",
                         "ip_address_v4": "192.168.100.101",
                         "ip_address_v6": "::1",
                         "personality": "worker.storage",
                         "status": "draining",
                         "system_info": {
                             "os_type": "Darwin-11.4.2-x86_64-i386-64bit",
                             "memory_mb": "1024",
                             "architecture": "",
                             "cpu_cores": "4",
                             "load_average": "0.234353456",
                             "disk_usage": {
                                 "/dev/sda1": {
                                     "total": 313764528,
                                     "used": 112512436
                                 }
                             }
                         }
                         }
     self.worker = Worker(_id='010101',
                          worker_id=self.worker_id,
                          worker_token='9876543210',
                          hostname='worker01',
                          callback='172.22.15.25:8080/v1/config/',
                          ip_address_v4='172.23.1.100',
                          ip_address_v6='::1',
                          personality='correlation',
                          status='online',
                          system_info=self.system_info.format())
     self.worker_list = [
         {"hostname": "worker-01",
          "callback": "192.168.100.101:8080/v1/callback/",
          "ip_address_v4": "192.168.100.101",
          "ip_address_v6": "::1",
          "personality": "storage",
          "status": "draining",
          "system_info": {
              "os_type": "Darwin-11.4.2-x86_64-i386-64bit",
              "memory_mb": "1024",
              "architecture": "",
              "cpu_cores": "4",
              "load_average": "0.234353456",
              "disk_usage": {
                  "/dev/sda1": {
                      "total": 313764528,
                      "used": 112512436
                  }}}},
         {"hostname": "worker-01",
          "callback": "192.168.100.101:8080/v1/callback/",
          "ip_address_v4": "192.168.100.101",
          "ip_address_v6": "::1",
          "personality": "storage",
          "status": "online",
          "system_info": {
              "os_type": "Darwin-11.4.2-x86_64-i386-64bit",
              "memory_mb": "1024",
              "architecture": "",
              "cpu_cores": "4",
              "load_average": "0.234353456",
              "disk_usage": {
                  "/dev/sda1": {
                      "total": 313764528,
                      "used": 112512436
                  }}}},
         {'hostname': "worker-01",
          "callback": "192.168.100.101:8080/v1/callback/",
          "ip_address_v4": "192.168.100.101",
          "ip_address_v6": "::1",
          "personality": "normalization",
          "status": "draining",
          "system_info": {
              "os_type": "Darwin-11.4.2-x86_64-i386-64bit",
              "memory_mb": "1024",
              "architecture": "",
              "cpu_cores": "4",
              "load_average": "0.234353456",
              "disk_usage": {
                  "/dev/sda1": {
                      "total": 313764528,
                      "used": 112512436
                  }}}}]