private final String configSnapshot;
private final StripCapabilitiesResult stripCapabilitiesResult;
- public CapabilityStrippingConfigSnapshotHolder(Element snapshot, Set<String> capabilities) {
+ public CapabilityStrippingConfigSnapshotHolder(final Element snapshot, final Set<String> capabilities) {
final XmlElement configElement = XmlElement.fromDomElement(snapshot);
configSnapshot = XmlUtil.toString(configElement.getDomElement());
stripCapabilitiesResult = stripCapabilities(configElement, capabilities);
private final SortedSet<String> requiredCapabilities;
private final SortedSet<String> obsoleteCapabilities;
- private StripCapabilitiesResult(SortedSet<String> requiredCapabilities, SortedSet<String> obsoleteCapabilities) {
+ private StripCapabilitiesResult(final SortedSet<String> requiredCapabilities, final SortedSet<String> obsoleteCapabilities) {
this.requiredCapabilities = Collections.unmodifiableSortedSet(requiredCapabilities);
this.obsoleteCapabilities = Collections.unmodifiableSortedSet(obsoleteCapabilities);
}
@VisibleForTesting
- static StripCapabilitiesResult stripCapabilities(XmlElement configElement, Set<String> allCapabilitiesFromHello) {
+ static StripCapabilitiesResult stripCapabilities(final XmlElement configElement, final Set<String> allCapabilitiesFromHello) {
// collect all namespaces
Set<String> foundNamespacesInXML = getNamespaces(configElement);
LOG.trace("All capabilities {}\nFound namespaces in XML {}", allCapabilitiesFromHello, foundNamespacesInXML);
return new StripCapabilitiesResult(requiredCapabilities, obsoleteCapabilities);
}
- static Set<String> getNamespaces(XmlElement element){
+ static Set<String> getNamespaces(final XmlElement element){
Set<String> result = new HashSet<>();
for (Entry<String,Attr> attribute : element.getAttributes().entrySet()) {
if (attribute.getKey().startsWith("xmlns")){
private final ConfigSubsystemFacadeFactory facade;
private ConfigPersisterNotificationHandler jmxNotificationHandler;
- public ConfigPusherImpl(ConfigSubsystemFacadeFactory facade, long maxWaitForCapabilitiesMillis,
- long conflictingVersionTimeoutMillis) {
+ public ConfigPusherImpl(final ConfigSubsystemFacadeFactory facade, final long maxWaitForCapabilitiesMillis,
+ final long conflictingVersionTimeoutMillis) {
this.maxWaitForCapabilitiesMillis = maxWaitForCapabilitiesMillis;
this.conflictingVersionTimeoutMillis = conflictingVersionTimeoutMillis;
this.facade = facade;
}
- public void process(List<AutoCloseable> autoCloseables, MBeanServerConnection platformMBeanServer,
- Persister persisterAggregator, boolean propagateExceptions) throws InterruptedException {
+ public void process(final List<AutoCloseable> autoCloseables, final MBeanServerConnection platformMBeanServer,
+ final Persister persisterAggregator, final boolean propagateExceptions) throws InterruptedException {
while(processSingle(autoCloseables, platformMBeanServer, persisterAggregator, propagateExceptions)) {
}
}
boolean processSingle(final List<AutoCloseable> autoCloseables, final MBeanServerConnection platformMBeanServer,
- final Persister persisterAggregator, boolean propagateExceptions) throws InterruptedException {
+ final Persister persisterAggregator, final boolean propagateExceptions) throws InterruptedException {
final List<? extends ConfigSnapshotHolder> configs = queue.take();
try {
internalPushConfigs(configs);
}
LOG.debug("ConfigPusher has pushed configs {}", configs);
- } catch (Exception e) {
+ } catch (final Exception e) {
// Exceptions are logged to error downstream
LOG.debug("Failed to push some of configs: {}", configs, e);
}
@Override
- public void pushConfigs(List<? extends ConfigSnapshotHolder> configs) throws InterruptedException {
+ public void pushConfigs(final List<? extends ConfigSnapshotHolder> configs) throws InterruptedException {
LOG.debug("Requested to push configs {}", configs);
this.queue.put(configs);
}
- private LinkedHashMap<? extends ConfigSnapshotHolder, Boolean> internalPushConfigs(List<? extends ConfigSnapshotHolder> configs)
+ private LinkedHashMap<? extends ConfigSnapshotHolder, Boolean> internalPushConfigs(final List<? extends ConfigSnapshotHolder> configs)
throws DocumentedException {
LOG.debug("Last config snapshots to be pushed to netconf: {}", configs);
LinkedHashMap<ConfigSnapshotHolder, Boolean> result = new LinkedHashMap<>();
boolean pushResult = false;
try {
pushResult = pushConfigWithConflictingVersionRetries(configSnapshotHolder);
- } catch (ConfigSnapshotFailureException e) {
+ } catch (final ConfigSnapshotFailureException e) {
LOG.error("Failed to apply configuration snapshot: {}. Config snapshot is not semantically correct and will be IGNORED. " +
"for detailed information see enclosed exception.", e.getConfigIdForReporting(), e);
throw new IllegalStateException("Failed to apply configuration snapshot " + e.getConfigIdForReporting(), e);
- } catch (Exception e) {
+ } catch (final Exception e) {
String msg = String.format("Failed to apply configuration snapshot: %s", configSnapshotHolder);
LOG.error(msg, e);
throw new IllegalStateException(msg, e);
return result;
}
- private synchronized boolean pushConfigWithConflictingVersionRetries(ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException {
+ private synchronized boolean pushConfigWithConflictingVersionRetries(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException {
ConflictingVersionException lastException;
Stopwatch stopwatch = Stopwatch.createUnstarted();
do {
stopwatch.start();
}
return pushConfig(configSnapshotHolder);
- } catch (ConflictingVersionException e) {
+ } catch (final ConflictingVersionException e) {
lastException = e;
LOG.info("Conflicting version detected, will retry after timeout");
sleep();
lastException);
}
- private void waitForCapabilities(Set<String> expectedCapabilities, String idForReporting) {
+ private void waitForCapabilities(final Set<String> expectedCapabilities, final String idForReporting) {
Stopwatch stopwatch = Stopwatch.createStarted();
ConfigPusherException lastException;
do {
throw new NotEnoughCapabilitiesException(
"Not enough capabilities for " + idForReporting + ". Expected but not found: " + notFoundCapabilities, notFoundCapabilities);
}
- } catch (ConfigPusherException e) {
+ } catch (final ConfigPusherException e) {
LOG.debug("Not enough capabilities: {}", e.toString());
lastException = e;
sleep();
+ ((NotEnoughCapabilitiesException) lastException).getMissingCaps(), lastException);
}
- private static Set<String> computeNotFoundCapabilities(Set<String> expectedCapabilities, Set<Capability> currentCapabilities) {
+ private static Set<String> computeNotFoundCapabilities(final Set<String> expectedCapabilities, final Set<Capability> currentCapabilities) {
Collection<String> actual = transformCapabilities(currentCapabilities);
Set<String> allNotFound = new HashSet<>(expectedCapabilities);
allNotFound.removeAll(actual);
private static final long serialVersionUID = 1L;
private final Set<String> missingCaps;
- NotEnoughCapabilitiesException(String message, Set<String> missingCaps) {
+ NotEnoughCapabilitiesException(final String message, final Set<String> missingCaps) {
super(message);
this.missingCaps = missingCaps;
}
private void sleep() {
try {
Thread.sleep(100);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
}
- private synchronized boolean pushConfig(ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException, ConflictingVersionException {
+ private synchronized boolean pushConfig(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException, ConflictingVersionException {
Element xmlToBePersisted;
try {
xmlToBePersisted = XmlUtil.readXmlToElement(configSnapshotHolder.getConfigSnapshot());
return true;
}
- private void executeWithMissingModuleFactoryRetries(ConfigSubsystemFacade facade, ConfigExecution configExecution)
+ private void executeWithMissingModuleFactoryRetries(final ConfigSubsystemFacade facade, final ConfigExecution configExecution)
throws DocumentedException, ValidationException, ModuleFactoryNotFoundException {
Stopwatch stopwatch = Stopwatch.createStarted();
ModuleFactoryNotFoundException lastException = null;
try {
facade.executeConfigExecution(configExecution);
return;
- } catch (ModuleFactoryNotFoundException e) {
+ } catch (final ModuleFactoryNotFoundException e) {
LOG.debug("{} - will retry after timeout", e.toString());
lastException = e;
sleep();
throw lastException;
}
- private ConfigExecution createConfigExecution(Element xmlToBePersisted, final ConfigSubsystemFacade currentFacade) throws DocumentedException {
+ private ConfigExecution createConfigExecution(final Element xmlToBePersisted, final ConfigSubsystemFacade currentFacade) throws DocumentedException {
final Config configMapping = currentFacade.getConfigMapping();
return currentFacade.getConfigExecution(configMapping, xmlToBePersisted);
}
private static final Logger LOG = LoggerFactory.getLogger(NoOpStorageAdapter.class);
@Override
- public Persister instantiate(PropertiesProvider propertiesProvider) {
+ public Persister instantiate(final PropertiesProvider propertiesProvider) {
LOG.debug("instantiate called with {}", propertiesProvider);
return this;
}
@Override
- public void persistConfig(ConfigSnapshotHolder holder) throws IOException {
+ public void persistConfig(final ConfigSnapshotHolder holder) throws IOException {
LOG.debug("persistConfig called with {}", holder);
}
private final Persister storage;
private final boolean readOnly;
- public PersisterWithConfiguration(Persister storage, boolean readOnly) {
+ public PersisterWithConfiguration(final Persister storage, final boolean readOnly) {
this.storage = storage;
this.readOnly = readOnly;
}
*/
private final List<PersisterWithConfiguration> persisterWithConfigurations;
- public PersisterAggregator(List<PersisterWithConfiguration> persisterWithConfigurations) {
+ public PersisterAggregator(final List<PersisterWithConfiguration> persisterWithConfigurations) {
this.persisterWithConfigurations = persisterWithConfigurations;
}
}
}
- public static PersisterAggregator createFromProperties(PropertiesProvider propertiesProvider) {
+ public static PersisterAggregator createFromProperties(final PropertiesProvider propertiesProvider) {
List<PersisterWithConfiguration> persisterWithConfigurations = new ArrayList<>();
String prefixes = propertiesProvider.getProperty("active");
if (prefixes!=null && !prefixes.isEmpty()) {
}
@Override
- public void persistConfig(ConfigSnapshotHolder holder) throws IOException {
+ public void persistConfig(final ConfigSnapshotHolder holder) throws IOException {
for (PersisterWithConfiguration persisterWithConfiguration: persisterWithConfigurations){
if (!persisterWithConfiguration.readOnly){
LOG.debug("Calling {}.persistConfig", persisterWithConfiguration.getStorage());
List<ConfigSnapshotHolder> configs = null;
try {
configs = persisterWithConfiguration.storage.loadLastConfigs();
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new RuntimeException("Error while calling loadLastConfig on " + persisterWithConfiguration, e);
}
if (!configs.isEmpty()) {
for (PersisterWithConfiguration persisterWithConfiguration: persisterWithConfigurations){
try{
persisterWithConfiguration.storage.close();
- }catch(RuntimeException e) {
+ }catch(final RuntimeException e) {
LOG.error("Error while closing {}", persisterWithConfiguration.storage, e);
if (lastException == null){
lastException = e;
private final PropertiesProvider inner;
private final String index;
- public PropertiesProviderAdapterImpl(PropertiesProvider inner, String index) {
+ public PropertiesProviderAdapterImpl(final PropertiesProvider inner, final String index) {
this.inner = inner;
this.index = index;
}
@Override
- public String getProperty(String key) {
+ public String getProperty(final String key) {
String fullKey = getFullKeyForReporting(key);
return inner.getPropertyWithoutPrefix(fullKey);
}
}
@Override
- public String getPropertyWithoutPrefix(String fullKey) {
+ public String getPropertyWithoutPrefix(final String fullKey) {
return inner.getPropertyWithoutPrefix(fullKey);
}
@Override
- public String getFullKeyForReporting(String key) {
+ public String getFullKeyForReporting(final String key) {
return getPrefix() + "." + key;
}
}
ServiceTrackerCustomizer<ConfigSubsystemFacadeFactory, ConfigSubsystemFacadeFactory> schemaServiceTrackerCustomizer = new ServiceTrackerCustomizer<ConfigSubsystemFacadeFactory, ConfigSubsystemFacadeFactory>() {
@Override
- public ConfigSubsystemFacadeFactory addingService(ServiceReference<ConfigSubsystemFacadeFactory> reference) {
+ public ConfigSubsystemFacadeFactory addingService(final ServiceReference<ConfigSubsystemFacadeFactory> reference) {
LOG.debug("Got addingService(SchemaContextProvider) event");
// Yang store service should not be registered multiple times
ConfigSubsystemFacadeFactory configSubsystemFacadeFactory = reference.getBundle().getBundleContext().getService(reference);
}
@Override
- public void modifiedService(ServiceReference<ConfigSubsystemFacadeFactory> reference, ConfigSubsystemFacadeFactory service) {
+ public void modifiedService(final ServiceReference<ConfigSubsystemFacadeFactory> reference, final ConfigSubsystemFacadeFactory service) {
LOG.warn("Config manager facade was modified unexpectedly");
}
@Override
- public void removedService(ServiceReference<ConfigSubsystemFacadeFactory> reference, ConfigSubsystemFacadeFactory service) {
+ public void removedService(final ServiceReference<ConfigSubsystemFacadeFactory> reference, final ConfigSubsystemFacadeFactory service) {
LOG.warn("Config manager facade was removed unexpectedly");
}
};
schemaContextProviderServiceTracker.open();
}
- private long getConflictingVersionTimeoutMillis(PropertiesProviderBaseImpl propertiesProvider) {
+ private long getConflictingVersionTimeoutMillis(final PropertiesProviderBaseImpl propertiesProvider) {
String timeoutProperty = propertiesProvider.getProperty(CONFLICTING_VERSION_TIMEOUT_MILLIS_PROPERTY);
return timeoutProperty == null ? CONFLICTING_VERSION_TIMEOUT_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
}
- private long getMaxWaitForCapabilitiesMillis(PropertiesProviderBaseImpl propertiesProvider) {
+ private long getMaxWaitForCapabilitiesMillis(final PropertiesProviderBaseImpl propertiesProvider) {
String timeoutProperty = propertiesProvider.getProperty(MAX_WAIT_FOR_CAPABILITIES_MILLIS_PROPERTY);
return timeoutProperty == null ? MAX_WAIT_FOR_CAPABILITIES_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
}
@Override
- public void stop(BundleContext context) throws Exception {
+ public void stop(final BundleContext context) throws Exception {
synchronized(autoCloseables) {
CloseableUtil.closeAll(autoCloseables);
autoCloseables.clear();
} else {
LOG.warn("Unable to process configs as BundleContext is null");
}
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
LOG.info("ConfigPusher thread stopped");
}
LOG.info("Configuration Persister initialization completed.");
private static final Logger LOG = LoggerFactory.getLogger(PropertiesProviderBaseImpl.class);
private final BundleContext bundleContext;
- public PropertiesProviderBaseImpl(BundleContext bundleContext) {
+ public PropertiesProviderBaseImpl(final BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
@Override
- public String getProperty(String key) {
+ public String getProperty(final String key) {
String fullKey = getFullKeyForReporting(key);
return getPropertyWithoutPrefix(fullKey);
}
- public String getPropertyWithoutPrefix(String fullKey){
+ public String getPropertyWithoutPrefix(final String fullKey){
LOG.trace("Full key {}", fullKey);
return bundleContext.getProperty(fullKey);
}
}
@Override
- public String getFullKeyForReporting(String key) {
+ public String getFullKeyForReporting(final String key) {
return getPrefix() + "." + key;
}
}
assertEquals(obsoleteCapabilities, tested.getObsoleteCapabilities());
}
- private Set<String> readLines(String fileName) throws IOException {
+ private Set<String> readLines(final String fileName) throws IOException {
return new HashSet<>(Resources.readLines(getClass().getResource(fileName), StandardCharsets.UTF_8));
}
- private String readToString(String fileName) throws IOException {
+ private String readToString(final String fileName) throws IOException {
return Resources.toString(getClass().getResource(fileName), StandardCharsets.UTF_8);
}
try {
configPusher.process(Lists.<AutoCloseable>newArrayList(), ManagementFactory.getPlatformMBeanServer(),
mockedAggregator, true);
- } catch(IllegalStateException e) {
+ } catch(final IllegalStateException e) {
Throwable cause = Throwables.getRootCause(e);
assertTrue(cause instanceof ConfigPusherImpl.NotEnoughCapabilitiesException);
final Set<String> missingCaps = ((ConfigPusherImpl.NotEnoughCapabilitiesException) cause).getMissingCaps();
configPusher.pushConfigs(Collections.singletonList(mockedConfigSnapshot));
try {
configPusher.processSingle(Lists.<AutoCloseable>newArrayList(), mBeanServer, mockedAggregator, true);
- } catch (IllegalStateException e) {
+ } catch (final IllegalStateException e) {
Throwable cause = Throwables.getRootCause(e);
assertTrue(cause instanceof ConflictingVersionException);
return;
static int persist = 0;
@Override
- public void persistConfig(ConfigSnapshotHolder holder) throws IOException {
+ public void persistConfig(final ConfigSnapshotHolder holder) throws IOException {
persist++;
}
static int props = 0;
@Override
- public Persister instantiate(PropertiesProvider propertiesProvider) {
+ public Persister instantiate(final PropertiesProvider propertiesProvider) {
props++;
return this;
}
private final Properties prop;
- public TestingPropertiesProvider(Properties prop) {
+ public TestingPropertiesProvider(final Properties prop) {
super(null);
this.prop = prop;
}
- public static TestingPropertiesProvider loadFile(String fileName) {
+ public static TestingPropertiesProvider loadFile(final String fileName) {
Properties prop = new Properties();
try {
prop.load(TestingPropertiesProvider.class.getClassLoader().getResourceAsStream(fileName));
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new RuntimeException(e);
}
return new TestingPropertiesProvider(prop);
}
@Override
- public String getFullKeyForReporting(String key) {
+ public String getFullKeyForReporting(final String key) {
return ConfigPersisterActivator.NETCONF_CONFIG_PERSISTER + "." + key;
}
@Override
- public String getProperty(String key) {
+ public String getProperty(final String key) {
return prop.getProperty(getFullKeyForReporting(key));
}
@Override
- public String getPropertyWithoutPrefix(String fullKey){
+ public String getPropertyWithoutPrefix(final String fullKey){
return prop.getProperty(fullKey);
}
}
try {
PersisterAggregator.createFromProperties(TestingPropertiesProvider.loadFile("test3.properties"));
fail();
- } catch (RuntimeException e) {
+ } catch (final RuntimeException e) {
assertThat(
e.getMessage(),
containsString("numberOfBackups property should be either set to positive value, or ommited. Can not be set to 0."));
}
}
- private ConfigSnapshotHolder mockHolder(String name){
+ private ConfigSnapshotHolder mockHolder(final String name){
ConfigSnapshotHolder result = mock(ConfigSnapshotHolder.class);
doReturn("mock:" + name).when(result).toString();
return result;
}
- private Persister mockPersister(String name){
+ private Persister mockPersister(final String name){
Persister result = mock(Persister.class);
doReturn("mock:" + name).when(result).toString();
doNothing().when(result).close();