Example #1
0
def delete(conversation, hostname):
    server = Server(hostname)

    DroneD.delete(server.droned)

    for app in list(server.apps):
        app.shouldRunOn.discard(server)

    for appinstance in list(server.appinstances):
        AppInstance.delete(appinstance)

    for appversion in list(AppVersion.objects):
        appversion.services.applicableServers.discard(server)

    for scab in list(server.scabs):
        Scab.delete(scab)

    Server.delete(server)

    conversation.say("All serializable references to %s have been deleted" %
                     hostname)

    if server.listed:
        conversation.say(
            "However this server is listed in my server list, you must remove it manually before restarting gov."
        )
Example #2
0
    def getInstance(self, label):
        """get a reference to the application instance

           I attempt to delegate to the original provider.

           @param label: (string)

           @return AppInstance()
           @exception AssertionError
        """
        label = str(label)
        if AppInstance.exists(Server(config.HOSTNAME), App(self.name), label):
            return AppInstance(Server(config.HOSTNAME), App(self.name), label)
        raise AssertionError('no such application instance')
Example #3
0
 def construct(state):
     server = Server(state['server'])
     droned = server.droned
     droned.port = state['port']
     droned.apps = frozenset(App(name) for name in state.get('apps', []))
     droned.currentFailure = state['currentFailure']
     return droned
Example #4
0
    def ignoreServers(self, *hostnames):
        """ignore another DroneD

           @param hostnames (iterable of droned.models.server.Server())
        """
        for hostname in hostnames:
            if Server.exists(hostname):
                Server(hostname).connectFailure = 'ignored'
                Server(hostname).stopPolling()
Example #5
0
    def addInstance(self, label):
        """add a new application instance optionally changing the version

           I attempt to delegate to the original provider.

           @param label: (string)

           @return AppInstance()
        """
        label = str(label)
        return AppInstance(Server(config.HOSTNAME), App(self.name), label)
Example #6
0
def joinEnvironmentalChatRoom(event):
    """determine if we should join a chatroom"""
    chat = ChatRoom(config.ROMEO_ENV_NAME)
    #make sure the drone can be managed by the room
    username = config.ROMEO_ENV_NAME
    jbserver = jconfig.JABBER_CHAT_SERVICE
    jid = "%(username)s@%(jbserver)s" % locals()
    Team('support').addMember(jid)
    #get the conversation context set to some sane defaults
    conversation = Conversation(jid)
    #grant the room access to the server
    if jconfig.JABBER_TRUST_ROOM:
        conversation.grantAuthorization(notify=False)
    #be vain assume all conversations revolve around ourself
    context = {
        'server': Server(config.HOSTNAME),
        'subject': Server(config.HOSTNAME),
    }
    conversation.context.update(context)
    #finally join the room
    chat.join()
Example #7
0
def delete(conversation, hostname):
  server = Server(hostname)

  DroneD.delete(server.droned)

  for app in list(server.apps):
    app.shouldRunOn.discard(server)

  for appinstance in list(server.appinstances):
    AppInstance.delete(appinstance)

  for appversion in list(AppVersion.objects):
    appversion.services.applicableServers.discard(server)

  for scab in list(server.scabs):
    Scab.delete(scab)

  Server.delete(server)

  conversation.say("All serializable references to %s have been deleted" % hostname)

  if server.listed:
    conversation.say("However this server is listed in my server list, you must remove it manually before restarting gov.")
Example #8
0
 def construct(state):
     server = Server(state.pop('server'))
     ap = None
     try:
         ap = AppProcess(server, state['pid'])
     except:
         return None
     if ap.localInstall and ap.inode != state['inode']:
         AppProcess.delete(ap)
         return None
     ap._created = state.pop('created')
     #we know this is going throw an adapter
     if IKittRemoteProcess.providedBy(ap.process.process):
         #remaining attributes go into the remote process
         ap.updateProcess(state)  #this is only useful to remote processes
     return ap
Example #9
0
 def construct(state):
     server = Server(state['server'])
     #we need to format the version correctly
     appname = state['app']
     version = AppVersion.makeAppVersion(appname, state['version'])
     appinstance = AppInstance(server, App(appname), state['label'])
     appinstance.appversion = version
     pid = state.get('pid', 0)
     inode = state.get('inode', 0)
     from kitt.proc import isRunning
     if pid and isRunning(pid):
         appinstance.info.update({'pid': pid, 'inode': inode})
         process = AppProcess(server, pid)
         if process.inode == inode:
             setattr(appinstance, '_process', process)
     appinstance.updateInfo(state['info'])
     appinstance.enabled = state.get('enabled', False)
     appinstance.shouldBeRunning = state.get('shouldBeRunning', False)
     x = appinstance.running  #preload the process information
     #attempt to get our instance into the last known state
     return appinstance
Example #10
0
 def _first_scan(self):
     for pid in listProcesses():
         try:
             AppProcess(Server(config.HOSTNAME), pid)
         except InvalidProcess:
             pass
Example #11
0
 def _scan(self):
     for pid in listProcesses():
         try:
             AppProcess(Server(config.HOSTNAME), pid)
         except InvalidProcess:
             pass
         except IOError:
             pass  #happens on linux when a pid dies
         except:
             err('process table scanning error')
     #scan for crashed instances
     for app in App.objects:
         if not app.__class__.isValid(app): continue
         for ai in app.localappinstances:
             if not ai.__class__.isValid(ai): continue
             if ai in self.tracking: continue
             if not self.first_run:  #avoid process table races
                 self.tracking.add(ai)
                 config.reactor.callLater(SERVICECONFIG.recovery_period,
                                          self.tracking.discard, ai)
                 if not ai.enabled: continue  #skip disabled
             result = None
             if ai.running and not ai.shouldBeRunning:
                 ai.shouldBeRunning = True
             if ai.running: continue
             manager = AppManager(ai.app.name)
             if not manager.running:
                 continue  #skip managers that are not running
             if not manager.discover:
                 continue  #app manager claims to be ok
             #look for processes that we can assimilate
             d = manager.model.findProcesses()
             wfd = defer.waitForDeferred(d)
             yield wfd
             for (pid, result) in wfd.getResult():
                 d = manager.model.assimilateProcess(result)
                 wfd2 = defer.waitForDeferred(d)
                 yield wfd2
                 ai2 = wfd2.getResult()
                 if ai2 and isinstance(ai2, AppInstance) and ai2 is ai:
                     Event('instance-found').fire(instance=ai)
                     manager.log('Sucessfully assimilated PID %d' % ai2.pid)
             if ai.running: continue  #may have assimilated the app
             if not ai.crashed: continue
             if not ai.enabled:
                 continue  #disabled instances are not actionable
             if self.first_run: continue  #avoid process table races
             Event('instance-crashed').fire(instance=ai)
             #cool off on eventing for a little while
     #keep the process objects up to date
     for process in AppProcess.objects:
         try:
             if not process.localInstall: continue
             if not process.running:
                 AppProcess.delete(process)
         except:
             err('process book keeping error')
     d = defer.Deferred()
     config.reactor.callLater(0.01, d.callback, None)
     wfd = defer.waitForDeferred(d)
     yield wfd
     wfd.getResult()
     self.first_run = False
     yield 'done'
Example #12
0
 def __setstate__(self, state):
   self.applicableServers = set( Server(hostname) for hostname in state['applicableServers'] )
   self.provided = state['provided']
   self.required = state['required']
Example #13
0
 def safe_process(pid):
     try:  #because processes can be invalid
         return AppProcess(Server(config.HOSTNAME), pid)
     except:
         err('problem')
         return None
Example #14
0
 def construct(state):
     app = App(state['name'])
     app.shouldRunOn = set( Server(hostname) for hostname in \
             state['shouldRunOn'] )
     return app