diff options
author | Ramya Ravichandran <ramya.ravichandran5@wipro.com> | 2019-02-15 16:26:45 +0530 |
---|---|---|
committer | Ramya Ravichandran <ramya.ravichandran5@wipro.com> | 2019-02-15 16:28:41 +0530 |
commit | 43467ecc6a1624b7fd695883c5c6c214782f6bcd (patch) | |
tree | 13d9bc07475d63fb1e29e44b7e82b33c54df09e7 /src/main/java/com/wipro/www/sonhms/child/ClusterFormation.java | |
parent | 8b5b35c5a7dfe7213e0d1ef824fc7ae5b6c82758 (diff) |
Son-handler microservice seed code
Change-Id: If4000e26044fe267bdd5fae3a1b2599182423950
Issue-ID: DCAEGEN2-1219
Signed-off-by: Ramya Ravichandran<ramya.ravichandran5@wipro.com>
Diffstat (limited to 'src/main/java/com/wipro/www/sonhms/child/ClusterFormation.java')
-rw-r--r-- | src/main/java/com/wipro/www/sonhms/child/ClusterFormation.java | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/src/main/java/com/wipro/www/sonhms/child/ClusterFormation.java b/src/main/java/com/wipro/www/sonhms/child/ClusterFormation.java new file mode 100644 index 0000000..7b3d5bf --- /dev/null +++ b/src/main/java/com/wipro/www/sonhms/child/ClusterFormation.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * ============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 com.wipro.www.sonhms.child; + +import com.wipro.www.sonhms.ConfigPolicy; +import com.wipro.www.sonhms.Configuration; +import com.wipro.www.sonhms.dao.ClusterDetailsRepository; +import com.wipro.www.sonhms.entity.ClusterDetails; +import com.wipro.www.sonhms.model.FapServiceList; +import com.wipro.www.sonhms.utils.BeanUtil; + +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.slf4j.Logger; + + +public class ClusterFormation { + + private static final Logger log = org.slf4j.LoggerFactory.getLogger(ClusterFormation.class); + private BlockingQueue<FapServiceList> queue; + private ClusterModification clusterModification; + 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.clusterModification = new ClusterModification(); + } + + /** + * 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 = clusterModification.clustermod(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; + } + +} |