def calculate_capacity(self):
     try:
        in_data = json_request()
        resource = in_data["Resource"]
        if not isinstance(resource, dict):
           raise Exception("Resource field is not an object!")
        
        if "Allocation" in in_data:
           allocation = in_data["Allocation"]
           if not isinstance(allocation,list):
              raise Exception("Allocation field is not an array!")
        else:
           allocation = {}
        
        if "Release" in in_data:
           release = in_data["Release"]
           if not isinstance(release, list):
              raise Exception("Release field is not an array!")              
        else:
           release = {} 
                   
        return json_reply(self._calculate_capacity(resource, allocation, release))
                     
     except Exception as e:           
        return json_error(e)   
    def create_reservation(self):
        try:
            in_data = json_request()
            alloc_req = in_data["Allocation"]

            if not isinstance(alloc_req, list):
                raise Exception("Allocation field is not an array!")

            if "Constraints" in in_data:
                constraints = in_data["Constraints"]
                if not isinstance(constraints, list):
                    raise Exception("Constraints field is not an array!")
            else:
                constraints = []

            if "Monitor" in in_data:
                monitor = in_data["Monitor"]
                if not isinstance(monitor, dict):
                    raise Exception("Monitor field is not an object!")
            else:
                monitor = {}

            if "Scheduler" in in_data:
                scheduler = in_data["Scheduler"]
            else:
                scheduler = ""

            ResourcesView().request_resources()
            return json_reply(
                self._create_reservation(scheduler, alloc_req, constraints,
                                         monitor))
        except Exception as e:
            return json_error(e)
示例#3
0
    def calculate_capacity(self):
        try:
            in_data = json_request()
            resource = in_data["Resource"]
            if not isinstance(resource, dict):
                raise Exception("Resource field is not an object!")

            if "Allocation" in in_data:
                allocation = in_data["Allocation"]
                if not isinstance(allocation, list):
                    raise Exception("Allocation field is not an array!")
            else:
                allocation = {}

            if "Release" in in_data:
                release = in_data["Release"]
                if not isinstance(release, list):
                    raise Exception("Release field is not an array!")
            else:
                release = {}

            return json_reply(
                self._calculate_capacity(resource, allocation, release))

        except Exception as e:
            return json_error(e)
 def delete_managers(self):
     try:
        ManagersTreeView.managers = {}   
           
        return json_reply({})    
            
     except Exception as e:           
        return json_error(e)      
 def request_resources(self):
    try:
       managers = copy.copy(ManagersTreeView.managers)
       for id in managers:          
          self.request_resources_id(id)
       return json_reply({})
    except Exception as e:
       return json_error(e)
示例#6
0
 def request_resources(self):
     try:
         managers = copy.copy(ManagersTreeView.managers)
         for id in managers:
             self.request_resources_id(id)
         return json_reply({})
     except Exception as e:
         return json_error(e)
 def get_manager(self, id):
     try:
        if id in  ManagersTreeView.managers:
           return json_reply(ManagersTreeView.managers[id]) 
        
        raise Exception("invalid manager id: " + id)
            
     except Exception as e:           
        return json_error(e)       
 def get_managers(self):
     try:
        mgrs = []
        
        for i in ManagersTreeView.managers:
           mgrs.append(ManagersTreeView.managers[i])
           
        return json_reply(mgrs)    
            
     except Exception as e:           
        return json_error(e)      
    def delete_manager(self, id):
        try:
           print "Unregistering %s" % id
           if id in  ManagersTreeView.managers:
              item = ManagersTreeView.managers[id]
              key = ManagersTreeView.gen_key(item['Name'], item['Address'], item['Port'])
              self._deleteManager(item['Name'], item['Address'], item['Port'], id)
              ManagersTreeView.managers.pop(id)
              return json_reply({})          
 
        except Exception as e:           
           return json_error(e)       
    def release_reservation(self):
        try:
            in_data = json_request()
            reservations = in_data["ReservationID"]

            if not isinstance(reservations, list):
                raise Exception("ReservationID field is not an array!")

            if len(reservations) == 0:
                raise Exception("ReservationID field cannot be empty!")

            return json_reply(self._release_reservation(reservations))
        except Exception as e:
            return json_error(e)
 def get_metrics_get(self):
    try:
       reservID=request.args.get('id')
       if reservID is None:
          raise Exception("no id specified!")          
       addr=request.args.get('addr')
       if addr is None:
          addr = ""
       entry=request.args.get('entry')
       if entry is None:
          entry = 0  
       entry_int = int(entry)         
       return json_reply(self._get_metrics(reservID, addr, entry_int))    
            
    except Exception as e:           
       return json_error(e)
    def register_manager(self):
        try:
           in_data = json_request()
           
           if 'Address' in in_data:               
              addr = in_data['Address']
           else:
              addr = request.remote_addr
           
           # when testing (no requests), addr is None. We assume localhost   
           if addr is None:
              addr = "127.0.0.1"
              
           port = in_data['Port']
           name = in_data['Name']
           
           if not self._acceptManager(addr, port, name):
              raise Exception("Manager %s rejected!" % name)
                         
           key = ManagersTreeView.gen_key(name, addr, port)           
           
           ################### check the database ####
           conn = sqlite3.connect('manager.db')
           c = conn.cursor()
           c.execute("SELECT * from managers where key = '%s'" % key)
           r = c.fetchone()

           if r == None:
              idx = str(uuid.uuid1())
              c.execute("INSERT INTO managers VALUES  ('%s', '%s')" % (key, idx))
              conn.commit()
           else:
              idx = r[1]            
           conn.close()             
           
           data = { 'Address': addr, 'Port': port, 'Name': name, 'ManagerID': idx }   
                
           ManagersTreeView.managers[idx] = data
           print "Adding manager: %s" % data['Name']
           self._registerManager(data)
           return json_reply(ManagersTreeView.managers[idx])    
               
        except Exception as e:           
           return json_error(e)
 def get_metrics_post(self):
    try:
       in_data = json_request()
       
       reservID = in_data['ReservationID']    
       if "Address" not in in_data:
          addr = ""
       else:       
          addr = in_data['Address']
       if 'Entry' not in in_data:
          entry = 1
       else:
          entry = in_data['Entry']
          
       ret = self._get_metrics(reservID, addr, entry) 
         
       return json_reply(ret) 
                         
    except Exception as e:           
       return json_error(e)
    def request_resources_id(self, id):
       try:
          if not id in ManagersTreeView.managers:
             raise Exception("cannot find manager: " + id)
          data = ManagersTreeView.managers[id]

          try:  
             out = get("getResources", data["Port"], data["Address"])

             if "result" in out:
                 ResourcesView.resources[data["ManagerID"]] = out["result"]["Resources"]
                 if "Constraints" in out["result"]:
                    ResourcesView.resource_constraints[data["ManagerID"]] = out["result"]["Constraints"]   
          except requests.exceptions.ConnectionError:
             ManagersTreeView._class().delete_manager(data["ManagerID"])
             return json_error(Exception)   
                                  
          except Exception as e:
             return json_error(e)
          return json_reply({})
       except Exception as e:
          return json_error(e)
示例#15
0
    def request_resources_id(self, id):
        try:
            if not id in ManagersTreeView.managers:
                raise Exception("cannot find manager: " + id)
            data = ManagersTreeView.managers[id]

            try:
                out = get("getResources", data["Port"], data["Address"])

                if "result" in out:
                    ResourcesView.resources[
                        data["ManagerID"]] = out["result"]["Resources"]
                    if "Constraints" in out["result"]:
                        ResourcesView.resource_constraints[
                            data["ManagerID"]] = out["result"]["Constraints"]
            except requests.exceptions.ConnectionError:
                ManagersTreeView._class().delete_manager(data["ManagerID"])
                return json_error(Exception)

            except Exception as e:
                return json_error(e)
            return json_reply({})
        except Exception as e:
            return json_error(e)
 def release_all_reservations(self):
     try:
         return json_reply(self._release_all_reservations())
     except Exception as e:
         return json_error(e)
示例#17
0
 def get_resources(self):
     try:
         return json_reply(self._get_resources())
     except Exception as e:
         return json_error(e)
 def get_alloc_spec(self):
     try:
        return json_reply(self._get_alloc_spec())
     except Exception as e:           
        return json_error(e)   
 def get_resources(self):
     try:
        return json_reply(self._get_resources())   
     except Exception as e:          
        return json_error(e) 
示例#20
0
 def get_alloc_spec(self):
     try:
         return json_reply(self._get_alloc_spec())
     except Exception as e:
         return json_error(e)