Refactor: perform further code simplification using asJavaMap
Change-Id: If61d9a0c14f77768a902c8c18340733bfb5d5357
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
index 19650e3..248061c 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
@@ -59,13 +59,22 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
-import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
-import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.*;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_NETWORK_CREATED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_NETWORK_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_NETWORK_UPDATED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_PORT_CREATED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_PORT_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_PORT_SECURITY_GROUP_ADDED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_PORT_SECURITY_GROUP_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_PORT_UPDATED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_SUBNET_CREATED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_SUBNET_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackNetworkEvent.Type.OPENSTACK_SUBNET_UPDATED;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -184,16 +193,12 @@
@Override
public Network network(String netId) {
- Versioned<Network> versioned = osNetworkStore.get(netId);
- return versioned == null ? null : versioned.value();
+ return osNetworkStore.asJavaMap().get(netId);
}
@Override
public Set<Network> networks() {
- Set<Network> osNets = osNetworkStore.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(osNets);
+ return ImmutableSet.copyOf(osNetworkStore.asJavaMap().values());
}
@Override
@@ -222,16 +227,12 @@
@Override
public Subnet subnet(String subnetId) {
- Versioned<Subnet> osSubnet = osSubnetStore.get(subnetId);
- return osSubnet == null ? null : osSubnet.value();
+ return osSubnetStore.asJavaMap().get(subnetId);
}
@Override
public Set<Subnet> subnets() {
- Set<Subnet> osSubnets = osSubnetStore.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(osSubnets);
+ return ImmutableSet.copyOf(osSubnetStore.asJavaMap().values());
}
@Override
@@ -260,16 +261,12 @@
@Override
public Port port(String portId) {
- Versioned<Port> osPort = osPortStore.get(portId);
- return osPort == null ? null : osPort.value();
+ return osPortStore.asJavaMap().get(portId);
}
@Override
public Set<Port> ports() {
- Set<Port> osPorts = osPortStore.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(osPorts);
+ return ImmutableSet.copyOf(osPortStore.asJavaMap().values());
}
@Override
@@ -286,30 +283,30 @@
switch (event.type()) {
case UPDATE:
log.debug("OpenStack network updated");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackNetworkEvent(
OPENSTACK_NETWORK_UPDATED,
- event.newValue().value()));
- });
+ event.newValue().value()))
+ );
break;
case INSERT:
log.debug("OpenStack network created");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackNetworkEvent(
OPENSTACK_NETWORK_CREATED,
- event.newValue().value()));
- });
+ event.newValue().value()))
+ );
break;
case REMOVE:
log.debug("OpenStack network removed");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackNetworkEvent(
OPENSTACK_NETWORK_REMOVED,
- event.oldValue().value()));
- });
+ event.oldValue().value()))
+ );
break;
default:
- log.error("Unsupported event type");
+ log.error("Unsupported openstack network event type");
break;
}
}
@@ -322,33 +319,33 @@
switch (event.type()) {
case UPDATE:
log.debug("OpenStack subnet updated");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackNetworkEvent(
OPENSTACK_SUBNET_UPDATED,
network(event.newValue().value().getNetworkId()),
- event.newValue().value()));
- });
+ event.newValue().value()))
+ );
break;
case INSERT:
log.debug("OpenStack subnet created");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackNetworkEvent(
OPENSTACK_SUBNET_CREATED,
network(event.newValue().value().getNetworkId()),
- event.newValue().value()));
- });
+ event.newValue().value()))
+ );
break;
case REMOVE:
log.debug("OpenStack subnet removed");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackNetworkEvent(
OPENSTACK_SUBNET_REMOVED,
network(event.oldValue().value().getNetworkId()),
- event.oldValue().value()));
- });
+ event.oldValue().value()))
+ );
break;
default:
- log.error("Unsupported event type");
+ log.error("Unsupported openstack subnet event type");
break;
}
}
@@ -372,24 +369,24 @@
break;
case INSERT:
log.debug("OpenStack port created");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackNetworkEvent(
OPENSTACK_PORT_CREATED,
network(event.newValue().value().getNetworkId()),
- event.newValue().value()));
- });
+ event.newValue().value()))
+ );
break;
case REMOVE:
log.debug("OpenStack port removed");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackNetworkEvent(
OPENSTACK_PORT_REMOVED,
network(event.oldValue().value().getNetworkId()),
- event.oldValue().value()));
- });
+ event.oldValue().value()))
+ );
break;
default:
- log.error("Unsupported event type");
+ log.error("Unsupported openstack port event type");
break;
}
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
index 62fc7ac..bea2a00 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
@@ -52,13 +52,24 @@
import java.util.Set;
import java.util.concurrent.ExecutorService;
-import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
-import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.*;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_FLOATING_IP_ASSOCIATED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_FLOATING_IP_CREATED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_FLOATING_IP_DISASSOCIATED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_FLOATING_IP_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_FLOATING_IP_UPDATED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_ROUTER_CREATED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_ROUTER_GATEWAY_ADDED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_ROUTER_GATEWAY_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_ROUTER_INTERFACE_ADDED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_ROUTER_INTERFACE_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_ROUTER_INTERFACE_UPDATED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_ROUTER_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackRouterEvent.Type.OPENSTACK_ROUTER_UPDATED;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -174,16 +185,12 @@
@Override
public Router router(String routerId) {
- Versioned<Router> versioned = osRouterStore.get(routerId);
- return versioned == null ? null : versioned.value();
+ return osRouterStore.asJavaMap().get(routerId);
}
@Override
public Set<Router> routers() {
- Set<Router> osRouters = osRouterStore.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(osRouters);
+ return ImmutableSet.copyOf(osRouterStore.asJavaMap().values());
}
@Override
@@ -212,16 +219,12 @@
@Override
public RouterInterface routerInterface(String routerIfaceId) {
- Versioned<RouterInterface> osRouterIface = osRouterInterfaceStore.get(routerIfaceId);
- return osRouterIface == null ? null : osRouterIface.value();
+ return osRouterInterfaceStore.asJavaMap().get(routerIfaceId);
}
@Override
public Set<RouterInterface> routerInterfaces() {
- Set<RouterInterface> osRouterIfaces = osRouterInterfaceStore.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(osRouterIfaces);
+ return ImmutableSet.copyOf(osRouterInterfaceStore.asJavaMap().values());
}
@Override
@@ -250,16 +253,12 @@
@Override
public NetFloatingIP floatingIp(String floatingIpId) {
- Versioned<NetFloatingIP> osFloatingIp = osFloatingIpStore.get(floatingIpId);
- return osFloatingIp == null ? null : osFloatingIp.value();
+ return osFloatingIpStore.asJavaMap().get(floatingIpId);
}
@Override
public Set<NetFloatingIP> floatingIps() {
- Set<NetFloatingIP> osFloatingIps = osFloatingIpStore.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(osFloatingIps);
+ return ImmutableSet.copyOf(osFloatingIpStore.asJavaMap().values());
}
@Override
@@ -285,22 +284,22 @@
break;
case INSERT:
log.debug("OpenStack router created");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackRouterEvent(
OPENSTACK_ROUTER_CREATED,
- event.newValue().value()));
- });
+ event.newValue().value()))
+ );
break;
case REMOVE:
log.debug("OpenStack router removed");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackRouterEvent(
OPENSTACK_ROUTER_REMOVED,
- event.oldValue().value()));
- });
+ event.oldValue().value()))
+ );
break;
default:
- log.error("Unsupported event type");
+ log.error("Unsupported openstack router event type");
break;
}
}
@@ -329,33 +328,33 @@
switch (event.type()) {
case UPDATE:
log.debug("OpenStack router interface updated");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackRouterEvent(
OPENSTACK_ROUTER_INTERFACE_UPDATED,
router(event.newValue().value().getId()),
- event.newValue().value()));
- });
+ event.newValue().value()))
+ );
break;
case INSERT:
log.debug("OpenStack router interface created");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackRouterEvent(
OPENSTACK_ROUTER_INTERFACE_ADDED,
router(event.newValue().value().getId()),
- event.newValue().value()));
- });
+ event.newValue().value()))
+ );
break;
case REMOVE:
log.debug("OpenStack router interface removed");
- eventExecutor.execute(() -> {
+ eventExecutor.execute(() ->
notifyDelegate(new OpenstackRouterEvent(
OPENSTACK_ROUTER_INTERFACE_REMOVED,
router(event.oldValue().value().getId()),
- event.oldValue().value()));
- });
+ event.oldValue().value()))
+ );
break;
default:
- log.error("Unsupported event type");
+ log.error("Unsupported openstack router interface event type");
break;
}
}
@@ -407,7 +406,7 @@
});
break;
default:
- log.error("Unsupported event type");
+ log.error("Unsupported openstack floating IP event type");
break;
}
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedSecurityGroupStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedSecurityGroupStore.java
index c82c703..0e1a880 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedSecurityGroupStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedSecurityGroupStore.java
@@ -50,7 +50,10 @@
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
-import static org.onosproject.openstacknetworking.api.OpenstackSecurityGroupEvent.Type.*;
+import static org.onosproject.openstacknetworking.api.OpenstackSecurityGroupEvent.Type.OPENSTACK_SECURITY_GROUP_CREATED;
+import static org.onosproject.openstacknetworking.api.OpenstackSecurityGroupEvent.Type.OPENSTACK_SECURITY_GROUP_REMOVED;
+import static org.onosproject.openstacknetworking.api.OpenstackSecurityGroupEvent.Type.OPENSTACK_SECURITY_GROUP_RULE_CREATED;
+import static org.onosproject.openstacknetworking.api.OpenstackSecurityGroupEvent.Type.OPENSTACK_SECURITY_GROUP_RULE_REMOVED;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -138,16 +141,12 @@
@Override
public SecurityGroup securityGroup(String sgId) {
- Versioned<SecurityGroup> osSg = osSecurityGroupStore.get(sgId);
- return osSg == null ? null : osSg.value();
+ return osSecurityGroupStore.asJavaMap().get(sgId);
}
@Override
public Set<SecurityGroup> securityGroups() {
- Set<SecurityGroup> osSgs = osSecurityGroupStore.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(osSgs);
+ return ImmutableSet.copyOf(osSecurityGroupStore.asJavaMap().values());
}
@Override
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
index 230e740..ac1e796 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
@@ -51,7 +51,6 @@
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
-import org.onosproject.store.service.Versioned;
import org.openstack4j.model.network.ExternalGateway;
import org.openstack4j.model.network.IP;
import org.openstack4j.model.network.Network;
@@ -508,10 +507,7 @@
@Override
public Set<ExternalPeerRouter> externalPeerRouters() {
- Set<ExternalPeerRouter> externalPeerRouters = externalPeerRouterMap.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(externalPeerRouters);
+ return ImmutableSet.copyOf(externalPeerRouterMap.asJavaMap().values());
}
private boolean isNetworkInUse(String netId) {
@@ -533,7 +529,7 @@
@Override
public void notify(OpenstackNetworkEvent event) {
if (event != null) {
- log.trace("send oepnstack switching event {}", event);
+ log.trace("send openstack switching event {}", event);
process(event);
}
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManager.java
index c636a1c..658dc4f 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManager.java
@@ -273,7 +273,7 @@
@Override
public void notify(OpenstackRouterEvent event) {
if (event != null) {
- log.trace("send oepnstack routing event {}", event);
+ log.trace("send openstack routing event {}", event);
process(event);
}
}
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
index dd54eb7..0b67d73 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
@@ -42,7 +42,6 @@
import java.util.Set;
import java.util.concurrent.ExecutorService;
-import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
@@ -140,16 +139,12 @@
@Override
public Set<OpenstackNode> nodes() {
- Set<OpenstackNode> osNodes = osNodeStore.values().stream()
- .map(Versioned::value)
- .collect(Collectors.toSet());
- return ImmutableSet.copyOf(osNodes);
+ return ImmutableSet.copyOf(osNodeStore.asJavaMap().values());
}
@Override
public OpenstackNode node(String hostname) {
- Versioned<OpenstackNode> osNode = osNodeStore.get(hostname);
- return osNode == null ? null : osNode.value();
+ return osNodeStore.asJavaMap().get(hostname);
}
/**