/** * Check if oldPath exist; if so, then raise a ConfigurationException with information for fixing issue * * @param oldPath Path that must NOT exist * @param message Error message thrown with exception * @throws ConfigurationException If an old path has been discovered */ protected void checkPath(File oldPath, String message) throws ConfigurationException { if (oldPath.exists()) { log.error("Deprecated paths used."); throw new ConfigurationException(message); } }
/** * @param address address to check for availability * @since 5.5 */ public static void checkAddressReachable(InetAddress address) throws ConfigurationException { try { log.debug("Checking availability of " + address); address.isReachable(ADDRESS_PING_TIMEOUT); } catch (IOException e) { throw new ConfigurationException("Unreachable bind address " + address); } }
@Override public void check(ConfigurationGenerator cg) throws ConfigurationException { try { checkDatabaseConnection(cg); } catch (IOException e) { throw new ConfigurationException(e); } catch (DatabaseDriverException e) { log.debug(e, e); log.error(e.getMessage()); throw new ConfigurationException("Could not find database driver: " + e.getMessage()); } catch (SQLException e) { log.debug(e, e); log.error(e.getMessage()); throw new ConfigurationException("Failed to connect on database: " + e.getMessage()); } }
/** * @param template path to configuration template directory * @return A {@code nuxeo.defaults} file if it exists. * @throws ConfigurationException if the template file is not found. * @since 7.4 */ public File getTemplateConf(String template) throws ConfigurationException { File templateDir = new File(template); if (!templateDir.isAbsolute()) { templateDir = new File(System.getProperty("user.dir"), template); if (!templateDir.exists() || !new File(templateDir, NUXEO_DEFAULT_CONF).exists()) { templateDir = new File(nuxeoDefaultConf.getParentFile(), template); } } if (!templateDir.exists() || !new File(templateDir, NUXEO_DEFAULT_CONF).exists()) { throw new ConfigurationException("Template not found: " + template); } return new File(templateDir, NUXEO_DEFAULT_CONF); }
/** * Read nuxeo.conf, replace backslashes in paths and write new nuxeo.conf * * @throws ConfigurationException if any error reading or writing nuxeo.conf * @since 5.4.1 */ protected void replaceBackslashes() throws ConfigurationException { StringBuilder sb = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new FileReader(nuxeoConf))) { String line; while ((line = reader.readLine()) != null) { if (line.matches(".*:\\\\.*")) { line = line.replaceAll("\\\\", "/"); } sb.append(line).append(System.getProperty("line.separator")); } } catch (IOException e) { throw new ConfigurationException("Error reading " + nuxeoConf, e); } try (FileWriter writer = new FileWriter(nuxeoConf, false)) { // Copy back file content writer.append(sb.toString()); } catch (IOException e) { throw new ConfigurationException("Error writing in " + nuxeoConf, e); } }
protected void generateFiles() throws ConfigurationException { try { serverConfigurator.parseAndCopy(userConfig); serverConfigurator.dumpProperties(userConfig); log.info("Configuration files generated."); // keep true or false, switch once to false if (onceGeneration) { setOnceToFalse = true; writeConfiguration(); } } catch (FileNotFoundException e) { throw new ConfigurationException("Missing file: " + e.getMessage(), e); } catch (TemplateException | ParseException e) { throw new ConfigurationException("Could not process FreeMarker template: " + e.getMessage(), e); } catch (IOException e) { throw new ConfigurationException("Configuration failure: " + e.getMessage(), e); } }
/** * Checks hostName bind address is not 0.0.0.0 and replaces it with 127.0.0.1 if needed * * @param hostName the hostname of Nuxeo server (works also with the IP) * @return the bind address matching hostName parameter if not 0.0.0.0 else 127.0.0.1 * @since 9.2 */ public static InetAddress getBindAddress(String hostName) throws ConfigurationException { InetAddress bindAddress; try { bindAddress = InetAddress.getByName(hostName); if (bindAddress.isAnyLocalAddress()) { boolean preferIPv6 = "false".equals(System.getProperty("java.net.preferIPv4Stack")) && "true".equals(System.getProperty("java.net.preferIPv6Addresses")); bindAddress = preferIPv6 ? InetAddress.getByName("::1") : InetAddress.getByName("127.0.0.1"); log.debug("Bind address is \"ANY\", using local address instead: " + bindAddress); } log.debug("Configured bind address: " + bindAddress); } catch (UnknownHostException e) { throw new ConfigurationException(e); } return bindAddress; }
public List<ConnectProject> getAvailableProjects(String username, char[] password) throws ConfigurationException { List<ConnectProject> studioProjects = registration().getAvailableProjectsForRegistration(username, new String(password)); if (studioProjects.isEmpty()) { throw new ConfigurationException("Wrong login or password."); } return studioProjects; } }
public void registerLocal(String strCLID, String description) throws IOException, ConfigurationException { try { registration().localRegisterInstance(strCLID, description); } catch (LogicalInstanceIdentifier.InvalidCLID e) { log.debug(e, e); throw new ConfigurationException("Instance registration failed.", e); } }
throw new ConfigurationException(e.getMessage() + ": " + address + ":" + port, e); } finally {
backup.delete(); } catch (IOException e) { throw new ConfigurationException(String.format( "Failed to restore %s from %s\nEdit or " + "delete %s to bypass that error.", line.substring(0, line.length() - 4), line, newFiles), e);
String line = reader.readLine(); if (line != null && line.startsWith("## DO NOT EDIT THIS FILE")) { throw new ConfigurationException("The template states in its header that it must not be modified.");
writer.append(newContent.getBuffer()); } catch (IOException e) { throw new ConfigurationException("Error writing in " + nuxeoConf, e);
protected Collection<BackingChecker> getCheckers() throws ConfigurationException { if (checkers == null) { checkers = new HashSet<>(); for (String template : configurationGenerator.getTemplateList()) { try { File templateDir = configurationGenerator.getTemplateConf(template).getParentFile(); String classPath = getClasspathForTemplate(template); String checkClass = configurationGenerator.getUserConfig() .getProperty(template + PARAM_CHECK_SUFFIX); Optional<URLClassLoader> ucl = getClassLoaderForTemplate(templateDir, classPath); if (ucl.isPresent()) { Class<?> klass = Class.forName(checkClass, true, ucl.get()); checkers.add((BackingChecker) klass.newInstance()); } } catch (IOException e) { log.warn("Unable to read check configuration for template : " + template, e); } catch (ReflectiveOperationException | ClassCastException e) { throw new ConfigurationException("Unable to check configuration for backing service " + template, e); } } } return checkers; }
currentConfigurationDigest = Hex.encodeHexString(digest.digest()); } catch (IOException e) { throw new ConfigurationException("Error reading " + nuxeoConf, e);
/** * Check server paths; warn if existing deprecated paths. Override this method to perform server specific checks. * * @throws ConfigurationException If deprecated paths have been detected * @since 5.4.2 */ public void checkPaths() throws ConfigurationException { File badInstanceClid = new File(generator.getNuxeoHome(), getDefaultDataDir() + File.separator + "instance.clid"); if (badInstanceClid.exists() && !getDataDir().equals(badInstanceClid.getParentFile())) { log.warn(String.format("Moving %s to %s.", badInstanceClid, getDataDir())); try { FileUtils.moveFileToDirectory(badInstanceClid, getDataDir(), true); } catch (IOException e) { throw new ConfigurationException("NXP-6722 move failed: " + e.getMessage(), e); } } File oldPackagesPath = new File(getDataDir(), getDefaultPackagesDir()); if (oldPackagesPath.exists() && !oldPackagesPath.equals(getPackagesDir())) { log.warn(String.format( "NXP-8014 Packages cache location changed. You can safely delete %s or move its content to %s", oldPackagesPath, getPackagesDir())); } }
/** * Will check the configured addresses are reachable and Nuxeo required ports are available on those addresses. * Server specific implementations should override this method in order to check for server specific ports. * {@link #PARAM_BIND_ADDRESS} must be set before. * * @since 5.5 * @see ServerConfigurator#verifyInstallation() */ public void checkAddressesAndPorts() throws ConfigurationException { InetAddress bindAddress = getBindAddress(); // Sanity check if (bindAddress.isMulticastAddress()) { throw new ConfigurationException("Multicast address won't work: " + bindAddress); } checkAddressReachable(bindAddress); checkPortAvailable(bindAddress, Integer.parseInt(userConfig.getProperty(PARAM_HTTP_PORT))); }
@Override public void check(ConfigurationGenerator cg) throws ConfigurationException { MongoClient ret = null; String serverName = cg.getUserConfig().getProperty(ConfigurationGenerator.PARAM_MONGODB_SERVER); String dbName = cg.getUserConfig().getProperty(ConfigurationGenerator.PARAM_MONGODB_NAME); MongoClientOptions.Builder optionsBuilder = MongoClientOptions.builder() .serverSelectionTimeout( (int) TimeUnit.SECONDS.toMillis(getCheckTimeoutInSeconds(cg))) .description("Nuxeo DB Check"); if (serverName.startsWith("mongodb://")) { // allow mongodb:// URI syntax for the server, to pass everything in one string ret = new MongoClient(new MongoClientURI(serverName, optionsBuilder)); } else { ret = new MongoClient(new ServerAddress(serverName), optionsBuilder.build()); } try { Document ping = new Document("ping", "1"); ret.getDatabase(dbName).runCommand(ping); } catch (MongoTimeoutException e) { throw new ConfigurationException( String.format("Unable to connect to MongoDB at %s, please check your connection", serverName)); } finally { ret.close(); } }
setDirectoryWithProperty(org.nuxeo.common.Environment.NUXEO_MP_DIR); } catch (NullPointerException e) { throw new ConfigurationException("Missing file", e); } catch (FileNotFoundException e) { throw new ConfigurationException("Missing file: " + nuxeoDefaultConf + " or " + nuxeoConf, e); } catch (IOException e) { throw new ConfigurationException("Error reading " + nuxeoConf, e); extractSecondaryDatabaseTemplateName(); } catch (FileNotFoundException e) { throw new ConfigurationException("Missing file", e); } catch (IOException e) { throw new ConfigurationException("Error reading " + nuxeoConf, e);
throw new ConfigurationException(message + " See '" + JVMCHECK_PROP + "' option to bypass version check.");