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

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


        this.subsystemReference = ref;
    }

    @Override
    public void execute(final InstallationContext ctx) {
        final TaskResource tr = this.getResource();
        ctx.log("Uninstalling subsystem from {}", tr);

        Subsystem subsystem = null;
        try {
            subsystem = this.bundleContext.getService(this.subsystemReference);
View Full Code Here


        this.subsystem = system;
    }

    @Override
    public void execute(final InstallationContext ctx) {
        final TaskResource tr = this.getResource();
        ctx.log("Starting subsystem from {}", tr);

        this.subsystem.start();
        ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.INSTALLED));
        ctx.log("Started subsystem {}", this.subsystem);
View Full Code Here

        this.rootSubsystem = rootSubsystem;
    }

    @Override
    public void execute(final InstallationContext ctx) {
        final TaskResource tr = this.getResource();
        ctx.log("Updating subsystem from {}", tr);

        Subsystem subsystem = null;
        try {
            subsystem = this.bundleContext.getService(this.subsystemReference);
View Full Code Here

        this.rootSubsystem = rootSubsystem;
    }

    @Override
    public void execute(final InstallationContext ctx) {
        final TaskResource tr = this.getResource();
        ctx.log("Installing new subsystem from {}", tr);

        try {
            final Subsystem sub = this.rootSubsystem.install(tr.getURL(), tr.getInputStream());
            ctx.addTaskToCurrentCycle(new StartSubsystemTask(this.getResourceGroup(), sub));
            ctx.log("Installed new subsystem {}", sub);
        } catch (final IOException e) {
            ctx.log("Unable to install subsystem {} : {}", tr, e);
            ctx.addTaskToCurrentCycle(new ChangeStateTask(this.getResourceGroup(), ResourceState.IGNORED));
View Full Code Here

     * 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

        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

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

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

        {
            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

    }

    @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

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.