Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cassandra.in.sh): Refactor script for readability and consistency #17

Merged
merged 3 commits into from
Sep 3, 2024
Merged

feat(cassandra.in.sh): Refactor script for readability and consistency #17

merged 3 commits into from
Sep 3, 2024

Conversation

Daniel-Boll
Copy link
Contributor

This commit refactors the cassandra.in.sh script to improve readability
and consistency. Changes include adjusting indentation, modifying the
path for jar files, and streamlining the JVM version and vendor
detection. The changes aim to enhance maintainability and adherence to
coding standards.

But mainly including the path correction for looking the files up:

-  SCYLLA_HOME="$(dirname "$0")/../../../scylla"
+  SCYLLA_HOME="$(dirname "$0")/../.."

Signed-off-by: Daniel Boll [email protected]

This commit refactors the cassandra.in.sh script to improve readability
and consistency. Changes include adjusting indentation, modifying the
path for jar files, and streamlining the JVM version and vendor
detection. The changes aim to enhance maintainability and adherence to
coding standards.

But mainly including the path correction for looking the files up:

```diff
-  SCYLLA_HOME="$(dirname "$0")/../../../scylla"
+  SCYLLA_HOME="$(dirname "$0")/../.."
```

Signed-off-by: Daniel Boll <[email protected]>
@Daniel-Boll
Copy link
Contributor Author

Steps to Compile Cassandra-Stress from Source

1. Clone the Repository from ScyllaDB's GitHub

Start by cloning the cassandra-stress repository from ScyllaDB's GitHub. This will give you access to the source code necessary to build the tool.

gh repo clone scylladb/cassandra-stress

This command will create a local copy of the repository in your current directory.

2. Install Apache Ant

Apache Ant is a Java-based build tool required to compile Cassandra-Stress. To keep this process as platform-independent as possible, we’ll use asdf, a version manager that allows you to manage multiple runtime versions easily. Although using nix might be a better choice for achieving complete platform independence, we're sticking with asdf for simplicity in this guide.

  1. Add the Ant plugin to asdf:

    asdf plugin add ant
  2. Install the required version of Ant:

    asdf install ant 1.10.14
  3. Set the local version of Ant:

    asdf local ant 1.10.14
  4. Verify the installation:

    ant -version

    You should see something like:

    Apache Ant(TM) version 1.10.14 compiled on August 16 2023
    

3. Set Up the Java Version

Cassandra-Stress requires Java to run, and it's important to ensure the correct version is used. We will use asdf again to manage the Java version.

  1. Add the Java plugin to asdf:

    asdf plugin add java
  2. Install the required Java version:

    asdf install java adoptopenjdk-11.0.24+8
  3. Set the local version of Java:

    asdf local java adoptopenjdk-11.0.24+8
  4. Verify the installation:

    java -version

    You should see an output like:

    openjdk version "11.0.24" 2024-07-16
    

4. Build the Project Using Ant

With Ant and Java set up, you can now compile the Cassandra-Stress tool from the source.

  1. Navigate to the project directory (if not already in it):

    cd cassandra-stress
  2. Build the project:

    ant -Drelease=true artifacts

    This command compiles the source code and packages it into artifacts ready for use.

5. Copy a Configuration File

Before running Cassandra-Stress, you need a configuration file. You can use the provided example configuration:

cp ./tools/cqlstress-example.yaml conf/scylla.yaml

This copies the example configuration file to the appropriate directory, renaming it to scylla.yaml.

6. Run Cassandra-Stress

Finally, you can run Cassandra-Stress using the following command:

./tools/bin/cassandra-stress help write

@danielhe4rt
Copy link

Before merge it, would be good to have a COMPILING.md with the comment above. Also don't forget to link it on main README.md :p

@fruch
Copy link

fruch commented Aug 27, 2024

Before merge it, would be good to have a COMPILING.md with the comment above. Also don't forget to link it on main README.md :p

I see that's a Daniel network in play here :)

@fruch fruch requested a review from CodeLieutenant August 27, 2024 18:44
@@ -15,11 +15,11 @@
# limitations under the License.

if [ "$SCYLLA_HOME" = "" ]; then
SCYLLA_HOME="$(dirname "$0")/../../../scylla"
SCYLLA_HOME="$(dirname "$0")/../.."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeLieutenant

We need to make sure it doesn't breaks the docker usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the Dockerfile already provide a SCYLLA_HOME probably when running this it won't override, but I'll take a look.

ENV SCYLLA_HOME=/scylla-tools-java

@danielhe4rt
Copy link

Before merge it, would be good to have a COMPILING.md with the comment above. Also don't forget to link it on main README.md :p

I see that's a Daniel network in play here :)

What can I say, bring talented contributors closer to scylladb is my job :p

This commit enhances the way SCYLLA_HOME is determined by searching
upwards in the directory tree until a directory with a 'conf' subdirectory
is found. If no such directory is found, an error is thrown.

Additionally, the paths for jar files have been updated to reflect the
correct locations. This ensures that all necessary jar files are included
in the CLASSPATH.

Signed-off-by: Daniel Boll <[email protected]>
This commit replaces the previous method of generating the CLASSPATH
variable in the cassandra.in.sh script. Instead of using two separate
for loops to add .jar files from different directories to the CLASSPATH,
it now uses the find command to locate all .jar files in the specified
directories and adds them to the CLASSPATH in one line.

Signed-off-by: Daniel Boll <[email protected]>
Comment on lines +65 to +66
CLASSPATH="${CLASSPATH}:$(find "$SCYLLA_HOME/lib" "$SCYLLA_HOME/build/lib" "$SCYLLA_HOME/tools" -name '*.jar' -print 2>/dev/null | paste -sd ":" -)"
CLASSPATH="${CLASSPATH#:}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Albeit odd this is to allow running from ./build, ./tools and docker

gh repo clone daniel-boll/cassandra-stress -- --depth 1 --branch fix/scripts-path
cd cassandra-stress
ant -Drelease=true artifacts
docker buildx build --build-arg='CASSANDRA_STRESS_VERSION=3.12.0' -t scylla-daniel:cassandra-stress .

Now with that the three ways

./tools/bin/cassandra-stress
./build/dist/tools/bin/cassandra-stress
docker run scylla-daniel:cassandra-stress

@CodeLieutenant CodeLieutenant added the enhancement New feature or request label Aug 30, 2024
@CodeLieutenant CodeLieutenant linked an issue Aug 30, 2024 that may be closed by this pull request
Copy link

@fruch fruch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CodeLieutenant CodeLieutenant merged commit d33b7cb into scylladb:master Sep 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

code doesn't run after compiled from source
4 participants