}
}
assertEquals("Expected identities not found " + copyOfExpectedNames,
- Collections.EMPTY_MAP, copyOfExpectedNames);
+ Collections.emptyMap(), copyOfExpectedNames);
}
@Test
public static Props props(final ActorRef target){
return Props.create(new Creator<ClientActor>(){
+ private static final long serialVersionUID = 1L;
@Override public ClientActor create() throws Exception {
return new ClientActor(target);
public static Props props(final String id, final Map<String, String> peerAddresses,
final Optional<ConfigParams> configParams){
return Props.create(new Creator<ExampleActor>(){
+ private static final long serialVersionUID = 1L;
@Override public ExampleActor create() throws Exception {
return new ExampleActor(id, peerAddresses, configParams);
import java.util.Map;
public class KeyValue extends Payload implements Serializable {
+ private static final long serialVersionUID = 1L;
private String key;
private String value;
import java.io.Serializable;
public class KeyValueSaved implements Serializable {
+ private static final long serialVersionUID = 1L;
}
import java.io.Serializable;
public class PrintRole implements Serializable {
+ private static final long serialVersionUID = 1L;
}
import java.io.Serializable;
public class PrintState implements Serializable {
+ private static final long serialVersionUID = 1L;
}
}
static class DeleteEntries implements Serializable {
+ private static final long serialVersionUID = 1L;
private final int fromIndex;
-
public DeleteEntries(int fromIndex) {
this.fromIndex = fromIndex;
}
}
static class UpdateElectionTerm implements Serializable {
+ private static final long serialVersionUID = 1L;
private final long currentTerm;
private final String votedFor;
public class ReplicatedLogImplEntry implements ReplicatedLogEntry,
Serializable {
+ private static final long serialVersionUID = 1L;
private final long index;
private final long term;
public class Snapshot implements Serializable {
+ private static final long serialVersionUID = 1L;
private final byte[] state;
private final List<ReplicatedLogEntry> unAppliedEntries;
private final long lastIndex;
*
*/
public class ApplyLogEntries implements Serializable {
+ private static final long serialVersionUID = 1L;
private final int toIndex;
public ApplyLogEntries(int toIndex) {
* Internal message, issued by follower to its actor
*/
public class ApplySnapshot implements Serializable {
+ private static final long serialVersionUID = 1L;
private final Snapshot snapshot;
public ApplySnapshot(Snapshot snapshot) {
import java.io.Serializable;
public class ApplyState implements Serializable {
+ private static final long serialVersionUID = 1L;
private final ActorRef clientActor;
private final String identifier;
private final ReplicatedLogEntry replicatedLogEntry;
* Message sent to commit an entry to the log
*/
public class CommitEntry implements Serializable {
+ private static final long serialVersionUID = 1L;
}
import java.io.Serializable;
public class ElectionTimeout implements Serializable {
+ private static final long serialVersionUID = 1L;
}
* Message sent to Persist an entry into the transaction journal
*/
public class PersistEntry implements Serializable {
+ private static final long serialVersionUID = 1L;
}
import java.io.Serializable;
public class Replicate implements Serializable {
+ private static final long serialVersionUID = 1L;
private final ActorRef clientActor;
private final String identifier;
private final ReplicatedLogEntry replicatedLogEntry;
* it and use it to save it's state
*/
public class SaveSnapshot implements Serializable {
+ private static final long serialVersionUID = 1L;
}
* Typically the Leader to itself on a schedule
*/
public class SendHeartBeat implements Serializable {
+ private static final long serialVersionUID = 1L;
}
import java.io.Serializable;
public class FindLeader implements Serializable{
+ private static final long serialVersionUID = 1L;
}
import java.io.Serializable;
public class FindLeaderReply implements Serializable {
+ private static final long serialVersionUID = 1L;
private final String leaderActor;
public FindLeaderReply(String leaderActor) {
package org.opendaylight.controller.cluster.raft.messages;
public class AbstractRaftRPC implements RaftRPC {
+ private static final long serialVersionUID = 1L;
// term
protected long term;
* heartbeat (§5.2).
*/
public class AppendEntries extends AbstractRaftRPC {
-
public static final Class<AppendEntriesMessages.AppendEntries> SERIALIZABLE_CLASS = AppendEntriesMessages.AppendEntries.class;
private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(AppendEntries.class);
+ private static final long serialVersionUID = 1L;
// So that follower can redirect clients
private final String leaderId;
* Reply for the AppendEntriesRpc message
*/
public class AppendEntriesReply extends AbstractRaftRPC {
+ private static final long serialVersionUID = 1L;
// true if follower contained entry matching
// prevLogIndex and prevLogTerm
public class InstallSnapshot extends AbstractRaftRPC {
public static final Class<InstallSnapshotMessages.InstallSnapshot> SERIALIZABLE_CLASS = InstallSnapshotMessages.InstallSnapshot.class;
+ private static final long serialVersionUID = 1L;
private final String leaderId;
private final long lastIncludedIndex;
package org.opendaylight.controller.cluster.raft.messages;
public class InstallSnapshotReply extends AbstractRaftRPC {
+ private static final long serialVersionUID = 1L;
// The followerId - this will be used to figure out which follower is
// responding
* Invoked by candidates to gather votes (§5.2).
*/
public class RequestVote extends AbstractRaftRPC {
+ private static final long serialVersionUID = 1L;
// candidate requesting vote
private String candidateId;
package org.opendaylight.controller.cluster.raft.messages;
public class RequestVoteReply extends AbstractRaftRPC {
+ private static final long serialVersionUID = 1L;
// true means candidate received vot
private final boolean voteGranted;
}
public static class MockPayload extends Payload implements Serializable {
+ private static final long serialVersionUID = 1L;
private String value = "";
public MockPayload(){
}
public static class MockReplicatedLogEntry implements ReplicatedLogEntry, Serializable {
+ private static final long serialVersionUID = 1L;
private final long term;
private final long index;
private final RaftActor delegate;
public static final class MockRaftActorCreator implements Creator<MockRaftActor> {
+ private static final long serialVersionUID = 1L;
private final Map<String, String> peerAddresses;
private final String id;
private final Optional<ConfigParams> config;
super(actorSystem);
raftActor = this.getSystem().actorOf(MockRaftActor.props(actorName,
- Collections.EMPTY_MAP, Optional.<ConfigParams>absent()), actorName);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>absent()), actorName);
}
config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
ActorRef followerActor = getSystem().actorOf(MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config)), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config)), persistenceId);
watch(followerActor);
//reinstate the actor
TestActorRef<MockRaftActor> ref = TestActorRef.create(getSystem(),
- MockRaftActor.props(persistenceId, Collections.EMPTY_MAP,
+ MockRaftActor.props(persistenceId, Collections.<String,String>emptyMap(),
Optional.<ConfigParams>of(config)));
ref.underlyingActor().waitForRecoveryComplete();
config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config)), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config)), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), new DataPersistenceProviderMonitor()), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), new DataPersistenceProviderMonitor()), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
dataPersistenceProviderMonitor.setPersistLatch(persistLatch);
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), dataPersistenceProviderMonitor), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), dataPersistenceProviderMonitor), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(),
- MockRaftActor.props(persistenceId,Collections.EMPTY_MAP,
+ MockRaftActor.props(persistenceId,Collections.<String,String>emptyMap(),
Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), dataPersistenceProvider), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
DataPersistenceProviderMonitor dataPersistenceProviderMonitor = new DataPersistenceProviderMonitor();
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), dataPersistenceProviderMonitor), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), dataPersistenceProviderMonitor), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
DataPersistenceProviderMonitor dataPersistenceProviderMonitor = new DataPersistenceProviderMonitor();
TestActorRef<MockRaftActor> mockActorRef = TestActorRef.create(getSystem(), MockRaftActor.props(persistenceId,
- Collections.EMPTY_MAP, Optional.<ConfigParams>of(config), dataPersistenceProviderMonitor), persistenceId);
+ Collections.<String,String>emptyMap(), Optional.<ConfigParams>of(config), dataPersistenceProviderMonitor), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl;
import org.opendaylight.controller.cluster.raft.MockRaftActorContext;
import org.opendaylight.controller.cluster.raft.RaftActorContext;
+import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
import org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout;
import org.opendaylight.controller.cluster.raft.messages.AppendEntries;
import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
import org.opendaylight.controller.cluster.raft.messages.RequestVote;
import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply;
import org.opendaylight.controller.cluster.raft.utils.DoNothingActor;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-
import static org.junit.Assert.assertEquals;
public class CandidateTest extends AbstractRaftActorBehaviorTest {
Candidate candidate = new Candidate(createActorContext(getTestActor()));
- candidate.handleMessage(getTestActor(), new AppendEntries(0, "test", 0,0,Collections.EMPTY_LIST, 0));
+ candidate.handleMessage(getTestActor(), new AppendEntries(0, "test", 0,0,Collections.<ReplicatedLogEntry>emptyList(), 0));
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "AppendEntriesResponse") {
// do not put code outside this method, will run afterwards
if (registry.getMetrics().containsKey(metricName))
return; //already registered
- Gauge queueSize = getQueueSizeGuage(monitoredQueue);
+ Gauge<Integer> queueSize = getQueueSizeGuage(monitoredQueue);
registerQueueSizeMetric(metricName, queueSize);
}
public static class MeteredMessageQueue extends BoundedDequeBasedMailbox.MessageQueue {
+ private static final long serialVersionUID = 1L;
public MeteredMessageQueue(int capacity, FiniteDuration pushTimeOut) {
super(capacity, pushTimeOut);
}
}
- private Gauge getQueueSizeGuage(final MeteredMessageQueue monitoredQueue ){
+ private Gauge<Integer> getQueueSizeGuage(final MeteredMessageQueue monitoredQueue ){
return new Gauge<Integer>() {
@Override
public Integer getValue() {
};
}
- private void registerQueueSizeMetric(String metricName, Gauge metric){
+ private void registerQueueSizeMetric(String metricName, Gauge<Integer> metric){
try {
registry.register(metricName,metric);
} catch (IllegalArgumentException e) {
import java.io.Serializable;
public class Monitor implements Serializable {
+ private static final long serialVersionUID = 1L;
private final ActorRef actorRef;
public Monitor(ActorRef actorRef){
public class CompositeModificationPayload extends Payload implements
Serializable {
+ private static final long serialVersionUID = 1L;
private final PersistentMessages.CompositeModification modification;
public static Props props(final ReentrantLock lock){
return Props.create(new Creator<PingPongActor>(){
+ private static final long serialVersionUID = 1L;
@Override
public PingPongActor create() throws Exception {
return new PingPongActor(lock);
@Test
public void testInputXmlToCompositeNode() {
CompositeNode node = XmlUtils.inputXmlToCompositeNode(testRpc.getQName(), XML_CONTENT, schema);
- ImmutableList<SimpleNode> input = (ImmutableList)node.getValue().get(0).getValue();
- SimpleNode firstNode = input.get(0);
+ ImmutableList<SimpleNode<?>> input = (ImmutableList<SimpleNode<?>>)node.getValue().get(0).getValue();
+ SimpleNode<?> firstNode = input.get(0);
Assert.assertEquals("id", firstNode.getNodeType().getLocalName());
Assert.assertEquals("flowid", firstNode.getValue());
- SimpleNode secondNode = input.get(1);
+ SimpleNode<?> secondNode = input.get(1);
Assert.assertEquals("flow", secondNode.getNodeType().getLocalName());
YangInstanceIdentifier instance = (YangInstanceIdentifier) secondNode.getValue();
@Test
public void testInputCompositeNodeToXML() {
CompositeNode input = XmlUtils.inputXmlToCompositeNode(testRpc.getQName(), XML_CONTENT, schema);
- List<Node<?>> childNodes = new ArrayList();
+ List<Node<?>> childNodes = new ArrayList<>();
childNodes.add(input);
QName rpcQName = schema.getOperations().iterator().next().getQName();
CompositeNode node = new ImmutableCompositeNode(rpcQName, input.getValue(), ModifyAction.REPLACE);
private static class DataChangeListenerRegistrationCreator
implements Creator<DataChangeListenerRegistration> {
+ private static final long serialVersionUID = 1L;
final ListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
NormalizedNode<?, ?>>> registration;
}
static class SchemaContextModules implements Serializable {
+ private static final long serialVersionUID = 1L;
private final Set<String> modules;
SchemaContextModules(Set<String> modules){
package org.opendaylight.controller.cluster.datastore.exceptions;
public class NotInitializedException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
public NotInitializedException(String message) {
super(message);
}
package org.opendaylight.controller.cluster.datastore.exceptions;
public class PrimaryNotFoundException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
public PrimaryNotFoundException(String message){
super(message);
}
package org.opendaylight.controller.cluster.datastore.exceptions;
public class TimeoutException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
public TimeoutException(String message, Exception e){
super(message, e);
}
package org.opendaylight.controller.cluster.datastore.exceptions;
public class UnknownMessageException extends Exception {
+ private static final long serialVersionUID = 1L;
private final Object message;
public UnknownMessageException(Object message) {
import java.io.Serializable;
public class ActorInitialized implements Serializable {
+ private static final long serialVersionUID = 1L;
}
import java.io.Serializable;
public class ActorNotInitialized implements Serializable {
+ private static final long serialVersionUID = 1L;
}
throws Exception {
final CountDownLatch persistLatch = new CountDownLatch(1);
final Creator<ShardManager> creator = new Creator<ShardManager>() {
+ private static final long serialVersionUID = 1L;
@Override
public ShardManager create() throws Exception {
return new ShardManager(shardMrgIDSuffix, new MockClusterWrapper(), new MockConfiguration(), DatastoreContext.newBuilder().build()) {
}
private static class DelegatingShardManagerCreator implements Creator<ShardManager> {
+ private static final long serialVersionUID = 1L;
private Creator<ShardManager> delegate;
public DelegatingShardManagerCreator(Creator<ShardManager> delegate) {
import java.io.Serializable;
-public class XSQLColumn implements Serializable, Comparable {
+public class XSQLColumn implements Serializable, Comparable<Object> {
+ private static final long serialVersionUID = 4854919735031714751L;
+
private String name = null;
private String tableName = null;
private int charWidth = -1;
import org.opendaylight.controller.md.sal.dom.xsql.XSQLBluePrint;
public class JDBCCommand implements Serializable {
+ private static final long serialVersionUID = 1L;
+
public int type = 0;
public static final int TYPE_EXECUTE_QUERY = 1;
public static final int TYPE_QUERY_REPLY = 2;
}
}
- public void addRecord(ArrayList hierarchy) {
+ public void addRecord(ArrayList<?> hierarchy) {
Map rec = new HashMap();
for (int i = hierarchy.size() - 1; i >= 0; i--) {
Object element = hierarchy.get(i);
return true;
}
- public void addRecord(ArrayList hierarchy) {
+ public void addRecord(ArrayList<?> hierarchy) {
rs.addRecord(hierarchy);
}
import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForGetConfig(schemaContext.get());
w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaForGetConfig, codecProvider);
} else {
- final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForRpc(rpc, schemaContext.get());
- w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaForGetConfig, codecProvider);
+ final Optional<RpcDefinition> schemaForRpc = NetconfMessageTransformUtil.findSchemaForRpc(rpc, schemaContext.get());
+ if(schemaForRpc.isPresent()) {
+ final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForRpc(schemaForRpc.get());
+ w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaForGetConfig, codecProvider);
+ } else {
+ w3cPayload = toRpcRequestWithoutSchema(rpcPayload, codecProvider);
+ }
}
} else {
- w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, codecProvider);
+ w3cPayload = toRpcRequestWithoutSchema(rpcPayload, codecProvider);
}
} catch (final UnsupportedDataTypeException e) {
throw new IllegalArgumentException("Unable to create message", e);
return new NetconfMessage(w3cPayload);
}
+ private Document toRpcRequestWithoutSchema(final CompositeNodeTOImpl rpcPayload, final XmlCodecProvider codecProvider) {
+ return XmlDocumentUtils.toDocument(rpcPayload, codecProvider);
+ }
+
@Override
public synchronized RpcResult<CompositeNode> toRpcResult(final NetconfMessage message, final QName rpc) {
if(schemaContext.isPresent()) {
*/
package org.opendaylight.controller.sal.connect.netconf.util;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl;
import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
public class NetconfMessageTransformUtil {
public static final String MESSAGE_ID_ATTR = "message-id";
static Node<?> toNode(final YangInstanceIdentifier.NodeIdentifierWithPredicates argument, final Node<?> node) {
final List<Node<?>> list = new ArrayList<>();
for (final Map.Entry<QName, Object> arg : argument.getKeyValues().entrySet()) {
- list.add(new SimpleNodeTOImpl(arg.getKey(), null, arg.getValue()));
+ list.add(new SimpleNodeTOImpl<>(arg.getKey(), null, arg.getValue()));
}
if (node != null) {
list.add(node);
return new NodeContainerProxy(NETCONF_RPC_QNAME, Sets.<DataSchemaNode>newHashSet(editConfigProxy));
}
+
+ public static Optional<RpcDefinition> findSchemaForRpc(final QName rpcName, final SchemaContext schemaContext) {
+ Preconditions.checkNotNull(rpcName);
+ Preconditions.checkNotNull(schemaContext);
+
+ for (final RpcDefinition rpcDefinition : schemaContext.getOperations()) {
+ if(rpcDefinition.getQName().equals(rpcName)) {
+ return Optional.of(rpcDefinition);
+ }
+ }
+
+ return Optional.absent();
+ }
+
/**
* Creates artificial schema node for schema defined rpc. This artificial schema looks like:
* <pre>
* This makes the translation of schema defined rpc request
* to xml use schema which is crucial for some types of nodes e.g. identity-ref.
*/
- public static DataNodeContainer createSchemaForRpc(final QName rpcName, final SchemaContext schemaContext) {
- Preconditions.checkNotNull(rpcName);
- Preconditions.checkNotNull(schemaContext);
-
- for (final RpcDefinition rpcDefinition : schemaContext.getOperations()) {
- if(rpcDefinition.getQName().equals(rpcName)) {
- final NodeContainerProxy rpcBodyProxy = new NodeContainerProxy(rpcName, rpcDefinition.getInput().getChildNodes());
- return new NodeContainerProxy(NETCONF_RPC_QNAME, Sets.<DataSchemaNode>newHashSet(rpcBodyProxy));
- }
- }
-
- throw new IllegalArgumentException("Rpc " + rpcName + " not found in schema context " + schemaContext + ". Unable to invoke Rpc");
+ public static DataNodeContainer createSchemaForRpc(final RpcDefinition rpcDefinition) {
+ final NodeContainerProxy rpcBodyProxy = new NodeContainerProxy(rpcDefinition.getQName(), rpcDefinition.getInput().getChildNodes());
+ return new NodeContainerProxy(NETCONF_RPC_QNAME, Sets.<DataSchemaNode>newHashSet(rpcBodyProxy));
}
public static CompositeNodeTOImpl wrap(final QName name, final Node<?> node) {
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco 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.sal.connect.netconf.schema.mapping;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.opendaylight.controller.sal.connect.netconf.NetconfToRpcRequestTest;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+public class NetconfMessageTransformerTest {
+
+ private static final QName COMMIT_Q_NAME = QName.create("namespace", "2012-12-12", "commit");
+
+ @Test
+ public void testToRpcRequestNoSchemaForRequest() throws Exception {
+ final NetconfMessageTransformer netconfMessageTransformer = getTransformer();
+ final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(COMMIT_Q_NAME,
+ NodeFactory.createImmutableCompositeNode(COMMIT_Q_NAME, null, Collections.<Node<?>>emptyList()));
+ assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<commit"));
+ }
+
+ private NetconfMessageTransformer getTransformer() {
+ final NetconfMessageTransformer netconfMessageTransformer = new NetconfMessageTransformer();
+ netconfMessageTransformer.onGlobalContextUpdated(getSchema());
+ return netconfMessageTransformer;
+ }
+
+ @Test
+ public void testToRpcResultNoSchemaForResult() throws Exception {
+ final NetconfMessageTransformer netconfMessageTransformer = getTransformer();
+ final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument(
+ "<rpc-reply><ok/></rpc-reply>"
+ ));
+ final RpcResult<CompositeNode> compositeNodeRpcResult = netconfMessageTransformer.toRpcResult(response, COMMIT_Q_NAME);
+ assertTrue(compositeNodeRpcResult.isSuccessful());
+ assertEquals("ok", compositeNodeRpcResult.getResult().getValue().get(0).getKey().getLocalName());
+ }
+
+ public SchemaContext getSchema() {
+ final List<InputStream> modelsToParse = Collections
+ .singletonList(NetconfToRpcRequestTest.class.getResourceAsStream("/schemas/rpc-notification-subscription.yang"));
+ final YangParserImpl parser = new YangParserImpl();
+ final Set<Module> configModules = parser.parseYangModelsFromStreams(modelsToParse);
+ final SchemaContext cfgCtx = parser.resolveSchemaContext(configModules);
+ assertNotNull(cfgCtx);
+ return cfgCtx;
+ }
+}
final Broker.ProviderSession brokerSession,
final RpcProvisionRegistry rpcProvisionRegistry) {
return Props.create(new Creator<RpcManager>() {
+ private static final long serialVersionUID = 1L;
@Override
public RpcManager create() throws Exception {
return new RpcManager(schemaContext, brokerSession, rpcProvisionRegistry);
import java.io.Serializable;
public class ExecuteRpc implements Serializable {
+ private static final long serialVersionUID = 1L;
private final String inputCompositeNode;
private final QName rpc;
import java.io.Serializable;
public class InvokeRpc implements Serializable {
+ private static final long serialVersionUID = 1L;
private final QName rpc;
private final YangInstanceIdentifier identifier;
*/
package org.opendaylight.controller.remote.rpc.messages;
-
-
import java.io.Serializable;
public class RpcResponse implements Serializable {
+ private static final long serialVersionUID = 1L;
private final String resultCompositeNode;
public RpcResponse(final String resultCompositeNode) {
import java.util.Map;
public class RoutingTable implements Copier<RoutingTable>, Serializable {
+ private static final long serialVersionUID = 1L;
private Map<RpcRouter.RouteIdentifier<?, ?, ?>, Long> table = new HashMap<>();
private ActorRef router;
import java.io.Serializable;
public class BucketImpl<T extends Copier<T>> implements Bucket<T>, Serializable {
+ private static final long serialVersionUID = 1L;
private Long version = System.currentTimeMillis();
public static class BucketStoreMessages{
- public static class GetLocalBucket implements Serializable{}
+ public static class GetLocalBucket implements Serializable {
+ private static final long serialVersionUID = 1L;
+ }
public static class ContainsBucket implements Serializable {
+ private static final long serialVersionUID = 1L;
final private Bucket bucket;
public ContainsBucket(Bucket bucket){
}
public static class UpdateBucket extends ContainsBucket implements Serializable {
+ private static final long serialVersionUID = 1L;
public UpdateBucket(Bucket bucket){
super(bucket);
}
}
public static class GetLocalBucketReply extends ContainsBucket implements Serializable {
+ private static final long serialVersionUID = 1L;
public GetLocalBucketReply(Bucket bucket){
super(bucket);
}
}
- public static class GetAllBuckets implements Serializable{}
+ public static class GetAllBuckets implements Serializable {
+ private static final long serialVersionUID = 1L;
+ }
public static class GetBucketsByMembers implements Serializable{
+ private static final long serialVersionUID = 1L;
private Set<Address> members;
public GetBucketsByMembers(Set<Address> members){
}
public static class ContainsBuckets implements Serializable{
+ private static final long serialVersionUID = 1L;
private Map<Address, Bucket> buckets;
public ContainsBuckets(Map<Address, Bucket> buckets){
}
public static class GetAllBucketsReply extends ContainsBuckets implements Serializable{
+ private static final long serialVersionUID = 1L;
public GetAllBucketsReply(Map<Address, Bucket> buckets) {
super(buckets);
}
}
public static class GetBucketsByMembersReply extends ContainsBuckets implements Serializable{
+ private static final long serialVersionUID = 1L;
public GetBucketsByMembersReply(Map<Address, Bucket> buckets) {
super(buckets);
}
}
- public static class GetBucketVersions implements Serializable{}
+ public static class GetBucketVersions implements Serializable {
+ private static final long serialVersionUID = 1L;
+ }
public static class ContainsBucketVersions implements Serializable{
+ private static final long serialVersionUID = 1L;
Map<Address, Long> versions;
public ContainsBucketVersions(Map<Address, Long> versions) {
}
public static class GetBucketVersionsReply extends ContainsBucketVersions implements Serializable{
+ private static final long serialVersionUID = 1L;
public GetBucketVersionsReply(Map<Address, Long> versions) {
super(versions);
}
}
public static class UpdateRemoteBuckets extends ContainsBuckets implements Serializable{
+ private static final long serialVersionUID = 1L;
public UpdateRemoteBuckets(Map<Address, Bucket> buckets) {
super(buckets);
}
}
public static class GossiperMessages{
- public static class Tick implements Serializable {}
+ public static class Tick implements Serializable {
+ private static final long serialVersionUID = 1L;
+ }
- public static final class GossipTick extends Tick {}
+ public static final class GossipTick extends Tick {
+ private static final long serialVersionUID = 1L;
+ }
public static final class GossipStatus extends ContainsBucketVersions implements Serializable{
+ private static final long serialVersionUID = 1L;
private Address from;
public GossipStatus(Address from, Map<Address, Long> versions) {
}
public static final class GossipEnvelope extends ContainsBuckets implements Serializable {
+ private static final long serialVersionUID = 1L;
private final Address from;
private final Address to;
@Test
public void testReceiveGossipTick_WhenNoRemoteMemberShouldIgnore(){
- mockGossiper.setClusterMembers(Collections.EMPTY_LIST);
+ mockGossiper.setClusterMembers(Collections.<Address>emptyList());
doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(Address.class));
mockGossiper.receiveGossipTick();
verify(mockGossiper, times(0)).getLocalStatusAndSendTo(any(Address.class));
NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class);
NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
- SessionNegotiator sessionNegotiator = mock(SessionNegotiator.class);
+ SessionNegotiator<?> sessionNegotiator = mock(SessionNegotiator.class);
doReturn("").when(sessionNegotiator).toString();
doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(any(SessionListenerFactory.class), any(Channel.class), any(Promise.class));
ChannelPipeline pipeline = mock(ChannelPipeline.class);
@Test
public void testInitializeSessionNegotiator() throws Exception {
NetconfClientSessionNegotiatorFactory factory = mock(NetconfClientSessionNegotiatorFactory.class);
- SessionNegotiator sessionNegotiator = mock(SessionNegotiator.class);
+ SessionNegotiator<?> sessionNegotiator = mock(SessionNegotiator.class);
doReturn("").when(sessionNegotiator).toString();
doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(SessionListenerFactory.class), any(Channel.class), any(Promise.class));
NetconfClientSessionListener listener = mock(NetconfClientSessionListener.class);
import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword;
import org.opendaylight.controller.netconf.ssh.SshProxyServer;
+import org.opendaylight.controller.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil;
import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
import org.opendaylight.controller.netconf.util.xml.XmlUtil;
clientGroup = new NioEventLoopGroup();
minaTimerEx = Executors.newScheduledThreadPool(1);
sshProxyServer = new SshProxyServer(minaTimerEx, clientGroup, nioExec);
- sshProxyServer.bind(TLS_ADDRESS, NetconfConfigUtil.getNetconfLocalAddress(), new PasswordAuthenticator() {
+ sshProxyServer.bind(
+ new SshProxyServerConfigurationBuilder()
+ .setBindingAddress(TLS_ADDRESS)
+ .setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress())
+ .setAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(final String username, final String password, final ServerSession session) {
return true;
}
- }, new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString()));
+ })
+ .setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString()))
+ .setIdleTimeout(Integer.MAX_VALUE)
+ .createSshProxyServerConfiguration());
}
@After
import com.google.common.collect.Lists;
import io.netty.channel.EventLoopGroup;
-import io.netty.channel.local.LocalAddress;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousChannelGroup;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.sshd.SshServer;
import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.KeyPairProvider;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.io.IoAcceptor;
import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory;
import org.apache.sshd.common.util.CloseableUtils;
import org.apache.sshd.server.Command;
-import org.apache.sshd.server.PasswordAuthenticator;
+import org.apache.sshd.server.ServerFactoryManager;
/**
* Proxy SSH server that just delegates decrypted content to a delegate server within same VM.
this.sshServer = SshServer.setUpDefaultServer();
}
- public void bind(final InetSocketAddress bindingAddress, final LocalAddress localAddress, final PasswordAuthenticator authenticator, final KeyPairProvider keyPairProvider) throws IOException {
- sshServer.setHost(bindingAddress.getHostString());
- sshServer.setPort(bindingAddress.getPort());
+ public void bind(final SshProxyServerConfiguration sshProxyServerConfiguration) throws IOException {
+ sshServer.setHost(sshProxyServerConfiguration.getBindingAddress().getHostString());
+ sshServer.setPort(sshProxyServerConfiguration.getBindingAddress().getPort());
- sshServer.setPasswordAuthenticator(authenticator);
- sshServer.setKeyPairProvider(keyPairProvider);
+ sshServer.setPasswordAuthenticator(sshProxyServerConfiguration.getAuthenticator());
+ sshServer.setKeyPairProvider(sshProxyServerConfiguration.getKeyPairProvider());
sshServer.setIoServiceFactoryFactory(nioServiceWithPoolFactoryFactory);
sshServer.setScheduledExecutorService(minaTimerExecutor);
+ sshServer.setProperties(getProperties(sshProxyServerConfiguration));
final RemoteNetconfCommand.NetconfCommandFactory netconfCommandFactory =
- new RemoteNetconfCommand.NetconfCommandFactory(clientGroup, localAddress);
+ new RemoteNetconfCommand.NetconfCommandFactory(clientGroup, sshProxyServerConfiguration.getLocalAddress());
sshServer.setSubsystemFactories(Lists.<NamedFactory<Command>>newArrayList(netconfCommandFactory));
sshServer.start();
}
+ private static Map<String, String> getProperties(final SshProxyServerConfiguration sshProxyServerConfiguration) {
+ return new HashMap<String, String>()
+ {{
+ put(ServerFactoryManager.IDLE_TIMEOUT, String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
+ }};
+ }
+
@Override
public void close() {
try {
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco 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.netconf.ssh;
+
+import com.google.common.base.Preconditions;
+import io.netty.channel.local.LocalAddress;
+import java.net.InetSocketAddress;
+import org.apache.sshd.common.KeyPairProvider;
+import org.apache.sshd.server.PasswordAuthenticator;
+
+public final class SshProxyServerConfiguration {
+ private final InetSocketAddress bindingAddress;
+ private final LocalAddress localAddress;
+ private final PasswordAuthenticator authenticator;
+ private final KeyPairProvider keyPairProvider;
+ private final int idleTimeout;
+
+ SshProxyServerConfiguration(final InetSocketAddress bindingAddress, final LocalAddress localAddress, final PasswordAuthenticator authenticator, final KeyPairProvider keyPairProvider, final int idleTimeout) {
+ this.bindingAddress = Preconditions.checkNotNull(bindingAddress);
+ this.localAddress = Preconditions.checkNotNull(localAddress);
+ this.authenticator = Preconditions.checkNotNull(authenticator);
+ this.keyPairProvider = Preconditions.checkNotNull(keyPairProvider);
+ // Idle timeout cannot be disabled in the sshd by using =< 0 value
+ Preconditions.checkArgument(idleTimeout > 0, "Idle timeout has to be > 0");
+ this.idleTimeout = idleTimeout;
+ }
+
+ public InetSocketAddress getBindingAddress() {
+ return bindingAddress;
+ }
+
+ public LocalAddress getLocalAddress() {
+ return localAddress;
+ }
+
+ public PasswordAuthenticator getAuthenticator() {
+ return authenticator;
+ }
+
+ public KeyPairProvider getKeyPairProvider() {
+ return keyPairProvider;
+ }
+
+ public int getIdleTimeout() {
+ return idleTimeout;
+ }
+
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco 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.netconf.ssh;
+
+import io.netty.channel.local.LocalAddress;
+import java.net.InetSocketAddress;
+import org.apache.sshd.common.KeyPairProvider;
+import org.apache.sshd.server.PasswordAuthenticator;
+
+public final class SshProxyServerConfigurationBuilder {
+ private InetSocketAddress bindingAddress;
+ private LocalAddress localAddress;
+ private PasswordAuthenticator authenticator;
+ private KeyPairProvider keyPairProvider;
+ private int idleTimeout;
+
+ public SshProxyServerConfigurationBuilder setBindingAddress(final InetSocketAddress bindingAddress) {
+ this.bindingAddress = bindingAddress;
+ return this;
+ }
+
+ public SshProxyServerConfigurationBuilder setLocalAddress(final LocalAddress localAddress) {
+ this.localAddress = localAddress;
+ return this;
+ }
+
+ public SshProxyServerConfigurationBuilder setAuthenticator(final PasswordAuthenticator authenticator) {
+ this.authenticator = authenticator;
+ return this;
+ }
+
+ public SshProxyServerConfigurationBuilder setKeyPairProvider(final KeyPairProvider keyPairProvider) {
+ this.keyPairProvider = keyPairProvider;
+ return this;
+ }
+
+ public SshProxyServerConfigurationBuilder setIdleTimeout(final int idleTimeout) {
+ this.idleTimeout = idleTimeout;
+ return this;
+ }
+
+ public SshProxyServerConfiguration createSshProxyServerConfiguration() {
+ return new SshProxyServerConfiguration(bindingAddress, localAddress, authenticator, keyPairProvider, idleTimeout);
+ }
+
+ public SshProxyServerConfigurationBuilder create () {
+ return new SshProxyServerConfigurationBuilder();
+ }
+}
\ No newline at end of file
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FilenameUtils;
import org.apache.sshd.common.util.ThreadUtils;
import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
import org.opendaylight.controller.netconf.ssh.SshProxyServer;
+import org.opendaylight.controller.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.InfixProp;
import org.osgi.framework.BundleActivator;
private static final java.lang.String ALGORITHM = "RSA";
private static final int KEY_SIZE = 4096;
public static final int POOL_SIZE = 8;
+ private static final int DEFAULT_IDLE_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(20);
private ScheduledExecutorService minaTimerExecutor;
private NioEventLoopGroup clientGroup;
NetconfConfigUtil.getPrivateKeyKey());
final SshProxyServer sshProxyServer = new SshProxyServer(minaTimerExecutor, clientGroup, nioExecutor);
- sshProxyServer.bind(sshSocketAddress, localAddress, authProviderTracker, new PEMGeneratorHostKeyProvider(path, ALGORITHM, KEY_SIZE));
+ sshProxyServer.bind(
+ new SshProxyServerConfigurationBuilder()
+ .setBindingAddress(sshSocketAddress)
+ .setLocalAddress(localAddress)
+ .setAuthenticator(authProviderTracker)
+ .setKeyPairProvider(new PEMGeneratorHostKeyProvider(path, ALGORITHM, KEY_SIZE))
+ .setIdleTimeout(DEFAULT_IDLE_TIMEOUT)
+ .createSshProxyServerConfiguration());
return sshProxyServer;
}
import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword;
import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
import org.opendaylight.controller.netconf.ssh.SshProxyServer;
+import org.opendaylight.controller.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10831);
final SshProxyServer sshProxyServer = new SshProxyServer(minaTimerEx, nettyGroup, nioExec);
- sshProxyServer.bind(addr, NetconfConfigUtil.getNetconfLocalAddress(),
- new PasswordAuthenticator() {
+ sshProxyServer.bind(
+ new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress()).setAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(final String username, final String password, final ServerSession session) {
return true;
}
- }, new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString()));
+ }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
final EchoClientHandler echoClientHandler = connectClient(addr);
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.netconf.ssh.SshProxyServer;
+import org.opendaylight.controller.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceListener;
final InetSocketAddress addr = InetSocketAddress.createUnresolved(HOST, PORT);
server = new SshProxyServer(minaTimerEx, clientGroup, nioExec);
- server.bind(addr, NetconfConfigUtil.getNetconfLocalAddress(),
- new PasswordAuthenticator() {
+ server.bind(
+ new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress()).setAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(final String username, final String password, final ServerSession session) {
return true;
}
- }, new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString()));
+ }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
logger.info("SSH server started on " + PORT);
}
import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService;
import org.opendaylight.controller.netconf.ssh.SshProxyServer;
+import org.opendaylight.controller.netconf.ssh.SshProxyServerConfiguration;
+import org.opendaylight.controller.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
server = dispatcher.createLocalServer(tcpLocalAddress);
try {
final SshProxyServer sshServer = new SshProxyServer(minaTimerExecutor, nettyThreadgroup, nioExecutor);
- sshServer.bind(bindingAddress, tcpLocalAddress,
- new PasswordAuthenticator() {
- @Override
- public boolean authenticate(final String username, final String password, final ServerSession session) {
- // All connections are accepted
- return true;
- }
- }, keyPairProvider);
-
+ sshServer.bind(getSshConfiguration(bindingAddress, tcpLocalAddress));
sshWrappers.add(sshServer);
} catch (final Exception e) {
LOG.warn("Cannot start simulated device on {}, skipping", address, e);
return openDevices;
}
+ private SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress, final LocalAddress tcpLocalAddress) throws IOException {
+ return new SshProxyServerConfigurationBuilder()
+ .setBindingAddress(bindingAddress)
+ .setLocalAddress(tcpLocalAddress)
+ .setAuthenticator(new PasswordAuthenticator() {
+ @Override
+ public boolean authenticate(final String username, final String password, final ServerSession session) {
+ return true;
+ }
+ })
+ .setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString()))
+ .setIdleTimeout(Integer.MAX_VALUE)
+ .createSshProxyServerConfiguration();
+ }
+
private PEMGeneratorHostKeyProvider getPemGeneratorHostKeyProvider() {
try {
final Path tempFile = Files.createTempFile("tempKeyNetconfTest", "suffix");
import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
public class PaginatedRequestFactory {
+ private static final Comparator<INeutronObject> NEUTRON_OBJECT_COMPARATOR = new Comparator<INeutronObject>() {
+ @Override
+ public int compare(INeutronObject o1, INeutronObject o2) {
+ return o1.getID().compareTo(o2.getID());
+ }
+ };
public static class PaginationResults<T extends INeutronObject> {
List<T> collection;
}
}
+ private static final class MarkerObject implements INeutronObject {
+ private final String id;
+
+ MarkerObject(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getID() {
+ return id;
+ }
+
+ @Override
+ public void setID(String id) {
+ throw new UnsupportedOperationException("Marker has constant ID");
+ }
+ }
+
/*
* SuppressWarnings is needed because the compiler does not understand that we
* are actually safe here.
private static <T extends INeutronObject> PaginationResults<T> _paginate(Integer limit, String marker, Boolean pageReverse, UriInfo uriInfo, List<T> collection) {
List<NeutronPageLink> links = new ArrayList<>();
- Integer startPos = null;
+ final int startPos;
String startMarker;
String endMarker;
Boolean firstPage = false;
Boolean lastPage = false;
- Comparator<INeutronObject> neutronObjectComparator = new Comparator<INeutronObject>() {
- @Override
- public int compare(INeutronObject o1, INeutronObject o2) {
- return o1.getID().compareTo(o2.getID());
- }
- };
-
- Collections.sort(collection, neutronObjectComparator);
+ Collections.sort(collection, NEUTRON_OBJECT_COMPARATOR);
- if (marker == null) {
- startPos = 0;
- }
-
- else {
-
- class MarkerObject implements INeutronObject {
- private String id;
-
- @Override
- public String getID() {
- return id;
- }
-
- @Override
- public void setID(String id) {
- this.id = id;
- }
+ if (marker != null) {
+ int offset = Collections.binarySearch(collection, new MarkerObject(marker), NEUTRON_OBJECT_COMPARATOR);
+ if (offset < 0) {
+ throw new ResourceNotFoundException("UUID for marker: " + marker + " could not be found");
}
- INeutronObject markerObject = new MarkerObject();
-
- markerObject.setID(marker);
-
- startPos = Collections.binarySearch(collection, markerObject, neutronObjectComparator);
-
- if (!pageReverse){
- startPos = startPos + 1;
+ if (!pageReverse) {
+ startPos = offset + 1;
}
else {
- startPos = startPos - limit;
+ startPos = offset - limit;
}
-
}
-
- if (startPos == null) {
- throw new ResourceNotFoundException("UUID for marker:" + marker + " could not be found");
+ else {
+ startPos = 0;
}
if (startPos == 0){