Examples of TaskResource


Examples of org.apache.sling.installer.api.tasks.TaskResource

     * Create a task to install or uninstall a configuration.
     *
   * @see org.apache.sling.installer.api.tasks.InstallTaskFactory#createTask(org.apache.sling.installer.api.tasks.TaskResourceGroup)
   */
  public InstallTask createTask(final TaskResourceGroup group) {
        final TaskResource toActivate = group.getActiveResource();
        if ( !toActivate.getType().equals(InstallableResource.TYPE_CONFIG) ) {
            return null;
        }

        final InstallTask result;
    if (toActivate.getState() == ResourceState.UNINSTALL) {
            // if this is an uninstall, check if we have to install an older version
            // in this case we should do an update instead of uninstall/install (!)
            final TaskResource second = group.getNextActiveResource();
            if ( second != null &&
                ( second.getState() == ResourceState.IGNORED || second.getState() == ResourceState.INSTALLED || second.getState() == ResourceState.INSTALL ) ) {
                result = new ChangeStateTask(group, ResourceState.UNINSTALLED);
            } else {
                result = new ConfigRemoveTask(group, this.configAdmin);
            }
    } else {
View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

        this.deploymentAdmin = dp;
    }

    @Override
    public void execute(final InstallationContext ctx) {
        final TaskResource tr = this.getResource();

        // get and check symbolic name
        final String symbolicName = (String)tr.getAttribute(DeploymentPackageInstaller.DEPLOYMENTPACKAGE_SYMBOLICMAME);
        if ( symbolicName == null ) {
            logger.error("Resource {} has no symbolic name - ignoring.", tr);
            this.getResourceGroup().setFinishState(ResourceState.IGNORED);
            return;
        }

        // get package if available
        final DeploymentPackage dp = this.deploymentAdmin.getDeploymentPackage(symbolicName);

        if ( tr.getState() == ResourceState.INSTALL) {
            InputStream is = null;
            try {
                is = tr.getInputStream();
                if ( is == null ) {
                    // something went wrong
                    logger.error("Resource {} does not provide an input stream!", tr);
                    this.getResourceGroup().setFinishState(ResourceState.IGNORED);
                } else {
                    final Version newVersion = new Version((String)tr.getAttribute(DeploymentPackageInstaller.DEPLOYMENTPACKAGE_VERSION));
                    // check version
                    if ( dp != null ) {
                        final int compare = dp.getVersion().compareTo(newVersion);
                        if (compare < 0) {
                            // installed version is lower -> update
View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

    /**
     * Check that the required attributes are available.
     * This is just a sanity check
     */
    private SubsystemInfo checkResource(final TaskResourceGroup toActivate) {
        final TaskResource rsrc = toActivate.getActiveResource();

        SubsystemInfo result = null;
        final String symbolicName = (String) rsrc.getAttribute(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME);
        if ( symbolicName == null ) {
            logger.error("Subsystem resource is missing symbolic name {}", rsrc);
        } else {
            final String version = (String)rsrc.getAttribute(SubsystemConstants.SUBSYSTEM_VERSION);
            if ( version == null ) {
                logger.error("Subsystem resource is missing version {}", rsrc);
            } else {
                // check the version for validity
                boolean validVersion = true;
View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

     * @see org.apache.sling.installer.api.tasks.InstallTaskFactory#createTask(org.apache.sling.installer.api.tasks.TaskResourceGroup)
     */
    public InstallTask createTask(final TaskResourceGroup toActivate) {
        final InstallTask result;

        final TaskResource rsrc = toActivate.getActiveResource();
        if ( rsrc.getType().equals(TYPE_SUBSYSTEM) ) {

            // check if the required info is available
            final SubsystemInfo info = checkResource(toActivate);
            if ( info == null ) {
                // ignore as info is missing
                result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
            } else {
                // search a subsystem with the symbolic name
                final ServiceReference<Subsystem> ref = this.getSubsystemReference(info.symbolicName);

                final Subsystem currentSubsystem = (ref != null ? this.bundleContext.getService(ref) : null);
                try {
                    final Version newVersion = new Version(info.version);
                    final Version oldVersion = (ref == null ? null : (Version)ref.getProperty("subsystem.version"));

                    // Install
                    if ( rsrc.getState() == ResourceState.INSTALL ) {
                        if ( oldVersion != null ) {

                            final int compare = oldVersion.compareTo(newVersion);
                            if (compare < 0) {
                                // installed version is lower -> update
                                result = new UpdateSubsystemTask(toActivate, this.bundleContext, ref, this.rootSubsystem);
                            } else if ( compare == 0 && isSnapshot(newVersion) ) {
                                // same version but snapshot -> update
                                result = new UpdateSubsystemTask(toActivate, this.bundleContext, ref, this.rootSubsystem);
                            } else if ( compare == 0 && currentSubsystem != null && currentSubsystem.getState() != State.ACTIVE ) {
                                // try to start the version
                                result = new StartSubsystemTask(toActivate, currentSubsystem);
                            } else {
                                logger.info("{} is not installed, subsystem with same or higher version is already installed: {}", info, newVersion);
                                result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
                            }
                        } else {
                            result = new InstallSubsystemTask(toActivate, this.rootSubsystem);
                        }

                    // Uninstall
                    } else if ( rsrc.getState() == ResourceState.UNINSTALL ) {
                        if ( oldVersion == null ) {
                            logger.error("Nothing to uninstall. {} is currently not installed.", info);
                            result = new ChangeStateTask(toActivate, ResourceState.IGNORED);
                        } else {

View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

        {
            final Hashtable<String, Object> data = new Hashtable<String, Object>();
            data.put("foo", "bar");
            data.put("other", 2);
            final TaskResource r = create(new InstallableResource("configuration:1", null, data, null, null, null));
            assertEquals("No-extension URL with Dictionary creates a CONFIG resource",
                    InstallableResource.TYPE_CONFIG, r.getType());
            final InputStream rs = r.getInputStream();
            assertNull("CONFIG resource does not provide an InputStream", rs);
            final Dictionary<String, Object> d = r.getDictionary();
            assertNotNull("CONFIG resource provides a Dictionary", d);
            assertEquals("CONFIG resource dictionary has two properties", 2, d.size());
            assertNotNull("CONFIG resource has a pid attribute", r.getAttribute(Constants.SERVICE_PID));
        }
    }
View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

    }

    @org.junit.Test public void testBundleManifest() throws Exception {
        final File f = getTestBundle("testbundle-1.0.jar");
        final InstallableResource i = new InstallableResource("test:" + f.getAbsolutePath(), new FileInputStream(f), null, f.getName(), null, null);
        final TaskResource r = create(i);
        assertNotNull("RegisteredResource must have bundle symbolic name", r.getAttribute(Constants.BUNDLE_SYMBOLICNAME));
        assertEquals("RegisteredResource entity ID must match", "bundle:osgi-installer-testbundle", r.getEntityId());
    }
View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

    }

//    @org.junit.Test
    public void testConfigEntity() throws Exception {
        final InstallableResource i = new InstallableResource("test:/foo/someconfig", null, new Hashtable<String, Object>(), null, null, null);
        final TaskResource r = create(i);
        assertNull("RegisteredResource must not have bundle symbolic name", r.getAttribute(Constants.BUNDLE_SYMBOLICNAME));
        assertEquals("RegisteredResource entity ID must match", "config:someconfig", r.getEntityId());
    }
View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

     * @see org.apache.sling.installer.api.tasks.TaskResourceGroup#getActiveResource()
     */
    public TaskResource getActiveResource() {
        if ( !resources.isEmpty() ) {
            Collections.sort(this.resources);
            final TaskResource r = resources.get(0);
            if ( r.getState() == ResourceState.INSTALL
                    || r.getState() == ResourceState.UNINSTALL ) {
                return r;
            }
        }
        return null;
    }
View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

    /**
     * @see org.apache.sling.installer.api.tasks.TaskResourceGroup#setFinishState(org.apache.sling.installer.api.tasks.ResourceState)
     */
    public void setFinishState(ResourceState state) {
        final TaskResource toActivate = getActiveResource();
        if ( toActivate != null ) {
            if ( toActivate.getState() == ResourceState.UNINSTALL
                    && this.resources.size() > 1 ) {

                final TaskResource second = this.getNextActiveResource();
                if ( state == ResourceState.UNINSTALLED ) {
                    // first resource got uninstalled, go back to second
                    if (second.getState() == ResourceState.IGNORED || second.getState() == ResourceState.INSTALLED) {
                        LOGGER.debug("Reactivating for next cycle: {}", second);
                        ((RegisteredResourceImpl)second).setState(ResourceState.INSTALL);
                    }
                } else {
                    // don't install as the first did not get uninstalled
                    if ( second.getState() == ResourceState.INSTALL ) {
                        ((RegisteredResourceImpl)second).setState(ResourceState.IGNORED);
                    }
                    // and now set resource to uninstalled
                    state = ResourceState.UNINSTALLED;
                }
            } else if ( state == ResourceState.INSTALLED ) {
                // make sure that no other resource has state INSTALLED
                if ( this.resources.size() > 1 ) {
                    // to get the second item in the set we have to use an iterator!
                    final Iterator<RegisteredResourceImpl> i = this.resources.iterator();
                    i.next(); // skip first
                    while ( i.hasNext() ) {
                        final TaskResource rsrc = i.next();
                        if ( rsrc.getState() == ResourceState.INSTALLED ) {
                            ((RegisteredResourceImpl)rsrc).setState(ResourceState.INSTALL);
                        }
                    }
                }

            }
            ((RegisteredResourceImpl)toActivate).setState(state);

            if ( state != ResourceState.INSTALLED ) {
                // make sure to remove all install info attributes if the resource is not
                // installed anymore
                toActivate.setAttribute(TaskResource.ATTR_INSTALL_EXCLUDED, null);
                toActivate.setAttribute(TaskResource.ATTR_INSTALL_INFO, null);
            }
            // remove install info attributes on all other resources in the group
            final Iterator<RegisteredResourceImpl> tri = this.resources.iterator();
            tri.next(); // skip first
            while ( tri.hasNext() ) {
                final TaskResource rsrc = tri.next();
                rsrc.setAttribute(TaskResource.ATTR_INSTALL_EXCLUDED, null);
                rsrc.setAttribute(TaskResource.ATTR_INSTALL_INFO, null);
            }

            this.listener.onEvent(new InstallationEvent() {

                public TYPE getType() {
View Full Code Here

Examples of org.apache.sling.installer.api.tasks.TaskResource

        // new one which might have different attributes
        boolean first = true;
        boolean add = true;
        final Iterator<RegisteredResourceImpl> taskIter = this.resources.iterator();
        while ( taskIter.hasNext() ) {
            final TaskResource rr = taskIter.next();
            if ( rr.getURL().equals(r.getURL()) ) {
                if ( RegisteredResourceImpl.isSameResource((RegisteredResourceImpl)rr, r) ) {
                    if ( !rr.getDigest().equals(r.getDigest()) ) {
                        // same resource but different digest, we need to remove the file
                        LOGGER.debug("Cleanup duplicate resource: {}", r);
                        this.cleanup(r);
                    }
                    // same resource, just ignore the new one
                    add = false;
                } else {
                    if ( first && rr.getState() == ResourceState.INSTALLED) {
                        // it's not the same, but the first one is installed, so uninstall
                        ((RegisteredResourceImpl)rr).setState(ResourceState.UNINSTALL);
                    } else {
                        LOGGER.debug("Cleanup obsolete resource: {}", rr);
                        taskIter.remove();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.