X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdependencyresolver%2FDependencyResolverImpl.java;h=925a57b044f44f87c31bf1aa9e8d60d7ebf210c9;hp=ecb02a1c4f1e1acc17076b3e17ee2791211dedc1;hb=c541f7868e6e2d654b8080b5426bb12a39bddf11;hpb=397cc9012f67596848019ca7874f3a303523b7e6 diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java index ecb02a1c4f..925a57b044 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java @@ -7,25 +7,25 @@ */ package org.opendaylight.controller.config.manager.impl.dependencyresolver; -import static java.lang.String.format; - -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Set; - -import javax.annotation.concurrent.GuardedBy; -import javax.management.ObjectName; - import org.opendaylight.controller.config.api.DependencyResolver; import org.opendaylight.controller.config.api.JmxAttribute; import org.opendaylight.controller.config.api.JmxAttributeValidationException; import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry; import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; import org.opendaylight.controller.config.manager.impl.TransactionStatus; import org.opendaylight.controller.config.spi.Module; import org.opendaylight.controller.config.spi.ModuleFactory; +import javax.annotation.concurrent.GuardedBy; +import javax.management.ObjectName; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; + +import static java.lang.String.format; + /** * Protect {@link org.opendaylight.controller.config.spi.Module#getInstance()} * by creating proxy that would throw exception if those methods are called @@ -38,25 +38,26 @@ final class DependencyResolverImpl implements DependencyResolver, private final TransactionStatus transactionStatus; @GuardedBy("this") private final Set dependencies = new HashSet<>(); + private final ServiceReferenceReadableRegistry readableRegistry; DependencyResolverImpl(ModuleIdentifier currentModule, - TransactionStatus transactionStatus, ModulesHolder modulesHolder) { + TransactionStatus transactionStatus, ModulesHolder modulesHolder, + ServiceReferenceReadableRegistry readableRegistry) { + this.name = currentModule; this.transactionStatus = transactionStatus; this.modulesHolder = modulesHolder; - } - - public ModuleIdentifier getName() { - return name; + this.readableRegistry = readableRegistry; } /** * {@inheritDoc} */ + //TODO: check for cycles @Override public void validateDependency( Class expectedServiceInterface, - ObjectName dependentModuleReadOnlyON, JmxAttribute jmxAttribute) { + ObjectName dependentReadOnlyON, JmxAttribute jmxAttribute) { transactionStatus.checkNotCommitted(); if (expectedServiceInterface == null) { @@ -66,22 +67,26 @@ final class DependencyResolverImpl implements DependencyResolver, if (jmxAttribute == null) throw new NullPointerException("Parameter 'jmxAttribute' is null"); - JmxAttributeValidationException.checkNotNull(dependentModuleReadOnlyON, + JmxAttributeValidationException.checkNotNull(dependentReadOnlyON, "is null, " + "expected dependency implementing " + expectedServiceInterface, jmxAttribute); + + // check that objectName belongs to this transaction - this should be // stripped // in DynamicWritableWrapper boolean hasTransaction = ObjectNameUtil - .getTransactionName(dependentModuleReadOnlyON) != null; + .getTransactionName(dependentReadOnlyON) != null; JmxAttributeValidationException.checkCondition( hasTransaction == false, format("ObjectName should not contain " + "transaction name. %s set to %s. ", jmxAttribute, - dependentModuleReadOnlyON), jmxAttribute); + dependentReadOnlyON), jmxAttribute); + + dependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON); - ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(dependentModuleReadOnlyON, ObjectNameUtil + ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(dependentReadOnlyON, ObjectNameUtil .TYPE_MODULE); ModuleFactory foundFactory = modulesHolder.findModuleFactory(moduleIdentifier, jmxAttribute); @@ -94,7 +99,7 @@ final class DependencyResolverImpl implements DependencyResolver, + "Module name is %s : %s, expected service interface %s, dependent module ON %s , " + "attribute %s", foundFactory.getImplementationName(), foundFactory, - expectedServiceInterface, dependentModuleReadOnlyON, + expectedServiceInterface, dependentReadOnlyON, jmxAttribute); throw new JmxAttributeValidationException(message, jmxAttribute); } @@ -103,23 +108,35 @@ final class DependencyResolverImpl implements DependencyResolver, } } + // transalate from serviceref to module ON + private ObjectName translateServiceRefIfPossible(ObjectName dependentReadOnlyON) { + if (ObjectNameUtil.isServiceReference(dependentReadOnlyON)) { + String serviceQName = ObjectNameUtil.getServiceQName(dependentReadOnlyON); + String refName = ObjectNameUtil.getReferenceName(dependentReadOnlyON); + dependentReadOnlyON = ObjectNameUtil.withoutTransactionName( // strip again of transaction name + readableRegistry.lookupConfigBeanByServiceInterfaceName(serviceQName, refName)); + } + return dependentReadOnlyON; + } + /** * {@inheritDoc} */ + //TODO: check for cycles @Override - public T resolveInstance(Class expectedType, ObjectName dependentON, + public T resolveInstance(Class expectedType, ObjectName dependentReadOnlyON, JmxAttribute jmxAttribute) { - if (expectedType == null || dependentON == null || jmxAttribute == null) { + if (expectedType == null || dependentReadOnlyON == null || jmxAttribute == null) { throw new IllegalArgumentException(format( "Null parameters not allowed, got {} {} {}", expectedType, - dependentON, jmxAttribute)); + dependentReadOnlyON, jmxAttribute)); } - + dependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON); transactionStatus.checkCommitStarted(); transactionStatus.checkNotCommitted(); ModuleIdentifier dependentModuleIdentifier = ObjectNameUtil.fromON( - dependentON, ObjectNameUtil.TYPE_MODULE); + dependentReadOnlyON, ObjectNameUtil.TYPE_MODULE); Module module = modulesHolder.findModule(dependentModuleIdentifier, jmxAttribute); synchronized (this) { @@ -175,7 +192,7 @@ final class DependencyResolverImpl implements DependencyResolver, int maxDepth = 0; LinkedHashSet chainForDetectingCycles2 = new LinkedHashSet<>( chainForDetectingCycles); - chainForDetectingCycles2.add(impl.getName()); + chainForDetectingCycles2.add(impl.getIdentifier()); for (ModuleIdentifier dependencyName : impl.dependencies) { DependencyResolverImpl dependentDRI = manager .getOrCreate(dependencyName); @@ -199,4 +216,9 @@ final class DependencyResolverImpl implements DependencyResolver, impl.maxDependencyDepth = maxDepth; return maxDepth; } + + @Override + public ModuleIdentifier getIdentifier() { + return name; + } }