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

Commit

Permalink
[Node Mgr] Add Interface for NCM Registration. (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkommoju authored Apr 14, 2021
1 parent d120be0 commit 5bd9709
Show file tree
Hide file tree
Showing 18 changed files with 403 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheC
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ free of charge, to any person obtaining a copy of this software and associated d

package com.futurewei.alcor.dataplane.service;

import com.futurewei.alcor.web.entity.node.BulkNodeInfoJson;
import com.futurewei.alcor.web.entity.node.NodeInfo;
import com.futurewei.alcor.web.entity.node.NodeInfoJson;
import com.futurewei.alcor.web.entity.node.*;

import java.util.List;

Expand All @@ -31,4 +29,4 @@ public interface NodeService {
void deleteNodeInfo(NodeInfoJson nodeInfoJson) throws Exception;

void createNodeInfoBulk(BulkNodeInfoJson bulkNodeInfoJson) throws Exception;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ free of charge, to any person obtaining a copy of this software and associated d
*/
package com.futurewei.alcor.netwconfigmanager.service;

import com.futurewei.alcor.web.entity.node.BulkNodeInfoJson;
import com.futurewei.alcor.web.entity.node.NodeInfo;
import com.futurewei.alcor.web.entity.node.NodeInfoJson;
import com.futurewei.alcor.web.entity.node.*;

import java.util.List;

Expand All @@ -32,4 +30,4 @@ public interface NodeService {
void createNodeInfoBulk(BulkNodeInfoJson bulkNodeInfoJson) throws Exception;

NodeInfo getNodeInfo(String nodeId) throws Exception;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ free of charge, to any person obtaining a copy of this software and associated d
import com.futurewei.alcor.common.logging.LoggerFactory;
import com.futurewei.alcor.netwconfigmanager.cache.NodeInfoCache;
import com.futurewei.alcor.netwconfigmanager.service.NodeService;
import com.futurewei.alcor.web.entity.node.BulkNodeInfoJson;
import com.futurewei.alcor.web.entity.node.NodeInfo;
import com.futurewei.alcor.web.entity.node.NodeInfoJson;
import com.futurewei.alcor.web.entity.node.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -64,4 +62,4 @@ public void createNodeInfoBulk(BulkNodeInfoJson bulkNodeInfoJson) throws Excepti
public NodeInfo getNodeInfo(String nodeId) throws Exception {
return nodeInfoCache.getNodeInfo(nodeId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ free of charge, to any person obtaining a copy of this software and associated d
import com.futurewei.alcor.nodemanager.exception.InvalidDataException;
import com.futurewei.alcor.nodemanager.service.NodeService;
import com.futurewei.alcor.nodemanager.utils.NodeManagerConstant;
import com.futurewei.alcor.web.entity.node.NodeInfo;
import com.futurewei.alcor.web.entity.node.NodeInfoJson;
import com.futurewei.alcor.web.entity.node.BulkNodeInfoJson;
import com.futurewei.alcor.web.entity.node.NodesWebJson;
import com.futurewei.alcor.web.entity.node.*;
import com.futurewei.alcor.web.json.annotation.FieldFilter;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -114,7 +111,8 @@ public NodeInfoJson getNodeInfoById(@PathVariable String nodeid) throws Exceptio
public NodesWebJson getAllNodes(@ApiParam(value = "node_name") @RequestParam(required = false) String name,
@ApiParam(value = "node_id") @RequestParam(required = false) String id,
@ApiParam(value = "mac_address") @RequestParam(required = false) String mac_address,
@ApiParam(value = "local_Ip") @RequestParam(required = false) String local_ip) throws ParameterNullOrEmptyException, Exception {
@ApiParam(value = "local_Ip") @RequestParam(required = false) String local_ip,
@ApiParam(value = "ncm_id") @RequestParam(required = false) String ncm_id) throws ParameterNullOrEmptyException, Exception {
List<NodeInfo> nodes = null;
try {
Map<String, Object[]> queryParams =
Expand All @@ -132,6 +130,9 @@ public NodesWebJson getAllNodes(@ApiParam(value = "node_name") @RequestParam(req
queryParams.put("localIp", new String[]{local_ip});
}

if (ncm_id != null)
queryParams.put("ncmId", new String[]{ncm_id});

nodes = service.getAllNodes(queryParams);
} catch (ParameterNullOrEmptyException e) {
throw e;
Expand Down Expand Up @@ -209,4 +210,101 @@ public String deleteNodeInfo(@PathVariable String nodeid) throws Exception {
}
return "{Node(Node) Id: " + nodeid + "}";
}
}

/**
* /ncms end-points: NCM metadata management methods
*/

@RequestMapping(
method = GET,
value = {"/ncms/{ncmId}", "/v4/ncms/{ncmId}"})
@DurationStatistics
public NcmInfoJson getNcmMetaData(@PathVariable String ncmId) throws Exception {
NcmInfo ncmInfo = null;
try {
RestPreconditionsUtil.verifyParameterNotNullorEmpty(ncmId);
ncmInfo = service.getNcmMetaData(ncmId);
} catch (ParameterNullOrEmptyException e) {
throw new Exception(e);
}
if (ncmInfo == null) {
return new NcmInfoJson();
}

return new NcmInfoJson(ncmInfo);
}

@RequestMapping(
method = GET,
value = {"/ncms", "/v4/ncms"})
@DurationStatistics
public NcmsWebJson getAllNcmMetaData() throws Exception {
List<NcmInfo> ncmInfos = null;
try {
ncmInfos = service.getAllNcmMetaData();
} catch (ParameterNullOrEmptyException e) {
throw new Exception(e);
}
if (ncmInfos == null) {
return new NcmsWebJson();
}

return new NcmsWebJson(ncmInfos);
}


/**
*
* @param resource
* @return
* @throws Exception
*/
@RequestMapping(
method = POST,
value = {"/ncms", "/v4/ncms"})
public void registerNcmMetaData(@RequestBody NcmInfoJson resource) throws Exception {
if (resource == null) {
throw new ParameterNullOrEmptyException(NodeManagerConstant.NODE_EXCEPTION_JSON_EMPTY);
}
try {
service.registerNcmMetaData(resource.getNcmInfo());
} catch (Exception e) {
LOG.log(Level.SEVERE,e.getMessage());
throw e;
}
}

@RequestMapping(
method = DELETE,
value = {"/ncms/{ncmId}", "/v4/ncms/{ncmId}"})
@DurationStatistics
public void unRegisterNcmMetaData(@PathVariable String ncmId) throws Exception {
try {
RestPreconditionsUtil.verifyParameterNotNullorEmpty(ncmId);
service.unRegisterNcmMetaData(ncmId);
} catch (ParameterNullOrEmptyException e) {
throw e;
}
}

@RequestMapping(
method = PUT,
value = {"/ncms/{ncmId}", "/v4/ncms/{ncmId}"})
@DurationStatistics
public void updateNcmMetaData(@PathVariable String ncmId, @RequestBody NcmInfoJson resource) throws Exception {
NcmInfo ncmInfo = null;
try {
NcmInfo inNcmInfo = resource.getNcmInfo();
RestPreconditionsUtil.verifyParameterNotNullorEmpty(inNcmInfo);
RestPreconditionsUtil.verifyParameterValid(ncmId, inNcmInfo.getId());
service.updateNcmMetaData(ncmId, inNcmInfo);
} catch (ParameterNullOrEmptyException e) {
throw e;
} catch (ParameterUnexpectedValueException e){
throw e;
}
catch (Exception e) {
throw new Exception(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public Map findAllNcmInfo() throws CacheException {
return cache.getAll();
}

/**
* find information about all NCM.
* @return list of NcmInfo
* @throws Exception;
*/
public NcmInfo getNcmInfoById(String ncmId) throws Exception {
return cache.get(ncmId);
}

/**
* add a new Ncm info to repository
*
Expand Down Expand Up @@ -107,40 +116,22 @@ public void addNcmInfo(NcmInfo ncmInfo) throws CacheException {
}

/**
* Append a new nodes to an NCM.
* add a new Ncm info to repository
*
* @param ncmInfo new Ncm information
* @throws CacheException or DbException
*/
public void appendNodes(String ncmId, List<String> nodeIds) throws CacheException {
logger.info("Append an nodes to NCM entry, NCM Id:" + ncmId);

try (Transaction tx = cache.getTransaction().start()) {
NcmInfo ncmInfo = cache.get(ncmId);
ncmInfo.appendNodes(nodeIds);
cache.put(ncmId, ncmInfo);
tx.commit();
} catch (CacheException e) {
throw e;
} catch (Exception e) {
logger.error("Add an NcmInfo entry error: "+e.getMessage());
}
}
public void updateNcmInfo(NcmInfo ncmInfo) throws CacheException {
String ncmId = ncmInfo.getId();
logger.info("Update an NcmInfo entry, NCM Id:" + ncmId);

/**
* @param ncmId
* @param nodeIds
* @throws CacheException or DbException
*/
public void removeNodes(String ncmId, List<String> nodeIds) throws CacheException {
logger.info("Remove nodes from NCM, NCM Id:" + ncmId);
try (Transaction tx = cache.getTransaction().start()) {
NcmInfo ncmInfo = cache.get(ncmId);
ncmInfo.removeNodes(nodeIds);
cache.put(ncmId, ncmInfo);
tx.commit();
} catch (CacheException e) {
throw e;
} catch (Exception e) {
logger.error("Add an NcmInfo entry error: "+e.getMessage());
logger.error("Update an ncmInfo entry error: "+e.getMessage());
}
}

Expand All @@ -161,4 +152,4 @@ public void deleteNcmInfo(String id) throws CacheException{
logger.error("delete an NcmInfo error: "+e.getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ free of charge, to any person obtaining a copy of this software and associated d
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractProcessor implements IProcessor{
public abstract class AbstractProcessor implements IProcessor {
private static final Logger LOG = LoggerFactory.getLogger(AbstractProcessor.class);

private IProcessor nextProcessor;
Expand Down Expand Up @@ -79,4 +79,4 @@ public void deleteNode(NodeContext context) throws Exception {
getNextProcessor().deleteNode(context);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public interface IProcessor {
void updateNode(NodeContext context) throws Exception;
void deleteNode(NodeContext context) throws Exception;
void setNextProcessor(IProcessor nextProcessor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ void bulkCreateProcess(NodeContext context) throws Exception {
IRestRequest bulkCreateNodeInfoRequest = new BulkCreateNodeInfoRequest(context, context.getNodeInfos());
context.getRequestManager().sendRequestAsync(bulkCreateNodeInfoRequest);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ free of charge, to any person obtaining a copy of this software and associated d

import com.futurewei.alcor.common.exception.ParameterNullOrEmptyException;
import com.futurewei.alcor.nodemanager.exception.InvalidDataException;
import com.futurewei.alcor.web.entity.node.NcmInfo;
import com.futurewei.alcor.web.entity.node.NcmInfoJson;
import com.futurewei.alcor.web.entity.node.NodeInfo;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -41,8 +43,18 @@ public interface NodeService {
NodeInfo updateNodeInfo(String nodeId, NodeInfo nodeInfo) throws ParameterNullOrEmptyException, InvalidDataException, Exception;

String deleteNodeInfo(String nodeId) throws ParameterNullOrEmptyException, Exception;

// TEMP: URI will be provided by the Admin but these are for testing purpose.
static String makeUpNcmId(String hostIP, int localPort) { return "ncm_" + hostIP + "_" + String.valueOf(localPort); }
static String makeUpNcmUri(String hostIP, int localPort) { return "ncm/" + hostIP + "/" + String.valueOf(localPort); }
}

/**
*
* NMM interface to manage NCM Metadata in NMM.
*/
void registerNcmMetaData(NcmInfo ncmInfo) throws Exception;

void unRegisterNcmMetaData(String ncmId) throws Exception;

NcmInfo getNcmMetaData(String ncmId) throws Exception;

List<NcmInfo> getAllNcmMetaData() throws Exception;

void updateNcmMetaData(String ncmId, NcmInfo ncmInfo) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ private NodeInfo parseNodeObject(JSONObject nodeJson) throws InvalidDataExceptio
throw new InvalidDataException(NodeManagerConstant.NODE_EXCEPTION_IP_FORMAT_INVALID);
}
String ncm_id = (String)nodeJson.get(NodeManagerConstant.JSON_NCM_ID);
if (ncm_id == null)
ncm_id = NodeService.makeUpNcmId(ip, NodeManagerConstant.GRPC_SERVER_PORT);
node.setNcmId(ncm_id);
} catch (Exception e) {
logger.error(strMethodName+e.getMessage());
throw e;
}
return node;
}
}
}
Loading

0 comments on commit 5bd9709

Please sign in to comment.