List of usage examples for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory
public YAMLFactory()
From source file:org.opencb.opencga.analysis.execution.plugins.OpenCGAAnalysis.java
public static Manifest loadManifest(String identifier) throws IOException { final String file; JsonFactory factory;/* w ww . j ava 2s .c o m*/ if (OpenCGAAnalysis.class.getResource("/" + identifier + "/manifest.yml") != null) { file = "/" + identifier + "/manifest.yml"; factory = new YAMLFactory(); } else if (OpenCGAAnalysis.class.getResource("/" + identifier + "/manifest.json") != null) { file = "/" + identifier + "/manifest.json"; factory = new JsonFactory(); } else if (OpenCGAAnalysis.class.getResource("/" + identifier + "/manifest.xml") != null) { file = "/" + identifier + "/manifest.xml"; factory = new XmlFactory(); } else { return null; } try (InputStream stream = OpenCGAAnalysis.class.getResourceAsStream(file)) { return new ObjectMapper(factory).readValue(stream, Manifest.class); } }
From source file:org.opencb.opencga.app.cli.main.OpenCGAMainOld.java
private static SessionFile loadUserFile() throws IOException { java.io.File file = Paths.get(System.getProperty("user.home"), ".opencga", "opencga.yml").toFile(); if (file.exists()) { return new ObjectMapper(new YAMLFactory()).readValue(file, SessionFile.class); } else {/* ww w . ja v a 2 s .c o m*/ return new SessionFile(); } }
From source file:org.opencb.opencga.app.cli.main.OpenCGAMainOld.java
private static void saveUserFile(SessionFile sessionFile) throws IOException { Path opencgaDirectoryPath = Paths.get(System.getProperty("user.home"), ".opencga"); if (!opencgaDirectoryPath.toFile().exists()) { Files.createDirectory(opencgaDirectoryPath); }/* w ww.j a v a 2s . c o m*/ FileUtils.checkDirectory(opencgaDirectoryPath, true); java.io.File file = opencgaDirectoryPath.resolve("opencga.yml").toFile(); ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); objectMapper.writeValue(file, sessionFile); }
From source file:org.wso2.security.tools.advisorytool.AdvisoryTool.java
/** * Loading the released products list./*from ww w . j a v a2 s. c om*/ * * @param releasedProductFilePath * @throws AdvisoryToolException */ private static void loadReleasedProductsList(String releasedProductFilePath) throws AdvisoryToolException { ProductDataHolder releasedProductDataHolder = null; File file = new File(releasedProductFilePath); if (file.exists()) { try { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); releasedProductDataHolder = mapper.readValue(file, ProductDataHolder.class); } catch (IOException e) { throw new AdvisoryToolException("Error while loading " + releasedProductFilePath + " products file", e); } for (Product product : releasedProductDataHolder.getProductList()) { if (StringUtils.isEmpty(product.getName())) { throw new AdvisoryToolException("Missing product name in Products list"); } if (StringUtils.isEmpty(product.getCodeName())) { throw new AdvisoryToolException("Missing product codename in Products list"); } for (Version version : product.getVersionList()) { if (StringUtils.isEmpty(version.getVersionNumber())) { throw new AdvisoryToolException("Missing version number for the product " + product.getName() + " in Products list"); } if (StringUtils.isEmpty(version.getKernelVersionNumber())) { throw new AdvisoryToolException("Missing kernel version number for " + "the product" + product.getName() + " in Products list"); } if (StringUtils.isEmpty(version.getPlatformVersionNumber())) { throw new AdvisoryToolException("Missing platform version number for " + " the product" + product.getName() + " in Products list"); } if (StringUtils.isEmpty(version.getReleasedDate().toString())) { throw new AdvisoryToolException( "Missing released date for the product " + product.getName() + " in Products list"); } } } } else { throw new AdvisoryToolException("Products list file not found in: " + releasedProductFilePath); } ProductDataHolder.getInstance().setProductList(releasedProductDataHolder.getProductList()); }
From source file:org.wso2.security.tools.advisorytool.AdvisoryTool.java
/** * Reading the security-advisory-data.yaml * * @throws AdvisoryToolException//from ww w . j a v a2s .c om */ private static void loadSecurityAdvisoryListFromFile() throws AdvisoryToolException { try { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); SecurityAdvisoryData securityAdvisoryData = mapper .readValue(new File(Constants.SECURITY_ADVISORY_DATA_FILE), SecurityAdvisoryData.class); for (SecurityAdvisory securityAdvisory : securityAdvisoryData.getAdvisories()) { if (StringUtils.isEmpty(securityAdvisory.getName())) { throw new AdvisoryToolException("Security Advisory name cannot be empty."); } if (StringUtils.isEmpty(securityAdvisory.getTitle())) { if (StringUtils.isEmpty(securityAdvisoryData.getTitle())) { // throw new AdvisoryToolException("Security Advisory title cannot be empty"); } else { securityAdvisory.setTitle(securityAdvisoryData.getTitle()); } } if (StringUtils.isEmpty(securityAdvisory.getThanks())) { if (StringUtils.isEmpty(securityAdvisoryData.getThanks())) { throw new AdvisoryToolException("Security Advisory thanks cannot be empty"); } else { securityAdvisory.setThanks(securityAdvisoryData.getThanks()); } } if (StringUtils.isEmpty(securityAdvisory.getDate())) { if (StringUtils.isEmpty(securityAdvisoryData.getDate())) { throw new AdvisoryToolException("Security Advisory date cannot be empty"); } else { securityAdvisory.setDate(securityAdvisoryData.getDate()); } } if (StringUtils.isEmpty(securityAdvisory.getDescription())) { securityAdvisory.setDescription(securityAdvisoryData.getDescription()); } if (StringUtils.isEmpty(securityAdvisory.getOverview())) { securityAdvisory.setOverview(securityAdvisoryData.getOverview()); } if (StringUtils.isEmpty(securityAdvisory.getImpact())) { securityAdvisory.setImpact(securityAdvisoryData.getImpact()); } if (StringUtils.isEmpty(securityAdvisory.getCredits())) { securityAdvisory.setCredits(securityAdvisoryData.getCredits()); } if (StringUtils.isEmpty(securityAdvisory.getSolution())) { securityAdvisory.setSolution(securityAdvisoryData.getSolution()); } if (StringUtils.isEmpty(securityAdvisory.getPublicDisclosure())) { securityAdvisory.setPublicDisclosure(securityAdvisoryData.getPublicDisclosure()); } if (StringUtils.isEmpty(securityAdvisory.getNotes())) { securityAdvisory.setNotes(securityAdvisoryData.getNotes()); } if (StringUtils.isEmpty(securityAdvisory.getScore())) { securityAdvisory.setScore(securityAdvisoryData.getScore()); } if (StringUtils.isEmpty(securityAdvisory.getSeverity())) { securityAdvisory.setSeverity(securityAdvisoryData.getSeverity()); } } SecurityAdvisoryDataHolder.getInstance().setSecurityAdvisoryData(securityAdvisoryData); } catch (IOException e) { throw new AdvisoryToolException("Error occurred while reading " + Constants.SECURITY_ADVISORY_DATA_FILE, e); } }
From source file:sonata.kernel.vimadaptor.AdaptorTest.java
/** * Create two wrappers with the same endpoint but using different tenants * /* w ww.ja va 2s.com*/ * @throws IOException */ @Test public void testCreateTwoWrappers() throws InterruptedException, IOException { String message = "{\"vim_type\":\"Mock\",\"vim_address\":\"10.100.32.200\",\"username\":\"sonata.dem\"," + "\"name\":\"Athens.100.Demo\"," + "\"pass\":\"s0n@t@.dem\",\"city\":\"Athens\",\"country\":\"Greece\"," + "\"configuration\":{\"tenant\":\"operator\",\"tenant_ext_net\":\"ext-subnet\",\"tenant_ext_router\":\"ext-router\"}}"; String topic = "infrastructure.management.compute.add"; BlockingQueue<ServicePlatformMessage> muxQueue = new LinkedBlockingQueue<ServicePlatformMessage>(); BlockingQueue<ServicePlatformMessage> dispatcherQueue = new LinkedBlockingQueue<ServicePlatformMessage>(); TestProducer producer = new TestProducer(muxQueue, this); ServicePlatformMessage addVimMessage = new ServicePlatformMessage(message, "application/json", topic, UUID.randomUUID().toString(), topic); consumer = new TestConsumer(dispatcherQueue); AdaptorCore core = new AdaptorCore(muxQueue, dispatcherQueue, consumer, producer, 0.05); core.start(); consumer.injectMessage(addVimMessage); Thread.sleep(2000); while (output == null) { synchronized (mon) { mon.wait(1000); } } JSONTokener tokener = new JSONTokener(output); JSONObject jsonObject = (JSONObject) tokener.nextValue(); String uuid1 = jsonObject.getString("uuid"); String status = jsonObject.getString("request_status"); Assert.assertTrue(status.equals("COMPLETED")); output = null; message = "{\"vim_type\":\"Mock\",\"vim_address\":\"10.100.32.200\",\"username\":\"sonata.dario\"," + "\"name\":\"Athens.100.Dario\"," + "\"pass\":\"s0n@t@.dario\",\"city\":\"Athens\",\"country\":\"Greece\"," + "\"configuration\":{\"tenant\":\"operator\",\"tenant_ext_net\":\"ext-subnet\",\"tenant_ext_router\":\"ext-router\"}}"; addVimMessage = new ServicePlatformMessage(message, "application/json", topic, UUID.randomUUID().toString(), topic); consumer.injectMessage(addVimMessage); Thread.sleep(2000); while (output == null) { synchronized (mon) { mon.wait(1000); } } tokener = new JSONTokener(output); jsonObject = (JSONObject) tokener.nextValue(); String uuid2 = jsonObject.getString("uuid"); status = jsonObject.getString("request_status"); Assert.assertTrue(status.equals("COMPLETED")); // List installed VIMS output = null; topic = "infrastructure.management.compute.list"; ServicePlatformMessage listVimMessage = new ServicePlatformMessage(null, null, topic, UUID.randomUUID().toString(), topic); consumer.injectMessage(listVimMessage); while (output == null) { synchronized (mon) { mon.wait(1000); } } ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); VimResources[] vimList = mapper.readValue(output, VimResources[].class); ArrayList<String> vimArrayList = new ArrayList<String>(); for (VimResources resource : vimList) { Assert.assertNotNull("Resource not set 'VIM UUID'", resource.getVimUuid()); Assert.assertNotNull("Resource not set 'tot_cores'", resource.getCoreTotal()); Assert.assertNotNull("Resource not set 'used_cores'", resource.getCoreUsed()); Assert.assertNotNull("Resource not set 'tot_mem'", resource.getMemoryTotal()); Assert.assertNotNull("Resource not set 'used_mem'", resource.getMemoryUsed()); vimArrayList.add(resource.getVimUuid()); } Assert.assertTrue("VIMs List doesn't contain vim " + uuid1, vimArrayList.contains(uuid1)); Assert.assertTrue("VIMs List doesn't contain vim " + uuid2, vimArrayList.contains(uuid2)); // Clear the environment output = null; message = "{\"uuid\":\"" + uuid1 + "\"}"; topic = "infrastructure.management.compute.remove"; ServicePlatformMessage removeVimMessage = new ServicePlatformMessage(message, "application/json", topic, UUID.randomUUID().toString(), topic); consumer.injectMessage(removeVimMessage); while (output == null) { synchronized (mon) { mon.wait(1000); } } tokener = new JSONTokener(output); jsonObject = (JSONObject) tokener.nextValue(); status = jsonObject.getString("request_status"); Assert.assertTrue(status.equals("COMPLETED")); output = null; message = "{\"uuid\":\"" + uuid2 + "\"}"; topic = "infrastructure.management.compute.remove"; removeVimMessage = new ServicePlatformMessage(message, "application/json", topic, UUID.randomUUID().toString(), topic); consumer.injectMessage(removeVimMessage); while (output == null) { synchronized (mon) { mon.wait(1000); } } tokener = new JSONTokener(output); jsonObject = (JSONObject) tokener.nextValue(); status = jsonObject.getString("request_status"); Assert.assertTrue(status.equals("COMPLETED")); core.stop(); }
From source file:sonata.kernel.vimadaptor.AdaptorTest.java
/** * Test list vim API call/*from w w w . j ava 2 s . co m*/ * * @throws IOException */ @Test public void testListVimList() throws InterruptedException, IOException { ArrayList<String> vimUuid = new ArrayList<String>(); JSONTokener tokener; JSONObject jsonObject; String uuid, status; BlockingQueue<ServicePlatformMessage> muxQueue = new LinkedBlockingQueue<ServicePlatformMessage>(); BlockingQueue<ServicePlatformMessage> dispatcherQueue = new LinkedBlockingQueue<ServicePlatformMessage>(); TestProducer producer = new TestProducer(muxQueue, this); consumer = new TestConsumer(dispatcherQueue); AdaptorCore core = new AdaptorCore(muxQueue, dispatcherQueue, consumer, producer, 0.05); core.start(); String topic = "infrastructure.management.compute.add"; for (int i = 0; i < 3; i++) { String message = "{\"vim_type\":\"mock\",\"vim_address\":\"http://vim" + i + ":9999\",\"username\":\"Eve\"," + "\"name\":\"Mock" + i + "\"," + "\"pass\":\"Operator\",\"city\":\"London\",\"country\":\"\"," + "\"configuration\":{\"tenant\":\"operator\",\"tenant_ext_net\":\"ext-subnet\",\"tenant_ext_router\":\"ext-router\"}}"; ServicePlatformMessage addVimMessage = new ServicePlatformMessage(message, "application/json", topic, UUID.randomUUID().toString(), topic); consumer.injectMessage(addVimMessage); Thread.sleep(2000); while (output == null) { synchronized (mon) { mon.wait(1000); } } System.out.println(output); tokener = new JSONTokener(output); jsonObject = (JSONObject) tokener.nextValue(); uuid = jsonObject.getString("uuid"); status = jsonObject.getString("request_status"); Assert.assertTrue(status.equals("COMPLETED")); vimUuid.add(uuid); output = null; } topic = "infrastructure.management.compute.list"; ServicePlatformMessage listVimMessage = new ServicePlatformMessage(null, null, topic, UUID.randomUUID().toString(), topic); consumer.injectMessage(listVimMessage); while (output == null) { synchronized (mon) { mon.wait(1000); } } ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); VimResources[] vimList = mapper.readValue(output, VimResources[].class); ArrayList<String> vimArrayList = new ArrayList<String>(); for (VimResources resource : vimList) { Assert.assertNotNull("Resource not set 'VIM UUID'", resource.getVimUuid()); Assert.assertNotNull("Resource not set 'tot_cores'", resource.getCoreTotal()); Assert.assertNotNull("Resource not set 'used_cores'", resource.getCoreUsed()); Assert.assertNotNull("Resource not set 'tot_mem'", resource.getMemoryTotal()); Assert.assertNotNull("Resource not set 'used_mem'", resource.getMemoryUsed()); vimArrayList.add(resource.getVimUuid()); } for (String returnUiid : vimUuid) { Assert.assertTrue("VIMs List doesn't contain vim " + returnUiid, vimArrayList.contains(returnUiid)); } output = null; for (String regUuid : vimUuid) { output = null; String removeMessage = "{\"uuid\":\"" + regUuid + "\"}"; topic = "infrastructure.management.compute.remove"; ServicePlatformMessage removeVimMessage = new ServicePlatformMessage(removeMessage, "application/json", topic, UUID.randomUUID().toString(), topic); consumer.injectMessage(removeVimMessage); while (output == null) { synchronized (mon) { mon.wait(1000); } } tokener = new JSONTokener(output); jsonObject = (JSONObject) tokener.nextValue(); status = jsonObject.getString("request_status"); Assert.assertTrue(status.equals("COMPLETED")); } output = null; consumer.injectMessage(listVimMessage); while (output == null) { synchronized (mon) { mon.wait(1000); } } vimList = mapper.readValue(output, VimResources[].class); Assert.assertTrue("VIMs List not empty", vimList.length == 0); output = null; core.stop(); WrapperBay.getInstance().clear(); }
From source file:streamflow.util.config.ConfigLoader.java
public static StreamflowConfig getConfig() { String yamlConfig = null;// ww w . j ava2 s . co m File yamlConfigFile = new File(StreamflowEnvironment.getConfDir(), "streamflow.yml"); if (yamlConfigFile.exists()) { try { yamlConfig = FileUtils.readFileToString(yamlConfigFile, "UTF-8"); LOG.info("Using user provided streamflow.yml: " + yamlConfigFile.getAbsolutePath()); } catch (Exception ex) { } } if (yamlConfig == null) { try { yamlConfig = IOUtils.toString( Thread.currentThread().getContextClassLoader().getResourceAsStream("streamflow.yml"), "UTF-8"); LOG.info("Using classpath provided streamflow.yml"); } catch (Exception ex) { } } if (yamlConfig == null) { LOG.info("streamflow.yml not found anywhere... using default configuration"); return new StreamflowConfig(); } else { // Parse the YAML configuration using the Jackson YAML factory ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); try { // Parse the yaml configuration using the specified mapping return objectMapper.readValue(yamlConfig, StreamflowConfig.class); } catch (Exception ex) { LOG.error("Unable to parse provided streamflow.yml configuration. " + "Using default values: ", ex); // If a parsing error is encountered, use the default Streamflow configuration return new StreamflowConfig(); } } }