コード例 #1
0
def test(job):
    """
    Test the given job.  This function returns immediately
    when the given job completes, or throws an L{OutlineException}
    if the job fails in any way.

    @type job: opencue.Entity.Job
    @param job: The job to test.
    """
    logging.basicConfig(level=logging.DEBUG)
    logger.info("Entering test mode for job: %s" % job.data.name)

    # Unpause the job.
    job.resume()

    try:
        while True:
            try:
                job = opencue.api.getJob(job.name())
                if job.data.job_stats.dead_frames + job.data.job_stats.eaten_frames > 0:
                    msg = "Job test failed, dead or eaten frames on: %s"
                    raise OutlineException(msg % job.data.name)
                if job.data.state == opencue.api.job_pb2.FINISHED:
                    break
                msg = "waiting on %s job to complete: %d/%d"
                logger.debug(
                    msg % (job.data.name, job.data.job_stats.succeeded_frames,
                           job.data.job_stats.total_frames))
            except opencue.CueException, ie:
                raise OutlineException("test for job %s failed: %s" %
                                       (job.data.name, ie))
            time.sleep(5)
    finally:
        job.kill()
コード例 #2
0
def _serialize(launcher, use_pycuerun):
    """
    Serialize the outline part of the given L{OutlineLauncher} into a
    opencue job specification.

    @type launcher: L{OutlineLauncher}
    @param launcher: The outline launcher being used to launch the job.

    @rtype: str
    @return: A opencue job specification.
    """
    ol = launcher.get_outline()

    root = Et.Element("spec")
    depends = Et.Element("depends")

    sub_element(root, "facility", launcher.get("facility"))
    sub_element(root, "show", launcher.get("show"))
    sub_element(root, "shot", launcher.get("shot"))
    user = launcher.get_flag("user")
    if not user:
        user = util.get_user()
    sub_element(root, "user", user)
    if not launcher.get("nomail"):
        sub_element(root, "email",
                    "%s@%s" % (user, config.get("outline", "domain")))
    sub_element(root, "uid", str(util.get_uid()))

    j = Et.SubElement(root, "job", {"name": ol.get_name()})
    sub_element(j, "paused", str(launcher.get("pause")))
    sub_element(j, "maxretries", str(launcher.get("maxretries")))
    sub_element(j, "autoeat", str(launcher.get("autoeat")))

    if ol.get_arg("localbook"):
        Et.SubElement(j, "localbook", ol.get_arg("localbook"))

    if launcher.get("os"):
        sub_element(j, "os", launcher.get("os"))
    elif os.environ.get("OL_OS", False):
        sub_element(j, "os", os.environ.get("OL_OS"))

    env = Et.SubElement(j, "env")
    for env_k, env_v in ol.get_env().iteritems():
        # Only pre-setshot environment variables are
        # passed up to the cue.
        if env_v[1]:
            pair = Et.SubElement(env, "key", {"name": env_k})
            pair.text = env_v[0]

    layers = Et.SubElement(j, "layers")
    for layer in ol.get_layers():

        # Unregistered layers are in the job but don't show up on the cue.
        if not layer.get_arg("register"):
            continue

        # Don't register child layers with opencue.
        if layer.get_parent():
            continue

        # The layer will return a valid range if its range and
        # the job's range are compatible.  If not, skip launching
        # that layer.
        frame_range = layer.get_frame_range()
        if not frame_range:
            logger.info("Skipping layer %s, its range (%s) does not intersect "
                        "with ol range %s" %
                        (layer, layer.get_arg("range"), ol.get_frame_range()))
            continue

        spec_layer = Et.SubElement(layers, "layer", {
            "name": layer.get_name(),
            "type": layer.get_type()
        })
        if use_pycuerun:
            sub_element(spec_layer, "cmd",
                        " ".join(build_command(launcher, layer)))
        else:
            sub_element(spec_layer, "cmd", " ".join(layer.get_arg("command")))
        sub_element(spec_layer, "range", str(frame_range))
        sub_element(spec_layer, "chunk", str(layer.get_chunk_size()))

        # opencue specific options
        if layer.get_arg("threads"):
            sub_element(spec_layer, "cores",
                        "%0.1f" % (layer.get_arg("threads")))

        if layer.is_arg_set("threadable"):
            sub_element(spec_layer, "threadable",
                        bool_to_str(layer.get_arg("threadable")))

        if layer.get_arg("memory"):
            sub_element(spec_layer, "memory", "%s" % (layer.get_arg("memory")))

        if os.environ.get("OL_TAG_OVERRIDE", False):
            sub_element(spec_layer, "tags",
                        scrub_tags(os.environ["OL_TAG_OVERRIDE"]))
        elif layer.get_arg("tags"):
            sub_element(spec_layer, "tags", scrub_tags(layer.get_arg("tags")))

        services = Et.SubElement(spec_layer, "services")
        service = Et.SubElement(services, "service")
        try:
            service.text = layer.get_service().split(",")[0].strip()
        except Exception:
            service.text = "default"

        build_dependencies(ol, layer, depends)

    if not len(layers):
        raise OutlineException(
            "Failed to launch job.  There are no layers with frame "
            "ranges that intersect the job's frame range: %s" %
            ol.get_frame_range())

    # Dependencies go after all of the layers
    root.append(depends)

    xml = []
    xml.append('<?xml version="1.0"?>')
    xml.append('<!DOCTYPE spec PUBLIC "SPI Cue  Specification Language" '
               '"http://localhost:8080/spcue/dtd/cjsl-1.8.dtd">')
    xml.append(Et.tostring(root))

    result = "".join(xml)
    logger.debug(parseString(result).toprettyxml())
    return result