Search in sources :

Example 6 with InstallationState

use of org.apache.sling.installer.api.info.InstallationState in project sling by apache.

the class OsgiInstallerHealthCheck method execute.

@Override
public Result execute() {
    InstallationState installationState = infoProvider.getInstallationState();
    FormattingResultLog hcLog = new FormattingResultLog();
    int numCheckedConfigurations = 0;
    int numCheckedBundles = 0;
    // go through all resource groups of the OSGi Installer
    for (final ResourceGroup group : installationState.getInstalledResources()) {
        String type = evaluateGroup(group, hcLog);
        switch(type) {
            case InstallableResource.TYPE_CONFIG:
                numCheckedConfigurations++;
                break;
            case InstallableResource.TYPE_BUNDLE:
                numCheckedBundles++;
                break;
        }
    }
    hcLog.info("Checked {} OSGi bundles and {} configurations.", numCheckedBundles, numCheckedConfigurations);
    if (hcLog.getAggregateStatus().ordinal() >= Result.Status.WARN.ordinal()) {
        hcLog.info("Refer to the OSGi installer's documentation page at {} for further details on how to fix those issues.", DOCUMENTATION_URL);
    }
    return new Result(hcLog);
}
Also used : InstallationState(org.apache.sling.installer.api.info.InstallationState) FormattingResultLog(org.apache.sling.hc.util.FormattingResultLog) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup) Result(org.apache.sling.hc.api.Result)

Example 7 with InstallationState

use of org.apache.sling.installer.api.info.InstallationState in project sling by apache.

the class OsgiInstallerWebConsolePlugin method printConfiguration.

/**
     * Method for the configuration printer.
     */
public void printConfiguration(final PrintWriter pw, final String mode) {
    if (!"zip".equals(mode) && !"txt".equals(mode)) {
        return;
    }
    pw.println("Apache Sling OSGi Installer");
    pw.println("===========================");
    final InstallationState state = this.installer.getInstallationState();
    pw.println("Active Resources");
    pw.println("----------------");
    String rt = null;
    for (final ResourceGroup group : state.getActiveResources()) {
        final Resource toActivate = group.getResources().get(0);
        if (!toActivate.getType().equals(rt)) {
            pw.printf("%s:%n", getType(toActivate));
            rt = toActivate.getType();
        }
        pw.printf("- %s: %s, %s, %s%n", getEntityId(toActivate, group.getAlias()), getInfo(toActivate), getURL(toActivate), toActivate.getState());
    }
    pw.println();
    pw.println("Processed Resources");
    pw.println("-------------------");
    rt = null;
    for (final ResourceGroup group : state.getInstalledResources()) {
        final Collection<Resource> resources = group.getResources();
        if (resources.size() > 0) {
            final Iterator<Resource> iter = resources.iterator();
            final Resource first = iter.next();
            if (!first.getType().equals(rt)) {
                pw.printf("%s:%n", getType(first));
                rt = first.getType();
            }
            pw.printf("* %s: %s, %s, %s%n", getEntityId(first, group.getAlias()), getInfo(first), getURL(first), getState(first));
            if (first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED) != null) {
                pw.printf("  : %s", first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED));
            }
            if (first.getAttribute(TaskResource.ATTR_INSTALL_INFO) != null) {
                pw.printf("  : %s", first.getAttribute(TaskResource.ATTR_INSTALL_INFO));
            }
            while (iter.hasNext()) {
                final Resource resource = iter.next();
                pw.printf("  - %s, %s, %s%n", getInfo(resource), getURL(resource), resource.getState());
            }
        }
    }
    pw.println();
    pw.println("Untransformed Resources");
    pw.println("-----------------------");
    rt = null;
    for (final RegisteredResource registeredResource : state.getUntransformedResources()) {
        if (!registeredResource.getType().equals(rt)) {
            pw.printf("%s:%n", getType(registeredResource));
            rt = registeredResource.getType();
        }
        pw.printf("- %s, %s%n", getInfo(registeredResource), registeredResource.getURL());
    }
}
Also used : InstallationState(org.apache.sling.installer.api.info.InstallationState) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) Resource(org.apache.sling.installer.api.info.Resource) InstallableResource(org.apache.sling.installer.api.InstallableResource) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup)

Example 8 with InstallationState

use of org.apache.sling.installer.api.info.InstallationState in project sling by apache.

the class OsgiInstallerWebConsolePlugin method service.

@Override
public void service(final ServletRequest req, final ServletResponse res) throws IOException {
    final PrintWriter pw = res.getWriter();
    final InstallationState state = this.installer.getInstallationState();
    pw.print("<p class='statline ui-state-highlight'>Apache Sling OSGi Installer");
    if (state.getActiveResources().size() == 0 && state.getInstalledResources().size() == 0 && state.getUntransformedResources().size() == 0) {
        pw.print(" - no resources registered.");
    }
    pw.print("</p>");
    String rt = null;
    for (final ResourceGroup group : state.getActiveResources()) {
        final Resource toActivate = group.getResources().get(0);
        if (!toActivate.getType().equals(rt)) {
            if (rt != null) {
                pw.println("</tbody></table>");
            }
            pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
            pw.printf("<span style='float: left; margin-left: 1em;'>Active Resources - %s</span>", getType(toActivate));
            pw.println("</div>");
            pw.println("<table class='nicetable'><tbody>");
            pw.printf("<tr><th>Entity ID</th><th>Digest/Priority</th><th>URL (Version)</th><th>State</th><th>Error</th></tr>");
            rt = toActivate.getType();
        }
        pw.printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", getEntityId(toActivate, group.getAlias()), getInfo(toActivate), getURL(toActivate), toActivate.getState(), getError(toActivate));
    }
    if (rt != null) {
        pw.println("</tbody></table>");
    }
    rt = null;
    for (final ResourceGroup group : state.getInstalledResources()) {
        final Collection<Resource> resources = group.getResources();
        if (resources.size() > 0) {
            final Iterator<Resource> iter = resources.iterator();
            final Resource first = iter.next();
            if (!first.getType().equals(rt)) {
                if (rt != null) {
                    pw.println("</tbody></table>");
                }
                pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
                pw.printf("<span style='float: left; margin-left: 1em;'>Processed Resources - %s</span>", getType(first));
                pw.println("</div>");
                pw.println("<table class='nicetable'><tbody>");
                pw.printf("<tr><th>Entity ID</th><th>Digest/Priority</th><th>URL (Version)</th><th>State</th><th>Error</th></tr>");
                rt = first.getType();
            }
            pw.print("<tr><td>");
            pw.print(getEntityId(first, group.getAlias()));
            pw.print("</td><td>");
            pw.print(getInfo(first));
            pw.print("</td><td>");
            pw.print(getURL(first));
            pw.print("</td><td>");
            pw.print(getState(first));
            if (first.getState() == ResourceState.INSTALLED) {
                final long lastChange = first.getLastChange();
                if (lastChange > 0) {
                    pw.print("<br/>");
                    pw.print(formatDate(lastChange));
                }
            }
            pw.print("</td><td>");
            pw.print(getError(first));
            pw.print("</td></tr>");
            if (first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED) != null) {
                pw.printf("<tr><td></td><td colspan='2'>%s</td><td></td><td></td></tr>", first.getAttribute(TaskResource.ATTR_INSTALL_EXCLUDED));
            }
            if (first.getAttribute(TaskResource.ATTR_INSTALL_INFO) != null) {
                pw.printf("<tr><td></td><td colspan='2'>%s</td><td></td><td></td></tr>", first.getAttribute(TaskResource.ATTR_INSTALL_INFO));
            }
            while (iter.hasNext()) {
                final Resource resource = iter.next();
                pw.printf("<tr><td></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", getInfo(resource), getURL(resource), resource.getState(), getError(resource));
            }
        }
    }
    if (rt != null) {
        pw.println("</tbody></table>");
    }
    rt = null;
    for (final RegisteredResource registeredResource : state.getUntransformedResources()) {
        if (!registeredResource.getType().equals(rt)) {
            if (rt != null) {
                pw.println("</tbody></table>");
            }
            pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
            pw.printf("<span style='float: left; margin-left: 1em;'>Untransformed Resources - %s</span>", getType(registeredResource));
            pw.println("</div>");
            pw.println("<table class='nicetable'><tbody>");
            pw.printf("<tr><th>Digest/Priority</th><th>URL</th></tr>");
            rt = registeredResource.getType();
        }
        pw.printf("<tr><td>%s</td><td>%s</td></tr>", getInfo(registeredResource), registeredResource.getURL());
    }
    if (rt != null) {
        pw.println("</tbody></table>");
    }
}
Also used : InstallationState(org.apache.sling.installer.api.info.InstallationState) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) Resource(org.apache.sling.installer.api.info.Resource) InstallableResource(org.apache.sling.installer.api.InstallableResource) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup) PrintWriter(java.io.PrintWriter)

Aggregations

InstallationState (org.apache.sling.installer.api.info.InstallationState)8 ResourceGroup (org.apache.sling.installer.api.info.ResourceGroup)6 Resource (org.apache.sling.installer.api.info.Resource)5 InstallableResource (org.apache.sling.installer.api.InstallableResource)4 RegisteredResource (org.apache.sling.installer.api.tasks.RegisteredResource)3 TaskResource (org.apache.sling.installer.api.tasks.TaskResource)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CheckForNull (javax.annotation.CheckForNull)1 Result (org.apache.sling.hc.api.Result)1 FormattingResultLog (org.apache.sling.hc.util.FormattingResultLog)1 ResourceState (org.apache.sling.installer.api.tasks.ResourceState)1 TaskResourceGroup (org.apache.sling.installer.api.tasks.TaskResourceGroup)1 Version (org.osgi.framework.Version)1