Esempio n. 1
0
 def delete_session(cls, session_id):
     """
     Deletes a session
     :param session_id: Id of the session to delete
     :rtype A tuple containing the status and a potential error description
     """
     try:
         session = Session.objects.get(id=session_id)
         if not session.status == SESSION_STATUS_STOPPING:
             log.info(1, 'Removing session ' + str(session_id))
             session.status = SESSION_STATUS_STOPPING
             session.save()
             if session.process_pid != -1:
                 process_manager.ProcessManager.stop(session)
             if session.job_id is not None and session.job_id != '':
                 jm = job_manager.JobManager()
                 jm.stop(session)
             session.delete()
             msg = 'Session successfully destroyed'
             log.info(1, msg)
             response = json.dumps({'contents': str(msg)})
             return [http_status.HTTP_200_OK, response]
     except Session.DoesNotExist as e:
         log.error(str(e))
         response = json.dumps({'contents': str(e)})
         return [http_status.HTTP_404_NOT_FOUND, response]
     except Exception as e:
         log.error(str(e))
         response = json.dumps({'contents': str(e)})
         return [http_status.HTTP_500_INTERNAL_ERROR, response]
     msg = 'Session is currently being destroyed'
     response = json.dumps({'contents': msg})
     log.info(1, msg)
     return [http_status.HTTP_200_OK, response]
Esempio n. 2
0
    def LogProgress(convertList, fnName, convertFn, name, threadSetting):
        if len(convertList) > 0:
            failedCount = 0
            maxThreads = toolkit_config.get_int_setting(
                "Performance", threadSetting)

            jm = job_manager.JobManager(maxThreads)
            convertedCount = 0
            processedCount = 0
            totalCount = len(convertList)

            def cb(success):
                nonlocal processedCount, convertedCount, failedCount
                processedCount += 1
                if success:
                    convertedCount += 1
                else:
                    failedCount += 1
                sys.stdout.write(
                    "{} Processed {}/{} ({}/{}) success/failure. \r".format(
                        name, processedCount, totalCount, convertedCount,
                        failedCount))
                sys.stdout.flush()

            for i in range(len(convertList)):
                file_path = convertList[i]
                job = job_manager.Job(cb, fnName, convertFn, target.lower(),
                                      file_path.lower())
                jm.AddJob(job)

            jm.ProcessBatch()
            sys.stdout.write(
                "{} Processing Complete: {}/{} ({}/{}) success/failure. \r".
                format(name, processedCount, totalCount, convertedCount,
                       failedCount))
            sys.stdout.write("\n")
            if processedCount != totalCount:
                sys.stdout.write("Not all were processed.\n")
            sys.stdout.flush()
Esempio n. 3
0
def main():
    args = runner_arguments()
    logger.account_info(args)
    start_time = datetime.datetime.now().replace(microsecond=0)
    logger.info('Template runner start time: [{}]'.format(start_time))

    # Create the blob client, for use in obtaining references to
    # blob storage containers and uploading files to containers.
    blob_client = azureblob.BlockBlobService(
        account_name=args.StorageAccountName,
        account_key=args.StorageAccountKey)

    # Create a batch account using AAD
    batch_client = create_batch_client(args)

    # Clean up any storage container that is older than a 7 days old.
    utils.cleanup_old_resources(blob_client)

    try:
        images_refs = []  # type: List[utils.ImageReference]
        with open(args.TestConfig) as f:
            template = json.load(f)

            for jobSetting in template["tests"]:
                application_licenses = None
                if 'applicationLicense' in jobSetting:
                    application_licenses = jobSetting["applicationLicense"]

                _job_managers.append(
                    job_manager.JobManager(jobSetting["template"],
                                           jobSetting["poolTemplate"],
                                           jobSetting["parameters"],
                                           jobSetting["expectedOutput"],
                                           application_licenses))

            for image in template["images"]:
                images_refs.append(
                    utils.ImageReference(image["osType"], image["offer"],
                                         image["version"]))

        run_job_manager_tests(blob_client, batch_client, images_refs,
                              args.VMImageURL, args.VMImageType)

    except batchmodels.batch_error.BatchErrorException as err:
        traceback.print_exc()
        utils.print_batch_exception(err)
        raise
    finally:
        # Delete all the jobs and containers needed for the job
        # Reties any jobs that failed
        utils.execute_parallel_jobmanagers("retry", _job_managers,
                                           batch_client, blob_client,
                                           _timeout / 2)
        utils.execute_parallel_jobmanagers("delete_resources", _job_managers,
                                           batch_client, blob_client)
        utils.execute_parallel_jobmanagers("delete_pool", _job_managers,
                                           batch_client)
        end_time = datetime.datetime.now().replace(microsecond=0)
        logger.print_result(_job_managers)
        logger.export_result(_job_managers, (end_time - start_time))
    logger.info('Sample end: {}'.format(end_time))
    logger.info('Elapsed time: {}'.format(end_time - start_time))
Esempio n. 4
0
def main():
    args = runner_arguments()
    logger.account_info(args)
    start_time = datetime.datetime.now().replace(microsecond=0)
    logger.info('Template runner start time: [{}]'.format(start_time))

    # Create the blob client, for use in obtaining references to
    # blob storage containers and uploading files to containers.
    blob_client = azureblob.BlockBlobService(
        account_name=args.StorageAccountName,
        account_key=args.StorageAccountKey)

    # Create a batch account using AAD
    batch_client = create_batch_client(args)

    # Create a keyvault client using AAD
    keyvault_client_with_url = create_keyvault_client(args)

    # Clean up any storage container that is older than a 7 days old.
    utils.cleanup_old_resources(blob_client)

    repository_branch_name = args.RepositoryBranchName
    if repository_branch_name == "current":
        repository_branch_name = Repository('../').head.shorthand

    logger.info('Pulling resource files from the branch: {}'.format(
        repository_branch_name))

    try:
        images_refs = []  # type: List[utils.ImageReference]
        with open(args.TestConfig) as f:
            try:
                template = json.load(f)
            except ValueError as e:
                logger.err(
                    "Failed to read test config file due to the following error",
                    e)
                raise e

            for jobSetting in template["tests"]:
                application_licenses = None
                if 'applicationLicense' in jobSetting:
                    application_licenses = jobSetting["applicationLicense"]

                _job_managers.append(
                    job_manager.JobManager(
                        jobSetting["template"], jobSetting["poolTemplate"],
                        jobSetting["parameters"], keyvault_client_with_url,
                        jobSetting["expectedOutput"], application_licenses,
                        repository_branch_name))

            for image in template["images"]:
                images_refs.append(
                    utils.ImageReference(image["osType"], image["offer"],
                                         image["version"]))

        run_job_manager_tests(blob_client, batch_client, images_refs,
                              args.VMImageURL)

    except batchmodels.BatchErrorException as err:
        utils.print_batch_exception(err)
        raise
    finally:
        # Delete all the jobs and containers needed for the job
        # Reties any jobs that failed

        if args.CleanUpResources:
            utils.execute_parallel_jobmanagers("retry", _job_managers,
                                               batch_client, blob_client,
                                               _timeout / 2)
            utils.execute_parallel_jobmanagers("delete_resources",
                                               _job_managers, batch_client,
                                               blob_client)
            utils.execute_parallel_jobmanagers("delete_pool", _job_managers,
                                               batch_client)
        end_time = datetime.datetime.now().replace(microsecond=0)
        logger.print_result(_job_managers)
        logger.export_result(_job_managers, (end_time - start_time))
    logger.info('Sample end: {}'.format(end_time))
    logger.info('Elapsed time: {}'.format(end_time - start_time))
Esempio n. 5
0
def main():
    job_manager = jm.JobManager()
    while (True):
        tm.sleep(
            conf.sleep_time_in_seconds)  # Check for new jobs at intervals.
        job_manager.run_next_job()
Esempio n. 6
0
from flask import Flask
import job_manager as jm_manager
import json as js

app = Flask(__name__)

jmanager = jm_manager.JobManager()


@app.route('/')
def hello_world():
    return 'Hello World!'


@app.route('/add/<job_id>')
def add_job(job_id):
    jmanager.add_job(job_id)
    return "success"


@app.route('/addcrazy/<job_id>')
def add_crazy(job_id):
    jmanager.add_crazy(job_id)
    return "success"


@app.route('/addlow/<job_id>')
def add_low(job_id):
    jmanager.add_low_usage_job(job_id)
    return "success"