Package org.osgi.service.deploymentadmin

Examples of org.osgi.service.deploymentadmin.DeploymentException


        BundleInfo[] infos = target.getBundleInfos();
        Map storageAreas = m_getStorageAreaCommand.getStorageAreas();
        for (int i = 0; i < infos.length; i++) {
            if (isCancelled()) {
                throw new DeploymentException(DeploymentException.CODE_CANCELLED);
            }

            String symbolicName = infos[i].getSymbolicName();
            Bundle bundle = target.getBundle(symbolicName);
            if (bundle != null) {
View Full Code Here


            }
            catch (ResourceProcessorException e) {
                session.getLog().log(LogService.LOG_ERROR, "Preparing commit for resource processor failed", e);
                // Check what error code we got...
                if (e.getCode() == ResourceProcessorException.CODE_PREPARE) {
                    throw new DeploymentException(DeploymentException.CODE_COMMIT_ERROR, "Preparing commit for resource processor failed!", e);
                }
                throw new DeploymentException(e.getCode(), "Preparing commit for resource processor failed!", e);
            }
            catch (Exception e) {
                session.getLog().log(LogService.LOG_ERROR, "Preparing commit for resource processor failed", e);
                throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Preparing commit for resource processor failed", e);
            }
        }
        for (ListIterator i = m_processors.listIterator(m_processors.size()); i.hasPrevious();) {
            ResourceProcessor processor = (ResourceProcessor) i.previous();
            try {
View Full Code Here

            throw new IllegalArgumentException("Inputstream may not be null");
        }

        try {
            if (!m_semaphore.tryAcquire(TIMEOUT)) {
                throw new DeploymentException(DeploymentException.CODE_TIMEOUT, "Timeout exceeded while waiting to install deployment package (" + TIMEOUT + " ms)");
            }
        }
        catch (InterruptedException ie) {
            throw new DeploymentException(DeploymentException.CODE_TIMEOUT, "Thread interrupted");
        }

        File tempPackage = null;
        StreamDeploymentPackage source = null;
        AbstractDeploymentPackage target = null;
        boolean succeeded = false;

        try {
            JarInputStream jarInput = null;
            File tempIndex = null;
            File tempContents = null;
            try {
                File tempDir = m_context.getDataFile(TEMP_DIR);
                tempDir.mkdirs();
                tempPackage = File.createTempFile(TEMP_PREFIX, TEMP_POSTFIX, tempDir);
                tempPackage.delete();
                tempPackage.mkdirs();
                tempIndex = new File(tempPackage, PACKAGEINDEX_FILE);
                tempContents = new File(tempPackage, PACKAGECONTENTS_DIR);
                tempContents.mkdirs();
                input = new ExplodingOutputtingInputStream(input, tempIndex, tempContents);
            }
            catch (IOException e) {
                m_log.log(LogService.LOG_ERROR, "Error writing package to disk", e);
                throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Error writing package to disk", e);
            }

            try {
                jarInput = new JarInputStream(input);
               
                if (jarInput.getManifest() == null) {
                    m_log.log(LogService.LOG_ERROR, "Stream does not contain a valid deployment package: missing manifest!");
                    throw new DeploymentException(DeploymentException.CODE_MISSING_HEADER, "No manifest present in deployment package!");
                }
            }
            catch (IOException e) {
                m_log.log(LogService.LOG_ERROR, "Stream does not contain a valid Jar", e);
                throw new DeploymentException(DeploymentException.CODE_NOT_A_JAR, "Stream does not contain a valid Jar", e);
            }

            source = new StreamDeploymentPackage(jarInput, m_context, this);
            String dpSymbolicName = source.getName();
           
            target = getExistingOrEmptyDeploymentPackage(dpSymbolicName);
           
            // Fire an event that we're about to install a new package
            sendStartedEvent(source, target);

            // Assert that:
            //   the source has no bundles that exists in other packages than the target.
            verifyNoResourcesShared(source, target);
           
            if (source.isFixPackage()) {
                // Assert that:
                //   a. the version of the target matches the required fix-package range;
                //   b. all missing source bundles are present in the target.
                verifyFixPackage(source, target);
            } else {
                // Assert that:
                //   no missing resources or bundles are declared.
                verifySourcePackage(source);
            }

            // To keep track whether or not we're masking an exception during the close of the input stream...
            boolean installFailed = false;
           
            try {
                m_session = new DeploymentSessionImpl(source, target, createInstallCommandChain(), this);
                m_session.call(false /* ignoreExceptions */);
            }
            catch (DeploymentException de) {
                installFailed = true;
                throw de;
            } finally {
                try {
                    // make sure we've read until the end-of-stream, so the explodingoutput-wrapper can process all bytes
                    Utils.readUntilEndOfStream(input);

                    // note that calling close on this stream will wait until asynchronous processing is done
                    input.close();
                }
                catch (IOException e) {
                    m_log.log(LogService.LOG_ERROR, "Could not close stream properly", e);
                    // Do not mask out any originally thrown exceptions...
                    if (!installFailed) {
                        throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not close stream properly", e);
                    }
                }
            }

            String dpInstallBaseDirectory = PACKAGE_DIR + File.separator + dpSymbolicName;

            File targetContents = m_context.getDataFile(dpInstallBaseDirectory + File.separator + PACKAGECONTENTS_DIR);
            File targetIndex = m_context.getDataFile(dpInstallBaseDirectory + File.separator + PACKAGEINDEX_FILE);

            if (source.isFixPackage()) {
                try {
                    Utils.merge(targetIndex, targetContents, tempIndex, tempContents);
                }
                catch (IOException e) {
                    m_log.log(LogService.LOG_ERROR, "Could not merge source fix package with target deployment package", e);
                    throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not merge source fix package with target deployment package", e);
                }
            }
            else {
                File targetPackage = m_context.getDataFile(dpInstallBaseDirectory);
                targetPackage.mkdirs();
                if (!Utils.replace(targetPackage, tempPackage)) {
                  throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not replace " + targetPackage + " with " + tempPackage);
                }
            }
           
            FileDeploymentPackage fileDeploymentPackage = null;
            try {
                fileDeploymentPackage = new FileDeploymentPackage(targetIndex, targetContents, m_context, this);
                m_packages.put(dpSymbolicName, fileDeploymentPackage);
            }
            catch (IOException e) {
                m_log.log(LogService.LOG_ERROR, "Could not create installed deployment package from disk", e);
                throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not create installed deployment package from disk", e);
            }

            // Since we're here, it means everything went OK, so we might as well raise our success flag...
            succeeded = true;

View Full Code Here

     * Called by dependency manager upon start of this component.
     */
    public void start() throws DeploymentException {
        File packageDir = m_context.getDataFile(PACKAGE_DIR);
        if (packageDir == null) {
            throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not create directories needed for deployment package persistence");
        } else {
            packageDir.mkdirs();
            File[] packages = packageDir.listFiles();
            for(int i = 0; i < packages.length; i++) {
                if (packages[i].isDirectory()) {
View Full Code Here

     * @throws DeploymentException in case the uninstall failed.
     */
    public void uninstallDeploymentPackage(DeploymentPackage dp, boolean forced) throws DeploymentException {
        try {
            if (!m_semaphore.tryAcquire(TIMEOUT)) {
                throw new DeploymentException(DeploymentException.CODE_TIMEOUT, "Timeout exceeded while waiting to uninstall deployment package (" + TIMEOUT + " ms)");
            }
        }
        catch (InterruptedException ie) {
            throw new DeploymentException(DeploymentException.CODE_TIMEOUT, "Thread interrupted");
        }
       
        boolean succeeded = false;
        AbstractDeploymentPackage source = AbstractDeploymentPackage.EMPTY_PACKAGE;
        AbstractDeploymentPackage target = (AbstractDeploymentPackage) dp;

        // Notify listeners that we've about to uninstall the deployment package...
        sendUninstallEvent(source, target);

        try {
            try {
                m_session = new DeploymentSessionImpl(source, target, createUninstallCommandChain(), this);
                m_session.call(forced /* ignoreExceptions */);
            }
            catch (DeploymentException de) {
                throw de;
            }

            File targetPackage = m_context.getDataFile(PACKAGE_DIR + File.separator + source.getName());
            if (!Utils.delete(targetPackage, true)) {
              m_log.log(LogService.LOG_ERROR, "Could not delete deployment package from disk");
              throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not delete deployment package from disk");
            }
           
            m_packages.remove(dp.getName());

            succeeded = true;
View Full Code Here

        boolean newPackage = target.isNew();

        // Verify whether the target package exists, and if so, falls in the requested fix-package range...
        if (newPackage || (!source.getVersionRange().isInRange(target.getVersion()))) {
            m_log.log(LogService.LOG_ERROR, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
            throw new DeploymentException(DeploymentException.CODE_MISSING_FIXPACK_TARGET, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
        }

        // Verify whether all missing bundles are available in the target package...
        BundleInfoImpl[] bundleInfos = source.getBundleInfoImpls();
        for (int i = 0; i < bundleInfos.length; i++) {
            if (bundleInfos[i].isMissing()) {
                // Check whether the bundle exists in the target package...
                BundleInfoImpl targetBundleInfo = target.getBundleInfoByPath(bundleInfos[i].getPath());
                if (targetBundleInfo == null) {
                    m_log.log(LogService.LOG_ERROR, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
                    throw new DeploymentException(DeploymentException.CODE_MISSING_BUNDLE, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
                }
            }
        }

        // Verify whether all missing resources are available in the target package...
        ResourceInfoImpl[] resourceInfos = source.getResourceInfos();
        for (int i = 0; i < resourceInfos.length; i++) {
            if (resourceInfos[i].isMissing()) {
                // Check whether the resource exists in the target package...
                ResourceInfoImpl targetResourceInfo = target.getResourceInfoByPath(resourceInfos[i].getPath());
                if (targetResourceInfo == null) {
                    m_log.log(LogService.LOG_ERROR, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
                    throw new DeploymentException(DeploymentException.CODE_MISSING_RESOURCE, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
                }
            }
        }
    }
View Full Code Here

            DeploymentPackage targetPackage = getDeploymentPackageContainingBundleWithSymbolicName(symbolicName);
            // If found, it should match the given target DP; not found is also ok...
            if ((targetPackage != null) && !targetPackage.equals(target)) {
                m_log.log(LogService.LOG_ERROR, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
                throw new DeploymentException(DeploymentException.CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
            }
           
            if (targetPackage == null) {
                // Maybe the bundle is installed without deployment admin...
                for (int j = 0; j < foreignBundles.length; j++) {
                    if (symbolicName.equals(foreignBundles[j].getSymbolicName()) && version.equals(foreignBundles[j].getVersion())) {
                        m_log.log(LogService.LOG_ERROR, "Bundle '" + symbolicName + "/" + version + " already present!");
                        throw new DeploymentException(DeploymentException.CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present!");
                    }
                }
            }
        }
       
View Full Code Here

     * @param manifest The manifest file to be used as deployment manifest
     * @throws DeploymentException If the specified manifest is not a valid deployment package manifest file.
     */
    public DeploymentPackageManifest(Manifest manifest) throws DeploymentException {
        if ((manifest == null) || (manifest.getMainAttributes() == null)) {
            throw new DeploymentException(DeploymentException.CODE_BAD_HEADER);
        }
        m_manifest = manifest;

        Attributes mainAttributes = m_manifest.getMainAttributes();

        // TODO: verify symbolic name and entry-names for valid format/chars
        m_symbolicName = getNonNullHeader(mainAttributes.getValue(Constants.DEPLOYMENTPACKAGE_SYMBOLICMAME));

        String version = getNonNullHeader(mainAttributes.getValue(Constants.DEPLOYMENTPACKAGE_VERSION));
        try {
            m_version = new Version(version);
        } catch (IllegalArgumentException e) {
            throw new DeploymentException(DeploymentException.CODE_BAD_HEADER);
        }

        String fixPackage = mainAttributes.getValue(Constants.DEPLOYMENTPACKAGE_FIXPACK);
        if (fixPackage != null) {
            try {
                m_fixPackage = VersionRange.parse(fixPackage);
            }
            catch (IllegalArgumentException iae) {
                throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Invalid version range for header: " + Constants.DEPLOYMENTPACKAGE_FIXPACK);
            }
        } else {
            m_fixPackage = null;
        }

View Full Code Here

    private void processEntry(String key, Attributes attributes, boolean isFixPack) throws DeploymentException {
        if (BundleInfoImpl.isBundleResource(attributes)) {
            BundleInfoImpl bundleInfo = new BundleInfoImpl(key, attributes);
            if (bundleInfo.isMissing() && !isFixPack) {
                throw new DeploymentException(DeploymentException.CODE_BAD_HEADER, "Header '" + Constants.DEPLOYMENTPACKAGE_MISSING + "' for manifest " +
                    "entry '" + key + "' may only be 'true' if " + Constants.DEPLOYMENTPACKAGE_FIXPACK + " manifest header is 'true'");
            }
            m_bundleInfos.add(bundleInfo);
        } else {
            m_resourceInfos.add(new ResourceInfoImpl(key, attributes));
View Full Code Here

        }
    }

    private String getNonNullHeader(String header) throws DeploymentException {
        if (header == null) {
            throw new DeploymentException(DeploymentException.CODE_MISSING_HEADER);
        } else if(header.trim().equals("")) {
            throw new DeploymentException(DeploymentException.CODE_BAD_HEADER);
        }
        return header;
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.deploymentadmin.DeploymentException

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.