import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
import java.util.List;
import java.util.Map;
public static String checkPrefixAndExtractServiceName(XmlElement typeElement, Map.Entry<String, String> prefixNamespace) throws NetconfDocumentedException {
String serviceName = typeElement.getTextContent();
// FIXME: comparing Entry with String:
- Preconditions.checkState(!prefixNamespace.equals(""), "Service %s value not prefixed with namespace",
+ Preconditions.checkState(!Strings.isNullOrEmpty(prefixNamespace.getKey()), "Service %s value not prefixed with namespace",
XmlNetconfConstants.TYPE_KEY);
String prefix = prefixNamespace.getKey() + PREFIX_SEPARATOR;
Preconditions.checkState(serviceName.startsWith(prefix),
Date revision = null;
Map<Date, EditConfig.IdentityMapping> revisions = identityMap.get(namespace);
if(revisions.keySet().size() > 1) {
- for (Date date : revisions.keySet()) {
- if(revisions.get(date).containsIdName(localName)) {
+ for (Map.Entry<Date, EditConfig.IdentityMapping> revisionToIdentityEntry : revisions.entrySet()) {
+ if(revisionToIdentityEntry.getValue().containsIdName(localName)) {
Preconditions.checkState(revision == null, "Duplicate identity %s, in namespace %s, with revisions: %s, %s detected. Cannot map attribute",
- localName, namespace, revision, date);
- revision = date;
+ localName, namespace, revision, revisionToIdentityEntry.getKey());
+ revision = revisionToIdentityEntry.getKey();
}
}
} else {
Map<String, Map<String, Collection<ObjectName>>> retVal = Maps.newLinkedHashMap();
- for (String namespace : configs.keySet()) {
+ for (Entry<String, Map<String, ModuleConfig>> namespaceToModuleToConfigEntry : configs.entrySet()) {
Map<String, Collection<ObjectName>> innerRetVal = Maps.newHashMap();
- for (Entry<String, ModuleConfig> mbeEntry : configs.get(namespace).entrySet()) {
+ for (Entry<String, ModuleConfig> mbeEntry : namespaceToModuleToConfigEntry.getValue().entrySet()) {
String moduleName = mbeEntry.getKey();
Collection<ObjectName> instances = moduleToInstances.get(moduleName);
}
- retVal.put(namespace, innerRetVal);
+ retVal.put(namespaceToModuleToConfigEntry.getKey(), innerRetVal);
}
return retVal;
}
Element modulesElement = XmlUtil.createElement(document, XmlNetconfConstants.MODULES_KEY, Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
dataElement.appendChild(modulesElement);
- for (String moduleNamespace : moduleToInstances.keySet()) {
- for (Entry<String, Collection<ObjectName>> moduleMappingEntry : moduleToInstances.get(moduleNamespace)
+ for (Entry<String, Map<String, Collection<ObjectName>>> moduleToInstanceEntry : moduleToInstances.entrySet()) {
+ for (Entry<String, Collection<ObjectName>> moduleMappingEntry : moduleToInstanceEntry.getValue()
.entrySet()) {
- ModuleConfig mapping = moduleConfigs.get(moduleNamespace).get(moduleMappingEntry.getKey());
+ ModuleConfig mapping = moduleConfigs.get(moduleToInstanceEntry.getKey()).get(moduleMappingEntry.getKey());
if (moduleMappingEntry.getValue().isEmpty()) {
continue;
}
for (ObjectName objectName : moduleMappingEntry.getValue()) {
- modulesElement.appendChild(mapping.toXml(objectName, document, moduleNamespace));
+ modulesElement.appendChild(mapping.toXml(objectName, document, moduleToInstanceEntry.getKey()));
}
}
this.configServiceRefRegistry = configServiceRefRegistry;
}
-
public ObjectName getByServiceAndRefName(String namespace, String serviceName, String refName) {
Map<String, Map<String, String>> serviceNameToRefNameToInstance = getMappedServices().get(namespace);
Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
Map<String, Map<String, ObjectName>> serviceMapping = configServiceRefRegistry.getServiceMapping();
- for (String serviceQName : serviceMapping.keySet()){
- for (String refName : serviceMapping.get(serviceQName).keySet()) {
+ for (Map.Entry<String, Map<String, ObjectName>> qNameToRefNameEntry : serviceMapping.entrySet()){
+ for (String refName : qNameToRefNameEntry.getValue().keySet()) {
- ObjectName on = serviceMapping.get(serviceQName).get(refName);
+ ObjectName on = qNameToRefNameEntry.getValue().get(refName);
Services.ServiceInstance si = Services.ServiceInstance.fromObjectName(on);
- QName qname = QName.create(serviceQName);
+ QName qname = QName.create(qNameToRefNameEntry.getKey());
String namespace = qname.getNamespace().toString();
Map<String, Map<String, String>> serviceToRefs = retVal.get(namespace);
if(serviceToRefs==null) {
Element root = XmlUtil.createElement(document, XmlNetconfConstants.SERVICES_KEY, Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
Map<String, Map<String, Map<String, String>>> mappedServices = serviceRegistryWrapper.getMappedServices();
- for (String namespace : mappedServices.keySet()) {
+ for (Entry<String, Map<String, Map<String, String>>> namespaceToRefEntry : mappedServices.entrySet()) {
- for (Entry<String, Map<String, String>> serviceEntry : mappedServices.get(namespace).entrySet()) {
+ for (Entry<String, Map<String, String>> serviceEntry : namespaceToRefEntry.getValue().entrySet()) {
// service belongs to config.yang namespace
Element serviceElement = XmlUtil.createElement(document, SERVICE_KEY, Optional.<String>absent());
root.appendChild(serviceElement);
// type belongs to config.yang namespace
String serviceType = serviceEntry.getKey();
Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlNetconfConstants.TYPE_KEY,
- XmlNetconfConstants.PREFIX, namespace, serviceType);
+ XmlNetconfConstants.PREFIX, namespaceToRefEntry.getKey(), serviceType);
serviceElement.appendChild(typeElement);
Map<String, Map<String, Map<String, Services.ServiceInstance>>> namespaceToServiceNameToRefNameToInstance = services
.getNamespaceToServiceNameToRefNameToInstance();
- for (String serviceNamespace : namespaceToServiceNameToRefNameToInstance.keySet()) {
- for (String serviceName : namespaceToServiceNameToRefNameToInstance.get(serviceNamespace).keySet()) {
+ for (Map.Entry<String, Map<String, Map<String, Services.ServiceInstance>>> namespaceToServiceToRefEntry : namespaceToServiceNameToRefNameToInstance.entrySet()) {
+ for (Map.Entry<String, Map<String, Services.ServiceInstance>> serviceToRefEntry : namespaceToServiceToRefEntry.getValue().entrySet()) {
- String qnameOfService = getQname(ta, serviceNamespace, serviceName);
- Map<String, Services.ServiceInstance> refNameToInstance = namespaceToServiceNameToRefNameToInstance
- .get(serviceNamespace).get(serviceName);
+ String qnameOfService = getQname(ta, namespaceToServiceToRefEntry.getKey(), serviceToRefEntry.getKey());
+ Map<String, Services.ServiceInstance> refNameToInstance = serviceToRefEntry.getValue();
- for (String refName : refNameToInstance.keySet()) {
- ObjectName on = refNameToInstance.get(refName).getObjectName(ta.getTransactionName());
+ for (Map.Entry<String, Services.ServiceInstance> refNameToServiceEntry : refNameToInstance.entrySet()) {
+ ObjectName on = refNameToServiceEntry.getValue().getObjectName(ta.getTransactionName());
try {
- ObjectName saved = ta.saveServiceReference(qnameOfService, refName, on);
+ ObjectName saved = ta.saveServiceReference(qnameOfService, refNameToServiceEntry.getKey(), on);
logger.debug("Saving service {} with on {} under name {} with service on {}", qnameOfService,
- on, refName, saved);
+ on, refNameToServiceEntry.getKey(), saved);
} catch (InstanceNotFoundException e) {
- throw new NetconfDocumentedException(String.format("Unable to save ref name " + refName + " for instance " + on, e),
+ throw new NetconfDocumentedException(String.format("Unable to save ref name " + refNameToServiceEntry.getKey() + " for instance " + on, e),
ErrorType.application,
ErrorTag.operation_failed,
ErrorSeverity.error);
Map<String, Map<String, ModuleConfig>> namespaceToModuleNameToModuleConfig = Maps.newHashMap();
- for (String namespace : mBeanEntries.keySet()) {
- for (Map.Entry<String, ModuleMXBeanEntry> moduleNameToMbe : mBeanEntries.get(namespace).entrySet()) {
+ for (Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleToMbe : mBeanEntries.entrySet()) {
+ for (Map.Entry<String, ModuleMXBeanEntry> moduleNameToMbe : namespaceToModuleToMbe.getValue().entrySet()) {
String moduleName = moduleNameToMbe.getKey();
ModuleMXBeanEntry moduleMXBeanEntry = moduleNameToMbe.getValue();
ModuleConfig moduleConfig = new ModuleConfig(moduleName,
new InstanceConfig(configRegistryClient,moduleMXBeanEntry.getAttributes(), moduleMXBeanEntry.getNullableDummyContainerName()));
- Map<String, ModuleConfig> moduleNameToModuleConfig = namespaceToModuleNameToModuleConfig.get(namespace);
+ Map<String, ModuleConfig> moduleNameToModuleConfig = namespaceToModuleNameToModuleConfig.get(namespaceToModuleToMbe.getKey());
if(moduleNameToModuleConfig == null) {
moduleNameToModuleConfig = Maps.newHashMap();
- namespaceToModuleNameToModuleConfig.put(namespace, moduleNameToModuleConfig);
+ namespaceToModuleNameToModuleConfig.put(namespaceToModuleToMbe.getKey(), moduleNameToModuleConfig);
}
moduleNameToModuleConfig.put(moduleName, moduleConfig);
Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries) {
Map<String, Map<String, ModuleRuntime>> retVal = Maps.newHashMap();
- for (String namespace : mBeanEntries.keySet()) {
+ for (Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleEntry : mBeanEntries.entrySet()) {
Map<String, ModuleRuntime> innerMap = Maps.newHashMap();
- Map<String, ModuleMXBeanEntry> entriesFromNamespace = mBeanEntries.get(namespace);
- for (String module : entriesFromNamespace.keySet()) {
+ Map<String, ModuleMXBeanEntry> entriesFromNamespace = namespaceToModuleEntry.getValue();
+ for (Map.Entry<String, ModuleMXBeanEntry> moduleToMXEntry : entriesFromNamespace.entrySet()) {
- ModuleMXBeanEntry mbe = entriesFromNamespace.get(module);
+ ModuleMXBeanEntry mbe = moduleToMXEntry.getValue();
Map<RuntimeBeanEntry, InstanceConfig> cache = Maps.newHashMap();
RuntimeBeanEntry root = null;
InstanceRuntime rootInstanceRuntime = createInstanceRuntime(root, cache);
ModuleRuntime moduleRuntime = new ModuleRuntime(rootInstanceRuntime);
- innerMap.put(module, moduleRuntime);
+ innerMap.put(moduleToMXEntry.getKey(), moduleRuntime);
}
- retVal.put(namespace, innerMap);
+ retVal.put(namespaceToModuleEntry.getKey(), innerMap);
}
return retVal;
}
final String[] signature = new String[attributes.size()];
int i = 0;
- for (final String attrName : attributes.keySet()) {
- final AttributeConfigElement attribute = attributes.get(attrName);
+ for (final AttributeConfigElement attribute : attributes.values()) {
final Optional<?> resolvedValueOpt = attribute.getResolvedValue();
params[i] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get() : attribute.getResolvedDefaultValue();
final Map<String, Map<String, ModuleRpcs>> map = Maps.newHashMap();
- for (final String namespace : mBeanEntries.keySet()) {
+ for (final Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleEntry : mBeanEntries.entrySet()) {
- Map<String, ModuleRpcs> namespaceToModules = map.get(namespace);
+ Map<String, ModuleRpcs> namespaceToModules = map.get(namespaceToModuleEntry.getKey());
if (namespaceToModules == null) {
namespaceToModules = Maps.newHashMap();
- map.put(namespace, namespaceToModules);
+ map.put(namespaceToModuleEntry.getKey(), namespaceToModules);
}
- for (final String moduleName : mBeanEntries.get(namespace).keySet()) {
+ for (final Map.Entry<String, ModuleMXBeanEntry> moduleEntry : namespaceToModuleEntry.getValue().entrySet()) {
- ModuleRpcs rpcMapping = namespaceToModules.get(moduleName);
+ ModuleRpcs rpcMapping = namespaceToModules.get(moduleEntry.getKey());
if (rpcMapping == null) {
rpcMapping = new ModuleRpcs();
- namespaceToModules.put(moduleName, rpcMapping);
+ namespaceToModules.put(moduleEntry.getKey(), rpcMapping);
}
- final ModuleMXBeanEntry entry = mBeanEntries.get(namespace).get(moduleName);
+ final ModuleMXBeanEntry entry = moduleEntry.getValue();
for (final RuntimeBeanEntry runtimeEntry : entry.getRuntimeBeans()) {
rpcMapping.addNameMapping(runtimeEntry);
allOpenedTransactions.clear();
}
- public Optional<ObjectName> getTransaction() {
+ public synchronized Optional<ObjectName> getTransaction() {
if (transaction == null){
return Optional.absent();
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 java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-
+import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import javax.management.MBeanServerConnection;
-
import org.opendaylight.controller.config.api.ConflictingVersionException;
import org.opendaylight.controller.config.persist.api.ConfigPusher;
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
-import com.google.common.base.Function;
-import com.google.common.base.Stopwatch;
-import com.google.common.collect.Collections2;
-
@Immutable
public class ConfigPusherImpl implements ConfigPusher {
private static final Logger logger = LoggerFactory.getLogger(ConfigPusherImpl.class);
private static Set<String> computeNotFoundCapabilities(Set<String> expectedCapabilities, NetconfOperationService serviceCandidate) {
Collection<String> actual = Collections2.transform(serviceCandidate.getCapabilities(), new Function<Capability, String>() {
@Override
- public String apply(Capability input) {
+ public String apply(@Nonnull final Capability input) {
return input.getCapabilityUri();
}
});
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.netty.util.internal.ConcurrentSet;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.Nonnull;
import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession;
import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
import org.opendaylight.controller.netconf.mapping.api.Capability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nullable;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, SessionMonitoringService {
private static final Logger logger = LoggerFactory.getLogger(NetconfMonitoringServiceImpl.class);
private List<Session> transformSessions(Set<NetconfManagementSession> sessions) {
return Lists.newArrayList(Collections2.transform(sessions, new Function<NetconfManagementSession, Session>() {
- @Nullable
@Override
- public Session apply(@Nullable NetconfManagementSession input) {
+ public Session apply(@Nonnull NetconfManagementSession input) {
return input.toManagementSession();
}
}));
this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot;
}
- private void initNetconfOperations(Set<NetconfOperation> allOperations) {
+ private synchronized void initNetconfOperations(Set<NetconfOperation> allOperations) {
allNetconfOperations = allOperations;
}
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2;
+import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema;
return Collections2.transform(schema.getLocation(), new Function<Schema.Location, String>() {
@Nullable
@Override
- public String apply(@Nullable Schema.Location input) {
+ public String apply(@Nonnull Schema.Location input) {
return input.getEnumeration().toString();
}
});
final AuthProvider authService = bundleContext.getService(reference);
final Integer newServicePreference = getPreference(reference);
if(isBetter(newServicePreference)) {
+ maxPreference = newServicePreference;
server.setAuthProvider(authService);
if(sshThread == null) {
sshThread = runNetconfSshThread(server);
}
@VisibleForTesting
- void setNullableUserManager(final IUserManager nullableUserManager) {
+ synchronized void setNullableUserManager(final IUserManager nullableUserManager) {
this.nullableUserManager = nullableUserManager;
}
}
rpcReply.appendChild(responseNS);
}
- for (String attrName : attributes.keySet()) {
- rpcReply.setAttributeNode((Attr) document.importNode(attributes.get(attrName), true));
+ for (Attr attribute : attributes.values()) {
+ rpcReply.setAttributeNode((Attr) document.importNode(attribute, true));
}
document.appendChild(rpcReply);
return document;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
-
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.Nonnull;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.api.NetconfMessage;
import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
-import javax.annotation.Nullable;
-
-import java.util.Collection;
-import java.util.List;
-
public final class NetconfMessageUtil {
private static final Logger logger = LoggerFactory.getLogger(NetconfMessageUtil.class);
List<XmlElement> caps = capabilitiesElement.getChildElements(XmlNetconfConstants.CAPABILITY);
return Collections2.transform(caps, new Function<XmlElement, String>() {
- @Nullable
@Override
- public String apply(@Nullable XmlElement input) {
+ public String apply(@Nonnull XmlElement input) {
// Trim possible leading/tailing whitespace
try {
return input.getTextContent().trim();
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.annotation.Nullable;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException;
import org.opendaylight.controller.netconf.util.exception.UnexpectedElementException;
return Lists.newArrayList(Collections2.filter(getChildElementsWithinNamespace(namespace),
new Predicate<XmlElement>() {
@Override
- public boolean apply(@Nullable XmlElement xmlElement) {
+ public boolean apply(XmlElement xmlElement) {
return xmlElement.getName().equals(childName);
}
}));
List<XmlElement> children = getChildElementsWithinNamespace(namespace);
children = Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
@Override
- public boolean apply(@Nullable XmlElement xmlElement) {
+ public boolean apply(XmlElement xmlElement) {
return xmlElement.getName().equals(childName);
}
}));
List<XmlElement> children = getChildElementsWithinNamespace(getNamespace());
return Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
@Override
- public boolean apply(@Nullable XmlElement xmlElement) {
+ public boolean apply(XmlElement xmlElement) {
return xmlElement.getName().equals(childName);
}
}));