/** * 判断是否超出策略阀值 * * @param policyType 1:系统功耗,2:CPU功耗,3:内存功耗,4:进风口温度 * @param policyLimt 阀值 * @return * @author zhangjh 新增日期:2012-9-5 * @since ipmi_task */ private boolean overPolicyLimit(SerInfo ser, int policyType, int policyLimt) { int current = 0; if (policyType == 4) { CompositeConfiguration conf = Config.getConfig(); GobblerServer gobblerServer = new GobblerServer( conf.getString("gobbler.host"), conf.getString("gobbler.user"), conf.getString("gobbler.passwd")); current = ipmiSensor.getTempSensorReading(ser, gobblerServer, Parameter.InletTemp); } else { PowerReading p = ipmiPower.getPlatformPowerReading(ser, policyType2Domain(policyType)); current = p.getCurrent(); } if (current >= policyLimt) { logger.info( "4.[" + ser.getHost() + "]的当前" + policyType2Name(policyType) + "为<" + current + ">,阀值为<" + policyLimt + ">,已超过阀值."); return true; } else { logger.info( "4.[" + ser.getHost() + "]的当前" + policyType2Name(policyType) + "为<" + current + ">,阀值为<" + policyLimt + ">,未超过阀值,退出."); return false; } }
/** * 判断服务器的当前值是否大于阀值,是则打开策略,降低功耗 * * @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.启动绑定该策略的所有服务器(前提超过阀值),完毕!"); }