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 3 commits
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 @@ -80,7 +80,7 @@ public IgniteClient igniteClientInstance() {
logger.log(Level.WARNING, "Unexpected failure:" + e.getMessage());
}

Assert.notNull(igniteClient, "IgniteClient is null");
//Assert.notNull(igniteClient, "IgniteClient is null");
kimeunju108 marked this conversation as resolved.
Show resolved Hide resolved

return igniteClient;
}
Expand Down
6 changes: 0 additions & 6 deletions services/node_manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@
<version>0.1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.futurewei.alcor.controller</groupId>
<artifactId>AlcorController</artifactId>
<version>0.1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
package com.futurewei.alcor.nodemanager;

import com.futurewei.alcor.controller.app.onebox.OneBoxConfig;
import com.futurewei.alcor.controller.app.onebox.OneBoxUtil;
import com.futurewei.alcor.controller.model.HostInfo;
import com.futurewei.alcor.controller.resourcemgr.physical.nodemgmt.DataCenterConfig;
import com.futurewei.alcor.controller.resourcemgr.physical.nodemgmt.DataCenterConfigLoader;
import com.futurewei.alcor.controller.resourcemgr.physical.nodemgmt.NodeManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;
import java.util.logging.Level;

@SpringBootApplication
public class NodeManagerApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.*;

@RestController
Expand Down Expand Up @@ -52,6 +56,42 @@ public NodeInfoJson getNodeInfoByMacAddress(@PathVariable String nodeid) throws
return new NodeInfoJson(hostInfo);
}

@RequestMapping(
method = GET,
value = {"/nodes", "/v4/nodes"})
public Hashtable getAllNodes() throws Exception {
Hashtable nodes = null;
try {
nodes = service.getAllNodes();
} catch (ParameterNullOrEmptyException e) {
//TODO: REST error code
throw new Exception(e);
}
if (nodes == null) {
//TODO: REST error code
return new Hashtable();
}
return nodes;
}

@RequestMapping(
method = GET,
value = {"/nodeslist", "/v4/nodeslist"})
public List<NodeInfo> getAllNodesList() throws Exception {
List<NodeInfo> nodes = null;
try {
nodes = service.getAllNodesList();
} catch (ParameterNullOrEmptyException e) {
//TODO: REST error code
throw new Exception(e);
}
if (nodes == null) {
//TODO: REST error code
return new ArrayList();
}
return nodes;
}

@RequestMapping(
method = POST,
value = {"/nodes", "/v4/nodes"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.futurewei.alcor.nodemanager.dao.repository;
package com.futurewei.alcor.nodemanager.dao;

import com.futurewei.alcor.common.db.CacheException;
import com.futurewei.alcor.common.db.CacheFactory;
Expand Down Expand Up @@ -71,6 +71,12 @@ public void deleteItem(String id) throws CacheException {
cache.remove(id);
}

/**
* add a new node info to node repository
* @param nodeInfo new node information
* @return void
* @throws Exception Db or cache operation exception
*/
public void addItemTransaction(NodeInfo nodeInfo) throws Exception {
logger.info("Add node, Node Id:" + nodeInfo.getId());
cache.put(nodeInfo.getId(), nodeInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.futurewei.alcor.nodemanager.entity;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.futurewei.alcor.nodemanager.utils.NodeUtil;
import lombok.Data;
Expand All @@ -27,6 +28,8 @@
import java.util.regex.Pattern;

@Data
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE,
setterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE)
public class NodeInfo implements Serializable {
private static final Logger logger = LoggerFactory.getLogger(NodeInfo.class);

Expand All @@ -53,34 +56,39 @@ public NodeInfo() {
}

public NodeInfo(NodeInfo nodeInfo) {
this(nodeInfo.id, nodeInfo.name, nodeInfo.localIp, nodeInfo.macAddress, nodeInfo.gRPCServerPort);
this(nodeInfo.id, nodeInfo.name, nodeInfo.localIp, nodeInfo.macAddress, nodeInfo.veth, nodeInfo.gRPCServerPort);
}

public NodeInfo(String id, String name, InetAddress localIp, String macAddress, int gRPCServerPort) {
public NodeInfo(String id, String name, InetAddress localIp, String macAddress, String veth, int gRPCServerPort) {
this.id = id;
this.name = name;
this.localIp = localIp;
this.macAddress = macAddress;
this.veth = veth;
this.gRPCServerPort = gRPCServerPort;
}

public NodeInfo(String nodeId, String nodeName, byte[] ipAddress, String macAddress, int gRPCServerPort) {
this(nodeId, nodeName, ipAddress, macAddress);
this.veth = "";
this.gRPCServerPort = gRPCServerPort;
}

public NodeInfo(String nodeId, String nodeName, byte[] ipAddress, String macAddress) {
this.id = nodeId;
this.name = nodeName;
try {
this.localIp = InetAddress.getByAddress(nodeName, ipAddress);
this.localIp = InetAddress.getByAddress(ipAddress);
if (this.validate(macAddress)) {
this.macAddress = macAddress;
} else {
this.macAddress = null;
this.macAddress = "";
}
} catch (UnknownHostException e) {
logger.error(NodeUtil.NODE_EXCEPTION_NODE_IP_INVALID + ipAddress, e);
}
this.veth = "";
this.gRPCServerPort = NodeUtil.GRPC_SERVER_PORT;
}

private boolean validate(String mac) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

import com.futurewei.alcor.nodemanager.entity.NodeInfo;

import java.util.Hashtable;
import java.util.List;

public interface NodeService {
NodeInfo getNodeInfoById(String nodeId) throws Exception;

Hashtable getAllNodes() throws Exception;

List getAllNodesList() throws Exception;

NodeInfo createNodeInfo(NodeInfo nodeInfo) throws Exception;

NodeInfo updateNodeInfo(String nodeId, NodeInfo nodeInfo) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.futurewei.alcor.nodemanager.dao.file;
package com.futurewei.alcor.nodemanager.service.datacenter;

public class DataCenterConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
limitations under the License.
*/

package com.futurewei.alcor.nodemanager.dao.file;
package com.futurewei.alcor.nodemanager.service.datacenter;

import com.futurewei.alcor.controller.utilities.Common;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.futurewei.alcor.nodemanager.entity.NodeInfo;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
Expand All @@ -27,32 +27,37 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Component
public class DataCenterConfigLoader {
private static final Logger logger = LoggerFactory.getLogger(DataCenterConfigLoader.class);

@Autowired
private ResourceLoader resourceLoader;

@Value("${alcor.machine.config:app/config/machine.json}")
@Value("${alcor.machine.config:.\\machine.json}")
private String machineConfigFile;

String getPropertyFile() {
return resourceLoader.getResource(this.machineConfigFile).getFilename();
}
//String getPropertyFile() {
// return resourceLoader.getResource(this.machineConfigFile).getFilename();
//}

public List<NodeInfo> loadAndGetHostNodeList() {
logger.info("Loading node from " + this.machineConfigFile);
return this.loadAndGetHostNodeList(this.machineConfigFile);
}

@JsonIgnore
public List<NodeInfo> loadAndGetHostNodeList(String machineConfigFilePath) {
JSONParser jsonParser = new JSONParser();
List<NodeInfo> nodeInfos = new ArrayList<>();
Expand All @@ -75,19 +80,33 @@ public List<NodeInfo> loadAndGetHostNodeList(String machineConfigFilePath) {
return nodeInfos;
}

@JsonIgnore
private NodeInfo parseNodeObject(JSONObject node) {
String id = (String) node.get("id");
String ip = (String) node.get("ip");
String mac = (String) node.get("mac");
System.out.println("Node ID:" + id + "|IP:" + ip + "|MAC:" + mac);

byte[] ipByteArray;
try {
ipByteArray = Common.fromIpAddressStringToByteArray(ip);
ipByteArray = fromIpAddressStringToByteArray(ip);
return new NodeInfo(id, id, ipByteArray, mac);
} catch (UnknownHostException e) {
logger.error("UnknownHostException");
}
return null;
}

@JsonIgnore
public byte[] fromIpAddressStringToByteArray(String ipAddressString) throws UnknownHostException {
InetAddress ip = InetAddress.getByName(ipAddressString);
byte[] bytes = ip.getAddress();
return bytes;
}

public int getRandomNumberInRange(int min, int max) {
if (min >= max) {
throw new IllegalArgumentException("Max must be greater than min");
}
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}
}
Loading