Beispiel #1
0
 private void prepare() {
   int offset = 0;
   int step = 1000;
   while (offset < total) {
     SimpleQuery<ApplianceVmFirewallRuleVO> q =
         dbf.createQuery(ApplianceVmFirewallRuleVO.class);
     q.add(ApplianceVmFirewallRuleVO_.applianceVmUuid, Op.EQ, self.getUuid());
     q.setLimit(step);
     q.setStart(offset);
     List<ApplianceVmFirewallRuleVO> vos = q.list();
     for (ApplianceVmFirewallRuleVO vo : vos) {
       String key =
           String.format(
               "%s-%s-%s-%s-%s",
               vo.getL3NetworkUuid(),
               vo.getProtocol(),
               vo.getSourceIp(),
               vo.getDestIp(),
               vo.getAllowCidr());
       List<ApplianceVmFirewallRuleVO> lst = rules.get(key);
       if (lst == null) {
         lst = new ArrayList<ApplianceVmFirewallRuleVO>();
         rules.put(key, lst);
       }
       lst.add(vo);
     }
     offset += step;
   }
 }
Beispiel #2
0
      private void normalize(List<ApplianceVmFirewallRuleVO> vos) {
        String l3Uuid = null;
        String sip = null;
        String dip = null;
        String allowedCidr = null;
        ApplianceVmFirewallProtocol protocol = null;

        RangeSet rset = new RangeSet();
        for (ApplianceVmFirewallRuleVO vo : vos) {
          if (l3Uuid == null) {
            l3Uuid = vo.getL3NetworkUuid();
          }
          if (sip == null) {
            sip = vo.getSourceIp();
          }
          if (dip == null) {
            dip = vo.getDestIp();
          }
          if (allowedCidr == null) {
            allowedCidr = vo.getAllowCidr();
          }
          if (protocol == null) {
            protocol = vo.getProtocol();
          }
          rset.closed(vo.getStartPort(), vo.getEndPort());
        }

        List<Range> rs = rset.merge();
        for (Range r : rs) {
          ApplianceVmFirewallRuleTO to = new ApplianceVmFirewallRuleTO();
          to.setDestIp(dip);
          to.setNicMac(l3NicMacMap.get(l3Uuid));
          to.setProtocol(protocol.toString());
          to.setAllowCidr(allowedCidr);
          to.setSourceIp(sip);
          to.setStartPort((int) r.getStart());
          to.setEndPort((int) r.getEnd());
          result.add(to);
        }
      }