static {
   try {
     htConfig = UtilLucene.luceneConfig(LuceneFields.HOST_PATHOGEN_TYPE, UtilTest.goodProperties);
   } catch (InitializationException e) {
     e.printStackTrace();
   }
 }
Example #2
0
  /**
   * Test to show that reporting an error about an uninitialized variable when generating templates
   * reports the correct line.
   */
  @Test
  public void testParseTemplate() throws Exception {
    String[] lines = {
      /* 0 */ "template: template",
      /* 1 */ "a: {missingVar}",
      /* 2 */ "a: b",
      /* 3 */ "a: c",
      /* 4 */ "",
      /* 5 */ "template: template2",
    };

    // Test must show "missingVar" missing on line 1.
    // Previous behaviour showed "missingVar" on line 5.

    TemplateFile templateFile = new TemplateFile(resourcePath);
    List<LocalizableMessage> warns = new ArrayList<>();

    try {
      templateFile.parse(lines, warns);
    } catch (InitializationException e) {
      String msg = e.getMessage();
      LocalizableMessage msg_locale = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get("missingVar", 1);
      assertEquals(msg, msg_locale.toString(), msg);
    }
  }
Example #3
0
  @Override
  public synchronized void initializePlugins() {
    if (_initialized) {
      InitializationException ex = new InitializationException();
      ex.reason = "plug-ins already initialized";
      throw ex;
    }

    //
    // Invoke initialize() on the plug-ins, in the order they were loaded.
    //
    java.util.List<Plugin> initializedPlugins = new java.util.ArrayList<>();
    try {
      for (PluginInfo p : _plugins) {
        try {
          p.plugin.initialize();
        } catch (PluginInitializationException ex) {
          throw ex;
        } catch (RuntimeException ex) {
          PluginInitializationException e = new PluginInitializationException();
          e.reason = "plugin `" + p.name + "' initialization failed";
          e.initCause(ex);
          throw e;
        }
        initializedPlugins.add(p.plugin);
      }
    } catch (RuntimeException ex) {
      //
      // Destroy the plug-ins that have been successfully initialized, in the
      // reverse order.
      //
      java.util.ListIterator<Plugin> i = initializedPlugins.listIterator(initializedPlugins.size());
      while (i.hasPrevious()) {
        Plugin p = i.previous();
        try {
          p.destroy();
        } catch (RuntimeException e) {
          // Ignore.
        }
      }
      throw ex;
    }

    _initialized = true;
  }
Example #4
0
  //
  // Only for use by IceInternal.ObjectAdapterFactory
  //
  public ObjectAdapterI(
      IceInternal.Instance instance,
      Communicator communicator,
      IceInternal.ObjectAdapterFactory objectAdapterFactory,
      String name,
      RouterPrx router,
      boolean noConfig) {
    _instance = instance;
    _communicator = communicator;
    _objectAdapterFactory = objectAdapterFactory;
    _servantManager = new IceInternal.ServantManager(instance, name);
    _name = name;
    _directCount = 0;
    _noConfig = noConfig;

    if (_noConfig) {
      _id = "";
      _replicaGroupId = "";
      _reference = _instance.referenceFactory().create("dummy -t", "");
      _acm = _instance.serverACM();
      _messageSizeMax = _instance.messageSizeMax();
      return;
    }

    final Properties properties = _instance.initializationData().properties;
    List<String> unknownProps = new ArrayList<String>();
    boolean noProps = filterProperties(unknownProps);

    //
    // Warn about unknown object adapter properties.
    //
    if (unknownProps.size() != 0
        && properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) {
      StringBuffer message = new StringBuffer("found unknown properties for object adapter `");
      message.append(_name);
      message.append("':");
      for (String p : unknownProps) {
        message.append("\n    ");
        message.append(p);
      }
      _instance.initializationData().logger.warning(message.toString());
    }

    //
    // Make sure named adapter has some configuration.
    //
    if (router == null && noProps) {
      //
      // These need to be set to prevent finalizer from complaining.
      //
      _state = StateDestroyed;
      _instance = null;
      _incomingConnectionFactories = null;

      InitializationException ex = new InitializationException();
      ex.reason = "object adapter `" + _name + "' requires configuration";
      throw ex;
    }

    _id = properties.getProperty(_name + ".AdapterId");
    _replicaGroupId = properties.getProperty(_name + ".ReplicaGroupId");

    //
    // Setup a reference to be used to get the default proxy options
    // when creating new proxies. By default, create twoway proxies.
    //
    String proxyOptions = properties.getPropertyWithDefault(_name + ".ProxyOptions", "-t");
    try {
      _reference = _instance.referenceFactory().create("dummy " + proxyOptions, "");
    } catch (ProxyParseException e) {
      InitializationException ex = new InitializationException();
      ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'";
      throw ex;
    }

    _acm =
        new IceInternal.ACMConfig(
            properties, communicator.getLogger(), _name + ".ACM", instance.serverACM());

    {
      final int defaultMessageSizeMax = instance.messageSizeMax() / 1024;
      int num =
          properties.getPropertyAsIntWithDefault(_name + ".MessageSizeMax", defaultMessageSizeMax);
      if (num < 1 || num > 0x7fffffff / 1024) {
        _messageSizeMax = 0x7fffffff;
      } else {
        _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes
      }
    }

    try {
      int threadPoolSize = properties.getPropertyAsInt(_name + ".ThreadPool.Size");
      int threadPoolSizeMax = properties.getPropertyAsInt(_name + ".ThreadPool.SizeMax");

      //
      // Create the per-adapter thread pool, if necessary.
      //
      if (threadPoolSize > 0 || threadPoolSizeMax > 0) {
        _threadPool = new IceInternal.ThreadPool(_instance, _name + ".ThreadPool", 0);
      }

      if (router == null) {
        router =
            RouterPrxHelper.uncheckedCast(
                _instance.proxyFactory().propertyToProxy(name + ".Router"));
      }
      if (router != null) {
        _routerInfo = _instance.routerManager().get(router);
        if (_routerInfo != null) {
          //
          // Make sure this router is not already registered with another adapter.
          //
          if (_routerInfo.getAdapter() != null) {
            throw new AlreadyRegisteredException(
                "object adapter with router", _instance.identityToString(router.ice_getIdentity()));
          }

          //
          // Add the router's server proxy endpoints to this object
          // adapter.
          //
          IceInternal.EndpointI[] endpoints = _routerInfo.getServerEndpoints();
          for (IceInternal.EndpointI endpoint : endpoints) {
            _routerEndpoints.add(endpoint);
          }
          java.util.Collections.sort(_routerEndpoints); // Must be sorted.

          //
          // Remove duplicate endpoints, so we have a list of unique
          // endpoints.
          //
          for (int i = 0; i < _routerEndpoints.size() - 1; ) {
            IceInternal.EndpointI e1 = _routerEndpoints.get(i);
            IceInternal.EndpointI e2 = _routerEndpoints.get(i + 1);
            if (e1.equals(e2)) {
              _routerEndpoints.remove(i);
            } else {
              ++i;
            }
          }

          //
          // Associate this object adapter with the router. This way,
          // new outgoing connections to the router's client proxy will
          // use this object adapter for callbacks.
          //
          _routerInfo.setAdapter(this);

          //
          // Also modify all existing outgoing connections to the
          // router's client proxy to use this object adapter for
          // callbacks.
          //
          _instance.outgoingConnectionFactory().setRouterInfo(_routerInfo);
        }
      } else {
        //
        // Parse the endpoints, but don't store them in the adapter. The connection
        // factory might change it, for example, to fill in the real port number.
        //
        List<IceInternal.EndpointI> endpoints =
            parseEndpoints(properties.getProperty(_name + ".Endpoints"), true);
        for (IceInternal.EndpointI endp : endpoints) {
          IncomingConnectionFactory factory =
              new IncomingConnectionFactory(instance, endp, this, _name);
          _incomingConnectionFactories.add(factory);
        }
        if (endpoints.size() == 0) {
          IceInternal.TraceLevels tl = _instance.traceLevels();
          if (tl.network >= 2) {
            _instance
                .initializationData()
                .logger
                .trace(tl.networkCat, "created adapter `" + name + "' without endpoints");
          }
        }

        //
        // Parse the publsihed endpoints.
        //
        _publishedEndpoints = parsePublishedEndpoints();
      }

      if (properties.getProperty(_name + ".Locator").length() > 0) {
        setLocator(
            LocatorPrxHelper.uncheckedCast(
                _instance.proxyFactory().propertyToProxy(_name + ".Locator")));
      } else {
        setLocator(_instance.referenceFactory().getDefaultLocator());
      }
    } catch (LocalException ex) {
      destroy();
      throw ex;
    }
  }
  /**
   * Rebuild index(es) in the backend instance. Note that the server will not explicitly initialize
   * this backend before calling this method.
   *
   * @param rebuildConfig The rebuild configuration.
   * @throws ConfigException If an unrecoverable problem arises during initialization.
   * @throws InitializationException If a problem occurs during initialization that is not related
   *     to the server configuration.
   * @throws DirectoryException If a Directory Server error occurs.
   */
  public void rebuildBackend(RebuildConfig rebuildConfig)
      throws InitializationException, ConfigException, DirectoryException {
    // If the backend already has the root container open, we must use the same
    // underlying root container
    boolean openRootContainer = rootContainer == null;

    /*
     * If the rootContainer is open, the backend is initialized by something
     * else. We can't do any rebuild of system indexes while others are using
     * this backend.
     */
    if (!openRootContainer && rebuildConfig.includesSystemIndex()) {
      Message message = ERR_JEB_REBUILD_BACKEND_ONLINE.get();
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    }

    try {
      EnvironmentConfig envConfig;
      if (openRootContainer) {
        envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setTransactional(false);
        envConfig.setDurability(Durability.COMMIT_NO_SYNC);
        envConfig.setLockTimeout(0, TimeUnit.SECONDS);
        envConfig.setTxnTimeout(0, TimeUnit.SECONDS);
        envConfig.setConfigParam(
            EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION,
            String.valueOf(cfg.getDBCleanerMinUtilization()));
        envConfig.setConfigParam(
            EnvironmentConfig.LOG_FILE_MAX, String.valueOf(cfg.getDBLogFileMax()));

        Importer importer = new Importer(rebuildConfig, cfg, envConfig);
        rootContainer = initializeRootContainer(envConfig);
        importer.rebuildIndexes(rootContainer);
      } else {
        envConfig = ConfigurableEnvironment.parseConfigEntry(cfg);

        Importer importer = new Importer(rebuildConfig, cfg, envConfig);
        importer.rebuildIndexes(rootContainer);
      }
    } catch (ExecutionException execEx) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, execEx);
      }
      Message message = ERR_EXECUTION_ERROR.get(execEx.getMessage());
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    } catch (InterruptedException intEx) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, intEx);
      }
      Message message = ERR_INTERRUPTED_ERROR.get(intEx.getMessage());
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    } catch (ConfigException ce) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, ce);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), ce.getMessageObject());
    } catch (JebException e) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), e.getMessageObject());
    } catch (InitializationException e) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
      throw new InitializationException(e.getMessageObject());
    } finally {
      // If a root container was opened in this method as read only, close it
      // to leave the backend in the same state.
      if (openRootContainer && rootContainer != null) {
        try {
          rootContainer.close();
          rootContainer = null;
        } catch (DatabaseException e) {
          if (debugEnabled()) {
            TRACER.debugCaught(DebugLogLevel.ERROR, e);
          }
        }
      }
    }
  }
  /** {@inheritDoc} */
  @Override()
  public LDIFImportResult importLDIF(LDIFImportConfig importConfig) throws DirectoryException {
    RuntimeInformation.logInfo();

    // If the backend already has the root container open, we must use the same
    // underlying root container
    boolean openRootContainer = rootContainer == null;

    // If the rootContainer is open, the backend is initialized by something
    // else.
    // We can't do import while the backend is online.
    if (!openRootContainer) {
      Message message = ERR_JEB_IMPORT_BACKEND_ONLINE.get();
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    }

    try {
      EnvironmentConfig envConfig = new EnvironmentConfig();

      envConfig.setAllowCreate(true);
      envConfig.setTransactional(false);
      envConfig.setDurability(Durability.COMMIT_NO_SYNC);
      envConfig.setLockTimeout(0, TimeUnit.SECONDS);
      envConfig.setTxnTimeout(0, TimeUnit.SECONDS);
      envConfig.setConfigParam(
          EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION,
          String.valueOf(cfg.getDBCleanerMinUtilization()));
      envConfig.setConfigParam(
          EnvironmentConfig.LOG_FILE_MAX, String.valueOf(cfg.getDBLogFileMax()));

      if (!importConfig.appendToExistingData()) {
        if (importConfig.clearBackend() || cfg.getBaseDN().size() <= 1) {
          // We have the writer lock on the environment, now delete the
          // environment and re-open it. Only do this when we are
          // importing to all the base DNs in the backend or if the backend only
          // have one base DN.
          File parentDirectory = getFileForPath(cfg.getDBDirectory());
          File backendDirectory = new File(parentDirectory, cfg.getBackendId());
          // If the backend does not exist the import will create it.
          if (backendDirectory.exists()) {
            EnvManager.removeFiles(backendDirectory.getPath());
          }
        }
      }

      Importer importer = new Importer(importConfig, cfg, envConfig);
      rootContainer = initializeRootContainer(envConfig);
      return importer.processImport(rootContainer);
    } catch (ExecutionException execEx) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, execEx);
      }
      if (execEx.getCause() instanceof DirectoryException) {
        throw ((DirectoryException) execEx.getCause());
      } else {
        Message message = ERR_EXECUTION_ERROR.get(execEx.getMessage());
        throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
      }
    } catch (InterruptedException intEx) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, intEx);
      }
      Message message = ERR_INTERRUPTED_ERROR.get(intEx.getMessage());
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    } catch (JebException je) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, je);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), je.getMessageObject());
    } catch (InitializationException ie) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, ie);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), ie.getMessageObject());
    } catch (ConfigException ce) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, ce);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), ce.getMessageObject());
    } finally {
      // leave the backend in the same state.
      try {
        if (rootContainer != null) {
          long startTime = System.currentTimeMillis();
          rootContainer.close();
          long finishTime = System.currentTimeMillis();
          long closeTime = (finishTime - startTime) / 1000;
          Message msg = NOTE_JEB_IMPORT_LDIF_ROOTCONTAINER_CLOSE.get(closeTime);
          logError(msg);
          rootContainer = null;
        }

        // Sync the environment to disk.
        if (debugEnabled()) {
          Message message = NOTE_JEB_IMPORT_CLOSING_DATABASE.get();
          TRACER.debugInfo(message.toString());
        }
      } catch (DatabaseException de) {
        if (debugEnabled()) {
          TRACER.debugCaught(DebugLogLevel.ERROR, de);
        }
      }
    }
  }
  /** {@inheritDoc} */
  @Override()
  public void exportLDIF(LDIFExportConfig exportConfig) throws DirectoryException {
    // If the backend already has the root container open, we must use the same
    // underlying root container
    boolean openRootContainer = rootContainer == null;

    try {
      if (openRootContainer) {
        EnvironmentConfig envConfig = ConfigurableEnvironment.parseConfigEntry(cfg);

        envConfig.setReadOnly(true);
        envConfig.setAllowCreate(false);
        envConfig.setTransactional(false);
        envConfig.setConfigParam("je.env.isLocking", "true");
        envConfig.setConfigParam("je.env.runCheckpointer", "true");

        rootContainer = initializeRootContainer(envConfig);
      }

      ExportJob exportJob = new ExportJob(exportConfig);
      exportJob.exportLDIF(rootContainer);
    } catch (IOException ioe) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, ioe);
      }
      Message message = ERR_JEB_EXPORT_IO_ERROR.get(ioe.getMessage());
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    } catch (JebException je) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, je);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), je.getMessageObject());
    } catch (DatabaseException de) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, de);
      }
      throw createDirectoryException(de);
    } catch (LDIFException e) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), e.getMessageObject());
    } catch (InitializationException ie) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, ie);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), ie.getMessageObject());
    } catch (ConfigException ce) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, ce);
      }
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), ce.getMessageObject());
    } finally {
      // If a root container was opened in this method as read only, close it
      // to leave the backend in the same state.
      if (openRootContainer && rootContainer != null) {
        try {
          rootContainer.close();
          rootContainer = null;
        } catch (DatabaseException e) {
          if (debugEnabled()) {
            TRACER.debugCaught(DebugLogLevel.ERROR, e);
          }
        }
      }
    }
  }