def main(argv): parser = create_opt_parser() (options, args) = parser.parse_args(argv) if options.verbose: setup_logging(logging.DEBUG) else: setup_logging(logging.INFO) resource_keys = \ engage.utils.rdef.parse_resource_keys_option(options.resource, parser) if len(args)==0: rdef_file = NamedTemporaryFile(delete=False) rdef_file.close() filename = rdef_file.name using_temp_file = True elif len(args)==1: filename = os.path.abspath(os.path.expanduser(args[0])) using_temp_file = False else: parser.error("Too many arguments") try: layout_mgr = engage_file_layout.get_engine_layout_mgr() main_rdef_file = os.path.abspath(os.path.expanduser(layout_mgr.get_resource_def_file())) all_input_files = layout_mgr.get_extension_resource_files() + [main_rdef_file,] if filename in all_input_files: # make sure user doesn't overwrite main file # should only get this problem if user specified the file assert not using_temp_file parser.error("Resource definition file parameter is for generated file, not the input file!") logger.debug("Preprocessing resource files, output is %s" % filename) preprocess_resource_file(main_rdef_file, layout_mgr.get_extension_resource_files(), filename, logger) with open(filename, "rb") as f: rg = engage.utils.rdef.create_resource_graph(json.load(f)) if resource_keys: rg = rg.filter(resource_keys) if not using_temp_file: rg.write_to_file(filename) (errors, warnings) = rg.validate() if errors==0 and warnings==0: print "Validation of resource definitions ok" return 0 else: print "Validation of resource definitions found %d errors, %d warnings" \ % (errors, warnings) return 1 finally: if using_temp_file: os.remove(filename)
def generate_port_checks(res_name, res_version): key = {u"name":unicode(res_name), u"version":unicode(res_version)} with NamedTempFile() as f: layout_mgr = efl.get_engine_layout_mgr() main_rdef_file = os.path.abspath(os.path.expanduser(layout_mgr.get_resource_def_file())) ppr.preprocess_resource_file(main_rdef_file, layout_mgr.get_extension_resource_files(), f.name, logger) with open(f.name, "rb") as rf: g = rdef.create_resource_graph(json.load(rf)) if not g.has_resource(key): raise Exception("Resource %s %s not found in resource definitions" % (res_name, res_version)) r = g.get_resource(key) if len(r.config_port.properties)>0: checks = resource_port_to_port_check(r.config_port) else: checks = "" for p in r.input_ports.values(): checks += resource_port_to_port_check(p) for p in r.output_ports.values(): checks += resource_port_to_port_check(p) return checks
def main(argv): global sphinx_mode parser = create_opt_parser() (options, args) = parser.parse_args(argv) if options.header and \ not os.path.exists(options.header): parser.error("Header text file %s does not exist" % options.header) if options.use_sphinx_references: sphinx_mode = True setup_logging(logging.INFO) resource_keys = \ engage.utils.rdef.parse_resource_keys_option(options.resource, parser) if len(args) > 1: parser.error("Too many arguments") def warning(msg): if not options.quiet: sys.stderr.write(msg + "\n") # preprocess resources and build the graph layout_mgr = engage_file_layout.get_engine_layout_mgr() main_rdef_file = os.path.abspath( os.path.expanduser(layout_mgr.get_resource_def_file())) all_input_files = layout_mgr.get_extension_resource_files() + [ main_rdef_file, ] with NamedTempFile() as temp: preprocess_resource_file(main_rdef_file, layout_mgr.get_extension_resource_files(), temp.name, logger) with open(temp.name, "rb") as f: rg = engage.utils.rdef.create_resource_graph(json.load(f)) if resource_keys: rg = rg.filter(resource_keys) if len(args) == 0: of = sys.stdout need_to_close = False else: of = open(args[0], "wb") need_to_close = True if options.header: with open(options.header, "rb") as f: for line in f: of.write(line) # get the resource library library = engage.engine.library.parse_library_files( layout_mgr, use_temporary_file=True) resource_drivers = {} # group the resources and build the map of drivers def is_host(r): return r.inside_constraint==None and r.env_constraint==None and \ r.peer_constraint==None keys = get_sorted_resource_keys(rg) num = len(keys) primary_keys = rg.find_resources_not_referenced_as_dependencies() primary = [] hosts = [] other = [] for k in keys: r = rg.get_resource(k) kstr = engage.utils.rdef.hash_key_for_res_key(k) if kstr in primary_keys: if is_host(r): warning("Skipping resource %s %s - it is an orphan" % (r.key["name"], r.key["version"])) else: primary.append(r) elif is_host(r): hosts.append(r) else: other.append(r) md = ResourceMD("test", k) library_entry = library.get_entry(md) if library_entry: resource_drivers[kstr] = library_entry.mgr_module_name else: resource_drivers[kstr] = None warning("Resource %s %s does not have a resource library entry" % (k["name"], k["value"])) def write_section(title, description, resources): of.write(title + "\n") of.write((RDEF_GROUP_HEADER * len(title)) + "\n") of.write(description + "\n\n") for r in resources: write_resource_as_rst(r, of, rg, resource_drivers) of.write("\n") write_section( "Primary Resources", 'The resources in this section are not referenced as dependencies by other resources. In most cases, these resources correspond to the applicaiton at the "top" of an application stack.', primary) write_section( "Host Resources", 'The resources in this section have no dependencies. In most cases, these resources correspond to the machine at the "bottom" of an application stack.', hosts) write_section( "Interior Resources", 'The resources in this section have dependencies and are dependencies for other resources. In most cases, these resources correspond to the "middle" of an application stack.', other) if need_to_close: of.close() print "Processed %d resources." % num