use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class ConfigTransactionControllerImpl method processDefaultBeans.
private synchronized void processDefaultBeans(final List<ModuleFactory> lastListOfFactories) {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
Set<ModuleFactory> oldSet = new HashSet<>(lastListOfFactories);
Set<ModuleFactory> newSet = new HashSet<>(factoriesHolder.getModuleFactories());
List<ModuleFactory> toBeAdded = new ArrayList<>();
List<ModuleFactory> toBeRemoved = new ArrayList<>();
for (ModuleFactory moduleFactory : factoriesHolder.getModuleFactories()) {
if (!oldSet.contains(moduleFactory)) {
toBeAdded.add(moduleFactory);
}
}
for (ModuleFactory moduleFactory : lastListOfFactories) {
if (!newSet.contains(moduleFactory)) {
toBeRemoved.add(moduleFactory);
}
}
// add default modules
for (ModuleFactory moduleFactory : toBeAdded) {
BundleContext bundleContext = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
Set<? extends Module> defaultModules = moduleFactory.getDefaultModules(dependencyResolverManager, bundleContext);
for (Module module : defaultModules) {
// ensure default module to be registered to jmx even if its module factory does
// not use dependencyResolverFactory
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(module.getIdentifier());
final ObjectName objectName;
try {
boolean defaultBean = true;
objectName = putConfigBeanToJMXAndInternalMaps(module.getIdentifier(), module, moduleFactory, null, dependencyResolver, defaultBean, bundleContext);
} catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException(e);
}
// register default module as every possible service
final Set<ServiceInterfaceAnnotation> serviceInterfaceAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(moduleFactory);
for (String qname : InterfacesHelper.getQNames(serviceInterfaceAnnotations)) {
try {
saveServiceReference(qname, module.getIdentifier().getInstanceName(), objectName);
} catch (final InstanceNotFoundException e) {
throw new IllegalStateException("Unable to register default module instance " + module + " as a service of " + qname, e);
}
}
}
}
// remove modules belonging to removed factories
for (ModuleFactory removedFactory : toBeRemoved) {
List<ModuleIdentifier> modulesOfRemovedFactory = dependencyResolverManager.findAllByFactory(removedFactory);
for (ModuleIdentifier name : modulesOfRemovedFactory) {
// remove service refs
final ModuleFactory moduleFactory = dependencyResolverManager.findModuleInternalTransactionalInfo(name).getModuleFactory();
final Set<ServiceInterfaceAnnotation> serviceInterfaceAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(moduleFactory);
for (String qname : InterfacesHelper.getQNames(serviceInterfaceAnnotations)) {
try {
removeServiceReference(qname, name.getInstanceName());
} catch (final InstanceNotFoundException e) {
throw new IllegalStateException("Unable to UNregister default module instance " + name + " as a service of " + qname, e);
}
}
// close module
destroyModule(name);
}
}
}
use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class ConfigTransactionControllerImpl method reCreateModule.
@Override
public synchronized void reCreateModule(final ObjectName objectName) throws InstanceNotFoundException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
checkTransactionName(objectName);
ObjectNameUtil.checkDomain(objectName);
ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(objectName, ObjectNameUtil.TYPE_MODULE);
ModuleInternalTransactionalInfo txInfo = dependencyResolverManager.findModuleInternalTransactionalInfo(moduleIdentifier);
Module realModule = txInfo.getRealModule();
if (realModule instanceof AbstractModule) {
((AbstractModule<?>) realModule).setCanReuseInstance(false);
}
}
use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class ConfigTransactionControllerImpl method destroyModule.
@Override
public synchronized void destroyModule(final ObjectName objectName) throws InstanceNotFoundException {
checkTransactionName(objectName);
ObjectNameUtil.checkDomain(objectName);
ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(objectName, ObjectNameUtil.TYPE_MODULE);
destroyModule(moduleIdentifier);
}
use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class ServiceReferenceRegistryImpl method findServiceReferencesLinkingTo.
private Set<ServiceReference> findServiceReferencesLinkingTo(final ObjectName moduleObjectName, final Set<String> serviceInterfaceQNames) {
String factoryName = ObjectNameUtil.getFactoryName(moduleObjectName);
if (serviceInterfaceQNames == null) {
LOG.warn("Possible error in code: cannot find factoryName {} in {}, object name {}", factoryName, factoryNamesToQNames, moduleObjectName);
throw new IllegalStateException("Possible error in code: cannot find annotations of existing factory " + factoryName);
}
String instanceName = ObjectNameUtil.getInstanceName(moduleObjectName);
ModuleIdentifier moduleIdentifier = new ModuleIdentifier(factoryName, instanceName);
Set<ServiceReference> result = new HashSet<>();
for (Entry<ServiceReference, ModuleIdentifier> entry : refNames.entrySet()) {
if (entry.getValue().equals(moduleIdentifier)) {
result.add(entry.getKey());
}
}
return result;
}
use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class ServiceReferenceRegistryImpl method saveServiceReference.
private synchronized ObjectName saveServiceReference(final ServiceReference serviceReference, final ObjectName moduleON, final boolean skipChecks) throws InstanceNotFoundException {
// make sure it is found
if (!skipChecks) {
lookupRegistry.checkConfigBeanExists(moduleON);
}
String factoryName = ObjectNameUtil.getFactoryName(moduleON);
String instanceName = ObjectNameUtil.getInstanceName(moduleON);
ModuleIdentifier moduleIdentifier = new ModuleIdentifier(factoryName, instanceName);
// check that service interface name exist
Set<String> serviceInterfaceQNames = factoryNamesToQNames.get(moduleIdentifier.getFactoryName());
if (serviceInterfaceQNames == null) {
LOG.error("Possible error in code: cannot find factoryName {} in {}, {}", moduleIdentifier.getFactoryName(), factoryNamesToQNames, moduleIdentifier);
throw new IllegalStateException("Possible error in code: cannot find annotations of existing factory " + moduleIdentifier.getFactoryName());
}
// supplied serviceInterfaceName must exist in this collection
if (!serviceInterfaceQNames.contains(serviceReference.getServiceInterfaceQName())) {
LOG.error("Cannot find qName {} with factory name {}, found {}", serviceReference.getServiceInterfaceQName(), moduleIdentifier.getFactoryName(), serviceInterfaceQNames);
throw new IllegalArgumentException("Cannot find service interface " + serviceReference.getServiceInterfaceQName() + " within factory " + moduleIdentifier.getFactoryName());
}
// create service reference object name, put to mBeans
ObjectName result = getServiceON(serviceReference);
Entry<ServiceReferenceMXBeanImpl, ServiceReferenceJMXRegistration> mxBeanEntry = managementBeans.get(serviceReference);
if (mxBeanEntry == null) {
// create dummy mx bean
ServiceReferenceMXBeanImpl dummyMXBean = new ServiceReferenceMXBeanImpl(moduleON);
ServiceReferenceJMXRegistration dummyMXBeanRegistration;
try {
dummyMXBeanRegistration = serviceReferenceRegistrator.registerMBean(dummyMXBean, result);
} catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException("Possible error in code. Cannot register " + result, e);
}
managementBeans.put(serviceReference, new SimpleImmutableEntry<>(dummyMXBean, dummyMXBeanRegistration));
} else {
// update
mxBeanEntry.getKey().setCurrentImplementation(moduleON);
}
// save to refNames
refNames.put(serviceReference, moduleIdentifier);
Map<ServiceInterfaceAnnotation, String> /* service ref name */
refNamesToAnnotations = modulesToServiceRef.computeIfAbsent(moduleIdentifier, k -> new HashMap<>());
ServiceInterfaceAnnotation annotation = serviceQNamesToAnnotations.get(serviceReference.getServiceInterfaceQName());
Preconditions.checkNotNull(annotation, "Possible error in code, cannot find annotation for " + serviceReference);
refNamesToAnnotations.put(annotation, serviceReference.getRefName());
return result;
}
Aggregations