Madan Jampani
Committed by Gerrit Code Review

Implementation for StorageAdmin and PartitionAdmin APIs

Change-Id: I48cbfae6f410425294196884cdb2ce4705fa2c3d
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.store.primitives; 16 package org.onosproject.store.primitives;
17 17
18 +import java.util.Set;
19 +
18 import org.onosproject.store.service.AsyncAtomicCounter; 20 import org.onosproject.store.service.AsyncAtomicCounter;
19 import org.onosproject.store.service.AsyncAtomicValue; 21 import org.onosproject.store.service.AsyncAtomicValue;
20 import org.onosproject.store.service.AsyncConsistentMap; 22 import org.onosproject.store.service.AsyncConsistentMap;
...@@ -84,4 +86,16 @@ public interface DistributedPrimitiveCreator { ...@@ -84,4 +86,16 @@ public interface DistributedPrimitiveCreator {
84 * @return leader elector 86 * @return leader elector
85 */ 87 */
86 AsyncLeaderElector newAsyncLeaderElector(String name); 88 AsyncLeaderElector newAsyncLeaderElector(String name);
89 +
90 + /**
91 + * Returns the names of all created {@code AsyncConsistentMap} instances.
92 + * @return set of {@code AsyncConsistentMap} names
93 + */
94 + Set<String> getAsyncConsistentMapNames();
95 +
96 + /**
97 + * Returns the names of all created {@code AsyncAtomicCounter} instances.
98 + * @return set of {@code AsyncAtomicCounter} names
99 + */
100 + Set<String> getAsyncAtomicCounterNames();
87 } 101 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
15 */ 15 */
16 package org.onosproject.store.primitives; 16 package org.onosproject.store.primitives;
17 17
18 +import java.util.List;
18 import java.util.concurrent.CompletableFuture; 19 import java.util.concurrent.CompletableFuture;
19 20
20 import org.onosproject.cluster.PartitionId; 21 import org.onosproject.cluster.PartitionId;
22 +import org.onosproject.store.service.PartitionInfo;
21 23
22 /** 24 /**
23 * Administrative interface for partition membership changes. 25 * Administrative interface for partition membership changes.
...@@ -25,6 +27,12 @@ import org.onosproject.cluster.PartitionId; ...@@ -25,6 +27,12 @@ import org.onosproject.cluster.PartitionId;
25 public interface PartitionAdminService { 27 public interface PartitionAdminService {
26 28
27 /** 29 /**
30 + * Returns the {@link PartitionInfo information} for existing partitions.
31 + * @return list of {@code PartitionInfo}
32 + */
33 + List<PartitionInfo> partitionInfo();
34 +
35 + /**
28 * Leaves a partition. 36 * Leaves a partition.
29 * 37 *
30 * @param partitionId partition identifier 38 * @param partitionId partition identifier
......
...@@ -31,6 +31,7 @@ public interface StorageAdminService { ...@@ -31,6 +31,7 @@ public interface StorageAdminService {
31 * 31 *
32 * @return list of partition information 32 * @return list of partition information
33 */ 33 */
34 + @Deprecated
34 List<PartitionInfo> getPartitionInfo(); 35 List<PartitionInfo> getPartitionInfo();
35 36
36 /** 37 /**
...@@ -38,6 +39,7 @@ public interface StorageAdminService { ...@@ -38,6 +39,7 @@ public interface StorageAdminService {
38 * 39 *
39 * @return list of map information 40 * @return list of map information
40 */ 41 */
42 + @Deprecated
41 List<MapInfo> getMapInfo(); 43 List<MapInfo> getMapInfo();
42 44
43 /** 45 /**
...@@ -47,6 +49,7 @@ public interface StorageAdminService { ...@@ -47,6 +49,7 @@ public interface StorageAdminService {
47 * 49 *
48 * @return mapping from counter name to that counter's next value 50 * @return mapping from counter name to that counter's next value
49 */ 51 */
52 + @Deprecated
50 Map<String, Long> getCounters(); 53 Map<String, Long> getCounters();
51 54
52 /** 55 /**
...@@ -54,6 +57,7 @@ public interface StorageAdminService { ...@@ -54,6 +57,7 @@ public interface StorageAdminService {
54 * 57 *
55 * @return mapping from counter name to that counter's next value 58 * @return mapping from counter name to that counter's next value
56 */ 59 */
60 + @Deprecated
57 Map<String, Long> getPartitionedDatabaseCounters(); 61 Map<String, Long> getPartitionedDatabaseCounters();
58 62
59 /** 63 /**
...@@ -61,6 +65,7 @@ public interface StorageAdminService { ...@@ -61,6 +65,7 @@ public interface StorageAdminService {
61 * 65 *
62 * @return mapping from counter name to that counter's next value 66 * @return mapping from counter name to that counter's next value
63 */ 67 */
68 + @Deprecated
64 Map<String, Long> getInMemoryDatabaseCounters(); 69 Map<String, Long> getInMemoryDatabaseCounters();
65 70
66 /** 71 /**
......
...@@ -22,6 +22,7 @@ import io.atomix.copycat.client.Query; ...@@ -22,6 +22,7 @@ import io.atomix.copycat.client.Query;
22 import io.atomix.manager.state.GetResource; 22 import io.atomix.manager.state.GetResource;
23 import io.atomix.manager.state.GetResourceKeys; 23 import io.atomix.manager.state.GetResourceKeys;
24 import io.atomix.resource.ResourceQuery; 24 import io.atomix.resource.ResourceQuery;
25 +import io.atomix.variables.state.ValueCommands;
25 26
26 import java.io.IOException; 27 import java.io.IOException;
27 import java.net.URL; 28 import java.net.URL;
...@@ -93,6 +94,8 @@ public final class CatalystSerializers { ...@@ -93,6 +94,8 @@ public final class CatalystSerializers {
93 GetResource.class, 94 GetResource.class,
94 GetResourceKeys.class, 95 GetResourceKeys.class,
95 ResourceQuery.class, 96 ResourceQuery.class,
97 + ValueCommands.Get.class,
98 + ValueCommands.Set.class,
96 Query.ConsistencyLevel.class)); 99 Query.ConsistencyLevel.class));
97 // ONOS classes 100 // ONOS classes
98 serializer.register(Change.class, factory); 101 serializer.register(Change.class, factory);
...@@ -115,6 +118,8 @@ public final class CatalystSerializers { ...@@ -115,6 +118,8 @@ public final class CatalystSerializers {
115 serializer.register(ResourceQuery.class, factory); 118 serializer.register(ResourceQuery.class, factory);
116 serializer.register(GetResource.class, factory); 119 serializer.register(GetResource.class, factory);
117 serializer.register(GetResourceKeys.class, factory); 120 serializer.register(GetResourceKeys.class, factory);
121 + serializer.register(ValueCommands.Get.class, factory);
122 + serializer.register(ValueCommands.Set.class, factory);
118 123
119 // ConsistentMap 124 // ConsistentMap
120 serializer.register(AtomixConsistentMapCommands.UpdateAndGet.class, factory); 125 serializer.register(AtomixConsistentMapCommands.UpdateAndGet.class, factory);
......
...@@ -15,7 +15,12 @@ ...@@ -15,7 +15,12 @@
15 */ 15 */
16 package org.onosproject.store.primitives.impl; 16 package org.onosproject.store.primitives.impl;
17 17
18 +import static org.slf4j.LoggerFactory.getLogger;
19 +
18 import org.onosproject.store.service.Serializer; 20 import org.onosproject.store.service.Serializer;
21 +import org.slf4j.Logger;
22 +
23 +import com.google.common.base.Throwables;
19 24
20 import io.atomix.catalyst.buffer.BufferInput; 25 import io.atomix.catalyst.buffer.BufferInput;
21 import io.atomix.catalyst.buffer.BufferOutput; 26 import io.atomix.catalyst.buffer.BufferOutput;
...@@ -28,6 +33,7 @@ import io.atomix.catalyst.serializer.TypeSerializerFactory; ...@@ -28,6 +33,7 @@ import io.atomix.catalyst.serializer.TypeSerializerFactory;
28 */ 33 */
29 public class DefaultCatalystTypeSerializerFactory implements TypeSerializerFactory { 34 public class DefaultCatalystTypeSerializerFactory implements TypeSerializerFactory {
30 35
36 + private final Logger log = getLogger(getClass());
31 private final TypeSerializer<?> typeSerializer; 37 private final TypeSerializer<?> typeSerializer;
32 38
33 public DefaultCatalystTypeSerializerFactory(Serializer serializer) { 39 public DefaultCatalystTypeSerializerFactory(Serializer serializer) {
...@@ -53,15 +59,25 @@ public class DefaultCatalystTypeSerializerFactory implements TypeSerializerFacto ...@@ -53,15 +59,25 @@ public class DefaultCatalystTypeSerializerFactory implements TypeSerializerFacto
53 int size = input.readInt(); 59 int size = input.readInt();
54 byte[] payload = new byte[size]; 60 byte[] payload = new byte[size];
55 input.read(payload); 61 input.read(payload);
56 - return this.serializer.decode(payload); 62 + try {
63 + return this.serializer.decode(payload);
64 + } catch (Exception e) {
65 + log.warn("Failed to deserialize as type {}", clazz, e);
66 + Throwables.propagate(e);
67 + return null;
68 + }
57 } 69 }
58 70
59 @Override 71 @Override
60 public void write(T object, BufferOutput<?> output, 72 public void write(T object, BufferOutput<?> output,
61 io.atomix.catalyst.serializer.Serializer serializer) { 73 io.atomix.catalyst.serializer.Serializer serializer) {
62 - byte[] payload = this.serializer.encode(object); 74 + try {
63 - output.writeInt(payload.length); 75 + byte[] payload = this.serializer.encode(object);
64 - output.write(payload); 76 + output.writeInt(payload.length);
77 + output.write(payload);
78 + } catch (Exception e) {
79 + log.warn("Failed to serialize {}", object, e);
80 + }
65 } 81 }
66 } 82 }
67 } 83 }
......
...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
19 19
20 import java.util.List; 20 import java.util.List;
21 import java.util.Map; 21 import java.util.Map;
22 +import java.util.Set;
22 import java.util.TreeMap; 23 import java.util.TreeMap;
23 24
24 import org.apache.commons.lang.StringUtils; 25 import org.apache.commons.lang.StringUtils;
...@@ -33,8 +34,10 @@ import org.onosproject.store.service.AsyncLeaderElector; ...@@ -33,8 +34,10 @@ import org.onosproject.store.service.AsyncLeaderElector;
33 import org.onosproject.store.service.DistributedQueue; 34 import org.onosproject.store.service.DistributedQueue;
34 import org.onosproject.store.service.Serializer; 35 import org.onosproject.store.service.Serializer;
35 36
37 +import com.google.common.collect.ImmutableSet;
36 import com.google.common.collect.Lists; 38 import com.google.common.collect.Lists;
37 import com.google.common.collect.Maps; 39 import com.google.common.collect.Maps;
40 +import com.google.common.collect.Sets;
38 import com.google.common.hash.HashCode; 41 import com.google.common.hash.HashCode;
39 import com.google.common.hash.Hashing; 42 import com.google.common.hash.Hashing;
40 import com.google.common.primitives.Bytes; 43 import com.google.common.primitives.Bytes;
...@@ -93,6 +96,24 @@ public class FederatedDistributedPrimitiveCreator implements DistributedPrimitiv ...@@ -93,6 +96,24 @@ public class FederatedDistributedPrimitiveCreator implements DistributedPrimitiv
93 return getCreator(name).newAsyncLeaderElector(name); 96 return getCreator(name).newAsyncLeaderElector(name);
94 } 97 }
95 98
99 + @Override
100 + public Set<String> getAsyncConsistentMapNames() {
101 + return members.values()
102 + .stream()
103 + .map(DistributedPrimitiveCreator::getAsyncConsistentMapNames)
104 + .reduce(Sets::union)
105 + .orElse(ImmutableSet.of());
106 + }
107 +
108 + @Override
109 + public Set<String> getAsyncAtomicCounterNames() {
110 + return members.values()
111 + .stream()
112 + .map(DistributedPrimitiveCreator::getAsyncAtomicCounterNames)
113 + .reduce(Sets::union)
114 + .orElse(ImmutableSet.of());
115 + }
116 +
96 /** 117 /**
97 * Returns the {@code DistributedPrimitiveCreator} to use for hosting a primitive. 118 * Returns the {@code DistributedPrimitiveCreator} to use for hosting a primitive.
98 * @param name primitive name 119 * @param name primitive name
......
...@@ -19,9 +19,12 @@ package org.onosproject.store.primitives.impl; ...@@ -19,9 +19,12 @@ package org.onosproject.store.primitives.impl;
19 import static org.slf4j.LoggerFactory.getLogger; 19 import static org.slf4j.LoggerFactory.getLogger;
20 20
21 import java.io.File; 21 import java.io.File;
22 +import java.util.List;
22 import java.util.Map; 23 import java.util.Map;
24 +import java.util.Optional;
23 import java.util.Set; 25 import java.util.Set;
24 import java.util.concurrent.CompletableFuture; 26 import java.util.concurrent.CompletableFuture;
27 +import java.util.stream.Collectors;
25 28
26 import org.apache.felix.scr.annotations.Activate; 29 import org.apache.felix.scr.annotations.Activate;
27 import org.apache.felix.scr.annotations.Component; 30 import org.apache.felix.scr.annotations.Component;
...@@ -40,6 +43,7 @@ import org.onosproject.store.primitives.PartitionAdminService; ...@@ -40,6 +43,7 @@ import org.onosproject.store.primitives.PartitionAdminService;
40 import org.onosproject.store.primitives.PartitionEvent; 43 import org.onosproject.store.primitives.PartitionEvent;
41 import org.onosproject.store.primitives.PartitionEventListener; 44 import org.onosproject.store.primitives.PartitionEventListener;
42 import org.onosproject.store.primitives.PartitionService; 45 import org.onosproject.store.primitives.PartitionService;
46 +import org.onosproject.store.service.PartitionInfo;
43 import org.slf4j.Logger; 47 import org.slf4j.Logger;
44 48
45 import com.google.common.collect.ImmutableSet; 49 import com.google.common.collect.ImmutableSet;
...@@ -137,4 +141,14 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa ...@@ -137,4 +141,14 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa
137 // members of partition 141 // members of partition
138 return getConfiguredMembers(partitionId); 142 return getConfiguredMembers(partitionId);
139 } 143 }
144 +
145 + @Override
146 + public List<PartitionInfo> partitionInfo() {
147 + return partitions.values()
148 + .stream()
149 + .map(StoragePartition::info)
150 + .filter(Optional::isPresent)
151 + .map(Optional::get)
152 + .collect(Collectors.toList());
153 + }
140 } 154 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -33,6 +33,7 @@ import org.onosproject.cluster.NodeId; ...@@ -33,6 +33,7 @@ import org.onosproject.cluster.NodeId;
33 import org.onosproject.cluster.Partition; 33 import org.onosproject.cluster.Partition;
34 import org.onosproject.store.cluster.messaging.MessagingService; 34 import org.onosproject.store.cluster.messaging.MessagingService;
35 import org.onosproject.store.primitives.resources.impl.AtomixConsistentMap; 35 import org.onosproject.store.primitives.resources.impl.AtomixConsistentMap;
36 +import org.onosproject.store.service.PartitionInfo;
36 37
37 import com.google.common.collect.Collections2; 38 import com.google.common.collect.Collections2;
38 import com.google.common.collect.ImmutableSet; 39 import com.google.common.collect.ImmutableSet;
...@@ -146,4 +147,13 @@ public class StoragePartition extends DefaultPartition implements Managed<Storag ...@@ -146,4 +147,13 @@ public class StoragePartition extends DefaultPartition implements Managed<Storag
146 public boolean isClosed() { 147 public boolean isClosed() {
147 return isOpened.get() && isClosed.get(); 148 return isOpened.get() && isClosed.get();
148 } 149 }
150 +
151 + /**
152 + * Returns the partition information if this partition is locally managed i.e.
153 + * this node is a active member of the partition.
154 + * @return partition info
155 + */
156 + public Optional<PartitionInfo> info() {
157 + return server.map(StoragePartitionServer::info);
158 + }
149 } 159 }
......
...@@ -22,6 +22,7 @@ import io.atomix.resource.ResourceType; ...@@ -22,6 +22,7 @@ import io.atomix.resource.ResourceType;
22 import io.atomix.variables.DistributedLong; 22 import io.atomix.variables.DistributedLong;
23 23
24 import java.util.Collection; 24 import java.util.Collection;
25 +import java.util.Set;
25 import java.util.concurrent.CompletableFuture; 26 import java.util.concurrent.CompletableFuture;
26 27
27 import org.onlab.util.HexString; 28 import org.onlab.util.HexString;
...@@ -136,6 +137,16 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana ...@@ -136,6 +137,16 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana
136 } 137 }
137 138
138 @Override 139 @Override
140 + public Set<String> getAsyncConsistentMapNames() {
141 + return client.keys(AtomixConsistentMap.class).join();
142 + }
143 +
144 + @Override
145 + public Set<String> getAsyncAtomicCounterNames() {
146 + return client.keys(DistributedLong.class).join();
147 + }
148 +
149 + @Override
139 public boolean isOpen() { 150 public boolean isOpen() {
140 return client.isOpen(); 151 return client.isOpen();
141 } 152 }
......
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.impl;
17 +
18 +import io.atomix.copycat.server.cluster.Member;
19 +
20 +import java.util.Collection;
21 +import java.util.Set;
22 +
23 +import org.onosproject.cluster.PartitionId;
24 +import org.onosproject.store.service.PartitionInfo;
25 +
26 +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.Lists;
30 +
31 +/**
32 + * Operational details for a {@code StoragePartition}.
33 + */
34 +public class StoragePartitionDetails {
35 +
36 + private final PartitionId partitionId;
37 + private final Set<Member> activeMembers;
38 + private final Set<Member> configuredMembers;
39 + private final Member leader;
40 + private final long leaderTerm;
41 +
42 + public StoragePartitionDetails(PartitionId partitionId,
43 + Collection<Member> activeMembers,
44 + Collection<Member> configuredMembers,
45 + Member leader,
46 + long leaderTerm) {
47 + this.partitionId = partitionId;
48 + this.activeMembers = ImmutableSet.copyOf(activeMembers);
49 + this.configuredMembers = ImmutableSet.copyOf(configuredMembers);
50 + this.leader = leader;
51 + this.leaderTerm = leaderTerm;
52 + }
53 +
54 + /**
55 + * Returns the set of active members.
56 + * @return active members
57 + */
58 + public Set<Member> activeMembers() {
59 + return activeMembers;
60 + }
61 +
62 + /**
63 + * Returns the set of configured members.
64 + * @return configured members
65 + */
66 + public Set<Member> configuredMembers() {
67 + return configuredMembers;
68 + }
69 +
70 + /**
71 + * Returns the partition leader.
72 + * @return leader
73 + */
74 + public Member leader() {
75 + return leader;
76 + }
77 +
78 + /**
79 + * Returns the partition leader term.
80 + * @return leader term
81 + */
82 + public long leaderTerm() {
83 + return leaderTerm;
84 + }
85 +
86 + @Override
87 + public String toString() {
88 + return MoreObjects.toStringHelper(getClass())
89 + .add("activeMembers", activeMembers)
90 + .add("configuredMembers", configuredMembers)
91 + .add("leader", leader)
92 + .add("leaderTerm", leaderTerm)
93 + .toString();
94 + }
95 +
96 + /**
97 + * Returns the details as an instance of {@code PartitionInfo}.
98 + * @return partition info
99 + */
100 + public PartitionInfo toPartitionInfo() {
101 + return new PartitionInfo(partitionId.toString(),
102 + leaderTerm,
103 + Lists.transform(ImmutableList.copyOf(activeMembers), m -> m.address().toString()),
104 + leader == null ? "none" : leader.address().toString());
105 + }
106 +}
...@@ -34,6 +34,7 @@ import java.util.concurrent.CompletableFuture; ...@@ -34,6 +34,7 @@ import java.util.concurrent.CompletableFuture;
34 import java.util.function.Supplier; 34 import java.util.function.Supplier;
35 35
36 import org.onosproject.cluster.NodeId; 36 import org.onosproject.cluster.NodeId;
37 +import org.onosproject.store.service.PartitionInfo;
37 38
38 import com.google.common.collect.ImmutableSet; 39 import com.google.common.collect.ImmutableSet;
39 import com.google.common.collect.Sets; 40 import com.google.common.collect.Sets;
...@@ -124,4 +125,16 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> { ...@@ -124,4 +125,16 @@ public class StoragePartitionServer implements Managed<StoragePartitionServer> {
124 public boolean isClosed() { 125 public boolean isClosed() {
125 return server.isClosed(); 126 return server.isClosed();
126 } 127 }
128 +
129 + /**
130 + * Returns the partition information.
131 + * @return partition info
132 + */
133 + public PartitionInfo info() {
134 + return new StoragePartitionDetails(partition.getId(),
135 + server.cluster().members(),
136 + server.cluster().members(),
137 + server.cluster().leader(),
138 + server.cluster().term()).toPartitionInfo();
139 + }
127 } 140 }
......
...@@ -71,8 +71,7 @@ public class AtomixCounter implements AsyncAtomicCounter { ...@@ -71,8 +71,7 @@ public class AtomixCounter implements AsyncAtomicCounter {
71 } 71 }
72 72
73 @Override 73 @Override
74 - public CompletableFuture<Boolean> compareAndSet(long expectedValue, 74 + public CompletableFuture<Boolean> compareAndSet(long expectedValue, long updateValue) {
75 - long updateValue) {
76 return distLong.compareAndSet(expectedValue, updateValue); 75 return distLong.compareAndSet(expectedValue, updateValue);
77 } 76 }
78 } 77 }
...\ No newline at end of file ...\ No newline at end of file
......