List of usage examples for java.util Map toString
public String toString()
From source file:com.zjy.mongo.splitter.MultiMongoCollectionSplitter.java
@Override public List<InputSplit> calculateSplits() throws SplitFailedException { List<MongoClientURI> inputURIs = MongoConfigUtil.getMongoURIs(this.getConfiguration(), MongoConfigUtil.INPUT_URI); List<InputSplit> returnVal = new LinkedList<InputSplit>(); List<MongoSplitter> splitters = new LinkedList<MongoSplitter>(); //For each input URI that is specified, get the appropriate //splitter for each implementation. if (inputURIs.size() > 0) { if (LOG.isDebugEnabled()) { LOG.debug("Using global split settings for multiple URIs specified."); }/*from w w w.j ava 2 s . co m*/ //Get options from the hadoop config. //Use these options for all URIs in the list. //Splitter class is ignored here, since it would just be referring //to MultiMongoCollectionSplitter here anyway. If the user needs //to customize the splitter class, they should use the JSON key for //the configuration instead. for (MongoClientURI uri : inputURIs) { MongoCollectionSplitter splitter; Configuration confForThisUri = new Configuration(getConfiguration()); MongoConfigUtil.setInputURI(confForThisUri, uri); confForThisUri.set(MongoConfigUtil.MONGO_SPLITTER_CLASS, ""); splitter = MongoSplitterFactory.getSplitterByStats(uri, confForThisUri); splitters.add(splitter); } } else { //Otherwise the user has set options per-collection. if (LOG.isDebugEnabled()) { LOG.debug("Loading multiple input URIs from JSON stored in " + MULTI_COLLECTION_CONF_KEY); } DBObject multiUriConfig = MongoConfigUtil.getDBObject(this.getConfiguration(), MULTI_COLLECTION_CONF_KEY); if (!(multiUriConfig instanceof List)) { throw new IllegalArgumentException( "Invalid JSON format in multi uri config key: Must be an array where each element " + "is an object describing the URI and config options for each split."); } for (Object obj : (List) multiUriConfig) { Map<String, Object> configMap; MongoClientURI inputURI; Configuration confForThisUri; try { configMap = (Map<String, Object>) obj; if (LOG.isDebugEnabled()) { LOG.debug("building config from " + configMap.toString()); } confForThisUri = MongoConfigUtil.buildConfiguration(configMap); inputURI = MongoConfigUtil.getInputURI(confForThisUri); } catch (ClassCastException e) { throw new IllegalArgumentException( "Invalid JSON format in multi uri config key: each config item must be an " + "object with keys/values describing options for each URI."); } MongoSplitter splitter; Class<? extends MongoSplitter> splitterClass = MongoConfigUtil.getSplitterClass(confForThisUri); if (splitterClass != null) { if (LOG.isDebugEnabled()) { LOG.debug(format("Using custom Splitter class for namespace: %s.%s; hosts: %s", inputURI.getDatabase(), inputURI.getCollection(), inputURI.getHosts())); } //User wants to use a specific custom class for this URI. //Make sure that the custom class isn't this one if (splitterClass == MultiMongoCollectionSplitter.class) { throw new IllegalArgumentException("Can't nest uses of MultiMongoCollectionSplitter"); } //All clear. MongoCollectionSplitter collectionSplitter; collectionSplitter = (MongoCollectionSplitter) ReflectionUtils.newInstance(splitterClass, confForThisUri); //Since we use no-arg constructor, need to inject //configuration and input URI. collectionSplitter.setConfiguration(confForThisUri); splitter = collectionSplitter; } else { if (LOG.isDebugEnabled()) { LOG.debug(format( "Fetching collection stats on namespace: %s.%s; hosts: %s to choose splitter implementation.", inputURI.getDatabase(), inputURI.getCollection(), inputURI.getHosts())); } //No class was specified, so choose one by looking at //collection stats. splitter = MongoSplitterFactory.getSplitterByStats(inputURI, confForThisUri); } splitters.add(splitter); } } //Now we have splitters for all the input collections. //Run through all of em, get all the splits for each, //compile them into one big ol' list. for (MongoSplitter splitter : splitters) { returnVal.addAll(splitter.calculateSplits()); } return returnVal; }
From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java
public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String fileId = (String) paramMap.get("fileId"); StringBuilder sb = new StringBuilder(); FileDTO fileDTO;/*from ww w . j a va 2 s . c o m*/ fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM sb.setLength(0); sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } response.setContentType(fileDTO.getContentType()); // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); BufferedInputStream bufferdInputStream = new BufferedInputStream(inputStream); ServletOutputStream servletOutputStream = response.getOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); return null; }
From source file:org.finra.dm.dao.impl.BaseJpaDaoImpl.java
@Override public <T> T queryUniqueByNamedQueryAndNamedParams(String queryName, Map<String, ?> params) { Validate.notEmpty(queryName);/* ww w . j a v a 2 s. c om*/ Validate.notEmpty(params); List<T> resultList = queryByNamedQueryAndNamedParams(queryName, params); Validate.isTrue(resultList.isEmpty() || resultList.size() == 1, "Found more than one persistent instance with parameters " + params.toString()); return resultList.size() == 1 ? resultList.get(0) : null; }
From source file:com.liferay.portal.osgi.web.wab.generator.internal.processor.WabProcessorTest.java
@Test public void testClassicThemeWab() throws Exception { File file = getFile("classic-theme.autodeployed.war"); Assert.assertNotNull(file);/*from ww w .j av a2 s . c om*/ try (Jar jar = new Jar(file)) { Assert.assertNull(jar.getBsn()); Map<String, Resource> resources = jar.getResources(); Assert.assertEquals(resources.toString(), 1244, resources.size()); } Map<String, String[]> parameters = new HashMap<>(); parameters.put("Bundle-Version", new String[] { "7.0.0.8" }); parameters.put("Web-ContextPath", new String[] { "/classic-theme" }); WabProcessor wabProcessor = new TestWabProcessor(getClassLoader(), file, parameters); File processedFile = wabProcessor.getProcessedFile(); Assert.assertNotNull(processedFile); try (Jar jar = new Jar(processedFile)) { Map<String, Map<String, Resource>> directories = jar.getDirectories(); Map<String, Resource> resources = jar.getResources(); // Check to see that the right number of resources are in the WAB Assert.assertEquals(resources.toString(), 1240, resources.size()); // Check if the basic metadata is correct Assert.assertEquals("classic-theme", jar.getBsn()); Assert.assertEquals("7.0.0.8", jar.getVersion()); // Assert that the Bundle-ClassPath is properly formed to our // conventions Domain domain = Domain.domain(jar.getManifest()); Parameters bundleClassPath = domain.getBundleClassPath(); Assert.assertEquals(4, bundleClassPath.size()); Assert.assertTrue(bundleClassPath.containsKey("ext/WEB-INF/classes")); for (String bundleClassPathEntry : bundleClassPath.keySet()) { if (bundleClassPathEntry.equals("ext/WEB-INF/classes")) { Assert.assertNull(resources.get(bundleClassPathEntry)); } else if (bundleClassPathEntry.equals("WEB-INF/classes")) { Assert.assertNull(resources.get(bundleClassPathEntry)); Assert.assertTrue(directories.containsKey(bundleClassPathEntry)); } else { // Check that all the libraries on the Bundle-ClassPath // exist in the WAB Assert.assertNotNull(resources.get(bundleClassPathEntry)); } } Parameters importedPackages = domain.getImportPackage(); // Check basic servlet and jsp packages are imported Assert.assertTrue(importedPackages.containsKey("javax.servlet")); Assert.assertTrue(importedPackages.containsKey("javax.servlet.http")); // Check if packages declared in portal property // module.framework.web.generator.default.servlet.packages are // included Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.model")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.service")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.servlet.filters.aggregate")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.osgi.web.servlet.jsp.compiler")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.spring.context")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.util")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portlet")); Assert.assertTrue(importedPackages.containsKey("com.sun.el")); Assert.assertTrue(importedPackages.containsKey("org.apache.commons.chain.generic")); Assert.assertTrue(importedPackages.containsKey("org.apache.naming.java")); // Check if packages only referenced in web.xml are imported Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.kernel.servlet.filters.invoker")); Assert.assertTrue(importedPackages.containsKey("com.liferay.portal.webserver")); } }
From source file:com.pinterest.rocksplicator.controller.tasks.HealthCheckTask.java
/** * Count the number of replicas for each shard within a segment. * Throws exception if the number doesn't match the expected one. *//* w w w .jav a 2 s.co m*/ private void checkSegment(SegmentBean segment, int numReplicas) throws Exception { Map<Integer, Integer> shardCount = new HashMap<>(); for (HostBean hostBean : segment.getHosts()) { for (ShardBean shardBean : hostBean.getShards()) { int cnt = shardCount.getOrDefault(shardBean.getId(), 0); shardCount.put(shardBean.getId(), cnt + 1); } } if (shardCount.size() != segment.getNumShards()) { throw new Exception(String.format("Incorrect number of shards. Expected %d but actually %d.", segment.getNumShards(), shardCount.size())); } Map<Integer, Integer> badShards = new HashMap<>(); for (Map.Entry<Integer, Integer> entry : shardCount.entrySet()) { if (entry.getValue() != numReplicas) { badShards.put(entry.getKey(), entry.getValue()); } } if (!badShards.isEmpty()) { throw new Exception("Incorrect number of replicas. Bad shards: " + badShards.toString()); } }
From source file:org.apache.griffin.core.job.SparkSubmitJob.java
public void setDataConnectorPartitions(DataConnector dc, String[] patternItemSet, String[] partitionItems, long timestamp) { Map<String, String> partitionItemMap = genPartitionMap(patternItemSet, partitionItems, timestamp); /**/*from w w w. j a v a 2 s .co m*/ * partitions must be a string like: "dt=20170301, hour=12" * partitionItemMap.toString() is like "{dt=20170301, hour=12}" */ String partitions = partitionItemMap.toString().substring(1, partitionItemMap.toString().length() - 1); Map<String, String> configMap = dc.getConfigInMaps(); //config should not be null configMap.put("partitions", partitions); try { dc.setConfig(configMap); } catch (JsonProcessingException e) { LOGGER.error("" + e); } }
From source file:brooklyn.rest.util.json.BrooklynJacksonSerializerTest.java
@Test public void testSensorSensible() throws Exception { Map<?, ?> result = checkSerializesAs(Attributes.HTTP_PORT, Map.class); log.info("SENSOR json is: " + result); Assert.assertFalse(result.toString().contains("error"), "Shouldn't have had an error, instead got: " + result); }
From source file:com.larryTheCoder.schematic.IslandBlock.java
public void setBook(Map<String, Tag> tileData) { //Bukkit.getLogger().info("DEBUG: Book data "); Utils.ConsoleMsg(tileData.toString()); }
From source file:org.apache.metron.stellar.common.shell.StellarShell.java
/** * Handle a magic '%globals'. List all of the global configuration values. *///w w w . j a v a 2 s . com private void handleMagicGlobals() { Map<String, Object> globals = getOrCreateGlobalConfig(executor); writeLine(globals.toString()); }
From source file:org.deeplearning4j.util.CrashReportingUtil.java
private static void appendHelperInformation(StringBuilder sb, org.deeplearning4j.nn.api.Layer[] layers) { sb.append("\n----- Layer Helpers - Memory Use -----\n"); int helperCount = 0; long helperWithMemCount = 0L; long totalHelperMem = 0L; //Layer index, layer name, layer class, helper class, total memory, breakdown String format = "%-3s %-20s %-25s %-30s %-12s %s"; boolean header = false; for (Layer l : layers) { LayerHelper h = l.getHelper();/*from w ww .j a v a2s . c o m*/ if (h == null) continue; helperCount++; Map<String, Long> mem = h.helperMemoryUse(); if (mem == null || mem.isEmpty()) continue; helperWithMemCount++; long layerTotal = 0; for (Long m : mem.values()) { layerTotal += m; } int idx = l.getIndex(); String layerName = l.conf().getLayer().getLayerName(); if (layerName == null) layerName = String.valueOf(idx); if (!header) { sb.append(String.format(format, "#", "Layer Name", "Layer Class", "Helper Class", "Total Memory", "Memory Breakdown")).append("\n"); header = true; } sb.append(String.format(format, idx, layerName, l.getClass().getSimpleName(), h.getClass().getSimpleName(), fBytes(layerTotal), mem.toString())).append("\n"); totalHelperMem += layerTotal; } sb.append(f("Total Helper Count", helperCount)); sb.append(f("Helper Count w/ Memory", helperWithMemCount)); sb.append(fBytes("Total Helper Persistent Memory Use", totalHelperMem)); }