List of usage examples for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory
public YAMLFactory()
From source file:pl.betoncraft.betonquest.editor.model.PackageSet.java
private static PackageSet parseStreams(String setName, HashMap<String, HashMap<String, InputStream>> streamMap) throws IOException { PackageSet set = new PackageSet(setName); for (Entry<String, HashMap<String, InputStream>> entry : streamMap.entrySet()) { String packName = entry.getKey(); HashMap<String, LinkedHashMap<String, String>> values = new LinkedHashMap<>(); for (Entry<String, InputStream> subEntry : entry.getValue().entrySet()) { String name = subEntry.getKey(); InputStream stream = subEntry.getValue(); YAMLParser parser = new YAMLFactory().createParser(stream); String currentPath = ""; String fieldName = ""; while (true) { JsonToken token = parser.nextToken(); if (token == null) break; switch (token) { case START_OBJECT: currentPath = currentPath + fieldName + "."; break; case FIELD_NAME: fieldName = parser.getText(); break; case END_OBJECT: currentPath = currentPath.substring(0, currentPath.substring(0, currentPath.length() - 1).lastIndexOf(".") + 1); break; case VALUE_STRING: case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: case VALUE_FALSE: case VALUE_TRUE: String key = (currentPath + fieldName).substring(1, currentPath.length() + fieldName.length()); LinkedHashMap<String, String> map = values.get(name); if (map == null) { map = new LinkedHashMap<>(); values.put(name, map); }/*from w ww . ja v a 2 s. c o m*/ map.put(key, parser.getText()); default: // do nothing } } parser.close(); stream.close(); } QuestPackage pack = new QuestPackage(set, packName, values); set.packages.add(pack); } return set; }
From source file:de.qaware.cloud.deployer.commons.config.util.ContentTreeUtil.java
/** * Returns the object mapper for the specified content type. * * @param contentType The content type.//from w ww .ja va 2s. c o m * @return The object mapper. * @throws ResourceConfigException If the specified content type is unsupported. */ private static ObjectMapper retrieveObjectMapper(ContentType contentType) throws ResourceConfigException { ObjectMapper mapper; switch (contentType) { case YAML: mapper = new ObjectMapper(new YAMLFactory()); break; case JSON: mapper = new ObjectMapper(new JsonFactory()); break; default: throw new ResourceConfigException( COMMONS_MESSAGE_BUNDLE.getMessage("DEPLOYER_COMMONS_ERROR_UNSUPPORTED_CONTENT_TYPE")); } return mapper; }
From source file:org.robotbrains.data.cloud.timeseries.server.ServerMain.java
/** * Read the configuration./*from ww w. jav a 2 s. c o m*/ * * @return the configuration * * @throws Exception * was unable to read the configuration file or could not parse the * configuration */ private Map<String, String> readConfiguration(CommandLine cmd) throws Exception { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); @SuppressWarnings("unchecked") Map<String, String> configuration = mapper.readValue(new File(cmd.getOptionValue(COMMAND_ARG_CONFIG)), Map.class); return configuration; }
From source file:com.exalttech.trex.util.TrafficProfile.java
/** * @param yamlFile File containing the Traffic Profile Yaml. * @return parsed Yaml file// www. j av a 2 s . c o m * @throws java.io.IOException */ public Profile[] getTrafficProfile(File yamlFile) throws IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); Profile[] trafficProfileArray = mapper.readValue(yamlFile, Profile[].class); int i = 0; for (Profile profile : trafficProfileArray) { Map<String, Object> streamAdditionalProperties = profile.getStream().getAdditionalProperties(); if (streamAdditionalProperties.containsKey("vm")) { profile.getStream().setVmRaw(streamAdditionalProperties.get("vm").toString()); } if (streamAdditionalProperties.containsKey("rx_stats")) { profile.getStream().setRxStatsRaw(streamAdditionalProperties.get("rx_stats").toString()); } // Check the Binary is in the Yaml File if (profile.getStream().getPacket().getBinary() == null) { String absolutePath = yamlFile.getAbsolutePath(); String filePath = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator)); String pacpFile = profile.getStream().getPacket().getPcap(); String encodedPcap = encodePcapFile(filePath + File.separator + pacpFile); profile.getStream().getPacket().setBinary(encodedPcap); } profile.getStream().getPacket().setPcap(null); if (profile.getName() == null) { profile.setName("Stream" + i++); } } return trafficProfileArray; }
From source file:io.fabric8.maven.enricher.standard.DependencyEnricher.java
private void processArtifactSetResources(Set<URL> artifactSet, Function<List<HasMetadata>, Void> function) { for (URL url : artifactSet) { try {/*from w ww . j av a2 s . c o m*/ InputStream is = url.openStream(); if (is != null) { log.debug("Processing Kubernetes YAML in at: %s", url); KubernetesList resources = new ObjectMapper(new YAMLFactory()).readValue(is, KubernetesList.class); List<HasMetadata> items = notNullList(resources.getItems()); if (items.size() == 0 && Objects.equals("Template", resources.getKind())) { is = url.openStream(); Template template = new ObjectMapper(new YAMLFactory()).readValue(is, Template.class); if (template != null) { items.add(template); } } for (HasMetadata item : items) { KubernetesResourceUtil.setSourceUrlAnnotationIfNotSet(item, url.toString()); log.debug(" found %s %s", getKind(item), KubernetesHelper.getName(item)); } function.apply(items); } } catch (IOException e) { getLog().debug("Skipping %s: %s", url, e); } } }
From source file:com.googlecode.blaisemath.app.MenuConfig.java
/** * Reads menu components from file./*from www .ja v a2s . c om*/ * @param cls class with associated resource * @return map, where values are either nested maps, or lists of strings representing actions * @throws IOException if there's an error reading from the config file */ public static Map<String, Object> readConfig(Class cls) throws IOException { String path = "resources/" + cls.getSimpleName() + MENU_SUFFIX + ".yml"; URL rsc = cls.getResource(path); checkNotNull(rsc, "Failed to locate " + path); ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); return mapper.readValue(rsc, Map.class); }
From source file:io.helixservice.feature.configuration.dynamo.DynamoConfigResourceLocator.java
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") private Optional<InputStream> getPropertiesFromDynamoDB(String resourcePath, Optional<InputStream> pResult) { Optional<InputStream> result = pResult; String environmentName = resourcePath.substring(0, resourcePath.lastIndexOf(APPLICATION_YAML_FILE)); try {// www .j a va 2s .c o m Item item = configTable.getItem("environment", environmentName, "service", serviceName); if (item == null) { LOG.info("No configuration found for environment=" + environmentName + "; creating default empty configuration"); createEmptyConfiguration(environmentName); } else { String json = item.toJSON(); JSONObject jsonObject = new JSONObject(json); JSONObject config = jsonObject.getJSONObject("config"); ObjectMapper objectMapper = new ObjectMapper(); Map mapOfValues = objectMapper.readValue(config.toString(), Map.class); ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory()); String yamlResult = yamlObjectMapper.writeValueAsString(mapOfValues); result = Optional.of(new StringInputStream(yamlResult)); } } catch (Throwable t) { LOG.error("Unable to load configuration from DynamoDB for environment=" + environmentName, t); } return result; }
From source file:de.qaware.cloud.deployer.kubernetes.test.BaseKubernetesResourceTest.java
protected void testUpdate(UrlPattern instancePattern) throws ResourceException, IOException { // Prepare body JsonNode body;/*w w w .j a va2 s .c om*/ ContentType contentType = resource.getResourceConfig().getContentType(); String content = resource.getResourceConfig().getContent(); if (contentType == ContentType.YAML) { body = new ObjectMapper(new YAMLFactory()).readTree(content); } else if (contentType == ContentType.JSON) { body = new ObjectMapper(new JsonFactory()).readTree(content); } else { throw new IllegalArgumentException("Can't process this type of content"); } String jsonContent = new ObjectMapper(new JsonFactory()).writeValueAsString(body); // Update deployment instanceRule.stubFor(patch(instancePattern).withRequestBody(equalTo(jsonContent)) .withHeader("Content-Type", equalTo("application/merge-patch+json; charset=utf-8")) .willReturn(aResponse().withStatus(200))); resource.update(); // Verify calls instanceRule.verify(1, patchRequestedFor(instancePattern)); }
From source file:com.basistech.yca.FlatteningConfigFileManager.java
private void processAddOrUpdate(Path filename) { // create and modify look quite similar. Path child = configurationDirectory.resolve(filename); // The heck with content type probing, let's do this the simple way. int lastDot = filename.toString().lastIndexOf('.'); if (lastDot == -1) { LOG.info("File has no suffix; ignoring: " + child); return;/* w w w. j av a 2s .c o m*/ } ObjectMapper mapper; String suffix = filename.toString().substring(lastDot + 1); if ("json".equals(suffix) || "js".equals(suffix)) { mapper = new ObjectMapper(); } else if ("yaml".equals(suffix) || "yml".equals(suffix)) { mapper = new ObjectMapper(new YAMLFactory()); } else { LOG.error("Unsupported file name " + filename.toString()); return; } JsonNode content; try { content = mapper.readTree(child.toFile()); } catch (IOException e) { LOG.error("Failed to read contents of " + child, e); return; } @SuppressWarnings("unchecked") Dictionary<String, Object> dict = (Dictionary<String, Object>) JsonNodeFlattener.flatten(content); String pid[] = parsePid(filename); Configuration config; try { config = getConfiguration(toConfigKey(filename), pid[0], pid[1]); } catch (IOException e) { LOG.error("Failed to get configuration for " + formatPid(pid)); return; } Dictionary<String, Object> props = config.getProperties(); Hashtable<String, Object> old = null; if (props != null) { old = new Hashtable<>(new DictionaryAsMap<>(props)); } if (old != null) { old.remove(FILENAME_PROPERTY_KEY); old.remove(Constants.SERVICE_PID); old.remove(ConfigurationAdmin.SERVICE_FACTORYPID); } if (!dict.equals(old)) { dict.put(FILENAME_PROPERTY_KEY, toConfigKey(filename)); if (old == null) { LOG.info("Creating configuration from " + filename); } else { LOG.info("Updating configuration from " + filename); } try { config.update(dict); } catch (IOException e) { LOG.error("Failed to update configuration for " + formatPid(pid)); } } }
From source file:org.mayocat.application.AbstractService.java
protected void configureObjectMapper() { // Initialize our own object mapper. We don't want to use Dropwizard's one (environment.getObjectMapper) because // we don't have full control over its initialization, and we don't necessarily want mayocat's one to be // configured identically as the one used by DW. objectMapper = new ObjectMapper(new YAMLFactory()); // Standard modules objectMapper.registerModule(new GuavaModule()); objectMapper.registerModule(new JodaModule()); objectMapper.registerModule(new AfterburnerModule()); // Dropwizard modules objectMapper.registerModule(new GuavaExtrasModule()); objectMapper.registerModule(new LogbackModule()); // Mayocat modules objectMapper.registerModule(new TimeZoneModule()); objectMapper.registerModule(new NIOModule()); objectMapper.registerModule(new MayocatJodaModule()); objectMapper.registerModule(new MayocatLocaleBCP47LanguageTagModule()); objectMapper.registerModule(new MayocatGroovyModule()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); }