Ejemplo n.º 1
0
 /**
  * Performs validation on the specified file to make sure that it is an actual OpenDJ
  * installation.
  *
  * @param rootDirectory File directory candidate
  * @throws IllegalArgumentException if root directory does not appear to be an OpenDJ installation
  *     root. The thrown exception contains a localized message indicating the reason why <code>
  *     rootDirectory</code> is not a valid OpenDJ install root.
  */
 public static void validateRootDirectory(File rootDirectory) throws IllegalArgumentException {
   LocalizableMessage failureReason = null;
   if (rootDirectory == null) {
     failureReason = INFO_ERROR_INSTALL_ROOT_DIR_NULL.get();
   } else if (!rootDirectory.exists()) {
     failureReason = INFO_ERROR_INSTALL_ROOT_DIR_NO_EXIST.get(Utils.getPath(rootDirectory));
   } else if (!rootDirectory.isDirectory()) {
     failureReason = INFO_ERROR_INSTALL_ROOT_DIR_NOT_DIR.get(Utils.getPath(rootDirectory));
   } else {
     String[] children = rootDirectory.list();
     if (children != null) {
       Set<String> childrenSet = CollectionUtils.newHashSet(children);
       for (String dir : REQUIRED_DIRECTORIES) {
         if (!childrenSet.contains(dir)) {
           failureReason =
               INFO_ERROR_INSTALL_ROOT_DIR_NO_DIR.get(Utils.getPath(rootDirectory), dir);
         }
       }
     } else {
       failureReason = INFO_ERROR_INSTALL_ROOT_DIR_EMPTY.get(Utils.getPath(rootDirectory));
     }
   }
   if (failureReason != null) {
     throw new IllegalArgumentException(failureReason.toString());
   }
 }
Ejemplo n.º 2
0
  /** The constructor of a CurrentInstallStatus object. */
  public CurrentInstallStatus() {
    if (Utils.isWebStart()) {
      isInstalled = false;
    } else {
      Installation installation = Installation.getLocal();
      ArrayList<LocalizableMessage> msgs = new ArrayList<>();

      if (installation.getStatus().isServerRunning()) {
        msgs.add(INFO_INSTALLSTATUS_SERVERRUNNING.get(getPort()));
      }

      if (dbFilesExist()) {
        canOverwriteCurrentInstall = true;
        msgs.add(INFO_INSTALLSTATUS_DBFILEEXIST.get());
      }

      if (configExists()) {
        canOverwriteCurrentInstall = false;
        isInstalled = true;
        msgs.add(INFO_INSTALLSTATUS_CONFIGFILEMODIFIED.get());
      }

      if (canOverwriteCurrentInstall) {
        installationMsg =
            !Utils.isCli()
                ? INFO_INSTALLSTATUS_CANOVERWRITECURRENTINSTALL_MSG.get()
                : INFO_INSTALLSTATUS_CANOVERWRITECURRENTINSTALL_MSG_CLI.get();
      } else if (isInstalled) {
        LocalizableMessageBuilder buf = new LocalizableMessageBuilder();
        if (Utils.isCli()) {
          buf = new LocalizableMessageBuilder();
          for (LocalizableMessage msg : msgs) {
            buf.append(Constants.LINE_SEPARATOR);
            buf.append("- ").append(msg);
          }
          String cmd =
              isWindows()
                  ? Installation.WINDOWS_SETUP_FILE_NAME
                  : Installation.UNIX_SETUP_FILE_NAME;
          installationMsg = INFO_INSTALLSTATUS_INSTALLED_CLI.get(cmd, buf);
        } else {
          buf.append("<ul>");
          for (LocalizableMessage msg : msgs) {
            buf.append("\n<li>");
            buf.append(msg);
            buf.append("</li>");
          }
          buf.append("</ul>");
          installationMsg = INFO_INSTALLSTATUS_INSTALLED.get(buf);
        }
      }
    }
    if (!isInstalled) {
      installationMsg = INFO_INSTALLSTATUS_NOT_INSTALLED.get();
    }
  }
Ejemplo n.º 3
0
 private static int getDefaultPort(int basePort) {
   for (int i = 0; i < 10000; i += 1000) {
     int port = i + basePort;
     if (Utils.canUseAsPort(port)) {
       return port;
     }
   }
   return -1;
 }
Ejemplo n.º 4
0
  /**
   * Provides the port that will be proposed to the user in the security dialog of the installation
   * wizard. It will check whether we can use ports of type X636 and if not it will return -1.
   *
   * @param defaultLdapPort the default port used for LDAP.
   * @return the free port of type X636 if it is available and we can use and -1 if not.
   */
  public static int getDefaultSslPort(int defaultLdapPort) {
    int port = defaultLdapPort - 389 + 636;
    // Try first with the correlated port of the default LDAP port.
    if (Utils.canUseAsPort(port)) {
      return port;
    }

    return getDefaultPort(636);
  }
Ejemplo n.º 5
0
  /**
   * Obtains the installation by reading the classpath of the running JVM to determine the location
   * of the jars and determine the installation root.
   *
   * @return Installation obtained by reading the classpath
   */
  public static Installation getLocal() {
    if (local == null) {

      // This allows testing of configuration components when the OpenDJ.jar
      // in the classpath does not necessarily point to the server's
      String installRoot = System.getProperty("org.opends.quicksetup.Root");
      String instanceRoot = System.getProperty("org.opends.quicksetup.instance");

      if (installRoot == null) {
        installRoot = Utils.getInstallPathFromClasspath();
      }
      if (instanceRoot == null) {
        instanceRoot = Utils.getInstancePathFromInstallPath(installRoot);
      }
      local = new Installation(installRoot, instanceRoot);
    }
    return local;
  }
Ejemplo n.º 6
0
  /**
   * Provides the port that will be used by default for JMX.
   *
   * @param forbiddenPorts an array of ports that we cannot use.
   * @return the port X689 if it is available and we can use and -1 if not.
   */
  public static int getDefaultJMXPort(int[] forbiddenPorts) {
    int defaultJMXPort = -1;

    for (int i = 0; i < 65000 && (defaultJMXPort == -1); i += 1000) {
      int port = i + CliConstants.DEFAULT_JMX_PORT;
      boolean isForbidden = false;
      if (forbiddenPorts != null) {
        for (int j = 0; j < forbiddenPorts.length && !isForbidden; j++) {
          isForbidden = forbiddenPorts[j] == port;
        }
      }
      if (!isForbidden && Utils.canUseAsPort(port)) {
        defaultJMXPort = port;
      }
    }
    return defaultJMXPort;
  }
Ejemplo n.º 7
0
  private static void updateReplicas(
      ServerDescriptor desc, InitialLdapContext ctx, TopologyCacheFilter cacheFilter)
      throws NamingException {
    if (!cacheFilter.searchBaseDNInformation()) {
      return;
    }
    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    ctls.setReturningAttributes(new String[] {"ds-cfg-base-dn", "ds-cfg-backend-id"});
    String filter = "(objectclass=ds-cfg-backend)";

    LdapName jndiName = new LdapName("cn=config");
    NamingEnumeration<SearchResult> databases = ctx.search(jndiName, filter, ctls);

    try {
      while (databases.hasMore()) {
        SearchResult sr = databases.next();

        String id = getFirstValue(sr, "ds-cfg-backend-id");

        if (!isConfigBackend(id) || isSchemaBackend(id)) {
          Set<String> baseDns = getValues(sr, "ds-cfg-base-dn");

          Set<String> entries;
          if (cacheFilter.searchMonitoringInformation()) {
            entries = getBaseDNEntryCount(ctx, id);
          } else {
            entries = new HashSet<String>();
          }

          Set<ReplicaDescriptor> replicas = desc.getReplicas();
          for (String baseDn : baseDns) {
            boolean addReplica = cacheFilter.searchAllBaseDNs();
            if (!addReplica) {
              for (String dn : cacheFilter.getBaseDNsToSearch()) {
                addReplica = Utils.areDnsEqual(dn, baseDn);
                if (addReplica) {
                  break;
                }
              }
            }
            if (addReplica) {
              SuffixDescriptor suffix = new SuffixDescriptor();
              suffix.setDN(baseDn);
              ReplicaDescriptor replica = new ReplicaDescriptor();
              replica.setServer(desc);
              replica.setBackendName(id);
              replicas.add(replica);
              HashSet<ReplicaDescriptor> r = new HashSet<ReplicaDescriptor>();
              r.add(replica);
              suffix.setReplicas(r);
              replica.setSuffix(suffix);
              int nEntries = -1;
              for (String s : entries) {
                int index = s.indexOf(" ");
                if (index != -1) {
                  String dn = s.substring(index + 1);
                  if (Utils.areDnsEqual(baseDn, dn)) {
                    try {
                      nEntries = Integer.parseInt(s.substring(0, index));
                    } catch (Throwable t) {
                      /* Ignore */
                    }
                    break;
                  }
                }
              }
              replica.setEntries(nEntries);
            }
          }
          desc.setReplicas(replicas);
        }
      }
    } finally {
      databases.close();
    }
  }