diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index a448091c2..0b6a52b8a 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -451,8 +451,12 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni e.printStackTrace(); } }); + unicastHostResourceBuilder.addAllResources(unicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(unicastGoalStateV2.getHostIp()).getResourcesList()); unicastGoalStateV2.getGoalStateBuilder().putHostResources(unicastGoalStateV2.getHostIp(), unicastHostResourceBuilder.build()); for (String hostIp : multicastGoalStateV2.getHostIps()) { + if (multicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap(). containsKey(hostIp) && multicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(hostIp) != null) { + multicastHostResourceBuilder.addAllResources(multicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(hostIp).getResourcesList()); + } multicastGoalStateV2.getGoalStateBuilder().putHostResources(hostIp, multicastHostResourceBuilder.build()); } unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java index 8dc0eb0aa..5ddf7e8b7 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java @@ -18,33 +18,20 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.logging.Logger; import com.futurewei.alcor.common.logging.LoggerFactory; import com.futurewei.alcor.common.stats.DurationStatistics; -import com.futurewei.alcor.netwconfigmanager.cache.ResourceStateCache; import com.futurewei.alcor.netwconfigmanager.client.GoalStateClient; import com.futurewei.alcor.netwconfigmanager.config.Config; import com.futurewei.alcor.netwconfigmanager.entity.HostGoalState; -import com.futurewei.alcor.netwconfigmanager.service.ResourceInfo; import com.futurewei.alcor.schema.*; import io.grpc.ConnectivityState; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder; -import io.grpc.netty.shaded.io.netty.channel.epoll.EpollEventLoopGroup; -import io.grpc.netty.shaded.io.netty.channel.epoll.EpollSocketChannel; -import io.grpc.stub.ClientCallStreamObserver; -import io.grpc.stub.ServerCallStreamObserver; import io.grpc.stub.StreamObserver; import io.jaegertracing.Configuration; -import io.jaegertracing.internal.JaegerTracer; import io.jaegertracing.internal.samplers.ConstSampler; -import io.lettuce.core.dynamic.annotation.Param; import io.netty.util.concurrent.DefaultThreadFactory; -import io.opentracing.Scope; -import io.opentracing.Span; -import io.opentracing.contrib.tracerresolver.TracerResolver; import io.opentracing.util.GlobalTracer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Service; import java.util.*; import java.util.concurrent.*; @@ -61,9 +48,6 @@ public class GoalStateClientImpl implements GoalStateClient { private final ExecutorService executor; - @Autowired - private ResourceInfo resourceInfo; - // each host_ip should have this amount of gRPC channels @Value("${grpc.number-of-channels-per-host:1}") private int numberOfGrpcChannelPerHost; @@ -128,9 +112,8 @@ public List sendGoalStates(Map hostGoalStates) th logger.log(Level.INFO, "Host goal states size: " + hostGoalStates.values().size()); List replies = new ArrayList<>(); - boolean isAttache = !hostGoalStates.values().parallelStream().anyMatch(hostGoalState -> hostGoalState.getGoalState().getPortStatesCount() > 0); for (HostGoalState hostGoalState : hostGoalStates.values()) { - doSendGoalState(hostGoalState, finishLatch, replies, isAttache); + doSendGoalState(hostGoalState, finishLatch, replies); } if (!finishLatch.await(5, TimeUnit.MINUTES)) { @@ -256,7 +239,7 @@ private GrpcChannelStub createGrpcChannelStub(String hostIp) { } - private void doSendGoalState(HostGoalState hostGoalState, CountDownLatch finishLatch, List replies, boolean isAttache) throws InterruptedException { + private void doSendGoalState(HostGoalState hostGoalState, CountDownLatch finishLatch, List replies) throws InterruptedException { String hostIp = hostGoalState.getHostIp(); logger.log(Level.FINE, "Setting up a channel to ACA on: " + hostIp); long start = System.currentTimeMillis(); @@ -302,19 +285,10 @@ public void onCompleted() { try { long before_get_goalState = System.currentTimeMillis(); Goalstate.GoalStateV2 goalState = hostGoalState.getGoalState(); - Set resourceIds = goalState.getHostResourcesMap().get(hostIp).getResourcesList().stream().filter(resourceIdType -> resourceIdType.getType().equals(Common.ResourceType.NEIGHBOR)).map(resourceIdType -> resourceIdType.getId()).collect(Collectors.toSet()); - Goalstate.GoalStateV2.Builder goalstateBuilder = Goalstate.GoalStateV2.newBuilder(); - goalstateBuilder.mergeFrom(goalState); - if (isAttache || goalstateBuilder.getPortStatesCount() > 0) { - Map neighborStateMap = resourceInfo.getNeighborStates(resourceIds); - if (neighborStateMap.size() > 0) { - goalstateBuilder.putAllNeighborStates(neighborStateMap); - } - } long after_get_goalState = System.currentTimeMillis(); - logger.log(Level.FINE, "Sending GS with size " + goalState.getSerializedSize() + " to Host " + hostIp + " as follows | " + goalstateBuilder.build()); + logger.log(Level.FINE, "Sending GS with size " + goalState.getSerializedSize() + " to Host " + hostIp + " as follows | " + goalState); - requestObserver.onNext(goalstateBuilder.build()); + requestObserver.onNext(goalState); long after_onNext = System.currentTimeMillis(); logger.log(Level.FINE, "[doSendGoalState] Get goalstatev2 from HostGoalState in milliseconds: " + (after_get_goalState - before_get_goalState)); logger.log(Level.FINE, "[doSendGoalState] Call onNext in milliseconds: " + (after_onNext - after_get_goalState)); diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java index 53e24b6b0..4a7aeda7f 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java @@ -214,7 +214,6 @@ public void onNext(Goalstate.GoalStateV2 value) { Span storeGsSpan = tracer.buildSpan(serverStoreGsSpanName).asChildOf(span.context()).start(); Scope storageCscope = tracer.scopeManager().activate(storeGsSpan); - //store the goal state in cache Map hostGoalStates = new HashMap<>(); try { @@ -225,9 +224,7 @@ public void onNext(Goalstate.GoalStateV2 value) { } storeGsSpan.finish(); - Set processedResourceIds = new HashSet<>(); - long end = System.currentTimeMillis(); logger.log(Level.FINE, "pushGoalStatesStream : finished putting GS into cache, elapsed time in milliseconds: " + + (end-start)); Span filterSendGsSpan = tracer.buildSpan(serverFilterSendGsSpanName).asChildOf(span.context()).start(); diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/GoalStatePersistenceService.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/GoalStatePersistenceService.java index d82a979ea..f602769df 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/GoalStatePersistenceService.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/GoalStatePersistenceService.java @@ -36,4 +36,6 @@ public interface GoalStatePersistenceService { Map updateGoalStates(Goalstate.GoalStateV2 goalStateV2) throws Exception; + void patchNeighbors(Map hostGoalStates) throws Exception; + } diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/ResourceInfo.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/ResourceInfo.java deleted file mode 100644 index 49958357f..000000000 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/ResourceInfo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.futurewei.alcor.netwconfigmanager.service; - -import com.futurewei.alcor.schema.Neighbor; - -import java.util.Map; -import java.util.Set; - -public interface ResourceInfo { - Map getNeighborStates (Set resourceIds) throws Exception; -} diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java index aac7b91a2..0dfe9ed38 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java @@ -34,6 +34,7 @@ free of charge, to any person obtaining a copy of this software and associated d import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; @Service @ComponentScan(value = "com.futurewei.alcor.netwconfigmanager.cache") @@ -81,12 +82,27 @@ public Map updateGoalStates(Goalstate.GoalStateV2 goalSta } } hostResourceMetadataCache.commit(); + patchNeighbors(hostGoalStates); } return hostGoalStates; } - public Map getNeighborStates(Set resourceIds) throws Exception { - return resourceStateCache.getResourceStates(resourceIds); + public void patchNeighbors(Map hostGoalStates) throws Exception { + boolean isAttache = !hostGoalStates.values().parallelStream().anyMatch(hostGoalState -> hostGoalState.getGoalState().getPortStatesCount() > 0); + for (Map.Entry hostGoalState : hostGoalStates.entrySet()) { + if (isAttache || hostGoalState.getValue().getGoalState().getPortStatesCount() > 0) { + String hostIp = hostGoalState.getValue().getHostIp(); + Goalstate.GoalStateV2 goalState = hostGoalState.getValue().getGoalState(); + Set resourceIds = goalState.getHostResourcesMap().get(hostIp).getResourcesList().stream().filter(resourceIdType -> resourceIdType.getType().equals(Common.ResourceType.NEIGHBOR)).map(resourceIdType -> resourceIdType.getId()).collect(Collectors.toSet()); + Goalstate.GoalStateV2.Builder goalstateBuilder = Goalstate.GoalStateV2.newBuilder(); + goalstateBuilder.mergeFrom(goalState); + Map neighborStateMap = resourceStateCache.getResourceStates(resourceIds); + if (neighborStateMap.size() > 0) { + goalstateBuilder.putAllNeighborStates(neighborStateMap); + } + hostGoalStates.put(hostGoalState.getKey(), new HostGoalState(hostIp, goalstateBuilder.build())); + } + } } @Override diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/ResourceInfoImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/ResourceInfoImpl.java deleted file mode 100644 index 6bb49d544..000000000 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/ResourceInfoImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.futurewei.alcor.netwconfigmanager.service.impl; - -import com.futurewei.alcor.netwconfigmanager.cache.ResourceStateCache; -import com.futurewei.alcor.netwconfigmanager.service.ResourceInfo; -import com.futurewei.alcor.schema.Neighbor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.stereotype.Service; - -import java.util.Map; -import java.util.Set; - -@Service -@ComponentScan(value = "com.futurewei.alcor.netwconfigmanager.cache") -public class ResourceInfoImpl implements ResourceInfo { - @Autowired - private ResourceStateCache resourceStateCache; - - public Map getNeighborStates (Set resourceIds) throws Exception { - return resourceStateCache.getResourceStates(resourceIds); - } -}