-
Notifications
You must be signed in to change notification settings - Fork 948
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP chore(core): migrate StorageInterface to service-loader mechanism
part-of: kestra-io/storage-minio#80 part-of: kestra-io/storage-s3#80 part-of: kestra-io/storage-gcs#119
- Loading branch information
1 parent
93f9f70
commit 97ccc1f
Showing
14 changed files
with
414 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
core/src/main/java/io/kestra/core/contexts/KestraApplicationContext.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
core/src/main/java/io/kestra/core/exceptions/KestraRuntimeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.kestra.core.exceptions; | ||
|
||
/** | ||
* The top-level {@link KestraRuntimeException} for non-recoverable errors. | ||
*/ | ||
public class KestraRuntimeException extends RuntimeException { | ||
|
||
public KestraRuntimeException() { | ||
} | ||
|
||
public KestraRuntimeException(String message) { | ||
super(message); | ||
} | ||
|
||
public KestraRuntimeException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public KestraRuntimeException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
core/src/main/java/io/kestra/core/storages/ClassLoaderAwareStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package io.kestra.core.storages; | ||
|
||
import io.kestra.core.utils.Classes; | ||
import io.micronaut.core.util.functional.ThrowingSupplier; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Class for decorating a {@link StorageInterface} that sets the context class loader when calling the respective | ||
* methods. | ||
*/ | ||
public final class ClassLoaderAwareStorage implements StorageInterface { | ||
|
||
private final ClassLoader classLoader; | ||
|
||
private final StorageInterface delegate; | ||
|
||
/** | ||
* Creates a new {@link ClassLoaderAwareStorage} instance. | ||
* | ||
* @param classLoader The {@link ClassLoader} to be used. | ||
* @param delegate The {@link StorageInterface} to delegate method calls. | ||
*/ | ||
public ClassLoaderAwareStorage(final ClassLoader classLoader, | ||
final StorageInterface delegate) { | ||
this.classLoader = Objects.requireNonNull(classLoader, "classLoader cannot be null"); | ||
this.delegate = Objects.requireNonNull(delegate, "delegate cannot be null"); | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public String getType() { | ||
return this.delegate.getType(); | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public void init() throws IOException{ | ||
Classes.withContextClassLoader(classLoader, (ThrowingSupplier<Void, IOException>) () -> { | ||
delegate.init(); | ||
return null; | ||
}); | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public void close() { | ||
Classes.withContextClassLoader(classLoader, delegate::close); | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public InputStream get(String tenantId, URI uri) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.get(tenantId, uri)); | ||
} | ||
/** {@inheritDoc} **/ | ||
@Override | ||
public List<URI> allByPrefix(String tenantId, URI prefix, boolean includeDirectories) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.allByPrefix(tenantId, prefix, includeDirectories)); | ||
} | ||
/** {@inheritDoc} **/ | ||
@Override | ||
public List<FileAttributes> list(String tenantId, URI uri) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.list(tenantId, uri)); | ||
} | ||
/** {@inheritDoc} **/ | ||
@Override | ||
public FileAttributes getAttributes(String tenantId, URI uri) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.getAttributes(tenantId, uri)); | ||
} | ||
/** {@inheritDoc} **/ | ||
@Override | ||
public URI put(String tenantId, URI uri, InputStream data) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.put(tenantId, uri, data)); | ||
} | ||
/** {@inheritDoc} **/ | ||
@Override | ||
public boolean delete(String tenantId, URI uri) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.delete(tenantId, uri)); | ||
} | ||
/** {@inheritDoc} **/ | ||
@Override | ||
public URI createDirectory(String tenantId, URI uri) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.createDirectory(tenantId, uri)); | ||
} | ||
/** {@inheritDoc} **/ | ||
@Override | ||
public URI move(String tenantId, URI from, URI to) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.move(tenantId, from, to)); | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public List<URI> deleteByPrefix(String tenantId, URI storagePrefix) throws IOException { | ||
return Classes.withContextClassLoader(classLoader, () -> delegate.deleteByPrefix(tenantId, storagePrefix)); | ||
} | ||
|
||
/** {@inheritDoc} **/ | ||
@Override | ||
public StorageInterface unwrapped() { | ||
return this.delegate.unwrapped(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.