Changeset 1877 for trunk


Ignore:
Timestamp:
2011-03-30 10:00:06 (14 months ago)
Author:
mpo
Message:

First stab at providing per module information in as needed for #447
Since we often now the version of each module from the explicit wiring.xml, we just pass that down into the ModuleDefinition?.

(This level seems to be the correct place for implementing auto-detection of versions from the jar contents)

The option has now been taken to dump a more elaborate moduleInfo() string that includes this version.

(Might be wise to lower this for e.g. security reasons)

Finally this information is accessible from outside the kauri-runtime in a number of ways

  • the exposed moduleInfo() method in the KauriModule? (rapi)
  • dumped to the CLI when the flag--info (-I) is present: --info module_id or --info + (for a list of all modules)
  • the module responsible for the rest-call handling adds its info-line to the http request header X-Kauri-ModuleInfo?
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/kauri-runtime-cli/src/main/java/org/kauriproject/runtime/cli/KauriRuntimeCli.java

    r1716 r1877  
    162162                .create("p"); 
    163163        cliOptions.addOption(modeOption); 
    164  
     164         
     165        Option infoOption = OptionBuilder 
     166            .withArgName("module-id") 
     167            .hasArg() 
     168            .withDescription("Don't start the service, only dump the info string for the module.") 
     169            .withLongOpt("info") 
     170            .create("I"); 
     171        cliOptions.addOption(infoOption);       
     172         
    165173        Option helpOption = new Option("h", "help", false, "Shows help"); 
    166174        cliOptions.addOption(helpOption); 
     
    267275            Mode mode = Mode.byName(optionValue); 
    268276            runtime.setMode(mode); 
     277        } 
     278         
     279        if (cmd.hasOption(infoOption.getOpt())) { 
     280            System.out.println(runtime.buildModel().moduleInfo(cmd.getOptionValue(infoOption.getOpt()))); 
     281            System.exit(0); 
    269282        } 
    270283 
  • trunk/core/kauri-runtime-rapi/src/main/java/org/kauriproject/runtime/rapi/KauriModule.java

    r1544 r1877  
    137137 
    138138    ConfRegistry getConfRegistry(); 
     139     
     140    String moduleInfo(); 
    139141} 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/KauriRuntime.java

    r1593 r1877  
    105105    } 
    106106 
     107 
     108    public KauriRuntimeModel buildModel() { 
     109        // Init the configuration manager 
     110        ConfManager confManager = settings.getConfManager(); 
     111        confManager.initRuntimeConfig(); 
     112 
     113        ConfRegistry confRegistry = confManager.getRuntimeConfRegistry(); 
     114         
     115        return buildModel(confRegistry); 
     116    } 
     117 
     118 
     119    private KauriRuntimeModel buildModel(ConfRegistry confRegistry) { 
     120        KauriRuntimeModel newModel; 
     121        if ((settings.getModel() != null)) { 
     122            newModel = settings.getModel(); 
     123        } else { 
     124            Conf modulesConf = confRegistry.getConfiguration("wiring", false, false); 
     125            Set<String> disabledModuleIds = settings.getDisabledModuleIds() != null ? 
     126                    settings.getDisabledModuleIds() : Collections.<String>emptySet(); 
     127            SourceLocations sourceLocations = settings.getSourceLocations() != null ? 
     128                    settings.getSourceLocations() : new SourceLocations(); 
     129            try { 
     130                newModel = KauriRuntimeModelBuilder.build(modulesConf, disabledModuleIds, settings.getRepository(), sourceLocations); 
     131            } catch (Exception e) { 
     132                throw new KauriRTException("Error building the Kauri model from configuration.", e); 
     133            } 
     134        } 
     135        return newModel; 
     136    } 
     137 
    107138    /** 
    108139     * Starts the Kauri Runtime. This will launch all modules (i.e. their Spring containers), 
     
    125156        ConfRegistry confRegistry = confManager.getRuntimeConfRegistry(); 
    126157 
    127         // Build the runtime model, unless it has been supplied via the settings 
    128         if (settings.getModel() != null) { 
    129             this.model = settings.getModel(); 
    130         } else { 
    131             Conf modulesConf = confRegistry.getConfiguration("wiring", false, false); 
    132             Set<String> disabledModuleIds = settings.getDisabledModuleIds() != null ? 
    133                     settings.getDisabledModuleIds() : Collections.<String>emptySet(); 
    134             SourceLocations sourceLocations = settings.getSourceLocations() != null ? 
    135                     settings.getSourceLocations() : new SourceLocations(); 
    136             try { 
    137                 this.model = KauriRuntimeModelBuilder.build(modulesConf, disabledModuleIds, settings.getRepository(), sourceLocations); 
    138             } catch (Exception e) { 
    139                 throw new KauriRTException("Error building the Kauri model from configuration.", e); 
    140             } 
     158        this.model = buildModel(confRegistry); 
     159         
     160        //extra model configuration to apply when not passed from settings  
     161        if (settings.getModel() == null) { 
    141162 
    142163            Conf connectorsConf = confRegistry.getConfiguration("connectors", false); 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/model/KauriRuntimeModel.java

    r1058 r1877  
    6868        } 
    6969    } 
     70    
     71    public String moduleInfo(String id){ 
     72        if (id == null || id.length() == 0 || id.equals("+")){ 
     73            String result = ""; 
     74            int i = 1; 
     75            for (ModuleDefinition module : modules) { 
     76                result += String.format(" [%3d.] %s\n",  i++ , module.moduleInfo()); 
     77            } 
     78            return result; 
     79        } 
     80         
     81        final ModuleDefinition module = getModuleById(id); 
     82        if (module == null) 
     83             return "No module with id: " + id; 
     84        return module.moduleInfo(); 
     85    } 
    7086 
    7187} 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/model/KauriRuntimeModelBuilder.java

    r1842 r1877  
    6464            File fileToImport = null; 
    6565            ModuleSourceType sourceType = null; 
     66            String version = "unknown"; 
    6667            String id = importConf.getAttribute("id"); 
    6768            if (importConf.getName().equals("file")) { 
     
    7475                String classifier = importConf.getAttribute("classifier", null); 
    7576                // Version is optional for org.kauriproject artifacts 
    76                 String version = groupId.equals("org.kauriproject") ? 
     77                version = groupId.equals("org.kauriproject") ? 
    7778                        importConf.getAttribute("version", null) : importConf.getAttribute("version"); 
    7879                version = version == null ? KauriRuntime.getVersion() : version; 
     
    113114                ModuleDefinition moduleDefinition = new ModuleDefinition(id, fileToImport, sourceType); 
    114115                moduleDefinition.setLocation(importConf.getLocation()); 
     116                moduleDefinition.setVersion(version); 
    115117                buildWiring(importConf, moduleDefinition); 
    116118 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/model/ModuleDefinition.java

    r1058 r1877  
    3535    private Map<String, JavaServiceInjectByServiceDefinition> javaServiceInjectsByService = new HashMap<String, JavaServiceInjectByServiceDefinition>(); 
    3636    private Location location; 
     37    private String version; 
    3738 
    3839    public ModuleDefinition(String id, File file, ModuleSourceType sourceType) { 
     
    5758        this.location = location; 
    5859    } 
     60     
     61    public String getVersion() { 
     62        return version; 
     63    } 
    5964 
     65    public void setVersion(String version) { 
     66        this.version = version; 
     67    } 
     68     
     69    public String moduleInfo() { 
     70        return String.format("%s (version: %s) - running from [%s] (in mode: %s)", id, version, file.getAbsolutePath(), sourceType.name()); 
     71    } 
     72     
    6073    /** 
    6174     * Use {@link #getSourceType()} to find out which kind of module source type this 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/module/restservice/RestserviceFacet.java

    r1706 r1877  
    3333import org.kauriproject.runtime.module.Module; 
    3434import org.kauriproject.runtime.rapi.FilterFactory; 
     35import org.kauriproject.runtime.rapi.KauriModule; 
    3536import org.kauriproject.runtime.rapi.ModuleSource; 
    3637import org.kauriproject.runtime.rapi_impl.KauriModuleImpl; 
     
    4041import org.restlet.Response; 
    4142import org.restlet.Restlet; 
     43import org.restlet.data.Form; 
    4244import org.restlet.data.MediaType; 
    4345import org.restlet.data.Protocol; 
     
    128130            request.getAttributes().put(RESTSERVICE_NAME_KEY, name); 
    129131            application.handle(request, response); 
    130         } 
    131     } 
    132  
     132            addModuleInfoHeader(response); 
     133        } 
     134    } 
     135 
     136    private void addModuleInfoHeader(Response response) { 
     137        Form responseHeaders = (Form) response.getAttributes().get("org.restlet.http.headers");   
     138        if (responseHeaders == null) {   
     139            responseHeaders = new Form();   
     140            response.getAttributes().put("org.restlet.http.headers", responseHeaders);   
     141        }   
     142        responseHeaders.add("X-Kauri-ModuleInfo", module.getDefinition().moduleInfo()); 
     143    } 
     144     
    133145    public void addRestserviceImport(String name, String restserviceType, RestserviceHandle restserviceHandle) { 
    134146        RestserviceRegistryEntry entry = new RestserviceRegistryEntry(RestserviceRegistryEntry.Type.IMPORT, restserviceType); 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/rapi_impl/KauriModuleImpl.java

    r1544 r1877  
    176176        return runtime.getConfManager().getConfRegistry(module.getDefinition().getId()); 
    177177    } 
     178     
     179    public String moduleInfo() { 
     180        return module.getDefinition().moduleInfo(); 
     181    } 
    178182} 
  • trunk/modules/kauri-representation/kauri-representationbuilder-impl/src/test/java/org/kauriproject/representation/test/BuilderTest.java

    r1544 r1877  
    145145                return null; 
    146146            } 
     147             
     148            public String moduleInfo() { 
     149                return null; 
     150            } 
    147151        }; 
    148152 
Note: See TracChangeset for help on using the changeset viewer.