From be3955b27466aef89808216cb12ba7b2d846e553 Mon Sep 17 00:00:00 2001 From: Stephen Joyner Date: Thu, 21 Nov 2024 11:00:39 -0600 Subject: [PATCH 1/2] Use slf4j for logging --- build.gradle | 3 +- .../plugins/S3LogFileStoragePlugin.java | 48 ++++++++----------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index a0e4f04..2028259 100644 --- a/build.gradle +++ b/build.gradle @@ -11,11 +11,12 @@ plugins { defaultTasks 'clean','build' apply plugin: 'java' apply plugin: 'idea' +apply plugin: 'maven-publish' apply plugin: 'pl.allegro.tech.build.axion-release' sourceCompatibility = 1.8 ext.rundeckPluginVersion= '1.2' -ext.rundeckVersion='4.17.2-rc1-20231025' +ext.rundeckVersion='4.17.6-20240402' /** * Set this to a comma-separated list of full classnames of your implemented Rundeck diff --git a/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java b/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java index e62541e..9a40617 100644 --- a/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java +++ b/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java @@ -20,6 +20,8 @@ import com.dtolabs.rundeck.plugins.descriptions.PluginProperty; import com.dtolabs.rundeck.plugins.logging.ExecutionFileStoragePlugin; import com.dtolabs.utils.Streams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.*; import java.net.URLEncoder; @@ -28,8 +30,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; /** @@ -52,7 +52,7 @@ public class S3LogFileStoragePlugin implements ExecutionFileStoragePlugin, AWSCr public static final String META_SERVERURL = "serverUrl"; public static final String META_SERVER_UUID = "serverUUID"; - protected static Logger logger = Logger.getLogger(S3LogFileStoragePlugin.class.getName()); + protected static Logger logger = LoggerFactory.getLogger(S3LogFileStoragePlugin.class.getName()); @PluginProperty(title = "AWS Access Key", description = "AWS Access Key") private String AWSAccessKeyId; @@ -284,13 +284,12 @@ protected boolean isPathAvailable(final String key, Map expected throws ExecutionFileStorageException { GetObjectMetadataRequest getObjectRequest = new GetObjectMetadataRequest(getBucket(), key); - logger.log(Level.FINE, "getState for S3 bucket {0}:{1}", new Object[]{getBucket(), - key}); + logger.debug("getState for S3 bucket {}:{}", getBucket(),key); try { ObjectMetadata objectMetadata = amazonS3.getObjectMetadata(getObjectRequest); Map userMetadata = objectMetadata != null ? objectMetadata.getUserMetadata() : null; - logger.log(Level.FINE, "Metadata {0}", new Object[]{userMetadata}); + logger.debug("Metadata {}", userMetadata); //execution ID is stored in the user metadata for the object //compare to the context execution ID we are expecting if (null != expectedMeta) { @@ -301,7 +300,7 @@ protected boolean isPathAvailable(final String key, Map expected } boolean matches = expectedMeta.get(s).equals(metaVal); if (!matches) { - logger.log(Level.WARNING, "S3 Object metadata '{0}' was not expected: {1}, expected {2}", + logger.warn("S3 Object metadata '{0}' was not expected: {1}, expected {2}", new Object[]{s, metaVal, expectedMeta.get(s)} ); } @@ -311,15 +310,13 @@ protected boolean isPathAvailable(final String key, Map expected } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404) { //not found - logger.log(Level.FINE, "getState: S3 Object not found for {0}", key); + logger.debug("getState: S3 Object not found for {}", key); } else { - logger.log(Level.SEVERE, e.getMessage()); - logger.log(Level.FINE, e.getMessage(), e); + logger.error("Failed get metadata", e); throw new ExecutionFileStorageException(e.getMessage(), e); } } catch (AmazonClientException e) { - logger.log(Level.SEVERE, e.getMessage()); - logger.log(Level.FINE, e.getMessage(), e); + logger.error("AWS client error", e); throw new ExecutionFileStorageException(e.getMessage(), e); } @@ -329,25 +326,23 @@ protected boolean isPathAvailable(final String key, Map expected public boolean store(final String filetype, InputStream stream, long length, Date lastModified) throws ExecutionFileStorageException { - boolean result = storePath( + return storePath( stream, resolvedFilepath(expandedPath, filetype), createObjectMetadata(length, lastModified) ); - return result; } protected boolean storePath( final InputStream stream, final String key, - final ObjectMetadata objectMetadata1 + final ObjectMetadata objectMetadata ) throws ExecutionFileStorageException { - logger.log(Level.FINE, "Storing content to S3 bucket {0} path {1}", new Object[]{getBucket(), key}); - ObjectMetadata objectMetadata = objectMetadata1; + logger.debug("Storing content to S3 bucket {} path {}", getBucket(), key); PutObjectRequest putObjectRequest = new PutObjectRequest( getBucket(), key, @@ -358,10 +353,10 @@ protected boolean storePath( amazonS3.putObject(putObjectRequest); return true; } catch (SdkClientException e){ - logger.log(Level.FINE, "Job could still be executing", e.getMessage()); + logger.debug("Job could still be executing: {}", e.getMessage()); throw new ExecutionFileStorageException(e.getMessage(), e); } catch (AmazonClientException e) { - logger.log(Level.SEVERE, e.getMessage(), e); + logger.error("AWS client error on store attempt", e); throw new ExecutionFileStorageException(e.getMessage(), e); } } @@ -369,10 +364,8 @@ protected boolean storePath( @Override public void storeMultiple(final MultiFileStorageRequest files) throws IOException, ExecutionFileStorageException { Set availableFiletypes = files.getAvailableFiletypes(); - logger.log( - Level.FINE, - "Storing multiple files to S3 bucket {0} filetypes: {1}", - new Object[]{getBucket(), availableFiletypes} + logger.debug("Storing multiple files to S3 bucket {} filetypes: {}", + getBucket(), availableFiletypes ); for (String filetype : availableFiletypes) { StorageFile storageFile = files.getStorageFile(filetype); @@ -390,8 +383,7 @@ public void storeMultiple(final MultiFileStorageRequest files) throws IOExceptio MultiFileStorageRequestErrors errors = (MultiFileStorageRequestErrors) files; errors.storageFailureForFiletype(filetype, e.getMessage()); } else { - logger.log(Level.SEVERE, e.getMessage()); - logger.log(Level.FINE, e.getMessage(), e); + logger.error(e.getMessage()); files.storageResultForFiletype(filetype, false); } } @@ -408,7 +400,7 @@ public boolean deleteFile(String filetype) throws IOException, ExecutionFileStor amazonS3.deleteObject(getBucket(), filePath); return true; } catch (AmazonClientException e) { - logger.log(Level.SEVERE, e.getMessage(), e); + logger.error("AWS client error on delete", e); throw new ExecutionFileStorageException(e.getMessage(), e); } } @@ -443,7 +435,7 @@ private String encodeStringToURLRequest(String value){ try { return URLEncoder.encode(value, StandardCharsets.UTF_8.toString()); } catch (UnsupportedEncodingException e) { - logger.log(Level.WARNING, e.getMessage(), e); + logger.warn(e.getMessage(), e); } return value; @@ -468,7 +460,7 @@ protected boolean retrievePath(final OutputStream stream, final String key) } } catch (AmazonClientException e) { - logger.log(Level.SEVERE, e.getMessage(), e); + logger.error("AWS client error on get object", e); throw new ExecutionFileStorageException(e.getMessage(), e); } From aaa62f7defbcc89b75bcf102b8b078ad198006bc Mon Sep 17 00:00:00 2001 From: Stephen Joyner Date: Thu, 21 Nov 2024 13:37:35 -0600 Subject: [PATCH 2/2] Add ability to publish to maven local --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 2028259..f8c3d90 100644 --- a/build.gradle +++ b/build.gradle @@ -109,3 +109,11 @@ jar { } //set jar task to depend on copyToLib jar.dependsOn(copyToLib) + +publishing { + publications { + maven(MavenPublication) { + from components.java + } + } +} \ No newline at end of file