Beispiel #1
0
 def check_cmd(self):
     command = self.get_cmd()
     if command:
         try:
             parse_time_variables(command=command)
             return True, ""
         except (ValueError, KeyError, TypeError):
             return False, ("Unparseable command '%s'. Hint: do you need to escape {} chars?") % command
     else:
         return True, ""
Beispiel #2
0
def test_parse_time_variables_parses_shortdate():
    input_time = datetime.datetime(2012, 3, 14)
    test_input = "mycommand --date {shortdate-1} --format foo/logs/%L/%Y/%m/%d/"
    expected = "mycommand --date 2012-03-13 --format foo/logs/%L/%Y/%m/%d/"
    actual = tron_tools.parse_time_variables(command=test_input,
                                             parse_time=input_time)
    assert actual == expected
Beispiel #3
0
def uses_time_variables(chronos_job):
    """
    Given a chronos job config, returns True the if the command uses time variables
    """
    current_command = chronos_job.get_cmd()
    interpolated_command = parse_time_variables(
        command=current_command, parse_time=datetime.datetime.utcnow())
    return current_command != interpolated_command
Beispiel #4
0
def format_command_for_type(command, instance_type, date):
    """
    Given an instance_type, return a function that appropriately formats
    the command to be run.
    """
    if instance_type == "tron":
        interpolated_command = parse_time_variables(command, date)
        return interpolated_command
    else:
        return command
Beispiel #5
0
    def format_chronos_job_dict(self, docker_url, docker_volumes,
                                docker_cfg_location, constraints):
        net = get_mesos_network_for_net(self.get_net())
        command = (parse_time_variables(self.get_cmd())
                   if self.get_cmd() else self.get_cmd())

        complete_config = {
            "name": self.get_job_name(),
            "container": {
                "image": docker_url,
                "network": net,
                "type": "DOCKER",
                "volumes": docker_volumes,
                "parameters": self.format_docker_parameters(),
            },
            "uris": [docker_cfg_location],
            "environmentVariables": self.get_env(),
            "mem": self.get_mem(),
            "cpus": self.get_cpus(),
            "disk": self.get_disk(),
            "constraints": constraints,
            "command": command,
            "arguments": self.get_args(),
            "epsilon": self.get_epsilon(),
            "retries": self.get_retries(),
            "async": False,  # we don't support async jobs
            "disabled": self.get_disabled(),
            "owner": self.get_owner(),
            "scheduleTimeZone": self.get_schedule_time_zone(),
            "shell": self.get_shell(),
        }
        if self.get_schedule() is not None:
            complete_config["schedule"] = self.get_schedule()
        else:
            # The input to parents is the normal paasta syntax, but for chronos we have to
            # convert it to what chronos expects, which uses its own spacer
            complete_config["parents"] = [
                paasta_to_chronos_job_name(parent)
                for parent in self.get_parents()
            ]
        return complete_config
Beispiel #6
0
    def format_chronos_job_dict(self, docker_url, docker_volumes,
                                docker_cfg_location, constraints):
        net = get_mesos_network_for_net(self.get_net())
        command = parse_time_variables(
            self.get_cmd()) if self.get_cmd() else self.get_cmd()

        complete_config = {
            'name': self.get_job_name(),
            'container': {
                'image': docker_url,
                'network': net,
                'type': 'DOCKER',
                'volumes': docker_volumes,
                'parameters': self.format_docker_parameters(),
            },
            'uris': [docker_cfg_location],
            'environmentVariables': self.get_env(),
            'mem': self.get_mem(),
            'cpus': self.get_cpus(),
            'disk': self.get_disk(),
            'constraints': constraints,
            'command': command,
            'arguments': self.get_args(),
            'epsilon': self.get_epsilon(),
            'retries': self.get_retries(),
            'async': False,  # we don't support async jobs
            'disabled': self.get_disabled(),
            'owner': self.get_owner(),
            'scheduleTimeZone': self.get_schedule_time_zone(),
            'shell': self.get_shell(),
        }
        if self.get_schedule() is not None:
            complete_config['schedule'] = self.get_schedule()
        else:
            # The input to parents is the normal paasta syntax, but for chronos we have to
            # convert it to what chronos expects, which uses its own spacer
            complete_config["parents"] = [
                paasta_to_chronos_job_name(parent)
                for parent in self.get_parents()
            ]
        return complete_config
Beispiel #7
0
 def format_tron_command(cmd: str) -> str:
     interpolated_command = parse_time_variables(cmd, date)
     return interpolated_command