예제 #1
0
def search_with_attrs(query_args, types_of_things):
    results = {}
    matched_builds = []
    matched_artifacts = []
    matched_deploys = []
    matched_promotes = []

    with PgServer(ENVIRONMENT_PROPERTIES) as server:
        for type_of_thing in types_of_things:
            search_args = filter_args(query_args, type_of_thing)
            if len(search_args) > 0:
                if type_of_thing == 'BUILDS':
                    for build in server.get_build_by_attrs(search_args):
                        matched_builds.append(build)
                    if len(matched_builds) > 0:
                        results['builds'] = matched_builds

                elif type_of_thing == 'ARTIFACTS':
                    for artifact in server.get_artifact_by_attrs(search_args):
                        matched_artifacts.append(artifact)
                    if len(matched_artifacts) > 0:
                        results['artifacts'] = matched_artifacts

                elif type_of_thing == 'DEPLOYS':
                    for deploy in server.get_deploy_by_attrs(search_args):
                        matched_deploys.append(deploy)
                    if len(matched_deploys) > 0:
                        results['deploys'] = matched_deploys

                elif type_of_thing == 'PROMOTES':
                    for promote in server.get_promote_by_attrs(search_args):
                        matched_promotes.append(promote)
                    if len(matched_promotes) > 0:
                        results['promotes'] = matched_promotes
    return results
예제 #2
0
    def get(self):
        """
        retrieve build assertion details
        """
        args = build_get_parser.parse_args()
        app.logger.debug(args)
        result = None
        code = 200

        with PgServer(ENVIRONMENT_PROPERTIES) as server:
            if args.get(ARGS.JOB_URL):
                app.logger.debug(ARGS.JOB_URL)
                result = server.get_build_by_url(args[ARGS.JOB_URL])
            elif args.get(ARGS.BUILD_ID):
                app.logger.debug(ARGS.BUILD_ID)
                result = server.get_build_by_build_id(args[ARGS.BUILD_ID])
            elif args.get(ARGS.VERSION_TYPE) and args.get(ARGS.VERSION):
                result = server.get_build_by_version(args[ARGS.VERSION_TYPE],
                                                     args[ARGS.VERSION])
            else:
                code = 409
                result = []
        result = [parse_times(x) for x in result]
        app.logger.debug(result)
        return result, code
예제 #3
0
 def get(self):
     """
     retrieve details of deployment assertion
     """
     args = deploy_get_parser.parse_args()
     app.logger.debug(args)
     result = []
     code = 200
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         if args.get(ARGS.DEPLOY_ID):
             result = server.get_deploys_by_deploy_id(args[ARGS.DEPLOY_ID])
         elif args.get(ARGS.ENVIRONMENT):
             result = server.get_deploys_by_environment(
                 args[ARGS.ENVIRONMENT])
         elif args.get(ARGS.VERSION_TYPE) and args.get(ARGS.VERSION):
             result = server.get_deploys_by_version(args[ARGS.VERSION_TYPE],
                                                    args[ARGS.VERSION])
         elif args.get(ARGS.THING_NAME):
             result = server.get_deploys_by_thing_name(
                 args[ARGS.THING_NAME])
         else:
             code = 409
     result = [parse_times(x) for x in result]
     app.logger.debug(result)
     return result, code
예제 #4
0
def thing_attrs():
    request_vars = flask.request.args
    app.logger.debug(request_vars)
    result = {}
    with PgServer(ENVIRONMENT_PROPERTIES) as server:
        result['build'] = server.wanted_build_columns
        result['artifact'] = server.wanted_artifact_columns
        result['deploy'] = server.wanted_deploy_columns
        result['promote'] = server.wanted_promote_columns
    return to_json(result)
예제 #5
0
 def get(self):
     """
     list all build assertions
     """
     result = None
     code = 200
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         result = server.get_all_builds()
     app.logger.debug(result)
     result = [parse_times(x) for x in result]
     return result, code
예제 #6
0
 def get(self):
     """
     list all deployment assertions
     """
     args = flask.request.values
     app.logger.debug(args)
     result = None
     code = 200
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         result = server.get_all_deploys()
     result = [parse_times(x) for x in result]
     return result, code
예제 #7
0
    def get(self):
        """
        list all artifacts
        """
        result = None
        code = 200
        args = flask.request.values
        app.logger.debug(args)

        with PgServer(ENVIRONMENT_PROPERTIES) as server:
            result = server.get_all_artifacts()
        result = [parse_times(x) for x in result]
        return (result, code)
예제 #8
0
 def post(self):
     """
     create a new build assertion
     """
     args = build_post_parser.parse_args()
     args[ARGS.MISC] = json.loads(args[ARGS.MISC])
     app.logger.debug(args)
     result = None
     code = 200
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         result = server.append_build(**args)
         app.logger.debug('created new build id: %d', result)
     return result, code
예제 #9
0
 def get(self, **kwargs):
     """
     get promote based on its id
     """
     id = kwargs['promote_id']
     app.logger.info("Getting id  %s", id)
     code = 200
     result = 'No data visible'
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         result = server.get_promote_by_promote_id(id)
     if result == []:
         code = 404
     result = [parse_times(x) for x in result]
     return result, code
예제 #10
0
 def get(self, **kwargs):
     """
     get artifact based on its id
     """
     id = kwargs['artifact_id']
     app.logger.info("Getting id  %s", id)
     code = 200
     result = []
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         result = server.get_artifact_by_artifact_id(id)
     if result == []:
         code = 404
     result = [parse_times(x) for x in result]
     return result, code
예제 #11
0
    def post(self):
        """
        create deployment assertion
        """
        args = deploy_post_parser.parse_args()
        args[ARGS.MISC] = json.loads(args[ARGS.MISC])

        app.logger.info("POST DEPLOY ARGS %s", args)
        code = 200
        result = None
        with PgServer(ENVIRONMENT_PROPERTIES) as server:
            result = server.append_deploy(**args)
            app.logger.debug('successful deploy asserted: %d' % result)
        return result, code
예제 #12
0
 def get(self, **kwargs):
     """
     get deploy based on its id
     """
     id = kwargs['deploy_id']
     app.logger.info("Getting deploy id  %s", id)
     code = 200
     result = 'No data available'
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         result = server.get_deploys_by_deploy_id(id)
         app.logger.debug('got deploy records: %s', result)
     if result == []:
         code = 404
     result = [parse_times(x) for x in result]
     return result, code
예제 #13
0
 def post(self):
     """
     create a promotion assertion
     """
     args = promote_post_parser.parse_args()
     args[ARGS.MISC] = json.loads(args[ARGS.MISC])
     app.logger.debug(args)
     code = 200
     result = None
     try:
         with PgServer(ENVIRONMENT_PROPERTIES) as server:
             result = server.append_promote(**args)
     except IntegrityError as ex:
         app.logger.warn(ex)
         api.abort(404, 'thing id not found')
     return result, code
예제 #14
0
 def post(self):
     """
     create a new artifact
     """
     result = None
     code = 200
     args = artifact_post_parser.parse_args()
     args[ARGS.MISC] = json.loads(args[ARGS.MISC])
     app.logger.debug(args)
     try:
         with PgServer(ENVIRONMENT_PROPERTIES) as server:
             result = server.append_artifact(**args)
     except IntegrityError as ex:
         app.logger.warn(ex)
         api.abort(404, 'build id not found')
     return result, code
예제 #15
0
def specific_thing_attrs(thing_type):
    request_vars = flask.request.args
    app.logger.debug(request_vars)
    result = []

    if thing_type not in ENUMS.PATH_THING_TYPES:
        abort(404)

    with PgServer(ENVIRONMENT_PROPERTIES) as server:
        if thing_type == 'build':
            result = server.wanted_build_columns
        elif thing_type == 'artifact':
            result = server.wanted_artifact_columns
        elif thing_type == 'deploy':
            result = server.wanted_deploy_columns
        elif thing_type == 'promote':
            result = server.wanted_promote_columns

    return to_json(result)
예제 #16
0
 def get(self):
     """
     retrieve details of promotion assertion
     """
     args = promote_get_parser.parse_args()
     app.logger.debug(args)
     result = []
     code = 200
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         if args.get(ARGS.THING_TYPE) and args.get(ARGS.THING_NAME):
             result = server.get_promote_by_thing(args[ARGS.THING_TYPE],
                                                  args[ARGS.THING_NAME])
         elif args.get(ARGS.ENVIRONMENT):
             result = server.get_promote_by_environment(
                 args[ARGS.ENVIRONMENT])
         elif args.get(ARGS.PROMOTE_ID):
             result = server.get_promote_by_promote_id(
                 args[ARGS.PROMOTE_ID])
         else:
             code = 409
     result = [parse_times(x) for x in result]
     app.logger.debug(result)
     return result, code
예제 #17
0
 def get(self):
     """
     retrieve artifact details
     """
     result = []
     code = 200
     args = artifact_get_parser.parse_args()
     app.logger.debug(args)
     with PgServer(ENVIRONMENT_PROPERTIES) as server:
         if args.get(ARGS.FILENAME):
             result = server.get_artifact_by_filename(args[ARGS.FILENAME])
         elif args.get(ARGS.VERSION) and ARGS.VERSION_TYPE:
             result = server.get_artifact_by_version(
                 args[ARGS.VERSION_TYPE], args[ARGS.VERSION])
         elif args.get(ARGS.BUILD_ID):
             result = server.get_artifact_by_build_id(args[ARGS.BUILD_ID])
         elif args.get(ARGS.ARTIFACT_ID):
             result = server.get_artifact_by_artifact_id(
                 args[ARGS.ARTIFACT_ID])
         else:
             code = 409
     result = [parse_times(x) for x in result]
     app.logger.debug('fetched artifact: %s', result)
     return result, code
예제 #18
0
def main(args):
    args = arg_handler()
    command_string = args.command
    with PgServer() as server:
        if command_string == 'w-changeset':
            for v in args.value:
                server.ensure_version('changeset', v)

        elif command_string == 'w-filename':
            for v in args.value:
                server.append_thing(ThingType.FILENAME, v)

        elif command_string == 'w-servername':
            server.ensure_servername(args.value)

        elif command_string == 'w-build':
            print server.append_build('changeset', args.changeset,
                                      args.job_url, args.job_description,
                                      args.duration, args.result, {})
        elif command_string == 'build':
            if args.job_url:
                pprint(server.get_build_by_url(args.job_url))
            elif args.build_id:
                pprint(server.get_build_by_build_id(args.build_id))
            elif args.changeset:
                pprint(server.get_build_by_version('changeset',
                                                   args.changeset))
            else:
                print "Must specify one of three options - execute --help"

        elif command_string == "all-builds":
            pprint(server.get_all_builds())

        elif command_string == 'w-artifact':
            print server.append_artifact('changeset', args.changeset,
                                         args.filename, args.build_id, {})

        elif command_string == 'artifact':
            if args.filename:
                pprint(server.get_artifact_by_filename(args.filename))
            elif args.changeset:
                pprint(
                    server.get_artifact_by_version('changeset',
                                                   args.changeset))
            elif args.build_id:
                pprint(server.get_artifact_by_build_id(args.build_id))
            elif args.artifact_id:
                pprint(server.get_artifact_by_artifact_id(args.artifact_id))
            else:
                print "Must specify one of three options... see --help"

        elif command_string == "all-artifacts":
            pprint(server.get_all_artifacts())

        elif command_string == "all-deploys":
            pprint(server.get_all_deploys())

        elif command_string == "all-promotes":
            pprint(server.get_all_promotes())

        elif command_string == 'w-deploy':
            pprint(
                server.append_deploy(args.thingtype, args.thingname,
                                     'changeset', args.changeset,
                                     args.environment, args.servername, {}))
        elif command_string == "deploy":

            if args.environment:
                pprint(server.get_deploys_by_environment(args.environment))
            elif args.deploy_id:
                pprint(server.get_deploys_by_deploy_id(args.deploy_id))
            elif args.thing_name:
                pprint(server.get_deploys_by_thing_name(args.thing_name))
            elif args.changeset:
                pprint(
                    server.get_deploys_by_version('changeset', args.changeset))
            else:
                print "must specify a correct option...  see --help"

        elif command_string == 'w-promote':
            pprint(
                server.append_promote(ThingType.FILENAME, args.filename,
                                      args.environment, {}))

        elif command_string == 'promote':
            if args.filename:
                pprint(
                    server.get_promote_by_thing(ThingType.FILENAME,
                                                args.filename))
            elif args.environment:
                pprint(server.get_promote_by_environment(args.environment))
            else:
                print "Need an option, specify --help"

        else:
            assert False, "unable to parse"
    return 0