diff options
Diffstat (limited to 'src/main/java/org')
67 files changed, 3357 insertions, 951 deletions
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/AlarmAdditionalInformation.java b/src/main/java/org/onap/dcaegen2/services/sonhms/AlarmAdditionalInformation.java new file mode 100644 index 0000000..63cc745 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/AlarmAdditionalInformation.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * pcims + * ================================================================================ + * Copyright (C) 2018 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + ******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +public class AlarmAdditionalInformation { + + private String networkId; + private int collisions; + private int confusions; + public String getNetworkId() { + return networkId; + } + public void setNetworkId(String networkId) { + this.networkId = networkId; + } + public int getCollisions() { + return collisions; + } + public void setCollisions(int collisions) { + this.collisions = collisions; + } + public int getConfusions() { + return confusions; + } + public void setConfusions(int confusions) { + this.confusions = confusions; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java index 22d58d9..22f458a 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Application.java @@ -31,24 +31,23 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; -@SpringBootApplication +@SpringBootApplication public class Application { - private static Logger log = LoggerFactory.getLogger(Application.class); /** * Main method where the pci context is initially set. */ public static void main(String[] args) { - + ConfigFetchFromCbs configFetchFromCbs = new ConfigFetchFromCbs(); configFetchFromCbs.getAppConfig(); try { - Thread.sleep(10000); - } catch (InterruptedException e) { - log.debug("InterruptedException : {}",e); - } + Thread.sleep(10000); + } catch (InterruptedException e) { + log.debug("InterruptedException : {}", e); + } log.info("after 10s sleep"); log.info("Starting spring boot application"); SpringApplication.run(Application.class); @@ -61,15 +60,11 @@ public class Application { @Bean public DataSource dataSource() { Configuration configuration = Configuration.getInstance(); - + String url = "jdbc:postgresql://" + configuration.getPgHost() + ":" + configuration.getPgPort() + "/sonhms"; - - return DataSourceBuilder - .create() - .url(url) - .username(configuration.getPgUsername()) - .password(configuration.getPgPassword()) - .build(); + + return DataSourceBuilder.create().url(url).username(configuration.getPgUsername()) + .password(configuration.getPgPassword()).build(); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponent.java index d1297b4..ce2b4bc 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponent.java @@ -40,7 +40,7 @@ public class BufferNotificationComponent { .getBean(BufferedNotificationsRepository.class); bufferedNotificationsRepository.save(bufferedNotifications); - } + } /** * Retrieves buffered notification from the database. diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/CommonEventHeader.java b/src/main/java/org/onap/dcaegen2/services/sonhms/CommonEventHeader.java new file mode 100644 index 0000000..013dc66 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/CommonEventHeader.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +public class CommonEventHeader { + + private String version; + private String vesEventListenerVersion; + private String domain; + private String eventName; + private String eventId; + private int sequence; + private String priority; + private String reportingEntityId; + private String reportingEntityName; + private String sourceId; + private String sourceName; + private long startEpochMicrosec; + private long lastEpochMicrosec; + private String timeZoneOffset; + private String nfNamingCode; + private String nfVendorName; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getVesEventListenerVersion() { + return vesEventListenerVersion; + } + + public void setVesEventListenerVersion(String vesEventListenerVersion) { + this.vesEventListenerVersion = vesEventListenerVersion; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public String getEventName() { + return eventName; + } + + public void setEventName(String eventName) { + this.eventName = eventName; + } + + public String getEventId() { + return eventId; + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public int getSequence() { + return sequence; + } + + public void setSequence(int sequence) { + this.sequence = sequence; + } + + public String getPriority() { + return priority; + } + + public void setPriority(String priority) { + this.priority = priority; + } + + public String getReportingEntityId() { + return reportingEntityId; + } + + public void setReportingEntityId(String reportingEntityId) { + this.reportingEntityId = reportingEntityId; + } + + public String getReportingEntityName() { + return reportingEntityName; + } + + public void setReportingEntityName(String reportingEntityName) { + this.reportingEntityName = reportingEntityName; + } + + public String getSourceId() { + return sourceId; + } + + public void setSourceId(String sourceId) { + this.sourceId = sourceId; + } + + public String getSourceName() { + return sourceName; + } + + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + + public long getStartEpochMicrosec() { + return startEpochMicrosec; + } + + public void setStartEpochMicrosec(long startEpochMicrosec) { + this.startEpochMicrosec = startEpochMicrosec; + } + + public long getLastEpochMicrosec() { + return lastEpochMicrosec; + } + + public void setLastEpochMicrosec(long lastEpochMicrosec) { + this.lastEpochMicrosec = lastEpochMicrosec; + } + + public String getTimeZoneOffset() { + return timeZoneOffset; + } + + public void setTimeZoneOffset(String timeZoneOffset) { + this.timeZoneOffset = timeZoneOffset; + } + + public String getNfNamingCode() { + return nfNamingCode; + } + + public void setNfNamingCode(String nfNamingCode) { + this.nfNamingCode = nfNamingCode; + } + + public String getNfVendorName() { + return nfVendorName; + } + + public void setNfVendorName(String nfVendorName) { + this.nfVendorName = nfVendorName; + } + + @Override + public String toString() { + return "CommonEventHeader [version=" + version + ", vesEventListenerVersion=" + vesEventListenerVersion + + ", domain=" + domain + ", eventName=" + eventName + ", eventId=" + eventId + ", sequence=" + sequence + + ", priority=" + priority + ", reportingEntityId=" + reportingEntityId + ", reportingEntityName=" + + reportingEntityName + ", sourceId=" + sourceId + ", sourceName=" + sourceName + + ", startEpochMicrosec=" + startEpochMicrosec + ", lastEpochMicrosec=" + lastEpochMicrosec + + ", timeZoneOffset=" + timeZoneOffset + ", nfNamingCode=" + nfNamingCode + ", nfVendorName=" + + nfVendorName + "]"; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java index 1126102..a0dc6c5 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java @@ -45,63 +45,71 @@ public class Configuration { private List<String> optimizers; private int numSolutions; private int bufferTime; - private int maximumClusters; + private int maximumClusters; private String aafUsername; private String aafPassword; - private Map<String,Object> streamsSubscribes; - private Map<String,Object> streamsPublishes; + private Map<String, Object> streamsSubscribes; + private Map<String, Object> streamsPublishes; + private int badThreshold; + private int poorThreshold; - public boolean isSecured() { - if(aafUsername.equals("")||aafUsername==null){ - return false; - } - else - return true; - } - - - - public String getAafUsername() { - return aafUsername; - } - - - - public void setAafUsername(String aafUsername) { - this.aafUsername = aafUsername; - } + public int getBadThreshold() { + return badThreshold; + } + public void setBadThreshold(int badThreshold) { + this.badThreshold = badThreshold; + } + public int getPoorThreshold() { + return poorThreshold; + } - public String getAafPassword() { - return aafPassword; - } + public void setPoorThreshold(int poorThreshold) { + this.poorThreshold = poorThreshold; + } + /** + * Check if topic is secure. + */ + public boolean isSecured() { + return (aafUsername != null); + + } + public String getAafUsername() { + return aafUsername; + } - public void setAafPassword(String aafPassword) { - this.aafPassword = aafPassword; - } + public void setAafUsername(String aafUsername) { + this.aafUsername = aafUsername; + } + public String getAafPassword() { + return aafPassword; + } + public void setAafPassword(String aafPassword) { + this.aafPassword = aafPassword; + } - public Map<String, Object> getStreamsSubscribes() { - return streamsSubscribes; - } + public Map<String, Object> getStreamsSubscribes() { + return streamsSubscribes; + } - public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { - this.streamsSubscribes = streamsSubscribes; - } + public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { + this.streamsSubscribes = streamsSubscribes; + } - public Map<String, Object> getStreamsPublishes() { - return streamsPublishes; - } + public Map<String, Object> getStreamsPublishes() { + return streamsPublishes; + } - public void setStreamsPublishes(Map<String, Object> streamsPublishes) { - this.streamsPublishes = streamsPublishes; - } + public void setStreamsPublishes(Map<String, Object> streamsPublishes) { + this.streamsPublishes = streamsPublishes; + } - public int getMaximumClusters() { + public int getMaximumClusters() { return maximumClusters; } @@ -187,7 +195,7 @@ public class Configuration { this.sourceId = sourceId; } - public String getCallbackUrl() { + public String getCallbackUrl() { return callbackUrl; } @@ -250,39 +258,33 @@ public class Configuration { public void setPgPassword(String pgPassword) { this.pgPassword = pgPassword; } - - public List<String> getDmaapServers() { - return dmaapServers; - } - - public void setDmaapServers(List<String> dmaapServers) { - this.dmaapServers = dmaapServers; - } - - public String getConfigDbService() { - return configDbService; - } - - public void setConfigDbService(String configDbService) { - this.configDbService = configDbService; - } + public List<String> getDmaapServers() { + return dmaapServers; + } + public void setDmaapServers(List<String> dmaapServers) { + this.dmaapServers = dmaapServers; + } - @Override - public String toString() { - return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword=" - + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService + ", oofService=" - + oofService + ", cg=" + cg + ", cid=" + cid + ", pollingInterval=" + pollingInterval - + ", pollingTimeout=" + pollingTimeout + ", minCollision=" + minCollision + ", minConfusion=" - + minConfusion + ", sourceId=" + sourceId + ", callbackUrl=" + callbackUrl + ", optimizers=" - + optimizers + ", numSolutions=" + numSolutions + ", bufferTime=" + bufferTime + ", maximumClusters=" - + maximumClusters + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword - + ", streamsSubscribes=" + streamsSubscribes + ", streamsPublishes=" + streamsPublishes + "]"; - } + public String getConfigDbService() { + return configDbService; + } - + public void setConfigDbService(String configDbService) { + this.configDbService = configDbService; + } + @Override + public String toString() { + return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword=" + + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService + + ", oofService=" + oofService + ", cg=" + cg + ", cid=" + cid + ", pollingInterval=" + pollingInterval + + ", pollingTimeout=" + pollingTimeout + ", minCollision=" + minCollision + ", minConfusion=" + + minConfusion + ", sourceId=" + sourceId + ", callbackUrl=" + callbackUrl + ", optimizers=" + + optimizers + ", numSolutions=" + numSolutions + ", bufferTime=" + bufferTime + ", maximumClusters=" + + maximumClusters + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword + + ", streamsSubscribes=" + streamsSubscribes + ", streamsPublishes=" + streamsPublishes + "]"; + } - } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java index f2c444c..39cfbd1 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponent.java @@ -26,9 +26,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import fj.data.Either; import java.io.IOException; - import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.dao.PerformanceNotificationsRepository; import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.model.PMNotification; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,12 +39,15 @@ public class DmaapNotificationsComponent { private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); /** - * Get dmaap notifications. + * Get sdnr notifications */ - public Either<Notification, Integer> getDmaapNotifications() { + public Either<Notification, Integer> getSdnrNotifications() { DmaapNotificationsRepository dmaapNotificationsRepository = BeanUtil .getBean(DmaapNotificationsRepository.class); String notificationString = dmaapNotificationsRepository.getNotificationFromQueue(); + if (notificationString == null) { + return Either.right(404); + } ObjectMapper mapper = new ObjectMapper(); Notification notification = new Notification(); @@ -55,5 +59,26 @@ public class DmaapNotificationsComponent { return Either.right(400); } } + + /** + * Get pm notifications + */ + public Either<PMNotification,Integer> getPmNotifications(){ + PerformanceNotificationsRepository pmNotificationRepository = BeanUtil.getBean(PerformanceNotificationsRepository.class); + String pmNotificationString = pmNotificationRepository.getPerformanceNotificationFromQueue(); + if (pmNotificationString == null) { + return Either.right(404); + } + ObjectMapper mapper = new ObjectMapper(); + PMNotification pmNotification = new PMNotification(); + + try { + pmNotification = mapper.readValue(pmNotificationString, PMNotification.class); + return Either.left(pmNotification); + } catch(IOException e) { + log.error("Exception in parsing pm notification ",pmNotificationString,e); + return Either.right(400); + } + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/Event.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Event.java new file mode 100644 index 0000000..84b8eee --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Event.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.dcaegen2.services.sonhms; + +public class Event { + private CommonEventHeader commonEventHeader; + private FaultFields faultFields; + public CommonEventHeader getCommonEventHeader() { + return commonEventHeader; + } + public void setCommonEventHeader(CommonEventHeader commonEventHeader) { + this.commonEventHeader = commonEventHeader; + } + public FaultFields getFaultFields() { + return faultFields; + } + public void setFaultFields(FaultFields faultFields) { + this.faultFields = faultFields; + } + @Override + public String toString() { + return "Event [commonEventHeader=" + commonEventHeader + ", faultFields=" + faultFields + "]"; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java index df24aa8..a25fe0e 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java @@ -25,9 +25,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import fj.data.Either; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -39,7 +39,10 @@ import org.onap.dcaegen2.services.sonhms.child.ChildThread; import org.onap.dcaegen2.services.sonhms.child.Graph; import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.model.ClusterMap; import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.model.LteNeighborListInUseLteCell; import org.onap.dcaegen2.services.sonhms.model.Notification; import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; import org.onap.dcaegen2.services.sonhms.utils.ThreadUtils; @@ -59,7 +62,7 @@ public class EventHandler { private ExecutorService pool; private ClusterUtils clusterUtils; - + private ThreadUtils threadUtils; /** @@ -76,15 +79,152 @@ public class EventHandler { } /** + * Handles fault notifications. + */ + public Boolean handleFaultNotification(List<FaultEvent> fmNotification) { + + log.info("Handling Fault notification"); + log.info("fm notification {}", fmNotification); + + Set<String> cellIds = new HashSet<>(); + List<ClusterDetails> clusterDetails = clusterUtils.getAllClusters(); + String networkId = ""; + Map<String, ArrayList<Integer>> collisionConfusionMap = new HashMap<>(); + + for (FaultEvent faultEvent : fmNotification) { + String cellId = faultEvent.getEvent().getCommonEventHeader().getSourceName(); + cellIds.add(cellId); + networkId = faultEvent.getEvent().getFaultFields().getAlarmAdditionalInformation().getNetworkId(); + ArrayList<Integer> counts = new ArrayList<>(); + counts.add(faultEvent.getEvent().getFaultFields().getAlarmAdditionalInformation().getCollisions()); + counts.add(faultEvent.getEvent().getFaultFields().getAlarmAdditionalInformation().getConfusions()); + collisionConfusionMap.put(cellId, counts); + } + FaultNotificationtoClusterMapping faultNotificationtoClusterMapping = clusterUtils + .getClustersForFmNotification(cellIds, clusterDetails); + + faultNotificationtoClusterMapping.setCollisionConfusionMap(collisionConfusionMap); + // matching cells + if (faultNotificationtoClusterMapping.getCellsinCluster() != null && !faultNotificationtoClusterMapping.getCellsinCluster().isEmpty()) { + try { + handleMatchedFmCells(faultNotificationtoClusterMapping, clusterDetails); + } catch (ConfigDbNotFoundException e) { + log.error("Config DB Exception {}", e); + } + + } + // unmatched new cells + if (faultNotificationtoClusterMapping.getNewCells() != null && !faultNotificationtoClusterMapping.getNewCells().isEmpty()) { + handleUnmatchedFmCells(faultNotificationtoClusterMapping, networkId); + + } + + return true; + } + + /** + * handle matched fm cells. + * + */ + private void handleMatchedFmCells(FaultNotificationtoClusterMapping faultNotificationtoClusterMapping, + List<ClusterDetails> clusterDetails) throws ConfigDbNotFoundException { + Map<String, String> cellsinCluster = faultNotificationtoClusterMapping.getCellsinCluster(); + log.info("Handling Matching cells for FM notification"); + + for (Entry<String, String> entry : cellsinCluster.entrySet()) { + + String cellId = entry.getKey(); + String clusterId = entry.getValue(); + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = clusterUtils.findClusterMap(cellId); + + Either<ClusterDetails, Integer> clusterDetail = clusterUtils.getClusterDetailsFromClusterId(clusterId, + clusterDetails); + + if (clusterDetail.isRight()) { + log.error("Cannot find the cluster for Cluster ID"); + return; + } else { + long threadId = clusterDetail.left().value().getChildThreadId(); + + if (childStatus.get(threadId).equals("triggeredOof")) { + log.info("OOF triggered for the cluster, buffering notification"); + bufferNotification(clusterMap, clusterId); + } else { + childThreadMap.get(threadId).putInQueue(clusterMap); + } + } + } + + } + + /** + * handle unmatched fm cells. + * + * @param networkId2 + * @param faultNotificationtoClusterMapping + */ + private void handleUnmatchedFmCells(FaultNotificationtoClusterMapping faultNotificationtoClusterMapping, + String networkId) { + List<String> newCells = faultNotificationtoClusterMapping.getNewCells(); + log.info("Handle Unmatching cells for FM notificatins newCells{}", newCells); + List<Graph> newClusters = new ArrayList<>(); + + for (String cellId : newCells) { + ArrayList<Integer> collisionConfusionCount = faultNotificationtoClusterMapping.getCollisionConfusionMap() + .get(cellId); + log.info("Handle Unmatching cells for FM notificatins,collisionConfusionCount{}", collisionConfusionCount); + + Either<Graph, Integer> existingCluster = clusterUtils.getClusterForFMCell(cellId, newClusters); + if (existingCluster.isRight()) { + try { + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = clusterUtils.findClusterMap(cellId); + Graph cluster = clusterUtils.createCluster(clusterMap); + cluster.setNetworkId(networkId); + Map<String, ArrayList<Integer>> collisionConfusionMap = new HashMap<>(); + collisionConfusionMap.put(cellId, collisionConfusionCount); + cluster.setCollisionConfusionMap(collisionConfusionMap); + + newClusters.add(cluster); + } catch (ConfigDbNotFoundException e) { + log.error("Error connecting with configDB {}", e); + } + } + + else { + Graph cluster = existingCluster.left().value(); + + Graph modifiedCluster = null; + try { + modifiedCluster = clusterUtils.modifyCluster(cluster, clusterUtils.findClusterMap(cellId)); + Map<String, ArrayList<Integer>> collisionConfusionMap = cluster.getCollisionConfusionMap(); + collisionConfusionMap.put(cellId, collisionConfusionCount); + cluster.setCollisionConfusionMap(collisionConfusionMap); + } catch (ConfigDbNotFoundException e) { + log.error("Config DB not found {}", e); + } + newClusters.remove(cluster); + newClusters.add(modifiedCluster); + } + + } + + // create new child thread + log.info("New clusters {}", newClusters); + + threadUtils.createNewThread(newClusters, childStatusQueue, pool, this, null); + + } + + /** * handle sdnr notification. */ public Boolean handleSdnrNotification(Notification notification) { // Check if notification matches with a cluster - + log.info("Handling SDNR notification"); try { List<ClusterDetails> clusterDetails = clusterUtils.getAllClusters(); - NotificationToClusterMapping mapping = clusterUtils.getClustersForNotification(notification, + NotificationToClusterMapping mapping = clusterUtils.getClustersForNotification(notification, clusterDetails); // Matching cells @@ -105,15 +245,22 @@ public class EventHandler { } - private void handleUnMatchingCells(List<FapServiceList> newCells) { + private void handleUnMatchingCells(List<FapServiceList> newCells) throws ConfigDbNotFoundException { + + log.info("handling unmatched cells"); + List<Graph> newClusters = new ArrayList<>(); for (FapServiceList fapService : newCells) { + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = clusterUtils.findClusterMap(fapService.getAlias()); Either<Graph, Integer> existingCluster = clusterUtils.getClusterForCell(fapService, newClusters); if (existingCluster.isRight()) { try { - Graph cluster = clusterUtils.createCluster(fapService); + Graph cluster = clusterUtils.createCluster(clusterMap); + cluster.setNetworkId(fapService.getCellConfig().getLte().getRan().getNeighborListInUse() + .getLteNeighborListInUseLteCell().get(0).getPlmnid()); + cluster.setCollisionConfusionMap(new HashMap<>()); newClusters.add(cluster); } catch (ConfigDbNotFoundException e) { log.error("Error connecting with configDB {}", e); @@ -122,8 +269,8 @@ public class EventHandler { else { Graph cluster = existingCluster.left().value(); - - Graph modifiedCluster = clusterUtils.modifyCluster(cluster, fapService); + Graph modifiedCluster = clusterUtils.modifyCluster(cluster, + clusterUtils.findClusterMap(fapService.getAlias())); newClusters.remove(cluster); newClusters.add(modifiedCluster); } @@ -131,16 +278,33 @@ public class EventHandler { } // create new child thread - - threadUtils.createNewThread(newClusters, childStatusQueue, pool, this); + + threadUtils.createNewThread(newClusters, childStatusQueue, pool, this, null); } - private void handleMatchingCells(Map<FapServiceList, String> cellsInCluster, List<ClusterDetails> clusterDetails) { + private void handleMatchingCells(Map<FapServiceList, String> cellsInCluster, List<ClusterDetails> clusterDetails) + throws ConfigDbNotFoundException { + + log.info("handling matching cells"); + for (Entry<FapServiceList, String> entry : cellsInCluster.entrySet()) { FapServiceList fapService = entry.getKey(); String clusterId = entry.getValue(); + String cellId = fapService.getAlias(); + int pci = fapService.getX0005b9Lte().getPhyCellIdInUse(); + ArrayList<CellPciPair> neighbours = new ArrayList<>(); + for (LteNeighborListInUseLteCell neighbour : fapService.getCellConfig().getLte().getRan() + .getNeighborListInUse().getLteNeighborListInUseLteCell()) { + String neighbourCellId = neighbour.getAlias(); + int neighbourPci = neighbour.getPhyCellId(); + neighbours.add(new CellPciPair(neighbourCellId, neighbourPci)); + + } + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<>(); + clusterMap.put(new CellPciPair(cellId, pci), neighbours); + Either<ClusterDetails, Integer> clusterDetail = clusterUtils.getClusterDetailsFromClusterId(clusterId, clusterDetails); @@ -152,23 +316,33 @@ public class EventHandler { if (childStatus.get(threadId).equals("triggeredOof")) { log.info("OOF triggered for the cluster, buffering notification"); - bufferNotification(fapService, clusterId); + + bufferNotification(clusterMap, clusterId); } else { - childThreadMap.get(threadId).putInQueue(fapService); + log.info("Forwarding notification to child thread {}", threadId); + childThreadMap.get(threadId).putInQueue(clusterMap); } } } } - private void bufferNotification(FapServiceList fapService, String clusterId) { + private void bufferNotification(Map<CellPciPair, ArrayList<CellPciPair>> clusterMap, String clusterId) { + + log.info("Buffering notifications ..."); ObjectMapper mapper = new ObjectMapper(); - BufferNotificationComponent bufferNotifComponent = new BufferNotificationComponent(); String serviceListString = ""; + + ClusterMap clusterMapJson = new ClusterMap(); + + clusterMapJson.setCell(clusterMap.keySet().iterator().next()); + clusterMapJson.setNeighbourList(clusterMap.get(clusterMap.keySet().iterator().next())); + try { - serviceListString = mapper.writeValueAsString(fapService); + serviceListString = mapper.writeValueAsString(clusterMapJson); } catch (JsonProcessingException e) { - log.debug("JSON processing exception: {}", e); + log.error("JSON processing exception: {}", e); } + BufferNotificationComponent bufferNotifComponent = new BufferNotificationComponent(); bufferNotifComponent.bufferNotification(serviceListString, clusterId); } @@ -178,52 +352,19 @@ public class EventHandler { */ public void handleChildStatusUpdate(List<String> childStatus) { - // update Child status in data structure + log.info("Handling child status update"); + Long childThreadId = Long.parseLong(childStatus.get(0)); addChildStatus(childThreadId, childStatus.get(1)); // if child status is OOF result success, handle buffered notifications - if (childStatus.get(1).equals("success")) { - BufferNotificationComponent bufferNotificationComponent = new BufferNotificationComponent(); - ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent(); - String clusterId = clusterDetailsComponent.getClusterId(childThreadId); - List<String> bufferedNotifications = bufferNotificationComponent.getBufferedNotification(clusterId); - - if (bufferedNotifications == null || bufferedNotifications.isEmpty()) { - log.info("No buffered notification for this thread"); - - Set<Thread> setOfThread = Thread.getAllStackTraces().keySet(); - for (Thread thread : setOfThread) { - if (thread.getId() == childThreadId) { - deleteChildStatus(childThreadId); - thread.interrupt(); - } - } - } else { - handleBufferedNotifications(childThreadId, bufferedNotifications); - } + if (childStatus.get(1).equals("done")) { + deleteChildStatus(childThreadId); } // else kill the child thread } - private void handleBufferedNotifications(Long childThreadId, List<String> bufferedNotifications) { - - ObjectMapper mapper = new ObjectMapper(); - for (String notification : bufferedNotifications) { - FapServiceList fapServiceList; - try { - fapServiceList = mapper.readValue(notification, FapServiceList.class); - log.debug("fapServiceList{}", fapServiceList); - - childThreadMap.get(childThreadId).putInQueueWithNotify(fapServiceList); - - } catch (IOException e) { - log.error("Error parsing the buffered notification, skipping {}", e); - } - } - } - public static void addChildThreadMap(Long childThreadId, ChildThread child) { childThreadMap.put(childThreadId, child); } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultEvent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultEvent.java new file mode 100644 index 0000000..57f7d43 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultEvent.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +public class FaultEvent { + + private Event event; + + public Event getEvent() { + return event; + } + + public void setEvent(Event event) { + this.event = event; + } + + @Override + public String toString() { + return "FaultEvent [event=" + event + "]"; + } + + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java new file mode 100644 index 0000000..462f550 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultFields.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +public class FaultFields { + + @Override + public String toString() { + return "FaultFields [faultFieldsVersion=" + faultFieldsVersion + ", alarmCondition=" + alarmCondition + + ", eventSourceType=" + eventSourceType + ", specificProblem=" + specificProblem + ", eventSeverity=" + + eventSeverity + ", vfStatus=" + vfStatus + ", alarmAdditionalInformation=" + + alarmAdditionalInformation + "]"; + } + + private int faultFieldsVersion; + private String alarmCondition; + private String eventSourceType; + private String specificProblem; + private String eventSeverity; + private String vfStatus; + private AlarmAdditionalInformation alarmAdditionalInformation; + + + public AlarmAdditionalInformation getAlarmAdditionalInformation() { + return alarmAdditionalInformation; + } + + public void setAlarmAdditionalInformation(AlarmAdditionalInformation alarmAdditionalInformation) { + this.alarmAdditionalInformation = alarmAdditionalInformation; + } + + public int getFaultFieldsVersion() { + return faultFieldsVersion; + } + + public void setFaultFieldsVersion(int faultFieldsVersion) { + this.faultFieldsVersion = faultFieldsVersion; + } + + public String getAlarmCondition() { + return alarmCondition; + } + + public void setAlarmCondition(String alarmCondition) { + this.alarmCondition = alarmCondition; + } + + public String getEventSourceType() { + return eventSourceType; + } + + public void setEventSourceType(String eventSourceType) { + this.eventSourceType = eventSourceType; + } + + public String getSpecificProblem() { + return specificProblem; + } + + public void setSpecificProblem(String specificProblem) { + this.specificProblem = specificProblem; + } + + public String getEventSeverity() { + return eventSeverity; + } + + public void setEventSeverity(String eventSeverity) { + this.eventSeverity = eventSeverity; + } + + public String getVfStatus() { + return vfStatus; + } + + public void setVfStatus(String vfStatus) { + this.vfStatus = vfStatus; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java new file mode 100644 index 0000000..99695ab --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponent.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import fj.data.Either; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.onap.dcaegen2.services.sonhms.dao.FaultNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FaultNotificationComponent { + + private static Logger log = LoggerFactory.getLogger(FaultNotificationComponent.class); + + /** + * Get fault notifications. + */ + public Either<List<FaultEvent>,Integer> getFaultNotifications() { + FaultNotificationsRepository faultNotificationsRepository = BeanUtil + .getBean(FaultNotificationsRepository.class); + String notificationString = faultNotificationsRepository.getFaultNotificationFromQueue(); + log.info("get fault notifications method"); + if (notificationString == null) { + return Either.right(404); + } + ObjectMapper mapper = new ObjectMapper(); + FaultEvent faultEvent = new FaultEvent(); + List<FaultEvent> faultEvents = new ArrayList<>(); + try { + faultEvent = mapper.readValue(notificationString,FaultEvent.class); + log.info("Parsing FM notification"); + + } catch (IOException e) { + log.error("Exception in parsing Notification {}", e); + return Either.right(400); + } + + faultEvents.add(faultEvent); + + return Either.left(faultEvents); + + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationtoClusterMapping.java b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationtoClusterMapping.java new file mode 100644 index 0000000..5e59467 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/FaultNotificationtoClusterMapping.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class FaultNotificationtoClusterMapping { + public Map<String, String> getCellsinCluster() { + return cellsinCluster; + } + + public void setCellsinCluster(Map<String, String> cellsinCluster) { + this.cellsinCluster = cellsinCluster; + } + + public List<String> getNewCells() { + return newCells; + } + + public void setNewCells(List<String> newCells) { + this.newCells = newCells; + } + + private Map<String, ArrayList<Integer>> collisionConfusionMap; + + //map that returns cellid and its matching cluster id + + public Map<String, ArrayList<Integer>> getCollisionConfusionMap() { + return collisionConfusionMap; + } + + public void setCollisionConfusionMap(Map<String, ArrayList<Integer>> collisionConfusionMap) { + this.collisionConfusionMap = collisionConfusionMap; + } + + private Map<String, String> cellsinCluster; + + //cells that dont match + private List<String> newCells; +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponent.java new file mode 100644 index 0000000..d27227f --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponent.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import fj.data.Either; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.dcaegen2.services.sonhms.dao.HandOverMetricsRepository; +import org.onap.dcaegen2.services.sonhms.model.HoDetails; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HoMetricsComponent { + + private static Logger log = LoggerFactory.getLogger(HoMetricsComponent.class); + + /** + * Get HO metrics. + */ + + public Either<List<HoDetails>, Integer> getHoMetrics(String srcCellId) { + HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); + String hoDetailsString = handOverMetricsRepository.getHandOverMetrics(srcCellId); + if (hoDetailsString != null) { + ObjectMapper mapper = new ObjectMapper(); + List<HoDetails> hoDetails = new ArrayList<>(); + try { + hoDetails = mapper.readValue(hoDetailsString, new TypeReference<ArrayList<HoDetails>>() { + }); + return Either.left(hoDetails); + } catch (Exception e) { + log.error("Exception in parsing HO metrics", hoDetailsString, e); + return Either.right(400); + } + } else + return Either.right(404); + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java index 84775ad..6cbb711 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThread.java @@ -23,12 +23,16 @@ package org.onap.dcaegen2.services.sonhms; import fj.data.Either; +import java.sql.Timestamp; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; +import org.onap.dcaegen2.services.sonhms.model.FapServiceList; import org.onap.dcaegen2.services.sonhms.model.Notification; import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; import org.onap.dcaegen2.services.sonhms.utils.ThreadUtils; @@ -36,37 +40,81 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MainThread implements Runnable { + private static Logger log = LoggerFactory.getLogger(MainThread.class); - private NewNotification newNotification; + private NewSdnrNotification newNotification; + + private NewFmNotification newFmNotification; private BlockingQueue<List<String>> childStatusQueue; - + private DmaapNotificationsComponent dmaapNotificationsComponent; - + + private FaultNotificationComponent faultNotificationComponent; + private EventHandler eventHandler; - + + private Map<String, FaultEvent> bufferedFMNotificationCells; + + private List<String> sdnrNotificationCells; + + private Boolean isTimer; + + private Timestamp startTimer; + + List<FaultEvent> fmNotificationToBuffer; + /** * parameterized constructor. */ - public MainThread(NewNotification newNotification) { - super(); + public MainThread(NewSdnrNotification newNotification, NewFmNotification newFmNotification) { + super(); + this.newFmNotification = newFmNotification; this.newNotification = newNotification; childStatusQueue = new LinkedBlockingQueue<>(); dmaapNotificationsComponent = new DmaapNotificationsComponent(); - eventHandler = new EventHandler(childStatusQueue, - Executors.newFixedThreadPool(Configuration.getInstance().getMaximumClusters()), - new HashMap<>(), new ClusterUtils(), new ThreadUtils()); - } - + faultNotificationComponent = new FaultNotificationComponent(); + sdnrNotificationCells = new ArrayList<>(); + fmNotificationToBuffer = new ArrayList<>(); + bufferedFMNotificationCells = new HashMap<>(); + eventHandler = new EventHandler(childStatusQueue, + Executors.newFixedThreadPool(Configuration.getInstance().getMaximumClusters()), new HashMap<>(), + new ClusterUtils(), new ThreadUtils()); + isTimer = false; + startTimer = new Timestamp(System.currentTimeMillis()); + + } + @Override public void run() { log.info("Starting Main Thread"); // Check for Notifications from Dmaap and Child thread - Boolean done = false; - + Boolean done = false; + while (!done) { + + Timestamp currentTime = new Timestamp(System.currentTimeMillis()); + if (isTimer) { + Long difference = currentTime.getTime() - startTimer.getTime(); + if (difference > 5000) { + log.info("FM handling difference > 5000"); + + for (String sdnrCell: sdnrNotificationCells) { + bufferedFMNotificationCells.remove(sdnrCell); + } + + log.info("FM bufferedFMNotificationCells {}", bufferedFMNotificationCells.values()); + List<FaultEvent> fmNotificationsToHandle = new ArrayList<>( + bufferedFMNotificationCells.values()); + Boolean result = eventHandler.handleFaultNotification(fmNotificationsToHandle); + bufferedFMNotificationCells = new HashMap<>(); + isTimer = false; + log.info("FM notification handling {}", result); + } + } + try { if (!childStatusQueue.isEmpty()) { List<String> childState = childStatusQueue.poll(); @@ -76,12 +124,57 @@ public class MainThread implements Runnable { } if (newNotification.getNewNotif()) { - Either<Notification, Integer> notification = dmaapNotificationsComponent.getDmaapNotifications(); + Either<Notification, Integer> notification = dmaapNotificationsComponent.getSdnrNotifications(); if (notification.isRight()) { - log.error("Error parsing the notification from SDNR"); + if (notification.right().value() == 400) { + log.error("Error parsing the notification from SDNR"); + } else if (notification.right().value() == 404) { + newNotification.setNewNotif(false); + } } else if (notification.isLeft()) { + List<FapServiceList> fapServiceLists = (notification.left().value()).getPayload() + .getRadioAccess().getFapServiceList(); + for (FapServiceList fapServiceList : fapServiceLists) { + sdnrNotificationCells.add(fapServiceList.getAlias()); + + } + Boolean result = eventHandler.handleSdnrNotification(notification.left().value()); log.debug("SDNR notification handling {}", result); + + } + + } + if (newFmNotification.getNewNotif()) { + log.info("newFmNotification has come"); + + String faultCellId = ""; + Either<List<FaultEvent>, Integer> fmNotifications = faultNotificationComponent + .getFaultNotifications(); + if (fmNotifications.isRight()) { + if (fmNotifications.right().value() == 400) { + log.info("Error parsing notifications"); + } else if (fmNotifications.right().value() == 404) { + newFmNotification.setNewNotif(false); + } + } else { + for (FaultEvent fmNotification : fmNotifications.left().value()) { + faultCellId = fmNotification.getEvent().getCommonEventHeader().getSourceName(); + bufferedFMNotificationCells.put(faultCellId, fmNotification); + log.info("Buffered FM cell {}", faultCellId); + log.info("fmNotification{}", fmNotification); + + } + log.info("bufferedFMNotificationCells before staring timer {}", + bufferedFMNotificationCells.keySet()); + + for (String sdnrCell: sdnrNotificationCells) { + bufferedFMNotificationCells.remove(sdnrCell); + } + + startTimer = new Timestamp(System.currentTimeMillis()); + isTimer = true; + log.info("Buffered FM cell {}", bufferedFMNotificationCells.keySet()); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java index 1b4ff26..606f420 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/MainThreadComponent.java @@ -34,7 +34,13 @@ public class MainThreadComponent { private static Logger log = LoggerFactory.getLogger(MainThreadComponent.class); @Autowired - private NewNotification newNotification; + private NewSdnrNotification newNotification; + + @Autowired + private NewPmNotification newPmNotification; + + @Autowired + private NewFmNotification newFmNotification; /** * main thread initialization. @@ -42,7 +48,9 @@ public class MainThreadComponent { @PostConstruct public void init() { log.debug("initializing main thread"); - Thread thread = new Thread(new MainThread(newNotification)); + Thread thread = new Thread(new MainThread(newNotification, newFmNotification)); thread.start(); + Thread pmThread = new Thread(new PMThread(newPmNotification)); + pmThread.start(); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/NewNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/NewFmNotification.java index 703204b..fa71c4f 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/NewNotification.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/NewFmNotification.java @@ -21,13 +21,19 @@ package org.onap.dcaegen2.services.sonhms; +import javax.annotation.PostConstruct; + import org.springframework.stereotype.Component; @Component -public class NewNotification { - +public class NewFmNotification { private Boolean newNotif; + @PostConstruct + void init() { + newNotif = false; + } + public Boolean getNewNotif() { return newNotif; } @@ -36,13 +42,12 @@ public class NewNotification { this.newNotif = newNotif; } - public NewNotification(Boolean newNotif) { + public NewFmNotification(Boolean newNotif) { super(); this.newNotif = newNotif; } - - public NewNotification() { - - } + public NewFmNotification() { + + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/NewPmNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/NewPmNotification.java new file mode 100644 index 0000000..ce583dd --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/NewPmNotification.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import javax.annotation.PostConstruct; + +import org.springframework.stereotype.Component; + +@Component +public class NewPmNotification { + + private Boolean newNotif; + + @PostConstruct + public void init() { + newNotif=false; + } + + public Boolean getNewNotif() { + return newNotif; + } + + public void setNewNotif(Boolean newNotif) { + this.newNotif = newNotif; + } + + public NewPmNotification(Boolean newNotif) { + super(); + this.newNotif = newNotif; + } + + public NewPmNotification() { + + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/NewSdnrNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/NewSdnrNotification.java new file mode 100644 index 0000000..127b559 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/NewSdnrNotification.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import javax.annotation.PostConstruct; + +import org.springframework.stereotype.Component; + +@Component +public class NewSdnrNotification { + + private Boolean newNotif; + + @PostConstruct + void init() { + newNotif = false; + } + + public Boolean getNewNotif() { + return newNotif; + } + + public void setNewNotif(Boolean newNotif) { + this.newNotif = newNotif; + } + + public NewSdnrNotification(Boolean newNotif) { + super(); + this.newNotif = newNotif; + } + + public NewSdnrNotification() { + + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandler.java new file mode 100644 index 0000000..0482b83 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandler.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * pcims + * ================================================================================ + * Copyright (C) 2018 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + ******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.List; +import org.onap.dcaegen2.services.sonhms.dao.HandOverMetricsRepository; +import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; +import org.onap.dcaegen2.services.sonhms.entity.HandOverMetrics; +import org.onap.dcaegen2.services.sonhms.model.AdditionalMeasurements; +import org.onap.dcaegen2.services.sonhms.model.CellConfig; +import org.onap.dcaegen2.services.sonhms.model.Common; +import org.onap.dcaegen2.services.sonhms.model.Configurations; +import org.onap.dcaegen2.services.sonhms.model.Data; +import org.onap.dcaegen2.services.sonhms.model.FapService; +import org.onap.dcaegen2.services.sonhms.model.HoDetails; +import org.onap.dcaegen2.services.sonhms.model.Lte; +import org.onap.dcaegen2.services.sonhms.model.LteCell; +import org.onap.dcaegen2.services.sonhms.model.NeighborListInUse; +import org.onap.dcaegen2.services.sonhms.model.PMNotification; +import org.onap.dcaegen2.services.sonhms.model.Payload; +import org.onap.dcaegen2.services.sonhms.model.Ran; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PMNotificationHandler { + + private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class); + PolicyDmaapClient policyDmaapClient; + + public PMNotificationHandler() { + + } + + public PMNotificationHandler(PolicyDmaapClient policyDmaapClient) { + this.policyDmaapClient = policyDmaapClient; + } + + /** + * handle pm notifications. + */ + public Boolean handlePmNotifications(PMNotification pmNotification, int badThreshold) { + HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); + Boolean result; + try { + List<HoDetails> hoDetailsList = new ArrayList<>(); + List<LteCell> lteCellList = new ArrayList<>(); + String srcCellId = pmNotification.getEvent().getCommonEventHeader().getSourceName(); + for (AdditionalMeasurements additionalMeasurements : pmNotification.getEvent().getMeasurement() + .getAdditionalMeasurements()) { + int attemptsCount = Integer + .parseInt(additionalMeasurements.getArrayOfNamedHashMap().get(1).get("InterEnbOutAtt_X2HO")); + int successCount = Integer + .parseInt(additionalMeasurements.getArrayOfNamedHashMap().get(2).get("InterEnbOutSucc_X2HO")); + float successRate = ((float) successCount / attemptsCount) * 100; + if (successRate >= badThreshold) { + HoDetails hoDetails = new HoDetails(); + hoDetails.setDstCellId(additionalMeasurements.getName()); + hoDetails.setAttemptsCount(attemptsCount); + hoDetails.setSuccessCount(successCount); + hoDetails.setSuccessRate(successRate); + hoDetailsList.add(hoDetails); + log.info("not bad neighbor {}",additionalMeasurements.getName()); + } else { + log.info(" bad neighbor {}",additionalMeasurements.getName()); + LteCell lteCell = new LteCell(); + lteCell.setBlacklisted("true"); + lteCell.setCid(additionalMeasurements.getName()); + lteCell.setPlmnId(additionalMeasurements.getArrayOfNamedHashMap().get(0).get("networkId")); + lteCell.setPnfName(pmNotification.getEvent().getCommonEventHeader().getReportingEntityName()); + lteCellList.add(lteCell); + } + } + if (!lteCellList.isEmpty()) { + log.info("triggering policy to remove bad neighbors"); + result = sendAnrUpdateToPolicy(pmNotification, lteCellList); + log.info("Sent ANR update to policy {}", result); + String hoDetailsString = handOverMetricsRepository.getHandOverMetrics(srcCellId); + if (hoDetailsString != null) { + ObjectMapper mapper = new ObjectMapper(); + String newHoDetailsString = null; + try { + newHoDetailsString = mapper.writeValueAsString(hoDetailsList); + } catch (Exception e) { + log.error("Error in writing handover metrics json ", e); + return false; + } + handOverMetricsRepository.updateHoMetrics(newHoDetailsString, srcCellId); + } + } + if (!hoDetailsList.isEmpty()) { + result = saveToHandOverMetrics(hoDetailsList, srcCellId); + log.debug("save HO metrics result {} ", result); + + } + + } catch (Exception e) { + log.error("Error in handlePmNotifications ", e); + return false; + } + return true; + + } + + private Boolean sendAnrUpdateToPolicy(PMNotification pmNotification, List<LteCell> lteCellList) { + ObjectMapper mapper = new ObjectMapper(); + try { + mapper.setSerializationInclusion(Include.NON_NULL); + ArrayList<Configurations> configurations = new ArrayList<>(); + String cellId = pmNotification.getEvent().getCommonEventHeader().getSourceName(); + Configurations configuration = new Configurations( + new Data(new FapService(cellId, null, new CellConfig(new Lte(new Ran(new Common(cellId), + new NeighborListInUse(null, lteCellList, String.valueOf(lteCellList.size())))))))); + configurations.add(configuration); + Payload payload = new Payload(configurations); + log.info("payload : {}", payload); + String anrUpdateString = mapper.writeValueAsString(payload); + + Boolean result = policyDmaapClient.sendNotificationToPolicy(anrUpdateString); + log.debug("send notification to policy result {} ", result); + } catch (Exception e) { + log.error("Exception in sending Anr update to policy ", e); + return false; + } + return true; + } + + private Boolean saveToHandOverMetrics(List<HoDetails> hoDetailsList, String srcCellId) { + HandOverMetricsRepository handOverMetricsRepository = BeanUtil.getBean(HandOverMetricsRepository.class); + ObjectMapper mapper = new ObjectMapper(); + String hoDetailsString = null; + try { + hoDetailsString = mapper.writeValueAsString(hoDetailsList); + } catch (Exception e) { + log.error("Error in writing handover metrics json ", e); + return false; + } + + if (handOverMetricsRepository.getHandOverMetrics(srcCellId) == null) { + HandOverMetrics handOverMetrics = new HandOverMetrics(); + handOverMetrics.setHoDetails(hoDetailsString); + handOverMetrics.setSrcCellId(srcCellId); + handOverMetricsRepository.save(handOverMetrics); + } + else { + handOverMetricsRepository.updateHoMetrics(hoDetailsString, srcCellId); + } + return true; + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/PMThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/PMThread.java new file mode 100644 index 0000000..608e61f --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/PMThread.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms; + +import fj.data.Either; + +import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; +import org.onap.dcaegen2.services.sonhms.model.PMNotification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PMThread implements Runnable { + + private static Logger log = LoggerFactory.getLogger(PMThread.class); + + private NewPmNotification newPmNotification; + + private DmaapNotificationsComponent dmaapNotificationsComponent; + + private PMNotificationHandler pmNotificationHandler; + + /** + * parameterized constructor. + */ + public PMThread(NewPmNotification newPmNotification) { + super(); + this.newPmNotification = newPmNotification; + dmaapNotificationsComponent = new DmaapNotificationsComponent(); + pmNotificationHandler = new PMNotificationHandler(new PolicyDmaapClient()); + } + + @Override + public void run() { + log.info("PM thread starting ..."); + // check for PM notifications + Boolean done = false; + while (!done) { + try { + Thread.sleep(1000); + if (newPmNotification.getNewNotif()) { + log.info("New PM notification from Dmaap"); + Either<PMNotification, Integer> pmNotification = dmaapNotificationsComponent.getPmNotifications(); + if (pmNotification.isRight()) { + if (pmNotification.right().value() == 400) { + log.error("error parsing pm notifications"); + } else if (pmNotification.right().value() == 404) { + log.info("Queue is empty"); + newPmNotification.setNewNotif(false); + } + } else if (pmNotification.isLeft()) { + Configuration configuration = Configuration.getInstance(); + Boolean result = pmNotificationHandler.handlePmNotifications(pmNotification.left().value(), + configuration.getBadThreshold()); + log.info("pm notification handler result {}", result); + } + + } + } catch (Exception e) { + log.error("Exception in PM Thread ", e); + done = true; + } + } + + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java index d12092b..5348e7d 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java @@ -21,18 +21,35 @@ package org.onap.dcaegen2.services.sonhms.child; +import com.fasterxml.jackson.databind.ObjectMapper; + +import fj.data.Either; + +import java.io.IOException; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import org.onap.dcaegen2.services.sonhms.BufferNotificationComponent; +import org.onap.dcaegen2.services.sonhms.ClusterDetailsComponent; +import org.onap.dcaegen2.services.sonhms.ConfigPolicy; import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.HoMetricsComponent; import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository; -import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository; +import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; +import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.AnrInput; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.model.ClusterMap; +import org.onap.dcaegen2.services.sonhms.model.HoDetails; import org.onap.dcaegen2.services.sonhms.model.ThreadId; import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; @@ -40,36 +57,45 @@ import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; import org.slf4j.Logger; import org.slf4j.MDC; - public class ChildThread implements Runnable { private BlockingQueue<List<String>> childStatusUpdate; - private BlockingQueue<FapServiceList> queue = new LinkedBlockingQueue<>(); + private BlockingQueue<Map<CellPciPair, ArrayList<CellPciPair>>> queue = new LinkedBlockingQueue<>(); private static Map<Long, AsyncResponseBody> responseMap = new HashMap<>(); private Graph cluster; private ThreadId threadId; - FapServiceList fapServiceList = new FapServiceList(); + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap; + HoMetricsComponent hoMetricsComponent; private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThread.class); /** * Constructor with parameters. */ public ChildThread(BlockingQueue<List<String>> childStatusUpdate, Graph cluster, - BlockingQueue<FapServiceList> queue, ThreadId threadId) { + BlockingQueue<Map<CellPciPair, ArrayList<CellPciPair>>> queue, ThreadId threadId, + HoMetricsComponent hoMetricsComponent) { super(); this.childStatusUpdate = childStatusUpdate; this.queue = queue; this.threadId = threadId; this.cluster = cluster; + this.hoMetricsComponent = hoMetricsComponent; + } + + public ChildThread() { + } /** * Puts notification in queue. */ - public void putInQueue(FapServiceList fapserviceList) { + // change this interface to send cell and neighbours to keep it generic for sdnr + // and fm + + public void putInQueue(Map<CellPciPair, ArrayList<CellPciPair>> clusterMap) { try { - queue.put(fapserviceList); + queue.put(clusterMap); } catch (InterruptedException e) { log.error(" The Thread is Interrupted", e); Thread.currentThread().interrupt(); @@ -79,10 +105,10 @@ public class ChildThread implements Runnable { /** * Puts notification in queue with notify. */ - public void putInQueueWithNotify(FapServiceList fapserviceList) { + public void putInQueueWithNotify(Map<CellPciPair, ArrayList<CellPciPair>> clusterMap) { synchronized (queue) { try { - queue.put(fapserviceList); + queue.put(clusterMap); queue.notifyAll(); } catch (InterruptedException e) { log.error(" The Thread is Interrupted", e); @@ -98,7 +124,7 @@ public class ChildThread implements Runnable { */ public static void putResponse(Long threadId, AsyncResponseBody obj) { synchronized (responseMap) { - responseMap.put(threadId, obj); + responseMap.put(threadId, obj); } } @@ -118,50 +144,132 @@ public class ChildThread implements Runnable { MDC.put("logFileName", Thread.currentThread().getName()); log.debug("Starting child thread"); - try { - fapServiceList = queue.take(); - if (log.isDebugEnabled()) { - log.debug("fapServicelist: {}", fapServiceList); - } - } catch (InterruptedException e1) { - log.error("InterruptedException is {}", e1); - Thread.currentThread().interrupt(); - } - - ClusterFormation clusterFormation = new ClusterFormation(queue); StateOof oof = new StateOof(childStatusUpdate); ClusterUtils clusterUtils = new ClusterUtils(); Detection detect = new Detection(); + ChildThreadUtils childUtils = new ChildThreadUtils(ConfigPolicy.getInstance(), new PnfUtils(), + new PolicyDmaapClient()); try { - String networkId = fapServiceList.getCellConfig().getLte().getRan().getNeighborListInUse() - .getLteNeighborListInUseLteCell().get(0).getPlmnid(); + String networkId = cluster.getNetworkId(); Boolean done = false; + Map<String, ArrayList<Integer>> collisionConfusionResult; while (!done) { + if (cluster.getCollisionConfusionMap().isEmpty()) { - Map<String, ArrayList<Integer>> collisionConfusionResult = detect.detectCollisionConfusion(cluster); - Boolean trigger = clusterFormation.triggerOrWait(collisionConfusionResult); + collisionConfusionResult = detect.detectCollisionConfusion(cluster); + } else { + collisionConfusionResult = cluster.getCollisionConfusionMap(); + } + Boolean trigger = childUtils.triggerOrWait(collisionConfusionResult); + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + int timer = 60; + try { + timer = (int) configPolicy.getConfig().get("PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS"); + } catch (NullPointerException e) { + log.info("Policy config not available. Using default timeout - 60 seconds"); + } if (!trigger) { - collisionConfusionResult = clusterFormation.waitForNotification(collisionConfusionResult, cluster); + try { + Thread.sleep((long) timer * 1000); + } catch (InterruptedException e) { + log.error("Interrupted Exception while waiting for more notifications {}", e); + Thread.currentThread().interrupt(); + } + + while (!queue.isEmpty()) { + Map<CellPciPair, ArrayList<CellPciPair>> newNotification; + newNotification = queue.poll(); + log.info("New notification from SDNR {}", newNotification); + cluster = clusterUtils.modifyCluster(cluster, newNotification); + + // update cluster in DB + clusterUtils.updateCluster(cluster); + + } + collisionConfusionResult = detect.detectCollisionConfusion(cluster); + + } + ArrayList<String> cellidList = new ArrayList<>(); + ArrayList<String> cellIds = new ArrayList<>(); + + for (Map.Entry<String, ArrayList<Integer>> entry : collisionConfusionResult.entrySet()) { + String key = entry.getKey(); + ArrayList<Integer> arr; + arr = entry.getValue(); + if (!arr.isEmpty()) { + Set<Integer> set = new HashSet<>(arr); + if (((set.size() == 1) && !set.contains(0)) || (set.size() != 1)) { + cellIds.add(key); + + } + } + + } + + for (String cell : cellIds) { + log.debug("cellidList entries: {}", cell); + cellidList.add(cell); + } + UUID transactionId; + Either<List<AnrInput>, Integer> anrTriggerResponse = checkAnrTrigger(cellidList); + if (anrTriggerResponse.isRight()) { + if (anrTriggerResponse.right().value() == 404) + log.debug("No poor neighbors found"); + else if (anrTriggerResponse.right().value() == 500) + log.debug("Failed to fetch HO details from DB "); + transactionId = oof.triggerOof(cellidList, networkId, new ArrayList<>()); + } else { + List<AnrInput> anrInputList = anrTriggerResponse.left().value(); + transactionId = oof.triggerOof(cellidList, networkId, anrInputList); + } + long childThreadId = Thread.currentThread().getId(); + childUtils.saveRequest(transactionId.toString(), childThreadId); + while (!ChildThread.getResponseMap().containsKey(childThreadId)) { + Thread.sleep(100); + } + + AsyncResponseBody asynResponseBody = ChildThread.getResponseMap().get(childThreadId); + + try { + childUtils.sendToPolicy(asynResponseBody); + } catch (ConfigDbNotFoundException e1) { + log.debug("Config DB is unreachable: {}", e1); + } + + SonRequestsRepository sonRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class); + sonRequestsRepository.deleteByChildThreadId(childThreadId); + + List<String> childStatus = new ArrayList<>(); + childStatus.add(Long.toString(Thread.currentThread().getId())); + childStatus.add("success"); + try { + childStatusUpdate.put(childStatus); + } catch (InterruptedException e) { + log.debug("InterruptedException during childStatus update {}", e); + Thread.currentThread().interrupt(); + } - oof.triggerOof(collisionConfusionResult, networkId); - if (isNotificationsBuffered()) { - List<FapServiceList> fapServiceLists = bufferNotification(); - for (FapServiceList fapService : fapServiceLists) { - cluster = clusterUtils.modifyCluster(cluster, fapService); + Either<List<String>, Integer> bufferedNotifications = getBufferedNotifications(); + + if (bufferedNotifications.isRight()) { + log.info("No buffered notifications"); + done = true; + } else { + List<Map<CellPciPair, ArrayList<CellPciPair>>> clusterMaps = getClusterMapsFromNotifications( + bufferedNotifications.left().value()); + for (Map<CellPciPair, ArrayList<CellPciPair>> bufferedClusterMap : clusterMaps) { + cluster = clusterUtils.modifyCluster(cluster, bufferedClusterMap); } String cellPciNeighbourString = cluster.getPciNeighbourJson(); UUID clusterId = cluster.getGraphId(); ClusterDetailsRepository clusterDetailsRepository = BeanUtil .getBean(ClusterDetailsRepository.class); clusterDetailsRepository.updateCluster(cellPciNeighbourString, clusterId.toString()); - - } else { - done = true; } } @@ -173,29 +281,57 @@ public class ChildThread implements Runnable { cleanup(); } - private boolean isNotificationsBuffered() { - synchronized (queue) { - + private List<Map<CellPciPair, ArrayList<CellPciPair>>> getClusterMapsFromNotifications(List<String> notifications) { + ObjectMapper mapper = new ObjectMapper(); + List<Map<CellPciPair, ArrayList<CellPciPair>>> clusterMaps = new ArrayList<>(); + for (String notification : notifications) { + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<>(); + ClusterMap clusterMapJson = new ClusterMap(); try { - while (queue.isEmpty()) { - queue.wait(); - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return false; + clusterMapJson = mapper.readValue(notification, ClusterMap.class); + clusterMap.put(clusterMapJson.getCell(), clusterMapJson.getNeighbourList()); + + log.debug("clusterMap{}", clusterMap); + clusterMaps.add(clusterMap); + } catch (IOException e) { + log.error("Error parsing the buffered notification, skipping {}", e); } } - return true; + return clusterMaps; + } + + private Either<List<String>, Integer> getBufferedNotifications() { + log.info("Check if notifications are buffered"); + BufferNotificationComponent bufferNotificationComponent = new BufferNotificationComponent(); + ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent(); + String clusterId = clusterDetailsComponent.getClusterId(Thread.currentThread().getId()); + List<String> bufferedNotifications = bufferNotificationComponent.getBufferedNotification(clusterId); + if (bufferedNotifications == null || bufferedNotifications.isEmpty()) { + return Either.right(404); + } else { + return Either.left(bufferedNotifications); + } + } /** * cleanup resources. */ private void cleanup() { - log.debug("cleaning up database and killing child thread"); + log.info("cleaning up database and killing child thread"); + List<String> childStatus = new ArrayList<>(); + childStatus.add(Long.toString(Thread.currentThread().getId())); + childStatus.add("done"); + try { + childStatusUpdate.put(childStatus); + } catch (InterruptedException e) { + log.debug("InterruptedException during cleanup{}", e); + Thread.currentThread().interrupt(); + + } ClusterDetailsRepository clusterDetailsRepository = BeanUtil.getBean(ClusterDetailsRepository.class); clusterDetailsRepository.deleteByChildThreadId(threadId.getChildThreadId()); - log.debug("Child thread :{} {}", Thread.currentThread().getId(), "completed"); + log.info("Child thread :{} {}", Thread.currentThread().getId(), "completed"); MDC.remove("logFileName"); } @@ -203,11 +339,11 @@ public class ChildThread implements Runnable { /** * Buffer Notification. */ - public List<FapServiceList> bufferNotification() { + public List<Map<CellPciPair, ArrayList<CellPciPair>>> bufferNotification() { // Processing Buffered notifications - List<FapServiceList> fapServiceLists = new ArrayList<>(); + List<Map<CellPciPair, ArrayList<CellPciPair>>> clusterMapList = new ArrayList<>(); Configuration config = Configuration.getInstance(); @@ -234,12 +370,49 @@ public class ChildThread implements Runnable { log.debug("Timer has run for seconds {}", difference); if (!queue.isEmpty()) { - FapServiceList fapService; - fapService = queue.poll(); - fapServiceLists.add(fapService); + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap; + clusterMap = queue.poll(); + clusterMapList.add(clusterMap); } + } - return fapServiceLists; + return clusterMapList; } + public Either<List<AnrInput>, Integer> checkAnrTrigger(List<String> cellidList) { + + List<AnrInput> anrInputList = new ArrayList<>(); + Configuration configuration = Configuration.getInstance(); + int poorThreshold = configuration.getPoorThreshold(); + List<HoDetails> hoDetailsList; + Either<List<HoDetails>, Integer> response; + for (String cellId : cellidList) { + response = hoMetricsComponent.getHoMetrics(cellId); + List<String> removeableNeighbors = new ArrayList<>(); + if (response.isLeft()) { + hoDetailsList = response.left().value(); + for (HoDetails hoDetail : hoDetailsList) { + if (hoDetail.getSuccessRate() < poorThreshold) { + removeableNeighbors.add(hoDetail.getDstCellId()); + } + } + } else { + if (response.right().value() == 400) { + log.error("Error in getting HO details from db"); + return Either.right(500); + } else { + log.info("no HO metrics found"); + } + } + + if (!removeableNeighbors.isEmpty()) { + AnrInput anrInput = new AnrInput(cellId, removeableNeighbors); + anrInputList.add(anrInput); + } + } + if (!anrInputList.isEmpty()) { + return Either.left(anrInputList); + } + return Either.right(404); + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java index 89cafd6..178d728 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java @@ -27,8 +27,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.UUID; import org.onap.dcaegen2.services.sonhms.ConfigPolicy; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository; +import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; +import org.onap.dcaegen2.services.sonhms.entity.SonRequests; +import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellConfig; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.Common; @@ -36,22 +43,71 @@ import org.onap.dcaegen2.services.sonhms.model.Configurations; import org.onap.dcaegen2.services.sonhms.model.Data; import org.onap.dcaegen2.services.sonhms.model.FapService; import org.onap.dcaegen2.services.sonhms.model.Lte; +import org.onap.dcaegen2.services.sonhms.model.LteCell; +import org.onap.dcaegen2.services.sonhms.model.NeighborListInUse; import org.onap.dcaegen2.services.sonhms.model.Payload; import org.onap.dcaegen2.services.sonhms.model.PolicyNotification; import org.onap.dcaegen2.services.sonhms.model.Ran; import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte; +import org.onap.dcaegen2.services.sonhms.restclient.AnrSolutions; +import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; +import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; +import org.onap.dcaegen2.services.sonhms.restclient.Solutions; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; public class ChildThreadUtils { - + private static final Logger log = org.slf4j.LoggerFactory.getLogger(ChildThreadUtils.class); - ConfigPolicy configPolicy; - - public ChildThreadUtils(ConfigPolicy configPolicy) { + private ConfigPolicy configPolicy; + private PnfUtils pnfUtils; + private PolicyDmaapClient policyDmaapClient; + + /** + * Parameterized constructor. + */ + public ChildThreadUtils(ConfigPolicy configPolicy, PnfUtils pnfUtils, PolicyDmaapClient policyDmaapClient) { this.configPolicy = configPolicy; + this.pnfUtils = pnfUtils; + this.policyDmaapClient = policyDmaapClient; } - - + + /** + * Save request. + */ + public void saveRequest(String transactionId, long childThreadId) { + SonRequestsRepository sonRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class); + + SonRequests sonRequest = new SonRequests(); + sonRequest.setTransactionId(transactionId); + sonRequest.setChildThreadId(childThreadId); + sonRequestsRepository.save(sonRequest); + } + + /** + * Determines whether to trigger Oof or wait for notifications. + */ + public Boolean triggerOrWait(Map<String, ArrayList<Integer>> collisionConfusionResult) { + // determine collision or confusion + + Configuration configuration = Configuration.getInstance(); + int collisionSum = 0; + int confusionSum = 0; + + for (Map.Entry<String, ArrayList<Integer>> entry : collisionConfusionResult.entrySet()) { + + ArrayList<Integer> arr; + arr = entry.getValue(); + // check for 0 collision and confusion + if (!arr.isEmpty()) { + collisionSum = collisionSum + arr.get(0); + confusionSum = confusionSum + arr.get(1); + } + } + return ((collisionSum >= configuration.getMinCollision()) && (confusionSum >= configuration.getMinConfusion())); + + } + /** * get policy notification string from oof result. * @@ -63,27 +119,33 @@ public class ChildThreadUtils { String cellId = cellPciPair.getCellId(); int pci = cellPciPair.getPhysicalCellId(); Configurations configuration = new Configurations(new Data(new FapService(cellId, - new X0005b9Lte(pci, pnfName), new CellConfig(new Lte(new Ran(new Common(cellId))))))); + new X0005b9Lte(pci, pnfName), new CellConfig(new Lte(new Ran(new Common(cellId), null)))))); configurations.add(configuration); } Payload payload = new Payload(configurations); ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); String payloadString = ""; try { payloadString = mapper.writeValueAsString(payload); } catch (JsonProcessingException e) { log.debug("JSON processing exception: {}", e); } - - String closedLoopControlName = (String) configPolicy.getConfig().get("PCI_MODCONFIG_POLICY_NAME"); - PolicyNotification policyNotification = new PolicyNotification(closedLoopControlName, - requestId, alarmStartTime, pnfName); - + + String closedLoopControlName = "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459"; + try { + closedLoopControlName = (String) configPolicy.getConfig().get("PCI_MODCONFIG_POLICY_NAME"); + } catch (NullPointerException e) { + log.error("Config policy not found, Using default"); + } + + PolicyNotification policyNotification = new PolicyNotification(closedLoopControlName, requestId, alarmStartTime, + pnfName); + policyNotification.setClosedLoopControlName(closedLoopControlName); policyNotification.setPayload(payloadString); - mapper.setSerializationInclusion(Include.NON_NULL); String notification = ""; try { notification = mapper.writeValueAsString(policyNotification); @@ -92,5 +154,77 @@ public class ChildThreadUtils { } return notification; } - + + /** + * Sends Dmaap notification to Policy. + * + * @throws ConfigDbNotFoundException + * when config db is unreachable + */ + public void sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException { + + if (log.isDebugEnabled()) { + log.debug(async.toString()); + } + + Solutions solutions; + solutions = async.getSolutions(); + + if (!solutions.getPciSolutions().isEmpty()) { + Map<String, List<CellPciPair>> pnfs = pnfUtils.getPnfs(solutions); + + for (Map.Entry<String, List<CellPciPair>> entry : pnfs.entrySet()) { + String pnfName = entry.getKey(); + List<CellPciPair> cellPciPairs = entry.getValue(); + + String notification = getNotificationString(pnfName, cellPciPairs, UUID.randomUUID().toString(), + System.currentTimeMillis()); + log.debug("Policy Notification: {}", notification); + PolicyDmaapClient policy = new PolicyDmaapClient(); + boolean status = policy.sendNotificationToPolicy(notification); + log.debug("sent Message: {}", status); + if (status) { + log.debug("Message sent to policy"); + } else { + log.debug("Sending notification to policy failed"); + } + + } + } + if (!solutions.getAnrSolutions().isEmpty()) { + + List<Configurations> configurations = new ArrayList<>(); + for (AnrSolutions anrSolution : solutions.getAnrSolutions()) { + String cellId = anrSolution.getCellId(); + List<LteCell> lteCellList = new ArrayList<>(); + for (String removeableNeighbor : anrSolution.getRemoveableNeighbors()) { + LteCell lteCell = new LteCell(); + lteCell.setBlacklisted("true"); + lteCell.setPlmnId(solutions.getNetworkId()); + lteCell.setCid(removeableNeighbor); + int pci = SdnrRestClient.getPci(cellId); + String pnfName = SdnrRestClient.getPnfName(cellId); + lteCell.setPhyCellId(pci); + lteCell.setPnfName(pnfName); + lteCellList.add(lteCell); + } + Configurations configuration = new Configurations( + new Data(new FapService(cellId, null, new CellConfig(new Lte(new Ran(new Common(cellId), + new NeighborListInUse(null, lteCellList, String.valueOf(lteCellList.size())))))))); + configurations.add(configuration); + } + Payload payload = new Payload(configurations); + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + String anrUpdateString = null; + try { + anrUpdateString = mapper.writeValueAsString(payload); + } catch (JsonProcessingException e) { + log.error("Exception in writing anrupdate string", e); + } + Boolean result = policyDmaapClient.sendNotificationToPolicy(anrUpdateString); + log.debug("send notification to policy result {} ", result); + } + } + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ClusterFormation.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ClusterFormation.java deleted file mode 100644 index e248a59..0000000 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ClusterFormation.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * son-handler - * ================================================================================ - * Copyright (C) 2019 Wipro Limited. - * ============================================================================== - * 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. - * ============LICENSE_END========================================================= - * - *******************************************************************************/ - -package org.onap.dcaegen2.services.sonhms.child; - -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Map; -import java.util.Properties; -import java.util.UUID; -import java.util.concurrent.BlockingQueue; - -import org.onap.dcaegen2.services.sonhms.ConfigPolicy; -import org.onap.dcaegen2.services.sonhms.Configuration; -import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository; -import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; -import org.onap.dcaegen2.services.sonhms.model.FapServiceList; -import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; -import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils; -import org.slf4j.Logger; - - -public class ClusterFormation { - - private static final Logger log = org.slf4j.LoggerFactory.getLogger(ClusterFormation.class); - private BlockingQueue<FapServiceList> queue; - private ClusterUtils clusterUtils; - private Detection detect; - Properties confProp; - ClusterDetails details = new ClusterDetails(); - - public ClusterFormation() { - this.detect = new Detection(); - } - - /** - * parameterized constructor. - * - */ - public ClusterFormation(BlockingQueue<FapServiceList> queue) { - super(); - this.queue = queue; - this.detect = new Detection(); - this.clusterUtils = new ClusterUtils(); - } - - /** - * Determines whether to trigger Oof or wait for notifications. - */ - public Boolean triggerOrWait(Map<String, ArrayList<Integer>> collisionConfusionResult) { - // determine collision or confusion - - Configuration configuration = Configuration.getInstance(); - int collisionSum = 0; - int confusionSum = 0; - - for (Map.Entry<String, ArrayList<Integer>> entry : collisionConfusionResult.entrySet()) { - - ArrayList<Integer> arr; - arr = entry.getValue(); - // check for 0 collision and confusion - if (!arr.isEmpty()) { - collisionSum = collisionSum + arr.get(0); - confusionSum = confusionSum + arr.get(1); - } - } - return ((collisionSum >= configuration.getMinCollision()) && (confusionSum >= configuration.getMinConfusion())); - - } - - /** - * Waits for notifications. - */ - public Map<String, ArrayList<Integer>> waitForNotification(Map<String, ArrayList<Integer>> collisionConfusionResult, - Graph cluster) { - - FapServiceList newNotification; - ConfigPolicy config = ConfigPolicy.getInstance(); - int timer = 60; - try { - timer = (int) config.getConfig().get("PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS"); - } catch (NullPointerException e) { - log.debug("Policy config not available. Using default timeout - 60 seconds"); - } - - Timestamp currentTime = new Timestamp(System.currentTimeMillis()); - log.debug("Current Time {}", currentTime); - - Timestamp laterTime = new Timestamp(System.currentTimeMillis()); - log.debug("LaterTime {}", laterTime); - - long difference = laterTime.getTime() - currentTime.getTime(); - - int flag = 0; - - while (difference < (timer * 1000)) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - log.error("Interrupted Exception is {}", e); - Thread.currentThread().interrupt(); - } - - laterTime = new Timestamp(System.currentTimeMillis()); - difference = laterTime.getTime() - currentTime.getTime(); - - if ((difference < (timer * 1000)) && (!queue.isEmpty())) { - newNotification = queue.poll(); - cluster = clusterUtils.modifyCluster(cluster, newNotification); - - // update cluster in DB - String cellPciNeighbourString = cluster.getPciNeighbourJson(); - UUID clusterId = cluster.getGraphId(); - ClusterDetailsRepository clusterDetailsRepository = BeanUtil.getBean(ClusterDetailsRepository.class); - clusterDetailsRepository.updateCluster(cellPciNeighbourString, clusterId.toString()); - flag++; - - } - } - if (flag != 0) { - return detect.detectCollisionConfusion(cluster); - - } - return collisionConfusionResult; - } - -} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/Detection.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/Detection.java index 2634d9a..bdfa8f6 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/Detection.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/Detection.java @@ -28,7 +28,6 @@ import java.util.Map; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.slf4j.Logger; - public class Detection { private static final Logger log = org.slf4j.LoggerFactory.getLogger(Detection.class); @@ -37,9 +36,9 @@ public class Detection { * Returns a map with key as cellid and its value is a list of its collision and * confusion. */ - public Map<String, ArrayList<Integer>> detectCollisionConfusion(Graph cluster) { + log.info("Finding collision and confusion count"); Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = cluster.getCellPciNeighbourMap(); HashMap<String, ArrayList<Integer>> hash = new HashMap<>(); @@ -79,7 +78,7 @@ public class Detection { hash.put(cellId, counts); } - log.debug("collison and confusion map {}", hash); + log.info("collison and confusion map {}", hash); return hash; } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/Graph.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/Graph.java index a76d0dd..7d1e898 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/Graph.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/Graph.java @@ -47,11 +47,32 @@ public class Graph { // symbol table: key = string vertex, value = set of neighboring vertices private Map<CellPciPair, ArrayList<CellPciPair>> cellPciNeighbourMap; private UUID graphId; + + private String networkId; + + public String getNetworkId() { + return networkId; + } + + public void setNetworkId(String networkId) { + this.networkId = networkId; + } + + + private Map<String, ArrayList<Integer>> collisionConfusionMap; + + public Map<String, ArrayList<Integer>> getCollisionConfusionMap() { + return collisionConfusionMap; + } + + public void setCollisionConfusionMap(Map<String, ArrayList<Integer>> collisionConfusionMap) { + this.collisionConfusionMap = collisionConfusionMap; + } /** * Parameterized constructor. */ - public Graph(String clusterInfo) { + public Graph(String clusterInfo) { JSONArray cells = new JSONArray(clusterInfo); Map<CellPciPair, ArrayList<CellPciPair>> cellMap = new HashMap<>(); @@ -62,9 +83,10 @@ public class Graph { ArrayList<CellPciPair> neighbours = new ArrayList<>(); try { neighbours = mapper.readValue(cell.getString("neighbours"), - new TypeReference<ArrayList<CellPciPair>>() { }); + new TypeReference<ArrayList<CellPciPair>>() { + }); } catch (JSONException | IOException e) { - log.debug("Error parsing json: {}", e); + log.error("Error parsing json: {}", e); } cellMap.put(cellPciPair, neighbours); @@ -195,7 +217,7 @@ public class Graph { try { pciNeighbourJson = mapper.writeValueAsString(cells); } catch (JsonProcessingException e) { - log.debug("Error while processing json: {}", e); + log.error("Error while processing json: {}", e); } return pciNeighbourJson; } @@ -211,31 +233,10 @@ public class Graph { @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } if (obj == null) { return false; } - if (getClass() != obj.getClass()) { - return false; - } - Graph other = (Graph) obj; - if (cellPciNeighbourMap == null) { - if (other.cellPciNeighbourMap != null) { - return false; - } - } else if (!cellPciNeighbourMap.equals(other.cellPciNeighbourMap)) { - return false; - } - if (graphId == null) { - if (other.graphId != null) { - return false; - } - } else if (!graphId.equals(other.graphId)) { - return false; - } - return true; + return (this.hashCode() == obj.hashCode()); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java index 30fd0b9..590a938 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java @@ -31,9 +31,9 @@ import org.onap.dcaegen2.services.sonhms.dao.CellInfoRepository; import org.onap.dcaegen2.services.sonhms.entity.CellInfo; import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.restclient.PciSolutions; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; -import org.onap.dcaegen2.services.sonhms.restclient.Solution; -import org.onap.dcaegen2.services.sonhms.restclient.SonSolution; +import org.onap.dcaegen2.services.sonhms.restclient.Solutions; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; @@ -44,13 +44,11 @@ public class PnfUtils { * get pnfs. * */ - public Map<String, List<CellPciPair>> getPnfs(List<Solution> solutions) throws ConfigDbNotFoundException { + public Map<String, List<CellPciPair>> getPnfs(Solutions solutions) throws ConfigDbNotFoundException { Map<String, List<CellPciPair>> pnfs = new HashMap<>(); - - for (Solution solution : solutions) { - List<SonSolution> pciSolutions = solution.getPciSolutions(); - for (SonSolution pciSolution : pciSolutions) { + List<PciSolutions> pciSolutions = solutions.getPciSolutions(); + for (PciSolutions pciSolution : pciSolutions) { String cellId = pciSolution.getCellId(); int pci = pciSolution.getPci(); @@ -70,7 +68,6 @@ public class PnfUtils { cellPciPairs.add(new CellPciPair(cellId, pci)); pnfs.put(pnfName, cellPciPairs); } - } } return pnfs; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java index ae40dbf..a92617c 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/StateOof.java @@ -22,31 +22,19 @@ package org.onap.dcaegen2.services.sonhms.child; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.UUID; import java.util.concurrent.BlockingQueue; -import org.onap.dcaegen2.services.sonhms.ConfigPolicy; import org.onap.dcaegen2.services.sonhms.Configuration; -import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository; -import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; -import org.onap.dcaegen2.services.sonhms.entity.PciRequests; -import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException; -import org.onap.dcaegen2.services.sonhms.model.CellPciPair; -import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; +import org.onap.dcaegen2.services.sonhms.model.AnrInput; import org.onap.dcaegen2.services.sonhms.restclient.OofRestClient; -import org.onap.dcaegen2.services.sonhms.restclient.Solution; -import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.slf4j.Logger; public class StateOof { private static final Logger log = org.slf4j.LoggerFactory.getLogger(StateOof.class); private BlockingQueue<List<String>> childStatusUpdate; - public StateOof() { } @@ -61,33 +49,14 @@ public class StateOof { } /** - * Triggers OOF. + * Triggers OOF for pci. * @throws OofNotFoundException when trigger oof fails */ - public void triggerOof(Map<String, ArrayList<Integer>> result, - String networkId) throws OofNotFoundException, InterruptedException { - // check for 0 collision and 0 confusion - ArrayList<String> cellidList = new ArrayList<>(); - ArrayList<String> cellIds = new ArrayList<>(); - - for (Map.Entry<String, ArrayList<Integer>> entry : result.entrySet()) { - String key = entry.getKey(); - ArrayList<Integer> arr; - arr = entry.getValue(); - if (!arr.isEmpty()) { - Set<Integer> set = new HashSet<>(arr); - if (((set.size() == 1) && !set.contains(0)) || (set.size() != 1)) { - cellIds.add(key); - - } - } - - } - - for (String cell : cellIds) { - log.debug("cellidList entries: {}", cell); - cellidList.add(cell); - } + public UUID triggerOof(List<String> cellidList, + String networkId, List<AnrInput> anrInputList) throws OofNotFoundException, InterruptedException { + + log.info("Triggering oof"); + log.debug("the cells triggering the oof are {}", cellidList); UUID transactionId = UUID.randomUUID(); @@ -97,8 +66,8 @@ public class StateOof { List<String> optimizers = config.getOptimizers(); String oofResponse = OofRestClient.queryOof(numSolutions, transactionId.toString(), "create", cellidList, - networkId, optimizers); - log.debug("Synchronous Response {}", oofResponse); + networkId, optimizers, anrInputList); + log.info("Synchronous Response {}", oofResponse); List<String> childStatus = new ArrayList<>(); childStatus.add(Long.toString(Thread.currentThread().getId())); @@ -110,83 +79,9 @@ public class StateOof { Thread.currentThread().interrupt(); } - - // Store Request details in Database - - PciRequests pciRequest = new PciRequests(); - - long childThreadId = Thread.currentThread().getId(); - pciRequest.setTransactionId(transactionId.toString()); - pciRequest.setChildThreadId(childThreadId); - SonRequestsRepository pciRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class); - pciRequestsRepository.save(pciRequest); - - while (!ChildThread.getResponseMap().containsKey(childThreadId)) { - Thread.sleep(100); - } - - AsyncResponseBody asynResponseBody = ChildThread.getResponseMap().get(childThreadId); - - try { - sendToPolicy(asynResponseBody); - } catch (ConfigDbNotFoundException e1) { - log.debug("Config DB is unreachable: {}", e1); - } - - pciRequestsRepository = BeanUtil.getBean(SonRequestsRepository.class); - pciRequestsRepository.deleteByChildThreadId(childThreadId); - - childStatus = new ArrayList<>(); - childStatus.add(Long.toString(Thread.currentThread().getId())); - childStatus.add("success"); - try { - childStatusUpdate.put(childStatus); - } catch (InterruptedException e) { - log.debug("InterruptedException {}", e); - Thread.currentThread().interrupt(); - - } - - } - - /** - * Sends Dmaap notification to Policy. - * - * @throws ConfigDbNotFoundException - * when config db is unreachable - */ - private void sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException { - - if (log.isDebugEnabled()) { - log.debug(async.toString()); - } - - List<Solution> solutions; - solutions = async.getSolutions(); - PnfUtils pnfUtils = new PnfUtils(); - Map<String, List<CellPciPair>> pnfs = pnfUtils.getPnfs(solutions); - - for (Map.Entry<String, List<CellPciPair>> entry : pnfs.entrySet()) { - String pnfName = entry.getKey(); - List<CellPciPair> cellPciPairs = entry.getValue(); - - ChildThreadUtils childThreadUtils = new ChildThreadUtils(ConfigPolicy.getInstance()); - String notification = childThreadUtils.getNotificationString(pnfName, cellPciPairs, - UUID.randomUUID().toString(), System.currentTimeMillis()); - log.debug("Policy Notification: {}", notification); - PolicyDmaapClient policy = new PolicyDmaapClient(); - boolean status = policy.sendNotificationToPolicy(notification); - log.debug("sent Message: {}", status); - if (status) { - log.debug("Message sent to policy"); - } else { - log.debug("Sending notification to policy failed"); - } - - } + return transactionId; } - } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java b/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java index ab6d40d..76e7929 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/controller/ConfigFetchFromCbs.java @@ -21,16 +21,26 @@ package org.onap.dcaegen2.services.sonhms.controller; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import java.lang.reflect.Type; import java.util.List; import java.util.Map; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClientFactory; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests; +import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import org.onap.dcaegen2.services.sonhms.ConfigPolicy; import org.onap.dcaegen2.services.sonhms.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + public class ConfigFetchFromCbs { private static Logger log = LoggerFactory.getLogger(ConfigFetchFromCbs.class); @@ -38,72 +48,102 @@ public class ConfigFetchFromCbs { /** * Gets app config from CBS. */ - @SuppressWarnings("unchecked") - public void getAppConfig() { + public void getAppConfig() { // Generate RequestID and InvocationID which will be used when logging and in // HTTP requests - log.debug("getAppconfig start .."); + log.info("getAppconfig start .."); RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); - log.debug("fiagnostic context : {}",diagnosticContext.toString()); // Read necessary properties from the environment final EnvProperties env = EnvProperties.fromEnvironment(); - log.debug("environments {}",env.toString()); - Configuration configuration = Configuration.getInstance(); + log.debug("environments {}",env); + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); // Create the client and use it to get the configuration - CbsClientFactory.createCbsClient(env).flatMap(cbsClient -> cbsClient.get(diagnosticContext)) + final CbsRequest request = CbsRequests.getAll(diagnosticContext); + CbsClientFactory.createCbsClient(env).flatMap(cbsClient -> cbsClient.get(request)) .subscribe(jsonObject -> { - log.debug("configuration from CBS {}", jsonObject.toString()); - final Map<String,Object> streamsSubscribes=(Map<String, Object>) jsonObject.get("streams_subscribes"); - final Map<String,Object> streamsPublishes=(Map<String, Object>) jsonObject.get("streams_publishes"); - final int pgPort = jsonObject.get("postgres.port").getAsInt(); - final int pollingInterval=jsonObject.get("sonhandler.pollingInterval").getAsInt(); - final String pgPassword = jsonObject.get("postgres.password").getAsString(); - final int numSolutions=jsonObject.get("sonhandler.numSolutions").getAsInt(); - final int minConfusion = jsonObject.get("sonhandler.minConfusion").getAsInt(); - final int maximumClusters =jsonObject.get("sonhandler.maximumClusters").getAsInt(); - final int minCollision = jsonObject.get("sonhandler.minCollision").getAsInt(); - final String sourceId = jsonObject.get("sonhandler.sourceId").getAsString(); - final String pgUsername = jsonObject.get("postgres.username").getAsString(); - final String pgHost = jsonObject.get("postgres.host").getAsString(); - final List<String> dmaapServers = (List<String>) jsonObject.get("sonhandler.dmaap.server"); - final String cg=jsonObject.get("sonhandler.cg").getAsString(); - final int bufferTime=jsonObject.get("sonhandler.bufferTime").getAsInt(); - final String cid =jsonObject.get("sonhandler.cid").getAsString(); - final String configDbService=jsonObject.get("sonhandler.configDb.service").getAsString(); - final String callbackUrl=jsonObject.get("sonhandler.callbackUrl").getAsString(); - final List<String> optimizers = (List<String>) jsonObject.get("sonhandler.optimizers"); - final String oofService=jsonObject.get("sonhandler.oof.service").getAsString(); - final int pollingTimeout=jsonObject.get("sonhandler.pollingTimeout").getAsInt(); - - configuration.setStreamsSubscribes(streamsSubscribes); - configuration.setStreamsPublishes(streamsPublishes); - configuration.setPgPassword(pgPassword); - configuration.setPgPort(pgPort); - configuration.setPollingInterval(pollingInterval); - configuration.setNumSolutions(numSolutions); - configuration.setMinCollision(minCollision); - configuration.setMinConfusion(minConfusion); - configuration.setMaximumClusters(maximumClusters); - configuration.setPgHost(pgHost); - configuration.setPgUsername(pgUsername); - configuration.setSourceId(sourceId); - configuration.setDmaapServers(dmaapServers); - configuration.setCg(cg); - configuration.setCid(cid); - configuration.setBufferTime(bufferTime); - configuration.setConfigDbService(configDbService); - configuration.setCallbackUrl(callbackUrl); - configuration.setOptimizers(optimizers); - configuration.setOofService(oofService); - configuration.setPollingTimeout(pollingTimeout); + log.debug("configuration from CBS {}", jsonObject); + JsonObject config = jsonObject.getAsJsonObject("config"); + + updateConfigurationFromJsonObject(config); - log.debug("configuration {}", configuration); - }, throwable -> { - log.warn("Ooops", throwable); - }); + Type mapType = new TypeToken<Map<String, Object>>() {}.getType(); + JsonObject policyJson = jsonObject.getAsJsonObject("policy"); + Map<String,Object> policy = new Gson().fromJson(policyJson, mapType); + configPolicy.setConfig(policy); + }, throwable -> log.warn("Ooops", throwable)) ; + + } + + private void updateConfigurationFromJsonObject(JsonObject jsonObject) { + + log.info("Updating configuration from CBS"); + Configuration configuration = Configuration.getInstance(); + log.debug("configuration from CBS {}", jsonObject); + Type mapType = new TypeToken<Map<String, Object>>() {}.getType(); + + JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); + Map<String, Object> streamsSubscribes = new Gson().fromJson(subscribes, mapType); + + JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); + Map<String, Object> streamsPublishes = new Gson().fromJson(publishes, mapType); + + int pgPort = jsonObject.get("postgres.port").getAsInt(); + int pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt(); + String pgPassword = jsonObject.get("postgres.password").getAsString(); + int numSolutions = jsonObject.get("sonhandler.numSolutions").getAsInt(); + int minConfusion = jsonObject.get("sonhandler.minConfusion").getAsInt(); + int maximumClusters = jsonObject.get("sonhandler.maximumClusters").getAsInt(); + int minCollision = jsonObject.get("sonhandler.minCollision").getAsInt(); + String sourceId = jsonObject.get("sonhandler.sourceId").getAsString(); + String pgUsername = jsonObject.get("postgres.username").getAsString(); + String pgHost = jsonObject.get("postgres.host").getAsString(); + + JsonArray servers = jsonObject.getAsJsonArray("sonhandler.dmaap.server"); + Type listType = new TypeToken<List<String>>() {}.getType(); + List<String> dmaapServers = new Gson().fromJson(servers, listType); + + String cg = jsonObject.get("sonhandler.cg").getAsString(); + int bufferTime = jsonObject.get("sonhandler.bufferTime").getAsInt(); + String cid = jsonObject.get("sonhandler.cid").getAsString(); + String configDbService = jsonObject.get("sonhandler.configDb.service").getAsString(); + + String callbackUrl = "http://" + System.getenv("HOSTNAME") + ":8080/callbackUrl"; + + JsonArray optimizersJson = jsonObject.getAsJsonArray("sonhandler.optimizers"); + List<String> optimizers = new Gson().fromJson(optimizersJson, listType); + + String oofService = jsonObject.get("sonhandler.oof.service").getAsString(); + int pollingTimeout = jsonObject.get("sonhandler.pollingTimeout").getAsInt(); + + int badThreshold = jsonObject.get("sonhandler.badThreshold").getAsInt(); + int poorThreshold = jsonObject.get("sonhandler.poorThreshold").getAsInt(); + + configuration.setStreamsSubscribes(streamsSubscribes); + configuration.setStreamsPublishes(streamsPublishes); + configuration.setPgPassword(pgPassword); + configuration.setPgPort(pgPort); + configuration.setPollingInterval(pollingInterval); + configuration.setNumSolutions(numSolutions); + configuration.setMinCollision(minCollision); + configuration.setMinConfusion(minConfusion); + configuration.setMaximumClusters(maximumClusters); + configuration.setPgHost(pgHost); + configuration.setPgUsername(pgUsername); + configuration.setSourceId(sourceId); + configuration.setDmaapServers(dmaapServers); + configuration.setCg(cg); + configuration.setCid(cid); + configuration.setBufferTime(bufferTime); + configuration.setConfigDbService(configDbService); + configuration.setCallbackUrl(callbackUrl); + configuration.setOptimizers(optimizers); + configuration.setOofService(oofService); + configuration.setPollingTimeout(pollingTimeout); + configuration.setBadThreshold(badThreshold); + configuration.setPoorThreshold(poorThreshold); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/HandOverMetricsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/HandOverMetricsRepository.java new file mode 100644 index 0000000..efc1e19 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/HandOverMetricsRepository.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.dao; + +import org.onap.dcaegen2.services.sonhms.entity.HandOverMetrics; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface HandOverMetricsRepository extends CrudRepository<HandOverMetrics, String> { + + @Query(nativeQuery=true, + value="SELECT ho_details FROM handover_metrics WHERE src_cell_id=?1") + public String getHandOverMetrics(String srcCellId); + + @Query(nativeQuery=true, + value="UPDATE handover_metrics SET ho_details=?1 where src_cell_id=?2") + public void updateHoMetrics(String hoDetails, String srcCellId); +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/PerformanceNotificationsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/PerformanceNotificationsRepository.java new file mode 100644 index 0000000..c83956f --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/PerformanceNotificationsRepository.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.dao; + +import org.onap.dcaegen2.services.sonhms.entity.PerformanceNotifications; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PerformanceNotificationsRepository extends CrudRepository<PerformanceNotifications, String> { + + @Query(nativeQuery = true, + value = "DELETE FROM performance_notifications " + + "WHERE notification = ( SELECT notification FROM performance_notifications ORDER BY " + + "created_at FOR UPDATE SKIP LOCKED LIMIT 1 ) RETURNING notification;") + + public String getPerformanceNotificationFromQueue(); + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/SonRequestsRepository.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/SonRequestsRepository.java index 4bf9dd6..63f7c45 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dao/SonRequestsRepository.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dao/SonRequestsRepository.java @@ -21,7 +21,7 @@ package org.onap.dcaegen2.services.sonhms.dao; -import org.onap.dcaegen2.services.sonhms.entity.PciRequests; +import org.onap.dcaegen2.services.sonhms.entity.SonRequests; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; @@ -31,10 +31,10 @@ import org.springframework.transaction.annotation.Transactional; @Repository @Transactional -public interface SonRequestsRepository extends CrudRepository<PciRequests, String> { +public interface SonRequestsRepository extends CrudRepository<SonRequests, String> { @Query(nativeQuery = true, value = "SELECT child_thread_id FROM pci_requests WHERE transaction_id = ?1") - public long getChildThreadMapping(String transactionId); + public Long getChildThreadMapping(String transactionId); @Modifying @Query(nativeQuery = true, value = "DELETE FROM pci_requests WHERE child_thread_id = ?1") diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java index 91e7117..d3ca349 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClient.java @@ -23,102 +23,97 @@ package org.onap.dcaegen2.services.sonhms.dmaap; import com.att.nsa.cambria.client.CambriaConsumer; -import org.onap.dcaegen2.services.sonhms.Configuration; -import org.onap.dcaegen2.services.sonhms.NewNotification; -import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; -import org.onap.dcaegen2.services.sonhms.entity.DmaapNotifications; -import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; - - import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import javax.annotation.PostConstruct; + +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class DmaapClient { - @Autowired - private DmaapNotificationsRepository dmaapNotificationsRepository; - private Configuration configuration; - private static Logger log = LoggerFactory.getLogger(DmaapClient.class); - - @Autowired - private NewNotification newNotification; - private DmaapUtils dmaapUtils; - - public class NotificationCallback { - DmaapClient dmaapClient; - - public NotificationCallback(DmaapClient dmaapClient) { - this.dmaapClient = dmaapClient; - } - - public void activateCallBack(String msg) { - handleNotification(msg); - } - - private void handleNotification(String msg) { - DmaapNotifications dmaapNotification = new DmaapNotifications(); - dmaapNotification.setNotification(msg); - if (log.isDebugEnabled()) { - log.debug(dmaapNotification.toString()); - } - dmaapNotificationsRepository.save(dmaapNotification); - newNotification.setNewNotif(true); - } - } - - /** - * init dmaap client. - */ - public void initClient() { - log.debug("initializing client"); - configuration = Configuration.getInstance(); - if (log.isDebugEnabled()) { - log.debug(configuration.toString()); - } - - startClient(); - } - - - /** - * start dmaap client. - */ - @SuppressWarnings("unchecked") - private synchronized void startClient() { - - Map<String,Object> streamSubscribes= Configuration.getInstance().getStreamsSubscribes(); - String sdnrTopicUrl =((Map<String,String>)((Map<String,Object>)streamSubscribes.get("nbr_list_change_topic")).get("dmaap_info")).get("topic_url"); - String[] sdnrTopicSplit=sdnrTopicUrl.split("\\/"); - String sdnrTopic=sdnrTopicSplit[sdnrTopicSplit.length-1]; - ScheduledExecutorService executorPool; - CambriaConsumer cambriaConsumer = null; - - cambriaConsumer = dmaapUtils.buildConsumer(configuration, sdnrTopic ); - /* - * cambriaConsumer = new ConsumerBuilder() - * .authenticatedBy(configuration.getPcimsApiKey(), - * configuration.getPcimsSecretKey()) .knownAs(configuration.getCg(), - * configuration.getCid()).onTopic(configuration.getSdnrTopic()) - * .usingHosts(configuration.getServers()).withSocketTimeout(configuration. - * getPollingTimeout() * 1000) .build(); - */ - - // create notification consumers for SNDR and policy - NotificationConsumer notificationConsumer = new NotificationConsumer(cambriaConsumer, - new NotificationCallback(this)); - - // start notification consumer threads - executorPool = Executors.newScheduledThreadPool(10); - executorPool.scheduleAtFixedRate(notificationConsumer, 0, configuration.getPollingInterval(), TimeUnit.SECONDS); - - } - + private Configuration configuration; + private static Logger log = LoggerFactory.getLogger(DmaapClient.class); + + private DmaapUtils dmaapUtils; + + /** + * init dmaap client. + */ + @PostConstruct + public void initClient() { + log.debug("initializing client"); + dmaapUtils = new DmaapUtils(); + configuration = Configuration.getInstance(); + if (log.isDebugEnabled()) { + log.debug(configuration.toString()); + } + + startClient(); + } + + /** + * start dmaap client. + */ + @SuppressWarnings("unchecked") + private synchronized void startClient() { + + Map<String, Object> streamSubscribes = Configuration.getInstance().getStreamsSubscribes(); + String sdnrTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes + .get("nbr_list_change_topic")).get("dmaap_info")).get("topic_url"); + String[] sdnrTopicSplit = sdnrTopicUrl.split("\\/"); + String sdnrTopic = sdnrTopicSplit[sdnrTopicSplit.length - 1]; + log.debug("sdnr topic : {}", sdnrTopic); + String fmTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes + .get("fault_management_topic")).get("dmaap_info")).get("topic_url"); + String[] fmTopicSplit = fmTopicUrl.split("\\/"); + String fmTopic = fmTopicSplit[sdnrTopicSplit.length - 1]; + log.debug("fm topic : {}", fmTopic); + String pmTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes + .get("performance_management_topic")).get("dmaap_info")).get("topic_url"); + String[] pmTopicSplit = pmTopicUrl.split("\\/"); + String pmTopic = pmTopicSplit[sdnrTopicSplit.length - 1]; + log.debug("pm topic : {}", pmTopic); + CambriaConsumer sdnrNotifCambriaConsumer = null; + CambriaConsumer fmNotifCambriaConsumer = null; + CambriaConsumer pmNotifCambriaConsumer = null; + + sdnrNotifCambriaConsumer = dmaapUtils.buildConsumer(configuration, sdnrTopic); + fmNotifCambriaConsumer = dmaapUtils.buildConsumer(configuration, fmTopic); + pmNotifCambriaConsumer = dmaapUtils.buildConsumer(configuration, pmTopic); + + // create notification consumers for SNDR and policy + NotificationConsumer sdnrNotificationConsumer = new NotificationConsumer(sdnrNotifCambriaConsumer, + new SdnrNotificationCallback()); + // start sdnr notification consumer threads + ScheduledExecutorService executorPool; + executorPool = Executors.newScheduledThreadPool(10); + executorPool.scheduleAtFixedRate(sdnrNotificationConsumer, 0, configuration.getPollingInterval(), + TimeUnit.SECONDS); + + // create notification consumers for FM + NotificationConsumer fmNotificationConsumer = new NotificationConsumer(fmNotifCambriaConsumer, + new FMNotificationCallback()); + // start fm notification consumer threads + executorPool = Executors.newScheduledThreadPool(10); + executorPool.scheduleAtFixedRate(fmNotificationConsumer, 0, configuration.getPollingInterval(), + TimeUnit.SECONDS); + + // create notification consumers for PM + NotificationConsumer pmNotificationConsumer = new NotificationConsumer(pmNotifCambriaConsumer, + new PMNotificationCallback()); + // start pm notification consumer threads + executorPool = Executors.newScheduledThreadPool(10); + executorPool.scheduleAtFixedRate(pmNotificationConsumer, 0, configuration.getPollingInterval(), + TimeUnit.SECONDS); + + } + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FMNotificationCallback.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FMNotificationCallback.java new file mode 100644 index 0000000..aede74b --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/FMNotificationCallback.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.dmaap; + +import org.onap.dcaegen2.services.sonhms.NewFmNotification; +import org.onap.dcaegen2.services.sonhms.dao.FaultNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.entity.FaultNotifications; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FMNotificationCallback extends NotificationCallback{ + + private static Logger log = LoggerFactory.getLogger(FMNotificationCallback.class); + + @Override + public void activateCallBack(String msg){ + handleNotification(msg); + } + + private void handleNotification(String msg) { + + FaultNotificationsRepository faultNotificationsRepository=BeanUtil + .getBean(FaultNotificationsRepository.class); + + NewFmNotification newNotification=BeanUtil.getBean(NewFmNotification.class); + FaultNotifications faultNotification = new FaultNotifications(); + faultNotification.setNotification(msg); + if (log.isDebugEnabled()) { + log.debug(faultNotification.toString()); + } + faultNotificationsRepository.save(faultNotification); + newNotification.setNewNotif(true); + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationCallback.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationCallback.java new file mode 100644 index 0000000..f488f03 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationCallback.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.dmaap; + +public abstract class NotificationCallback { + + public abstract void activateCallBack(String msg); + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationConsumer.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationConsumer.java index 78294a3..3860311 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationConsumer.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationConsumer.java @@ -25,7 +25,6 @@ import com.att.nsa.cambria.client.CambriaConsumer; import java.io.IOException; -import org.onap.dcaegen2.services.sonhms.dmaap.DmaapClient.NotificationCallback; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PMNotificationCallback.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PMNotificationCallback.java new file mode 100644 index 0000000..47e285a --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PMNotificationCallback.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.dmaap; + +import org.onap.dcaegen2.services.sonhms.NewPmNotification; +import org.onap.dcaegen2.services.sonhms.dao.PerformanceNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.entity.PerformanceNotifications; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PMNotificationCallback extends NotificationCallback { + + private static Logger log = LoggerFactory.getLogger(PMNotificationCallback.class); + + @Override + public void activateCallBack(String msg){ + handleNotification(msg); + } + + private void handleNotification(String msg) { + + PerformanceNotificationsRepository performanceNotificationsRepository=BeanUtil.getBean(PerformanceNotificationsRepository.class); + NewPmNotification newNotification=BeanUtil.getBean(NewPmNotification.class); + PerformanceNotifications performanceNotification = new PerformanceNotifications(); + performanceNotification.setNotification(msg); + log.info("Performance notification {}", performanceNotification); + performanceNotificationsRepository.save(performanceNotification); + newNotification.setNewNotif(true); + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java index 68cb788..dbd9b58 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/PolicyDmaapClient.java @@ -22,37 +22,39 @@ package org.onap.dcaegen2.services.sonhms.dmaap; import com.att.nsa.cambria.client.CambriaBatchingPublisher; -import org.onap.dcaegen2.services.sonhms.Configuration; -import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; import java.io.IOException; import java.util.Map; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils; + public class PolicyDmaapClient { - DmaapUtils dmaapUtils = new DmaapUtils(); - - /** - * Method stub for sending notification to policy. - */ - @SuppressWarnings("unchecked") - public boolean sendNotificationToPolicy(String msg) { - - Map<String,Object> streamSubscribes= Configuration.getInstance().getStreamsPublishes(); - String policyTopicUrl =((Map<String,String>)((Map<String,Object>)streamSubscribes.get("CL_topic")).get("dmaap_info")).get("topic_url"); - String[] policyTopicSplit=policyTopicUrl.split("\\/"); - String policyTopic=policyTopicSplit[policyTopicSplit.length-1]; - Configuration configuration = Configuration.getInstance(); - CambriaBatchingPublisher cambriaBatchingPublisher; - try { - - cambriaBatchingPublisher = dmaapUtils.buildPublisher(configuration, policyTopic); - - NotificationProducer notificationProducer = new NotificationProducer(cambriaBatchingPublisher); - notificationProducer.sendNotification(msg); - } catch (IOException e) { - return false; - } - return true; - } + private DmaapUtils dmaapUtils; + + /** + * Method stub for sending notification to policy. + */ + @SuppressWarnings("unchecked") + public boolean sendNotificationToPolicy(String msg) { + dmaapUtils = new DmaapUtils(); + Map<String, Object> streamsPublishes = Configuration.getInstance().getStreamsPublishes(); + String policyTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamsPublishes.get("CL_topic")) + .get("dmaap_info")).get("topic_url"); + String[] policyTopicSplit = policyTopicUrl.split("\\/"); + String policyTopic = policyTopicSplit[policyTopicSplit.length - 1]; + Configuration configuration = Configuration.getInstance(); + CambriaBatchingPublisher cambriaBatchingPublisher; + try { + + cambriaBatchingPublisher = dmaapUtils.buildPublisher(configuration, policyTopic); + + NotificationProducer notificationProducer = new NotificationProducer(cambriaBatchingPublisher); + notificationProducer.sendNotification(msg); + } catch (IOException e) { + return false; + } + return true; + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/SdnrNotificationCallback.java b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/SdnrNotificationCallback.java new file mode 100644 index 0000000..d4430ea --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/dmaap/SdnrNotificationCallback.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.dmaap; + +import org.onap.dcaegen2.services.sonhms.NewSdnrNotification; +import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository; +import org.onap.dcaegen2.services.sonhms.entity.DmaapNotifications; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdnrNotificationCallback extends NotificationCallback { + + private static Logger log = LoggerFactory.getLogger(SdnrNotificationCallback.class); + + @Override + public void activateCallBack(String msg) { + handleNotification(msg); + } + + private void handleNotification(String msg) { + + DmaapNotificationsRepository dmaapNotificationsRepository = BeanUtil + .getBean(DmaapNotificationsRepository.class); + DmaapNotifications dmaapNotification = new DmaapNotifications(); + dmaapNotification.setNotification(msg); + if (log.isDebugEnabled()) { + log.debug(dmaapNotification.toString()); + } + dmaapNotificationsRepository.save(dmaapNotification); + NewSdnrNotification newNotification = BeanUtil.getBean(NewSdnrNotification.class); + newNotification.setNewNotif(true); + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/entity/HandOverMetrics.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/HandOverMetrics.java new file mode 100644 index 0000000..be5aad7 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/HandOverMetrics.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.entity; + +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.CreationTimestamp; + +@Entity +@Table(name = "HANDOVER_METRICS") +public class HandOverMetrics { + + @Id + @Column(name = "src_cell_id", columnDefinition = "srcCellId") + private String srcCellId; + + @Column(name = "ho_details", columnDefinition = "text") + private String hoDetails; + + @CreationTimestamp + @Column(name = "created_at", columnDefinition = "timestamp") + private Timestamp createdAt; + + public HandOverMetrics() { + super(); + } + + public String getSrcCellId() { + return srcCellId; + } + + public void setSrcCellId(String srcCellId) { + this.srcCellId = srcCellId; + } + + public String getHoDetails() { + return hoDetails; + } + + public void setHoDetails(String hoDetails) { + this.hoDetails = hoDetails; + } + + public Timestamp getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Timestamp createdAt) { + this.createdAt = createdAt; + } + + @Override + public String toString() { + return "HandOverMetrics [srcCellId=" + srcCellId + ", hoDetails=" + hoDetails + ", createdAt=" + createdAt + + "]"; + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PerformanceNotifications.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PerformanceNotifications.java new file mode 100644 index 0000000..30a6c0e --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PerformanceNotifications.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.entity; + +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.CreationTimestamp; + +@Entity +@Table(name = "PERFORMANCE_NOTIFICATIONS") +public class PerformanceNotifications { + + @Id + @Column(name = "notification", columnDefinition = "text") + private String notification; + + @CreationTimestamp + @Column(name = "created_at", columnDefinition = "timestamp") + private Timestamp createdAt; + + public PerformanceNotifications() { + + } + + public PerformanceNotifications(String notification, Timestamp createdAt) { + this.notification = notification; + this.createdAt = createdAt; + } + + public String getNotification() { + return notification; + } + + public void setNotification(String notification) { + this.notification = notification; + } + + public Timestamp getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Timestamp createdAt) { + this.createdAt = createdAt; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PciRequests.java b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/SonRequests.java index 79120ee..e9c454e 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/entity/PciRequests.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/entity/SonRequests.java @@ -28,7 +28,7 @@ import javax.persistence.Table; @Entity @Table(name = "PCI_REQUESTS") -public class PciRequests { +public class SonRequests { @Id @Column(name = "TRANSACTION_ID") @@ -37,14 +37,14 @@ public class PciRequests { @Column(name = "CHILD_THREAD_ID") private long childThreadId; - public PciRequests() { + public SonRequests() { } /** * Parameterised constructor. */ - public PciRequests(String transactionId, long childThreadId) { + public SonRequests(String transactionId, long childThreadId) { super(); this.transactionId = transactionId; this.childThreadId = childThreadId; @@ -66,4 +66,9 @@ public class PciRequests { this.childThreadId = childThreadId; } + @Override + public String toString() { + return "PciRequests [transactionId=" + transactionId + ", childThreadId=" + childThreadId + "]"; + } + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/AdditionalMeasurements.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/AdditionalMeasurements.java new file mode 100644 index 0000000..10329ba --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/AdditionalMeasurements.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +import java.util.List; +import java.util.Map; + +public class AdditionalMeasurements { + + String name; + List<Map<String,String>> arrayOfNamedHashMap; + + public AdditionalMeasurements() { + + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public List<Map<String, String>> getArrayOfNamedHashMap() { + return arrayOfNamedHashMap; + } + public void setArrayOfNamedHashMap(List<Map<String, String>> arrayOfNamedHashMap) { + this.arrayOfNamedHashMap = arrayOfNamedHashMap; + } + @Override + public String toString() { + return "AdditionalMeasurements [name=" + name + ", arrayOfNamedHashMap=" + arrayOfNamedHashMap + "]"; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/AnrInput.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/AnrInput.java new file mode 100644 index 0000000..faff91e --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/AnrInput.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +import java.util.List; + +public class AnrInput { + + String cellId; + List<String> removeableNeighbors; + + public AnrInput() { + + } + /** + * Parameterized Constructor. + */ + + public AnrInput(String cellId, List<String> removeableNeighbors) { + super(); + this.cellId = cellId; + this.removeableNeighbors = removeableNeighbors; + } + public String getCellId() { + return cellId; + } + public void setCellId(String cellId) { + this.cellId = cellId; + } + public List<String> getRemoveableNeighbors() { + return removeableNeighbors; + } + public void setRemoveableNeighbors(List<String> removeableNeighbors) { + this.removeableNeighbors = removeableNeighbors; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellPciPair.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellPciPair.java index 866c51e..b5b9398 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellPciPair.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/CellPciPair.java @@ -30,6 +30,7 @@ public class CellPciPair { @JsonProperty("physicalCellId") private int physicalCellId; + @Override public String toString() { return "CellPciPair [cellId=" + cellId + ", physicalCellId=" + physicalCellId + "]"; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/ClusterMap.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/ClusterMap.java new file mode 100644 index 0000000..c01b3c8 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/ClusterMap.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +import java.util.ArrayList; + +public class ClusterMap { + + CellPciPair cell; + ArrayList<CellPciPair> neighbourList; + + public ClusterMap() { + + } + + /** + * Constructor. + */ + public ClusterMap(CellPciPair cell, ArrayList<CellPciPair> neighbourList) { + super(); + this.cell = cell; + this.neighbourList = neighbourList; + } + + public CellPciPair getCell() { + return cell; + } + + public void setCell(CellPciPair cell) { + this.cell = cell; + } + + public ArrayList<CellPciPair> getNeighbourList() { + return neighbourList; + } + + public void setNeighbourList(ArrayList<CellPciPair> neighbourList) { + this.neighbourList = neighbourList; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java index e043aaf..415b7d9 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Configurations.java @@ -34,7 +34,6 @@ public class Configurations { public Configurations() { } - /** * Parameterized constructor. * @@ -43,13 +42,14 @@ public class Configurations { super(); this.data = data; } - public Data getData() { return data; } - public void setData(Data data) { this.data = data; } + + + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Event.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Event.java new file mode 100644 index 0000000..b958318 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Event.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +import org.onap.dcaegen2.services.sonhms.CommonEventHeader; + +public class Event { + CommonEventHeader commonEventHeader; + Measurement measurement; + + public Event() { + + } + + public CommonEventHeader getCommonEventHeader() { + return commonEventHeader; + } + + public void setCommonEventHeader(CommonEventHeader commonEventHeader) { + this.commonEventHeader = commonEventHeader; + } + + public Measurement getMeasurement() { + return measurement; + } + + public void setMeasurement(Measurement measurement) { + this.measurement = measurement; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/HoDetails.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/HoDetails.java new file mode 100644 index 0000000..ecc2048 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/HoDetails.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +public class HoDetails { + + private String dstCellId; + private int attemptsCount; + private int successCount; + private float successRate; + + /** + * default constructor + */ + public HoDetails() { + + } + + public String getDstCellId() { + return dstCellId; + } + public void setDstCellId(String dstCellId) { + this.dstCellId = dstCellId; + } + public int getAttemptsCount() { + return attemptsCount; + } + public void setAttemptsCount(int attemptsCount) { + this.attemptsCount = attemptsCount; + } + public int getSuccessCount() { + return successCount; + } + public void setSuccessCount(int successCount) { + this.successCount = successCount; + } + public float getSuccessRate() { + return successRate; + } + public void setSuccessRate(float successRate) { + this.successRate = successRate; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteCell.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteCell.java new file mode 100644 index 0000000..a23bc6a --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteCell.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class LteCell { + + @JsonProperty("PNFName") + private String pnfName; + + @JsonProperty("PLMNID") + private String plmnId; + + @JsonProperty("CID") + private String cid; + + @JsonProperty("PhyCellID") + private int phyCellId; + + @JsonProperty("Blacklisted") + private String blacklisted; + + public LteCell() { + + } + + public String getPnfName() { + return pnfName; + } + + public void setPnfName(String pnfName) { + this.pnfName = pnfName; + } + + public String getPlmnId() { + return plmnId; + } + + public void setPlmnId(String plmnId) { + this.plmnId = plmnId; + } + + public String getCid() { + return cid; + } + + public void setCid(String cid) { + this.cid = cid; + } + + public int getPhyCellId() { + return phyCellId; + } + + public void setPhyCellId(int phyCellId) { + this.phyCellId = phyCellId; + } + + public String getBlacklisted() { + return blacklisted; + } + + public void setBlacklisted(String blacklisted) { + this.blacklisted = blacklisted; + } + +}
\ No newline at end of file diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java index 961e5f0..f1cae93 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/LteNeighborListInUseLteCell.java @@ -52,10 +52,6 @@ public class LteNeighborListInUseLteCell { } - /** - * Parameterized Constructor. - */ - public LteNeighborListInUseLteCell(String pnfName, String enable, String alias, String mustInclude, String plmnId, String cid, int phyCellId, String blacklisted) { super(); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Measurement.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Measurement.java new file mode 100644 index 0000000..c3863b0 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Measurement.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +import java.util.List; + +public class Measurement { + + String measurementInterval; + List<AdditionalMeasurements> additionalMeasurements; + + /** + * default constructor + */ + public Measurement() { + + } + public String getMeasurementInterval() { + return measurementInterval; + } + + public void setMeasurementInterval(String measurementInterval) { + this.measurementInterval = measurementInterval; + } + + public List<AdditionalMeasurements> getAdditionalMeasurements() { + return additionalMeasurements; + } + + public void setAdditionalMeasurements(List<AdditionalMeasurements> additionalMeasurements) { + this.additionalMeasurements = additionalMeasurements; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/NeighborListInUse.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NeighborListInUse.java index b88cb5a..c7baa25 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/NeighborListInUse.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/NeighborListInUse.java @@ -29,6 +29,9 @@ public class NeighborListInUse { @JsonProperty("LTENeighborListInUseLTECell") private List<LteNeighborListInUseLteCell> lteNeighborListInUseLteCell; + @JsonProperty("LTECell") + private List<LteCell> lteCell; + @JsonProperty("LTECellNumberOfEntries") private String lteCellNumberOfEntries; @@ -39,13 +42,14 @@ public class NeighborListInUse { /** * Parameterized Constructor. */ - - public NeighborListInUse(List<LteNeighborListInUseLteCell> lteNeighborListInUseLteCell, + public NeighborListInUse(List<LteNeighborListInUseLteCell> lteNeighborListInUseLteCell, List<LteCell> lteCell, String lteCellNumberOfEntries) { super(); this.lteNeighborListInUseLteCell = lteNeighborListInUseLteCell; + this.lteCell = lteCell; this.lteCellNumberOfEntries = lteCellNumberOfEntries; } + public List<LteNeighborListInUseLteCell> getLteNeighborListInUseLteCell() { return lteNeighborListInUseLteCell; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/PMNotification.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PMNotification.java new file mode 100644 index 0000000..076be31 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/PMNotification.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.model; + +public class PMNotification { + + Event event; + + /** + * default constructor + */ + public PMNotification() { + + } + + public Event getEvent() { + return event; + } + public void setEvent(Event event) { + this.event = event; + } + + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Ran.java b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Ran.java index f2be944..8f016dc 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/model/Ran.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/model/Ran.java @@ -27,6 +27,9 @@ public class Ran { @JsonProperty(value = "Common") private Common common; + + @JsonProperty("NeighborListInUse") + private NeighborListInUse neighborListInUse; public Ran() { @@ -35,15 +38,18 @@ public class Ran { /** * Parameterized constructor. */ - public Ran(Common common) { + public Ran(Common common, NeighborListInUse neighborListInUse) { super(); this.common = common; + this.neighborListInUse = neighborListInUse; } + public Common getCommon() { return common; } + public void setCommon(Common common) { this.common = common; } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AnrSolutions.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AnrSolutions.java new file mode 100644 index 0000000..117f202 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AnrSolutions.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019 Wipro Limited. + * ============================================================================== + * 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. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.dcaegen2.services.sonhms.restclient; + +import java.util.ArrayList; +import java.util.List; + +public class AnrSolutions { + + String cellId; + List<String> removeableNeighbors = new ArrayList<>(); + + public AnrSolutions() { + + } + + public AnrSolutions(String cellId, List<String> removeableNeighbors) { + super(); + this.cellId = cellId; + this.removeableNeighbors = removeableNeighbors; + } + + public String getCellId() { + return cellId; + } + public void setCellId(String cellId) { + this.cellId = cellId; + } + public List<String> getRemoveableNeighbors() { + return removeableNeighbors; + } + public void setRemoveableNeighbors(List<String> removeableNeighbors) { + this.removeableNeighbors = removeableNeighbors; + } + @Override + public String toString() { + return "AnrSolutions [cellId=" + cellId + ", removeableNeighbors=" + removeableNeighbors + "]"; + } + + +} diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBody.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBody.java index 61e0421..1102f76 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBody.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBody.java @@ -21,15 +21,13 @@ package org.onap.dcaegen2.services.sonhms.restclient; -import java.util.List; - public class AsyncResponseBody { String transactionId = null; String requestId = null; String requestStatus = null; String statusMessage = null; - List<Solution> solutions; + Solutions solutions; public String getTransactionId() { return transactionId; @@ -69,11 +67,11 @@ public class AsyncResponseBody { this.statusMessage = statusMessage; } - public List<Solution> getSolutions() { + public Solutions getSolutions() { return solutions; } - public void setSolutions(List<Solution> solutions) { + public void setSolutions(Solutions solutions) { this.solutions = solutions; } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfo.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfo.java index edac16f..2501e53 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfo.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfo.java @@ -24,9 +24,30 @@ package org.onap.dcaegen2.services.sonhms.restclient; import java.util.ArrayList; import java.util.List; +import org.onap.dcaegen2.services.sonhms.model.AnrInput; + public class CellInfo { String networkId = null; List<String> cellIdList = new ArrayList<>(); + protected List<AnrInput> anrInputList = new ArrayList<>(); + String trigger; + + + public List<AnrInput> getAnrInputList() { + return anrInputList; + } + + public void setAnrInputList(List<AnrInput> anrInputList) { + this.anrInputList = anrInputList; + } + + public String getTrigger() { + return trigger; + } + + public void setTrigger(String trigger) { + this.trigger = trigger; + } public String getNetworkId() { return networkId; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBody.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBody.java index 2e5eeaa..974c483 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBody.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBody.java @@ -25,7 +25,7 @@ public class OofRequestBody { protected RequestInfo requestInfo = new RequestInfo(); protected CellInfo cellInfo = new CellInfo(); - + public RequestInfo getRequestInfo() { return requestInfo; } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java index 083341b..9cb1d18 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClient.java @@ -24,12 +24,15 @@ package org.onap.dcaegen2.services.sonhms.restclient; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import org.onap.dcaegen2.services.sonhms.ConfigPolicy; import org.onap.dcaegen2.services.sonhms.Configuration; import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.AnrInput; import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +54,7 @@ public class OofRestClient { */ public static String queryOof(int numSolutions, String transactionId, String requestType, List<String> cellIdList, - String networkId, List<String> optimizers) throws OofNotFoundException { + String networkId, List<String> optimizers, List<AnrInput> anrInputList) throws OofNotFoundException { log.debug("inside queryoof"); Configuration configuration = Configuration.getInstance(); @@ -67,6 +70,9 @@ public class OofRestClient { requestInfo.setRequestType(requestType); requestInfo.setNumSolutions(numSolutions); requestInfo.setOptimizers(optimizers); + Map<String,String> callbackHeader = new HashMap<>(); + callbackHeader.put("Content-Type", "application/json"); + requestInfo.setCallbackHeader(callbackHeader); ConfigPolicy config = ConfigPolicy.getInstance(); int timeout = 60; try { @@ -75,9 +81,13 @@ public class OofRestClient { log.debug("No config policy available. Using default timeout 60 sec"); } requestInfo.setTimeout(timeout); + CellInfo cellInfo = new CellInfo(); cellInfo.setCellIdList(cellIdList); cellInfo.setNetworkId(networkId); + cellInfo.setTrigger("NbrListChange"); + if(!anrInputList.isEmpty()) + cellInfo.setAnrInputList(anrInputList); OofRequestBody oofRequestBody = new OofRequestBody(); oofRequestBody.setRequestInfo(requestInfo); oofRequestBody.setCellInfo(cellInfo); diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SonSolution.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutions.java index 25f474a..eec3fd8 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SonSolution.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutions.java @@ -21,11 +21,14 @@ package org.onap.dcaegen2.services.sonhms.restclient; -public class SonSolution { +public class PciSolutions { String cellId = null; int pci; + public PciSolutions() { + + } public String getCellId() { return cellId; } @@ -42,4 +45,9 @@ public class SonSolution { this.pci = pci; } + @Override + public String toString() { + return "PciSolutions [cellId=" + cellId + ", pci=" + pci + "]"; + } + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfo.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfo.java index ff53b33..3504e5d 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfo.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfo.java @@ -21,7 +21,9 @@ package org.onap.dcaegen2.services.sonhms.restclient; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class RequestInfo { String transactionId = null; @@ -31,6 +33,16 @@ public class RequestInfo { String requestType = null; int numSolutions; List<String> optimizers = null; + protected Map<String, String> callbackHeader = new HashMap<>(); + + + public Map<String, String> getCallbackHeader() { + return callbackHeader; + } + + public void setCallbackHeader(Map<String, String> callbackHeader) { + this.callbackHeader = callbackHeader; + } public void setOptimizers(List<String> optimizers) { this.optimizers = optimizers; diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java index 996e553..65bd756 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java @@ -58,7 +58,7 @@ public class SdnrRestClient { Configuration configuration = Configuration.getInstance(); String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); String requestUrl = configuration.getConfigDbService() + "/SDNCConfigDBAPI/getCellList" + "/" + networkId + "/" - + encode(ts); + + ts; return sendRequest(requestUrl); } @@ -72,7 +72,7 @@ public class SdnrRestClient { Configuration configuration = Configuration.getInstance(); String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); String requestUrl = configuration.getConfigDbService() + "/SDNCConfigDBAPI/getNbrList" + "/" + cellId + "/" - + encode(ts); + + ts; log.debug("request url: {}", requestUrl); String response = sendRequest(requestUrl); List<CellPciPair> nbrList = new ArrayList<>(); @@ -96,7 +96,7 @@ public class SdnrRestClient { Configuration configuration = Configuration.getInstance(); String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); String requestUrl = configuration.getConfigDbService() + "/SDNCConfigDBAPI/getPCI" + "/" + cellId + "/" - + encode(ts); + + ts; String response = sendRequest(requestUrl); JSONObject respObj = new JSONObject(response); return respObj.getInt("value"); @@ -112,18 +112,12 @@ public class SdnrRestClient { Configuration configuration = Configuration.getInstance(); String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis())); String requestUrl = configuration.getConfigDbService() + "/SDNCConfigDBAPI/getPnfName" + "/" + cellId + "/" - + encode(ts); + + ts; String response = sendRequest(requestUrl); JSONObject responseObject = new JSONObject(response); return responseObject.getString("value"); } - /** - * Method to encode url. - */ - private static String encode(String url) { - return url.replace(" ", "%20"); - } /** * Method to send request. diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solution.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solutions.java index 66af930..8e694a3 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solution.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/Solutions.java @@ -24,28 +24,15 @@ package org.onap.dcaegen2.services.sonhms.restclient; import java.util.ArrayList; import java.util.List; -public class Solution { - String startTime = null; - String finishTime = null; +public class Solutions { + String networkId = null; - List<SonSolution> pciSolutions = new ArrayList<>(); - - public String getStartTime() { - return startTime; - } - - public void setStartTime(String startTime) { - this.startTime = startTime; - } - - public String getFinishTime() { - return finishTime; - } - - public void setFinishTime(String finishTime) { - this.finishTime = finishTime; + List<PciSolutions> pciSolutions = new ArrayList<>(); + List<AnrSolutions> anrSolutions = new ArrayList<>(); + + public Solutions() { + } - public String getNetworkId() { return networkId; } @@ -54,22 +41,33 @@ public class Solution { this.networkId = networkId; } - public List<SonSolution> getPciSolutions() { + public List<PciSolutions> getPciSolutions() { return pciSolutions; } /** * Sets PciSolutions. */ - public void setPciSolutions(List<SonSolution> pciSolutions) { + public void setPciSolutions(List<PciSolutions> pciSolutions) { this.pciSolutions = pciSolutions; } + public List<AnrSolutions> getAnrSolutions() { + return anrSolutions; + } + + public void setAnrSolutions(List<AnrSolutions> anrSolutions) { + this.anrSolutions = anrSolutions; + } @Override public String toString() { - return "Solutions [startTime=" + startTime + ", finishTime=" + finishTime + ", networkId=" + networkId - + ", pciSolutions=" + pciSolutions + "]"; + return "Solutions [networkId=" + networkId + ", pciSolutions=" + pciSolutions + ", anrSolutions=" + anrSolutions + + "]"; } + + + + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java index 5b4ca55..a25fd54 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java @@ -26,12 +26,14 @@ import fj.data.Either; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import org.onap.dcaegen2.services.sonhms.ClusterDetailsComponent; +import org.onap.dcaegen2.services.sonhms.FaultNotificationtoClusterMapping; import org.onap.dcaegen2.services.sonhms.NotificationToClusterMapping; import org.onap.dcaegen2.services.sonhms.child.Graph; import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository; @@ -45,17 +47,50 @@ import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +public class ClusterUtils { - -public class ClusterUtils { - private static Logger log = LoggerFactory.getLogger(ClusterUtils.class); - + public List<ClusterDetails> getAllClusters() { ClusterDetailsComponent clusterDetailsComponent = new ClusterDetailsComponent(); - return clusterDetailsComponent.getClusterDetails(); + return clusterDetailsComponent.getClusterDetails(); + } + + /** + * Get cluster for FM notifications. + */ + public FaultNotificationtoClusterMapping getClustersForFmNotification(Set<String> cellIds, + List<ClusterDetails> clusterDetails) { + List<String> newCells = new ArrayList<>(); + Map<String, String> cellsInCluster = new HashMap<String, String>(); + FaultNotificationtoClusterMapping faultNotificationtoClusterMapping = new FaultNotificationtoClusterMapping(); + for (String cellId : cellIds) { + for (ClusterDetails clusterDetail : clusterDetails) { + Graph cluster = new Graph(clusterDetail.getClusterInfo()); + + Set<String> clusterCells = getCellsInCluster(cluster); + for (String clusterCell : clusterCells) { + if (cellId.equals(clusterCell)) { + cellsInCluster.put(cellId, clusterDetail.getClusterId()); + break; + + } + + } + + } + if (!cellsInCluster.containsKey(cellId)) { + newCells.add(cellId); + } + + } + + faultNotificationtoClusterMapping.setCellsinCluster(cellsInCluster); + faultNotificationtoClusterMapping.setNewCells(newCells); + return faultNotificationtoClusterMapping; + } - + /** * Get clusters for notifications. */ @@ -66,23 +101,23 @@ public class ClusterUtils { Map<FapServiceList, String> cellsInCluster = new HashMap<>(); List<FapServiceList> newCells = new ArrayList<>(); - + List<FapServiceList> fapServiceList = notification.getPayload().getRadioAccess().getFapServiceList(); - + for (FapServiceList fapService : fapServiceList) { for (ClusterDetails clusterDetail : clusterDetails) { Set<String> cellsInNotification = getCellsInNotification(fapService); - + Graph cluster = new Graph(clusterDetail.getClusterInfo()); Set<String> clusterCells = getCellsInCluster(cluster); log.debug("cells in cluster {}", clusterCells); - + cellsInNotification.retainAll(clusterCells); - + if (!cellsInNotification.isEmpty()) { log.debug("cell or it's neighbour in the cluster"); cellsInCluster.put(fapService, clusterDetail.getClusterId()); @@ -99,7 +134,7 @@ public class ClusterUtils { mapping.setNewCells(newCells); return mapping; } - + /** * Get cluster details from cluster ID. */ @@ -113,19 +148,18 @@ public class ClusterUtils { } return Either.right(404); } - + /** * Get clusters for Cell. */ public Either<Graph, Integer> getClusterForCell(FapServiceList fapService, List<Graph> newClusters) { - + if (newClusters.isEmpty()) { return Either.right(404); } - - + for (Graph cluster : newClusters) { - + Set<String> cellsInNotification = getCellsInNotification(fapService); Set<String> clusterCells = getCellsInCluster(cluster); @@ -139,7 +173,31 @@ public class ClusterUtils { return Either.right(404); } - + + /** + * Get clusters for FM Cell. + */ + public Either<Graph, Integer> getClusterForFMCell(String cellId, List<Graph> newClusters) { + if (newClusters.isEmpty()) { + log.info("getClusterForFMCell 404"); + return Either.right(404); + } + for (Graph cluster : newClusters) { + + Set<String> clusterCells = getCellsInCluster(cluster); + for (String clusterCell : clusterCells) { + if (cellId.equals(clusterCell)) { + return Either.left(cluster); + + } + + } + + } + return Either.right(404); + + } + private Set<String> getCellsInNotification(FapServiceList fapService) { Set<String> cellsInNotification = new HashSet<>(); cellsInNotification.add(fapService.getAlias()); @@ -164,38 +222,29 @@ public class ClusterUtils { return clusterCells; } - - /** - * Create cluster from notification. - */ - public Graph createCluster(FapServiceList fapService) throws ConfigDbNotFoundException { + // generic create cluster for both fm and sdnr + + public Graph createCluster(Map<CellPciPair, ArrayList<CellPciPair>> clusterMap) throws ConfigDbNotFoundException { Graph cluster = new Graph(); log.debug("cluster formation started"); - int phycellId = fapService.getX0005b9Lte().getPhyCellIdInUse(); - String cellId = fapService.getCellConfig().getLte().getRan().getCellIdentity(); - - CellPciPair val = new CellPciPair(); - val.setCellId(cellId); - val.setPhysicalCellId(phycellId); - List<LteNeighborListInUseLteCell> neighbourlist; - neighbourlist = fapService.getCellConfig().getLte().getRan().getNeighborListInUse() - .getLteNeighborListInUseLteCell(); - log.debug("Neighbor list size: {}", neighbourlist.size()); - for (int i = 0; i < neighbourlist.size(); i++) { - String cell = neighbourlist.get(i).getAlias(); - int phy = neighbourlist.get(i).getPhyCellId(); + Set<CellPciPair> keySet = clusterMap.keySet(); + Iterator<CellPciPair> iterate = keySet.iterator(); + CellPciPair val = (CellPciPair) iterate.next(); + + List<CellPciPair> firstNeighbourlist = clusterMap.get(val); + + for (int i = 0; i < firstNeighbourlist.size(); i++) { + String cell = firstNeighbourlist.get(i).getCellId(); + int phy = firstNeighbourlist.get(i).getPhysicalCellId(); - log.debug("cellID: {}", cell); - log.debug("PCI: {}", phy); CellPciPair val1 = new CellPciPair(); val1.setCellId(cell); val1.setPhysicalCellId(phy); cluster.addEdge(val, val1); - log.debug("cluster: {}", cluster); - List<CellPciPair> nbrList = SdnrRestClient.getNbrList(neighbourlist.get(i).getAlias()); + List<CellPciPair> nbrList = SdnrRestClient.getNbrList(cell); for (CellPciPair nbr : nbrList) { String cid = nbr.getCellId(); @@ -211,7 +260,7 @@ public class ClusterUtils { log.debug("final cluster: {}", cluster); return cluster; } - + /** * Save cluster. */ @@ -232,28 +281,52 @@ public class ClusterUtils { return clusterId.toString(); } - + /** - * update cluster. + * Update cluster. */ - public Graph modifyCluster(Graph cluster, FapServiceList fapser) { - - int phycellId = fapser.getX0005b9Lte().getPhyCellIdInUse(); - String cellId = fapser.getCellConfig().getLte().getRan().getCellIdentity(); - CellPciPair mainCellPciPair = new CellPciPair(); - mainCellPciPair.setCellId(cellId); - mainCellPciPair.setPhysicalCellId(phycellId); - List<LteNeighborListInUseLteCell> newNeighbourList; - newNeighbourList = fapser.getCellConfig().getLte().getRan().getNeighborListInUse() - .getLteNeighborListInUseLteCell(); + public void updateCluster(Graph cluster) { + String cellPciNeighbourString = cluster.getPciNeighbourJson(); + UUID clusterId = cluster.getGraphId(); + ClusterDetailsRepository clusterDetailsRepository = BeanUtil.getBean(ClusterDetailsRepository.class); + clusterDetailsRepository.updateCluster(cellPciNeighbourString, clusterId.toString()); + } - Map<CellPciPair, ArrayList<CellPciPair>> clusterMap; - clusterMap = cluster.getCellPciNeighbourMap(); + /** + * Find cluster Map. + */ + public Map<CellPciPair, ArrayList<CellPciPair>> findClusterMap(String cellId) throws ConfigDbNotFoundException { + log.info("indide clusterMap"); + int phyCellId = SdnrRestClient.getPci(cellId); + CellPciPair main = new CellPciPair(); + main.setCellId(cellId); + main.setPhysicalCellId(phyCellId); + ArrayList<CellPciPair> cellPciPairs; + cellPciPairs = (ArrayList<CellPciPair>) SdnrRestClient.getNbrList(cellId); + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<>(); + clusterMap.put(main, cellPciPairs); + log.info("clusterMap{}", clusterMap); + + return clusterMap; + } + + /** + * Modify cluster. + */ + public Graph modifyCluster(Graph cluster, Map<CellPciPair, ArrayList<CellPciPair>> clusterMap) { + Set<CellPciPair> keySet = clusterMap.keySet(); + Iterator<CellPciPair> iterate = keySet.iterator(); + CellPciPair mainCellPciPair = (CellPciPair) iterate.next(); + String cellId = mainCellPciPair.getCellId(); + List<CellPciPair> newNeighbourList = clusterMap.get(mainCellPciPair); + + Map<CellPciPair, ArrayList<CellPciPair>> existingClusterMap; + existingClusterMap = cluster.getCellPciNeighbourMap(); // coe List<CellPciPair> tempCellPair = new ArrayList<>(); - for (Map.Entry<CellPciPair, ArrayList<CellPciPair>> entry : clusterMap.entrySet()) { + for (Map.Entry<CellPciPair, ArrayList<CellPciPair>> entry : existingClusterMap.entrySet()) { CellPciPair oldClusterKeys = entry.getKey(); tempCellPair.add(oldClusterKeys); } @@ -276,14 +349,14 @@ public class ClusterUtils { /////// update cluster with new pci values for the same cell - if (clusterMap.containsKey(mainCellPciPair)) { + if (existingClusterMap.containsKey(mainCellPciPair)) { ArrayList<CellPciPair> oldClusterArray; - oldClusterArray = clusterMap.get(mainCellPciPair); + oldClusterArray = existingClusterMap.get(mainCellPciPair); oldClusterArray.clear(); for (int i = 0; i < newNeighbourList.size(); i++) { - String cid = newNeighbourList.get(i).getAlias(); - int phy = newNeighbourList.get(i).getPhyCellId(); + String cid = newNeighbourList.get(i).getCellId(); + int phy = newNeighbourList.get(i).getPhysicalCellId(); CellPciPair val2 = new CellPciPair(); val2.setCellId(cid); val2.setPhysicalCellId(phy); @@ -299,8 +372,8 @@ public class ClusterUtils { mapVal.setCellId(cell); mapVal.setPhysicalCellId(physicalCell); for (int j = 0; j < newNeighbourList.size(); j++) { - String cid1 = newNeighbourList.get(j).getAlias(); - int phy1 = newNeighbourList.get(j).getPhyCellId(); + String cid1 = newNeighbourList.get(j).getCellId(); + int phy1 = newNeighbourList.get(j).getPhysicalCellId(); CellPciPair val3 = new CellPciPair(); val3.setCellId(cid1); val3.setPhysicalCellId(phy1); @@ -316,28 +389,29 @@ public class ClusterUtils { } for (int j = 0; j < newNeighbourList.size(); j++) { - String cid1 = newNeighbourList.get(j).getAlias(); - int phy1 = newNeighbourList.get(j).getPhyCellId(); + String cid1 = newNeighbourList.get(j).getCellId(); + int phy1 = newNeighbourList.get(j).getPhysicalCellId(); CellPciPair val3 = new CellPciPair(); val3.setCellId(cid1); val3.setPhysicalCellId(phy1); - if (clusterMap.containsKey(val3)) { + if (existingClusterMap.containsKey(val3)) { cluster.addEdge(mainCellPciPair, val3); } } for (int k = 0; k < newNeighbourList.size(); k++) { - String cid2 = newNeighbourList.get(k).getAlias(); - int phy2 = newNeighbourList.get(k).getPhyCellId(); + String cid2 = newNeighbourList.get(k).getCellId(); + int phy2 = newNeighbourList.get(k).getPhysicalCellId(); CellPciPair val5 = new CellPciPair(); val5.setCellId(cid2); val5.setPhysicalCellId(phy2); cluster.addEdge(mainCellPciPair, val5); } - log.debug("Modified Cluster {}", cluster); + log.info("Modified Cluster {}", cluster); return cluster; } + } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/DmaapUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/DmaapUtils.java index ad6c385..f5efd3b 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/DmaapUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/DmaapUtils.java @@ -21,11 +21,6 @@ package org.onap.dcaegen2.services.sonhms.utils; -import java.net.MalformedURLException; -import java.security.GeneralSecurityException; - -import org.onap.dcaegen2.services.sonhms.Configuration; - import com.att.nsa.cambria.client.CambriaBatchingPublisher; import com.att.nsa.cambria.client.CambriaClient; import com.att.nsa.cambria.client.CambriaClientBuilders; @@ -35,99 +30,109 @@ import com.att.nsa.cambria.client.CambriaClientBuilders.TopicManagerBuilder; import com.att.nsa.cambria.client.CambriaConsumer; import com.att.nsa.cambria.client.CambriaTopicManager; +import java.net.MalformedURLException; +import java.security.GeneralSecurityException; + +import org.onap.dcaegen2.services.sonhms.Configuration; + public class DmaapUtils { - public CambriaBatchingPublisher buildPublisher(Configuration config, String topic) { - try { - return builder(config, topic).build(); - } catch (MalformedURLException | GeneralSecurityException e) { - // TODO Auto-generated catch block - return null; - - } - } - - public CambriaConsumer buildConsumer(Configuration config, String topic) { - - try { - return builderConsumer(config, topic).build(); - } catch (MalformedURLException | GeneralSecurityException e) { - // TODO Auto-generated catch block - return null; - } - - } - - private static PublisherBuilder builder(Configuration config, String topic) { - if (config.isSecured()) { - return authenticatedBuilder(config, topic); - } else { - return unAuthenticatedBuilder(config, topic); - } - } - - private static PublisherBuilder authenticatedBuilder(Configuration config, String topic) { - return unAuthenticatedBuilder(config, topic).usingHttps().authenticatedByHttp(config.getAafUsername(), - config.getAafPassword()); - } - - private static PublisherBuilder unAuthenticatedBuilder(Configuration config, String topic) { - return new CambriaClientBuilders.PublisherBuilder().usingHosts(config.getDmaapServers()).onTopic(topic) - .logSendFailuresAfter(5); - } - - private static ConsumerBuilder builderConsumer(Configuration config, String topic) { - if (config.isSecured()) { - return authenticatedConsumerBuilder(config, topic); - } else { - return unAuthenticatedConsumerBuilder(config, topic); - } - } - - private static ConsumerBuilder unAuthenticatedConsumerBuilder(Configuration config, String topic) { - // TODO Auto-generated method stub - return new CambriaClientBuilders.ConsumerBuilder().usingHosts(config.getDmaapServers()).onTopic(topic) - .knownAs(config.getCg(), config.getCid()).withSocketTimeout(config.getPollingTimeout() * 1000); - } - - private static ConsumerBuilder authenticatedConsumerBuilder(Configuration config, String topic) { - return unAuthenticatedConsumerBuilder(config, topic).usingHttps().authenticatedByHttp(config.getAafUsername(), - config.getAafPassword()); - } - - public CambriaTopicManager cambriaCLientBuilder(Configuration configuration) { - if(configuration.isSecured()) { - return authenticatedCambriaCLientBuilder(configuration); - } - else - { - return unAuthenticatedCambriaCLientBuilder(configuration); - - } - } - - private static CambriaTopicManager authenticatedCambriaCLientBuilder(Configuration config) { - try { - return buildCambriaClient(new TopicManagerBuilder().usingHosts(config.getDmaapServers()) - .authenticatedByHttp(config.getAafUsername(), config.getAafPassword())); - } catch (MalformedURLException | GeneralSecurityException e) { - return null; - } - } - - private static CambriaTopicManager unAuthenticatedCambriaCLientBuilder(Configuration config) { - try { - return buildCambriaClient(new TopicManagerBuilder().usingHosts(config.getDmaapServers())); - } catch (MalformedURLException | GeneralSecurityException e) { - return null; - - } - } - @SuppressWarnings("unchecked") - private static <T extends CambriaClient> T buildCambriaClient( - CambriaClientBuilders.AbstractAuthenticatedManagerBuilder<? extends CambriaClient> client) - throws MalformedURLException, GeneralSecurityException { - return (T) client.build(); - } + /** + * Build publisher. + */ + public CambriaBatchingPublisher buildPublisher(Configuration config, String topic) { + try { + return builder(config, topic).build(); + } catch (MalformedURLException | GeneralSecurityException e) { + return null; + + } + } + + /** + * Build consumer. + */ + public CambriaConsumer buildConsumer(Configuration config, String topic) { + + try { + return builderConsumer(config, topic).build(); + } catch (MalformedURLException | GeneralSecurityException e) { + return null; + } + + } + + private static PublisherBuilder builder(Configuration config, String topic) { + if (config.isSecured()) { + return authenticatedBuilder(config, topic); + } else { + return unAuthenticatedBuilder(config, topic); + } + } + + private static PublisherBuilder authenticatedBuilder(Configuration config, String topic) { + return unAuthenticatedBuilder(config, topic).usingHttps().authenticatedByHttp(config.getAafUsername(), + config.getAafPassword()); + } + + private static PublisherBuilder unAuthenticatedBuilder(Configuration config, String topic) { + return new CambriaClientBuilders.PublisherBuilder().usingHosts(config.getDmaapServers()).onTopic(topic) + .logSendFailuresAfter(5); + } + + private static ConsumerBuilder builderConsumer(Configuration config, String topic) { + if (config.isSecured()) { + return authenticatedConsumerBuilder(config, topic); + } else { + return unAuthenticatedConsumerBuilder(config, topic); + } + } + + private static ConsumerBuilder unAuthenticatedConsumerBuilder(Configuration config, String topic) { + return new CambriaClientBuilders.ConsumerBuilder().usingHosts(config.getDmaapServers()).onTopic(topic) + .knownAs(config.getCg(), config.getCid()).withSocketTimeout(config.getPollingTimeout() * 1000); + } + + private static ConsumerBuilder authenticatedConsumerBuilder(Configuration config, String topic) { + return unAuthenticatedConsumerBuilder(config, topic).usingHttps().authenticatedByHttp(config.getAafUsername(), + config.getAafPassword()); + } + + /** + * Build cambriaClient. + */ + public CambriaTopicManager cambriaCLientBuilder(Configuration configuration) { + if (configuration.isSecured()) { + return authenticatedCambriaCLientBuilder(configuration); + } else { + return unAuthenticatedCambriaCLientBuilder(configuration); + + } + } + + private static CambriaTopicManager authenticatedCambriaCLientBuilder(Configuration config) { + try { + return buildCambriaClient(new TopicManagerBuilder().usingHosts(config.getDmaapServers()) + .authenticatedByHttp(config.getAafUsername(), config.getAafPassword())); + } catch (MalformedURLException | GeneralSecurityException e) { + return null; + } + } + + private static CambriaTopicManager unAuthenticatedCambriaCLientBuilder(Configuration config) { + try { + return buildCambriaClient(new TopicManagerBuilder().usingHosts(config.getDmaapServers())); + } catch (MalformedURLException | GeneralSecurityException e) { + return null; + + } + } + + @SuppressWarnings("unchecked") + private static <T extends CambriaClient> T buildCambriaClient( + CambriaClientBuilders.AbstractAuthenticatedManagerBuilder<? extends CambriaClient> client) + throws MalformedURLException, GeneralSecurityException { + return (T) client.build(); + } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java index 2fe478e..c46d912 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java @@ -24,7 +24,6 @@ package org.onap.dcaegen2.services.sonhms.utils; import java.util.Collections; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -37,8 +36,6 @@ import org.springframework.web.client.RestTemplate; @Component public class SonHandlerRestTemplate { - @Autowired - static RestTemplate restTemplate; private static final String AUTH = "Authorization"; private static final String EXCEPTION_MSG = "Exception caught during request {}"; @@ -59,6 +56,7 @@ public class SonHandlerRestTemplate { headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); try { + RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class); return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); } catch (Exception e) { log.debug(EXCEPTION_MSG, e.getMessage()); @@ -66,25 +64,6 @@ public class SonHandlerRestTemplate { } } - /** - * Send Post Request to policy. - */ - public static <T> ResponseEntity<T> sendPostToPolicy(String requestUrl, String requestBody, - ParameterizedTypeReference<T> responseType) { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.add("ClientAuth", "cHl0aG9uOnRlc3Q="); - headers.add(AUTH, "Basic dGVzdHBkcDphbHBoYTEyMw== "); - headers.add("Environment", "TEST"); - HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); - try { - return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); - } catch (Exception e) { - log.debug(EXCEPTION_MSG, e.getMessage()); - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } - } /** * Send Get Request. @@ -95,6 +74,7 @@ public class SonHandlerRestTemplate { headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); HttpEntity<Void> requestEntity = new HttpEntity<>(headers); try { + RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class); return restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, responseType); } catch (Exception e) { log.debug(EXCEPTION_MSG, e.getMessage()); @@ -114,6 +94,7 @@ public class SonHandlerRestTemplate { headers.add(AUTH, "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA=="); HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); try { + RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class); return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); } catch (Exception e) { log.debug(EXCEPTION_MSG, e.getMessage()); @@ -133,9 +114,10 @@ public class SonHandlerRestTemplate { headers.add(AUTH, "Basic cGNpX3Rlc3Q6cGNpX3Rlc3Rwd2Q="); HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); try { + RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class); return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); } catch (Exception e) { - log.debug(EXCEPTION_MSG, e.getMessage()); + log.debug(EXCEPTION_MSG, e); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java index 78722ba..96b1a24 100644 --- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java +++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ThreadUtils.java @@ -20,16 +20,19 @@ package org.onap.dcaegen2.services.sonhms.utils; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import org.onap.dcaegen2.services.sonhms.EventHandler; +import org.onap.dcaegen2.services.sonhms.HoMetricsComponent; import org.onap.dcaegen2.services.sonhms.child.ChildThread; import org.onap.dcaegen2.services.sonhms.child.Graph; -import org.onap.dcaegen2.services.sonhms.model.FapServiceList; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.ThreadId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,13 +47,17 @@ public class ThreadUtils { * Create thread. */ public Boolean createNewThread(List<Graph> newClusters, BlockingQueue<List<String>> childStatusQueue, - ExecutorService pool, EventHandler eventHandler) { + ExecutorService pool, EventHandler eventHandler,String cellId) { + + for (Graph cluster : newClusters) { - BlockingQueue<FapServiceList> queue = new LinkedBlockingQueue<>(); + BlockingQueue<Map<CellPciPair, ArrayList<CellPciPair>>> queue = new LinkedBlockingQueue<>(); ThreadId threadId = new ThreadId(); threadId.setChildThreadId(0); - ChildThread child = new ChildThread(childStatusQueue, cluster, queue, threadId); + ChildThread child = new ChildThread(childStatusQueue, cluster, queue, threadId, new HoMetricsComponent()); + + log.info("Creating new child thread"); pool.execute(child); waitForThreadId(threadId); UUID clusterId = UUID.randomUUID(); @@ -75,7 +82,7 @@ public class ThreadUtils { } } catch (InterruptedException e) { - log.error("ChildThread queue error {}", e); + log.error("ChildThread queue error {}", e); Thread.currentThread().interrupt(); } } |