private void updateCassandraYaml(Configuration newConfig) {
    ConfigEditor editor = new ConfigEditor(cassandraYamlFile);
    try {
      editor.load();

      PropertySimple cqlPortProperty = newConfig.getSimple("cqlPort");
      if (cqlPortProperty != null) {
        editor.setNativeTransportPort(cqlPortProperty.getIntegerValue());
      }

      PropertySimple gossipPortProperty = newConfig.getSimple("gossipPort");
      if (gossipPortProperty != null) {
        editor.setStoragePort(gossipPortProperty.getIntegerValue());
      }

      editor.save();
    } catch (ConfigEditorException e) {
      if (e.getCause() instanceof YAMLException) {
        log.error("Failed to update " + cassandraYamlFile);
        log.info("Attempting to restore " + cassandraYamlFile);
        try {
          editor.restore();
          throw e;
        } catch (ConfigEditorException e1) {
          log.error(
              "Failed to restore "
                  + cassandraYamlFile
                  + ". A copy of the file prior to any "
                  + "modifications can be found at "
                  + editor.getBackupFile());
          throw new ConfigEditorException(
              "There was an error updating "
                  + cassandraYamlFile
                  + " and "
                  + "undoing the changes failed. A copy of the file can be found at "
                  + editor.getBackupFile()
                  + ". See the agent logs for more details.",
              e);
        }
      } else {
        log.error(
            "No updates were made to " + cassandraYamlFile + " due to an unexpected error", e);
        throw e;
      }
    }
  }