Madan Jampani

Using latest atomix release candidate + Updates to CopycatTransport

Change-Id: I960af428ff733ee7467024811e3b3470e951ecb7
Showing 15 changed files with 92 additions and 62 deletions
...@@ -86,7 +86,7 @@ public class CopycatTransport implements Transport { ...@@ -86,7 +86,7 @@ public class CopycatTransport implements Transport {
86 86
87 /** 87 /**
88 * Maps {@link Address address} to {@link Endpoint endpoint}. 88 * Maps {@link Address address} to {@link Endpoint endpoint}.
89 - * @param address 89 + * @param address address
90 * @return end point 90 * @return end point
91 */ 91 */
92 public static Endpoint toEndpoint(Address address) { 92 public static Endpoint toEndpoint(Address address) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.store.primitives.impl; 16 package org.onosproject.store.primitives.impl;
17 17
18 import static com.google.common.base.Preconditions.checkNotNull; 18 import static com.google.common.base.Preconditions.checkNotNull;
19 +import static org.slf4j.LoggerFactory.getLogger;
19 20
20 import java.util.Set; 21 import java.util.Set;
21 import java.util.concurrent.CompletableFuture; 22 import java.util.concurrent.CompletableFuture;
...@@ -23,8 +24,10 @@ import java.util.concurrent.CompletableFuture; ...@@ -23,8 +24,10 @@ import java.util.concurrent.CompletableFuture;
23 import org.apache.commons.lang.math.RandomUtils; 24 import org.apache.commons.lang.math.RandomUtils;
24 import org.onosproject.cluster.PartitionId; 25 import org.onosproject.cluster.PartitionId;
25 import org.onosproject.store.cluster.messaging.MessagingService; 26 import org.onosproject.store.cluster.messaging.MessagingService;
27 +import org.slf4j.Logger;
26 28
27 import com.google.common.collect.Sets; 29 import com.google.common.collect.Sets;
30 +import com.google.common.primitives.Longs;
28 31
29 import io.atomix.catalyst.transport.Address; 32 import io.atomix.catalyst.transport.Address;
30 import io.atomix.catalyst.transport.Client; 33 import io.atomix.catalyst.transport.Client;
...@@ -36,26 +39,30 @@ import io.atomix.catalyst.util.concurrent.ThreadContext; ...@@ -36,26 +39,30 @@ import io.atomix.catalyst.util.concurrent.ThreadContext;
36 */ 39 */
37 public class CopycatTransportClient implements Client { 40 public class CopycatTransportClient implements Client {
38 41
42 + private final Logger log = getLogger(getClass());
39 private final PartitionId partitionId; 43 private final PartitionId partitionId;
40 private final MessagingService messagingService; 44 private final MessagingService messagingService;
41 private final CopycatTransport.Mode mode; 45 private final CopycatTransport.Mode mode;
46 + private final String newConnectionMessageSubject;
42 private final Set<CopycatTransportConnection> connections = Sets.newConcurrentHashSet(); 47 private final Set<CopycatTransportConnection> connections = Sets.newConcurrentHashSet();
43 48
44 CopycatTransportClient(PartitionId partitionId, MessagingService messagingService, CopycatTransport.Mode mode) { 49 CopycatTransportClient(PartitionId partitionId, MessagingService messagingService, CopycatTransport.Mode mode) {
45 this.partitionId = checkNotNull(partitionId); 50 this.partitionId = checkNotNull(partitionId);
46 this.messagingService = checkNotNull(messagingService); 51 this.messagingService = checkNotNull(messagingService);
47 this.mode = checkNotNull(mode); 52 this.mode = checkNotNull(mode);
53 + this.newConnectionMessageSubject = String.format("onos-copycat-server-connection-%s", partitionId);
48 } 54 }
49 55
50 @Override 56 @Override
51 public CompletableFuture<Connection> connect(Address remoteAddress) { 57 public CompletableFuture<Connection> connect(Address remoteAddress) {
52 ThreadContext context = ThreadContext.currentContextOrThrow(); 58 ThreadContext context = ThreadContext.currentContextOrThrow();
53 return messagingService.sendAndReceive(CopycatTransport.toEndpoint(remoteAddress), 59 return messagingService.sendAndReceive(CopycatTransport.toEndpoint(remoteAddress),
54 - PartitionManager.HELLO_MESSAGE_SUBJECT, 60 + newConnectionMessageSubject,
55 - "hello".getBytes()) 61 + Longs.toByteArray(nextConnectionId()))
56 - .thenApplyAsync(r -> { 62 + .thenApplyAsync(bytes -> {
63 + long connectionId = Longs.fromByteArray(bytes);
57 CopycatTransportConnection connection = new CopycatTransportConnection( 64 CopycatTransportConnection connection = new CopycatTransportConnection(
58 - nextConnectionId(), 65 + connectionId,
59 CopycatTransport.Mode.CLIENT, 66 CopycatTransport.Mode.CLIENT,
60 partitionId, 67 partitionId,
61 remoteAddress, 68 remoteAddress,
...@@ -64,6 +71,7 @@ public class CopycatTransportClient implements Client { ...@@ -64,6 +71,7 @@ public class CopycatTransportClient implements Client {
64 if (mode == CopycatTransport.Mode.CLIENT) { 71 if (mode == CopycatTransport.Mode.CLIENT) {
65 connection.setBidirectional(); 72 connection.setBidirectional();
66 } 73 }
74 + log.debug("Created new outgoing connection[id={}] to {}", connectionId, remoteAddress);
67 connections.add(connection); 75 connections.add(connection);
68 return connection; 76 return connection;
69 }, context.executor()); 77 }, context.executor());
......
...@@ -31,12 +31,14 @@ import org.apache.commons.io.IOUtils; ...@@ -31,12 +31,14 @@ import org.apache.commons.io.IOUtils;
31 import org.onlab.util.Tools; 31 import org.onlab.util.Tools;
32 import org.onosproject.cluster.PartitionId; 32 import org.onosproject.cluster.PartitionId;
33 import org.onosproject.store.cluster.messaging.MessagingService; 33 import org.onosproject.store.cluster.messaging.MessagingService;
34 +import org.slf4j.Logger;
34 35
35 import com.google.common.base.MoreObjects; 36 import com.google.common.base.MoreObjects;
36 import com.google.common.base.Throwables; 37 import com.google.common.base.Throwables;
37 import com.google.common.collect.Maps; 38 import com.google.common.collect.Maps;
38 39
39 import static com.google.common.base.Preconditions.checkNotNull; 40 import static com.google.common.base.Preconditions.checkNotNull;
41 +import static org.slf4j.LoggerFactory.getLogger;
40 import io.atomix.catalyst.transport.Address; 42 import io.atomix.catalyst.transport.Address;
41 import io.atomix.catalyst.transport.Connection; 43 import io.atomix.catalyst.transport.Connection;
42 import io.atomix.catalyst.transport.MessageHandler; 44 import io.atomix.catalyst.transport.MessageHandler;
...@@ -52,6 +54,7 @@ import io.atomix.catalyst.util.concurrent.ThreadContext; ...@@ -52,6 +54,7 @@ import io.atomix.catalyst.util.concurrent.ThreadContext;
52 */ 54 */
53 public class CopycatTransportConnection implements Connection { 55 public class CopycatTransportConnection implements Connection {
54 56
57 + private final Logger log = getLogger(getClass());
55 private final Listeners<Throwable> exceptionListeners = new Listeners<>(); 58 private final Listeners<Throwable> exceptionListeners = new Listeners<>();
56 private final Listeners<Connection> closeListeners = new Listeners<>(); 59 private final Listeners<Connection> closeListeners = new Listeners<>();
57 60
...@@ -82,11 +85,11 @@ public class CopycatTransportConnection implements Connection { ...@@ -82,11 +85,11 @@ public class CopycatTransportConnection implements Connection {
82 this.remoteAddress = checkNotNull(address); 85 this.remoteAddress = checkNotNull(address);
83 this.messagingService = checkNotNull(messagingService); 86 this.messagingService = checkNotNull(messagingService);
84 if (mode == CopycatTransport.Mode.CLIENT) { 87 if (mode == CopycatTransport.Mode.CLIENT) {
85 - this.outboundMessageSubject = String.format("onos-copycat-%s", partitionId); 88 + this.outboundMessageSubject = String.format("onos-copycat-server-%s", partitionId);
86 - this.inboundMessageSubject = String.format("onos-copycat-%s-%d", partitionId, connectionId); 89 + this.inboundMessageSubject = String.format("onos-copycat-client-%s-%d", partitionId, connectionId);
87 } else { 90 } else {
88 - this.outboundMessageSubject = String.format("onos-copycat-%s-%d", partitionId, connectionId); 91 + this.outboundMessageSubject = String.format("onos-copycat-client-%s-%d", partitionId, connectionId);
89 - this.inboundMessageSubject = String.format("onos-copycat-%s", partitionId); 92 + this.inboundMessageSubject = String.format("onos-copycat-server-%s", partitionId);
90 } 93 }
91 this.context = checkNotNull(context); 94 this.context = checkNotNull(context);
92 } 95 }
...@@ -203,6 +206,7 @@ public class CopycatTransportConnection implements Connection { ...@@ -203,6 +206,7 @@ public class CopycatTransportConnection implements Connection {
203 206
204 @Override 207 @Override
205 public CompletableFuture<Void> close() { 208 public CompletableFuture<Void> close() {
209 + log.debug("Closing connection[id={}, mode={}] to {}", connectionId, mode, remoteAddress);
206 closeListeners.forEach(listener -> listener.accept(this)); 210 closeListeners.forEach(listener -> listener.accept(this));
207 if (mode == CopycatTransport.Mode.CLIENT) { 211 if (mode == CopycatTransport.Mode.CLIENT) {
208 messagingService.unregisterHandler(inboundMessageSubject); 212 messagingService.unregisterHandler(inboundMessageSubject);
......
...@@ -35,6 +35,7 @@ import org.onosproject.store.cluster.messaging.MessagingService; ...@@ -35,6 +35,7 @@ import org.onosproject.store.cluster.messaging.MessagingService;
35 import org.slf4j.Logger; 35 import org.slf4j.Logger;
36 36
37 import com.google.common.collect.Maps; 37 import com.google.common.collect.Maps;
38 +import com.google.common.primitives.Longs;
38 39
39 import io.atomix.catalyst.transport.Address; 40 import io.atomix.catalyst.transport.Address;
40 import io.atomix.catalyst.transport.Connection; 41 import io.atomix.catalyst.transport.Connection;
...@@ -54,13 +55,15 @@ public class CopycatTransportServer implements Server { ...@@ -54,13 +55,15 @@ public class CopycatTransportServer implements Server {
54 private final ScheduledExecutorService executorService; 55 private final ScheduledExecutorService executorService;
55 private final PartitionId partitionId; 56 private final PartitionId partitionId;
56 private final MessagingService messagingService; 57 private final MessagingService messagingService;
57 - private final String messageSubject; 58 + private final String protocolMessageSubject;
59 + private final String newConnectionMessageSubject;
58 private final Map<Long, CopycatTransportConnection> connections = Maps.newConcurrentMap(); 60 private final Map<Long, CopycatTransportConnection> connections = Maps.newConcurrentMap();
59 61
60 CopycatTransportServer(PartitionId partitionId, MessagingService messagingService) { 62 CopycatTransportServer(PartitionId partitionId, MessagingService messagingService) {
61 this.partitionId = checkNotNull(partitionId); 63 this.partitionId = checkNotNull(partitionId);
62 this.messagingService = checkNotNull(messagingService); 64 this.messagingService = checkNotNull(messagingService);
63 - this.messageSubject = String.format("onos-copycat-%s", partitionId); 65 + this.protocolMessageSubject = String.format("onos-copycat-server-%s", partitionId);
66 + this.newConnectionMessageSubject = String.format("onos-copycat-server-connection-%s", partitionId);
64 this.executorService = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(), 67 this.executorService = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(),
65 new CatalystThreadFactory("copycat-server-p" + partitionId + "-%d")); 68 new CatalystThreadFactory("copycat-server-p" + partitionId + "-%d"));
66 } 69 }
...@@ -68,49 +71,49 @@ public class CopycatTransportServer implements Server { ...@@ -68,49 +71,49 @@ public class CopycatTransportServer implements Server {
68 @Override 71 @Override
69 public CompletableFuture<Void> listen(Address address, Consumer<Connection> listener) { 72 public CompletableFuture<Void> listen(Address address, Consumer<Connection> listener) {
70 if (listening.compareAndSet(false, true)) { 73 if (listening.compareAndSet(false, true)) {
71 - ThreadContext context = ThreadContext.currentContextOrThrow(); 74 + // message handler for all non-connection-establishment messages.
72 - listen(address, listener, context); 75 + messagingService.registerHandler(protocolMessageSubject, (sender, payload) -> {
76 + try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(payload))) {
77 + long connectionId = input.readLong();
78 + CopycatTransportConnection connection = connections.get(connectionId);
79 + if (connection == null) {
80 + throw new IOException("Closed connection");
73 } 81 }
74 - return listenFuture; 82 + byte[] messagePayload = IOUtils.toByteArray(input);
83 + return connection.handle(messagePayload);
84 + } catch (IOException e) {
85 + return Tools.exceptionalFuture(e);
75 } 86 }
87 + });
76 88
77 - private void listen(Address address, Consumer<Connection> listener, ThreadContext context) { 89 + // message handler for new connection attempts.
78 - messagingService.registerHandler(messageSubject, (sender, payload) -> { 90 + ThreadContext context = ThreadContext.currentContextOrThrow();
79 - try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(payload))) { 91 + messagingService.registerHandler(newConnectionMessageSubject, (sender, payload) -> {
80 - long connectionId = input.readLong(); 92 + long connectionId = Longs.fromByteArray(payload);
81 - AtomicBoolean newConnectionCreated = new AtomicBoolean(false); 93 + CopycatTransportConnection connection = new CopycatTransportConnection(connectionId,
82 - CopycatTransportConnection connection = connections.computeIfAbsent(connectionId, k -> {
83 - newConnectionCreated.set(true);
84 - CopycatTransportConnection newConnection = new CopycatTransportConnection(connectionId,
85 CopycatTransport.Mode.SERVER, 94 CopycatTransport.Mode.SERVER,
86 partitionId, 95 partitionId,
87 CopycatTransport.toAddress(sender), 96 CopycatTransport.toAddress(sender),
88 messagingService, 97 messagingService,
89 getOrCreateContext(context)); 98 getOrCreateContext(context));
90 - log.debug("Created new incoming connection {}", connectionId); 99 + connections.put(connectionId, connection);
91 - newConnection.closeListener(c -> connections.remove(connectionId, c)); 100 + connection.closeListener(c -> connections.remove(connectionId, c));
92 - return newConnection; 101 + log.debug("Created new incoming connection[id={}] from {}", connectionId, sender);
93 - }); 102 + return CompletableFuture.supplyAsync(() -> {
94 - byte[] request = IOUtils.toByteArray(input);
95 - return CompletableFuture.supplyAsync(
96 - () -> {
97 - if (newConnectionCreated.get()) {
98 listener.accept(connection); 103 listener.accept(connection);
99 - } 104 + // echo the connectionId back to indicate successful completion.
100 - return connection; 105 + return payload;
101 - }, context.executor()).thenCompose(c -> c.handle(request)); 106 + }, context.executor());
102 - } catch (IOException e) {
103 - return Tools.exceptionalFuture(e);
104 - }
105 - });
106 - context.execute(() -> {
107 - listenFuture.complete(null);
108 }); 107 });
108 + context.execute(() -> listenFuture.complete(null));
109 + }
110 + return listenFuture;
109 } 111 }
110 112
111 @Override 113 @Override
112 public CompletableFuture<Void> close() { 114 public CompletableFuture<Void> close() {
113 - messagingService.unregisterHandler(messageSubject); 115 + messagingService.unregisterHandler(newConnectionMessageSubject);
116 + messagingService.unregisterHandler(protocolMessageSubject);
114 executorService.shutdown(); 117 executorService.shutdown();
115 return CompletableFuture.completedFuture(null); 118 return CompletableFuture.completedFuture(null);
116 } 119 }
......
...@@ -54,7 +54,7 @@ public class DefaultCatalystTypeSerializerFactory implements TypeSerializerFacto ...@@ -54,7 +54,7 @@ public class DefaultCatalystTypeSerializerFactory implements TypeSerializerFacto
54 } 54 }
55 55
56 @Override 56 @Override
57 - public void write(T object, BufferOutput<?> buffer, 57 + public void write(T object, BufferOutput buffer,
58 io.atomix.catalyst.serializer.Serializer serializer) { 58 io.atomix.catalyst.serializer.Serializer serializer) {
59 try { 59 try {
60 byte[] payload = this.serializer.encode(object); 60 byte[] payload = this.serializer.encode(object);
...@@ -66,7 +66,7 @@ public class DefaultCatalystTypeSerializerFactory implements TypeSerializerFacto ...@@ -66,7 +66,7 @@ public class DefaultCatalystTypeSerializerFactory implements TypeSerializerFacto
66 } 66 }
67 67
68 @Override 68 @Override
69 - public T read(Class<T> type, BufferInput<?> buffer, 69 + public T read(Class<T> type, BufferInput buffer,
70 io.atomix.catalyst.serializer.Serializer serializer) { 70 io.atomix.catalyst.serializer.Serializer serializer) {
71 int size = buffer.readInt(); 71 int size = buffer.readInt();
72 try { 72 try {
......
...@@ -27,6 +27,7 @@ import java.util.stream.Collectors; ...@@ -27,6 +27,7 @@ import java.util.stream.Collectors;
27 27
28 import org.apache.felix.scr.annotations.Activate; 28 import org.apache.felix.scr.annotations.Activate;
29 import org.apache.felix.scr.annotations.Component; 29 import org.apache.felix.scr.annotations.Component;
30 +import org.apache.felix.scr.annotations.Deactivate;
30 import org.apache.felix.scr.annotations.Reference; 31 import org.apache.felix.scr.annotations.Reference;
31 import org.apache.felix.scr.annotations.ReferenceCardinality; 32 import org.apache.felix.scr.annotations.ReferenceCardinality;
32 import org.apache.felix.scr.annotations.Service; 33 import org.apache.felix.scr.annotations.Service;
...@@ -56,7 +57,6 @@ import com.google.common.collect.Maps; ...@@ -56,7 +57,6 @@ import com.google.common.collect.Maps;
56 public class PartitionManager extends AbstractListenerManager<PartitionEvent, PartitionEventListener> 57 public class PartitionManager extends AbstractListenerManager<PartitionEvent, PartitionEventListener>
57 implements PartitionService, PartitionAdminService { 58 implements PartitionService, PartitionAdminService {
58 59
59 - public static final String HELLO_MESSAGE_SUBJECT = "partition-manager-hello";
60 private final Logger log = getLogger(getClass()); 60 private final Logger log = getLogger(getClass());
61 61
62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -72,8 +72,6 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa ...@@ -72,8 +72,6 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa
72 72
73 @Activate 73 @Activate
74 public void activate() { 74 public void activate() {
75 - messagingService.registerHandler(HELLO_MESSAGE_SUBJECT,
76 - (ep, input) -> CompletableFuture.completedFuture(input));
77 eventDispatcher.addSink(PartitionEvent.class, listenerRegistry); 75 eventDispatcher.addSink(PartitionEvent.class, listenerRegistry);
78 76
79 metadataService.getClusterMetadata() 77 metadataService.getClusterMetadata()
...@@ -93,8 +91,8 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa ...@@ -93,8 +91,8 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa
93 log.info("Started"); 91 log.info("Started");
94 } 92 }
95 93
94 + @Deactivate
96 public void deactivate() { 95 public void deactivate() {
97 - messagingService.unregisterHandler(HELLO_MESSAGE_SUBJECT);
98 eventDispatcher.removeSink(PartitionEvent.class); 96 eventDispatcher.removeSink(PartitionEvent.class);
99 97
100 CompletableFuture<Void> closeFuture = CompletableFuture.allOf(partitions.values() 98 CompletableFuture<Void> closeFuture = CompletableFuture.allOf(partitions.values()
......
...@@ -90,7 +90,7 @@ public class StorageManager implements StorageService, StorageAdminService { ...@@ -90,7 +90,7 @@ public class StorageManager implements StorageService, StorageAdminService {
90 private TransactionCoordinator transactionCoordinator; 90 private TransactionCoordinator transactionCoordinator;
91 91
92 @Activate 92 @Activate
93 - public void actiavte() { 93 + public void activate() {
94 basePrimitiveCreator = partitionService.getDistributedPrimitiveCreator(PartitionId.from(0)); 94 basePrimitiveCreator = partitionService.getDistributedPrimitiveCreator(PartitionId.from(0));
95 Map<PartitionId, DistributedPrimitiveCreator> partitionMap = Maps.newHashMap(); 95 Map<PartitionId, DistributedPrimitiveCreator> partitionMap = Maps.newHashMap();
96 partitionService.getAllPartitionIds().stream() 96 partitionService.getAllPartitionIds().stream()
......
...@@ -19,14 +19,14 @@ import io.atomix.copycat.server.cluster.Member; ...@@ -19,14 +19,14 @@ import io.atomix.copycat.server.cluster.Member;
19 19
20 import java.util.Collection; 20 import java.util.Collection;
21 import java.util.Set; 21 import java.util.Set;
22 +import java.util.function.Function;
23 +import java.util.stream.Collectors;
22 24
23 import org.onosproject.cluster.PartitionId; 25 import org.onosproject.cluster.PartitionId;
24 import org.onosproject.store.service.PartitionInfo; 26 import org.onosproject.store.service.PartitionInfo;
25 27
26 import com.google.common.base.MoreObjects; 28 import com.google.common.base.MoreObjects;
27 -import com.google.common.collect.ImmutableList;
28 import com.google.common.collect.ImmutableSet; 29 import com.google.common.collect.ImmutableSet;
29 -import com.google.common.collect.Lists;
30 30
31 /** 31 /**
32 * Operational details for a {@code StoragePartition}. 32 * Operational details for a {@code StoragePartition}.
...@@ -98,9 +98,11 @@ public class StoragePartitionDetails { ...@@ -98,9 +98,11 @@ public class StoragePartitionDetails {
98 * @return partition info 98 * @return partition info
99 */ 99 */
100 public PartitionInfo toPartitionInfo() { 100 public PartitionInfo toPartitionInfo() {
101 + Function<Member, String> memberToString =
102 + m -> m == null ? "none" : String.format("%s:%d", m.address().host(), m.address().port());
101 return new PartitionInfo(partitionId.toString(), 103 return new PartitionInfo(partitionId.toString(),
102 leaderTerm, 104 leaderTerm,
103 - Lists.transform(ImmutableList.copyOf(activeMembers), m -> m.address().toString()), 105 + activeMembers.stream().map(memberToString).collect(Collectors.toList()),
104 - leader == null ? "none" : leader.address().toString()); 106 + memberToString.apply(leader));
105 } 107 }
106 } 108 }
......
...@@ -22,6 +22,7 @@ import io.atomix.catalyst.transport.Transport; ...@@ -22,6 +22,7 @@ import io.atomix.catalyst.transport.Transport;
22 import io.atomix.copycat.server.CopycatServer; 22 import io.atomix.copycat.server.CopycatServer;
23 import io.atomix.copycat.server.storage.Storage; 23 import io.atomix.copycat.server.storage.Storage;
24 import io.atomix.copycat.server.storage.StorageLevel; 24 import io.atomix.copycat.server.storage.StorageLevel;
25 +import io.atomix.manager.ResourceManagerTypeResolver;
25 import io.atomix.manager.state.ResourceManagerState; 26 import io.atomix.manager.state.ResourceManagerState;
26 import io.atomix.resource.ResourceRegistry; 27 import io.atomix.resource.ResourceRegistry;
27 import io.atomix.resource.ResourceType; 28 import io.atomix.resource.ResourceType;
...@@ -107,7 +108,7 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { ...@@ -107,7 +108,7 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> {
107 ResourceRegistry registry = new ResourceRegistry(); 108 ResourceRegistry registry = new ResourceRegistry();
108 resourceTypes.forEach(registry::register); 109 resourceTypes.forEach(registry::register);
109 resourceResolver.resolve(registry); 110 resourceResolver.resolve(registry);
110 - return CopycatServer.builder(localAddress, partition.getMemberAddresses()) 111 + CopycatServer server = CopycatServer.builder(localAddress, partition.getMemberAddresses())
111 .withName("partition-" + partition.getId()) 112 .withName("partition-" + partition.getId())
112 .withSerializer(serializer.clone()) 113 .withSerializer(serializer.clone())
113 .withTransport(transport.get()) 114 .withTransport(transport.get())
...@@ -119,6 +120,8 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { ...@@ -119,6 +120,8 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> {
119 .withMaxEntriesPerSegment(MAX_ENTRIES_PER_LOG_SEGMENT) 120 .withMaxEntriesPerSegment(MAX_ENTRIES_PER_LOG_SEGMENT)
120 .build()) 121 .build())
121 .build(); 122 .build();
123 + server.serializer().resolve(new ResourceManagerTypeResolver(registry));
124 + return server;
122 } 125 }
123 126
124 public Set<NodeId> configuredMembers() { 127 public Set<NodeId> configuredMembers() {
......
...@@ -43,8 +43,10 @@ import com.google.common.collect.Sets; ...@@ -43,8 +43,10 @@ import com.google.common.collect.Sets;
43 /** 43 /**
44 * Distributed resource providing the {@link AsyncConsistentMap} primitive. 44 * Distributed resource providing the {@link AsyncConsistentMap} primitive.
45 */ 45 */
46 -@ResourceTypeInfo(id = -151, stateMachine = AtomixConsistentMapState.class) 46 +@ResourceTypeInfo(id = -151,
47 -public class AtomixConsistentMap extends Resource<AtomixConsistentMap, Resource.Options> 47 + stateMachine = AtomixConsistentMapState.class,
48 + typeResolver = AtomixConsistentMapCommands.TypeResolver.class)
49 +public class AtomixConsistentMap extends Resource<AtomixConsistentMap>
48 implements AsyncConsistentMap<String, byte[]> { 50 implements AsyncConsistentMap<String, byte[]> {
49 51
50 private final Set<MapEventListener<String, byte[]>> mapEventListeners = Sets.newCopyOnWriteArraySet(); 52 private final Set<MapEventListener<String, byte[]>> mapEventListeners = Sets.newCopyOnWriteArraySet();
......
...@@ -26,6 +26,7 @@ import io.atomix.copycat.server.session.SessionListener; ...@@ -26,6 +26,7 @@ import io.atomix.copycat.server.session.SessionListener;
26 import io.atomix.copycat.server.storage.snapshot.SnapshotReader; 26 import io.atomix.copycat.server.storage.snapshot.SnapshotReader;
27 import io.atomix.copycat.server.storage.snapshot.SnapshotWriter; 27 import io.atomix.copycat.server.storage.snapshot.SnapshotWriter;
28 import io.atomix.resource.ResourceStateMachine; 28 import io.atomix.resource.ResourceStateMachine;
29 +import io.atomix.resource.ResourceType;
29 30
30 import java.util.Collection; 31 import java.util.Collection;
31 import java.util.HashMap; 32 import java.util.HashMap;
...@@ -69,12 +70,17 @@ import static com.google.common.base.Preconditions.checkState; ...@@ -69,12 +70,17 @@ import static com.google.common.base.Preconditions.checkState;
69 * State Machine for {@link AtomixConsistentMap} resource. 70 * State Machine for {@link AtomixConsistentMap} resource.
70 */ 71 */
71 public class AtomixConsistentMapState extends ResourceStateMachine implements SessionListener, Snapshottable { 72 public class AtomixConsistentMapState extends ResourceStateMachine implements SessionListener, Snapshottable {
73 +
72 private final Map<Long, Commit<? extends AtomixConsistentMapCommands.Listen>> listeners = new HashMap<>(); 74 private final Map<Long, Commit<? extends AtomixConsistentMapCommands.Listen>> listeners = new HashMap<>();
73 private final Map<String, MapEntryValue> mapEntries = new HashMap<>(); 75 private final Map<String, MapEntryValue> mapEntries = new HashMap<>();
74 private final Set<String> preparedKeys = Sets.newHashSet(); 76 private final Set<String> preparedKeys = Sets.newHashSet();
75 private final Map<TransactionId, Commit<? extends TransactionPrepare>> pendingTransactions = Maps.newHashMap(); 77 private final Map<TransactionId, Commit<? extends TransactionPrepare>> pendingTransactions = Maps.newHashMap();
76 private AtomicLong versionCounter = new AtomicLong(0); 78 private AtomicLong versionCounter = new AtomicLong(0);
77 79
80 + public AtomixConsistentMapState() {
81 + super(new ResourceType(AtomixConsistentMap.class));
82 + }
83 +
78 @Override 84 @Override
79 public void snapshot(SnapshotWriter writer) { 85 public void snapshot(SnapshotWriter writer) {
80 writer.writeLong(versionCounter.get()); 86 writer.writeLong(versionCounter.get());
......
...@@ -25,7 +25,6 @@ import java.util.Set; ...@@ -25,7 +25,6 @@ import java.util.Set;
25 import java.util.concurrent.CompletableFuture; 25 import java.util.concurrent.CompletableFuture;
26 import java.util.function.Consumer; 26 import java.util.function.Consumer;
27 27
28 -import org.onlab.util.SharedExecutors;
29 import org.onosproject.cluster.Leadership; 28 import org.onosproject.cluster.Leadership;
30 import org.onosproject.cluster.NodeId; 29 import org.onosproject.cluster.NodeId;
31 import org.onosproject.event.Change; 30 import org.onosproject.event.Change;
...@@ -36,8 +35,10 @@ import com.google.common.collect.Sets; ...@@ -36,8 +35,10 @@ import com.google.common.collect.Sets;
36 /** 35 /**
37 * Distributed resource providing the {@link AsyncLeaderElector} primitive. 36 * Distributed resource providing the {@link AsyncLeaderElector} primitive.
38 */ 37 */
39 -@ResourceTypeInfo(id = -152, stateMachine = AtomixLeaderElectorState.class) 38 +@ResourceTypeInfo(id = -152,
40 -public class AtomixLeaderElector extends Resource<AtomixLeaderElector, Resource.Options> 39 + stateMachine = AtomixLeaderElectorState.class,
40 + typeResolver = AtomixLeaderElectorCommands.TypeResolver.class)
41 +public class AtomixLeaderElector extends Resource<AtomixLeaderElector>
41 implements AsyncLeaderElector { 42 implements AsyncLeaderElector {
42 private final Set<Consumer<Change<Leadership>>> leadershipChangeListeners = 43 private final Set<Consumer<Change<Leadership>>> leadershipChangeListeners =
43 Sets.newConcurrentHashSet(); 44 Sets.newConcurrentHashSet();
...@@ -62,8 +63,7 @@ public class AtomixLeaderElector extends Resource<AtomixLeaderElector, Resource. ...@@ -62,8 +63,7 @@ public class AtomixLeaderElector extends Resource<AtomixLeaderElector, Resource.
62 } 63 }
63 64
64 private void handleEvent(Change<Leadership> change) { 65 private void handleEvent(Change<Leadership> change) {
65 - SharedExecutors.getSingleThreadExecutor().execute(() -> 66 + leadershipChangeListeners.forEach(l -> l.accept(change));
66 - leadershipChangeListeners.forEach(l -> l.accept(change)));
67 } 67 }
68 68
69 @Override 69 @Override
......
...@@ -24,6 +24,7 @@ import io.atomix.copycat.server.session.SessionListener; ...@@ -24,6 +24,7 @@ import io.atomix.copycat.server.session.SessionListener;
24 import io.atomix.copycat.server.storage.snapshot.SnapshotReader; 24 import io.atomix.copycat.server.storage.snapshot.SnapshotReader;
25 import io.atomix.copycat.server.storage.snapshot.SnapshotWriter; 25 import io.atomix.copycat.server.storage.snapshot.SnapshotWriter;
26 import io.atomix.resource.ResourceStateMachine; 26 import io.atomix.resource.ResourceStateMachine;
27 +import io.atomix.resource.ResourceType;
27 28
28 import java.util.Arrays; 29 import java.util.Arrays;
29 import java.util.HashMap; 30 import java.util.HashMap;
...@@ -72,6 +73,10 @@ public class AtomixLeaderElectorState extends ResourceStateMachine ...@@ -72,6 +73,10 @@ public class AtomixLeaderElectorState extends ResourceStateMachine
72 ElectionState.class, 73 ElectionState.class,
73 Registration.class); 74 Registration.class);
74 75
76 + public AtomixLeaderElectorState() {
77 + super(new ResourceType(AtomixLeaderElector.class));
78 + }
79 +
75 @Override 80 @Override
76 protected void configure(StateMachineExecutor executor) { 81 protected void configure(StateMachineExecutor executor) {
77 // Notification 82 // Notification
...@@ -261,7 +266,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine ...@@ -261,7 +266,7 @@ public class AtomixLeaderElectorState extends ResourceStateMachine
261 } 266 }
262 267
263 private void onSessionEnd(Session session) { 268 private void onSessionEnd(Session session) {
264 - Commit<? extends AtomixLeaderElectorCommands.Listen> listener = listeners.remove(session); 269 + Commit<? extends AtomixLeaderElectorCommands.Listen> listener = listeners.remove(session.id());
265 if (listener != null) { 270 if (listener != null) {
266 listener.close(); 271 listener.close();
267 } 272 }
......
...@@ -110,7 +110,6 @@ public abstract class AtomixTestBase { ...@@ -110,7 +110,6 @@ public abstract class AtomixTestBase {
110 .withStorage(Storage.builder() 110 .withStorage(Storage.builder()
111 .withStorageLevel(StorageLevel.DISK) 111 .withStorageLevel(StorageLevel.DISK)
112 .withDirectory(TEST_DIR + "/" + address.port()) 112 .withDirectory(TEST_DIR + "/" + address.port())
113 - .withSerializer(serializer.clone())
114 .build()) 113 .build())
115 .withStateMachine(() -> new ResourceManagerState(resourceRegistry)) 114 .withStateMachine(() -> new ResourceManagerState(resourceRegistry))
116 .withSerializer(serializer.clone()) 115 .withSerializer(serializer.clone())
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
79 <onos-build-conf.version>1.2-SNAPSHOT</onos-build-conf.version> 79 <onos-build-conf.version>1.2-SNAPSHOT</onos-build-conf.version>
80 <netty4.version>4.0.33.Final</netty4.version> 80 <netty4.version>4.0.33.Final</netty4.version>
81 <!-- TODO: replace with final release version when it is out --> 81 <!-- TODO: replace with final release version when it is out -->
82 - <atomix.version>0.1.0-beta5</atomix.version> 82 + <atomix.version>1.0.0-rc1</atomix.version>
83 <copycat.version>0.5.1.onos</copycat.version> 83 <copycat.version>0.5.1.onos</copycat.version>
84 <openflowj.version>0.9.1.onos</openflowj.version> 84 <openflowj.version>0.9.1.onos</openflowj.version>
85 <onos-maven-plugin.version>1.8-SNAPSHOT</onos-maven-plugin.version> 85 <onos-maven-plugin.version>1.8-SNAPSHOT</onos-maven-plugin.version>
......