2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
 
   7  * ================================================================================
 
   8  * Licensed under the Apache License, Version 2.0 (the "License");
 
   9  * you may not use this file except in compliance with the License.
 
  10  * You may obtain a copy of the License at
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  14  * Unless required by applicable law or agreed to in writing, software
 
  15  * distributed under the License is distributed on an "AS IS" BASIS,
 
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  17  * See the License for the specific language governing permissions and
 
  18  * limitations under the License.
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.ccsdk.sli.adaptors.ra.pref;
 
  24 import java.util.ArrayList;
 
  25 import java.util.List;
 
  27 import org.onap.ccsdk.sli.adaptors.ra.comp.PreferenceRule;
 
  28 import org.onap.ccsdk.sli.adaptors.ra.comp.ServiceData;
 
  29 import org.onap.ccsdk.sli.adaptors.ra.equip.data.EquipmentData;
 
  30 import org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManager;
 
  31 import org.onap.ccsdk.sli.adaptors.rm.data.LimitResource;
 
  32 import org.onap.ccsdk.sli.adaptors.rm.data.Resource;
 
  33 import org.slf4j.Logger;
 
  34 import org.slf4j.LoggerFactory;
 
  36 public class AffinityLinkPref implements PreferenceRule {
 
  38     private static final Logger log = LoggerFactory.getLogger(AffinityLinkPref.class);
 
  40     private ResourceManager resourceManager;
 
  41     private List<String> affinityLinkIdList;
 
  43     public AffinityLinkPref() {
 
  44         // Set default values for affinity link ids (can be overridden by the spring config)
 
  45         affinityLinkIdList = new ArrayList<>();
 
  46         affinityLinkIdList.add("1");
 
  47         affinityLinkIdList.add("2");
 
  51     public int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData) {
 
  53         // This class does not really assign order number, but instead sets the affinity link with the lowest
 
  54         // assigned bandwidth in the equipment data
 
  56         String preferedAffinityLinkId = "1";
 
  57         long lowestAssignedBw = Long.MAX_VALUE;
 
  58         for (String affinityLinkId : affinityLinkIdList) {
 
  59             String assetId = equipData.equipmentId + "-" + affinityLinkId;
 
  60             Resource r = resourceManager.getResource("Bandwidth", assetId);
 
  62                 LimitResource ll = (LimitResource) r;
 
  63                 if (ll.used < lowestAssignedBw) {
 
  64                     lowestAssignedBw = ll.used;
 
  65                     preferedAffinityLinkId = affinityLinkId;
 
  67                 log.info("Assigned bandwidth on affinity link: " + assetId + ": " + ll.used);
 
  71         equipData.data.put("affinity-link", preferedAffinityLinkId);
 
  73         log.info("Prefered affinity link for " + equipData.equipmentId + ": " + preferedAffinityLinkId);
 
  78     public void setResourceManager(ResourceManager resourceManager) {
 
  79         this.resourceManager = resourceManager;
 
  82     public void setAffinityLinkIdList(List<String> affinityLinkIdList) {
 
  83         this.affinityLinkIdList = affinityLinkIdList;