aboutsummaryrefslogtreecommitdiffstats
path: root/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services
diff options
context:
space:
mode:
Diffstat (limited to 'ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services')
-rw-r--r--ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimControllerServices.java122
-rw-r--r--ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimRepositoryService.java53
2 files changed, 175 insertions, 0 deletions
diff --git a/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimControllerServices.java b/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimControllerServices.java
index 94ac9c8..027c97e 100644
--- a/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimControllerServices.java
+++ b/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimControllerServices.java
@@ -104,6 +104,11 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+
@Service
public class RansimControllerServices {
@@ -1806,6 +1811,123 @@ public class RansimControllerServices {
}
}
+ public synchronized void addWebSocketSessionsForRanApp(String ipPort, Session session) {
+ // TODO Auto-generated method stub
+ if (webSocketSessions.containsKey(ipPort)) {
+ log.info("addWebSocketSessions: Client session " + session.getId() + " for " + ipPort
+ + " already exist. Removing old session.");
+ webSocketSessions.remove(ipPort);
+ }
+
+ log.info("addWebSocketSessions: Adding Client session " + session.getId() + " for " + ipPort);
+ webSocketSessions.put(ipPort, session);
+ }
+
+
+
+ public ResponsetoRanapp sendPayloadtoHC(String message,String ipPort, Session session) {
+ // TODO Auto-generated method stub
+ addWebSocketSessionsForRanApp(ipPort, session);
+ ResponsetoRanapp response=new ResponsetoRanapp();
+ try {
+
+ PayloadOutput neighbourListinUse=new ObjectMapper().readValue(message, PayloadOutput.class);
+ log.info("neighbourListinUse payload: "+ neighbourListinUse);
+ NetconfServers server=findserverIdfromPayload(neighbourListinUse);
+ if( server != null) {
+ NetconfClient netconfClient = new NetconfClient("ransim", "admin", "admin", server.getServerId(),
+ server.getIp(), Integer.parseInt(server.getNetconfPort()));
+ log.info("Initializing Netconf client session for "+ server.getIp() +":"+server.getNetconfPort());
+ Integer nearrtric=nearrtricfindNearrtricIdfromserverId(server.getServerId());
+ netconfClient.editConfig(
+ netconfClient.updateNeighbourListCUCP(neighbourListinUse, nearrtric.toString()));
+ response.setResponse_code(200);
+ response.setError_info("Neighbour Cell Relation changed Successfully");
+ return response;
+ }else {
+ log.info("HC device not found for the respective config change");
+ response.setResponse_code(400);
+ response.setError_info("HC device not found");
+ return response;
+ }
+ } catch (JsonParseException e) {
+ // TODO Auto-generated catch block
+ e.getLocalizedMessage();
+ e.printStackTrace();
+ response.setResponse_code(500);
+ if(e.getMessage() == null) {
+ response.setError_info("Causing JsonParse Exception");
+ }else
+ response.setError_info(e.getMessage());
+ return response;
+ } catch (JsonMappingException e) {
+ // TODO Auto-generated catch block
+ e.getLocalizedMessage();
+ e.printStackTrace();
+ response.setResponse_code(500);
+ if(e.getMessage() == null) {
+ response.setError_info("Causing JsonMapping Exception");
+ }else
+ response.setError_info(e.getMessage());
+ return response;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.getLocalizedMessage();
+ e.printStackTrace();
+ response.setResponse_code(500);
+ if(e.getMessage() == null) {
+ response.setError_info("Exception Occured while connecting Netconf server");
+ }else
+ response.setError_info(e.getMessage());
+ return response;
+ }
+
+ }
+
+ private Integer nearrtricfindNearrtricIdfromserverId(String serverId) {
+ // TODO Auto-generated method stub
+ Integer gnbcucpmodel = null,gnbcuupmodel = null,gnbdumodel = null;
+ gnbcucpmodel=ransimRepo.getNeartricfromCUCPmodel(serverId);
+ if(gnbcucpmodel == null) {
+ gnbcuupmodel=ransimRepo.getNeartricfromCUUPmodel(serverId);
+ if(gnbcuupmodel == null) {
+ gnbdumodel=ransimRepo.getNeartricfromDUmodel(serverId);
+ if(gnbdumodel == null) {
+ return null;
+ }else
+ return gnbdumodel;
+ }else
+ return gnbcuupmodel;
+ }else
+ return gnbcucpmodel;
+
+
+ }
+
+ private NetconfServers findserverIdfromPayload(PayloadOutput readValue) {
+ // TODO Auto-generated method stub
+ String serverId=readValue.getConfigurations().get(0).getData().getFAPService().getIdNRCellCU();
+ if(serverIdIpPortMapping.keySet().contains(serverId)) {
+ try {
+ log.info("Retrieve Netconf server from database using serverId: "+serverId);
+ NetconfServers server = ransimRepo.getNetconfServer(serverId);
+ if (server != null) {
+ log.info("Retrieved Netconf server"+ server +"from database using serverId: "+serverId);
+ return server;
+ }else {
+ log.info("No Netconf server found for serverId"+ serverId);
+ return null;
+ }
+ } catch (Exception e1) {
+ log.error("Exception mapServerIdToNodes :", e1);
+ }
+ }
+ log.info("serverIdIpPortMapping does not contain serverId"+ serverId + "in it");
+
+ return null;
+ }
+
+
}
diff --git a/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimRepositoryService.java b/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimRepositoryService.java
index 8a6713b..6c607ea 100644
--- a/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimRepositoryService.java
+++ b/ransim/ransimctrlr/RANSIM-CTRLR/src/main/java/org/onap/ransim/rest/api/services/RansimRepositoryService.java
@@ -33,8 +33,14 @@ import org.onap.ransim.rest.api.models.NRCellCU;
import org.onap.ransim.rest.api.models.NRCellDU;
import org.onap.ransim.rest.api.models.NRCellRelation;
import org.onap.ransim.rest.api.models.OperationLog;
+import org.onap.ransim.rest.api.models.GNBCUCPFunction;
+import org.onap.ransim.rest.api.models.GNBCUUPFunction;
+import org.onap.ransim.rest.api.models.GNBDUFunction;
import org.onap.ransim.rest.api.repository.CellDetailsRepo;
import org.onap.ransim.rest.api.repository.CellNeighborRepo;
+import org.onap.ransim.rest.api.repository.GNBCUCPRepository;
+import org.onap.ransim.rest.api.repository.GNBCUUPRepository;
+import org.onap.ransim.rest.api.repository.GNBDURepository;
import org.onap.ransim.rest.api.repository.NRCellCURepository;
import org.onap.ransim.rest.api.repository.NRCellDURepository;
import org.onap.ransim.rest.api.repository.NRCellRelationRepository;
@@ -72,6 +78,15 @@ public class RansimRepositoryService {
@Autowired
OperationLogRepo operationLogRepo;
+
+ @Autowired
+ GNBCUCPRepository gnbcucpfuncRepo;
+
+ @Autowired
+ GNBCUUPRepository gnbcuupfuncRepo;
+
+ @Autowired
+ GNBDURepository gnbdufuncRepo;
/**
* Method to retrieve cell details
@@ -383,4 +398,42 @@ public class RansimRepositoryService {
public void mergeOperationLog(OperationLog opLog) {
operationLogRepo.save(opLog);
}
+
+ public Integer getNeartricfromCUCPmodel(String serverId) {
+ // TODO Auto-generated method stub
+ Optional<GNBCUCPFunction> cucp = gnbcucpfuncRepo.findById(serverId);
+ GNBCUCPFunction cucpdetails = null;
+ if (cucp.isPresent()) {
+ cucpdetails = cucp.get();
+ return cucpdetails.getNearRTRIC().getNearRTRICId();
+ }else
+ return null;
+
+ }
+
+ public Integer getNeartricfromCUUPmodel(String serverId) {
+ // TODO Auto-generated method stub
+ Optional<GNBCUUPFunction> cuup = gnbcuupfuncRepo.findById(Integer.getInteger(serverId));
+ GNBCUUPFunction cuupdetails = null;
+ if (cuup.isPresent()) {
+ cuupdetails = cuup.get();
+ return cuupdetails.getNearRTRIC().getNearRTRICId();
+ }else
+ return null;
+ }
+
+ public Integer getNeartricfromDUmodel(String serverId) {
+ // TODO Auto-generated method stub
+
+
+ Optional<GNBDUFunction> du = gnbdufuncRepo.findById(Integer.getInteger(serverId));
+ GNBDUFunction dudetails = null;
+ if (du.isPresent()) {
+ dudetails = du.get();
+ return dudetails.getNearRTRIC().getNearRTRICId();
+ }else
+ return null;
+ }
+
+
}