Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

[MAC manager] Improve API consistency and impose retry limit #170

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d933b0d
[Microservices] Mac address manager
kimeunju108 Apr 6, 2020
f6316b4
[Microservices] Mac address manager - APIs create, get, delete
kimeunju108 Apr 6, 2020
e4b5604
[Microservices] Mac manager - update pom file and lib files
kimeunju108 Apr 7, 2020
336e499
[Microservies] Macmanager document update
kimeunju108 Apr 8, 2020
969841b
Revert "[Microservies] Macmanager document update"
kimeunju108 Apr 8, 2020
55d9c59
update macmanager design such as api and data structure
kimeunju108 Apr 9, 2020
677cf6e
Add design sketch for new requirements
kimeunju108 Apr 9, 2020
449d6e6
Update mac manager design doc
Apr 9, 2020
5886a77
[Microservices] Mac manager - updated unit test cases
kimeunju108 Apr 10, 2020
feb5a20
[Microservices] Mac manager - updated unit test cases
kimeunju108 Apr 10, 2020
c5dd021
Merge branch 'eunju/macmanager' of https://github.com/kimeunju108/alc…
kimeunju108 Apr 10, 2020
391ba83
Merge from featurewei/alcor master and resolve conflicts on macmanage…
Apr 10, 2020
62957d3
[Microservices] Mac manager - updated pictures and unit test cases
kimeunju108 Apr 11, 2020
935e57f
[Microservices] Mac manager - added mac range and mac address pool
kimeunju108 Apr 13, 2020
4d1f37a
Merge branch 'eunju/macmanager' of https://github.com/kimeunju108/alc…
kimeunju108 Apr 13, 2020
ca953ae
Merge branch 'master' into eunju/macmanager
Apr 14, 2020
00e766c
[Microservices] Mac manager - added macmanager service interface and …
kimeunju108 Apr 14, 2020
3f44896
Merge branch 'eunju/macmanager' of https://github.com/kimeunju108/alc…
kimeunju108 Apr 14, 2020
33466fb
[Microservices] Mac manager - add MAC range APIs and MAC allocation a…
kimeunju108 Apr 14, 2020
a86d141
Merge pull request #1 from kimeunju108/eunju/macmanager
kimeunju108 Apr 14, 2020
6f05522
[Microservices] Macmanager - combined activate/deactivate APIs to upd…
kimeunju108 Apr 15, 2020
0d23506
Fix broken maven CI workflow
Apr 15, 2020
7ca5df6
[Microservices] MAC manager - update a pom file
kimeunju108 Apr 15, 2020
2137d4c
Merge branch 'eunju/macmanager' of https://github.com/kimeunju108/alc…
kimeunju108 Apr 15, 2020
42e4ca5
[Microservices] MAC manager - added concurrent handling and comparing…
kimeunju108 Apr 17, 2020
e30c48c
[Microservices] MAC manager - added two sections: concurrent handling…
kimeunju108 Apr 17, 2020
0b852b2
[Microservices] MAC manager - updated delete API response
kimeunju108 Apr 18, 2020
3c223d9
[Microservices] MAC manager - updated activate/deactivate APIs response
kimeunju108 Apr 18, 2020
6ac310e
[Microservices] MAC manager - updated activate/deactivate APIs response
kimeunju108 Apr 18, 2020
3d3a0f4
[Microservices] MAC manager - tested APIs and matched output formaat …
kimeunju108 Apr 18, 2020
f78c95e
[Microservices] MAC manager - tested APIs and matched I/O data format…
kimeunju108 Apr 18, 2020
e44d501
[Microservices] MAC manager - tested APIs and matched I/O data format…
kimeunju108 Apr 18, 2020
d1fc282
[Microservices] MAC manager - tested and verified the design document…
kimeunju108 Apr 18, 2020
1dc52ed
[Microservices] MAC manager - tested and verified the design document…
kimeunju108 Apr 18, 2020
d0745e7
Merge branch 'eunju/macmanager', remote-tracking branch 'origin'
kimeunju108 Apr 18, 2020
44aef16
Merge remote-tracking branch 'origin' into eunju/macmanager
kimeunju108 Apr 18, 2020
325720f
Merge branch 'master' into eunju/macmanager
kimeunju108 Apr 18, 2020
d23fd98
Merge pull request #2 from kimeunju108/eunju/macmanager
kimeunju108 Apr 18, 2020
a11ec2e
[Microservices] MAC manager - resolved github conflict
kimeunju108 Apr 18, 2020
3b7355d
Merge pull request #3 from kimeunju108/eunju/macmanager
kimeunju108 Apr 18, 2020
2d0b7a9
[Microservices] MAC manager - fixed 2 pictures
kimeunju108 Apr 19, 2020
5d4f0b8
Merge pull request #4 from kimeunju108/eunju/macmanager
kimeunju108 Apr 19, 2020
a94f372
[Microservices] MAC manager - add concurrent mac creation function
kimeunju108 Apr 20, 2020
b81ade7
[Microservices] MAC manager - reviewed and corrected the design document
kimeunju108 Apr 20, 2020
59f8837
Merge pull request #5 from kimeunju108/eunju/macmanager
kimeunju108 Apr 20, 2020
a2c0c5b
[Microservices] MAC manager - synchronized redis transaction methods
kimeunju108 Apr 22, 2020
6471dbc
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kimeunju108 Apr 22, 2020
9a3217a
Merge pull request #6 from kimeunju108/eunju/macmanager
kimeunju108 Apr 22, 2020
3addc2e
Merge branch 'master' of https://github.com/futurewei-cloud/alcor
kimeunju108 Apr 22, 2020
485ff9e
Merge pull request #7 from kimeunju108/eunju/macmanager
kimeunju108 Apr 22, 2020
d647d13
[Microservices] Node manager - add controller, service, dao, entity, …
kimeunju108 Apr 27, 2020
2200f24
Merge branch 'master' of https://github.com/futurewei-cloud/alcor
kimeunju108 Apr 27, 2020
27f8d72
Merge branch 'master' into eunju/nodemanager
kimeunju108 Apr 27, 2020
a88e4fa
Merge pull request #8 from kimeunju108/eunju/nodemanager
kimeunju108 Apr 27, 2020
ec24cf4
Microservices] Node Manager - implemented UT and tested APIs.
kimeunju108 Apr 28, 2020
60334f2
Merge branch 'eunju/nodemanager' of https://github.com/kimeunju108/al…
kimeunju108 Apr 28, 2020
7aef537
Merge pull request #9 from kimeunju108/eunju/nodemanager
kimeunju108 Apr 28, 2020
4fbcbaf
[Microservices Node Manager - Add exception handlings
kimeunju108 Apr 29, 2020
a07e2fd
Merge pull request #10 from kimeunju108/eunju/nodemanager
kimeunju108 Apr 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public Map findAllItems() {
public void addItem(String newItem) {
Logger logger = LoggerFactory.getLogger();
logger.log(Level.INFO, newItem);
setOperations.add(KEY, newItem);
if (setOperations.isMember(KEY, newItem) == false)
setOperations.add(KEY, newItem);
}

@Override
Expand All @@ -71,7 +72,10 @@ public void deleteItem(String value) {
}

public String getItem() {

return (String) setOperations.randomMember(KEY);
}

public long getSize() {
return setOperations.size(KEY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Map<String, MacRange> findAllItems() {
public void addItem(MacRange newItem) {
Logger logger = LoggerFactory.getLogger();
logger.log(Level.INFO, "mac address:" + newItem.getRangeId());
hashOperations.put(KEY, newItem.getRangeId(), newItem);
hashOperations.putIfAbsent(KEY, newItem.getRangeId(), newItem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Map findAllItems() {
public void addItem(MacState newItem) {
Logger logger = LoggerFactory.getLogger();
logger.log(Level.INFO, "mac address:" + newItem.getMacAddress());
hashOperations.put(KEY, newItem.getMacAddress(), newItem);
hashOperations.putIfAbsent(KEY, newItem.getMacAddress(), newItem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;

@Service
public class MacRedisServiceImpl implements MacService {
static public Hashtable<String, MacRange> activeMacRanges = new Hashtable<String, MacRange>();
final String DELIMITER = "/";

@Autowired
Expand All @@ -50,7 +52,8 @@ public class MacRedisServiceImpl implements MacService {
@Value("${macmanager.oui}")
private String oui;

private HashMap<String, MacRange> macRanges = new HashMap<String, MacRange>();
@Value("${macmanager.pool.size}")
private long nMacPoolSize;

public MacState getMacStateByMacAddress(String macAddress) {
MacState macState = macRedisRepository.findItem(macAddress);
Expand All @@ -61,7 +64,48 @@ public MacState createMacState(MacState macState) throws Exception {
MacAddress macAddress = new MacAddress();
if (macState.getState() == null)
macState.setState(MacUtil.MAC_STATE_ACTIVE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that MAC_STATE_ACTIVE is a constant, we should collect them and store in some constant file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Currently, all constants are in MacUtil class. But once we decide a location, I will put them there.

else if (macState.getState().trim().length()==0)
else if (macState.getState().trim().length() == 0)
macState.setState(MacUtil.MAC_STATE_ACTIVE);
if (macPoolRedisRepository.getSize() < (nMacPoolSize - 10)) {
CompletableFuture<Long> completableFuture = CompletableFuture.supplyAsync(() -> {
long n = 0;
try {
n = generateMacInPool(20);
} catch (Exception e) {
e.printStackTrace();
}
return n;
});
long l = completableFuture.get();
completableFuture.thenAccept(System.out::println);
System.out.println(("# of new MAC: " + l));
xieus marked this conversation as resolved.
Show resolved Hide resolved
completableFuture.join();
}

String strMacAddress = allocateMacState(macState);
kimeunju108 marked this conversation as resolved.
Show resolved Hide resolved
if (strMacAddress != null) {
macState.setMacAddress(strMacAddress);
macRedisRepository.addItem(macState);
} else {
String nic = generateNic();
macAddress.setOui(oui);
macAddress.setNic(nic);
macState.setMacAddress(macAddress.getMacAddress());
MacState macState2 = macRedisRepository.findItem(macAddress.getMacAddress());
if (macRedisRepository.findItem(macAddress.getMacAddress()) != null)
throw (new UniquenessViolationException("This mac address is not unique!!" + macAddress.getMacAddress() + macState2.getProjectId()));
else
macRedisRepository.addItem(macState);
}

return macState;
}

public MacState createMacState1(MacState macState) throws Exception {
MacAddress macAddress = new MacAddress();
if (macState.getState() == null)
macState.setState(MacUtil.MAC_STATE_ACTIVE);
else if (macState.getState().trim().length() == 0)
macState.setState(MacUtil.MAC_STATE_ACTIVE);
String strMacAddress = allocateMacState(macState);
if (strMacAddress != null) {
Expand All @@ -74,7 +118,7 @@ else if (macState.getState().trim().length()==0)
macState.setMacAddress(macAddress.getMacAddress());
MacState macState2 = macRedisRepository.findItem(macAddress.getMacAddress());
if (macRedisRepository.findItem(macAddress.getMacAddress()) != null)
throw (new UniquenessViolationException("This mac address is not unique!!"+macAddress.getMacAddress()+macState2.getProjectId()));
throw (new UniquenessViolationException("This mac address is not unique!!" + macAddress.getMacAddress() + macState2.getProjectId()));
else
macRedisRepository.addItem(macState);
}
Expand All @@ -83,7 +127,7 @@ else if (macState.getState().trim().length()==0)

@Override
public MacState updateMacState(String macAddress, MacState macState) throws Exception {
if(macState != null)
if (macState != null)
macRedisRepository.updateItem(macState);
return macState;
}
Expand All @@ -94,11 +138,10 @@ public String releaseMacState(String macAddress) throws Exception {
ResourceNotFoundException e = new ResourceNotFoundException("MAC address Not Found");
throw e;
} else {
macPoolRedisRepository.addItem(macAddress);
macRedisRepository.deleteItem(macAddress);
macPoolRedisRepository.addItem(macAddress);
}
return macState.getMacAddress();
//return new String ("{mac_address: " + macAddress+"}");
}

@Override
Expand All @@ -117,6 +160,8 @@ public Map<String, MacRange> getAllMacRanges() {
public MacRange createMacRange(MacRange macRange) throws Exception {
if (macRange != null) {
macRangeRedisRepository.addItem(macRange);
if (macRange.getState().equals(MacUtil.MAC_RANGE_STATE_ACTIVE))
activeMacRanges.put(macRange.getRangeId(), macRange);
}
return macRange;
}
Expand All @@ -125,6 +170,10 @@ public MacRange createMacRange(MacRange macRange) throws Exception {
public MacRange updateMacRange(MacRange macRange) throws Exception {
if (macRange != null) {
macRangeRedisRepository.updateItem(macRange);
if (macRange.getState().equals(MacUtil.MAC_RANGE_STATE_INACTIVE) && activeMacRanges.containsKey(macRange.getRangeId()))
activeMacRanges.remove(macRange.getRangeId(), macRange);
else if (macRange.getState().equals(MacUtil.MAC_RANGE_STATE_ACTIVE) && activeMacRanges.containsKey(macRange.getRangeId()) == false)
activeMacRanges.put(macRange.getRangeId(), macRange);
}
return macRange;
}
Expand All @@ -133,9 +182,9 @@ public MacRange updateMacRange(MacRange macRange) throws Exception {
public String deleteMacRange(String rangeId) throws Exception {
if (rangeId != null) {
macRangeRedisRepository.deleteItem(rangeId);
activeMacRanges.remove(rangeId);
}
return rangeId;
//return new String ("{mac_range: " + rangeId+"}");
}

private String allocateMacState(MacState macState) {
Expand Down Expand Up @@ -172,28 +221,48 @@ private String generateNic() {

private MacRange getMacRange() {
MacRange macRange = new MacRange();
Vector<MacRange> activeMacRanges = getActiveMacRanges();
if (activeMacRanges.isEmpty())
getActiveMacRanges();
int randomIndex = ThreadLocalRandom.current().nextInt(0, activeMacRanges.size());
return activeMacRanges.get(randomIndex);
Vector<String> vector = new Vector<String>(activeMacRanges.keySet());
return activeMacRanges.get(vector.elementAt(randomIndex));
}

public Vector<MacRange> getActiveMacRanges() {
Vector<MacRange> activeMacRanges = new Vector<MacRange>();

macRanges = (HashMap<String, MacRange>) macRangeRedisRepository.findAllItems();
public void getActiveMacRanges() {
Hashtable<String, MacRange> macRanges = new Hashtable(macRangeRedisRepository.findAllItems());
if (macRanges == null)
macRanges = new Hashtable<String, MacRange>();
int nSize = macRanges.size();
if (nSize > 0) {
for (Map.Entry<String, MacRange> entry : macRanges.entrySet()) {
if (entry.getValue().getState().equals("Active")) {
activeMacRanges.add(entry.getValue());
if (entry.getValue().getState().equals(MacUtil.MAC_RANGE_STATE_ACTIVE)) {
activeMacRanges.put(entry.getKey(), entry.getValue());
}
}
} else if (macRanges != null) {
MacRange newRange = new MacRange();
newRange.createDefault(oui);
macRangeRedisRepository.addItem(newRange);
activeMacRanges.add(newRange);
activeMacRanges.put(newRange.getRangeId(), newRange);
}
}

public long generateMacInPool(int n) throws Exception {
long nReturn = 0;
ArrayList<String> list = new ArrayList<String>();
if (n < 1) return nReturn;
MacAddress macAddress = new MacAddress();
for (int i = 0; i < n; i++) {
String nic = generateNic();
macAddress.setOui(oui);
macAddress.setNic(nic);
String strMacAddress = macAddress.getMacAddress();
MacState macState = macRedisRepository.findItem(strMacAddress);
if (macState == null) {
macPoolRedisRepository.addItem(strMacAddress);
nReturn++;
}
}
return activeMacRanges;
return nReturn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ logging.type=file
#ignite.key-store-password=123456
#ignite.trust-store-path=F:\\work\\alcor\\git\\chenpp\\alcor\\src\\resources\\truststore.jks
#ignite.trust-store-password=123456
macmanager.oui = 00-AA-BB
macmanager.oui = 00-AA-BB
macmanager.pool.size = 100