Search in sources :

Example 11 with BundleDefinition

use of lucee.runtime.osgi.OSGiUtil.BundleDefinition in project Lucee by lucee.

the class Admin method doGetBundles.

private void doGetBundles() throws PageException {
    CFMLEngine engine = ConfigWebUtil.getEngine(config);
    BundleCollection coreBundles = engine.getBundleCollection();
    java.util.Collection<BundleDefinition> extBundles = config.getAllExtensionBundleDefintions();
    List<BundleDefinition> bds = OSGiUtil.getBundleDefinitions(engine.getBundleContext());
    Iterator<BundleDefinition> it = bds.iterator();
    BundleDefinition bd;
    Bundle b;
    String str;
    Query qry = new QueryImpl(new Key[] { SYMBOLIC_NAME, KeyConstants._title, KeyConstants._description, KeyConstants._version, VENDOR, KeyConstants._state, PATH, USED_BY, KeyConstants._id, FRAGMENT, HEADERS }, bds.size(), "bundles");
    int row = 0;
    while (it.hasNext()) {
        row++;
        bd = it.next();
        b = bd.getLoadedBundle();
        qry.setAt(SYMBOLIC_NAME, row, bd.getName());
        qry.setAt(KeyConstants._title, row, bd.getName());
        qry.setAt(KeyConstants._version, row, bd.getVersionAsString());
        qry.setAt(USED_BY, row, _usedBy(bd.getName(), bd.getVersion(), coreBundles, extBundles));
        BundleFile bf = null;
        try {
            if (b != null) {
                qry.setAt(PATH, row, b.getLocation());
            } else {
                bf = bd.getBundleFile(false);
                qry.setAt(PATH, row, bf.getFile());
            }
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
        Map<String, Object> headers = null;
        if (b != null) {
            qry.setAt(KeyConstants._version, row, bd.getVersion().toString());
            qry.setAt(KeyConstants._id, row, b.getBundleId());
            qry.setAt(KeyConstants._state, row, OSGiUtil.toState(b.getState(), null));
            qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(b));
            headers = OSGiUtil.getHeaders(b);
        } else {
            qry.setAt(KeyConstants._state, row, "notinstalled");
            try {
                if (b != null) {
                    qry.setAt(KeyConstants._version, row, b.getVersion().toString());
                    qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(b));
                    Dictionary<String, String> dic = b.getHeaders();
                    Enumeration<String> keys = dic.keys();
                    headers = new HashMap<String, Object>();
                    String key;
                    while (keys.hasMoreElements()) {
                        key = keys.nextElement();
                        headers.put(key, dic.get(key));
                    }
                } else {
                    if (bf != null)
                        bf = bd.getBundleFile(false);
                    qry.setAt(KeyConstants._version, row, bf.getVersionAsString());
                    // qry.setAt(KeyConstants._id, row, bf.getBundleId());
                    qry.setAt(FRAGMENT, row, OSGiUtil.isFragment(bf));
                    headers = bf.getHeaders();
                }
            } catch (BundleException e) {
            }
        }
        if (headers != null) {
            Struct h = Caster.toStruct(headers, false);
            qry.setAt(HEADERS, row, h);
            // title
            str = Caster.toString(h.get("Bundle-Title", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Implementation-Title", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Specification-Title", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Bundle-Name", null), null);
            if (!StringUtil.isEmpty(str))
                qry.setAt(KeyConstants._title, row, str);
            // description
            str = Caster.toString(h.get("Bundle-Description", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Implementation-Description", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Specification-Description", null), null);
            if (!StringUtil.isEmpty(str))
                qry.setAt(KeyConstants._description, row, str);
            // Vendor
            str = Caster.toString(h.get("Bundle-Vendor", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Implementation-Vendor", null), null);
            if (StringUtil.isEmpty(str))
                str = Caster.toString(h.get("Specification-Vendor", null), null);
            if (!StringUtil.isEmpty(str))
                qry.setAt(VENDOR, row, str);
        // Specification-Vendor,Bundle-Vendor
        }
    }
    QuerySort.call(pageContext, qry, "title");
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : Query(lucee.runtime.type.Query) Bundle(org.osgi.framework.Bundle) Struct(lucee.runtime.type.Struct) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) BundleCollection(lucee.loader.osgi.BundleCollection) QueryImpl(lucee.runtime.type.QueryImpl) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleException(org.osgi.framework.BundleException) BundleFile(lucee.runtime.osgi.BundleFile)

Example 12 with BundleDefinition

use of lucee.runtime.osgi.OSGiUtil.BundleDefinition in project Lucee by lucee.

the class Admin method _usedBy.

private String _usedBy(String name, Version version, BundleCollection coreBundles, java.util.Collection<BundleDefinition> extBundles) {
    // core
    if (_eq(name, version, coreBundles.core.getSymbolicName(), coreBundles.core.getVersion()))
        return "core";
    Iterator<Bundle> it = coreBundles.getSlaves();
    Bundle b;
    while (it.hasNext()) {
        b = it.next();
        if (_eq(name, version, b.getSymbolicName(), b.getVersion()))
            return "core";
    }
    Iterator<BundleDefinition> itt = extBundles.iterator();
    BundleDefinition bd;
    while (itt.hasNext()) {
        bd = itt.next();
        if (_eq(name, version, bd.getName(), bd.getVersion()))
            return "extension";
    }
    return null;
}
Also used : BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) Bundle(org.osgi.framework.Bundle)

Example 13 with BundleDefinition

use of lucee.runtime.osgi.OSGiUtil.BundleDefinition in project Lucee by lucee.

the class XMLConfigAdmin method removeRHExtension.

/**
 * removes an installed extension from the system
 *
 * @param config
 * @param rhe extension to remove
 * @param replacementRH the extension that will replace this extension, so do not remove parts defined in this extension.
 * @throws PageException
 */
private void removeRHExtension(Config config, RHExtension rhe, RHExtension replacementRH, boolean deleteExtension) throws PageException {
    ConfigImpl ci = ((ConfigImpl) config);
    Log logger = ci.getLog("deploy");
    try {
        // remove the bundles
        BundleDefinition[] candidatesToRemove = OSGiUtil.toBundleDefinitions(rhe.getBundles());
        if (replacementRH != null) {
            // spare bundles used in the new extension as well
            Map<String, BundleDefinition> notRemove = toMap(OSGiUtil.toBundleDefinitions(replacementRH.getBundles()));
            List<BundleDefinition> tmp = new ArrayList<OSGiUtil.BundleDefinition>();
            String key;
            for (int i = 0; i < candidatesToRemove.length; i++) {
                key = candidatesToRemove[i].getName() + "|" + candidatesToRemove[i].getVersionAsString();
                if (notRemove.containsKey(key))
                    continue;
                tmp.add(candidatesToRemove[i]);
            }
            candidatesToRemove = tmp.toArray(new BundleDefinition[tmp.size()]);
        }
        XMLConfigAdmin.cleanBundles(rhe, ci, candidatesToRemove);
        // FLD
        // MUST check if others use one of this fld
        removeFLDs(rhe.getFlds());
        // TLD
        // MUST check if others use one of this tld
        removeTLDs(rhe.getTlds());
        // Tag
        removeTags(rhe.getTags());
        // Functions
        removeFunctions(rhe.getFunctions());
        // Event Gateway
        removeEventGateways(rhe.getEventGateways());
        // context
        // MUST check if others use one of this
        removeContext(config, false, rhe.getContexts());
        // web contextS
        // MUST check if others use one of this
        removeWebContexts(config, false, rhe.getWebContexts());
        // applications
        // MUST check if others use one of this
        removeApplications(config, rhe.getWebContexts());
        // plugins
        // MUST check if others use one of this
        removePlugins(config, rhe.getWebContexts());
        // remove cache handler
        if (!ArrayUtil.isEmpty(rhe.getCacheHandlers())) {
            Iterator<Map<String, String>> itl = rhe.getCacheHandlers().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String _id = map.get("id");
                if (!StringUtil.isEmpty(_id) && cd != null && cd.hasClass()) {
                    _removeCacheHandler(_id);
                // reload=true;
                }
                logger.info("extension", "remove cache handler [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove cache
        if (!ArrayUtil.isEmpty(rhe.getCaches())) {
            Iterator<Map<String, String>> itl = rhe.getCaches().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.isBundle()) {
                    _removeCache(cd);
                // reload=true;
                }
                logger.info("extension", "remove cache handler [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove Search
        if (!ArrayUtil.isEmpty(rhe.getSearchs())) {
            Iterator<Map<String, String>> itl = rhe.getSearchs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _removeSearchEngine();
                // reload=true;
                }
                logger.info("extension", "remove search engine [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove resource
        if (!ArrayUtil.isEmpty(rhe.getResources())) {
            Iterator<Map<String, String>> itl = rhe.getResources().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String scheme = map.get("scheme");
                if (cd != null && cd.hasClass()) {
                    _removeResourceProvider(scheme);
                }
                logger.info("extension", "remove resource [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove AMF
        if (!ArrayUtil.isEmpty(rhe.getAMFs())) {
            Iterator<Map<String, String>> itl = rhe.getAMFs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _removeAMFEngine();
                // reload=true;
                }
                logger.info("extension", "remove search engine [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove orm
        if (!ArrayUtil.isEmpty(rhe.getOrms())) {
            Iterator<Map<String, String>> itl = rhe.getOrms().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _removeORMEngine();
                // reload=true;
                }
                logger.info("extension", "remove orm engine [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove monitor
        if (!ArrayUtil.isEmpty(rhe.getMonitors())) {
            Iterator<Map<String, String>> itl = rhe.getMonitors().iterator();
            Map<String, String> map;
            String name;
            while (itl.hasNext()) {
                map = itl.next();
                // ClassDefinition cd = RHExtension.toClassDefinition(config,map);
                // if(cd.hasClass()) {
                _removeMonitor(map.get("type"), name = map.get("name"));
                // reload=true;
                // }
                logger.info("extension", "remove monitor [" + name + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove jdbc
        if (!ArrayUtil.isEmpty(rhe.getJdbcs())) {
            Iterator<Map<String, String>> itl = rhe.getJdbcs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.isBundle()) {
                    _removeJDBCDriver(cd);
                }
                logger.info("extension", "remove JDBC Driver [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
            }
        }
        // remove mapping
        if (!ArrayUtil.isEmpty(rhe.getMappings())) {
            Iterator<Map<String, String>> itl = rhe.getMappings().iterator();
            Map<String, String> map;
            String virtual;
            while (itl.hasNext()) {
                map = itl.next();
                virtual = map.get("virtual");
                _removeMapping(virtual);
                logger.info("extension", "remove Mapping [" + virtual + "]");
            }
        }
        // remove event-gateway-instance
        if (!ArrayUtil.isEmpty(rhe.getEventGatewayInstances())) {
            Iterator<Map<String, Object>> itl = rhe.getEventGatewayInstances().iterator();
            Map<String, Object> map;
            String id;
            while (itl.hasNext()) {
                map = itl.next();
                id = Caster.toString(map.get("id"), null);
                if (!StringUtil.isEmpty(id)) {
                    _removeGatewayEntry(id);
                    logger.info("extension", "remove event gateway entry [" + id + "]");
                }
            }
        }
        // Loop Files
        ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(rhe.getExtensionFile().getInputStream()));
        String type = ci instanceof ConfigWeb ? "web" : "server";
        try {
            ZipEntry entry;
            String path;
            String fileName;
            Resource tmp;
            while ((entry = zis.getNextEntry()) != null) {
                path = entry.getName();
                fileName = fileName(entry);
                // archives
                if (!entry.isDirectory() && (startsWith(path, type, "archives") || startsWith(path, type, "mappings"))) {
                    String sub = subFolder(entry);
                    logger.log(Log.LEVEL_INFO, "extension", "remove archive " + sub + " registered as a mapping");
                    tmp = SystemUtil.getTempFile(".lar", false);
                    IOUtil.copy(zis, tmp, false);
                    removeArchive(tmp);
                }
                zis.closeEntry();
            }
        } finally {
            IOUtil.closeEL(zis);
        }
        // now we can delete the extension
        if (deleteExtension)
            rhe.getExtensionFile().delete();
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        // failed to uninstall, so we install it again
        try {
            updateRHExtension(config, rhe.getExtensionFile(), true);
        // RHExtension.install(config, rhe.getExtensionFile());
        } catch (Throwable t2) {
            ExceptionUtil.rethrowIfNecessary(t2);
        }
        throw Caster.toPageException(t);
    }
}
Also used : Log(lucee.commons.io.log.Log) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) ClassDefinition(lucee.runtime.db.ClassDefinition) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) OSGiUtil(lucee.runtime.osgi.OSGiUtil) ZipInputStream(java.util.zip.ZipInputStream) CreateObject(lucee.runtime.functions.other.CreateObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with BundleDefinition

use of lucee.runtime.osgi.OSGiUtil.BundleDefinition in project Lucee by lucee.

the class XMLConfigAdmin method cleanBundles.

public static void cleanBundles(RHExtension rhe, ConfigImpl config, BundleDefinition[] candiatesToRemove) throws BundleException, ApplicationException, IOException {
    if (ArrayUtil.isEmpty(candiatesToRemove))
        return;
    BundleCollection coreBundles = ConfigWebUtil.getEngine(config).getBundleCollection();
    // core master
    _cleanBundles(candiatesToRemove, coreBundles.core.getSymbolicName(), coreBundles.core.getVersion());
    // core slaves
    Iterator<Bundle> it = coreBundles.getSlaves();
    Bundle b;
    while (it.hasNext()) {
        b = it.next();
        _cleanBundles(candiatesToRemove, b.getSymbolicName(), b.getVersion());
    }
    // all extension
    Iterator<RHExtension> itt = config.getAllRHExtensions().iterator();
    RHExtension _rhe;
    while (itt.hasNext()) {
        _rhe = itt.next();
        if (rhe != null && rhe.equals(_rhe))
            continue;
        BundleInfo[] bundles = _rhe.getBundles();
        for (BundleInfo bi : bundles) {
            _cleanBundles(candiatesToRemove, bi.getSymbolicName(), bi.getVersion());
        }
    }
    // now we only have BundlesDefs in the array no longer used
    for (BundleDefinition ctr : candiatesToRemove) {
        if (ctr != null)
            OSGiUtil.removeLocalBundleSilently(ctr.getName(), ctr.getVersion(), true);
    }
}
Also used : BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) BundleCollection(lucee.loader.osgi.BundleCollection) RHExtension(lucee.runtime.extension.RHExtension) BundleInfo(lucee.runtime.osgi.BundleInfo) Bundle(org.osgi.framework.Bundle)

Example 15 with BundleDefinition

use of lucee.runtime.osgi.OSGiUtil.BundleDefinition in project Lucee by lucee.

the class ConfigImpl method getExtensionBundleDefintions.

public Collection<BundleDefinition> getExtensionBundleDefintions() {
    if (this.extensionBundles == null) {
        RHExtension[] rhes = getRHExtensions();
        Map<String, BundleDefinition> extensionBundles = new HashMap<String, BundleDefinition>();
        for (RHExtension rhe : rhes) {
            BundleInfo[] bis;
            try {
                bis = rhe.getBundles();
            } catch (Exception e) {
                continue;
            }
            if (bis != null)
                for (BundleInfo bi : bis) {
                    extensionBundles.put(bi.getSymbolicName() + "|" + bi.getVersionAsString(), bi.toBundleDefinition());
                }
        }
        this.extensionBundles = extensionBundles;
    }
    return extensionBundles.values();
}
Also used : BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) RHExtension(lucee.runtime.extension.RHExtension) BundleInfo(lucee.runtime.osgi.BundleInfo) HashMap(java.util.HashMap) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) IOException(java.io.IOException) DatabaseException(lucee.runtime.exp.DatabaseException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) TemplateException(lucee.runtime.exp.TemplateException) ClassException(lucee.commons.lang.ClassException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Aggregations

BundleDefinition (lucee.runtime.osgi.OSGiUtil.BundleDefinition)15 HashMap (java.util.HashMap)4 BundleFile (lucee.runtime.osgi.BundleFile)4 Struct (lucee.runtime.type.Struct)4 Bundle (org.osgi.framework.Bundle)4 BundleException (org.osgi.framework.BundleException)4 IOException (java.io.IOException)3 Resource (lucee.commons.io.res.Resource)3 BundleCollection (lucee.loader.osgi.BundleCollection)3 RHExtension (lucee.runtime.extension.RHExtension)3 BundleInfo (lucee.runtime.osgi.BundleInfo)3 StructImpl (lucee.runtime.type.StructImpl)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 Log (lucee.commons.io.log.Log)2 CFMLEngine (lucee.loader.engine.CFMLEngine)2 ClassDefinition (lucee.runtime.db.ClassDefinition)2 ApplicationException (lucee.runtime.exp.ApplicationException)2