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

Added logs in material poller + s3 artifact store #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ private GoPluginApiResponse handleLatestRevisionSince(GoPluginApiRequest goPlugi

String s3Bucket = repositoryKeyValuePairs.get(S3_BUCKET);
S3ArtifactStore artifactStore = s3ArtifactStore(s3Bucket);
Artifact artifact = artifact(packageKeyValuePairs);
try {
RevisionStatus revision = artifactStore.getLatest(artifact(packageKeyValuePairs));
RevisionStatus revision = artifactStore.getLatest(artifact);
if(new Revision(revision.revision.getRevision()).compareTo(new Revision(previousRevision)) > 0) {
return createResponse(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, revision.toMap());
}

return createResponse(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, null);
} catch (Exception e) {
logger.error(e.getMessage(), e);
logger.error("Error during handleLatestRevisionSince for "+artifact.toString()+", with msg: "+e.getMessage(), e);
return createResponse(DefaultGoPluginApiResponse.INTERNAL_ERROR, null);
}
}
Expand All @@ -92,11 +93,13 @@ private GoPluginApiResponse handleGetLatestRevision(GoPluginApiRequest goPluginA
final Map<String, String> packageKeyValuePairs = keyValuePairs(goPluginApiRequest, REQUEST_PACKAGE_CONFIGURATION);
String s3Bucket = repositoryKeyValuePairs.get(S3_BUCKET);
S3ArtifactStore artifactStore = s3ArtifactStore(s3Bucket);
Artifact artifact = artifact(packageKeyValuePairs);
try {
RevisionStatus revision = artifactStore.getLatest(artifact(packageKeyValuePairs));
RevisionStatus revision = artifactStore.getLatest(artifact);
return createResponse(DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, revision.toMap());
} catch (Exception e) {
logger.error(e.getMessage(), e);
logger.error("Error during getLatestRevision for "+artifact.toString()+", with msg: "+e.getMessage(), e);
return createResponse(DefaultGoPluginApiResponse.INTERNAL_ERROR, null);
}
}
Expand Down
10 changes: 10 additions & 0 deletions utils/src/main/java/com/indix/gocd/models/Artifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ public String prefixWithRevision(){
else
return prefix();
}

@Override
public String toString() {
return "Artifact{" +
"pipelineName='" + pipelineName + '\'' +
", stageName='" + stageName + '\'' +
", jobName='" + jobName + '\'' +
", revision=" + revision.getRevision() +
'}';
}
}
13 changes: 13 additions & 0 deletions utils/src/main/java/com/indix/gocd/utils/GoEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,17 @@ private String getEnvInvalidFormatMessage(String environmentVariable, String val
"Unexpected value in %s environment variable; was %s, but expected one of the following %s",
environmentVariable, value, expected);
}

@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
for(String key : environment.keySet()) {
buffer.append(key+":"+environment.get(key));
buffer.append(";");
}

return "GoEnvironment{" +
"environment=" + buffer.toString() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.indix.gocd.utils.utils.Lists;
import com.indix.gocd.utils.utils.Maps;
import org.apache.commons.lang3.StringUtils;
import com.thoughtworks.go.plugin.api.logging.Logger;

import java.io.File;
import java.util.Collections;
Expand All @@ -26,7 +27,7 @@
import static com.indix.gocd.utils.Constants.*;

public class S3ArtifactStore {

private static Logger logger = Logger.getLoggerFor(S3ArtifactStore.class);
private static Map<String, StorageClass> STORAGE_CLASSES = Maps.<String, StorageClass>builder()
.with(STORAGE_CLASS_STANDARD, StorageClass.Standard)
.with(STORAGE_CLASS_STANDARD_IA, StorageClass.StandardInfrequentAccess)
Expand Down Expand Up @@ -229,15 +230,20 @@ public String getLatestPrefix(String pipeline, String stage, String job, String

public static AmazonS3 getS3client(GoEnvironment env) {
AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard();

logger.debug("Instantiating S3 client with following env variables: ");
logger.debug(env.toString());
if (env.has(AWS_REGION)) {
amazonS3ClientBuilder.withRegion(env.get(AWS_REGION));
}
if (env.hasAWSUseIamRole()) {
logger.info("S3Artifact's getS3client uses AWS IAM Role");
amazonS3ClientBuilder.withCredentials(new InstanceProfileCredentialsProvider(false));
} else if (env.has(AWS_ACCESS_KEY_ID) && env.has(AWS_SECRET_ACCESS_KEY)) {
logger.info("S3Artifact's getS3client uses AWS credentials from ENV");
BasicAWSCredentials basicCreds = new BasicAWSCredentials(env.get(AWS_ACCESS_KEY_ID), env.get(AWS_SECRET_ACCESS_KEY));
amazonS3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(basicCreds));
} else {
logger.warn("S3Artifact's getS3client fallback to default credentials chain");
}

return amazonS3ClientBuilder.build();
Expand Down