Пример #1
0
 /**
  * 关闭服务器上的策略
  *
  * @param serverList
  * @author zhangjh 新增日期:2012-9-5
  * @since ipmi_task
  */
 private void closePolicy(List<Object[]> serverList, TbPolicy p) {
   for (Object[] cc : serverList) {
     TbPolicySever serverPolicy = (TbPolicySever) cc[0];
     TbServer server = (TbServer) cc[1];
     SerInfo ser = new SerInfo();
     ser.setHost(server.getIdracIp());
     ser.setUser(server.getIdracUser());
     ser.setPasswd(server.getIdracPassword());
     PolicyEntity e =
         ipmiPolicy.getPolicyById(
             ser, serverPolicy.getPolicyidInServer(), policyType2Domain(p.getPolicyType()));
     if (e == null) {
       logger.info(
           "4.[" + ser.getHost() + "]的<" + serverPolicy.getPolicyidInServer() + ">策略未建立,不必关闭.");
       continue;
     }
     if (e.isPolicyEnabled()) {
       ipmiPolicy.setPolicyStatus(
           ser, serverPolicy.getPolicyidInServer(), false, policyType2Domain(p.getPolicyType()));
       logger.info(
           "4.设置["
               + ser.getHost()
               + "]的<"
               + p.getPolicyName()
               + ">("
               + policyType2Name(p.getPolicyType())
               + ")策略,策略ID为<"
               + e.getPolicyId()
               + ">,,策略状态设置为关闭.");
     }
     if (serverPolicy.getBiningState() != 0) {
       serverPolicy.setBiningType(e.getPolicyType());
       serverPolicy.setBiningState(0);
       policyServerDAO.saveOrUpdate(serverPolicy);
     }
   }
   logger.info("5.关闭绑定该策略的所有服务器,完毕!");
 }
Пример #2
0
  /**
   * 判断服务器的当前值是否大于阀值,是则打开策略,降低功耗
   *
   * @param serverList
   * @param p
   * @author zhangjh 新增日期:2012-9-5
   * @since ipmi_task
   */
  private void enablePolicy(List<Object[]> serverList, TbPolicy p) {
    for (Object[] cc : serverList) {
      TbPolicySever serverPolicy = (TbPolicySever) cc[0];
      TbServer server = (TbServer) cc[1];
      SerInfo ser = new SerInfo();
      ser.setHost(server.getIdracIp());
      ser.setUser(server.getIdracUser());
      ser.setPasswd(server.getIdracPassword());
      if (p.getPolicyType() == 4) {
        boolean isOver = overPolicyLimit(ser, p.getPolicyType(), p.getPolicyLimit());
        if (!isOver) {
          continue;
        }
      }
      PolicyEntity policyEntity =
          ipmiPolicy.getPolicyById(
              ser, serverPolicy.getPolicyidInServer(), policyType2Domain(p.getPolicyType()));

      if (policyEntity != null
          && p.getPolicyType() != 4
          && policyEntity.getPolicyLimit() == p.getPolicyLimit()
          && policyEntity.isPolicyEnabled()) {
        continue;
      }
      int policyLimit = p.getPolicyLimit();
      // 当为入风口温度策略时,把策略阀值降低到当前功耗的百分几
      if (p.getPolicyType() == 4) {
        PowerReading powerReading =
            ipmiPower.getPlatformPowerReading(ser, policyType2Domain(p.getPolicyType()));
        policyLimit = powerReading.getCurrent() * (100 - p.getPolicyBumber()) / 100;
      }
      if (policyEntity != null) {
        policyEntity.setPolicyEnabled(true);
        policyEntity.setPolicyLimit(policyLimit);
        policyEntity.setPolicyTriggerLimit(policyLimit);
      } else {
        policyEntity = new PolicyEntity();
        policyEntity.setPolicyId(serverPolicy.getPolicyidInServer());
        policyEntity.setPolicyType(Parameter.policyPower);
        policyEntity.setPolicyEnabled(true);
        policyEntity.setComponent(policyType2Domain(p.getPolicyType()));
        policyEntity.setSendAlert(false);
        policyEntity.setShutdown(false);
        policyEntity.setStatReportingPeriod(10);
        policyEntity.setCorrectionTime(1000L);
        policyEntity.setPolicyTriggerLimit(policyLimit);
        policyEntity.setPolicyLimit(policyLimit);
      }
      serverPolicy.setBiningType(policyEntity.getPolicyType());
      serverPolicy.setBiningState(1);
      policyServerDAO.saveOrUpdate(serverPolicy);
      ipmiPolicy.setPolicy(ser, policyEntity);
      logger.info(
          "5.设置["
              + ser.getHost()
              + "]的<"
              + p.getPolicyName()
              + ">("
              + policyType2Name(p.getPolicyType())
              + ")策略,策略ID为<"
              + policyEntity.getPolicyId()
              + ">,阀值设定为<"
              + policyEntity.getPolicyLimit()
              + ">,策略状态设置为开启.");
    }
    logger.info("6.启动绑定该策略的所有服务器(前提超过阀值),完毕!");
  }