--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.api;
+
+/**
+ * Exception thrown when a ModuleFactory is not found while pushing a config.
+ *
+ * @author Thomas Pantelis
+ */
+public class ModuleFactoryNotFoundException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ private final String moduleName;
+
+ public ModuleFactoryNotFoundException(String moduleName) {
+ super("ModuleFactory not found for module name: " + moduleName);
+ this.moduleName = moduleName;
+ }
+
+ public String getModuleName() {
+ return moduleName;
+ }
+}
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
-
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collection;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.ModuleFactoryNotFoundException;
import org.opendaylight.controller.config.api.ModuleIdentifier;
import org.opendaylight.controller.config.api.ValidationException;
import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
}
- private synchronized void copyExistingModule(ModuleInternalInfo oldConfigBeanInfo) throws InstanceAlreadyExistsException {
+ private synchronized void copyExistingModule(ModuleInternalInfo oldConfigBeanInfo)
+ throws InstanceAlreadyExistsException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
try {
moduleFactory = factoriesHolder.findByModuleName(moduleIdentifier.getFactoryName());
bc = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
- } catch (InstanceNotFoundException e) {
+ } catch (ModuleFactoryNotFoundException e) {
throw new IllegalStateException(e);
}
}
@Override
- public synchronized ObjectName createModule(String factoryName,
- String instanceName) throws InstanceAlreadyExistsException {
+ public synchronized ObjectName createModule(String factoryName, String instanceName)
+ throws InstanceAlreadyExistsException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
dependencyResolverManager.assertNotExists(moduleIdentifier);
// find factory
- ModuleFactory moduleFactory;
- try {
- moduleFactory = factoriesHolder.findByModuleName(factoryName);
- } catch (InstanceNotFoundException e) {
- throw new IllegalArgumentException(e);
- }
+ ModuleFactory moduleFactory = factoriesHolder.findByModuleName(factoryName);
+
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
BundleContext bundleContext = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
Module module = moduleFactory.createModule(instanceName, dependencyResolver,
close();
}
+ @Override
public void close() {
dependencyResolverManager.close();
txLookupRegistry.close();
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-import javax.management.InstanceNotFoundException;
+import org.opendaylight.controller.config.api.ModuleFactoryNotFoundException;
import org.opendaylight.controller.config.spi.ModuleFactory;
import org.osgi.framework.BundleContext;
* @throws IllegalArgumentException
* if factory is not found
*/
- public ModuleFactory findByModuleName(String moduleName) throws InstanceNotFoundException {
+ public ModuleFactory findByModuleName(String moduleName) throws ModuleFactoryNotFoundException {
Map.Entry<ModuleFactory, BundleContext> result = moduleNamesToConfigBeanFactories.get(moduleName);
if (result == null) {
- throw new InstanceNotFoundException(
- "ModuleFactory not found with module name: " + moduleName);
+ throw new ModuleFactoryNotFoundException(moduleName);
}
return result.getKey();
}
ModuleFactoryBundleTracker moduleFactoryTracker = new ModuleFactoryBundleTracker(
blankTransactionServiceTracker);
- boolean scanResolvedBundlesForModuleInfo = false;
+ boolean scanResolvedBundlesForModuleInfo = true;
BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> moduleInfoResolvedBundleTracker = null;
ExtensibleBundleTracker<?> moduleFactoryBundleTracker;
if(scanResolvedBundlesForModuleInfo) {
package org.opendaylight.controller.config.persist.impl;
import static com.google.common.base.Preconditions.checkNotNull;
-
import com.google.common.base.Function;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Collections2;
import javax.annotation.concurrent.Immutable;
import javax.management.MBeanServerConnection;
import org.opendaylight.controller.config.api.ConflictingVersionException;
+import org.opendaylight.controller.config.api.ModuleFactoryNotFoundException;
import org.opendaylight.controller.config.api.ValidationException;
import org.opendaylight.controller.config.facade.xml.ConfigExecution;
import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade;
private final long maxWaitForCapabilitiesMillis;
private final long conflictingVersionTimeoutMillis;
- private BlockingQueue<List<? extends ConfigSnapshotHolder>> queue = new LinkedBlockingQueue<>(QUEUE_SIZE);
+ private final BlockingQueue<List<? extends ConfigSnapshotHolder>> queue = new LinkedBlockingQueue<>(QUEUE_SIZE);
- private ConfigSubsystemFacadeFactory facade;
+ private final ConfigSubsystemFacadeFactory facade;
private ConfigPersisterNotificationHandler jmxNotificationHandler;
public ConfigPusherImpl(ConfigSubsystemFacadeFactory facade, long maxWaitForCapabilitiesMillis,
}
}
+ @Override
public void pushConfigs(List<? extends ConfigSnapshotHolder> configs) throws InterruptedException {
LOG.debug("Requested to push configs {}", configs);
this.queue.put(configs);
static class NotEnoughCapabilitiesException extends ConfigPusherException {
private static final long serialVersionUID = 1L;
- private Set<String> missingCaps;
+ private final Set<String> missingCaps;
NotEnoughCapabilitiesException(String message, Set<String> missingCaps) {
super(message);
final ConfigSubsystemFacade currentFacade = this.facade.createFacade("config-push");
try {
ConfigExecution configExecution = createConfigExecution(xmlToBePersisted, currentFacade);
- currentFacade.executeConfigExecution(configExecution);
- } catch (ValidationException | DocumentedException e) {
+ executeWithMissingModuleFactoryRetries(currentFacade, configExecution);
+ } catch (ValidationException | DocumentedException | ModuleFactoryNotFoundException e) {
LOG.trace("Validation for config: {} failed", configSnapshotHolder, e);
throw new ConfigSnapshotFailureException(configSnapshotHolder.toString(), "edit", e);
}
return true;
}
+ private void executeWithMissingModuleFactoryRetries(ConfigSubsystemFacade facade, ConfigExecution configExecution)
+ throws DocumentedException, ValidationException, ModuleFactoryNotFoundException {
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ ModuleFactoryNotFoundException lastException = null;
+ do {
+ try {
+ facade.executeConfigExecution(configExecution);
+ return;
+ } catch (ModuleFactoryNotFoundException e) {
+ LOG.debug("{} - will retry after timeout", e.toString());
+ lastException = e;
+ sleep();
+ }
+ } while (stopwatch.elapsed(TimeUnit.MILLISECONDS) < maxWaitForCapabilitiesMillis);
+
+ throw lastException;
+ }
+
private ConfigExecution createConfigExecution(Element xmlToBePersisted, final ConfigSubsystemFacade currentFacade) throws DocumentedException {
final Config configMapping = currentFacade.getConfigMapping();
return currentFacade.getConfigExecution(configMapping, xmlToBePersisted);