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

Exception when passing a Path argument to WebCassandraDirectoryProvider #367

Closed
utkuaydn opened this issue Jan 30, 2024 · 6 comments
Closed
Assignees

Comments

@utkuaydn
Copy link

utkuaydn commented Jan 30, 2024

Hi,

I am trying to start an instance with the working directory being inside the project rather than in the home directory of the machine and I have the following Scala code:

val cassandra: Cassandra = new CassandraBuilder()
   .configFile(configFile)
   .logger(new Slf4jLogger(LoggerFactory.getLogger("Cassandra")))
   .workingDirectoryInitializer(
     new DefaultWorkingDirectoryInitializer(
       new WebCassandraDirectoryProvider(Paths.get(".")),
       DefaultWorkingDirectoryInitializer.CopyStrategy.SKIP_EXISTING
     )
   )
   .registerShutdownHook(true)
   .build()

 try cassandra.start()
 catch {
   case e: CassandraException => throw e
 }

However, I get the following exception:

Unable to initialize DefaultCassandra{name='cassandra-0', version='4.1.3'}. Caused by: java.io.IOException: Unable to provide Cassandra Directory for a version: '4.1.3'
java.io.IOException: Bad zip entry [apache-cassandra-4.1.3/bin/]

I see that the .embedded-cassandra folder gets created wherever I set the path but it still results in an exception.

Whenever new WebCassandraDirectoryProvider does not have an argument and it defaults to user.home it seems to work but otherwise it does not. I have tried setting it to the project root folder, target directory, but none of them seem to work. Any clues what might be happening?

@nosan
Copy link
Owner

nosan commented Jan 30, 2024

Hello,

  new CassandraBuilder()
            .workingDirectoryInitializer(new DefaultWorkingDirectoryInitializer(new CassandraDirectoryProvider() {

                @Override
                public Path getDirectory(Version version) throws IOException {
                    //here it means '.' directory must contain all necessary Apache Cassandra files
                    return Paths.get(".");
                }
            }));


WebCassandraDirectoryProvider is being used for downloading Apache Cassandra and extracts an archive into user.home directory and later uses this directory for Working Directory initializing (/tmp/<...>) by default.

@nosan
Copy link
Owner

nosan commented Jan 30, 2024

But actually, I tried your example:


	private final CassandraBuilder builder = new CassandraBuilder().workingDirectoryInitializer(
			new DefaultWorkingDirectoryInitializer(new WebCassandraDirectoryProvider(Paths.get("."))));


and got the same exception.

@nosan
Copy link
Owner

nosan commented Jan 30, 2024

also by default in WebCassandraDirectory we have the following:

	Path downloadDirectory = this.downloadDirectory.resolve(".embedded-cassandra").resolve("cassandra")
				.resolve(version.toString());
				

@nosan
Copy link
Owner

nosan commented Jan 30, 2024

So, just to clarify, do you want to be able to set the download directory is .? right?

@nosan
Copy link
Owner

nosan commented Jan 30, 2024

You can try this option for now:

  	new DefaultWorkingDirectoryInitializer(new WebCassandraDirectoryProvider(Paths.get(System.getProperty("user.dir")))));

@utkuaydn
Copy link
Author

utkuaydn commented Feb 5, 2024

That seems to have done the trick, thanks :)

@utkuaydn utkuaydn closed this as completed Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants