def retrieve_job(auth, config):
    """
    Get the details of the most recently submitted job of a given name.
    
    :Args:
        - auth (:class:`.Credentials`): instance of the Credentials
          class as returned by authentication()

    :Returns:
        - The first from a list of :class:`.SubmittedJob` objects
        
    """

    job_mgr = JobManager(auth, cfg=config)
    job = input("Which job would you like to cancel? ")

    try:
        job_ref = job_mgr.get_jobs(per_call=1,
                                   name=job if job is not '' else None)

        if len(job_ref) < 1:
            raise ValueError("Found no jobs by that name.")

        return job_ref[0]

    except RestCallException:
        raise
def retrieve_job(auth, config):
    """
    Get the details of the most recently submitted job of a given name.
    
    :Args:
        - auth (:class:`.Credentials`): instance of the Credentials
          class as returned by authentication()

    :Returns:
        - The first from a list of :class:`.SubmittedJob` objects
        
    """

    job_mgr = JobManager(auth, cfg=config)
    job = input("Which job would you like to cancel? ")

    try:
        job_ref = job_mgr.get_jobs(per_call=1,
                                   name=job if job is not '' else None)

        if len(job_ref) < 1:
            raise ValueError("Found no jobs by that name.")

        return job_ref[0]

    except RestCallException:
        raise
    def start(self, creds):
        """
        Initialize all the addon subpages after authentication is
        complete.
        Sets page to HOME.

        :Args:
            - creds (:class:`batchapps.Credentials`): Authorised credentials
              with which API calls will be made.
        """
        job_mgr = JobManager(creds, cfg=self.cfg)
        asset_mgr = FileManager(creds, cfg=self.cfg)
        pool_mgr = PoolManager(creds, cfg=self.cfg)

        self.submission = BatchAppsSubmission(job_mgr, asset_mgr, pool_mgr)
        self.log.debug("Initialised submission module")

        self.assets = BatchAppsAssets(asset_mgr)
        self.log.debug("Initialised assets module")

        self.history = BatchAppsHistory(job_mgr)
        self.log.debug("Initialised history module")

        self.pools = BatchAppsPools(pool_mgr)
        self.log.debug("Initialised pool module")

        self.page = "HOME"
def retrieve_job_status(auth, config):
    """
    Prints the status of the selected job.
    
    :Args:
        - auth (:class:`.Credentials`): instance of the Credentials class
          as returned by authentication()
        - config :class:`.Configuration`: instance of the Configuration class
          as returned by create_config()
    """

    job_mgr = JobManager(auth, cfg=config)
    jobid = input("Please enter the job ID: ")

    try:
        job = job_mgr.get_job(jobid=jobid)
        print("Job '{0}' is {1}".format(job.name, job.status))

    except RestCallException as e:
        print("Request failed: {0}".format(e))
def retrieve_job_status(auth, config):
    """
    Prints the status of the selected job.
    
    :Args:
        - auth (:class:`.Credentials`): instance of the Credentials class
          as returned by authentication()
        - config :class:`.Configuration`: instance of the Configuration class
          as returned by create_config()
    """
    
    job_mgr = JobManager(auth, cfg=config)
    jobid = input("Please enter the job ID: ")

    try:
        job = job_mgr.get_job(jobid=jobid)
        print("Job '{0}' is {1}".format(job.name, job.status))

    except RestCallException as e:
        print("Request failed: {0}".format(e))
def submit_job(auth, config):
    """
    Create a new job submission and send it to the cloud.
    
    :Args:
        - auth :class:`.Credentials`: instance of the Credentials
          class as returned by authentication()
        - config :class:`.Configuration`: instance of the Configuration
          class as returned by create_config()
    """

    asset_mgr = FileManager(auth, cfg=config)
    job_mgr = JobManager(auth, cfg=config)

    # Converts directory contents to a FileCollection
    file_collection = asset_mgr.files_from_dir(ASSET_DIR)

    new_job = job_mgr.create_job("Test Job", files=file_collection)

    # Set various job parameters. The pre-configured parameters for the
    # job type can be found using new_job.get_default_params().

    new_job.instances = 5 # Number of machines to work on the job.
    new_job.start = 1
    new_job.end = 10
    new_job.numFrames = 10
    
    # This sets the file that will be run to start the job.
    # In this case the first file in the FileCollection.
    new_job.set_job_file(file_collection[0])

    # Upload all files needed for the job.
    new_job.required_files.upload(threads=4)

    try:
        submission = new_job.submit()
        print("New job submitted with ID: {0}".format(submission['jobId']))

    except RestCallException as e:
        print("Job failed: {0}".format(e))
def submit_job(auth, config):
    """
    Create a new job submission and send it to the cloud.
    
    :Args:
        - auth :class:`.Credentials`: instance of the Credentials
          class as returned by authentication()
        - config :class:`.Configuration`: instance of the Configuration
          class as returned by create_config()
    """

    asset_mgr = FileManager(auth, cfg=config)
    job_mgr = JobManager(auth, cfg=config)

    # Converts directory contents to a FileCollection
    file_collection = asset_mgr.files_from_dir(ASSET_DIR)

    new_job = job_mgr.create_job("Test Job", files=file_collection)

    # Set various job parameters. The pre-configured parameters for the
    # job type can be found using new_job.get_default_params().

    new_job.instances = 5  # Number of machines to work on the job.
    new_job.start = 1
    new_job.end = 10
    new_job.numFrames = 10

    # This sets the file that will be run to start the job.
    # In this case the first file in the FileCollection.
    new_job.set_job_file(file_collection[0])

    # Upload all files needed for the job.
    new_job.required_files.upload(threads=4)

    try:
        submission = new_job.submit()
        print("New job submitted with ID: {0}".format(submission['jobId']))

    except RestCallException as e:
        print("Job failed: {0}".format(e))
def download_ouput(auth, config):
    """
    Downloads final job output as to specified location.

    :Args:
        - auth (:class:`.Credentials`): instance of the Credentials class
          as returned by authentication()
    """
    
    job_mgr = JobManager(auth, cfg=config)
    jobid = input("Please enter the job ID: ")

    try:
        job = job_mgr.get_job(jobid=jobid)
        print("Downloading output of {0} job called {1}".format(
            job.type, job.name))

        output = job.get_output(DOWNLOAD_DIR, overwrite=True)
        print("Job output successfully downloaded to: {0}".format(output))

    except RestCallException as exc:
        print("Download failed: {0}".format(exc.msg))
示例#9
0
def download_ouput(auth, config):
    """
    Downloads final job output as to specified location.

    :Args:
        - auth (:class:`.Credentials`): instance of the Credentials class
          as returned by authentication()
    """

    job_mgr = JobManager(auth, cfg=config)
    jobid = input("Please enter the job ID: ")

    try:
        job = job_mgr.get_job(jobid=jobid)
        print("Downloading output of {0} job called {1}".format(
            job.type, job.name))

        output = job.get_output(DOWNLOAD_DIR, overwrite=True)
        print("Job output successfully downloaded to: {0}".format(output))

    except RestCallException as exc:
        print("Download failed: {0}".format(exc.msg))
示例#10
0
def update_job(auth, config):
    """
    Updates the job and returns True or False depending on the success
    of the operation.
    
    :Args:
        - auth (:class:`.Credentials`): instance of the Credentials class as
          returned by authentication()
        - config (:class:`.Configuration`): instance of the Configuration
          class as returned by logging_mode()
    """
    
    job_mgr = JobManager(auth, cfg=config)
    jobid = input("Please enter the job ID: ")

    try:
        job = job_mgr.get_job(jobid=jobid)
        job.update()
        print("Latest updates on job {0} retrieved.\nStatus: {1}\n"
              "Progress: {2}%".format(job.name, job.status, job.percentage))

    except RestCallException as e:
        print("Update failed: {0}".format(e))
    except RestCallException as exp:
        raise RuntimeError("Rest call failed: {0}".format(exp))

    except (TypeError, AttributeError) as exp:
        raise RuntimeError("Error occured: {0}".format(exp))

    except KeyboardInterrupt:
        raise RuntimeError("Monitoring aborted.")


if __name__ == "__main__":

    EXIT_STRING = "Successfully completed"

    try:
        im_config = generate_config()
        im_auth = authentication(im_config)
        im_jobmgr = JobManager(im_auth, cfg=im_config)

        im_submission = submit_job(im_config, im_auth, im_jobmgr)
        track_job_progress(im_jobmgr, im_submission)

    except RuntimeError as exp:
        EXIT_STRING = "{0}\nExiting program...".format(exp)

    except Exception as exp:
        EXIT_STRING = "An unexpected exception occured: {0}".format(exp)

    finally:
        sys.exit(EXIT_STRING)