Пример #1
0
  def adjustForUpdatingComponent(self, component, started_container):
    # Add container to target group in ELB
    self.registerContainer()

    # Now wait until all of the elb checks/conditions are met
    checks = []
    for check in component.config.elb_checks:
      checks.append((check, buildHealthCheck(check)))

    report('Waiting for %s elb checks' % len(checks), component=component)

    for (config, check) in checks:
      check_passed = False

      while not check_passed:
        report('Running elb check: ' + config.getTitle(), component=component)
        result = check.run(started_container, report)
        if not result:
          report('Elb check failed', component=component)

          report('Sleeping ' + str(config.timeout) + ' second(s)...', component=component)
          time.sleep(config.timeout)
        else:
          check_passed = True

    report('Elb check finished', level=ReportLevels.BACKGROUND)

    setContainerStatus(started_container, 'running')
Пример #2
0
    def isHealthy(self):
        """ Runs the health checks on this component's container, ensuring that it is healthy.
        Returns True if healthy and False otherwise.
    """
        self.logger.debug('Checking if component %s is healthy...',
                          self.getName())
        container = self.getPrimaryContainer()
        if not container:
            self.logger.debug('No container running for component %s',
                              self.getName())
            return False

        checks = []
        for check in self.config.health_checks:
            checks.append((check, buildHealthCheck(check)))

        for (config, check) in checks:
            report('Running health check: ' + config.getTitle(),
                   component=self)
            result = check.run(container, report)
            if not result:
                report('Health check failed', component=self)
                return False

        self.logger.debug('Component %s is healthy', self.getName())
        return True
Пример #3
0
    def isHealthy(self):
        """ Runs the health checks on this component's container, ensuring that it is healthy.
        Returns True if healthy and False otherwise.
    """
        self.logger.debug("Checking if component %s is healthy...", self.getName())
        container = self.getPrimaryContainer()
        if not container:
            self.logger.debug("No container running for component %s", self.getName())
            return False

        checks = []
        for check in self.config.health_checks:
            checks.append((check, buildHealthCheck(check)))

        for (config, check) in checks:
            report("Config: ")
            report(config)
            report("Running health check: " + config.getTitle(), component=self)
            result = check.run(container, report)
            if not result:
                report("Health check failed", component=self)
                return False

        self.logger.debug("Component %s is healthy", self.getName())
        return True
Пример #4
0
  def watchTermination(self, container, component):
    report('Monitor check started', level=ReportLevels.BACKGROUND)

    client = getDockerClient()

    # Send the termination signal(s) to the container
    signals = []

    for signal in component.config.termination_signals:
      signals.append((signal, buildTerminationSignal(signal)))

    report('Sending %s termination signals' % len(signals), component=component)

    for (config, signal) in signals:
      report('Sending termination signal: ' + config.getTitle(), component=component)
      result = signal.run(container, report)
      if not result:
        report('Termination signal failed', component=component)

    # Now wait until all of the termination conditions are met
    checks = []
    for check in component.config.termination_checks:
      checks.append((check, buildHealthCheck(check)))

    report('Waiting for %s termination checks' % len(checks), component=component)

    for (config, check) in checks:
      check_passed = False

      while not check_passed:
        report('Running termination check: ' + config.getTitle(), component=component)
        result = check.run(container, report)
        if not result:
          report('Termination check failed', component=component)

          report('Sleeping ' + str(config.timeout) + ' second(s)...', component=component)
          time.sleep(config.timeout)
        else:
          check_passed = True

    report('Monitor check finished', level=ReportLevels.BACKGROUND)

    setContainerStatus(container, 'shutting-down')
    report('Shutting down container: ' + container['Id'][0:12], level=ReportLevels.BACKGROUND)
    client.stop(container)
    removeContainerMetadata(container)
Пример #5
0
    def readyCheck(self, container, timeout):
        """ Method which performs ready health check(s) on a container, returning whether
        they succeeded or not.

        container: The container running the component that will be checked.
        timeout: The amount of time after which the checks have timed out.
    """
        self.logger.debug('Checking if component %s is ready...',
                          self.getName())
        checks = []
        for check in self.config.ready_checks:
            checks.append((check, buildHealthCheck(check)))

        start = time.time()
        while True:
            now = time.time()
            if now - start > timeout:
                # Timed out completely.
                self.logger.debug('Component %s ready checks have timed out')
                return False

            # Try each check. If any fail, we'll sleep and try again.
            check_failed = None
            for (config, check) in checks:
                report('Running health check: ' + config.getTitle(),
                       component=self)
                result = check.run(container, report)
                if not result:
                    report('Health check failed', component=self)
                    check_failed = config
                    break

            if check_failed:
                report('Sleeping ' + str(check_failed.timeout) +
                       ' second(s)...',
                       component=self)
                time.sleep(check_failed.timeout)
            else:
                break

        return True
Пример #6
0
  def readyCheck(self, container, timeout):
    """ Method which performs ready health check(s) on a container, returning whether
        they succeeded or not.

        container: The container running the component that will be checked.
        timeout: The amount of time after which the checks have timed out.
    """
    self.logger.debug('Checking if component %s is ready...', self.getName())
    checks = []
    for check in self.config.ready_checks:
      checks.append((check, buildHealthCheck(check)))

    start = time.time()
    while True:
      now = time.time()
      if now - start > timeout:
        # Timed out completely.
        self.logger.debug('Component %s ready checks have timed out')
        return False

      # Try each check. If any fail, we'll sleep and try again.
      check_failed = None
      for (config, check) in checks:
        report('Running health check: ' + config.getTitle(), component=self)
        result = check.run(container, report)
        if not result:
          report('Health check failed', component=self)
          check_failed = config
          break

      if check_failed:
        report('Sleeping ' + str(check_failed.timeout) + ' second(s)...', component=self)
        time.sleep(check_failed.timeout)
      else:
        break

    return True