Removed usage of deprecated ClusterCommunicationService APIs
Change-Id: Id306dadad48d1bad7b3fbde3a40ba3e0fdac4cbc
Showing
3 changed files
with
32 additions
and
68 deletions
| ... | @@ -17,6 +17,7 @@ package org.onosproject.store.app; | ... | @@ -17,6 +17,7 @@ package org.onosproject.store.app; |
| 17 | 17 | ||
| 18 | import com.google.common.base.Charsets; | 18 | import com.google.common.base.Charsets; |
| 19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
| 20 | + | ||
| 20 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -39,8 +40,6 @@ import org.onosproject.core.ApplicationIdStore; | ... | @@ -39,8 +40,6 @@ import org.onosproject.core.ApplicationIdStore; |
| 39 | import org.onosproject.core.DefaultApplication; | 40 | import org.onosproject.core.DefaultApplication; |
| 40 | import org.onosproject.core.Permission; | 41 | import org.onosproject.core.Permission; |
| 41 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 42 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
| 42 | -import org.onosproject.store.cluster.messaging.ClusterMessage; | ||
| 43 | -import org.onosproject.store.cluster.messaging.ClusterMessageHandler; | ||
| 44 | import org.onosproject.store.cluster.messaging.MessageSubject; | 43 | import org.onosproject.store.cluster.messaging.MessageSubject; |
| 45 | import org.onosproject.store.serializers.KryoNamespaces; | 44 | import org.onosproject.store.serializers.KryoNamespaces; |
| 46 | import org.onosproject.store.service.EventuallyConsistentMap; | 45 | import org.onosproject.store.service.EventuallyConsistentMap; |
| ... | @@ -48,10 +47,12 @@ import org.onosproject.store.service.EventuallyConsistentMapEvent; | ... | @@ -48,10 +47,12 @@ import org.onosproject.store.service.EventuallyConsistentMapEvent; |
| 48 | import org.onosproject.store.service.EventuallyConsistentMapListener; | 47 | import org.onosproject.store.service.EventuallyConsistentMapListener; |
| 49 | import org.onosproject.store.service.LogicalClockService; | 48 | import org.onosproject.store.service.LogicalClockService; |
| 50 | import org.onosproject.store.service.MultiValuedTimestamp; | 49 | import org.onosproject.store.service.MultiValuedTimestamp; |
| 50 | +import org.onosproject.store.service.StorageException; | ||
| 51 | import org.onosproject.store.service.StorageService; | 51 | import org.onosproject.store.service.StorageService; |
| 52 | import org.slf4j.Logger; | 52 | import org.slf4j.Logger; |
| 53 | 53 | ||
| 54 | import java.io.ByteArrayInputStream; | 54 | import java.io.ByteArrayInputStream; |
| 55 | +import java.io.IOException; | ||
| 55 | import java.io.InputStream; | 56 | import java.io.InputStream; |
| 56 | import java.util.Set; | 57 | import java.util.Set; |
| 57 | import java.util.concurrent.CountDownLatch; | 58 | import java.util.concurrent.CountDownLatch; |
| ... | @@ -126,7 +127,17 @@ public class GossipApplicationStore extends ApplicationArchive | ... | @@ -126,7 +127,17 @@ public class GossipApplicationStore extends ApplicationArchive |
| 126 | messageHandlingExecutor = Executors.newSingleThreadExecutor( | 127 | messageHandlingExecutor = Executors.newSingleThreadExecutor( |
| 127 | groupedThreads("onos/store/app", "message-handler")); | 128 | groupedThreads("onos/store/app", "message-handler")); |
| 128 | 129 | ||
| 129 | - clusterCommunicator.addSubscriber(APP_BITS_REQUEST, new InternalBitServer(), messageHandlingExecutor); | 130 | + clusterCommunicator.<String, byte[]>addSubscriber(APP_BITS_REQUEST, |
| 131 | + bytes -> new String(bytes, Charsets.UTF_8), | ||
| 132 | + name -> { | ||
| 133 | + try { | ||
| 134 | + return toByteArray(getApplicationInputStream(name)); | ||
| 135 | + } catch (IOException e) { | ||
| 136 | + throw new StorageException(e); | ||
| 137 | + } | ||
| 138 | + }, | ||
| 139 | + Function.identity(), | ||
| 140 | + messageHandlingExecutor); | ||
| 130 | 141 | ||
| 131 | // FIXME: Consider consolidating into a single map. | 142 | // FIXME: Consider consolidating into a single map. |
| 132 | 143 | ||
| ... | @@ -394,21 +405,6 @@ public class GossipApplicationStore extends ApplicationArchive | ... | @@ -394,21 +405,6 @@ public class GossipApplicationStore extends ApplicationArchive |
| 394 | } | 405 | } |
| 395 | 406 | ||
| 396 | /** | 407 | /** |
| 397 | - * Responder to requests for application bits. | ||
| 398 | - */ | ||
| 399 | - private class InternalBitServer implements ClusterMessageHandler { | ||
| 400 | - @Override | ||
| 401 | - public void handle(ClusterMessage message) { | ||
| 402 | - String name = new String(message.payload(), Charsets.UTF_8); | ||
| 403 | - try { | ||
| 404 | - message.respond(toByteArray(getApplicationInputStream(name))); | ||
| 405 | - } catch (Exception e) { | ||
| 406 | - log.debug("Unable to read bits for application {}", name); | ||
| 407 | - } | ||
| 408 | - } | ||
| 409 | - } | ||
| 410 | - | ||
| 411 | - /** | ||
| 412 | * Prunes applications which are not in the map, but are on disk. | 408 | * Prunes applications which are not in the map, but are on disk. |
| 413 | */ | 409 | */ |
| 414 | private void pruneUninstalledApps() { | 410 | private void pruneUninstalledApps() { | ... | ... |
| ... | @@ -60,8 +60,6 @@ import org.onosproject.net.group.StoredGroupBucketEntry; | ... | @@ -60,8 +60,6 @@ import org.onosproject.net.group.StoredGroupBucketEntry; |
| 60 | import org.onosproject.net.group.StoredGroupEntry; | 60 | import org.onosproject.net.group.StoredGroupEntry; |
| 61 | import org.onosproject.store.AbstractStore; | 61 | import org.onosproject.store.AbstractStore; |
| 62 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 62 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
| 63 | -import org.onosproject.store.cluster.messaging.ClusterMessage; | ||
| 64 | -import org.onosproject.store.cluster.messaging.ClusterMessageHandler; | ||
| 65 | import org.onosproject.store.service.MultiValuedTimestamp; | 63 | import org.onosproject.store.service.MultiValuedTimestamp; |
| 66 | import org.onosproject.store.serializers.DeviceIdSerializer; | 64 | import org.onosproject.store.serializers.DeviceIdSerializer; |
| 67 | import org.onosproject.store.serializers.KryoNamespaces; | 65 | import org.onosproject.store.serializers.KryoNamespaces; |
| ... | @@ -198,9 +196,10 @@ public class DistributedGroupStore | ... | @@ -198,9 +196,10 @@ public class DistributedGroupStore |
| 198 | newFixedThreadPool(MESSAGE_HANDLER_THREAD_POOL_SIZE, | 196 | newFixedThreadPool(MESSAGE_HANDLER_THREAD_POOL_SIZE, |
| 199 | groupedThreads("onos/store/group", | 197 | groupedThreads("onos/store/group", |
| 200 | "message-handlers")); | 198 | "message-handlers")); |
| 201 | - clusterCommunicator. | 199 | + |
| 202 | - addSubscriber(GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, | 200 | + clusterCommunicator.addSubscriber(GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, |
| 203 | - new ClusterGroupMsgHandler(), | 201 | + kryoBuilder.build()::deserialize, |
| 202 | + this::process, | ||
| 204 | messageHandlingExecutor); | 203 | messageHandlingExecutor); |
| 205 | 204 | ||
| 206 | log.debug("Creating EC map groupstorekeymap"); | 205 | log.debug("Creating EC map groupstorekeymap"); |
| ... | @@ -970,26 +969,13 @@ public class DistributedGroupStore | ... | @@ -970,26 +969,13 @@ public class DistributedGroupStore |
| 970 | } | 969 | } |
| 971 | } | 970 | } |
| 972 | } | 971 | } |
| 973 | - /** | 972 | + |
| 974 | - * Message handler to receive messages from group subsystems of | 973 | + private void process(GroupStoreMessage groupOp) { |
| 975 | - * other cluster members. | 974 | + log.debug("Received remote group operation {} request for device {}", |
| 976 | - */ | ||
| 977 | - private final class ClusterGroupMsgHandler | ||
| 978 | - implements ClusterMessageHandler { | ||
| 979 | - @Override | ||
| 980 | - public void handle(ClusterMessage message) { | ||
| 981 | - if (message.subject().equals( | ||
| 982 | - GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST)) { | ||
| 983 | - GroupStoreMessage groupOp = kryoBuilder. | ||
| 984 | - build().deserialize(message.payload()); | ||
| 985 | - log.debug("received remote group operation {} request for device {}", | ||
| 986 | groupOp.type(), | 975 | groupOp.type(), |
| 987 | groupOp.deviceId()); | 976 | groupOp.deviceId()); |
| 988 | - if (mastershipService. | 977 | + if (!mastershipService.isLocalMaster(groupOp.deviceId())) { |
| 989 | - getLocalRole(groupOp.deviceId()) != | 978 | + log.warn("This node is not MASTER for device {}", groupOp.deviceId()); |
| 990 | - MastershipRole.MASTER) { | ||
| 991 | - log.warn("ClusterGroupMsgHandler: This node is not " | ||
| 992 | - + "MASTER for device {}", groupOp.deviceId()); | ||
| 993 | return; | 979 | return; |
| 994 | } | 980 | } |
| 995 | if (groupOp.type() == GroupStoreMessage.Type.ADD) { | 981 | if (groupOp.type() == GroupStoreMessage.Type.ADD) { |
| ... | @@ -1004,11 +990,6 @@ public class DistributedGroupStore | ... | @@ -1004,11 +990,6 @@ public class DistributedGroupStore |
| 1004 | deleteGroupDescriptionInternal(groupOp.deviceId(), | 990 | deleteGroupDescriptionInternal(groupOp.deviceId(), |
| 1005 | groupOp.appCookie()); | 991 | groupOp.appCookie()); |
| 1006 | } | 992 | } |
| 1007 | - } else { | ||
| 1008 | - log.warn("ClusterGroupMsgHandler: Unknown remote message type {}", | ||
| 1009 | - message.subject()); | ||
| 1010 | - } | ||
| 1011 | - } | ||
| 1012 | } | 993 | } |
| 1013 | 994 | ||
| 1014 | /** | 995 | /** | ... | ... |
| ... | @@ -35,8 +35,6 @@ import org.onosproject.net.packet.PacketStore; | ... | @@ -35,8 +35,6 @@ import org.onosproject.net.packet.PacketStore; |
| 35 | import org.onosproject.net.packet.PacketStoreDelegate; | 35 | import org.onosproject.net.packet.PacketStoreDelegate; |
| 36 | import org.onosproject.store.AbstractStore; | 36 | import org.onosproject.store.AbstractStore; |
| 37 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 37 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
| 38 | -import org.onosproject.store.cluster.messaging.ClusterMessage; | ||
| 39 | -import org.onosproject.store.cluster.messaging.ClusterMessageHandler; | ||
| 40 | import org.onosproject.store.cluster.messaging.MessageSubject; | 38 | import org.onosproject.store.cluster.messaging.MessageSubject; |
| 41 | import org.onosproject.store.serializers.KryoNamespaces; | 39 | import org.onosproject.store.serializers.KryoNamespaces; |
| 42 | import org.onosproject.store.serializers.KryoSerializer; | 40 | import org.onosproject.store.serializers.KryoSerializer; |
| ... | @@ -104,8 +102,9 @@ public class DistributedPacketStore | ... | @@ -104,8 +102,9 @@ public class DistributedPacketStore |
| 104 | MESSAGE_HANDLER_THREAD_POOL_SIZE, | 102 | MESSAGE_HANDLER_THREAD_POOL_SIZE, |
| 105 | groupedThreads("onos/store/packet", "message-handlers")); | 103 | groupedThreads("onos/store/packet", "message-handlers")); |
| 106 | 104 | ||
| 107 | - communicationService.addSubscriber(PACKET_OUT_SUBJECT, | 105 | + communicationService.<OutboundPacket>addSubscriber(PACKET_OUT_SUBJECT, |
| 108 | - new InternalClusterMessageHandler(), | 106 | + SERIALIZER::decode, |
| 107 | + packet -> notifyDelegate(new PacketEvent(Type.EMIT, packet)), | ||
| 109 | messageHandlingExecutor); | 108 | messageHandlingExecutor); |
| 110 | 109 | ||
| 111 | tracker = new PacketRequestTracker(); | 110 | tracker = new PacketRequestTracker(); |
| ... | @@ -134,9 +133,12 @@ public class DistributedPacketStore | ... | @@ -134,9 +133,12 @@ public class DistributedPacketStore |
| 134 | return; | 133 | return; |
| 135 | } | 134 | } |
| 136 | 135 | ||
| 137 | - // TODO check unicast return value | 136 | + communicationService.unicast(packet, PACKET_OUT_SUBJECT, SERIALIZER::encode, master) |
| 138 | - communicationService.unicast(packet, PACKET_OUT_SUBJECT, SERIALIZER::encode, master); | 137 | + .whenComplete((r, error) -> { |
| 139 | - // error log: log.warn("Failed to send packet-out to {}", master); | 138 | + if (error != null) { |
| 139 | + log.warn("Failed to send packet-out to {}", master, error); | ||
| 140 | + } | ||
| 141 | + }); | ||
| 140 | } | 142 | } |
| 141 | 143 | ||
| 142 | @Override | 144 | @Override |
| ... | @@ -154,21 +156,6 @@ public class DistributedPacketStore | ... | @@ -154,21 +156,6 @@ public class DistributedPacketStore |
| 154 | return tracker.requests(); | 156 | return tracker.requests(); |
| 155 | } | 157 | } |
| 156 | 158 | ||
| 157 | - /** | ||
| 158 | - * Handles incoming cluster messages. | ||
| 159 | - */ | ||
| 160 | - private class InternalClusterMessageHandler implements ClusterMessageHandler { | ||
| 161 | - @Override | ||
| 162 | - public void handle(ClusterMessage message) { | ||
| 163 | - if (!message.subject().equals(PACKET_OUT_SUBJECT)) { | ||
| 164 | - log.warn("Received message with wrong subject: {}", message); | ||
| 165 | - } | ||
| 166 | - | ||
| 167 | - OutboundPacket packet = SERIALIZER.decode(message.payload()); | ||
| 168 | - notifyDelegate(new PacketEvent(Type.EMIT, packet)); | ||
| 169 | - } | ||
| 170 | - } | ||
| 171 | - | ||
| 172 | private class PacketRequestTracker { | 159 | private class PacketRequestTracker { |
| 173 | 160 | ||
| 174 | private ConsistentMap<TrafficSelector, Set<PacketRequest>> requests; | 161 | private ConsistentMap<TrafficSelector, Set<PacketRequest>> requests; | ... | ... |
-
Please register or login to post a comment