*/
@Override
public synchronized ObjectName beginConfig() {
- return beginConfigInternal().getControllerObjectName();
+ return beginConfig(false);
}
- private synchronized ConfigTransactionControllerInternal beginConfigInternal() {
+ /**
+ * @param blankTransaction true if this transaction is created automatically by
+ * org.opendaylight.controller.config.manager.impl.osgi.BlankTransactionServiceTracker
+ */
+ public synchronized ObjectName beginConfig(boolean blankTransaction) {
+ return beginConfigInternal(blankTransaction).getControllerObjectName();
+ }
+
+ private synchronized ConfigTransactionControllerInternal beginConfigInternal(boolean blankTransaction) {
versionCounter++;
String transactionName = "ConfigTransaction-" + version + "-" + versionCounter;
TransactionJMXRegistrator transactionRegistrator = baseJMXRegistrator
Map<String, Map.Entry<ModuleFactory, BundleContext>> allCurrentFactories = Collections.unmodifiableMap(resolver.getAllFactories());
ConfigTransactionControllerInternal transactionController = new ConfigTransactionControllerImpl(
transactionName, transactionRegistrator, version,
- versionCounter, allCurrentFactories, transactionsMBeanServer, configMBeanServer, bundleContext);
+ versionCounter, allCurrentFactories, transactionsMBeanServer, configMBeanServer, blankTransaction);
try {
transactionRegistrator.registerMBean(transactionController, transactionController.getControllerObjectName());
} catch (InstanceAlreadyExistsException e) {
RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
if (entry.hasOldModule() == false) {
runtimeBeanRegistrator = baseJMXRegistrator
- .createRuntimeBeanRegistrator(entry.getName());
+ .createRuntimeBeanRegistrator(entry.getIdentifier());
} else {
// reuse old JMX registrator
runtimeBeanRegistrator = entry.getOldInternalInfo()
.setRuntimeBeanRegistrator(runtimeBeanRegistrator);
}
// save it to info so it is accessible afterwards
- runtimeRegistrators.put(entry.getName(), runtimeBeanRegistrator);
+ runtimeRegistrators.put(entry.getIdentifier(), runtimeBeanRegistrator);
}
// can register runtime beans
// determine if current instance was recreated or reused or is new
// rules for closing resources:
- // osgi registration - will be (re)created every time, so it needs
- // to be closed here
+ // osgi registration - will be reused if possible.
// module jmx registration - will be (re)created every time, needs
// to be closed here
// runtime jmx registration - should be taken care of by module
ModuleInternalInfo oldInternalInfo = entry.getOldInternalInfo();
DynamicReadableWrapper oldReadableConfigBean = oldInternalInfo
.getReadableModule();
- currentConfig.remove(entry.getName());
+ currentConfig.remove(entry.getIdentifier());
// test if old instance == new instance
if (oldReadableConfigBean.getInstance().equals(module.getInstance())) {
BundleContext bc = configTransactionController.
getModuleFactoryBundleContext(moduleFactory.getImplementationName());
osgiRegistration = beanToOsgiServiceManager.registerToOsgi(module.getClass(),
- newReadableConfigBean.getInstance(), entry.getName(), bc);
+ newReadableConfigBean.getInstance(), entry.getIdentifier(), bc);
} else {
throw new NullPointerException(entry.getIdentifier().getFactoryName() + " ModuleFactory not found.");
}
}
RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator = runtimeRegistrators
- .get(entry.getName());
+ .get(entry.getIdentifier());
ModuleInternalInfo newInfo = new ModuleInternalInfo(
- entry.getName(), newReadableConfigBean, osgiRegistration,
+ entry.getIdentifier(), newReadableConfigBean, osgiRegistration,
runtimeBeanRegistrator, newModuleJMXRegistrator,
- orderingIdx);
+ orderingIdx, entry.isDefaultBean());
newConfigEntries.put(module, newInfo);
orderingIdx++;
/**
* Abort open transactions and unregister read only modules. Since this
* class is not responsible for registering itself under
- * {@link ConfigRegistryMXBean#OBJECT_NAME}, it will not unregister itself
+ * {@link org.opendaylight.controller.config.api.ConfigRegistry#OBJECT_NAME}, it will not unregister itself
* here.
*/
@Override
configBeanModificationDisabled);
private final MBeanServer configMBeanServer;
- private final BundleContext bundleContext;
+ private final boolean blankTransaction;
public ConfigTransactionControllerImpl(String transactionName,
TransactionJMXRegistrator transactionRegistrator,
long parentVersion, long currentVersion,
Map<String, Map.Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories,
- MBeanServer transactionsMBeanServer, MBeanServer configMBeanServer, BundleContext bundleContext) {
+ MBeanServer transactionsMBeanServer, MBeanServer configMBeanServer,
+ boolean blankTransaction) {
this.transactionIdentifier = new TransactionIdentifier(transactionName);
this.controllerON = ObjectNameUtil
this.dependencyResolverManager = new DependencyResolverManager(transactionName, transactionStatus);
this.transactionsMBeanServer = transactionsMBeanServer;
this.configMBeanServer = configMBeanServer;
- this.bundleContext = bundleContext;
+ this.blankTransaction = blankTransaction;
}
@Override
// ensure default module to be registered to jmx even if its module factory does not use dependencyResolverFactory
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(module.getIdentifier());
try {
- putConfigBeanToJMXAndInternalMaps(module.getIdentifier(), module, moduleFactory, null, dependencyResolver);
+ boolean defaultBean = true;
+ putConfigBeanToJMXAndInternalMaps(module.getIdentifier(), module, moduleFactory, null, dependencyResolver, defaultBean);
} catch (InstanceAlreadyExistsException e) {
throw new IllegalStateException(e);
}
"Error while copying old configuration from %s to %s",
oldConfigBeanInfo, moduleFactory), e);
}
- putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module, moduleFactory, oldConfigBeanInfo, dependencyResolver);
+ putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module, moduleFactory, oldConfigBeanInfo, dependencyResolver,
+ oldConfigBeanInfo.isDefaultBean());
}
@Override
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
Module module = moduleFactory.createModule(instanceName, dependencyResolver,
getModuleFactoryBundleContext(moduleFactory.getImplementationName()));
+ boolean defaultBean = false;
return putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module,
- moduleFactory, null, dependencyResolver);
+ moduleFactory, null, dependencyResolver, defaultBean);
}
private synchronized ObjectName putConfigBeanToJMXAndInternalMaps(
ModuleIdentifier moduleIdentifier, Module module,
ModuleFactory moduleFactory,
- @Nullable ModuleInternalInfo maybeOldConfigBeanInfo, DependencyResolver dependencyResolver)
+ @Nullable ModuleInternalInfo maybeOldConfigBeanInfo, DependencyResolver dependencyResolver, boolean isDefaultBean)
throws InstanceAlreadyExistsException {
logger.debug("Adding module {} to transaction {}", moduleIdentifier, this);
.registerMBean(writableDynamicWrapper, writableON);
ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = new ModuleInternalTransactionalInfo(
moduleIdentifier, module, moduleFactory,
- maybeOldConfigBeanInfo, transactionModuleJMXRegistration);
+ maybeOldConfigBeanInfo, transactionModuleJMXRegistration, isDefaultBean);
dependencyResolverManager.put(moduleInternalTransactionalInfo);
return writableON;
}
@Override
- public void destroyModule(ObjectName objectName)
+ public synchronized void destroyModule(ObjectName objectName)
throws InstanceNotFoundException {
String foundTransactionName = ObjectNameUtil
.getTransactionName(objectName);
destroyModule(moduleIdentifier);
}
- private void destroyModule(ModuleIdentifier moduleIdentifier) {
+ private synchronized void destroyModule(ModuleIdentifier moduleIdentifier) {
logger.debug("Destroying module {} in transaction {}", moduleIdentifier, this);
transactionStatus.checkNotAborted();
+
+ if (blankTransaction == false) {
+ ModuleInternalTransactionalInfo found =
+ dependencyResolverManager.findModuleInternalTransactionalInfo(moduleIdentifier);
+ if (found.isDefaultBean()) {
+ logger.warn("Warning: removing default bean. This will be forbidden in next version of config-subsystem");
+ }
+ }
ModuleInternalTransactionalInfo removedTInfo = dependencyResolverManager.destroyModule(moduleIdentifier);
// remove from jmx
removedTInfo.getTransactionModuleJMXRegistration().close();
private final OsgiRegistration osgiRegistration;
private final ModuleJMXRegistrator moduleJMXRegistrator;
private final int orderingIdx;
+ private final boolean isDefaultBean;
public ModuleInternalInfo(ModuleIdentifier name,
@Nullable DynamicReadableWrapper readableModule,
OsgiRegistration osgiRegistration,
RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
- ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx) {
+ ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx,
+ boolean isDefaultBean) {
if (osgiRegistration == null) {
throw new IllegalArgumentException(
this.name = name;
this.moduleJMXRegistrator = moduleJMXRegistrator;
this.orderingIdx = orderingIdx;
+ this.isDefaultBean = isDefaultBean;
}
public DynamicReadableWrapper getReadableModule() {
public ModuleIdentifier getIdentifier() {
return name;
}
+
+ public boolean isDefaultBean() {
+ return isDefaultBean;
+ }
}
@Nullable
private final ModuleInternalInfo maybeOldInternalInfo;
private final TransactionModuleJMXRegistration transactionModuleJMXRegistration;
+ private final boolean isDefaultBean;
ModuleInternalTransactionalInfo(ModuleIdentifier name, Module module,
ModuleFactory moduleFactory,
ModuleInternalInfo maybeOldInternalInfo,
- TransactionModuleJMXRegistration transactionModuleJMXRegistration) {
+ TransactionModuleJMXRegistration transactionModuleJMXRegistration,
+ boolean isDefaultBean) {
this.name = name;
this.module = module;
this.moduleFactory = moduleFactory;
this.maybeOldInternalInfo = maybeOldInternalInfo;
this.transactionModuleJMXRegistration = transactionModuleJMXRegistration;
+ this.isDefaultBean = isDefaultBean;
}
- /**
- * Use {@link #getIdentifier()} instead.
- */
- @Deprecated
- public ModuleIdentifier getName() {
- return name;
- }
-
public boolean hasOldModule() {
return maybeOldInternalInfo != null;
}
public ModuleIdentifier getIdentifier() {
return name;
}
+
+ public boolean isDefaultBean() {
+ return isDefaultBean;
+ }
}
jmxAttributeForReporting);
}
+ @Override
+ public ModuleInternalTransactionalInfo findModuleInternalTransactionalInfo(ModuleIdentifier moduleIdentifier) {
+ return modulesHolder.findModuleInternalTransactionalInfo(moduleIdentifier);
+ }
+
@Override
public ModuleFactory findModuleFactory(ModuleIdentifier moduleIdentifier,
JmxAttribute jmxAttributeForReporting) {
List<ModuleIdentifier> result = new ArrayList<>();
for( ModuleInternalTransactionalInfo info : modulesHolder.getAllInfos()) {
if (factory.equals(info.getModuleFactory())) {
- result.add(info.getName());
+ result.add(info.getIdentifier());
}
}
return result;
public Map<ModuleIdentifier, Module> getAllModules() {
Map<ModuleIdentifier, Module> result = new HashMap<>();
for (ModuleInternalTransactionalInfo entry : commitMap.values()) {
- ModuleIdentifier name = entry.getName();
+ ModuleIdentifier name = entry.getIdentifier();
result.put(name, entry.getModule());
}
return result;
@Override
public void put(
ModuleInternalTransactionalInfo moduleInternalTransactionalInfo) {
- commitMap.put(moduleInternalTransactionalInfo.getName(),
+ commitMap.put(moduleInternalTransactionalInfo.getIdentifier(),
moduleInternalTransactionalInfo);
}
@Override
public ModuleInternalTransactionalInfo destroyModule(
ModuleIdentifier moduleIdentifier) {
- ModuleInternalTransactionalInfo found = commitMap
- .remove(moduleIdentifier);
- if (found == null)
+ ModuleInternalTransactionalInfo found = commitMap.remove(moduleIdentifier);
+ if (found == null) {
throw new IllegalStateException("Not found:" + moduleIdentifier);
+ }
if (found.hasOldModule()) {
unorderedDestroyedFromPreviousTransactions.add(found);
}
public Collection<ModuleInternalTransactionalInfo> getAllInfos(){
return commitMap.values();
}
+
+ @Override
+ public ModuleInternalTransactionalInfo findModuleInternalTransactionalInfo(ModuleIdentifier moduleIdentifier) {
+ ModuleInternalTransactionalInfo found = commitMap.get(moduleIdentifier);
+ if (found == null) {
+ throw new IllegalStateException("Not found:" + moduleIdentifier);
+ }
+ return found;
+ }
}
void assertNotExists(ModuleIdentifier moduleIdentifier)
throws InstanceAlreadyExistsException;
+ ModuleInternalTransactionalInfo findModuleInternalTransactionalInfo(ModuleIdentifier moduleIdentifier);
+
}
for (int i = 0; i < 10; i++) {
try {
// create transaction
- ObjectName tx = configRegistry.beginConfig();
+ boolean blankTransaction = true;
+ ObjectName tx = configRegistry.beginConfig(blankTransaction);
CommitStatus commitStatus = configRegistry.commitConfig(tx);
logger.debug("Committed blank transaction with status {}", commitStatus);
return;
testedTxController = new ConfigTransactionControllerImpl(
transactionName123, jmxRegistrator123, 1, 1,
currentlyRegisteredFactories, transactionsMBeanServer,
- ManagementFactory.getPlatformMBeanServer(), null);
+ ManagementFactory.getPlatformMBeanServer(), false);
TransactionModuleJMXRegistrator transactionModuleJMXRegistrator123 = testedTxController
.getTxModuleJMXRegistrator();
transactionModuleJMXRegistrator123.registerMBean(
private static void mockGetInstance(DependencyResolverManager tested,
ModuleIdentifier moduleIdentifier) {
ModuleInternalTransactionalInfo mock = mock(ModuleInternalTransactionalInfo.class);
- doReturn(moduleIdentifier).when(mock).getName();
+ doReturn(moduleIdentifier).when(mock).getIdentifier();
doReturn(mockedModule()).when(mock).getModule();
tested.put(mock);
}