/**
   * Writes driver configuration to disk.
   *
   * @param jobFolder The folder in which the job is staged.
   * @param jobId id of the job to be submitted
   * @param clientRemoteId The client remote id
   * @return the configuration
   * @throws IOException
   */
  public Configuration writeConfiguration(
      final File jobFolder, final String jobId, final String clientRemoteId) throws IOException {
    final File driverFolder = new File(jobFolder, PreparedDriverFolderLauncher.DRIVER_FOLDER_NAME);

    final Configuration driverConfiguration1 =
        driverConfigurationProvider.getDriverConfiguration(
            jobFolder.toURI(),
            clientRemoteId,
            jobId,
            Constants.DRIVER_CONFIGURATION_WITH_HTTP_AND_NAMESERVER);
    final ConfigurationBuilder configurationBuilder =
        Tang.Factory.getTang().newConfigurationBuilder();
    for (final ConfigurationProvider configurationProvider : this.configurationProviders) {
      configurationBuilder.addConfiguration(configurationProvider.getConfiguration());
    }
    final Configuration providedConfigurations = configurationBuilder.build();
    final Configuration driverConfiguration =
        Configurations.merge(
            driverConfiguration1,
            Tang.Factory.getTang()
                .newConfigurationBuilder()
                .bindNamedParameter(JobSubmissionDirectory.class, driverFolder.toString())
                .build(),
            providedConfigurations);
    final File driverConfigurationFile =
        new File(driverFolder, fileNames.getDriverConfigurationPath());
    configurationSerializer.toFile(driverConfiguration, driverConfigurationFile);
    return driverConfiguration;
  }
  public void validatePlan() throws IOException, BindException, InjectionException {

    final Tang t = Tang.Factory.getTang();

    // TODO Use the AvroClassHierarchySerializer
    final ClassHierarchyProto.Node root;
    try (final InputStream chin = new FileInputStream(this.ch)) {
      root = ClassHierarchyProto.Node.parseFrom(chin);
    }

    final ClassHierarchy classHierarchy = new ProtocolBufferClassHierarchy(root);
    final ConfigurationBuilder cb = t.newConfigurationBuilder(classHierarchy);

    if (!inConfig.canRead()) {
      throw new IOException("Cannot read input config file: " + inConfig);
    }

    ConfigurationFile.addConfiguration(cb, inConfig);

    if (target != null) {
      final Injector i = t.newInjector(cb.build());
      final InjectionPlan<?> ip = i.getInjectionPlan(target);
      if (!ip.isInjectable()) {
        throw new InjectionException(target + " is not injectable: " + ip.toCantInjectString());
      }
    }

    ConfigurationFile.writeConfigurationFile(cb.build(), outConfig);

    //    Injector i = t.newInjector(cb.build());
    //    InjectionPlan<?> ip = i.getInjectionPlan(target);
    //    try (final OutputStream ipout = new FileOutputStream(injectionPlan)) {
    //      new ProtocolBufferInjectionPlan().serialize(ip).writeTo(ipout);
    //    }
  }