bobzhou
Committed by Gerrit Code Review

[ONOS-5185] fix bug for VTN data synchronized failed in cluster mode

Change-Id: I8458d2492c52f43f1df0b661a921ee6f3027297d
...@@ -22,6 +22,7 @@ import java.util.Collection; ...@@ -22,6 +22,7 @@ import java.util.Collection;
22 import java.util.Collections; 22 import java.util.Collections;
23 import java.util.Iterator; 23 import java.util.Iterator;
24 import java.util.List; 24 import java.util.List;
25 +import java.util.UUID;
25 import java.util.stream.Collectors; 26 import java.util.stream.Collectors;
26 27
27 import org.apache.felix.scr.annotations.Activate; 28 import org.apache.felix.scr.annotations.Activate;
...@@ -37,6 +38,7 @@ import org.onosproject.core.ApplicationId; ...@@ -37,6 +38,7 @@ import org.onosproject.core.ApplicationId;
37 import org.onosproject.core.CoreService; 38 import org.onosproject.core.CoreService;
38 import org.onosproject.event.AbstractListenerManager; 39 import org.onosproject.event.AbstractListenerManager;
39 import org.onosproject.net.DeviceId; 40 import org.onosproject.net.DeviceId;
41 +import org.onosproject.net.Host;
40 import org.onosproject.store.serializers.KryoNamespaces; 42 import org.onosproject.store.serializers.KryoNamespaces;
41 import org.onosproject.store.service.EventuallyConsistentMap; 43 import org.onosproject.store.service.EventuallyConsistentMap;
42 import org.onosproject.store.service.EventuallyConsistentMapEvent; 44 import org.onosproject.store.service.EventuallyConsistentMapEvent;
...@@ -46,12 +48,18 @@ import org.onosproject.store.service.StorageService; ...@@ -46,12 +48,18 @@ import org.onosproject.store.service.StorageService;
46 import org.onosproject.store.service.WallClockTimestamp; 48 import org.onosproject.store.service.WallClockTimestamp;
47 import org.onosproject.vtnrsc.AllowedAddressPair; 49 import org.onosproject.vtnrsc.AllowedAddressPair;
48 import org.onosproject.vtnrsc.BindingHostId; 50 import org.onosproject.vtnrsc.BindingHostId;
51 +import org.onosproject.vtnrsc.DefaultFloatingIp;
49 import org.onosproject.vtnrsc.DefaultVirtualPort; 52 import org.onosproject.vtnrsc.DefaultVirtualPort;
50 import org.onosproject.vtnrsc.FixedIp; 53 import org.onosproject.vtnrsc.FixedIp;
54 +import org.onosproject.vtnrsc.FloatingIp;
55 +import org.onosproject.vtnrsc.FloatingIpId;
56 +import org.onosproject.vtnrsc.RouterId;
51 import org.onosproject.vtnrsc.SecurityGroup; 57 import org.onosproject.vtnrsc.SecurityGroup;
52 import org.onosproject.vtnrsc.SubnetId; 58 import org.onosproject.vtnrsc.SubnetId;
53 import org.onosproject.vtnrsc.TenantId; 59 import org.onosproject.vtnrsc.TenantId;
60 +import org.onosproject.vtnrsc.TenantNetwork;
54 import org.onosproject.vtnrsc.TenantNetworkId; 61 import org.onosproject.vtnrsc.TenantNetworkId;
62 +import org.onosproject.vtnrsc.TenantRouter;
55 import org.onosproject.vtnrsc.VirtualPort; 63 import org.onosproject.vtnrsc.VirtualPort;
56 import org.onosproject.vtnrsc.VirtualPortId; 64 import org.onosproject.vtnrsc.VirtualPortId;
57 import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; 65 import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
...@@ -71,7 +79,7 @@ implements VirtualPortService { ...@@ -71,7 +79,7 @@ implements VirtualPortService {
71 79
72 private final Logger log = LoggerFactory.getLogger(getClass()); 80 private final Logger log = LoggerFactory.getLogger(getClass());
73 81
74 - private static final String VIRTUALPORT = "vtn-virtual-port"; 82 + private static final String VIRTUALPORT = "vtn-virtual-port-store";
75 private static final String VTNRSC_APP = "org.onosproject.vtnrsc"; 83 private static final String VTNRSC_APP = "org.onosproject.vtnrsc";
76 84
77 private static final String VIRTUALPORT_ID_NULL = "VirtualPort ID cannot be null"; 85 private static final String VIRTUALPORT_ID_NULL = "VirtualPort ID cannot be null";
...@@ -106,22 +114,35 @@ implements VirtualPortService { ...@@ -106,22 +114,35 @@ implements VirtualPortService {
106 114
107 eventDispatcher.addSink(VirtualPortEvent.class, listenerRegistry); 115 eventDispatcher.addSink(VirtualPortEvent.class, listenerRegistry);
108 116
109 - vPortStore = storageService.<VirtualPortId, VirtualPort>eventuallyConsistentMapBuilder() 117 + KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
110 - .withName(VIRTUALPORT) 118 + .register(KryoNamespaces.API)
111 - .withSerializer(KryoNamespace.newBuilder().register(KryoNamespaces.API)
112 .register(MultiValuedTimestamp.class) 119 .register(MultiValuedTimestamp.class)
113 - .register(VirtualPortId.class, 120 + .register(TenantNetworkId.class)
114 - TenantNetworkId.class, 121 + .register(Host.class)
115 - VirtualPort.State.class, 122 + .register(TenantNetwork.class)
116 - TenantId.class, 123 + .register(TenantNetworkId.class)
117 - AllowedAddressPair.class, 124 + .register(TenantId.class)
118 - FixedIp.class, 125 + .register(SubnetId.class)
119 - BindingHostId.class, 126 + .register(VirtualPortId.class)
120 - SecurityGroup.class, 127 + .register(VirtualPort.State.class)
121 - SubnetId.class, 128 + .register(AllowedAddressPair.class)
122 - IpAddress.class, 129 + .register(FixedIp.class)
123 - DefaultVirtualPort.class)) 130 + .register(FloatingIp.class)
124 - .withTimestampProvider((k, v) ->new WallClockTimestamp()) 131 + .register(FloatingIpId.class)
132 + .register(FloatingIp.Status.class)
133 + .register(UUID.class)
134 + .register(DefaultFloatingIp.class)
135 + .register(BindingHostId.class)
136 + .register(SecurityGroup.class)
137 + .register(IpAddress.class)
138 + .register(DefaultVirtualPort.class)
139 + .register(RouterId.class)
140 + .register(TenantRouter.class)
141 + .register(VirtualPort.class);
142 + vPortStore = storageService
143 + .<VirtualPortId, VirtualPort>eventuallyConsistentMapBuilder()
144 + .withName(VIRTUALPORT).withSerializer(serializer)
145 + .withTimestampProvider((k, v) -> new WallClockTimestamp())
125 .build(); 146 .build();
126 147
127 vPortStore.addListener(virtualPortListener); 148 vPortStore.addListener(virtualPortListener);
...@@ -130,7 +151,8 @@ implements VirtualPortService { ...@@ -130,7 +151,8 @@ implements VirtualPortService {
130 151
131 @Deactivate 152 @Deactivate
132 public void deactivate() { 153 public void deactivate() {
133 - vPortStore.clear(); 154 + vPortStore.removeListener(virtualPortListener);
155 + vPortStore.destroy();
134 log.info("Stoppped"); 156 log.info("Stoppped");
135 } 157 }
136 158
......