[
https://issues.apache.org/jira/browse/FELIX-4352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13858724#comment-13858724
]
Pierre De Rop commented on FELIX-4352:
--------------------------------------
Hi Jago,
I committed the Circular.patch in rv 1554191.
But I think there is an issue, which was already present before the
Circular.patch was committed: it concerns configuration dependency.
Consider the following usecase: A -> B -> C with pid="C" and the configuration
for pid="C" is unavailable.
The code for A is the following:
{code}
package org.apache.felix.dependencymanager.test.wtf;
import org.apache.felix.dm.annotation.api.Component;
import org.apache.felix.dm.annotation.api.ServiceDependency;
@Component
public class A
{
@ServiceDependency
B b;
}
{code}
The code for B is the following:
{code}
package org.apache.felix.dependencymanager.test.wtf;
import org.apache.felix.dm.annotation.api.Component;
import org.apache.felix.dm.annotation.api.ServiceDependency;
@Component(provides={B.class})
public class B {
@ServiceDependency
C c;
}
{code}
The code for C is the following:
{code}
package org.apache.felix.dependencymanager.test.wtf;
import java.util.Dictionary;
import org.apache.felix.dm.annotation.api.Component;
import org.apache.felix.dm.annotation.api.ConfigurationDependency;
@Component(provides={C.class})
public class C {
@ConfigurationDependency // pid is by default
"org.apache.felix.dependencymanager.test.wtf.C"
void updated(Dictionary conf) {
}
}
{code}
Then when I type "dm wtf", I'm getting this:
{code}
3 missing dependencies found.
-------------------------------------
Circular dependency found:
* -> org.apache.felix.dependencymanager.test.wtf.C ->
org.apache.felix.dependencymanager.test.wtf.C ->
org.apache.felix.dependencymanager.test.wtf.C
Circular dependency found:
* -> org.apache.felix.dependencymanager.test.wtf.C ->
org.apache.felix.dependencymanager.test.wtf.C
Circular dependency found:
* -> org.apache.felix.dependencymanager.test.wtf.B ->
org.apache.felix.dependencymanager.test.wtf.C ->
org.apache.felix.dependencymanager.test.wtf.C ->
org.apache.felix.dependencymanager.test.wtf.C
The following service(s) are missing:
* org.apache.felix.dependencymanager.test.wtf.C and needs:
org.apache.felix.dependencymanager.test.wtf.C
to work
{code}
The problem is I think located in the getRoot method:
{code}
private ComponentId getRoot(List<ComponentDeclaration> downComponents,
ComponentDeclaration c, List<ComponentId> backTrace) {
ComponentDependencyDeclaration[] componentDependencies =
c.getComponentDependencies();
int downDeps = 0;
for (ComponentDependencyDeclaration cdd : componentDependencies) {
if (cdd.getState() ==
ComponentDependencyDeclaration.STATE_UNAVAILABLE_REQUIRED) {
downDeps++;
ComponentDeclaration component =
getComponentDeclaration(cdd.getName(), downComponents);
if (component == null) {
String contextName = null;
if (CONFIGURATION.equals(cdd.getType())) {
contextName =
c.getBundleContext().getBundle().getSymbolicName();
}
return new ComponentId(cdd.getName(), cdd.getType(),
contextName);
}
// Detect circular dependency
...
{code}
In the code above, when we are iterating on the "C" component, we do
getComponentDeclaration(cdd.getName(), downComponents); but cdd.getName()
returns the pid "org.apache.felix.dependencymanager.test.wtf.C" of the
configuration dependency. However, this also corresponds to "C" component name,
which results in a wrongly detected circular dependency.
I think that the following patch is correct (let me know if you agree with it
so I can commit it), unless I'm missing something ?
Here is the patch:
{code}
private ComponentId getRoot(List<ComponentDeclaration> downComponents,
ComponentDeclaration c, List<ComponentId> backTrace) {
ComponentDependencyDeclaration[] componentDependencies =
c.getComponentDependencies();
int downDeps = 0;
for (ComponentDependencyDeclaration cdd : componentDependencies) {
if (cdd.getState() ==
ComponentDependencyDeclaration.STATE_UNAVAILABLE_REQUIRED) {
downDeps++;
// Detect missing configuration dependency
if (CONFIGURATION.equals(cdd.getType())) {
String contextName =
c.getBundleContext().getBundle().getSymbolicName();
return new ComponentId(cdd.getName(), cdd.getType(),
contextName);
}
// Detect if the missing dependency is a root cause failure
ComponentDeclaration component =
getComponentDeclaration(cdd.getName(), downComponents);
if (component == null) {
return new ComponentId(cdd.getName(), cdd.getType(), null);
}
// Detect circular dependency
...
{code}
I attached it to Circular.patch.pierre.
with this patch, then the "wtf" command displays:
{code}
3 missing dependencies found.
-------------------------------------
The following configuration(s) are missing:
* org.apache.felix.dependencymanager.test.wtf.C for bundle
org.apache.felix.dependencymanager.test.wtf
{code}
let me know what you think.
thanks.
/Pierre
> Extend shell command to give better insight in where the problem is
> -------------------------------------------------------------------
>
> Key: FELIX-4352
> URL: https://issues.apache.org/jira/browse/FELIX-4352
> Project: Felix
> Issue Type: Improvement
> Components: Dependency Manager
> Affects Versions: dependencymanager.shell-2.0.1
> Reporter: Jago de Vreede
> Assignee: Pierre De Rop
> Attachments: Circular.patch, Circular.patch.pierre, shell wtf
> 1.3.patch, shell wtf 1.5.patch
>
>
> 'dm notavail' is a command that we use regularly but it can become hard to
> figure out where the actual problem is.
> This patch allows you to find the root cause very quickly example output:
> 60 missing dependencies found.
> -------------------------------------
> Please note that the following bundles are in the RESOLVED state:
> * [65] com.example.mongo
> The following service(s) are missing:
> * com.example.mongo.MongoService is not found in the service registry
> So the shell command tells you that you have a resolved bundle that could
> trigger you where the problem might be. The command can also tell you if a
> configuration is missing as a root cause.
> The shell can be executed by dm wtf
> wtf stands for Where is The Failure
> This issue has 2 patches:
> 'shell wtf 1.3.patch' and contains a patch that works for java 1.3 and the
> current shell.
> 'shell wtf 1.5.patch' and lifts the shell project to java 1.5 (as I
> understand this is something you have planned) and contains java 1.5 code and
> unittests backed by mockito to mock certain stuff.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)