Пример #1
0
 def listStatus(self):
   """ Lists the status of all components in this project. """
   self.getConfig()
   self.initialize([c.name for c in self.config.components])
   
   print "%-20s %-20s %-20s" % ('COMPONENT', 'STATUS', 'IMAGE ID')
   for component in self.components:
     state = ComponentState(self.project_name, component, self.etcd_client).getState()
     status = ComponentState.getStatusOf(state)
     imageid = ComponentState.getImageIdOf(state)
     print "%-20s %-20s %-20s" % (component.getName(), status, imageid)
Пример #2
0
    def listStatus(self):
        """ Lists the status of all components in this project. """
        self.getConfig()
        self.initialize([c.name for c in self.config.components])

        print "%-20s %-20s %-20s" % ('COMPONENT', 'STATUS', 'IMAGE ID')
        for component in self.components:
            state = ComponentState(self.project_name, component,
                                   self.etcd_client).getState()
            status = ComponentState.getStatusOf(state)
            imageid = ComponentState.getImageIdOf(state)
            print "%-20s %-20s %-20s" % (component.getName(), status, imageid)
Пример #3
0
    def handleReady(self, state, was_initial_check):
        """ Handles when the component has been marked as ready. """

        # If the status is ready, we update the component if:
        #   - The ID of the component's image does not match that found in the status.
        #   - The process is not running.
        imageid = ComponentState.getImageIdOf(state)
        imageid_different = imageid != self.component.getImageId()
        should_update = not self.is_running or imageid_different

        if should_update:
            self.is_running = False
            self.monitor_event.clear()

            # We need to update this machine's copy. First, do a test and set to ensure that
            # we are the only machine allowed to update. If the test and set fails, we'll
            # try again in 10s.
            if imageid_different:
                report('Detected pushed update for component ' +
                       self.component.getName(),
                       project=self.project_name,
                       component=self.component)
            else:
                report('Component %s is not running; starting' %
                       self.component.getName(),
                       project=self.project_name,
                       component=self.component)

            result = self.state.setUpdatingStatus('updating', self.machine_id,
                                                  state)
            if not result:
                # The exchange failed. Sleep CHECK_SHORT_SLEEP_TIME seconds and try again.
                report(
                    'Could not grab update lock. Will try again in %s seconds'
                    % CHECK_SHORT_SLEEP_TIME,
                    project=self.project_name,
                    component=self.component)
                return CHECK_SHORT_SLEEP_TIME

            # Start the update by pulling the repo for the component.
            if imageid_different:
                report('Pulling the image for component ' +
                       self.component.getName())
                if not self.component.pullRepo():
                    # The pull failed.
                    report('Pull failed of image %s for component %s' %
                           (imageid[0:12], self.component.getName()),
                           project=self.project_name,
                           component=self.component,
                           level=ReportLevels.IMPORTANT)
                    self.state.setUpdatingStatus('pullfail', self.machine_id,
                                                 result)
                    return CHECK_SLEEP_TIME

            # Run the update on the component and wait for it to finish.
            if imageid_different:
                report('Starting update for component ' +
                       self.component.getName(),
                       project=self.project_name,
                       component=self.component)

            if not self.component.update():
                # The update failed.
                self.state.setUpdatingStatus('updatefail', self.machine_id,
                                             result)
                return CHECK_SLEEP_TIME

            # Otherwise, the update has succeeded. Mark the component as ready, so another
            # gantryd can start its update.
            if imageid_different:
                report('Update completed for component ' +
                       self.component.getName(),
                       project=self.project_name,
                       component=self.component)
            else:
                report('Component ' + self.component.getName() +
                       ' is now running',
                       project=self.project_name,
                       component=self.component)

            self.state.setReadyStatus(self.component.getImageId())
            self.is_running = True
            self.monitor_event.set()

        return CHECK_SLEEP_TIME
Пример #4
0
  def handleReady(self, state, was_initial_check):
    """ Handles when the component has been marked as ready. """

    # If the status is ready, we update the component if:
    #   - The ID of the component's image does not match that found in the status.
    #   - The process is not running.
    imageid = ComponentState.getImageIdOf(state)
    imageid_different = imageid != self.component.getImageId()
    should_update = not self.is_running or imageid_different

    if should_update:
      self.is_running = False
      self.monitor_event.clear()

      # We need to update this machine's copy. First, do a test and set to ensure that
      # we are the only machine allowed to update. If the test and set fails, we'll
      # try again in 10s.
      if imageid_different:
        report('Detected pushed update for component ' + self.component.getName(),
               project=self.project_name, component=self.component)
      else:
        report('Component %s is not running; starting' % self.component.getName(),
               project=self.project_name, component=self.component)

      result = self.state.setUpdatingStatus('updating', self.machine_id, state)
      if not result:
        # The exchange failed. Sleep CHECK_SHORT_SLEEP_TIME seconds and try again.
        report('Could not grab update lock. Will try again in %s seconds' % CHECK_SHORT_SLEEP_TIME,
               project=self.project_name, component=self.component)
        return CHECK_SHORT_SLEEP_TIME

      # Start the update by pulling the repo for the component.
      if imageid_different:
        report('Pulling the image for component ' + self.component.getName())
        if not self.component.pullRepo():
          # The pull failed.
          report('Pull failed of image %s for component %s' % (imageid[0:12],
                                                               self.component.getName()),
                 project=self.project_name, component=self.component, level=ReportLevels.IMPORTANT)
          self.state.setUpdatingStatus('pullfail', self.machine_id, result)
          return CHECK_SLEEP_TIME

      # Run the update on the component and wait for it to finish.
      if imageid_different:
        report('Starting update for component ' + self.component.getName(),
               project=self.project_name, component=self.component)

      if not self.component.update():
        # The update failed.
        self.state.setUpdatingStatus('updatefail', self.machine_id, result)
        return CHECK_SLEEP_TIME

      # Otherwise, the update has succeeded. Mark the component as ready, so another
      # gantryd can start its update.
      if imageid_different:
        report('Update completed for component ' + self.component.getName(),
               project=self.project_name, component=self.component)
      else:
        report('Component ' + self.component.getName() + ' is now running',
               project=self.project_name, component=self.component)

      self.state.setReadyStatus(self.component.getImageId())
      self.is_running = True
      self.monitor_event.set()

    return CHECK_SLEEP_TIME