This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d1490d
commit f45e561
Showing
10 changed files
with
276 additions
and
55 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...ices/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.futurewei.alcor.dataplane.cache; | ||
|
||
import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; | ||
import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; | ||
|
||
public interface LocalCache { | ||
void addSubnetPorts(NetworkConfiguration networkConfig) throws Exception; | ||
void updateSubnetPorts(NetworkConfiguration networkConfig) throws Exception; | ||
void deleteSubnetPorts(NetworkConfiguration networkConfig); | ||
InternalSubnetPorts getSubnetPorts(String subnetId) throws Exception; | ||
} |
116 changes: 116 additions & 0 deletions
116
.../data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/LocalCacheImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.futurewei.alcor.dataplane.cache; | ||
|
||
import com.futurewei.alcor.dataplane.exception.SubnetEntityNotFound; | ||
import com.futurewei.alcor.web.entity.dataplane.InternalPortEntity; | ||
import com.futurewei.alcor.web.entity.dataplane.InternalSubnetEntity; | ||
import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; | ||
import com.futurewei.alcor.web.entity.port.PortEntity; | ||
import com.futurewei.alcor.web.entity.port.PortHostInfo; | ||
import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; | ||
import com.futurewei.alcor.web.entity.subnet.SubnetEntity; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Repository | ||
public class LocalCacheImpl implements LocalCache { | ||
@Autowired | ||
private SubnetPortsCache subnetPortsCache; | ||
|
||
@Override | ||
public void addSubnetPorts(NetworkConfiguration networkConfig) throws Exception { | ||
List<InternalPortEntity> portEntities = networkConfig.getPortEntities(); | ||
if (portEntities == null) { | ||
return; | ||
} | ||
|
||
Map<String, InternalSubnetPorts> subnetPortsMap = new HashMap<>(); | ||
for (InternalPortEntity portEntity: portEntities) { | ||
List<PortEntity.FixedIp> fixedIps = portEntity.getFixedIps(); | ||
if (fixedIps == null) { | ||
continue; | ||
} | ||
|
||
for (PortEntity.FixedIp fixedIp: fixedIps) { | ||
String subnetId = fixedIp.getSubnetId(); | ||
|
||
PortHostInfo portHostInfo = new PortHostInfo(); | ||
portHostInfo.setPortMac(portEntity.getMacAddress()); | ||
portHostInfo.setPortIp(fixedIp.getIpAddress()); | ||
portHostInfo.setPortId(portEntity.getId()); | ||
portHostInfo.setHostIp(portEntity.getBindingHostIP()); | ||
portHostInfo.setHostId(portEntity.getBindingHostId()); | ||
|
||
InternalSubnetPorts subnetPorts = subnetPortsMap.get(subnetId); | ||
if (subnetPorts == null) { | ||
SubnetEntity subnetEntity = getSubnetEntity(networkConfig, fixedIp.getSubnetId()); | ||
subnetPorts = new InternalSubnetPorts(); | ||
subnetPorts.setSubnetId(subnetId); | ||
subnetPorts.setGatewayPortMac(subnetEntity.getGatewayMacAddress()); | ||
subnetPorts.setGatewayPortIp(subnetEntity.getGatewayIp()); | ||
|
||
//FIXME: get the gateway port id | ||
subnetPorts.setGatewayPortId(null); | ||
subnetPorts.setPorts(new ArrayList<>()); | ||
|
||
subnetPortsMap.put(subnetId, subnetPorts); | ||
} | ||
|
||
subnetPorts.getPorts().add(portHostInfo); | ||
} | ||
} | ||
|
||
for (Map.Entry<String, InternalSubnetPorts> entry: subnetPortsMap.entrySet()) { | ||
subnetPortsCache.updateSubnetPorts(entry.getValue()); | ||
} | ||
} | ||
|
||
private SubnetEntity getSubnetEntity(NetworkConfiguration networkConfig, String subnetId) throws Exception { | ||
List<InternalSubnetEntity> subnetEntities = networkConfig.getSubnets(); | ||
if (subnetEntities == null) { | ||
throw new SubnetEntityNotFound(); | ||
} | ||
|
||
for (SubnetEntity subnetEntity: subnetEntities) { | ||
if (subnetId.equals(subnetEntity.getId())) { | ||
return subnetEntity; | ||
} | ||
} | ||
|
||
throw new SubnetEntityNotFound(); | ||
} | ||
|
||
@Override | ||
public void updateSubnetPorts(NetworkConfiguration networkConfig) throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void deleteSubnetPorts(NetworkConfiguration networkConfig) { | ||
|
||
} | ||
|
||
@Override | ||
public InternalSubnetPorts getSubnetPorts(String subnetId) throws Exception { | ||
return subnetPortsCache.getSubnetPorts(subnetId); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ata_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SubnetPortsCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.futurewei.alcor.dataplane.cache; | ||
|
||
import com.futurewei.alcor.common.db.CacheException; | ||
import com.futurewei.alcor.common.db.CacheFactory; | ||
import com.futurewei.alcor.common.db.ICache; | ||
import com.futurewei.alcor.common.stats.DurationStatistics; | ||
import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Map; | ||
|
||
@Repository | ||
@ComponentScan(value="com.futurewei.alcor.common.db") | ||
public class SubnetPortsCache { | ||
private ICache<String, InternalSubnetPorts> subnetPortsCache; | ||
|
||
@Autowired | ||
public SubnetPortsCache(CacheFactory cacheFactory) { | ||
subnetPortsCache = cacheFactory.getCache(InternalSubnetPorts.class); | ||
} | ||
|
||
@DurationStatistics | ||
public InternalSubnetPorts getSubnetPorts(String subnetId) throws CacheException { | ||
return subnetPortsCache.get(subnetId); | ||
} | ||
|
||
@DurationStatistics | ||
public Map<String, InternalSubnetPorts> getAllSubnetPorts() throws CacheException { | ||
return subnetPortsCache.getAll(); | ||
} | ||
|
||
@DurationStatistics | ||
public Map<String, InternalSubnetPorts> getAllSubnetPorts(Map<String, Object[]> queryParams) throws CacheException { | ||
return subnetPortsCache.getAll(queryParams); | ||
} | ||
|
||
@DurationStatistics | ||
public synchronized void addSubnetPorts(InternalSubnetPorts internalSubnetPorts) throws Exception { | ||
subnetPortsCache.put(internalSubnetPorts.getSubnetId(), internalSubnetPorts); | ||
} | ||
|
||
@DurationStatistics | ||
public void updateSubnetPorts(InternalSubnetPorts internalSubnetPorts) throws Exception { | ||
subnetPortsCache.put(internalSubnetPorts.getSubnetId(), internalSubnetPorts); | ||
} | ||
|
||
@DurationStatistics | ||
public void deleteSubnetPorts(String subnetId) throws Exception { | ||
subnetPortsCache.remove(subnetId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.