Ejemplo n.º 1
0
  public String configFile() {
    // Check template URL exists
    String templateUrl = driver.getEntity().getConfig(NginxController.SERVER_CONF_TEMPLATE_URL);
    ResourceUtils.create(this).checkUrlExists(templateUrl);

    // Check SSL configuration
    ProxySslConfig ssl = driver.getEntity().getConfig(NginxController.SSL_CONFIG);
    if (ssl != null
        && Strings.isEmpty(ssl.getCertificateDestination())
        && Strings.isEmpty(ssl.getCertificateSourceUrl())) {
      throw new IllegalStateException(
          "ProxySslConfig can't have a null certificateDestination and null certificateSourceUrl. One or both need to be set");
    }

    // For mapping by URL
    Iterable<UrlMapping> mappings = ((NginxController) driver.getEntity()).getUrlMappings();
    Multimap<String, UrlMapping> mappingsByDomain = LinkedHashMultimap.create();
    for (UrlMapping mapping : mappings) {
      Collection<String> addrs = mapping.getAttribute(UrlMapping.TARGET_ADDRESSES);
      if (addrs != null && addrs.size() > 0) {
        mappingsByDomain.put(mapping.getDomain(), mapping);
      }
    }
    Map<String, Object> substitutions =
        MutableMap.<String, Object>builder()
            .putIfNotNull("ssl", ssl)
            .put("urlMappings", mappings)
            .put("domainMappings", mappingsByDomain)
            .build();

    // Get template contents and process
    String contents = ResourceUtils.create(driver.getEntity()).getResourceAsString(templateUrl);
    return TemplateProcessor.processTemplateContents(contents, driver, substitutions);
  }
    protected void postStartCustom() {
      super.postStartCustom();

      // now run the creation script
      String creationScript;
      String creationScriptUrl = entity().getConfig(PostgreSqlNode.CREATION_SCRIPT_URL);
      if (creationScriptUrl != null) {
        creationScript = ResourceUtils.create(entity()).getResourceAsString(creationScriptUrl);
      } else {
        creationScript = entity().getConfig(PostgreSqlNode.CREATION_SCRIPT_CONTENTS);
      }
      entity().executeScript(creationScript);

      // and finally connect sensors
      entity().connectSensors();
    }