/** * Reads default JUL configuration. */ private void defaultConfiguration() { final URL cfgUrl = U.resolveGridGainUrl(DFLT_CONFIG_PATH); if (cfgUrl == null) { error("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); } }
/** {@inheritDoc} */ @Nullable @Override protected Collection<VisorLogFile> run(final GridBiTuple<String, String> arg) throws GridException { String path = arg.get1(); String regexp = arg.get2(); assert path != null; assert regexp != null; URL url = U.resolveGridGainUrl(path); if (url == null) return null; try { File folder = new File(url.toURI()); List<VisorLogFile> files = matchedFiles(folder, regexp); if (files.isEmpty()) return null; if (files.size() > LOG_FILES_COUNT_LIMIT) files = new ArrayList<>(files.subList(0, LOG_FILES_COUNT_LIMIT)); return files; } catch (Exception ignored) { return null; } }
/** * Resolve GGFS profiler logs directory. * * @param ggfs GGFS instance to resolve logs dir for. * @return {@link Path} to log dir or {@code null} if not found. * @throws GridException if failed to resolve. */ public static Path resolveGgfsProfilerLogsDir(GridGgfs ggfs) throws GridException { String logsDir; if (ggfs instanceof GridGgfsEx) logsDir = ((GridGgfsEx) ggfs).clientLogDirectory(); else if (ggfs == null) throw new GridException("Failed to get profiler log folder (GGFS instance not found)"); else throw new GridException("Failed to get profiler log folder (unexpected GGFS instance type)"); URL logsDirUrl = U.resolveGridGainUrl(logsDir != null ? logsDir : DFLT_GGFS_LOG_DIR); return logsDirUrl != null ? new File(logsDirUrl.getPath()).toPath() : null; } }
/** * Resolve Spring configuration URL. * * @param springCfgPath Spring XML configuration file path or URL. This cannot be {@code null}. * @return URL. * @throws GridException If failed. */ private static URL resolveSpringUrl(String springCfgPath) throws GridException { A.notNull(springCfgPath, "springCfgPath"); URL url; try { url = new URL(springCfgPath); } catch (MalformedURLException e) { url = U.resolveGridGainUrl(springCfgPath); if (url == null) throw new GridException("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 GRIDGAIN_HOME.", e); } return url; }
/** * Resolve GGFS profiler logs directory. * * @param ggfs GGFS instance to resolve logs dir for. * @return {@link Path} to log dir or {@code null} if not found. * @throws GridException if failed to resolve. */ public static Path resolveGgfsProfilerLogsDir(GridGgfs ggfs) throws GridException { String logsDir; if (ggfs instanceof GridGgfsEx) logsDir = ((GridGgfsEx) ggfs).clientLogDirectory(); else if (ggfs == null) throw new GridException("Failed to get profiler log folder (GGFS instance not found)"); else throw new GridException("Failed to get profiler log folder (unexpected GGFS instance type)"); URL logsDirUrl = U.resolveGridGainUrl(logsDir != null ? logsDir : DFLT_GGFS_LOG_DIR); return logsDirUrl != null ? new File(logsDirUrl.getPath()).toPath() : null; } }
URL url = U.resolveGridGainUrl("config/gridgain-log4j.xml");
URL url = U.resolveGridGainUrl(arg.folder);
/** * Loads all grid configurations specified within given Spring XML configuration file. * <p> * Usually Spring XML configuration file will contain only one Grid definition. Note that * Grid configuration bean(s) is retrieved form configuration file by type, so the name of * the Grid configuration bean is ignored. * * @param springCfgPath Spring XML configuration file path. This cannot be {@code null}. * @return Tuple containing all loaded configurations and Spring context used to load them. * @throws GridException If grid could not be started or configuration * read. This exception will be thrown also if grid with given name has already * been started or Spring XML configuration file is invalid. */ public static GridBiTuple<Collection<GridConfiguration>, ? extends GridSpringResourceContext> loadConfigurations( String springCfgPath) throws GridException { A.notNull(springCfgPath, "springCfgPath"); URL url; try { url = new URL(springCfgPath); } catch (MalformedURLException e) { url = U.resolveGridGainUrl(springCfgPath); if (url == null) throw new GridException("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 GRIDGAIN_HOME.", e); } return loadConfigurations(url); }
/** * Creates new logger with given configuration {@code path}. * * @param path Path to log4j configuration XML file. * @throws GridException Thrown in case logger can't be created. */ public GridLog4jLogger(String path) throws GridException { if (path == null) throw new GridException("Configuration XML file for Log4j must be specified."); this.path = path; final URL cfgUrl = U.resolveGridGainUrl(path); if (cfgUrl == null) throw new GridException("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; }
URL folderUrl = U.resolveGridGainUrl(path);
/** {@inheritDoc} */ @Override protected GridBiTuple<? extends IOException, VisorFileBlock> run(VisorFileBlockArg arg) throws GridException { try { URL url = U.resolveGridGainUrl(arg.path); if (url == null) return new GridBiTuple<>(new NoSuchFileException("File path not found: " + arg.path), null); VisorFileBlock block = readBlock(new File(url.toURI()), arg.offset, arg.blockSz, arg.lastModified); return new GridBiTuple<>(null, block); } catch (IOException e) { return new GridBiTuple<>(e, null); } catch (URISyntaxException ignored) { return new GridBiTuple<>(new NoSuchFileException("File path not found: " + arg.path), null); } }
/** * Starts grid with default configuration. By default this method will * use grid configuration defined in {@code GRIDGAIN_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 GridSpringApplicationContextResource @GridSpringApplicationContextResource} annotation. * @return Started grid. * @throws GridException If default grid could not be started. This exception will be thrown * also if default grid has already been started. */ public static Grid start(@Nullable GridSpringResourceContext springCtx) throws GridException { URL url = U.resolveGridGainUrl(DFLT_CFG); if (url != null) return start(DFLT_CFG, null, springCtx); U.warn(null, "Default Spring XML file not found (is GRIDGAIN_HOME set?): " + DFLT_CFG); return start0(new GridStartContext(new GridConfiguration(), null, springCtx)).grid(); }
URL cfgUrl = U.resolveGridGainUrl(cfgPath);
/** * Reads log. * * @param path Path where read log located. * @param from Number of line to start from. * @param to Number tof line to finish on. * @return List of read lines. * @throws GridException If argumets are illegal. * @throws IOException If file couldn't be accessed or read failed. */ private List<String> readLog(String path, int from, int to) throws GridException, IOException { URL url = U.resolveGridGainUrl(path); if (url == null) throw new GridException("Log file not found: " + path); if (!isAccessible(url)) throw new GridException("File is not accessible through REST" + " (check restAccessibleFolders configuration property): " + path); if (from >= 0 && to >= 0) return readLinesForward(url, from, to); else if (from < 0 && to < 0) return readLinesBackward(url, from, to); else throw new GridException( "Illegal arguments (both should be positive or negative) [from=" + from + ", to=" + to + ']'); }