Search in sources :

Example 1 with ResourcesGenerator

use of org.glassfish.admin.rest.generator.ResourcesGenerator in project Payara by payara.

the class GeneratorResource method get.

@GET
@Produces({ "text/plain" })
public String get(@QueryParam("outputDir") String outputDir) {
    if (outputDir == null) {
        outputDir = DEFAULT_OUTPUT_DIR;
    }
    String retVal = "Code Generation done at : " + outputDir;
    try {
        LocatorBridge locatorBridge = habitat.getService(LocatorBridge.class);
        Dom dom = Dom.unwrap(locatorBridge.getRemoteLocator().<Domain>getService(Domain.class));
        DomDocument document = dom.document;
        ConfigModel rootModel = dom.document.getRoot().model;
        ResourcesGenerator resourcesGenerator = new TextResourcesGenerator(outputDir, habitat);
        resourcesGenerator.generateSingle(rootModel, document);
        resourcesGenerator.endGeneration();
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
        retVal = "Exception encountered during generation process: " + ex.toString() + "\nPlease look at server.log for more information.";
    }
    return retVal;
}
Also used : Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel) ResourcesGenerator(org.glassfish.admin.rest.generator.ResourcesGenerator) TextResourcesGenerator(org.glassfish.admin.rest.generator.TextResourcesGenerator) TextResourcesGenerator(org.glassfish.admin.rest.generator.TextResourcesGenerator) LocatorBridge(org.glassfish.admin.rest.adapter.LocatorBridge) Domain(com.sun.enterprise.config.serverbeans.Domain) DomDocument(org.jvnet.hk2.config.DomDocument) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ResourcesGenerator

use of org.glassfish.admin.rest.generator.ResourcesGenerator in project Payara by payara.

the class StatusGenerator method getPlain.

@GET
@Produces({ "text/plain" })
public String getPlain() {
    // status.append("Status of Command usage\n");
    try {
        Domain entity = serviceLocator.getService(Domain.class);
        Dom dom = Dom.unwrap(entity);
        DomDocument document = dom.document;
        ConfigModel rootModel = dom.document.getRoot().model;
        ResourcesGenerator resourcesGenerator = new NOOPResourcesGenerator(serviceLocator);
        resourcesGenerator.generateSingle(rootModel, document);
        resourcesGenerator.endGeneration();
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    // retVal = "Exception encountered during generation process: " + ex.toString() + "\nPlease look at server.log for more information.";
    }
    status.append("\n------------------------");
    status.append("All Commands used in REST Admin:\n");
    for (String ss : commandsUsed) {
        status.append(ss + "\n");
    }
    listOfCommands();
    for (String ss : commandsUsed) {
        allCommands.remove(ss);
    }
    status.append("\n------------------------");
    status.append("Missing Commands not used in REST Admin:\n");
    for (String ss : allCommands) {
        if (hasTargetParam(ss)) {
            status.append(ss + "          has a target param " + "\n");
        } else {
            status.append(ss + "\n");
        }
    }
    status.append("\n------------------------");
    status.append("REST-REDIRECT Commands defined on ConfigBeans:\n");
    for (String ss : restRedirectCommands) {
        status.append(ss + "\n");
    }
    status.append("\n------------------------");
    status.append("Commands to Resources Mapping Usage in REST Admin:\n");
    for (String ss : commandsToResources.keySet()) {
        if (hasTargetParam(ss)) {
            status.append(ss + "   :::target:::   " + commandsToResources.get(ss) + "\n");
        } else {
            status.append(ss + "      :::      " + commandsToResources.get(ss) + "\n");
        }
    }
    status.append("\n------------------------");
    status.append("Resources with Delete Commands in REST Admin (not counting RESTREDIRECT:\n");
    for (String ss : resourcesToDeleteCommands.keySet()) {
        status.append(ss + "      :::      " + resourcesToDeleteCommands.get(ss) + "\n");
    }
    FileOutputStream f = null;
    try {
        f = new FileOutputStream(System.getProperty("user.home") + "/GlassFishI18NData.properties");
        propsI18N.store(f, "");
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    } finally {
        if (f != null) {
            try {
                f.close();
            } catch (IOException ex) {
                RestLogging.restLogger.log(Level.SEVERE, null, ex);
            }
        }
    }
    return status.toString();
}
Also used : Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel) FileOutputStream(java.io.FileOutputStream) ResourcesGenerator(org.glassfish.admin.rest.generator.ResourcesGenerator) IOException(java.io.IOException) Domain(com.sun.enterprise.config.serverbeans.Domain) IOException(java.io.IOException) MultiException(org.glassfish.hk2.api.MultiException) DomDocument(org.jvnet.hk2.config.DomDocument) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ResourcesGenerator

use of org.glassfish.admin.rest.generator.ResourcesGenerator in project Payara by payara.

the class RestManagementResourceProvider method generateASM.

private void generateASM(ServiceLocator habitat) {
    try {
        Domain entity = habitat.getService(Domain.class);
        Dom dom = Dom.unwrap(entity);
        ResourcesGenerator resourcesGenerator = new ASMResourcesGenerator(habitat);
        resourcesGenerator.generateSingle(dom.document.getRoot().model, dom.document);
        resourcesGenerator.endGeneration();
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    }
}
Also used : Dom(org.jvnet.hk2.config.Dom) ASMResourcesGenerator(org.glassfish.admin.rest.generator.ASMResourcesGenerator) ResourcesGenerator(org.glassfish.admin.rest.generator.ResourcesGenerator) Domain(com.sun.enterprise.config.serverbeans.Domain) ASMResourcesGenerator(org.glassfish.admin.rest.generator.ASMResourcesGenerator) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException)

Example 4 with ResourcesGenerator

use of org.glassfish.admin.rest.generator.ResourcesGenerator in project Payara by payara.

the class StatusGenerator method getHtml.

@GET
@Produces({ MediaType.TEXT_HTML })
public String getHtml() {
    try {
        Domain entity = serviceLocator.getService(Domain.class);
        Dom dom = Dom.unwrap(entity);
        DomDocument document = dom.document;
        ConfigModel rootModel = dom.document.getRoot().model;
        ResourcesGenerator resourcesGenerator = new NOOPResourcesGenerator(serviceLocator);
        resourcesGenerator.generateSingle(rootModel, document);
        resourcesGenerator.endGeneration();
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    }
    status.append("<h4>All Commands used in REST Admin</h4>\n<ul>\n");
    for (String ss : commandsUsed) {
        status.append("<li>").append(ss).append("</li>\n");
    }
    listOfCommands();
    for (String ss : commandsUsed) {
        allCommands.remove(ss);
    }
    status.append("</ul>\n<hr/>\n").append("<h4>Missing Commands not used in REST Admin</h4>\n<ul>\n");
    for (String ss : allCommands) {
        if (hasTargetParam(ss)) {
            status.append("<li>").append(ss).append("          has a target param.</li>\n");
        } else {
            status.append("<li>").append(ss).append("</li>\n");
        }
    }
    status.append("</ul>\n<hr/>\n").append("<h4>REST-REDIRECT Commands defined on ConfigBeans</h4>\n<ul>\n");
    for (String ss : restRedirectCommands) {
        status.append("<li>").append(ss).append("</li>\n");
    }
    status.append("</ul>\n<hr/>\n").append("<h4>Commands to Resources Mapping Usage in REST Admin</h4>\n").append("<table border=\"1\" style=\"border-collapse: collapse\">\n").append("<tr><th>Command</th><th>Target</th><th>Resource</th></tr>\n");
    for (String ss : commandsToResources.keySet()) {
        status.append("<tr><td>").append(ss).append("</td><td>").append(hasTargetParam(ss) ? "target" : "").append("</td><td>").append(commandsToResources.get(ss)).append("</td></tr>\n");
    }
    status.append("</table>\n<hr/>\n").append("<h4>Resources with Delete Commands in REST Admin (not counting RESTREDIRECT)</h4>\n").append("<table border=\"1\" style=\"border-collapse: collapse\">\n").append("<tr><th>Resource</th><th>Delete Command</th></tr>\n");
    for (String ss : resourcesToDeleteCommands.keySet()) {
        status.append("<tr><td>").append(ss).append("</td><td>").append(resourcesToDeleteCommands.get(ss)).append("</td></tr>\n");
    }
    status.append("</table>");
    FileOutputStream f = null;
    try {
        f = new FileOutputStream(System.getProperty("user.home") + "/GlassFishI18NData.properties");
        propsI18N.store(f, "");
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    } finally {
        if (f != null) {
            try {
                f.close();
            } catch (IOException ex) {
                RestLogging.restLogger.log(Level.SEVERE, null, ex);
            }
        }
    }
    return status.toString();
}
Also used : Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel) FileOutputStream(java.io.FileOutputStream) ResourcesGenerator(org.glassfish.admin.rest.generator.ResourcesGenerator) IOException(java.io.IOException) Domain(com.sun.enterprise.config.serverbeans.Domain) IOException(java.io.IOException) MultiException(org.glassfish.hk2.api.MultiException) DomDocument(org.jvnet.hk2.config.DomDocument) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Domain (com.sun.enterprise.config.serverbeans.Domain)4 ResourcesGenerator (org.glassfish.admin.rest.generator.ResourcesGenerator)4 Dom (org.jvnet.hk2.config.Dom)4 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 ConfigModel (org.jvnet.hk2.config.ConfigModel)3 DomDocument (org.jvnet.hk2.config.DomDocument)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 MultiException (org.glassfish.hk2.api.MultiException)2 LocatorBridge (org.glassfish.admin.rest.adapter.LocatorBridge)1 ASMResourcesGenerator (org.glassfish.admin.rest.generator.ASMResourcesGenerator)1 TextResourcesGenerator (org.glassfish.admin.rest.generator.TextResourcesGenerator)1 EndpointRegistrationException (org.glassfish.api.container.EndpointRegistrationException)1