use of org.apache.sling.installer.api.info.InstallationState 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;
}
use of org.apache.sling.installer.api.info.InstallationState in project sling by apache.
the class ServerSideInstallerTest method noUntransformedResources.
@Test
public void noUntransformedResources() {
final InstallationState is = ip.getInstallationState();
final List<?> utr = is.getUntransformedResources();
if (utr.size() > 0) {
fail("Untransformed resources found: " + utr);
}
}
use of org.apache.sling.installer.api.info.InstallationState 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);
}
}
use of org.apache.sling.installer.api.info.InstallationState 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;
}
}
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());
}
}
Aggregations