Ejemplo n.º 1
0
 def on_add_node(self, nodeId, groupId, site_id, auth, def_manager):
     op = constants.ATTACH
     if not(nodeId or groupId):
         return None
     defn_list = []
     errs = []
     sync_manager = SyncDef()
     defType = def_manager.getType()
     sp_defns = DBSession.query(SPDefLink).filter_by(group_id=to_unicode(groupId))
     if sp_defns:
         for eachdefn in sp_defns:
             defn = def_manager.get_defn(eachdefn.def_id)
             if defn:
                 defn_list.append(defn)
                 status = to_unicode(constants.OUT_OF_SYNC)
                 details = None
                 sync_manager.add_node_defn(nodeId, defn.id, defType, status, details)
     node = DBSession.query(ManagedNode).filter_by(id=nodeId).first()
     if node:
         update_status = True
         try:
             sync_manager.sync_node(defn_list, node, groupId, site_id, auth, defType, op, def_manager, update_status, errs)
         except Exception as ex:
             if errs:
                 if len(errs)>0:
                     LOGGER.error('Error in syncing definition while adding node: ' + to_str(errs))
Ejemplo n.º 2
0
 def on_remove_node(self, nodeId, groupId, site_id, auth, def_manager, isTransfer=False, csep_id=None):
     op = constants.DETACH
     if not groupId:
         return None
     errs = []
     sync_manager = SyncDef()
     defType = def_manager.getType()
     node = DBSession.query(ManagedNode).filter_by(id=nodeId).first()
     if node:
         defn_list = []
         node_defns = DBSession.query(ServerDefLink).filter_by(server_id=nodeId, def_type=defType)
         if node_defns:
             for eachdefn in node_defns:
                 defn = def_manager.get_defn(eachdefn.def_id)
                 if defn:
                     defn_list.append(defn)
                     continue
         try:
             update_status = True
             sync_manager.sync_node(defn_list, node, groupId, site_id, auth, defType, op, def_manager, update_status, errs)
         except Exception as ex:
             LOGGER.error('Error: ' + to_str(ex))
             if errs:
                 if len(errs)>0:
                     LOGGER.error('Error in syncing definition while removing node: ' + to_str(errs))
         if node_defns:
             for eachdefn in node_defns:
                 defn = def_manager.get_defn(eachdefn.def_id)
                 if defn:
                     if defn.scope!=constants.SCOPE_S:
                         if eachdefn.status == constants.OUT_OF_SYNC:
                             LOGGER.error('WARNING: The definition status is OUT_OF_SYNC. Still the definition linking with the server is getting deleted. server_id=' + node.id + ', def_id=' + eachdefn.def_id + ', def_type=' + eachdefn.def_type + ', details=' + to_str(eachdefn.details))
                         DBSession.delete(eachdefn)
                     if defn.scope == constants.SCOPE_S and isTransfer == False:
                         DBSession.delete(defn)
                     self.update_node_defn(auth, nodeId, groupId, site_id, defn.id, defn.type, '', datetime.now(), '', defn.scope, defType, csep_id)