/** * Loads all the files in the given folder */ protected <T extends HasMetadata> List<T> loadFiles(File folder, Class<T> clazz) { List<T> answer = new ArrayList<>(); File[] files = folder.listFiles(); if (files != null) { for (File file : files) { String name = file.getName().toLowerCase(); if (file.isFile() && name.endsWith(".json")) { Object value = null; try { value = KubernetesHelper.loadJson(file); } catch (IOException e) { LOG.warn("Failed to load JSON file " + file + ". " + e, e); } if (value != null) { if (clazz.isInstance(value)) { T cast = clazz.cast(value); answer.add(cast); } else { LOG.warn("Ignoring instance " + value + " of type " + value.getClass().getName() + " when expecting instance of " + clazz.getName() + " from file " + file); } } } } } return answer; }
/** * Loads all the files in the given folder */ protected <T extends HasMetadata> List<T> loadFiles(File folder, Class<T> clazz) { List<T> answer = new ArrayList<>(); File[] files = folder.listFiles(); if (files != null) { for (File file : files) { String name = file.getName().toLowerCase(); if (file.isFile() && name.endsWith(".json")) { Object value = null; try { value = KubernetesHelper.loadJson(file); } catch (IOException e) { LOG.warn("Failed to load JSON file " + file + ". " + e, e); } if (value != null) { if (clazz.isInstance(value)) { T cast = clazz.cast(value); answer.add(cast); } else { LOG.warn("Ignoring instance " + value + " of type " + value.getClass().getName() + " when expecting instance of " + clazz.getName() + " from file " + file); } } } } } return answer; }
public static KubernetesNames loadFile(File kubernetesJsonOrYamlFile) throws IOException { KubernetesNames answer = new KubernetesNames(); if (kubernetesJsonOrYamlFile.isFile() && kubernetesJsonOrYamlFile.exists()) { Object value = KubernetesHelper.loadJson(kubernetesJsonOrYamlFile); if (value != null) { answer.addNamesFromDTO(value); } } return answer; }
public void loadDependency(Logger log, List<Config> kubeConfigs, String dependency) throws IOException { // lets test if the dependency is a local string String baseDir = System.getProperty("basedir", "."); String path = baseDir + "/" + dependency; File file = new File(path); if (file.exists()) { loadDependency(log, kubeConfigs, file); } else { addConfig(kubeConfigs, loadJson(readAsString(new URL(dependency)))); } }
protected void loadDependency(Logger log, List<Config> kubeConfigs, File file) throws IOException { if (file.isFile()) { log.info("Loading file " + file); addConfig(kubeConfigs, loadJson(file)); } else { File[] children = file.listFiles(); if (children != null) { for (File child : children) { String name = child.getName().toLowerCase(); if (name.endsWith(".json") || name.endsWith(".yaml")) { loadDependency(log, kubeConfigs, child); } } } } }
protected void loadDependency(Logger log, List<KubernetesList> kubeConfigs, File file, Controller controller, Configuration configuration, Logger logger, String namespace) throws IOException { if (file.isFile()) { log.info("Loading file " + file); Object content; if (file.getName().endsWith(".yaml") || file.getName().endsWith(".yml")) { content = loadYaml(file); } else { content = loadJson(file); } addConfig(kubeConfigs, content, controller, configuration, log, namespace, file.getPath()); } else { File[] children = file.listFiles(); if (children != null) { for (File child : children) { String name = child.getName().toLowerCase(); if (name.endsWith(".json") || name.endsWith(".yaml") || name.endsWith(".yml")) { loadDependency(log, kubeConfigs, child, controller, configuration, log, namespace); } } } } }
public void loadDependency(Logger log, List<KubernetesList> kubeConfigs, String dependency, Controller controller, Configuration configuration, String namespace) throws Exception { // lets test if the dependency is a local string String baseDir = System.getProperty("basedir", "."); String path = baseDir + "/" + dependency; File file = new File(path); if (file.exists()) { loadDependency(log, kubeConfigs, file, controller, configuration, log, namespace); } else { String text = readAsString(createURL(dependency)); Object resources; if (text.trim().startsWith("---") || dependency.endsWith(".yml") || dependency.endsWith(".yaml")) { resources = loadYaml(text); } else { resources = loadJson(text); } addConfig(kubeConfigs, resources, controller, configuration, log, namespace, dependency); } }
Object dto = KubernetesHelper.loadJson(data); updateLocalModel(dto, remove); } catch (Exception e) {
kubeConfigs.add((Config) loadJson(readAsString(configuration.getConfigUrl())));
dto = loadYaml(configText, KubernetesResource.class); } else { dto = loadJson(configText);
dto = KubernetesHelper.loadJson(resources); } else { dto = KubernetesHelper.loadYaml(resources.getBytes(), KubernetesResource.class);
dto = KubernetesHelper.loadJson(resources); } else { dto = KubernetesHelper.loadYaml(resources.getBytes(), KubernetesResource.class);