public static String getContent(File file, Function<JsonNode, String> edit) { YAMLMapper mapper = new YAMLMapper(); try { JsonNode node = mapper.readTree(file); return edit.apply(node); } catch (IOException e) { throw new RuntimeException(e); } }
private void readTags(String fileName, StringBuffer template) throws FileNotFoundException, IOException { File resourceFile = new File(path, fileName); if(resourceFile.exists()){ try (InputStream inputStream = new FileInputStream(resourceFile)) { String contents = IOUtils.toString(inputStream); YAMLMapper mapper = new YAMLMapper(new YAMLFactory()); JsonNode node = mapper.readTree(contents); JsonNode resourcesNode = node.get("Tags"); String jsonAsYaml = new YAMLMapper().writeValueAsString(resourcesNode); String[] resourceLines=jsonAsYaml.split("\n"); for(String line:resourceLines){ if(!line.contains("---")){ template.append(""+line+"\n "); } } } } }
public static String changeDeploymentNamespaceUpgrade(File deploymentFile, String namespace) { YAMLMapper mapper = new YAMLMapper(); try { JsonNode node = mapper.readTree(deploymentFile); // Change the docker org of the images in the 050-deployment.yaml ObjectNode containerNode = (ObjectNode) node.at("/spec/template/spec/containers").get(0); for (JsonNode envVar : containerNode.get("env")) { String varName = envVar.get("name").textValue(); if (varName.matches("STRIMZI_NAMESPACE")) { // Replace all the default images with ones from the $DOCKER_ORG org and with the $DOCKER_TAG tag ((ObjectNode) envVar).remove("valueFrom"); ((ObjectNode) envVar).put("value", namespace); } } return mapper.writeValueAsString(node); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Changes the {@code subject} of the RoleBinding in the given YAML resource to be the * {@code strimzi-cluster-operator} {@code ServiceAccount} in the given namespace. * @param roleBindingFile * @param namespace * @return role */ public static String changeRoleBindingSubject(File roleBindingFile, String namespace) { YAMLMapper mapper = new YAMLMapper(); try { JsonNode node = mapper.readTree(roleBindingFile); ArrayNode subjects = (ArrayNode) node.get("subjects"); ObjectNode subject = (ObjectNode) subjects.get(0); subject.put("kind", "ServiceAccount") .put("name", "strimzi-cluster-operator") .put("namespace", namespace); return mapper.writeValueAsString(node); } catch (IOException e) { throw new RuntimeException(e); } }
contents = tempresult.toString(); YAMLMapper mapper = new YAMLMapper(new YAMLFactory()); JsonNode node = mapper.readTree(contents); JsonNode outputNode=node.get("Outputs"); if(outputNode!=null){