Ejemplo n.º 1
0
 public void registerAndPush(int configId, int envId) {
   Config config = getConfig(configId);
   if (config == null) {
     throw new EntityNotFoundException("config[id=" + configId + "] not found, maybe deleted.");
   }
   ConfigInstance defaultInst = findDefaultInstance(configId, envId);
   if (defaultInst == null) {
     throw new RuntimeBusinessException("该环境下配置项不存在!");
   }
   try {
     ConfigRegisterService registerService = getRegisterService(envId);
     // register context value需要放在register default value前面,重要的操作在后面,确保zk与db数据一致,大部分配置无context value
     // 第一个注册操作就需要push,第二个不需要,确保第一个操作时客户端感知到变化时就已经感知到了push事务
     registerService.registerAndPushContextValue(
         config.getKey(), getConfigContextValue(configId, envId));
     registerService.registerDefaultValue(
         config.getKey(), resolveConfigFinalValue(defaultInst.getValue(), envId));
   } catch (RuntimeException e) {
     Environment environment = environmentService.findEnvByID(envId);
     logger.error(
         "Register and push config["
             + config.getKey()
             + "] to env["
             + (environment != null ? environment.getLabel() : envId)
             + "] failed.",
         e);
     throw e;
   }
 }