Exemplo n.º 1
0
 @Test
 public void extensionsProperties() throws IOException {
   Object extensionsBasePackage =
       context.getEnvironment().getProperty("xd.extensions.basepackages", Object.class);
   assertEquals(
       "org.springframework.xd.extensions.test,org.springframework.xd.extensions.test2",
       extensionsBasePackage);
   String extensionsLocation = context.getEnvironment().getProperty("xd.extensions.locations");
   assertEquals("META-INF/spring-xd/ext/test,META-INF/spring-xd/ext/test2", extensionsLocation);
 }
 /**
  * {@inheritDoc}
  *
  * <p>The parent {@linkplain ApplicationContext#getEnvironment() environment} is {@linkplain
  * ConfigurableEnvironment#merge(ConfigurableEnvironment) merged} with this (child) application
  * context environment if the parent is non-{@code null} and its environment is an instance of
  * {@link ConfigurableEnvironment}.
  *
  * @see ConfigurableEnvironment#merge(ConfigurableEnvironment)
  */
 @Override
 public void setParent(ApplicationContext parent) {
   this.parent = parent;
   if (parent != null) {
     Environment parentEnvironment = parent.getEnvironment();
     if (parentEnvironment instanceof ConfigurableEnvironment) {
       getEnvironment().merge((ConfigurableEnvironment) parentEnvironment);
     }
   }
 }
Exemplo n.º 3
0
  /**
   * Creates a {@link CoreContainer} object which has all the Solr cores.
   *
   * @param context The application's context. Required.
   * @return A {@link CoreContainer} object which has all the Solr cores.
   * @throws IOException If the Solr home cannot be created.
   * @throws ParserConfigurationException If the any of the Solr XML files are corrupted.
   * @throws SAXException If the any of the Solr XML files are corrupted.
   */
  @Bean
  public static CoreContainer solrCores(final ApplicationContext context)
      throws IOException, ParserConfigurationException, SAXException {
    notNull(context, "The application's context is required.");
    Environment env = context.getEnvironment();

    final File solrHome = findSolrHome(context);

    final File dataDir = findSolrDataDir(env);

    final Map<String, String> coreDefs = new LinkedHashMap<String, String>();
    CoreContainer cores =
        new CoreContainer(solrHome.getAbsolutePath()) {
          @Override
          public SolrCore create(final CoreDescriptor coreDescriptor) {
            String coreName = coreDescriptor.getName();
            if (coreName.length() == 0) {
              coreName = getDefaultCoreName();
            }

            Properties properties = new Properties();
            String coreDataDir = new File(dataDir, coreName).getAbsolutePath();
            coreDefs.put(coreName, coreDataDir);
            // default data dir
            properties.setProperty(CoreDescriptor.CORE_DATADIR, coreDataDir);

            return super.create(
                new CoreDescriptor(
                    coreDescriptor.getCoreContainer(),
                    coreDescriptor.getName(),
                    coreDescriptor.getInstanceDir(),
                    properties));
          }
        };
    // Initialize cores
    cores.load();

    logger.info("Solr home directory: {}", solrHome);
    for (Entry<String, String> core : coreDefs.entrySet()) {
      logger.info("  core: {}, dataDir: {}", core.getKey(), core.getValue());
    }
    return cores;
  }
Exemplo n.º 4
0
  /**
   *
   *
   * <h3>Fixtures</h3>
   *
   * You can add test or init data by creating a 'fixtures' directory under a Solr core. Test files
   * are described using the Solr XML format for documents.
   *
   * <h4>Fixtures properties</h4>
   *
   * <ul>
   *   solr.fixtures: enabled or disabled the loading of test files. Default is: true.
   *   solr.fixtures.async: if true, a new thread will be created for loading the fixtures. Default
   *   is: true.
   * </ul>
   */
  @PostConstruct
  public void runFixtures() {
    Environment env = applicationContext.getEnvironment();
    boolean runFixtures = env.getProperty(SOLR_FIXTURES, boolean.class, true);
    if (runFixtures) {
      Map<String, SolrServer> servers = applicationContext.getBeansOfType(SolrServer.class);
      CoreContainer cores = applicationContext.getBean(CoreContainer.class);
      String solrHome = cores.getSolrHome();

      boolean async = env.getProperty(SOLR_FIXTURES_ASYNC, boolean.class, true);

      for (Entry<String, SolrServer> server : servers.entrySet()) {
        String coreName = server.getKey();
        File coreHome = new File(solrHome, coreName);
        File fixtures = new File(coreHome, "fixtures");
        if (fixtures.exists()) {
          populate(server.getValue(), coreName, fixtures, async);
        }
      }
    }
  }
Exemplo n.º 5
0
 public static void main(String[] args) {
   TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
   SpringApplication app = new SpringApplication(Application.class);
   app.addListeners(
       new ApplicationListener<ApplicationEnvironmentPreparedEvent>() {
         @Override
         public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
           MDC.put("appName", event.getEnvironment().getProperty("project.name"));
           MDC.put("requestId", "N/A");
           try {
             MDC.put("hostName", InetAddress.getLocalHost().getHostName());
           } catch (IllegalArgumentException | UnknownHostException e) {
             log.info(e);
           }
         }
       });
   ApplicationContext ctx = app.run(args);
   log.info("-----------------------------------------------------------------");
   log.info("Active profiles:");
   Arrays.asList(ctx.getEnvironment().getActiveProfiles()).forEach(log::info);
   log.info("-----------------------------------------------------------------");
 }
Exemplo n.º 6
0
  /**
   * Find the solr home from the given environment.
   *
   * @param context The application's environment.
   * @return The solr's home directory.
   * @throws IOException If the solr.home cannot be resolve.
   */
  private static File findSolrHome(final ApplicationContext context) throws IOException {
    Environment env = context.getEnvironment();
    String solrHome = env.getRequiredProperty(SOLR_HOME);
    File solrHomeDir = new File(solrHome);
    if (!solrHomeDir.exists()) {
      // Ask Spring for it
      Resource resource = context.getResource(solrHome);
      if (!resource.exists()) {
        resource = context.getResource(ResourceUtils.CLASSPATH_URL_PREFIX + solrHome);
      }
      if (resource.exists()) {
        solrHomeDir = resource.getFile();
      }
    }

    isTrue(solrHomeDir.exists(), "Cannot to set: '%s', '%s' doesn't exist", SOLR_HOME, solrHomeDir);
    isTrue(
        solrHomeDir.isDirectory(),
        "Cannot to set: '%s', '%s' must be a directory",
        SOLR_HOME,
        solrHomeDir);

    return solrHomeDir;
  }
Exemplo n.º 7
0
 @Override
 public void setApplicationContext(ApplicationContext context) throws BeansException {
   if (context.getEnvironment().getProperty(LiveBeansView.MBEAN_DOMAIN_PROPERTY_NAME) == null) {
     this.liveBeansView.setApplicationContext(context);
   }
 }
 @Override
 public void setApplicationContext(ApplicationContext context) throws BeansException {
   factory = ((ConfigurableApplicationContext) context).getBeanFactory();
   resolver = new RelaxedPropertyResolver(context.getEnvironment(), PROPERTY_BASE);
 }
Exemplo n.º 9
0
 public static void main(String[] args) {
   ApplicationContext ctx = SpringApplication.run(Application.class, args);
   log.info(
       "Application ready, active profiles:{}",
       Arrays.toString(ctx.getEnvironment().getActiveProfiles()));
 }
Exemplo n.º 10
0
 public Environment getEnvironment() {
   return applicationContext.getEnvironment();
 }