Committed by
Gerrit Code Review
Moving to Atomix version 1.0.0-rc3
Change-Id: I75572a52b530741f482455d59922327121a03999
Showing
15 changed files
with
170 additions
and
118 deletions
... | @@ -20,6 +20,8 @@ import java.util.Arrays; | ... | @@ -20,6 +20,8 @@ import java.util.Arrays; |
20 | import io.atomix.catalyst.serializer.Serializer; | 20 | import io.atomix.catalyst.serializer.Serializer; |
21 | import io.atomix.catalyst.serializer.TypeSerializerFactory; | 21 | import io.atomix.catalyst.serializer.TypeSerializerFactory; |
22 | import io.atomix.copycat.Query; | 22 | import io.atomix.copycat.Query; |
23 | +import io.atomix.manager.util.ResourceManagerTypeResolver; | ||
24 | +import io.atomix.variables.state.LongCommands; | ||
23 | 25 | ||
24 | import org.onlab.util.Match; | 26 | import org.onlab.util.Match; |
25 | import org.onosproject.cluster.Leader; | 27 | import org.onosproject.cluster.Leader; |
... | @@ -28,6 +30,10 @@ import org.onosproject.cluster.NodeId; | ... | @@ -28,6 +30,10 @@ import org.onosproject.cluster.NodeId; |
28 | import org.onosproject.event.Change; | 30 | import org.onosproject.event.Change; |
29 | import org.onosproject.store.primitives.MapUpdate; | 31 | import org.onosproject.store.primitives.MapUpdate; |
30 | import org.onosproject.store.primitives.TransactionId; | 32 | import org.onosproject.store.primitives.TransactionId; |
33 | +import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands; | ||
34 | +import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapFactory; | ||
35 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands; | ||
36 | +import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorFactory; | ||
31 | import org.onosproject.store.primitives.resources.impl.CommitResult; | 37 | import org.onosproject.store.primitives.resources.impl.CommitResult; |
32 | import org.onosproject.store.primitives.resources.impl.MapEntryUpdateResult; | 38 | import org.onosproject.store.primitives.resources.impl.MapEntryUpdateResult; |
33 | import org.onosproject.store.primitives.resources.impl.PrepareResult; | 39 | import org.onosproject.store.primitives.resources.impl.PrepareResult; |
... | @@ -79,6 +85,14 @@ public final class CatalystSerializers { | ... | @@ -79,6 +85,14 @@ public final class CatalystSerializers { |
79 | serializer.register(MapEvent.class, factory); | 85 | serializer.register(MapEvent.class, factory); |
80 | serializer.register(Maps.immutableEntry("a", "b").getClass(), factory); | 86 | serializer.register(Maps.immutableEntry("a", "b").getClass(), factory); |
81 | 87 | ||
88 | + serializer.resolve(new LongCommands.TypeResolver()); | ||
89 | + serializer.resolve(new AtomixConsistentMapCommands.TypeResolver()); | ||
90 | + serializer.resolve(new AtomixLeaderElectorCommands.TypeResolver()); | ||
91 | + serializer.resolve(new ResourceManagerTypeResolver()); | ||
92 | + | ||
93 | + serializer.registerClassLoader(AtomixConsistentMapFactory.class) | ||
94 | + .registerClassLoader(AtomixLeaderElectorFactory.class); | ||
95 | + | ||
82 | return serializer; | 96 | return serializer; |
83 | } | 97 | } |
84 | } | 98 | } | ... | ... |
... | @@ -41,10 +41,4 @@ public interface Managed<T> { | ... | @@ -41,10 +41,4 @@ public interface Managed<T> { |
41 | * @return {@code true} if open | 41 | * @return {@code true} if open |
42 | */ | 42 | */ |
43 | boolean isOpen(); | 43 | boolean isOpen(); |
44 | - | ||
45 | - /** | ||
46 | - * Return {@code true} if the managed object is closed. | ||
47 | - * @return {@code true} if closed | ||
48 | - */ | ||
49 | - boolean isClosed(); | ||
50 | } | 44 | } | ... | ... |
... | @@ -47,21 +47,20 @@ import com.google.common.collect.ImmutableSet; | ... | @@ -47,21 +47,20 @@ import com.google.common.collect.ImmutableSet; |
47 | public class StoragePartition implements Managed<StoragePartition> { | 47 | public class StoragePartition implements Managed<StoragePartition> { |
48 | 48 | ||
49 | private final AtomicBoolean isOpened = new AtomicBoolean(false); | 49 | private final AtomicBoolean isOpened = new AtomicBoolean(false); |
50 | - private final AtomicBoolean isClosed = new AtomicBoolean(false); | ||
51 | private final Serializer serializer; | 50 | private final Serializer serializer; |
52 | private final MessagingService messagingService; | 51 | private final MessagingService messagingService; |
53 | private final ClusterService clusterService; | 52 | private final ClusterService clusterService; |
54 | private final File logFolder; | 53 | private final File logFolder; |
55 | private Partition partition; | 54 | private Partition partition; |
56 | - private static final Collection<ResourceType> RESOURCE_TYPES = ImmutableSet.of( | ||
57 | - new ResourceType(DistributedLong.class), | ||
58 | - new ResourceType(AtomixLeaderElector.class), | ||
59 | - new ResourceType(AtomixConsistentMap.class)); | ||
60 | - | ||
61 | private NodeId localNodeId; | 55 | private NodeId localNodeId; |
62 | private StoragePartitionServer server; | 56 | private StoragePartitionServer server; |
63 | private StoragePartitionClient client; | 57 | private StoragePartitionClient client; |
64 | 58 | ||
59 | + public static final Collection<ResourceType> RESOURCE_TYPES = ImmutableSet.of( | ||
60 | + new ResourceType(DistributedLong.class), | ||
61 | + new ResourceType(AtomixLeaderElector.class), | ||
62 | + new ResourceType(AtomixConsistentMap.class)); | ||
63 | + | ||
65 | public StoragePartition(Partition partition, | 64 | public StoragePartition(Partition partition, |
66 | MessagingService messagingService, | 65 | MessagingService messagingService, |
67 | ClusterService clusterService, | 66 | ClusterService clusterService, |
... | @@ -96,8 +95,7 @@ public class StoragePartition implements Managed<StoragePartition> { | ... | @@ -96,8 +95,7 @@ public class StoragePartition implements Managed<StoragePartition> { |
96 | public CompletableFuture<Void> close() { | 95 | public CompletableFuture<Void> close() { |
97 | // We do not explicitly close the server and instead let the cluster | 96 | // We do not explicitly close the server and instead let the cluster |
98 | // deal with this as an unclean exit. | 97 | // deal with this as an unclean exit. |
99 | - return closeClient().thenAccept(v -> isClosed.set(true)) | 98 | + return closeClient(); |
100 | - .thenApply(v -> null); | ||
101 | } | 99 | } |
102 | 100 | ||
103 | /** | 101 | /** |
... | @@ -138,7 +136,6 @@ public class StoragePartition implements Managed<StoragePartition> { | ... | @@ -138,7 +136,6 @@ public class StoragePartition implements Managed<StoragePartition> { |
138 | () -> new CopycatTransport(CopycatTransport.Mode.SERVER, | 136 | () -> new CopycatTransport(CopycatTransport.Mode.SERVER, |
139 | partition.getId(), | 137 | partition.getId(), |
140 | messagingService), | 138 | messagingService), |
141 | - RESOURCE_TYPES, | ||
142 | logFolder); | 139 | logFolder); |
143 | return server.open().thenRun(() -> this.server = server); | 140 | return server.open().thenRun(() -> this.server = server); |
144 | } | 141 | } |
... | @@ -158,7 +155,6 @@ public class StoragePartition implements Managed<StoragePartition> { | ... | @@ -158,7 +155,6 @@ public class StoragePartition implements Managed<StoragePartition> { |
158 | () -> new CopycatTransport(CopycatTransport.Mode.SERVER, | 155 | () -> new CopycatTransport(CopycatTransport.Mode.SERVER, |
159 | partition.getId(), | 156 | partition.getId(), |
160 | messagingService), | 157 | messagingService), |
161 | - RESOURCE_TYPES, | ||
162 | logFolder); | 158 | logFolder); |
163 | return server.join(Collections2.transform(otherMembers, this::toAddress)).thenRun(() -> this.server = server); | 159 | return server.join(Collections2.transform(otherMembers, this::toAddress)).thenRun(() -> this.server = server); |
164 | } | 160 | } |
... | @@ -168,8 +164,7 @@ public class StoragePartition implements Managed<StoragePartition> { | ... | @@ -168,8 +164,7 @@ public class StoragePartition implements Managed<StoragePartition> { |
168 | serializer, | 164 | serializer, |
169 | new CopycatTransport(CopycatTransport.Mode.CLIENT, | 165 | new CopycatTransport(CopycatTransport.Mode.CLIENT, |
170 | partition.getId(), | 166 | partition.getId(), |
171 | - messagingService), | 167 | + messagingService)); |
172 | - RESOURCE_TYPES); | ||
173 | return client.open().thenApply(v -> client); | 168 | return client.open().thenApply(v -> client); |
174 | } | 169 | } |
175 | 170 | ||
... | @@ -183,12 +178,7 @@ public class StoragePartition implements Managed<StoragePartition> { | ... | @@ -183,12 +178,7 @@ public class StoragePartition implements Managed<StoragePartition> { |
183 | 178 | ||
184 | @Override | 179 | @Override |
185 | public boolean isOpen() { | 180 | public boolean isOpen() { |
186 | - return isOpened.get() && !isClosed.get(); | 181 | + return isOpened.get(); |
187 | - } | ||
188 | - | ||
189 | - @Override | ||
190 | - public boolean isClosed() { | ||
191 | - return isClosed.get(); | ||
192 | } | 182 | } |
193 | 183 | ||
194 | private CompletableFuture<Void> closeClient() { | 184 | private CompletableFuture<Void> closeClient() { |
... | @@ -209,7 +199,7 @@ public class StoragePartition implements Managed<StoragePartition> { | ... | @@ -209,7 +199,7 @@ public class StoragePartition implements Managed<StoragePartition> { |
209 | * @return partition info | 199 | * @return partition info |
210 | */ | 200 | */ |
211 | public Optional<PartitionInfo> info() { | 201 | public Optional<PartitionInfo> info() { |
212 | - return server != null && !server.isClosed() ? Optional.of(server.info()) : Optional.empty(); | 202 | + return server != null && server.isOpen() ? Optional.of(server.info()) : Optional.empty(); |
213 | } | 203 | } |
214 | 204 | ||
215 | public void onUpdate(Partition newValue) { | 205 | public void onUpdate(Partition newValue) { | ... | ... |
... | @@ -19,10 +19,8 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -19,10 +19,8 @@ import static org.slf4j.LoggerFactory.getLogger; |
19 | import io.atomix.Atomix; | 19 | import io.atomix.Atomix; |
20 | import io.atomix.AtomixClient; | 20 | import io.atomix.AtomixClient; |
21 | import io.atomix.catalyst.transport.Transport; | 21 | import io.atomix.catalyst.transport.Transport; |
22 | -import io.atomix.resource.ResourceType; | ||
23 | import io.atomix.variables.DistributedLong; | 22 | import io.atomix.variables.DistributedLong; |
24 | 23 | ||
25 | -import java.util.Collection; | ||
26 | import java.util.Set; | 24 | import java.util.Set; |
27 | import java.util.concurrent.CompletableFuture; | 25 | import java.util.concurrent.CompletableFuture; |
28 | 26 | ||
... | @@ -43,7 +41,6 @@ import org.slf4j.Logger; | ... | @@ -43,7 +41,6 @@ import org.slf4j.Logger; |
43 | 41 | ||
44 | import com.google.common.base.Supplier; | 42 | import com.google.common.base.Supplier; |
45 | import com.google.common.base.Suppliers; | 43 | import com.google.common.base.Suppliers; |
46 | -import com.google.common.collect.ImmutableSet; | ||
47 | 44 | ||
48 | /** | 45 | /** |
49 | * StoragePartition client. | 46 | * StoragePartition client. |
... | @@ -55,7 +52,6 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -55,7 +52,6 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
55 | private final StoragePartition partition; | 52 | private final StoragePartition partition; |
56 | private final Transport transport; | 53 | private final Transport transport; |
57 | private final io.atomix.catalyst.serializer.Serializer serializer; | 54 | private final io.atomix.catalyst.serializer.Serializer serializer; |
58 | - private final Collection<ResourceType> resourceTypes; | ||
59 | private Atomix client; | 55 | private Atomix client; |
60 | private static final String ATOMIC_VALUES_CONSISTENT_MAP_NAME = "onos-atomic-values"; | 56 | private static final String ATOMIC_VALUES_CONSISTENT_MAP_NAME = "onos-atomic-values"; |
61 | private final Supplier<AsyncConsistentMap<String, byte[]>> onosAtomicValuesMap = | 57 | private final Supplier<AsyncConsistentMap<String, byte[]>> onosAtomicValuesMap = |
... | @@ -64,12 +60,10 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -64,12 +60,10 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
64 | 60 | ||
65 | public StoragePartitionClient(StoragePartition partition, | 61 | public StoragePartitionClient(StoragePartition partition, |
66 | io.atomix.catalyst.serializer.Serializer serializer, | 62 | io.atomix.catalyst.serializer.Serializer serializer, |
67 | - Transport transport, | 63 | + Transport transport) { |
68 | - Collection<ResourceType> resourceTypes) { | ||
69 | this.partition = partition; | 64 | this.partition = partition; |
70 | this.serializer = serializer; | 65 | this.serializer = serializer; |
71 | this.transport = transport; | 66 | this.transport = transport; |
72 | - this.resourceTypes = ImmutableSet.copyOf(resourceTypes); | ||
73 | } | 67 | } |
74 | 68 | ||
75 | @Override | 69 | @Override |
... | @@ -79,10 +73,8 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -79,10 +73,8 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
79 | } | 73 | } |
80 | synchronized (StoragePartitionClient.this) { | 74 | synchronized (StoragePartitionClient.this) { |
81 | client = AtomixClient.builder(partition.getMemberAddresses()) | 75 | client = AtomixClient.builder(partition.getMemberAddresses()) |
76 | + .withResourceTypes(StoragePartition.RESOURCE_TYPES) | ||
82 | .withSerializer(serializer.clone()) | 77 | .withSerializer(serializer.clone()) |
83 | - .withResourceResolver(r -> { | ||
84 | - resourceTypes.forEach(r::register); | ||
85 | - }) | ||
86 | .withTransport(transport) | 78 | .withTransport(transport) |
87 | .build(); | 79 | .build(); |
88 | } | 80 | } |
... | @@ -103,7 +95,8 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -103,7 +95,8 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
103 | @Override | 95 | @Override |
104 | public <K, V> AsyncConsistentMap<K, V> newAsyncConsistentMap(String name, Serializer serializer) { | 96 | public <K, V> AsyncConsistentMap<K, V> newAsyncConsistentMap(String name, Serializer serializer) { |
105 | AsyncConsistentMap<String, byte[]> rawMap = | 97 | AsyncConsistentMap<String, byte[]> rawMap = |
106 | - new DelegatingAsyncConsistentMap<String, byte[]>(client.get(name, AtomixConsistentMap.class).join()) { | 98 | + new DelegatingAsyncConsistentMap<String, byte[]>(client.getResource(name, AtomixConsistentMap.class) |
99 | + .join()) { | ||
107 | @Override | 100 | @Override |
108 | public String name() { | 101 | public String name() { |
109 | return name; | 102 | return name; |
... | @@ -125,7 +118,7 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -125,7 +118,7 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
125 | 118 | ||
126 | @Override | 119 | @Override |
127 | public AsyncAtomicCounter newAsyncCounter(String name) { | 120 | public AsyncAtomicCounter newAsyncCounter(String name) { |
128 | - DistributedLong distributedLong = client.get(name, DistributedLong.class).join(); | 121 | + DistributedLong distributedLong = client.getLong(name).join(); |
129 | return new AtomixCounter(name, distributedLong); | 122 | return new AtomixCounter(name, distributedLong); |
130 | } | 123 | } |
131 | 124 | ||
... | @@ -144,7 +137,7 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -144,7 +137,7 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
144 | 137 | ||
145 | @Override | 138 | @Override |
146 | public AsyncLeaderElector newAsyncLeaderElector(String name) { | 139 | public AsyncLeaderElector newAsyncLeaderElector(String name) { |
147 | - return client.get(name, AtomixLeaderElector.class).join(); | 140 | + return client.getResource(name, AtomixLeaderElector.class).join(); |
148 | } | 141 | } |
149 | 142 | ||
150 | @Override | 143 | @Override |
... | @@ -161,9 +154,4 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -161,9 +154,4 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
161 | public boolean isOpen() { | 154 | public boolean isOpen() { |
162 | return client.isOpen(); | 155 | return client.isOpen(); |
163 | } | 156 | } |
164 | - | ||
165 | - @Override | ||
166 | - public boolean isClosed() { | ||
167 | - return client.isClosed(); | ||
168 | - } | ||
169 | } | 157 | } | ... | ... |
... | @@ -22,12 +22,8 @@ import io.atomix.catalyst.transport.Transport; | ... | @@ -22,12 +22,8 @@ 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; | ||
26 | import io.atomix.manager.state.ResourceManagerState; | 25 | import io.atomix.manager.state.ResourceManagerState; |
27 | -import io.atomix.resource.ResourceRegistry; | 26 | +import io.atomix.manager.util.ResourceManagerTypeResolver; |
28 | -import io.atomix.resource.ResourceType; | ||
29 | -import io.atomix.resource.ResourceTypeResolver; | ||
30 | -import io.atomix.resource.ServiceLoaderResourceResolver; | ||
31 | 27 | ||
32 | import java.io.File; | 28 | import java.io.File; |
33 | import java.util.Collection; | 29 | import java.util.Collection; |
... | @@ -37,8 +33,6 @@ import java.util.function.Supplier; | ... | @@ -37,8 +33,6 @@ import java.util.function.Supplier; |
37 | import org.onosproject.store.service.PartitionInfo; | 33 | import org.onosproject.store.service.PartitionInfo; |
38 | import org.slf4j.Logger; | 34 | import org.slf4j.Logger; |
39 | 35 | ||
40 | -import com.google.common.collect.ImmutableSet; | ||
41 | - | ||
42 | /** | 36 | /** |
43 | * {@link StoragePartition} server. | 37 | * {@link StoragePartition} server. |
44 | */ | 38 | */ |
... | @@ -52,20 +46,17 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { | ... | @@ -52,20 +46,17 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { |
52 | private final Supplier<Transport> transport; | 46 | private final Supplier<Transport> transport; |
53 | private final Serializer serializer; | 47 | private final Serializer serializer; |
54 | private final File dataFolder; | 48 | private final File dataFolder; |
55 | - private final Collection<ResourceType> resourceTypes; | ||
56 | private CopycatServer server; | 49 | private CopycatServer server; |
57 | 50 | ||
58 | public StoragePartitionServer(Address localAddress, | 51 | public StoragePartitionServer(Address localAddress, |
59 | StoragePartition partition, | 52 | StoragePartition partition, |
60 | Serializer serializer, | 53 | Serializer serializer, |
61 | Supplier<Transport> transport, | 54 | Supplier<Transport> transport, |
62 | - Collection<ResourceType> resourceTypes, | ||
63 | File dataFolder) { | 55 | File dataFolder) { |
64 | this.partition = partition; | 56 | this.partition = partition; |
65 | this.localAddress = localAddress; | 57 | this.localAddress = localAddress; |
66 | this.serializer = serializer; | 58 | this.serializer = serializer; |
67 | this.transport = transport; | 59 | this.transport = transport; |
68 | - this.resourceTypes = ImmutableSet.copyOf(resourceTypes); | ||
69 | this.dataFolder = dataFolder; | 60 | this.dataFolder = dataFolder; |
70 | } | 61 | } |
71 | 62 | ||
... | @@ -73,13 +64,13 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { | ... | @@ -73,13 +64,13 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { |
73 | public CompletableFuture<Void> open() { | 64 | public CompletableFuture<Void> open() { |
74 | CompletableFuture<CopycatServer> serverOpenFuture; | 65 | CompletableFuture<CopycatServer> serverOpenFuture; |
75 | if (partition.getMemberAddresses().contains(localAddress)) { | 66 | if (partition.getMemberAddresses().contains(localAddress)) { |
76 | - if (server != null && server.isOpen()) { | 67 | + if (server != null && server.isRunning()) { |
77 | return CompletableFuture.completedFuture(null); | 68 | return CompletableFuture.completedFuture(null); |
78 | } | 69 | } |
79 | synchronized (this) { | 70 | synchronized (this) { |
80 | server = buildServer(partition.getMemberAddresses()); | 71 | server = buildServer(partition.getMemberAddresses()); |
81 | } | 72 | } |
82 | - serverOpenFuture = server.open(); | 73 | + serverOpenFuture = server.start(); |
83 | } else { | 74 | } else { |
84 | serverOpenFuture = CompletableFuture.completedFuture(null); | 75 | serverOpenFuture = CompletableFuture.completedFuture(null); |
85 | } | 76 | } |
... | @@ -106,19 +97,15 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { | ... | @@ -106,19 +97,15 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { |
106 | * @return future that is completed when the operation is complete | 97 | * @return future that is completed when the operation is complete |
107 | */ | 98 | */ |
108 | public CompletableFuture<Void> closeAndExit() { | 99 | public CompletableFuture<Void> closeAndExit() { |
109 | - return server.close(); | 100 | + return server.stop(); |
110 | } | 101 | } |
111 | 102 | ||
112 | private CopycatServer buildServer(Collection<Address> clusterMembers) { | 103 | private CopycatServer buildServer(Collection<Address> clusterMembers) { |
113 | - ResourceTypeResolver resourceResolver = new ServiceLoaderResourceResolver(); | ||
114 | - ResourceRegistry registry = new ResourceRegistry(); | ||
115 | - resourceTypes.forEach(registry::register); | ||
116 | - resourceResolver.resolve(registry); | ||
117 | CopycatServer server = CopycatServer.builder(localAddress, clusterMembers) | 104 | CopycatServer server = CopycatServer.builder(localAddress, clusterMembers) |
118 | .withName("partition-" + partition.getId()) | 105 | .withName("partition-" + partition.getId()) |
119 | .withSerializer(serializer.clone()) | 106 | .withSerializer(serializer.clone()) |
120 | .withTransport(transport.get()) | 107 | .withTransport(transport.get()) |
121 | - .withStateMachine(() -> new ResourceManagerState(registry)) | 108 | + .withStateMachine(ResourceManagerState::new) |
122 | .withStorage(Storage.builder() | 109 | .withStorage(Storage.builder() |
123 | .withStorageLevel(StorageLevel.DISK) | 110 | .withStorageLevel(StorageLevel.DISK) |
124 | .withCompactionThreads(1) | 111 | .withCompactionThreads(1) |
... | @@ -126,14 +113,14 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { | ... | @@ -126,14 +113,14 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { |
126 | .withMaxEntriesPerSegment(MAX_ENTRIES_PER_LOG_SEGMENT) | 113 | .withMaxEntriesPerSegment(MAX_ENTRIES_PER_LOG_SEGMENT) |
127 | .build()) | 114 | .build()) |
128 | .build(); | 115 | .build(); |
129 | - server.serializer().resolve(new ResourceManagerTypeResolver(registry)); | 116 | + server.serializer().resolve(new ResourceManagerTypeResolver()); |
130 | return server; | 117 | return server; |
131 | } | 118 | } |
132 | 119 | ||
133 | public CompletableFuture<Void> join(Collection<Address> otherMembers) { | 120 | public CompletableFuture<Void> join(Collection<Address> otherMembers) { |
134 | server = buildServer(otherMembers); | 121 | server = buildServer(otherMembers); |
135 | 122 | ||
136 | - return server.open().whenComplete((r, e) -> { | 123 | + return server.start().whenComplete((r, e) -> { |
137 | if (e == null) { | 124 | if (e == null) { |
138 | log.info("Successfully joined partition {}", partition.getId()); | 125 | log.info("Successfully joined partition {}", partition.getId()); |
139 | } else { | 126 | } else { |
... | @@ -144,12 +131,7 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { | ... | @@ -144,12 +131,7 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { |
144 | 131 | ||
145 | @Override | 132 | @Override |
146 | public boolean isOpen() { | 133 | public boolean isOpen() { |
147 | - return server.isOpen(); | 134 | + return server.isRunning(); |
148 | - } | ||
149 | - | ||
150 | - @Override | ||
151 | - public boolean isClosed() { | ||
152 | - return server.isClosed(); | ||
153 | } | 135 | } |
154 | 136 | ||
155 | /** | 137 | /** | ... | ... |
... | @@ -16,13 +16,14 @@ | ... | @@ -16,13 +16,14 @@ |
16 | package org.onosproject.store.primitives.resources.impl; | 16 | package org.onosproject.store.primitives.resources.impl; |
17 | 17 | ||
18 | import io.atomix.copycat.client.CopycatClient; | 18 | import io.atomix.copycat.client.CopycatClient; |
19 | -import io.atomix.resource.Resource; | 19 | +import io.atomix.resource.AbstractResource; |
20 | import io.atomix.resource.ResourceTypeInfo; | 20 | import io.atomix.resource.ResourceTypeInfo; |
21 | 21 | ||
22 | import java.util.Collection; | 22 | import java.util.Collection; |
23 | import java.util.ConcurrentModificationException; | 23 | import java.util.ConcurrentModificationException; |
24 | import java.util.List; | 24 | import java.util.List; |
25 | import java.util.Map.Entry; | 25 | import java.util.Map.Entry; |
26 | +import java.util.Properties; | ||
26 | import java.util.Set; | 27 | import java.util.Set; |
27 | import java.util.concurrent.CompletableFuture; | 28 | import java.util.concurrent.CompletableFuture; |
28 | import java.util.concurrent.atomic.AtomicReference; | 29 | import java.util.concurrent.atomic.AtomicReference; |
... | @@ -57,18 +58,16 @@ import com.google.common.collect.Sets; | ... | @@ -57,18 +58,16 @@ import com.google.common.collect.Sets; |
57 | /** | 58 | /** |
58 | * Distributed resource providing the {@link AsyncConsistentMap} primitive. | 59 | * Distributed resource providing the {@link AsyncConsistentMap} primitive. |
59 | */ | 60 | */ |
60 | -@ResourceTypeInfo(id = -151, | 61 | +@ResourceTypeInfo(id = -151, factory = AtomixConsistentMapFactory.class) |
61 | - stateMachine = AtomixConsistentMapState.class, | 62 | +public class AtomixConsistentMap extends AbstractResource<AtomixConsistentMap> |
62 | - typeResolver = AtomixConsistentMapCommands.TypeResolver.class) | ||
63 | -public class AtomixConsistentMap extends Resource<AtomixConsistentMap> | ||
64 | implements AsyncConsistentMap<String, byte[]> { | 63 | implements AsyncConsistentMap<String, byte[]> { |
65 | 64 | ||
66 | private final Set<MapEventListener<String, byte[]>> mapEventListeners = Sets.newCopyOnWriteArraySet(); | 65 | private final Set<MapEventListener<String, byte[]>> mapEventListeners = Sets.newCopyOnWriteArraySet(); |
67 | 66 | ||
68 | public static final String CHANGE_SUBJECT = "changeEvents"; | 67 | public static final String CHANGE_SUBJECT = "changeEvents"; |
69 | 68 | ||
70 | - public AtomixConsistentMap(CopycatClient client, Resource.Options options) { | 69 | + public AtomixConsistentMap(CopycatClient client, Properties properties) { |
71 | - super(client, options); | 70 | + super(client, properties); |
72 | } | 71 | } |
73 | 72 | ||
74 | @Override | 73 | @Override | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.store.primitives.resources.impl; | ||
17 | + | ||
18 | +import io.atomix.catalyst.serializer.SerializableTypeResolver; | ||
19 | +import io.atomix.copycat.client.CopycatClient; | ||
20 | +import io.atomix.resource.ResourceFactory; | ||
21 | +import io.atomix.resource.ResourceStateMachine; | ||
22 | + | ||
23 | +import java.util.Properties; | ||
24 | + | ||
25 | +/** | ||
26 | + * {@link AtomixConsistentMap} resource factory. | ||
27 | + * | ||
28 | + */ | ||
29 | +public class AtomixConsistentMapFactory implements ResourceFactory<AtomixConsistentMap> { | ||
30 | + | ||
31 | + @Override | ||
32 | + public SerializableTypeResolver createSerializableTypeResolver() { | ||
33 | + return new AtomixConsistentMapCommands.TypeResolver(); | ||
34 | + } | ||
35 | + | ||
36 | + @Override | ||
37 | + public ResourceStateMachine createStateMachine(Properties config) { | ||
38 | + return new AtomixConsistentMapState(config); | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public AtomixConsistentMap createInstance(CopycatClient client, Properties options) { | ||
43 | + return new AtomixConsistentMap(client, options); | ||
44 | + } | ||
45 | + } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -26,13 +26,13 @@ import io.atomix.copycat.server.session.SessionListener; | ... | @@ -26,13 +26,13 @@ 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; | ||
30 | 29 | ||
31 | import java.util.Collection; | 30 | import java.util.Collection; |
32 | import java.util.HashMap; | 31 | import java.util.HashMap; |
33 | import java.util.Iterator; | 32 | import java.util.Iterator; |
34 | import java.util.List; | 33 | import java.util.List; |
35 | import java.util.Map; | 34 | import java.util.Map; |
35 | +import java.util.Properties; | ||
36 | import java.util.Set; | 36 | import java.util.Set; |
37 | import java.util.concurrent.atomic.AtomicLong; | 37 | import java.util.concurrent.atomic.AtomicLong; |
38 | import java.util.stream.Collectors; | 38 | import java.util.stream.Collectors; |
... | @@ -77,8 +77,8 @@ public class AtomixConsistentMapState extends ResourceStateMachine implements Se | ... | @@ -77,8 +77,8 @@ public class AtomixConsistentMapState extends ResourceStateMachine implements Se |
77 | private final Map<TransactionId, Commit<? extends TransactionPrepare>> pendingTransactions = Maps.newHashMap(); | 77 | private final Map<TransactionId, Commit<? extends TransactionPrepare>> pendingTransactions = Maps.newHashMap(); |
78 | private AtomicLong versionCounter = new AtomicLong(0); | 78 | private AtomicLong versionCounter = new AtomicLong(0); |
79 | 79 | ||
80 | - public AtomixConsistentMapState() { | 80 | + public AtomixConsistentMapState(Properties properties) { |
81 | - super(new ResourceType(AtomixConsistentMap.class)); | 81 | + super(properties); |
82 | } | 82 | } |
83 | 83 | ||
84 | @Override | 84 | @Override | ... | ... |
... | @@ -17,11 +17,12 @@ package org.onosproject.store.primitives.resources.impl; | ... | @@ -17,11 +17,12 @@ package org.onosproject.store.primitives.resources.impl; |
17 | 17 | ||
18 | import io.atomix.catalyst.util.Listener; | 18 | import io.atomix.catalyst.util.Listener; |
19 | import io.atomix.copycat.client.CopycatClient; | 19 | import io.atomix.copycat.client.CopycatClient; |
20 | -import io.atomix.resource.Resource; | 20 | +import io.atomix.resource.AbstractResource; |
21 | import io.atomix.resource.ResourceTypeInfo; | 21 | import io.atomix.resource.ResourceTypeInfo; |
22 | 22 | ||
23 | import java.util.List; | 23 | import java.util.List; |
24 | import java.util.Map; | 24 | import java.util.Map; |
25 | +import java.util.Properties; | ||
25 | import java.util.Set; | 26 | import java.util.Set; |
26 | import java.util.concurrent.CompletableFuture; | 27 | import java.util.concurrent.CompletableFuture; |
27 | import java.util.function.Consumer; | 28 | import java.util.function.Consumer; |
... | @@ -45,10 +46,8 @@ import com.google.common.collect.Sets; | ... | @@ -45,10 +46,8 @@ import com.google.common.collect.Sets; |
45 | /** | 46 | /** |
46 | * Distributed resource providing the {@link AsyncLeaderElector} primitive. | 47 | * Distributed resource providing the {@link AsyncLeaderElector} primitive. |
47 | */ | 48 | */ |
48 | -@ResourceTypeInfo(id = -152, | 49 | +@ResourceTypeInfo(id = -151, factory = AtomixLeaderElectorFactory.class) |
49 | - stateMachine = AtomixLeaderElectorState.class, | 50 | +public class AtomixLeaderElector extends AbstractResource<AtomixLeaderElector> |
50 | - typeResolver = AtomixLeaderElectorCommands.TypeResolver.class) | ||
51 | -public class AtomixLeaderElector extends Resource<AtomixLeaderElector> | ||
52 | implements AsyncLeaderElector { | 51 | implements AsyncLeaderElector { |
53 | private final Set<Consumer<Change<Leadership>>> leadershipChangeListeners = | 52 | private final Set<Consumer<Change<Leadership>>> leadershipChangeListeners = |
54 | Sets.newConcurrentHashSet(); | 53 | Sets.newConcurrentHashSet(); |
... | @@ -56,8 +55,8 @@ public class AtomixLeaderElector extends Resource<AtomixLeaderElector> | ... | @@ -56,8 +55,8 @@ public class AtomixLeaderElector extends Resource<AtomixLeaderElector> |
56 | public static final String CHANGE_SUBJECT = "leadershipChangeEvents"; | 55 | public static final String CHANGE_SUBJECT = "leadershipChangeEvents"; |
57 | private Listener<Change<Leadership>> listener; | 56 | private Listener<Change<Leadership>> listener; |
58 | 57 | ||
59 | - public AtomixLeaderElector(CopycatClient client, Resource.Options options) { | 58 | + public AtomixLeaderElector(CopycatClient client, Properties properties) { |
60 | - super(client, options); | 59 | + super(client, properties); |
61 | } | 60 | } |
62 | 61 | ||
63 | @Override | 62 | @Override | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.store.primitives.resources.impl; | ||
17 | + | ||
18 | +import io.atomix.catalyst.serializer.SerializableTypeResolver; | ||
19 | +import io.atomix.copycat.client.CopycatClient; | ||
20 | +import io.atomix.resource.ResourceFactory; | ||
21 | +import io.atomix.resource.ResourceStateMachine; | ||
22 | + | ||
23 | +import java.util.Properties; | ||
24 | + | ||
25 | +/** | ||
26 | + * {@link AtomixLeaderElector} resource factory. | ||
27 | + * | ||
28 | + */ | ||
29 | +public class AtomixLeaderElectorFactory implements ResourceFactory<AtomixLeaderElector> { | ||
30 | + | ||
31 | + @Override | ||
32 | + public SerializableTypeResolver createSerializableTypeResolver() { | ||
33 | + return new AtomixLeaderElectorCommands.TypeResolver(); | ||
34 | + } | ||
35 | + | ||
36 | + @Override | ||
37 | + public ResourceStateMachine createStateMachine(Properties config) { | ||
38 | + return new AtomixLeaderElectorState(config); | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public AtomixLeaderElector createInstance(CopycatClient client, Properties options) { | ||
43 | + return new AtomixLeaderElector(client, options); | ||
44 | + } | ||
45 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -24,7 +24,6 @@ import io.atomix.copycat.server.session.SessionListener; | ... | @@ -24,7 +24,6 @@ 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; | ||
28 | 27 | ||
29 | import java.util.Arrays; | 28 | import java.util.Arrays; |
30 | import java.util.HashMap; | 29 | import java.util.HashMap; |
... | @@ -33,6 +32,7 @@ import java.util.LinkedList; | ... | @@ -33,6 +32,7 @@ import java.util.LinkedList; |
33 | import java.util.List; | 32 | import java.util.List; |
34 | import java.util.Map; | 33 | import java.util.Map; |
35 | import java.util.Optional; | 34 | import java.util.Optional; |
35 | +import java.util.Properties; | ||
36 | import java.util.Set; | 36 | import java.util.Set; |
37 | import java.util.concurrent.atomic.AtomicLong; | 37 | import java.util.concurrent.atomic.AtomicLong; |
38 | import java.util.function.Supplier; | 38 | import java.util.function.Supplier; |
... | @@ -75,8 +75,8 @@ public class AtomixLeaderElectorState extends ResourceStateMachine | ... | @@ -75,8 +75,8 @@ public class AtomixLeaderElectorState extends ResourceStateMachine |
75 | ElectionState.class, | 75 | ElectionState.class, |
76 | Registration.class); | 76 | Registration.class); |
77 | 77 | ||
78 | - public AtomixLeaderElectorState() { | 78 | + public AtomixLeaderElectorState(Properties properties) { |
79 | - super(new ResourceType(AtomixLeaderElector.class)); | 79 | + super(properties); |
80 | } | 80 | } |
81 | 81 | ||
82 | @Override | 82 | @Override | ... | ... |
... | @@ -116,7 +116,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -116,7 +116,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
116 | final byte[] rawFooValue = Tools.getBytesUtf8("Hello foo!"); | 116 | final byte[] rawFooValue = Tools.getBytesUtf8("Hello foo!"); |
117 | final byte[] rawBarValue = Tools.getBytesUtf8("Hello bar!"); | 117 | final byte[] rawBarValue = Tools.getBytesUtf8("Hello bar!"); |
118 | 118 | ||
119 | - AtomixConsistentMap map = createAtomixClient().get("test", AtomixConsistentMap.class).join(); | 119 | + AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); |
120 | 120 | ||
121 | map.isEmpty().thenAccept(result -> { | 121 | map.isEmpty().thenAccept(result -> { |
122 | assertTrue(result); | 122 | assertTrue(result); |
... | @@ -246,7 +246,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -246,7 +246,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
246 | final byte[] value2 = Tools.getBytesUtf8("value2"); | 246 | final byte[] value2 = Tools.getBytesUtf8("value2"); |
247 | final byte[] value3 = Tools.getBytesUtf8("value3"); | 247 | final byte[] value3 = Tools.getBytesUtf8("value3"); |
248 | 248 | ||
249 | - AtomixConsistentMap map = createAtomixClient().get("test", AtomixConsistentMap.class).join(); | 249 | + AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); |
250 | 250 | ||
251 | map.computeIfAbsent("foo", k -> value1).thenAccept(result -> { | 251 | map.computeIfAbsent("foo", k -> value1).thenAccept(result -> { |
252 | assertTrue(Arrays.equals(Versioned.valueOrElse(result, null), value1)); | 252 | assertTrue(Arrays.equals(Versioned.valueOrElse(result, null), value1)); |
... | @@ -284,7 +284,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -284,7 +284,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
284 | final byte[] value2 = Tools.getBytesUtf8("value2"); | 284 | final byte[] value2 = Tools.getBytesUtf8("value2"); |
285 | final byte[] value3 = Tools.getBytesUtf8("value3"); | 285 | final byte[] value3 = Tools.getBytesUtf8("value3"); |
286 | 286 | ||
287 | - AtomixConsistentMap map = createAtomixClient().get("test", AtomixConsistentMap.class).join(); | 287 | + AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); |
288 | TestMapEventListener listener = new TestMapEventListener(); | 288 | TestMapEventListener listener = new TestMapEventListener(); |
289 | 289 | ||
290 | // add listener; insert new value into map and verify an INSERT event is received. | 290 | // add listener; insert new value into map and verify an INSERT event is received. |
... | @@ -343,7 +343,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -343,7 +343,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
343 | final byte[] value1 = Tools.getBytesUtf8("value1"); | 343 | final byte[] value1 = Tools.getBytesUtf8("value1"); |
344 | final byte[] value2 = Tools.getBytesUtf8("value2"); | 344 | final byte[] value2 = Tools.getBytesUtf8("value2"); |
345 | 345 | ||
346 | - AtomixConsistentMap map = createAtomixClient().get("test", AtomixConsistentMap.class).join(); | 346 | + AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); |
347 | TestMapEventListener listener = new TestMapEventListener(); | 347 | TestMapEventListener listener = new TestMapEventListener(); |
348 | 348 | ||
349 | map.addListener(listener).join(); | 349 | map.addListener(listener).join(); |
... | @@ -398,7 +398,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { | ... | @@ -398,7 +398,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { |
398 | final byte[] value1 = Tools.getBytesUtf8("value1"); | 398 | final byte[] value1 = Tools.getBytesUtf8("value1"); |
399 | final byte[] value2 = Tools.getBytesUtf8("value2"); | 399 | final byte[] value2 = Tools.getBytesUtf8("value2"); |
400 | 400 | ||
401 | - AtomixConsistentMap map = createAtomixClient().get("test", AtomixConsistentMap.class).join(); | 401 | + AtomixConsistentMap map = createAtomixClient().getResource("test", AtomixConsistentMap.class).join(); |
402 | TestMapEventListener listener = new TestMapEventListener(); | 402 | TestMapEventListener listener = new TestMapEventListener(); |
403 | 403 | ||
404 | map.addListener(listener).join(); | 404 | map.addListener(listener).join(); | ... | ... |
... | @@ -60,7 +60,7 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -60,7 +60,7 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
60 | private void leaderElectorRunTests(int numServers) throws Throwable { | 60 | private void leaderElectorRunTests(int numServers) throws Throwable { |
61 | createCopycatServers(numServers); | 61 | createCopycatServers(numServers); |
62 | Atomix client1 = createAtomixClient(); | 62 | Atomix client1 = createAtomixClient(); |
63 | - AtomixLeaderElector elector1 = client1.get("test-elector", AtomixLeaderElector.class).join(); | 63 | + AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); |
64 | elector1.run("foo", node1).thenAccept(result -> { | 64 | elector1.run("foo", node1).thenAccept(result -> { |
65 | assertEquals(node1, result.leaderNodeId()); | 65 | assertEquals(node1, result.leaderNodeId()); |
66 | assertEquals(1, result.leader().term()); | 66 | assertEquals(1, result.leader().term()); |
... | @@ -68,7 +68,7 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -68,7 +68,7 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
68 | assertEquals(node1, result.candidates().get(0)); | 68 | assertEquals(node1, result.candidates().get(0)); |
69 | }).join(); | 69 | }).join(); |
70 | Atomix client2 = createAtomixClient(); | 70 | Atomix client2 = createAtomixClient(); |
71 | - AtomixLeaderElector elector2 = client2.get("test-elector", AtomixLeaderElector.class).join(); | 71 | + AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); |
72 | elector2.run("foo", node2).thenAccept(result -> { | 72 | elector2.run("foo", node2).thenAccept(result -> { |
73 | assertEquals(node1, result.leaderNodeId()); | 73 | assertEquals(node1, result.leaderNodeId()); |
74 | assertEquals(1, result.leader().term()); | 74 | assertEquals(1, result.leader().term()); |
... | @@ -91,10 +91,10 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -91,10 +91,10 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
91 | private void leaderElectorWithdrawTests(int numServers) throws Throwable { | 91 | private void leaderElectorWithdrawTests(int numServers) throws Throwable { |
92 | createCopycatServers(numServers); | 92 | createCopycatServers(numServers); |
93 | Atomix client1 = createAtomixClient(); | 93 | Atomix client1 = createAtomixClient(); |
94 | - AtomixLeaderElector elector1 = client1.get("test-elector", AtomixLeaderElector.class).join(); | 94 | + AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); |
95 | elector1.run("foo", node1).join(); | 95 | elector1.run("foo", node1).join(); |
96 | Atomix client2 = createAtomixClient(); | 96 | Atomix client2 = createAtomixClient(); |
97 | - AtomixLeaderElector elector2 = client2.get("test-elector", AtomixLeaderElector.class).join(); | 97 | + AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); |
98 | elector2.run("foo", node2).join(); | 98 | elector2.run("foo", node2).join(); |
99 | 99 | ||
100 | LeaderEventListener listener1 = new LeaderEventListener(); | 100 | LeaderEventListener listener1 = new LeaderEventListener(); |
... | @@ -133,11 +133,11 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -133,11 +133,11 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
133 | private void leaderElectorAnointTests(int numServers) throws Throwable { | 133 | private void leaderElectorAnointTests(int numServers) throws Throwable { |
134 | createCopycatServers(numServers); | 134 | createCopycatServers(numServers); |
135 | Atomix client1 = createAtomixClient(); | 135 | Atomix client1 = createAtomixClient(); |
136 | - AtomixLeaderElector elector1 = client1.get("test-elector", AtomixLeaderElector.class).join(); | 136 | + AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); |
137 | Atomix client2 = createAtomixClient(); | 137 | Atomix client2 = createAtomixClient(); |
138 | - AtomixLeaderElector elector2 = client2.get("test-elector", AtomixLeaderElector.class).join(); | 138 | + AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); |
139 | Atomix client3 = createAtomixClient(); | 139 | Atomix client3 = createAtomixClient(); |
140 | - AtomixLeaderElector elector3 = client3.get("test-elector", AtomixLeaderElector.class).join(); | 140 | + AtomixLeaderElector elector3 = client3.getResource("test-elector", AtomixLeaderElector.class).join(); |
141 | elector1.run("foo", node1).join(); | 141 | elector1.run("foo", node1).join(); |
142 | elector2.run("foo", node2).join(); | 142 | elector2.run("foo", node2).join(); |
143 | 143 | ||
... | @@ -195,11 +195,11 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -195,11 +195,11 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
195 | private void leaderElectorPromoteTests(int numServers) throws Throwable { | 195 | private void leaderElectorPromoteTests(int numServers) throws Throwable { |
196 | createCopycatServers(numServers); | 196 | createCopycatServers(numServers); |
197 | Atomix client1 = createAtomixClient(); | 197 | Atomix client1 = createAtomixClient(); |
198 | - AtomixLeaderElector elector1 = client1.get("test-elector", AtomixLeaderElector.class).join(); | 198 | + AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); |
199 | Atomix client2 = createAtomixClient(); | 199 | Atomix client2 = createAtomixClient(); |
200 | - AtomixLeaderElector elector2 = client2.get("test-elector", AtomixLeaderElector.class).join(); | 200 | + AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); |
201 | Atomix client3 = createAtomixClient(); | 201 | Atomix client3 = createAtomixClient(); |
202 | - AtomixLeaderElector elector3 = client3.get("test-elector", AtomixLeaderElector.class).join(); | 202 | + AtomixLeaderElector elector3 = client3.getResource("test-elector", AtomixLeaderElector.class).join(); |
203 | elector1.run("foo", node1).join(); | 203 | elector1.run("foo", node1).join(); |
204 | elector2.run("foo", node2).join(); | 204 | elector2.run("foo", node2).join(); |
205 | 205 | ||
... | @@ -252,10 +252,10 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -252,10 +252,10 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
252 | private void leaderElectorLeaderSessionCloseTests(int numServers) throws Throwable { | 252 | private void leaderElectorLeaderSessionCloseTests(int numServers) throws Throwable { |
253 | createCopycatServers(numServers); | 253 | createCopycatServers(numServers); |
254 | Atomix client1 = createAtomixClient(); | 254 | Atomix client1 = createAtomixClient(); |
255 | - AtomixLeaderElector elector1 = client1.get("test-elector", AtomixLeaderElector.class).join(); | 255 | + AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); |
256 | elector1.run("foo", node1).join(); | 256 | elector1.run("foo", node1).join(); |
257 | Atomix client2 = createAtomixClient(); | 257 | Atomix client2 = createAtomixClient(); |
258 | - AtomixLeaderElector elector2 = client2.get("test-elector", AtomixLeaderElector.class).join(); | 258 | + AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); |
259 | LeaderEventListener listener = new LeaderEventListener(); | 259 | LeaderEventListener listener = new LeaderEventListener(); |
260 | elector2.run("foo", node2).join(); | 260 | elector2.run("foo", node2).join(); |
261 | elector2.addChangeListener(listener).join(); | 261 | elector2.addChangeListener(listener).join(); |
... | @@ -280,10 +280,10 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -280,10 +280,10 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
280 | private void leaderElectorNonLeaderSessionCloseTests(int numServers) throws Throwable { | 280 | private void leaderElectorNonLeaderSessionCloseTests(int numServers) throws Throwable { |
281 | createCopycatServers(numServers); | 281 | createCopycatServers(numServers); |
282 | Atomix client1 = createAtomixClient(); | 282 | Atomix client1 = createAtomixClient(); |
283 | - AtomixLeaderElector elector1 = client1.get("test-elector", AtomixLeaderElector.class).join(); | 283 | + AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); |
284 | elector1.run("foo", node1).join(); | 284 | elector1.run("foo", node1).join(); |
285 | Atomix client2 = createAtomixClient(); | 285 | Atomix client2 = createAtomixClient(); |
286 | - AtomixLeaderElector elector2 = client2.get("test-elector", AtomixLeaderElector.class).join(); | 286 | + AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); |
287 | LeaderEventListener listener = new LeaderEventListener(); | 287 | LeaderEventListener listener = new LeaderEventListener(); |
288 | elector2.run("foo", node2).join(); | 288 | elector2.run("foo", node2).join(); |
289 | elector1.addChangeListener(listener).join(); | 289 | elector1.addChangeListener(listener).join(); |
... | @@ -309,8 +309,8 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { | ... | @@ -309,8 +309,8 @@ public class AtomixLeaderElectorTest extends AtomixTestBase { |
309 | createCopycatServers(numServers); | 309 | createCopycatServers(numServers); |
310 | Atomix client1 = createAtomixClient(); | 310 | Atomix client1 = createAtomixClient(); |
311 | Atomix client2 = createAtomixClient(); | 311 | Atomix client2 = createAtomixClient(); |
312 | - AtomixLeaderElector elector1 = client1.get("test-elector", AtomixLeaderElector.class).join(); | 312 | + AtomixLeaderElector elector1 = client1.getResource("test-elector", AtomixLeaderElector.class).join(); |
313 | - AtomixLeaderElector elector2 = client2.get("test-elector", AtomixLeaderElector.class).join(); | 313 | + AtomixLeaderElector elector2 = client2.getResource("test-elector", AtomixLeaderElector.class).join(); |
314 | elector1.run("foo", node1).join(); | 314 | elector1.run("foo", node1).join(); |
315 | elector2.run("foo", node2).join(); | 315 | elector2.run("foo", node2).join(); |
316 | elector2.run("bar", node2).join(); | 316 | elector2.run("bar", node2).join(); | ... | ... |
... | @@ -26,7 +26,6 @@ import io.atomix.copycat.server.CopycatServer; | ... | @@ -26,7 +26,6 @@ import io.atomix.copycat.server.CopycatServer; |
26 | import io.atomix.copycat.server.storage.Storage; | 26 | import io.atomix.copycat.server.storage.Storage; |
27 | import io.atomix.copycat.server.storage.StorageLevel; | 27 | import io.atomix.copycat.server.storage.StorageLevel; |
28 | import io.atomix.manager.state.ResourceManagerState; | 28 | import io.atomix.manager.state.ResourceManagerState; |
29 | -import io.atomix.resource.ResourceRegistry; | ||
30 | import io.atomix.resource.ResourceType; | 29 | import io.atomix.resource.ResourceType; |
31 | 30 | ||
32 | import java.io.File; | 31 | import java.io.File; |
... | @@ -90,7 +89,7 @@ public abstract class AtomixTestBase { | ... | @@ -90,7 +89,7 @@ public abstract class AtomixTestBase { |
90 | 89 | ||
91 | for (int i = 0; i < nodes; i++) { | 90 | for (int i = 0; i < nodes; i++) { |
92 | CopycatServer server = createCopycatServer(members.get(i)); | 91 | CopycatServer server = createCopycatServer(members.get(i)); |
93 | - server.open().thenRun(latch::countDown); | 92 | + server.start().thenRun(latch::countDown); |
94 | servers.add(server); | 93 | servers.add(server); |
95 | } | 94 | } |
96 | 95 | ||
... | @@ -103,15 +102,13 @@ public abstract class AtomixTestBase { | ... | @@ -103,15 +102,13 @@ public abstract class AtomixTestBase { |
103 | * Creates a Copycat server. | 102 | * Creates a Copycat server. |
104 | */ | 103 | */ |
105 | protected CopycatServer createCopycatServer(Address address) { | 104 | protected CopycatServer createCopycatServer(Address address) { |
106 | - ResourceRegistry resourceRegistry = new ResourceRegistry(); | ||
107 | - resourceRegistry.register(resourceType()); | ||
108 | CopycatServer server = CopycatServer.builder(address, members) | 105 | CopycatServer server = CopycatServer.builder(address, members) |
109 | .withTransport(new LocalTransport(registry)) | 106 | .withTransport(new LocalTransport(registry)) |
110 | .withStorage(Storage.builder() | 107 | .withStorage(Storage.builder() |
111 | .withStorageLevel(StorageLevel.DISK) | 108 | .withStorageLevel(StorageLevel.DISK) |
112 | .withDirectory(TEST_DIR + "/" + address.port()) | 109 | .withDirectory(TEST_DIR + "/" + address.port()) |
113 | .build()) | 110 | .build()) |
114 | - .withStateMachine(() -> new ResourceManagerState(resourceRegistry)) | 111 | + .withStateMachine(ResourceManagerState::new) |
115 | .withSerializer(serializer.clone()) | 112 | .withSerializer(serializer.clone()) |
116 | .withHeartbeatInterval(Duration.ofMillis(25)) | 113 | .withHeartbeatInterval(Duration.ofMillis(25)) |
117 | .withElectionTimeout(Duration.ofMillis(50)) | 114 | .withElectionTimeout(Duration.ofMillis(50)) |
... | @@ -134,7 +131,7 @@ public abstract class AtomixTestBase { | ... | @@ -134,7 +131,7 @@ public abstract class AtomixTestBase { |
134 | .toArray(CompletableFuture[]::new)); | 131 | .toArray(CompletableFuture[]::new)); |
135 | 132 | ||
136 | closeClients.thenCompose(v -> CompletableFuture.allOf(copycatServers.stream() | 133 | closeClients.thenCompose(v -> CompletableFuture.allOf(copycatServers.stream() |
137 | - .map(CopycatServer::close) | 134 | + .map(CopycatServer::stop) |
138 | .toArray(CompletableFuture[]::new))).join(); | 135 | .toArray(CompletableFuture[]::new))).join(); |
139 | 136 | ||
140 | deleteDirectory(TEST_DIR); | 137 | deleteDirectory(TEST_DIR); |
... | @@ -171,7 +168,6 @@ public abstract class AtomixTestBase { | ... | @@ -171,7 +168,6 @@ public abstract class AtomixTestBase { |
171 | Atomix client = AtomixClient.builder(members) | 168 | Atomix client = AtomixClient.builder(members) |
172 | .withTransport(new LocalTransport(registry)) | 169 | .withTransport(new LocalTransport(registry)) |
173 | .withSerializer(serializer.clone()) | 170 | .withSerializer(serializer.clone()) |
174 | - .withResourceResolver(r -> r.register(resourceType())) | ||
175 | .build(); | 171 | .build(); |
176 | client.open().thenRun(latch::countDown); | 172 | client.open().thenRun(latch::countDown); |
177 | atomixClients.add(client); | 173 | atomixClients.add(client); | ... | ... |
... | @@ -77,7 +77,7 @@ | ... | @@ -77,7 +77,7 @@ |
77 | <onos-build-conf.version>1.2</onos-build-conf.version> | 77 | <onos-build-conf.version>1.2</onos-build-conf.version> |
78 | <netty4.version>4.0.33.Final</netty4.version> | 78 | <netty4.version>4.0.33.Final</netty4.version> |
79 | <!-- TODO: replace with final release version when it is out --> | 79 | <!-- TODO: replace with final release version when it is out --> |
80 | - <atomix.version>1.0.0-rc2</atomix.version> | 80 | + <atomix.version>1.0.0-rc3</atomix.version> |
81 | <copycat.version>0.5.1.onos</copycat.version> | 81 | <copycat.version>0.5.1.onos</copycat.version> |
82 | <openflowj.version>0.9.2.onos</openflowj.version> | 82 | <openflowj.version>0.9.2.onos</openflowj.version> |
83 | <onos-maven-plugin.version>1.9</onos-maven-plugin.version> | 83 | <onos-maven-plugin.version>1.9</onos-maven-plugin.version> | ... | ... |
-
Please register or login to post a comment