From 17de6a67a2399226aaf84e5826af14ef6a7c507e Mon Sep 17 00:00:00 2001 From: tengu-alt Date: Wed, 27 Nov 2024 15:52:41 +0200 Subject: [PATCH] Autogenerate Native protocol specifications documentation Uses cqlprotodoc from cassandra-website to generate the versioned native protocol spec html pages. Uses process-native-protocol-specs-in-docker.sh as a wrapper around this to also generate the native protocol spec adoc page that includes all the versions and makes each header navigable. This is executed as part of the existing `ant gen-asciidoc` and doc/Makefile. patch by Olexandr Luzhniy; reviewed by Mick Semb Wever for CASSANDRA-19915 --- doc/Makefile | 2 + doc/modules/ROOT/pages/index.adoc | 3 +- doc/native_protocol_v3.spec | 2 +- doc/native_protocol_v5.spec | 7 +- ...process-native-protocol-specs-in-docker.sh | 126 ++++++++++++++++++ 5 files changed, 134 insertions(+), 6 deletions(-) create mode 100755 doc/scripts/process-native-protocol-specs-in-docker.sh diff --git a/doc/Makefile b/doc/Makefile index 2eee114669..dac8e11fb0 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -13,6 +13,7 @@ GENERATE_NODETOOL_DOCS = ./scripts/gen-nodetool-docs.py MAKE_CASSANDRA_YAML = ./scripts/convert_yaml_to_adoc.py ../conf/cassandra.yaml ./modules/cassandra/pages/managing/configuration/cass_yaml_file.adoc +PROCESS_NATIVE_PROC_SPECS = ./scripts/process-native-protocol-specs-in-docker.sh .PHONY: html html: @@ -24,3 +25,4 @@ gen-asciidoc: @mkdir -p modules/cassandra/examples/TEXT/NODETOOL python3 $(GENERATE_NODETOOL_DOCS) python3 $(MAKE_CASSANDRA_YAML) + $(PROCESS_NATIVE_PROC_SPECS) diff --git a/doc/modules/ROOT/pages/index.adoc b/doc/modules/ROOT/pages/index.adoc index 02b3f949ea..beeb121f22 100644 --- a/doc/modules/ROOT/pages/index.adoc +++ b/doc/modules/ROOT/pages/index.adoc @@ -40,7 +40,8 @@ If you would like to contribute to this documentation, you are welcome to do so | xref:cassandra:integrating/plugins/index.adoc[Plug-ins] | Third-party plug-ins -| xref:master@_:ROOT:native_protocol.adoc[Native Protocols] | Native Cassandra protocol specifications +| link:cassandra/reference/native-protocol.html[Native Protocols] | Native Cassandra protocol specifications + |=== == Meta information diff --git a/doc/native_protocol_v3.spec b/doc/native_protocol_v3.spec index 8187ca0b27..30881c9497 100644 --- a/doc/native_protocol_v3.spec +++ b/doc/native_protocol_v3.spec @@ -728,7 +728,7 @@ Table of Contents Clients are expected to answer the server challenge by an AUTH_RESPONSE message. -4.2.7. AUTH_SUCCESS +4.2.8. AUTH_SUCCESS Indicate the success of the authentication phase. See Section 4.2.3 for more details. diff --git a/doc/native_protocol_v5.spec b/doc/native_protocol_v5.spec index cbc7f9fe9c..e080801978 100644 --- a/doc/native_protocol_v5.spec +++ b/doc/native_protocol_v5.spec @@ -29,7 +29,6 @@ Table of Contents 2.3.1 Initial Handshake 2.3.2 Compression 2.4. Frame Payload - 2.4.1 Frame Header 2.4.1.1. version 2.4.1.2. flags 2.4.1.3. stream @@ -232,7 +231,7 @@ Table of Contents All values in an envelope are big-endian (network byte order). Each envelope contains a fixed size header (9 bytes) followed by a variable size - body. The header is described in Section 2.4.1. The content of the body depends + body. The content of the body depends on the header opcode value (the body can in particular be empty for some opcode values). The list of allowed opcodes is defined in Section 2.4.1.4 and the details of each corresponding message are described Section 4. @@ -255,7 +254,7 @@ Table of Contents previously possible to enable compression for an individual envelope. This is no longer possible, as the framing format is responsible for compression, which is set for the lifetime of a connection and applies to all messages transmitted throughout it - (see Section 2.2.1 for caveats). The compression flag is therefore deprecated and + (see Section 2.2 for caveats). The compression flag is therefore deprecated and ignored in protocol v5. 2.4.1.1. version @@ -277,7 +276,7 @@ Table of Contents connection. This document describes version 5 of the protocol. For the changes made since - version 4, see Section 10. + version 4, see Section 9. 2.4.1.2. flags diff --git a/doc/scripts/process-native-protocol-specs-in-docker.sh b/doc/scripts/process-native-protocol-specs-in-docker.sh new file mode 100755 index 0000000000..3af83f4a31 --- /dev/null +++ b/doc/scripts/process-native-protocol-specs-in-docker.sh @@ -0,0 +1,126 @@ +#!/bin/sh +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[ -f "../build.xml" ] || { echo "build.xml must exist (current directory needs to be doc/ in cassandra repo"; exit 1; } +[ -f "antora.yml" ] || { echo "antora.yml must exist (current directory needs to be doc/ in cassandra repo"; exit 1; } + +# Variables +GO_VERSION="1.23.1" +GO_TAR="go${GO_VERSION}.linux-amd64.tar.gz" +TMPDIR="${TMPDIR:-/tmp}" + +# Step 0: Download and install Go +echo "Downloading Go $GO_VERSION..." +wget -q "https://golang.org/dl/$GO_TAR" -O "$TMPDIR/$GO_TAR" + +echo "Installing Go..." +tar -C "$TMPDIR" -xzf "$TMPDIR/$GO_TAR" +rm "$TMPDIR/$GO_TAR" + +# Set Go environment variables +export PATH="$PATH:$TMPDIR/go/bin" +export GOPATH="$TMPDIR/go" + +# Step 1: Building the parser +echo "Building the cqlprotodoc..." +DIR="$(pwd)" +cd "${TMPDIR}" + +git clone -n --depth=1 --filter=tree:0 https://github.com/apache/cassandra-website + +cd "${TMPDIR}/cassandra-website" +git sparse-checkout set --no-cone /cqlprotodoc +git checkout +cd "${TMPDIR}/cassandra-website/cqlprotodoc" +go build -o "$TMPDIR"/cqlprotodoc + +# Step 2: Process the spec files using the parser +echo "Processing the .spec files..." +cd "${DIR}" +output_dir="modules/cassandra/attachments" +mkdir -p "${output_dir}" +"$TMPDIR"/cqlprotodoc . "${output_dir}" + +# Step 4: Generate summary file +summary_file="modules/cassandra/pages/reference/native-protocol.adoc" + +# Write the header +echo "= Native Protocol Versions" > "$summary_file" +echo ":page-layout: default" >> "$summary_file" +echo >> "$summary_file" + +# Loop through the files from step 2 in reverse version order +for file in $(ls ${output_dir}/native_protocol_v*.html | sort -r | awk -F/ '{print $NF}'); do + version=$(echo "$file" | sed -E 's/native_protocol_v([0-9]+)\.html/\1/') + echo "== Native Protocol Version $version" >> "$summary_file" + echo >> "$summary_file" + echo "[source, html]" >> "$summary_file" + echo "++++" >> "$summary_file" + echo "include::cassandra:attachment\$$file[Version $version]" >> "$summary_file" + echo "++++" >> "$summary_file" + echo >> "$summary_file" +done + +# Navigation setup +echo "[source, js]" >> "$summary_file" +echo "++++" >> "$summary_file" +echo "" >> "$summary_file" + + +# Step 3: Cleanup - Remove the Cassandra and parser directories +echo "Cleaning up..." +cd "${DIR}" +rm -rf "${TMPDIR}/go" "${TMPDIR}/cassandra-website" "${TMPDIR}/cqlprotodoc" 2>/dev/null + +echo "Script completed successfully."