[ 
https://issues.apache.org/jira/browse/FELIX-6015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16744892#comment-16744892
 ] 

Cristiano Gavião commented on FELIX-6015:
-----------------------------------------

[~tjwatson] I'm going to close this issue since Resolver is working properly.
 It was my lack of knowledge about Fragment resource, especially System Bundle 
Fragments, sorry.

Just to answer your question: yes I'm starting with a set of resources. The 
requirements for the initial resources are defined as soon as Configurator 
triggers the bootstrap component.  

I'm doing a POC where I have one basic Node docker image containing an OSGi 
container with multiple common compendium bundles. The goal is to setup nodes 
(based on pre-defined capabilities) at bootstrap installing additional bundles 
(then subsystems) based on capabilities defined on the Configurator's json 
returned from a central server.

My custom resolver context is going well now since I bypassed the Region issue 
adding it to my basic container. In order to it to work I had to use my own 
resource, requirement and capability builder when creating the set for both 
getWirings and getMandatoryResources() because equals() and hascode() are a key 
factor.

One last question, while doing some debugging, what I understood is that 
Resolver won't let pass a Fragment whose Host is already resolved. So, as I'm 
including the system bundle in my getWirings(), Resolver is pulling Region out 
of the process, am I right?

Then, it is not possible to install a system bundle after container is running ?
{code:java}
            // Do a sanity check incase the resolve context tries to attach
            // a fragment to an already resolved host capability
            if (HostNamespace.HOST_NAMESPACE.equals(req.getNamespace())) {
                if (rc.getWirings().containsKey(candCap.getResource())) {
                    itCandCap.remove();
                    continue;
                }
            }
{code}
many thanks again

> IndexOutOfBoundsException due a missing HostNamespace.HOST_NAMESPACE
> --------------------------------------------------------------------
>
>                 Key: FELIX-6015
>                 URL: https://issues.apache.org/jira/browse/FELIX-6015
>             Project: Felix
>          Issue Type: Bug
>          Components: Resolver
>    Affects Versions: resolver-1.16.0
>            Reporter: Cristiano Gavião
>            Priority: Major
>
> When creating a custom ResolveContext we need to build a collection of 
> mandatory resources using the method getMandatoryResources().
>  Normally we will create such collection using a custom built Resource 
> containing only a IdentityNamespace.IDENTITY_NAMESPACE capability, because it 
> is enough in order to search for more details of such resource in the 
> installed bundles/fragments or in the registered bundle repositories inside 
> the findProviders() method.
> The error that I'm getting is due the fact that the resolver, most precisely, 
> the Candidates class is using getMandatoryResources() after the 
> getInitialCandidates(session) been executed and inferring that it has a 
> information about fragments that it doesn't have.
> {code:java}
>     public Map<Resource, Resource> getRootHosts()
>     {
>         Map<Resource, Resource> hosts = new LinkedHashMap<Resource, 
> Resource>();
>         for (Resource res : *m_session.getMandatoryResources()*)
>         {
>             addHost(res, hosts);
>         }
>         for (Resource res : m_session.getOptionalResources())
>         {
>             if (isPopulated(res)) {
>                 addHost(res, hosts);
>             }
>         }
>         return hosts;
>     }
> {code}
> {code:java}
>     private void addHost(Resource res, Map<Resource, Resource> hosts) {
>         if (res instanceof WrappedResource)
>         {
>             res = ((WrappedResource) res).getDeclaredResource();
>         }
>         if (!Util.isFragment(res))
>         {
>             hosts.put(res, getWrappedHost(res));
>         } else {
> // The error is happening here:
>             *Requirement hostReq = 
> res.getRequirements(HostNamespace.HOST_NAMESPACE).get(0);*
>             Capability hostCap = getFirstCandidate(hostReq);
>             // If the resource is an already resolved fragment and can not
>             // be attached to new hosts, there will be no matching host,
>             // so ignore this resource
>             if (hostCap != null) {
>                 res = getWrappedHost(hostCap.getResource());
>                 if (res instanceof WrappedResource) {
>                     hosts.put(((WrappedResource) res).getDeclaredResource(), 
> res);
>                 }
>             }
>         }
>     }
> {code}
> Wouldn't be possible to use the processed initial candidates resources 
> instead ?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to