Example #1
0
 def start(self):
     from storage import backup_fs
     from storage import backup_control
     from storage import backup_matrix
     from storage import backup_monitor
     from main import settings
     from main.config import conf
     from p2p import p2p_connector
     backup_fs.init()
     backup_control.init()
     backup_matrix.init()
     if settings.NewWebGUI():
         from web import control
         backup_matrix.SetBackupStatusNotifyCallback(
             control.on_backup_stats)
         backup_matrix.SetLocalFilesNotifyCallback(
             control.on_read_local_files)
     else:
         from web import webcontrol
         backup_matrix.SetBackupStatusNotifyCallback(
             webcontrol.OnBackupStats)
         backup_matrix.SetLocalFilesNotifyCallback(
             webcontrol.OnReadLocalFiles)
     backup_monitor.A('init')
     backup_monitor.A('restart')
     conf().addCallback('services/backups/keep-local-copies-enabled',
                        self._on_keep_local_copies_modified)
     conf().addCallback('services/backups/wait-suppliers-enabled',
                        self._on_wait_suppliers_modified)
     p2p_connector.A().addStateChangedCallback(
         self._on_p2p_connector_state_changed, 'INCOMMING?', 'CONNECTED')
     p2p_connector.A().addStateChangedCallback(
         self._on_p2p_connector_state_changed, 'MY_IDENTITY', 'CONNECTED')
     return True
Example #2
0
 def start(self):
     from storage import backup_fs
     from storage import backup_control
     from storage import backup_matrix
     from storage import backup_monitor
     from main.config import conf
     from main import control
     from transport import callback
     from p2p import p2p_connector
     backup_fs.init()
     backup_control.init()
     backup_matrix.init()
     backup_matrix.SetBackupStatusNotifyCallback(control.on_backup_stats)
     backup_matrix.SetLocalFilesNotifyCallback(control.on_read_local_files)
     backup_monitor.A('init')
     backup_monitor.A('restart')
     conf().addCallback('services/backups/keep-local-copies-enabled',
                        self._on_keep_local_copies_modified)
     conf().addCallback('services/backups/wait-suppliers-enabled',
                        self._on_wait_suppliers_modified)
     p2p_connector.A().addStateChangedCallback(
         self._on_p2p_connector_state_changed, 'INCOMMING?', 'CONNECTED')
     p2p_connector.A().addStateChangedCallback(
         self._on_p2p_connector_state_changed, 'MY_IDENTITY', 'CONNECTED')
     callback.append_inbox_callback(self._on_inbox_packet_received)
     return True
 def start(self):
     from storage import backup_fs
     from storage import backup_control
     from storage import backup_matrix
     from storage import backup_monitor
     from main.config import conf
     from main import control
     from main import events
     from main import listeners
     from transport import callback
     from p2p import p2p_connector
     backup_fs.init()
     backup_control.init()
     backup_matrix.init()
     backup_matrix.SetBackupStatusNotifyCallback(control.on_backup_stats)
     backup_matrix.SetLocalFilesNotifyCallback(control.on_read_local_files)
     backup_monitor.A('init')
     backup_monitor.A('restart')
     conf().addConfigNotifier('services/backups/keep-local-copies-enabled',
                        self._on_keep_local_copies_modified)
     conf().addConfigNotifier('services/backups/wait-suppliers-enabled',
                        self._on_wait_suppliers_modified)
     p2p_connector.A().addStateChangedCallback(
         self._on_p2p_connector_state_changed, 'INCOMMING?', 'CONNECTED')
     p2p_connector.A().addStateChangedCallback(
         self._on_p2p_connector_state_changed, 'MY_IDENTITY', 'CONNECTED')
     callback.append_inbox_callback(self._on_inbox_packet_received)
     events.add_subscriber(self._on_my_identity_rotated, 'my-identity-rotated')
     events.add_subscriber(self._on_key_erased, 'key-erased')
     if listeners.is_populate_requered('remote_version'):
         listeners.populate_later().remove('remote_version')
         backup_matrix.populate_remote_versions()
     return True
def _delete_version(params):
    lg.out(6, '_delete_version %s' % str(params))
    backupID = params['backupid']
    if not packetid.Valid(backupID):
        return {
            'result': {
                "success": False,
                "error": "backupID %s is not valid" % backupID
            }
        }
    customerGlobalID, remotePath, version = packetid.SplitBackupID(backupID)
    if not customerGlobalID:
        customerGlobalID = my_id.getGlobalID()
    if not backup_fs.ExistsID(
            remotePath,
            iterID=backup_fs.fsID(
                global_id.GlobalUserToIDURL(customerGlobalID))):
        return {
            'result': {
                "success": False,
                "error": "path %s not found" % remotePath
            }
        }
    if version:
        backup_control.DeleteBackup(backupID, saveDB=False, calculate=False)
    backup_fs.Scan()
    backup_fs.Calculate()
    backup_control.Save()
    backup_monitor.A('restart')
    control.request_update([
        ('backupID', backupID),
    ])
    return {'result': {"success": True, "error": None}}
def _delete(params):
    # localPath = params['path'].lstrip('/')
    pathID = params['id']
    if not packetid.Valid(pathID):
        return {
            'result': {
                "success": False,
                "error": "path %s is not valid" % pathID
            }
        }
    if not backup_fs.ExistsID(pathID):
        return {
            'result': {
                "success": False,
                "error": "path %s not found" % pathID
            }
        }
    backup_control.DeletePathBackups(pathID, saveDB=False, calculate=False)
    backup_fs.DeleteLocalDir(settings.getLocalBackupsDir(), pathID)
    backup_fs.DeleteByID(pathID)
    backup_fs.Scan()
    backup_fs.Calculate()
    backup_control.Save()
    control.request_update([
        ('pathID', pathID),
    ])
    backup_monitor.A('restart')
    return {'result': {"success": True, "error": None}}
Example #6
0
 def doRestartBackupMonitor(self, arg):
     """
     Action method.
     """
     if driver.is_on('service_backup_monitor'):
         from storage import backup_monitor
         backup_monitor.A('restart')
Example #7
0
 def _on_p2p_connector_state_changed(self, oldstate, newstate, event_string,
                                     *args, **kwargs):
     from storage import backup_monitor
     from logs import lg
     lg.warn(
         'restarting backup_monitor() machine because p2p_connector state changed'
     )
     backup_monitor.A('restart')
Example #8
0
def OnJobDone(backupID, result):
    """
    A callback method fired when backup is finished.

    Here we need to save the index data base.
    """
    from storage import backup_rebuilder
    # from customer import io_throttle
    lg.info('job done [%s] with result "%s", %d more tasks' %
            (backupID, result, len(tasks())))
    jobs().pop(backupID)
    customerGlobalID, remotePath, version = packetid.SplitBackupID(backupID)
    customer_idurl = global_id.GlobalUserToIDURL(customerGlobalID)
    if result == 'done':
        maxBackupsNum = settings.getBackupsMaxCopies()
        if maxBackupsNum:
            item = backup_fs.GetByID(remotePath,
                                     iterID=backup_fs.fsID(customer_idurl))
            if item:
                versions = item.list_versions(sorted=True, reverse=True)
                if len(versions) > maxBackupsNum:
                    for version in versions[maxBackupsNum:]:
                        item.delete_version(version)
                        backupID = packetid.MakeBackupID(
                            customerGlobalID, remotePath, version)
                        backup_rebuilder.RemoveBackupToWork(backupID)
                        # io_throttle.DeleteBackupRequests(backupID)
                        # io_throttle.DeleteBackupSendings(backupID)
                        # callback.delete_backup_interest(backupID)
                        backup_fs.DeleteLocalBackup(
                            settings.getLocalBackupsDir(), backupID)
                        backup_matrix.EraseBackupLocalInfo(backupID)
                        backup_matrix.EraseBackupLocalInfo(backupID)
        backup_fs.ScanID(remotePath)
        backup_fs.Calculate()
        Save()
        control.request_update([
            ('pathID', remotePath),
        ])
        # TODO: check used space, if we have over use - stop all tasks immediately
        backup_matrix.RepaintBackup(backupID)
    elif result == 'abort':
        DeleteBackup(backupID)
    if len(tasks()) == 0:
        # do we really need to restart backup_monitor after each backup?
        # if we have a lot tasks started this will produce a lot unneeded actions
        # will be smarter to restart it once we finish all tasks
        # because user will probably leave BitDust working after starting a long running operations
        from storage import backup_monitor
        if _Debug:
            lg.out(
                _DebugLevel,
                'backup_control.OnJobDone restarting backup_monitor() machine because no tasks left'
            )
        backup_monitor.A('restart')
    reactor.callLater(0, RunTask)  # @UndefinedVariable
    reactor.callLater(0, FireTaskFinishedCallbacks, remotePath, version,
                      result)  # @UndefinedVariable
Example #9
0
 def health_check(self):
     from storage import backup_monitor
     return backup_monitor.A().state in [
         'READY',
         'FIRE_HIRE',
         'LIST_FILES',
         'LIST_BACKUPS',
         'REBUILDING',
     ]
Example #10
0
    def state_changed(self, oldstate, newstate, event, arg):
        """
        This method is called every time when my state is changed.

        Need to notify backup_monitor() machine about my new state.
        """
        # global_state.set_global_state('REBUILD ' + newstate)
        if newstate in ['NEXT_BACKUP', 'REQUEST', 'REBUILDING', ]:
            self.automat('instant')
        elif newstate == 'DONE' or newstate == 'STOPPED':
            if driver.is_on('service_backups'):
                from storage import backup_monitor
                backup_monitor.A('backup_rebuilder.state', newstate)
Example #11
0
 def state_changed(self, oldstate, newstate, event, *args, **kwargs):
     if self.target_customer_idurl is None or self.target_customer_idurl == my_id.getIDURL():
         if driver.is_on('service_backups'):
             # TODO: rebuild using "list-files-orator-state-changed" event
             from storage import backup_monitor
             backup_monitor.A('list_files_orator.state', newstate)
     if newstate == 'SAW_FILES':
         lt_saw_files = self.last_time_saw_files.get(self.target_customer_idurl, -1)
         if lt_saw_files <= 0 or time.time() - lt_saw_files < 20:
             events.send('my-list-files-refreshed', data={'customer_idurl': self.target_customer_idurl, })
         self.last_time_saw_files[self.target_customer_idurl] = time.time()
     if newstate == 'NO_FILES':
         self.last_time_saw_files[self.target_customer_idurl] = -1
     if newstate in ['SAW_FILES', 'NO_FILES', ]:
         self.target_customer_idurl = None
         if self.result_defer:
             if not self.result_defer.called:
                 self.result_defer.callback(self.state)
             self.result_defer = None
 def state_changed(self, oldstate, newstate, event, *args, **kwargs):
     if driver.is_on('service_backups'):
         # TODO: rebuild using "list-files-orator-state-changed" event
         from storage import backup_monitor
         backup_monitor.A('list_files_orator.state', newstate)
     if newstate == 'SAW_FILES':
         if A().last_time_saw_files > 0 and time.time() - A(
         ).last_time_saw_files < 20:
             if _Debug:
                 lg.dbg(
                     _DebugLevel, 'already saw files %r seconds ago' %
                     (time.time() - A().last_time_saw_files))
         else:
             if _Debug:
                 lg.dbg(
                     _DebugLevel,
                     'saw files just now, raising "my-list-files-refreshed" event'
                 )
             events.send('my-list-files-refreshed', data={})
         self.last_time_saw_files = time.time()
     if newstate == 'NO_FILES':
         self.last_time_saw_files = -1
Example #13
0
 def state_changed(self, oldstate, newstate, event, arg):
     #global_state.set_global_state('ORATOR ' + newstate)
     if driver.is_on('service_backups'):
         from storage import backup_monitor
         backup_monitor.A('list_files_orator.state', newstate)
 def _on_keep_local_copies_modified(self, path, value, oldvalue, result):
     from storage import backup_monitor
     backup_monitor.A('restart')
Example #15
0
 def doNotifyFinished(self, arg):
     if driver.is_on('service_backups'):
         from storage import backup_monitor
         backup_monitor.A('fire-hire-finished')
Example #16
0
 def doNotifySuppliersChanged(self, arg):
     if driver.is_on('service_backups'):
         from storage import backup_monitor
         backup_monitor.A('suppliers-changed')
 def _on_wait_suppliers_modified(self, path, value, oldvalue, result):
     from storage import backup_monitor
     backup_monitor.A('restart')
Example #18
0
 def doNotifyFinished(self, *args, **kwargs):
     self.hire_list = []
     if driver.is_on('service_backups'):
         from storage import backup_monitor
         backup_monitor.A('fire-hire-finished')
Example #19
0
 def doNotifySuppliersChanged(self, *args, **kwargs):
     self.hire_list = []
     if driver.is_on('service_backups'):
         from storage import backup_monitor
         backup_monitor.A('suppliers-changed')
Example #20
0
 def _on_keep_local_copies_modified(self, path, value, oldvalue, result):
     from storage import backup_monitor
     from logs import lg
     lg.warn('restarting backup_monitor() machine')
     backup_monitor.A('restart')
 def _on_p2p_connector_state_changed(self, oldstate, newstate, event_string,
                                     args):
     from storage import backup_monitor
     backup_monitor.A('restart')
Example #22
0
 def _on_wait_suppliers_modified(self, path, value, oldvalue, result):
     from storage import backup_monitor
     from logs import lg
     lg.warn('restarting backup_monitor() machine')
     backup_monitor.A('restart')