Package org.apache.sling.installer.api.tasks

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


     * @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

    /**
     * @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

        // 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

    public void remove(final String url) {
        Collections.sort(this.resources);
        final Iterator<RegisteredResourceImpl> i = resources.iterator();
        boolean first = true;
        while ( i.hasNext() ) {
            final TaskResource r = i.next();
            if ( r.getURL().equals(url) ) {
                if ( first && (r.getState() == ResourceState.INSTALLED
                        || r.getState() == ResourceState.INSTALL)) {
                    LOGGER.debug("Marking for uninstalling: {}", r);
                    ((RegisteredResourceImpl)r).setState(ResourceState.UNINSTALL);
                } else {
                    LOGGER.debug("Removing unused: {}", r);
                    i.remove();
View Full Code Here

     *
   * @see org.apache.sling.installer.api.tasks.InstallTaskFactory#createTask(org.apache.sling.installer.api.tasks.TaskResourceGroup)
   */
  public InstallTask createTask(final TaskResourceGroup resourceList) {
      // quick check of the resource type.
      final TaskResource toActivate = resourceList.getActiveResource();
      if ( toActivate.getType().equals(PersistentResourceList.RESTART_ACTIVE_BUNDLES_TYPE) ) {
          return new RestartActiveBundlesTask(resourceList, this.taskSupport);
      }
      if ( !toActivate.getType().equals(InstallableResource.TYPE_BUNDLE) ) {
          return null;
      }

      // check if symbolic name and version is provided in the attributes
        if ( toActivate.getAttribute(Constants.BUNDLE_SYMBOLICNAME) == null ) {
            final Util.BundleHeaders headers = Util.readBundleHeaders(toActivate, logger);
            if ( headers == null ) {
                logger.info("Resource of type bundle {} is not really a bundle - manifest entries are missing.", toActivate);
                return new ChangeStateTask(resourceList, ResourceState.IGNORED);
            }
            toActivate.setAttribute(Constants.BUNDLE_SYMBOLICNAME, headers.symbolicName);
            toActivate.setAttribute(Constants.BUNDLE_VERSION, headers.version);
            if ( headers.activationPolicy != null ) {
                toActivate.setAttribute(Constants.BUNDLE_ACTIVATIONPOLICY, headers.activationPolicy);
            }
        }
        final String symbolicName = (String)toActivate.getAttribute(Constants.BUNDLE_SYMBOLICNAME);
        final boolean isInstallerCoreBundle = this.bundleContext.getBundle().getSymbolicName().equals(symbolicName);

        // Uninstall
        final InstallTask result;
    if (toActivate.getState() == ResourceState.UNINSTALL) {
            // find the info with the exact version
            final BundleInfo info = this.getBundleInfo(
                    symbolicName,
                    (String)toActivate.getAttribute(Constants.BUNDLE_VERSION));
        // Remove corresponding bundle if present and if we installed it
        if ( info != null ) {
              // 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 = resourceList.getNextActiveResource();
              if ( second != null &&
                  ( second.getState() == ResourceState.IGNORED || second.getState() == ResourceState.INSTALLED || second.getState() == ResourceState.INSTALL ) ) {
                    second.setAttribute(FORCE_INSTALL_VERSION, info.version.toString());
                    BundleUtil.clearBundleStart(second);
                    logger.debug("Detected downgrade of bundle {}", symbolicName);
                    result = new ChangeStateTask(resourceList, ResourceState.UNINSTALLED);
              } else {
                  // prevent uninstalling the installer itself!
View Full Code Here

                // we first check for update
                boolean updated = false;
                if ( erl != null && erl.getFirstResource() != null ) {
                    // check digest for dictionaries
                    final TaskResource tr = erl.getFirstResource();
                    if ( dict != null ) {
                        final String digest = FileDataStore.computeDigest(dict);
                        if ( tr.getState() == ResourceState.INSTALLED && tr.getDigest().equals(digest) ) {
                            logger.debug("Resource did not change {}", key);
                            return;
                        }
                    }
                    final UpdateHandler handler = this.findHandler(tr.getScheme());
                    if ( handler == null ) {
                        logger.debug("No handler found to handle update of resource with scheme {}", tr.getScheme());
                    } else {
                        final InputStream localIS = data.getInputStream();
                        try {
                            final UpdateResult result = (localIS == null ? handler.handleUpdate(resourceType, entityId, tr.getURL(), data.getDictionary(), attributes)
                                    : handler.handleUpdate(resourceType, entityId, tr.getURL(), localIS, attributes));
                            if ( result != null ) {
                                if ( !result.getURL().equals(tr.getURL()) && !result.getResourceIsMoved() ) {
                                    // resource has been added!
                                    final InternalResource internalResource = new InternalResource(result.getScheme(),
                                            result.getResourceId(),
                                            null,
                                            data.getDictionary(),
View Full Code Here

            logger.debug("Removed {} : {}", key, erl);
            // if this is not registered at all, we can simply ignore this
            if ( erl != null ) {
                resourceId = erl.getResourceId();
                key = resourceType + ':' + resourceId;
                final TaskResource tr = erl.getFirstResource();
                if ( tr != null ) {
                    if ( tr.getState() == ResourceState.IGNORED ) {
                        // if it has been ignored before, we activate it now again!
                        ((RegisteredResourceImpl)tr).setState(ResourceState.INSTALL);
                        this.persistentList.save();
                    } else if ( tr.getState() == ResourceState.UNINSTALLED ) {
                        // it has already been removed - nothing do to
                    } else {
                        final UpdateHandler handler = this.findHandler(tr.getScheme());
                        if ( handler == null ) {
                            // set to ignored
                            logger.debug("No handler found to handle remove of resource with scheme {}", tr.getScheme());
                            ((RegisteredResourceImpl)tr).setState(ResourceState.IGNORED);
                        } else {
                            // we don't need to check the result, we just check if a result is returned
                            if ( handler.handleRemoval(resourceType, resourceId, tr.getURL()) != null ) {
                                // We first set the state of the resource to uninstall to make setFinishState work in all cases
                                ((RegisteredResourceImpl)tr).setState(ResourceState.UNINSTALL);
                                erl.setFinishState(ResourceState.UNINSTALLED);
                                erl.compact();
                            } else {
                                // set to ignored
                                logger.debug("No handler found to handle remove of resource with scheme {}", tr.getScheme());
                                ((RegisteredResourceImpl)tr).setState(ResourceState.IGNORED);
                            }
                        }
                        this.persistentList.save();
                    }
View Full Code Here

            if ( event.getType() == InstallationEvent.TYPE.STARTED ) {
                logger.debug("onEvent(STARTED).");
            } else if ( event.getType() == InstallationEvent.TYPE.SUSPENDED ) {
                logger.debug("onEvent(SUSPENDED).");
            } else {
                final TaskResource src = (TaskResource)event.getSource();
                logger.debug("onEvent(event.getSource(): {})", src);
            }
        }
        final Object[] listeners = this.tracker.getServices();
        if ( listeners != null ) {
View Full Code Here

        }
        return map;
    }
   
    public InstallTask createTask(TaskResourceGroup taskResourceGroup) {
        TaskResource toActivate = taskResourceGroup.getActiveResource();
        if (SOLR_INDEX_ARCHIVE_RESOURCE_TYPE.equals(toActivate.getType())) {
            lock.readLock().lock();
            try {
                if (toActivate.getState() == ResourceState.UNINSTALL) {
                    log.debug(" ... create IndexRemoveTask with servers {}",activeServers);
                    return new IndexRemoveTask(taskResourceGroup, activeServers);
                } else {
                    log.debug(" ... create IndexInstallTask with servers {}",activeServers);
                    return new IndexInstallTask(taskResourceGroup, activeServers);
View Full Code Here

TOP

Related Classes of org.apache.sling.installer.api.tasks.TaskResource

Copyright © 2018 www.massapicom. 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.