예제 #1
0
파일: manager.py 프로젝트: philipz/gantryd
  def findConnectionLessContainers(self, containers):
    """ Determines which containers no longer have any valid connections to the
        outside world.
    """
    # Build the set of active connections from all the running proxy processes.
    connections = self.proxy.get_connections()
    
    # Build the set of container-local ports used.
    ports = set([])
    for connection in connections:
      laddr = connection.laddr
      raddr = connection.raddr
      if not laddr or not raddr:
        continue
      
      laddress = laddr[0]
      raddress = raddr[0]
      lport = laddr[1]
      rport = raddr[1]
      
      if laddress == '127.0.0.1' and raddress == '127.0.0.1':
        ports.add(rport)

    # For each draining container, if the port set contains one of the known mappings, then
    # the container is still being used.
    connectionless = list(containers)
    for container in containers:
      if getContainerStatus(container) == 'draining':
        container_local_ports = containerutil.getLocalPorts(container)
        if ports.intersection(container_local_ports):
          connectionless.remove(container)

    return connectionless
예제 #2
0
파일: manager.py 프로젝트: philipz/gantryd
  def updateProxy(self):
    """ Updates the proxy used for port mapping to conform to the current running container
        list.
    """
    client = getDockerClient()
    
    # Clear all routes in the proxy.
    # TODO: When this is in daemon mode, don't need do this. We could selectively
    # edit it instead.
    self.proxy.clear_routes()
    
    # Add routes for the non-draining containers and collect the draining containers to
    # watch.
    report('Finding running containers...', level = ReportLevels.EXTRA)
    draining_containers = []
    starting_containers = []
    
    for component in self.components.values():
      for container in component.getAllContainers(client):
        if getContainerStatus(container) != 'draining':
          starting_containers.append(container)
          for mapping in component.config.ports:
            local_port = containerutil.getLocalPort(client, container, mapping.container)
            route = Route(mapping.kind == 'http', mapping.external, 'localhost', local_port)
            self.proxy.add_route(route)
        else:
          draining_containers.append(container)

    # Commit the changes to the proxy.
    if draining_containers or starting_containers:
      report('Updating proxy...', level = ReportLevels.EXTRA)
      self.proxy.commit()
    else:
      report('Shutting down proxy...', level = ReportLevels.EXTRA)
      self.proxy.shutdown()
    
    # Mark the starting containers as running.
    for container in starting_containers:
      setContainerStatus(container, 'running')

    if draining_containers:
      report('Starting monitoring...', level = ReportLevels.EXTRA)
    
    # If there are any draining containers, add them to the watcher thread.
    with self.watcher_lock:
      self.containers_watched.extend(draining_containers)
    
    # Call the event to wakeup the watcher thread.
    if draining_containers:
      self.watcher_event.set()    
    
    # If in local mode, then wait until all the containers have drained. This
    # prevents the python debugger from shutting down, since the other threads
    # are all daemon threads.
    if not self.daemon_mode and draining_containers:
      while True:
        self.watcher_thread.join(10)
        if not self.watcher_thread.isAlive():
          break
예제 #3
0
  def getContainerInformation(self):
    """ Returns the container status information for all containers. """
    client = getDockerClient()
    information = []

    for container in self.getAllContainers(client):
      information.append((container, getContainerStatus(container)))

    return information
예제 #4
0
    def getContainerInformation(self):
        """ Returns the container status information for all containers. """
        client = getDockerClient()
        information = []

        for container in self.getAllContainers(client):
            information.append((container, getContainerStatus(container)))

        return information
예제 #5
0
  def getPrimaryContainer(self):
    """ Returns the container for this component that is not marked as draining or None if
        none.
    """
    client = getDockerClient()
    for container in self.getAllContainers(client):
      if getContainerStatus(container) != 'draining':
        return container

    return None
예제 #6
0
    def getPrimaryContainer(self):
        """ Returns the container for this component that is not marked as draining or None if
        none.
    """
        client = getDockerClient()
        for container in self.getAllContainers(client):
            if getContainerStatus(container) != 'draining':
                return container

        return None
예제 #7
0
파일: manager.py 프로젝트: mc0/gantryd
  def updateProxy(self):
    """ Updates the proxy used for port mapping to conform to the current running container
        list.
    """
    client = getDockerClient()

    # Clear all routes in the proxy.
    # TODO: When this is in daemon mode, don't need do this. We could selectively
    # edit it instead.
    self.proxy.clear_routes()

    # Add routes for the non-draining containers and collect the draining containers to
    # watch.
    report('Finding running containers...', level=ReportLevels.EXTRA)
    draining_containers = []
    starting_containers = []

    for component in self.components.values():
      for container in component.getAllContainers(client):
        if getContainerStatus(container) != 'draining':
          container_ip = containerutil.getContainerIPAddress(client, container)
          starting_containers.append(container)

          # Add the normal exposed ports.
          for mapping in component.config.ports:
            route = Route(mapping.kind == 'http', mapping.external, container_ip,
                          mapping.container)
            self.proxy.add_route(route)

          # Add the container link ports.
          for link in component.config.defined_component_links:
            route = Route(link.kind == 'http', link.getHostPort(), container_ip, link.port)
            self.proxy.add_route(route)
        else:
          draining_containers.append(container)

    # Commit the changes to the proxy.
    if draining_containers or starting_containers:
      report('Updating proxy...', level=ReportLevels.EXTRA)
      self.proxy.commit()
    else:
      report('Shutting down proxy...', level=ReportLevels.EXTRA)
      self.proxy.shutdown()

    # Mark the starting containers as running.
    for container in starting_containers:
      setContainerStatus(container, 'running')