Пример #1
0
 private static void reloadMachineConfig(String configDir) throws Exception {
   File configFile = new File(configDir, "machine.json");
   if (configFile.exists()) {
     machineMap.clear();
     logger.info("load config from:" + configFile.getAbsolutePath());
     String ss = FileUtil.getContent(configFile);
     List<Machine> machines = JSONUtil.fromJsonList(ss, Machine.class);
     machines.forEach(in -> machineMap.put(in.id, in));
   } else {
     logErrorMessage("can not find :" + configFile);
   }
 }
Пример #2
0
 private static void reloadUserConfig(String configDir) throws Exception {
   File configFile = new File(configDir, "user.json");
   if (configFile.exists()) {
     userMap.clear();
     logger.info("load user from:" + configFile.getAbsolutePath());
     String ss = FileUtil.getContent(configFile);
     List<User> apps = JSONUtil.fromJsonList(ss, User.class);
     apps.forEach(
         in -> {
           userMap.put(in.id, in);
         });
   } else {
     logErrorMessage("can not find :" + configFile);
   }
 }
Пример #3
0
 private static void reloadInstanceConfig(String configDir) throws Exception {
   File configFile = new File(configDir, "instance.json");
   if (configFile.exists()) {
     instanceMap.clear();
     logger.info("load config from:" + configFile.getAbsolutePath());
     String ss = FileUtil.getContent(configFile);
     List<Instance> instances = JSONUtil.fromJsonList(ss, Instance.class);
     AtomicInteger ai = new AtomicInteger();
     instances.forEach(
         in -> {
           if (in.user == null) {
             in.user = ("");
           }
           if (in.password == null) {
             in.password = ("");
           }
           if (in.packageVersion == null) {
             in.packageVersion = ("1.0.0");
           }
           in.priority = (ai.incrementAndGet());
           Machine m = machineMap.get(in.machineId);
           if (m == null) {
             logErrorMessage(
                 "can not find machine " + in.machineId + " for instance " + in.id + "");
           } else {
             in.machine = (m);
           }
           Application app = applicationMap.get(in.appId);
           if (app == null) {
             logErrorMessage(
                 "can not find application " + in.appId + " for instance " + in.id + "");
           } else {
             in.application = (app);
           }
           instanceMap.put(in.id, in);
         });
   } else {
     logErrorMessage("can not find :" + configFile);
   }
 }
Пример #4
0
 public static void saveInstanceConfig() throws Exception {
   String configDir = workSpaceDir;
   configDir += "config";
   File configFile = new File(configDir, "instance.json");
   List<Instance> list = getInstances();
   Collections.sort(list, (o1, o2) -> o1.priority - o2.priority);
   if (configFile.exists()) {
     String result =
         JSONUtil.toJson(
             list,
             new JSONPropertyFilter() {
               @Override
               public boolean apply(Object arg0, String name, Object arg2) {
                 if (name.equals("alive") || name.equals("machine") || name.equals("priority")) {
                   return false;
                 }
                 return true;
               }
             },
             true);
     FileUtil.saveContent(result, configFile);
   }
 }