/** * Reads default JUL configuration. */ private void defaultConfiguration() { final URL cfgUrl = U.resolveIgniteUrl(DFLT_CONFIG_PATH); if (cfgUrl == null) { warning("Failed to resolve default logging config file: " + DFLT_CONFIG_PATH); return; } try (InputStream in = cfgUrl.openStream()) { LogManager.getLogManager().readConfiguration(in); } catch (IOException e) { error("Failed to read logging configuration: " + cfgUrl, e); } cfg = cfgUrl.getPath(); }
/** * Gets config of concrete File System. * * @return Config of concrete File System. */ protected Configuration getFileSystemConfig() { Configuration cfg = new Configuration(); cfg.addResource(U.resolveIgniteUrl(HADOOP_FS_CFG)); return cfg; }
/** * Resolve IGFS profiler logs directory. * * @param igfs IGFS instance to resolve logs dir for. * @return {@link Path} to log dir or {@code null} if not found. * @throws IgniteCheckedException if failed to resolve. */ public static Path resolveIgfsProfilerLogsDir(IgniteFileSystem igfs) throws IgniteCheckedException { String logsDir; if (igfs instanceof IgfsEx) logsDir = ((IgfsEx)igfs).clientLogDirectory(); else if (igfs == null) throw new IgniteCheckedException("Failed to get profiler log folder (IGFS instance not found)"); else throw new IgniteCheckedException("Failed to get profiler log folder (unexpected IGFS instance type)"); URL logsDirUrl = U.resolveIgniteUrl(logsDir != null ? logsDir : DFLT_IGFS_LOG_DIR); return logsDirUrl != null ? new File(logsDirUrl.getPath()).toPath() : null; }
/** * Gets instance of Hadoop local file system. * * @param home File system home. * @return File system. * @throws IOException If failed. */ private FileSystem local(Path home) throws IOException { Configuration cfg = new Configuration(); cfg.addResource(U.resolveIgniteUrl(HADOOP_FS_CFG)); return FileSystem.get(home.toUri(), cfg); }
/** * Load grid configuration for specified node type. * * @param type Node type to load configuration for. * @return Grid configuration for specified node type. */ static IgniteConfiguration getConfig(String type) { String path = NODE_CFG.get(type); if (path == null) throw new IllegalArgumentException("Unsupported node type: " + type); URL url = U.resolveIgniteUrl(path); BeanFactory ctx = new FileSystemXmlApplicationContext(url.toString()); return (IgniteConfiguration)ctx.getBean("grid.cfg"); }
/** * Resolve Spring configuration URL. * * @param springCfgPath Spring XML configuration file path or URL. This cannot be {@code null}. * @return URL. * @throws IgniteCheckedException If failed. */ public static URL resolveSpringUrl(String springCfgPath) throws IgniteCheckedException { A.notNull(springCfgPath, "springCfgPath"); URL url; try { url = new URL(springCfgPath); } catch (MalformedURLException e) { url = U.resolveIgniteUrl(springCfgPath); if (url == null) url = resolveInClasspath(springCfgPath); if (url == null) throw new IgniteCheckedException("Spring XML configuration path is invalid: " + springCfgPath + ". Note that this path should be either absolute or a relative local file system path, " + "relative to META-INF in classpath or valid URL to IGNITE_HOME.", e); } return url; }
/** * Instantiate new file system. * * @return New file system. * @throws Exception If failed. */ private IgniteHadoopFileSystem fileSystem() throws Exception { Configuration fsCfg = new Configuration(); fsCfg.addResource(U.resolveIgniteUrl("modules/core/src/test/config/hadoop/core-site-loopback.xml")); fsCfg.setBoolean("fs.igfs.impl.disable.cache", true); if (logging) fsCfg.setBoolean(String.format(PARAM_IGFS_LOG_ENABLED, "igfs@"), logging); fsCfg.setStrings(String.format(PARAM_IGFS_LOG_DIR, "igfs@"), U.getIgniteHome()); return (IgniteHadoopFileSystem)FileSystem.get(new URI("igfs://igfs@/"), fsCfg); }
/** * Creates new logger with given configuration {@code path}. * * @param path Path to log4j2 configuration XML file. * @throws IgniteCheckedException Thrown in case logger can't be created. */ public Log4J2Logger(String path) throws IgniteCheckedException { if (path == null) throw new IgniteCheckedException("Configuration XML file for Log4j2 must be specified."); final URL cfgUrl = U.resolveIgniteUrl(path); if (cfgUrl == null) throw new IgniteCheckedException("Log4j2 configuration path was not found: " + path); addConsoleAppenderIfNeeded(new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { if (init) Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString()); return (Logger)LogManager.getRootLogger(); } }); quiet = quiet0; cfg = path; }
throw new ServletException("Failed to read property: " + cfgFilePathParam); URL cfgUrl = U.resolveIgniteUrl(cfgFile);
/** * @param outputDir Directory for process output. * @return Logger. */ private IgniteLogger logger(final File outputDir) { final URL url = U.resolveIgniteUrl(DFLT_LOG4J_CONFIG); Log4JLogger logger; try { logger = url != null ? new Log4JLogger(url) : new Log4JLogger(true); } catch (IgniteCheckedException e) { System.err.println("Failed to create URL-based logger. Will use default one."); e.printStackTrace(); logger = new Log4JLogger(true); } logger.updateFilePath(new IgniteClosure<String, String>() { @Override public String apply(String s) { return new File(outputDir, args.childProcId + ".log").getAbsolutePath(); } }); return logger; }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { primaryFsUri = new URI(primaryFileSystemUriPath()); primaryFsCfg = new Configuration(); primaryFsCfg.addResource(U.resolveIgniteUrl(primaryFileSystemConfigPath())); UserGroupInformation ugi = UserGroupInformation.getBestUGI(null, getClientFsUser()); // Create Fs on behalf of the client user: ugi.doAs(new PrivilegedExceptionAction<Object>() { @Override public Object run() throws Exception { fs = AbstractFileSystem.get(primaryFsUri, primaryFsCfg); return null; } }); barrier = new CyclicBarrier(THREAD_CNT); }
Arrays.toString(proxy0.getConfigPaths())); else { URL url = U.resolveIgniteUrl(cfgPath);
/** * Configures the Hadoop MapReduce job. * * @return Instance of the Hadoop MapRed job. * @throws IOException If failed. */ @SuppressWarnings("deprecation") private Job createConfigBasedHadoopJob() throws IOException { Job jobCfg = new Job(); Configuration cfg = jobCfg.getConfiguration(); // Use explicit configuration of distributed file system, if provided. cfg.addResource(U.resolveIgniteUrl(DFS_CFG)); jobCfg.setJobName("HadoopPopularWordExample"); jobCfg.setJarByClass(HadoopPopularWords.class); jobCfg.setInputFormatClass(TextInputFormat.class); jobCfg.setOutputKeyClass(Text.class); jobCfg.setOutputValueClass(IntWritable.class); jobCfg.setMapperClass(TokenizingMapper.class); jobCfg.setReducerClass(TopNWordsReducer.class); FileInputFormat.setInputPaths(jobCfg, BOOKS_DFS_DIR); FileOutputFormat.setOutputPath(jobCfg, RESULT_DFS_DIR); // Local job tracker allows the only task per wave, but text input format // replaces it with the calculated value based on input split size option. if ("local".equals(cfg.get("mapred.job.tracker", "local"))) { // Split job into tasks using 32MB split size. FileInputFormat.setMinInputSplitSize(jobCfg, 32L * 1024 * 1024); FileInputFormat.setMaxInputSplitSize(jobCfg, Long.MAX_VALUE); } return jobCfg; }
/** * @param args Args. */ @SuppressWarnings("InfiniteLoopStatement") public static void main(String[] args) { Ignite g = G.start(U.resolveIgniteUrl(CFG_PATH)); IgniteDataStreamer<Long, String> ldr = g.dataStreamer("default"); ldr.perNodeBufferSize(16 * 1024); StringBuilder sb = new StringBuilder(); for (int i = 0; i < VALUE_SIZE - 42; i++) sb.append('a'); String str = sb.toString(); long cntr = 0; while (true) { ldr.addData(cntr++, UUID.randomUUID() + str); if (cntr % 1000000 == 0) X.println("!!! Entries added: " + cntr); } } }
/** * Starts grid with default configuration. By default this method will * use grid configuration defined in {@code IGNITE_HOME/config/default-config.xml} * configuration file. If such file is not found, then all system defaults will be used. * * @param springCtx Optional Spring application context, possibly {@code null}. * Spring bean definitions for bean injection are taken from this context. * If provided, this context can be injected into grid tasks and grid jobs using * {@link SpringApplicationContextResource @SpringApplicationContextResource} annotation. * @return Started grid. * @throws IgniteCheckedException If default grid could not be started. This exception will be thrown * also if default grid has already been started. */ public static Ignite start(@Nullable GridSpringResourceContext springCtx) throws IgniteCheckedException { URL url = U.resolveIgniteUrl(DFLT_CFG); if (url != null) return start(DFLT_CFG, null, springCtx, null); U.warn(null, "Default Spring XML file not found (is IGNITE_HOME set?): " + DFLT_CFG); return start0(new GridStartContext(new IgniteConfiguration(), null, springCtx), true) .get1().grid(); }
URL url = U.resolveIgniteUrl(IgnitionEx.DFLT_CFG);
URL cfgLocation = U.resolveIgniteUrl(springCfgPath); cfgLocation = U.resolveIgniteUrl(springCfgPath, false);
/** * Creates new logger with given configuration {@code path}. * * @param path Path to log4j configuration XML file. * @throws IgniteCheckedException Thrown in case logger can't be created. */ public GridTestLog4jLogger(String path) throws IgniteCheckedException { if (path == null) throw new IgniteCheckedException("Configuration XML file for Log4j must be specified."); this.cfg = path; final URL cfgUrl = U.resolveIgniteUrl(path); if (cfgUrl == null) throw new IgniteCheckedException("Log4j configuration path was not found: " + path); addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { if (init) DOMConfigurator.configure(cfgUrl); return Logger.getRootLogger(); } }); quiet = quiet0; }
/** {@inheritDoc} */ @Override protected VisorEither<VisorFileBlock> run(VisorFileBlockTaskArg arg) { try { URL url = U.resolveIgniteUrl(arg.getPath()); if (url == null) return new VisorEither<>(new NoSuchFileException("File path not found: " + arg.getPath())); VisorFileBlock block = readBlock( new File(url.toURI()), arg.getOffset(), arg.getBlockSize(), arg.getLastModified()); return new VisorEither<>(block); } catch (IOException e) { return new VisorEither<>(e); } catch (URISyntaxException ignored) { return new VisorEither<>(new NoSuchFileException("File path not found: " + arg.getPath())); } }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { store = store(); URL cfgUrl; try { cfgUrl = new URL(DFLT_MAPPING_CONFIG); } catch (MalformedURLException ignore) { cfgUrl = U.resolveIgniteUrl(DFLT_MAPPING_CONFIG); } if (cfgUrl == null) throw new Exception("Failed to resolve metadata path: " + DFLT_MAPPING_CONFIG); try { GenericApplicationContext springCtx = new GenericApplicationContext(); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(cfgUrl)); springCtx.refresh(); Collection<JdbcType> types = new ArrayList<>(springCtx.getBeansOfType(JdbcType.class).values()); store.setTypes(types.toArray(new JdbcType[types.size()])); } catch (BeansException e) { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) " + "[springUrl=" + cfgUrl + ']', e); else throw new IgniteCheckedException("Failed to instantiate Spring XML application context [springUrl=" + cfgUrl + ", err=" + e.getMessage() + ']', e); } }