public final class GcsResourceManager extends java.lang.Object implements ArtifactClient, org.apache.beam.it.common.ResourceManager
Tests should store this as a static value of the class and call ArtifactClient.cleanupAll()
in the @AfterClass
method.
Modifier and Type | Class and Description |
---|---|
static class |
GcsResourceManager.Builder
Builder for
GcsResourceManager . |
Constructor and Description |
---|
GcsResourceManager(GcsResourceManager.Builder builder) |
Modifier and Type | Method and Description |
---|---|
static GcsResourceManager.Builder |
builder(java.lang.String bucket,
java.lang.String testClassName,
com.google.auth.Credentials credentials)
Returns a new
GcsResourceManager.Builder for configuring a client. |
void |
cleanupAll()
Deletes all the files located under test-class-name/run-id.
|
Artifact |
copyFileToGcs(java.nio.file.Path localPath,
java.lang.String objectName)
Copies a file from a local path to a specified object name in Google Cloud Storage.
|
Artifact |
createArtifact(java.lang.String artifactName,
byte[] contents)
Creates a new artifact in whatever service is being used to store them.
|
Artifact |
createArtifact(java.lang.String artifactName,
java.lang.String contents)
Creates a new artifact in whatever service is being used to store them.
|
com.google.cloud.storage.Notification |
createNotification(java.lang.String topicName,
java.lang.String gcsPrefix)
Creates a new notification for the given topic and GCS prefix.
|
java.lang.String |
getPathForArtifact(java.lang.String artifactName)
Returns a path the artifact will be created at.
|
java.util.List<Artifact> |
listArtifacts(java.lang.String prefix,
java.util.regex.Pattern regex)
Lists all artifacts under test-class-name/run-id/
prefix . |
java.util.List<Artifact> |
listArtifacts(TestName testName,
java.util.regex.Pattern regex)
Lists all artifacts under test-class-name/run-id/
prefix . |
void |
registerTempDir(java.lang.String dirName)
Register a temporary directory that will be cleaned up after test.
|
java.lang.String |
runId()
Returns the id associated with the particular run of the test class.
|
Artifact |
uploadArtifact(java.lang.String artifactName,
java.nio.file.Path localPath)
Uploads a local file to the service being used for storing artifacts.
|
Artifact |
uploadArtifact(java.lang.String artifactName,
java.lang.String localPath)
Uploads a local file to the service being used for storing artifacts.
|
public GcsResourceManager(GcsResourceManager.Builder builder)
public static GcsResourceManager.Builder builder(java.lang.String bucket, java.lang.String testClassName, com.google.auth.Credentials credentials)
GcsResourceManager.Builder
for configuring a client.public java.lang.String runId()
ArtifactClient
runId
in interface ArtifactClient
public java.lang.String getPathForArtifact(java.lang.String artifactName)
ArtifactClient
getPathForArtifact
in interface ArtifactClient
artifactName
- Artifact namepublic Artifact createArtifact(java.lang.String artifactName, java.lang.String contents)
ArtifactClient
createArtifact
in interface ArtifactClient
artifactName
- the name of the artifact. If this is supposed to go under an input/output
directory, then it should include that (example: input/artifact.txt)contents
- the contents of the artifact in String formatpublic Artifact createArtifact(java.lang.String artifactName, byte[] contents)
ArtifactClient
createArtifact
in interface ArtifactClient
artifactName
- the name of the artifact. If this is supposed to go under an input/output
directory, then it should include that (example: input/artifact.txt)contents
- the contents of the artifact in byte array formatpublic Artifact uploadArtifact(java.lang.String artifactName, java.lang.String localPath) throws java.io.IOException
ArtifactClient
uploadArtifact
in interface ArtifactClient
artifactName
- the name of the artifact. If this is supposed to go under an input/output
directory, then it should include that (example: input/artifact.txt)localPath
- the absolute local path to the file to uploadjava.io.IOException
- if there is an issue reading the local filepublic Artifact uploadArtifact(java.lang.String artifactName, java.nio.file.Path localPath) throws java.io.IOException
ArtifactClient
uploadArtifact
in interface ArtifactClient
artifactName
- the name of the artifact. If this is supposed to go under an input/output
directory, then it should include that (example: input/artifact.txt)localPath
- the local path to the file to uploadjava.io.IOException
- if there is an issue reading the local filepublic Artifact copyFileToGcs(java.nio.file.Path localPath, java.lang.String objectName) throws java.io.IOException
localPath
- the path of the file to be copied.objectName
- the name of the object to be created in Google Cloud Storage.java.io.IOException
- if there is an error reading the file at the specified local path.public java.util.List<Artifact> listArtifacts(TestName testName, java.util.regex.Pattern regex)
ArtifactClient
prefix
.listArtifacts
in interface ArtifactClient
testName
- the test name to use as the prefix on the testing artifacts.regex
- a regex to use for filtering out unwanted artifactspublic java.util.List<Artifact> listArtifacts(java.lang.String prefix, java.util.regex.Pattern regex)
ArtifactClient
prefix
.listArtifacts
in interface ArtifactClient
prefix
- the prefix to use along with the fixed values method above. This must include the
test-method-name value, but it can include other directories or files under it.regex
- a regex to use for filtering out unwanted artifactspublic com.google.cloud.storage.Notification createNotification(java.lang.String topicName, java.lang.String gcsPrefix)
topicName
- the name of the Pub/Sub topic to which the notification should be sent.gcsPrefix
- the prefix of the object names to which the notification applies.public void registerTempDir(java.lang.String dirName)
dirName
- name of the temporary directorypublic void cleanupAll()
ArtifactClient
cleanupAll
in interface org.apache.beam.it.common.ResourceManager
cleanupAll
in interface ArtifactClient