def substitute_thermos(cls, command, task, cluster, **kw): prefix_command = 'cd %s;' % cls.thermos_sandbox(cluster, **kw) thermos_namespace = ThermosContext( task_id=task.assignedTask.taskId, ports=task.assignedTask.assignedPorts) mesos_namespace = MesosContext(instance=task.assignedTask.instanceId) command = String(prefix_command + command) % Environment( thermos=thermos_namespace, mesos=mesos_namespace) return command.get()
def interpolate_cmd(task, cmd): """ :param task: Assigned task passed from Mesos Agent :param cmd: Command defined inside shell_command inside config. :return: Interpolated cmd with filled in values, for example ports. """ thermos_namespace = ThermosContext(task_id=task.taskId, ports=task.assignedPorts) mesos_namespace = MesosContext(instance=task.instanceId) command = String(cmd) % Environment(thermos=thermos_namespace, mesos=mesos_namespace) return command.get()
def task_instance_from_job(job, instance, hostname): instance_context = MesosContext(instance=instance, hostname=hostname) health_check_config = HealthCheckConfig() if job.has_health_check_config(): health_check_config = job.health_check_config() ti = MesosTaskInstance(task=job.task(), role=job.role(), health_check_config=health_check_config, instance=instance) if job.has_announce(): ti = ti(announce=job.announce()) if job.has_environment(): ti = ti(environment=job.environment()) if job.has_lifecycle(): ti = ti(lifecycle=job.lifecycle()) return ti.bind(mesos=instance_context)
def task_instance_from_job(job, instance): instance_context = MesosContext(instance=instance) # TODO(Sathya): Remove health_check_interval_secs references after deprecation cycle is complete. health_check_config = HealthCheckConfig() if job.has_health_check_interval_secs(): health_check_config = HealthCheckConfig( interval_secs=job.health_check_interval_secs().get()) elif job.has_health_check_config(): health_check_config = job.health_check_config() ti = MesosTaskInstance( task=job.task(), role=job.role(), health_check_interval_secs=health_check_config.interval_secs().get(), health_check_config=health_check_config, instance=instance) if job.has_announce(): ti = ti(announce=job.announce()) if job.has_environment(): ti = ti(environment=job.environment()) return ti.bind(mesos=instance_context).interpolate()
def context(self, instance=None): context = dict(instance=instance) # Filter unspecified values return Environment(mesos=MesosContext(dict((k, v) for k, v in context.items() if v)))