/**
   * This is a validation of the application configuration on the AM. Here is where things like the
   * existence of keytabs and other not-seen-client-side properties can be tested, before the actual
   * process is spawned.
   *
   * @param instanceDefinition clusterSpecification
   * @param confDir configuration directory
   * @param secure flag to indicate that secure mode checks must exist
   * @throws IOException IO problemsn
   * @throws SliderException any failure
   */
  @Override
  public void validateApplicationConfiguration(
      AggregateConf instanceDefinition, File confDir, boolean secure)
      throws IOException, SliderException {
    String siteXMLFilename = SITE_XML;
    File siteXML = new File(confDir, siteXMLFilename);
    if (!siteXML.exists()) {
      throw new BadCommandArgumentsException(
          "Configuration directory %s doesn't contain %s - listing is %s",
          confDir, siteXMLFilename, SliderUtils.listDir(confDir));
    }

    // now read it in
    siteConf = ConfigHelper.loadConfFromFile(siteXML);
    // look in the site spec to see that it is OK
    clientProvider.validateHBaseSiteXML(siteConf, secure, siteXMLFilename);

    if (secure) {
      // secure mode: take a look at the keytab of master and RS
      SliderUtils.verifyKeytabExists(siteConf, HBaseConfigFileOptions.KEY_MASTER_KERBEROS_KEYTAB);
      SliderUtils.verifyKeytabExists(
          siteConf, HBaseConfigFileOptions.KEY_REGIONSERVER_KERBEROS_KEYTAB);
    }
  }
  @Override
  public void prepareAMAndConfigForLaunch(
      SliderFileSystem fileSystem,
      Configuration serviceConf,
      AbstractLauncher launcher,
      AggregateConf instanceDescription,
      Path snapshotConfDirPath,
      Path generatedConfDirPath,
      Configuration clientConfExtras,
      String libdir,
      Path tempPath,
      boolean miniClusterTestRun)
      throws IOException, SliderException {
    // load in the template site config
    log.debug("Loading template configuration from {}", snapshotConfDirPath);
    Configuration siteConf =
        ConfigHelper.loadTemplateConfiguration(
            serviceConf,
            snapshotConfDirPath,
            AccumuloKeys.SITE_XML,
            AccumuloKeys.SITE_XML_RESOURCE);

    Map<String, LocalResource> providerResources;
    providerResources =
        fileSystem.submitDirectory(generatedConfDirPath, SliderKeys.PROPAGATED_CONF_DIR_NAME);

    ProviderUtils.addProviderJar(
        providerResources,
        this,
        "slider-accumulo-provider.jar",
        fileSystem,
        tempPath,
        libdir,
        miniClusterTestRun);

    addAccumuloDependencyJars(providerResources, fileSystem, libdir, tempPath);
    launcher.addLocalResources(providerResources);

    // construct the cluster configuration values

    ConfTreeOperations appconf = instanceDescription.getAppConfOperations();

    Map<String, String> clusterConfMap = buildSiteConfFromInstance(instanceDescription);

    // merge them
    ConfigHelper.addConfigMap(siteConf, clusterConfMap.entrySet(), "Accumulo Provider");

    // now, if there is an extra client conf, merge it in too
    if (clientConfExtras != null) {
      ConfigHelper.mergeConfigurations(siteConf, clientConfExtras, "Slider Client");
    }

    if (log.isDebugEnabled()) {
      log.debug("Merged Configuration");
      ConfigHelper.dumpConf(siteConf);
    }

    Path sitePath =
        ConfigHelper.saveConfig(serviceConf, siteConf, generatedConfDirPath, AccumuloKeys.SITE_XML);

    log.debug("Saving the config to {}", sitePath);
    launcher.submitDirectory(generatedConfDirPath, SliderKeys.PROPAGATED_CONF_DIR_NAME);
  }