Search in sources :

Example 1 with ResourceGroup

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

the class OsgiInstallerTestBase method waitForResource.

protected Resource waitForResource(final String url, final ResourceState state) {
    final long start = System.currentTimeMillis();
    final long end = start + WAIT_FOR_CHANGE_TIMEOUT;
    do {
        final InstallationState is = this.infoProvider.getInstallationState();
        for (final ResourceGroup rg : (state == ResourceState.INSTALL || state == ResourceState.UNINSTALL ? is.getActiveResources() : is.getInstalledResources())) {
            for (final Resource rsrc : rg.getResources()) {
                if (url.equals(rsrc.getURL())) {
                    if (rsrc.getState() == state) {
                        return rsrc;
                    }
                }
            }
        }
        sleep(50);
    } while (System.currentTimeMillis() < end);
    fail("Resource " + url + " not found with state " + state + " : " + this.infoProvider.getInstallationState());
    return null;
}
Also used : InstallationState(org.apache.sling.installer.api.info.InstallationState) Resource(org.apache.sling.installer.api.info.Resource) InstallableResource(org.apache.sling.installer.api.InstallableResource) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup)

Example 2 with ResourceGroup

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

the class OsgiInstallerImpl method getInstallationState.

/**
     * @see org.apache.sling.installer.api.info.InfoProvider#getInstallationState()
     */
@Override
public InstallationState getInstallationState() {
    synchronized (this.resourcesLock) {
        final InstallationState state = new InstallationState() {

            private final List<ResourceGroup> activeResources = new ArrayList<>();

            private final List<ResourceGroup> installedResources = new ArrayList<>();

            private final List<RegisteredResource> untransformedResources = new ArrayList<>();

            @Override
            public List<ResourceGroup> getActiveResources() {
                return activeResources;
            }

            @Override
            public List<ResourceGroup> getInstalledResources() {
                return installedResources;
            }

            @Override
            public List<RegisteredResource> getUntransformedResources() {
                return untransformedResources;
            }

            @Override
            public String toString() {
                return "InstallationState[active resources: " + this.activeResources + ", installed resources: " + this.installedResources + ", untransformed resources: " + this.untransformedResources + "]";
            }
        };
        for (final String entityId : this.persistentList.getEntityIds()) {
            if (!this.persistentList.isSpecialEntityId(entityId)) {
                final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
                final String alias = group.getAlias();
                final List<Resource> resources = new ArrayList<>();
                boolean first = true;
                boolean isActive = false;
                for (final TaskResource tr : group.getResources()) {
                    final ResourceState resourceState = tr.getState();
                    if (first) {
                        if (resourceState == ResourceState.INSTALL || resourceState == ResourceState.UNINSTALL) {
                            isActive = true;
                        }
                        first = false;
                    }
                    resources.add(new Resource() {

                        @Override
                        public String getScheme() {
                            return tr.getScheme();
                        }

                        @Override
                        public String getURL() {
                            return tr.getURL();
                        }

                        @Override
                        public String getType() {
                            return tr.getType();
                        }

                        @Override
                        public InputStream getInputStream() throws IOException {
                            return tr.getInputStream();
                        }

                        @Override
                        public Dictionary<String, Object> getDictionary() {
                            return tr.getDictionary();
                        }

                        @Override
                        public String getDigest() {
                            return tr.getDigest();
                        }

                        @Override
                        public int getPriority() {
                            return tr.getPriority();
                        }

                        @Override
                        public String getEntityId() {
                            return tr.getEntityId();
                        }

                        @Override
                        public ResourceState getState() {
                            return resourceState;
                        }

                        @Override
                        public Version getVersion() {
                            return tr.getVersion();
                        }

                        @Override
                        public long getLastChange() {
                            return ((RegisteredResourceImpl) tr).getLastChange();
                        }

                        @Override
                        public Object getAttribute(final String key) {
                            return tr.getAttribute(key);
                        }

                        @Override
                        @CheckForNull
                        public String getError() {
                            return tr.getError();
                        }

                        @Override
                        public String toString() {
                            return "resource[entityId=" + getEntityId() + ", scheme=" + getScheme() + ", url=" + getURL() + ", type=" + getType() + ", error=" + getError() + ", state=" + getState() + ", version=" + getVersion() + ", lastChange=" + getLastChange() + ", priority=" + getPriority() + ", digest=" + getDigest() + "]";
                        }
                    });
                }
                final ResourceGroup rg = new ResourceGroup() {

                    @Override
                    public List<Resource> getResources() {
                        return resources;
                    }

                    @Override
                    public String getAlias() {
                        return alias;
                    }

                    @Override
                    public String toString() {
                        return "group[" + resources + "]";
                    }
                };
                if (isActive) {
                    state.getActiveResources().add(rg);
                } else {
                    state.getInstalledResources().add(rg);
                }
            }
        }
        Collections.sort(state.getActiveResources(), COMPARATOR);
        Collections.sort(state.getInstalledResources(), COMPARATOR);
        state.getUntransformedResources().addAll(this.persistentList.getUntransformedResources());
        return state;
    }
}
Also used : Dictionary(java.util.Dictionary) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) InputStream(java.io.InputStream) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) ArrayList(java.util.ArrayList) TaskResource(org.apache.sling.installer.api.tasks.TaskResource) Resource(org.apache.sling.installer.api.info.Resource) RegisteredResource(org.apache.sling.installer.api.tasks.RegisteredResource) InstallableResource(org.apache.sling.installer.api.InstallableResource) IOException(java.io.IOException) InstallationState(org.apache.sling.installer.api.info.InstallationState) Version(org.osgi.framework.Version) CheckForNull(javax.annotation.CheckForNull) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ResourceState(org.apache.sling.installer.api.tasks.ResourceState) TaskResourceGroup(org.apache.sling.installer.api.tasks.TaskResourceGroup) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup)

Example 3 with ResourceGroup

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

the class ServerSideInstallerTest method noDuplicates.

@Test
public void noDuplicates() {
    final InstallationState is = ip.getInstallationState();
    String output = "";
    final List<ResourceGroup> resources = is.getInstalledResources();
    for (final ResourceGroup group : resources) {
        if (group.getResources().size() > 1) {
            boolean first = true;
            for (final Resource rsrc : group.getResources()) {
                if (ignore(rsrc.getEntityId())) {
                    continue;
                }
                if (first) {
                    output += "Duplicate resources for '" + rsrc.getEntityId() + "' : ";
                    first = false;
                } else {
                    output += ", ";
                }
                output += rsrc.getURL();
            }
            if (!output.isEmpty()) {
                output += "\n";
            }
        }
    }
    if (output.length() > 0) {
        fail(output);
    }
}
Also used : InstallationState(org.apache.sling.installer.api.info.InstallationState) Resource(org.apache.sling.installer.api.info.Resource) ResourceGroup(org.apache.sling.installer.api.info.ResourceGroup) Test(org.junit.Test)

Example 4 with ResourceGroup

use of org.apache.sling.installer.api.info.ResourceGroup 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 5 with ResourceGroup

use of org.apache.sling.installer.api.info.ResourceGroup 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)

Aggregations

InstallationState (org.apache.sling.installer.api.info.InstallationState)6 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 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 Test (org.junit.Test)1 Version (org.osgi.framework.Version)1