private void markExternalPoliciesAsDisabled(List<PolicyUnit> units) {
   for (PolicyUnit policyUnit : units) {
     if (!policyUnit.isInternal()) {
       policyUnit.setEnabled(false);
       getPolicyUnitDao().update(policyUnit);
     }
   }
 }
 private void sendToDb(
     ExternalSchedulerDiscoveryUnit discovery, Guid policyUnitId, PolicyUnitType type) {
   PolicyUnit policy = createFromDiscoveryUnit(discovery, type);
   if (policyUnitId != null) {
     policy.setId(policyUnitId);
     getPolicyUnitDao().update(policy);
   } else {
     policy.setId(Guid.newGuid());
     getPolicyUnitDao().save(policy);
   }
 }
  private PolicyUnit compareToDB(
      List<PolicyUnit> dbEnteries,
      ExternalSchedulerDiscoveryUnit discoveryUnit,
      PolicyUnitType type) {
    for (PolicyUnit policyUnit : dbEnteries) {
      if (policyUnit.isInternal()) {
        continue;
      }

      if (policyUnit.getPolicyUnitType() != type) {
        continue;
      }

      if (!policyUnit.getName().equals(discoveryUnit.getName())) {
        continue;
      }

      Map<String, String> discoveryPropMap =
          StringUtils.isEmpty(discoveryUnit.getRegex())
              ? new LinkedHashMap<String, String>()
              : SimpleCustomPropertiesUtil.getInstance()
                  .convertProperties(discoveryUnit.getRegex());
      if (!discoveryPropMap.equals(policyUnit.getParameterRegExMap())
          || !discoveryUnit.getDescription().equals(policyUnit.getDescription())
          || !policyUnit.isEnabled()) {
        sendToDb(discoveryUnit, policyUnit.getId(), type);
      }

      return policyUnit;
    }
    sendToDb(discoveryUnit, null, type);
    return null;
  }
Exemplo n.º 4
0
 private void fillClusterPolicy(
     Map<Guid, ClusterPolicy> map, List<ClusterPolicyUnit> clusterPolicyUnits) {
   Map<Guid, PolicyUnit> policyUnitMap = new HashMap<Guid, PolicyUnit>();
   for (PolicyUnit policyUnit : policyUnitDao.getAll()) {
     policyUnitMap.put(policyUnit.getId(), policyUnit);
   }
   for (ClusterPolicyUnit clusterPolicyUnit : clusterPolicyUnits) {
     ClusterPolicy clusterPolicy = map.get(clusterPolicyUnit.getClusterPolicyId());
     if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType()
         == PolicyUnitType.FILTER) {
       if (clusterPolicy.getFilters() == null) {
         clusterPolicy.setFilters(new ArrayList<Guid>());
       }
       clusterPolicy.getFilters().add(clusterPolicyUnit.getPolicyUnitId());
       if (clusterPolicyUnit.getFilterSequence() != 0) {
         if (clusterPolicy.getFilterPositionMap() == null) {
           clusterPolicy.setFilterPositionMap(new HashMap<Guid, Integer>());
         }
         clusterPolicy
             .getFilterPositionMap()
             .put(clusterPolicyUnit.getPolicyUnitId(), clusterPolicyUnit.getFilterSequence());
       }
     }
     if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType()
         == PolicyUnitType.WEIGHT) {
       if (clusterPolicy.getFunctions() == null) {
         clusterPolicy.setFunctions(new ArrayList<Pair<Guid, Integer>>());
       }
       clusterPolicy
           .getFunctions()
           .add(
               new Pair<Guid, Integer>(
                   clusterPolicyUnit.getPolicyUnitId(), clusterPolicyUnit.getFactor()));
     }
     if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType()
         == PolicyUnitType.LOAD_BALANCING) {
       clusterPolicy.setBalance(clusterPolicyUnit.getPolicyUnitId());
     }
   }
 }
 private PolicyUnit createFromDiscoveryUnit(
     ExternalSchedulerDiscoveryUnit discoveryUnit, PolicyUnitType type) {
   PolicyUnit policy = new PolicyUnit();
   policy.setInternal(false);
   policy.setName(discoveryUnit.getName());
   policy.setPolicyUnitType(type);
   policy.setDescription(discoveryUnit.getDescription());
   if (!StringUtils.isEmpty(discoveryUnit.getRegex())) {
     policy.setParameterRegExMap(
         SimpleCustomPropertiesUtil.getInstance().convertProperties(discoveryUnit.getRegex()));
   } else {
     policy.setParameterRegExMap(new LinkedHashMap<String, String>());
   }
   return policy;
 }