Skip to content

Commit

Permalink
Merge pull request #55 from rundeck-plugins/RCLOUD-1533-switch-loggin…
Browse files Browse the repository at this point in the history
…g-to-slf4j

RCLOUD-1533: Switch logging to slf4j
  • Loading branch information
sjrd218 authored Nov 22, 2024
2 parents b941ced + faeaca2 commit 55cd29f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
11 changes: 10 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,3 +109,11 @@ jar {
}
//set jar task to depend on copyToLib
jar.dependsOn(copyToLib)

publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}
49 changes: 21 additions & 28 deletions src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;


/**
Expand All @@ -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;
Expand Down Expand Up @@ -284,13 +284,12 @@ protected boolean isPathAvailable(final String key, Map<String, Object> 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<String, String> 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) {
Expand All @@ -301,7 +300,7 @@ protected boolean isPathAvailable(final String key, Map<String, Object> 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)}
);
}
Expand All @@ -311,15 +310,13 @@ protected boolean isPathAvailable(final String key, Map<String, Object> 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);
}

Expand All @@ -329,25 +326,23 @@ protected boolean isPathAvailable(final String key, Map<String, Object> 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,
Expand All @@ -358,21 +353,19 @@ 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);
}
}

@Override
public void storeMultiple(final MultiFileStorageRequest files) throws IOException, ExecutionFileStorageException {
Set<String> 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);
Expand All @@ -390,8 +383,8 @@ 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());
logger.debug(e.getMessage(), e);
files.storageResultForFiletype(filetype, false);
}
}
Expand All @@ -408,7 +401,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);
}
}
Expand Down Expand Up @@ -443,7 +436,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;
Expand All @@ -468,7 +461,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);
}

Expand Down

0 comments on commit 55cd29f

Please sign in to comment.