Exemplo n.º 1
0
 public static void saveScript(String name, String content) throws IOException {
   File scriptFile = new File(workSpaceDir + "script/" + name);
   if (!scriptFile.exists()) {
     scriptFile.createNewFile();
   }
   FileUtil.saveContent(content, scriptFile);
 }
Exemplo n.º 2
0
 public static void saveConfigFile(String file, String value) {
   String configDir = workSpaceDir + "config";
   try {
     FileUtil.saveContent(value, new File(configDir, file));
     reload();
   } catch (IOException e) {
     logger.catching(e);
   }
 }
Exemplo n.º 3
0
 public static String getConfigFile(String file) {
   String configDir = workSpaceDir + "config";
   try {
     return FileUtil.getContent(new File(configDir, file));
   } catch (IOException e) {
     logger.catching(e);
     return null;
   }
 }
Exemplo n.º 4
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);
   }
 }
Exemplo n.º 5
0
 public static void saveTemplate(String appId, String value) {
   String templateDir = workSpaceDir;
   templateDir += "template";
   File file = new File(templateDir + "/" + appId + ".vm");
   try {
     if (!file.exists()) {
       file.createNewFile();
     }
     FileUtil.saveContent(value, file);
   } catch (Exception e) {
     logger.catching(e);
   }
 }
Exemplo n.º 6
0
 private static void createFile(String path) {
   try {
     logger.info("create new file {}", path);
     String s =
         IOUtil.getContent(DeployStartServlet.class.getResourceAsStream("workspace/" + path));
     File configFile = new File(workSpaceDir, path);
     if (!configFile.exists()) {
       configFile.createNewFile();
       FileUtil.saveContent(s, configFile);
     }
   } catch (IOException e) {
     logger.catching(e);
   }
 }
Exemplo n.º 7
0
 public static String getTemplate(String appId) {
   String templateDir = workSpaceDir;
   templateDir += "template";
   File file = new File(templateDir + "/" + appId + ".vm");
   if (!file.exists()) {
     return null;
   }
   try {
     return FileUtil.getContent(file);
   } catch (IOException e) {
     logger.catching(e);
     return null;
   }
 }
Exemplo n.º 8
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);
   }
 }
Exemplo n.º 9
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);
   }
 }
Exemplo n.º 10
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);
   }
 }
Exemplo n.º 11
0
 public static String getScript(String name) throws IOException {
   File scriptFile = new File(workSpaceDir + "script/" + name);
   return FileUtil.getContent(scriptFile);
 }