예제 #1
0
파일: cond_qplan.py 프로젝트: rjose/ratchet
class CondQPlan(SnapshotFilter):
    """
    Conditions raw data from a work spreadsheet, a staff spreadsheet, and a
    vacation spreadsheet.
    """

    def __init__(self, config, listen):
        """
        Constructs CondQPlan using config file info and a listen flag. If the
        listen flag is False, this runs a conditioning pass once and then exits.
        If listen is True, this runs in a loop.
        """
        self.team = config.get('Team', 'name')
        hub_host = config.get('Ratchet Hub', 'host')
        hub_port = int(config.get('Ratchet Hub', 'port'))
        self.ratchet_hub = RatchetHub(hub_host, hub_port)
        instance_config = self.ratchet_hub.get_qplan_instance_config(self.team)
        update_periods = self.ratchet_hub.get_update_periods()
        error_retry_period = update_periods['error_retry']
        ratchet_hub_info = self.ratchet_hub.get_ratchet_hub_info()
        self.name = "%s/%s/CondQPlan" % (ratchet_hub_info['org_name'], self.team)

        qplan_config = self.ratchet_hub.get_qplan_config()
        self.skill_headings = self.parse_skill_headings(qplan_config['skills'])

        SnapshotFilter.__init__(self,
                                listen,
                                instance_config['host'],
                                instance_config['req_port'],
                                instance_config['sub_port'],
                                error_retry_period,
                                # TODO: Rename staff -> assignments and artists -> people
                                ["=====raw work", "=====raw staff", "=====raw vacation", "=====raw artists"],
                                "=====cond qplan"
                               )
        return

    # @Override
    def get_processed_data(self):
        """
        Overrides function in SnapshotFilter. This is where the actual work is
        coordinated from.
        """
        self.ratchet_hub.log_info(self.name, "Start conditioning")
        try:
            [work_lines, staff_lines, vacation_lines, artists_lines] = self.get_inputs()
            result = self.condition_qplan_data(work_lines, staff_lines, vacation_lines, artists_lines)
            self.ratchet_hub.log_info(self.name, "Done conditioning")
        except Exception, e:
            self.ratchet_hub.log_error(self.name, "Problem conditioning data: %s" % e)
            raise

        return result
예제 #2
0
class CondVacationator(SnapshotFilter):

    #---------------------------------------------------------------------------
    # Constructs using a config file and a listen flag.
    #
    def __init__(self, config, listen):
        self.team = config.get('Team', 'name')
        hub_host = config.get('Ratchet Hub', 'host')
        hub_port = int(config.get('Ratchet Hub', 'port'))
        self.ratchet_hub = RatchetHub(hub_host, hub_port)

        instance_config = self.ratchet_hub.get_qplan_instance_config(self.team)
            # NOTE: The qplan instance is the same as the vacationator instance

        update_periods = self.ratchet_hub.get_update_periods()
        error_retry_period = update_periods['error_retry']

        ratchet_hub_info = self.ratchet_hub.get_ratchet_hub_info()
        self.name = "%s/%s/CondVacationator" % (ratchet_hub_info['org_name'], self.team)

        vacationator_config = self.ratchet_hub.get_vacationator_config()
        self.horizon = int(vacationator_config['horizon'])

        SnapshotFilter.__init__(self,
                                listen,
                                instance_config['host'],
                                instance_config['req_port'],
                                instance_config['sub_port'],
                                error_retry_period,
                                [
                                    "=====raw staff",
                                    "=====raw vacation",
                                    "=====raw oncall"
                                ],
                                "=====cond vacationator"
                               )
        return


    #===========================================================================
    # Internal functions

    # @Override
    def get_processed_data(self):
        self.ratchet_hub.log_info(self.name, "Start conditioning")
        try:
            [staff_lines, vacation_lines, oncall_lines] = self.get_inputs()
            result = self.condition_vacation_data(staff_lines, vacation_lines, oncall_lines)
        except Exception, e:
            self.ratchet_hub.log_error(self.name, "Problem conditioning data: %s" % e)
        return result
예제 #3
0
파일: app_qplan.py 프로젝트: rjose/ratchet
class AppQPlan(SnapshotFilter):
    def __init__(self, config, listen):
        self.team = config.get('Team', 'name')
        hub_host = config.get('Ratchet Hub', 'host')
        hub_port = int(config.get('Ratchet Hub', 'port'))

        self.ratchet_hub = RatchetHub(hub_host, hub_port)
        instance_config = self.ratchet_hub.get_qplan_instance_config(self.team)
        ratchet_hub_info = self.ratchet_hub.get_ratchet_hub_info()
        self.src_root = ratchet_hub_info['src_root']
        self.name = "%s/%s/AppQPlan" % (ratchet_hub_info['org_name'], self.team)

        update_periods = self.ratchet_hub.get_update_periods()
        error_retry_period = update_periods['error_retry']

        SnapshotFilter.__init__(self,
                                listen,
                                instance_config['host'],
                                instance_config['req_port'],
                                instance_config['sub_port'],
                                error_retry_period,
                                ["=====cond qplan"],
                                "=====app qplan"
                               )
        return

    # @Override
    def get_processed_data(self):
        self.ratchet_hub.log_info(self.name, "Start appifying")
        p = None
        result = ""

        try:
            [cond_data] = self.get_inputs()

            qplan_path = "%s/apps/filters/QPlan/dist/build/qplan/qplan" % self.src_root

            p = subprocess.Popen(qplan_path, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
            result = p.communicate(input=cond_data)[0]
        except Exception, e:
            self.ratchet_hub.log_error(self.name, "Exception happened running qplan: %s" % e)
            raise

        if p.returncode != 0:
            err_msg = "Something went wrong with the qplan filter (%d)" % p.returncode
            self.ratchet_hub.log_error(self.name, err_msg)
            raise Exception(err_msg)

        self.ratchet_hub.log_info(self.name, "Done appifying")
        return result
예제 #4
0
class AppVacationator(SnapshotFilter):
    def __init__(self, config, listen):
        self.team = config.get("Team", "name")
        hub_host = config.get("Ratchet Hub", "host")
        hub_port = int(config.get("Ratchet Hub", "port"))
        self.ratchet_hub = RatchetHub(hub_host, hub_port)
        # The qplan instance is the same as the vacationator instance

        instance_config = self.ratchet_hub.get_qplan_instance_config(self.team)
        update_periods = self.ratchet_hub.get_update_periods()
        error_retry_period = update_periods["error_retry"]

        ratchet_hub_info = self.ratchet_hub.get_ratchet_hub_info()
        self.name = "%s/%s/AppVacationator" % (ratchet_hub_info["org_name"], self.team)

        SnapshotFilter.__init__(
            self,
            listen,
            instance_config["host"],
            instance_config["req_port"],
            instance_config["sub_port"],
            error_retry_period,
            ["=====cond vacationator"],
            "=====app vacationator",
        )
        return

    # ===========================================================================
    # Internal functions

    # @Override
    def get_processed_data(self):
        self.ratchet_hub.log_info(self.name, "Start appifying")
        try:
            [cond_data] = self.get_inputs()
            result = self.process_app_data(cond_data)
        except Exception, e:
            self.ratchet_hub.log_error(self.name, "Problem conditioning data: %s" % e)
            raise

        self.ratchet_hub.log_info(self.name, "Done appifying")
        return result
예제 #5
0
    # Ask ratchet hub for port info
    hub_host = config.get('Ratchet Hub', 'host')
    hub_port = int(config.get('Ratchet Hub', 'port'))
    ratchet_hub = RatchetHub(hub_host, hub_port)

    try:
        ratchet_hub_info = ratchet_hub.get_ratchet_hub_info()
        name = "%s/vantage" % (ratchet_hub_info['org_name'])

        vantage_config = ratchet_hub.get_vantage_config()

        web_port = int(vantage_config['web_port'])
        ratchet_src_root = ratchet_hub.get_src_root()
        working_dir = "%s/apps/web/vantage" % ratchet_src_root
        catserve_path = "%s/apps/misc/catserve/catserve" % ratchet_src_root
        print("%s -r=%s -p=%d -c=%s" % (catserve_path, working_dir, web_port, full_config_path))
        p = subprocess.Popen("%s -r=%s -p=%d -c=%s" % (catserve_path, working_dir, web_port, full_config_path), shell=True)

        p.communicate()
        if p.returncode != 0:
            err_msg = "Something went wrong catserve (%s)" % p.returncode
            raise Exception(err_msg)

    except Exception, e:
        ratchet_hub.log_error(name, "Problem running catserve: %s" % e)
        raise

    while True:
        time.sleep(1)