Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Show Elastic Beanstalk logs during deployment
Browse files Browse the repository at this point in the history
Prepare for v1.0.0 release
  • Loading branch information
rtfpessoa committed Oct 29, 2016
1 parent 4cc8603 commit 4a1a934
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 119 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

* Use `git rebase` (not `git merge`) to sync your work from time to time with the master branch.

* After creating your pull request make sure the build is passing in [Travis](https://travis-ci.org/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin).
* After creating your pull request make sure the build is passing in [CircleCI](https://circleci.com/gh/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin).

### Commit Style

Expand Down
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright 2010-2016 JetBrains s.r.o.
Copyright 2016 rtfpessoa

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![CircleCI](https://circleci.com/gh/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin.svg?style=svg)](https://circleci.com/gh/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin)
[![Dependency Status](https://dependencyci.com/github/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin/badge)](https://dependencyci.com/github/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin)

teamcity-aws-elasticbeanstalk-plugin is a **VERY EARLY STAGE** Teamcity plugin that allows deployments
teamcity-aws-elasticbeanstalk-plugin is a Teamcity plugin that allows deployments
to Elastic Beanstalk.

This plugin started from the code in [teamcity-aws-codedeploy-plugin](https://github.com/JetBrains/teamcity-aws-codedeploy-plugin)
Expand All @@ -16,7 +16,8 @@ and was adapted for Elastic Beanstalk and slightly ajusted.

## Release

* 1.0.0-alpha1 [aws-elasticbeanstalk-plugin.zip](https://github.com/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin/releases/download/1.0.0-alpha1/aws-elasticbeanstalk-plugin.zip)
* [1.0.0](https://github.com/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin/releases/tag/v1.0.0)
* [Previous versions](https://github.com/rtfpessoa/teamcity-aws-elasticbeanstalk-plugin/releases)

## Contributions

Expand All @@ -26,7 +27,7 @@ I will try to review them as soon as possible.

## License

Copyright 2016 Rodrigo Fernandes. Licensed under the Apache License, Version 2.0 (the "License").
Licensed under the Apache License, Version 2.0 (the "License").

## Thanks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected BuildFinishedStatus runImpl() throws RunBuildException {
m.s3ObjectVersion = nullIfEmpty(configParameters.get(S3_OBJECT_VERSION_CONFIG_PARAM));

final AWSClient awsClient = createAWSClient(runnerParameters, runningBuild).withListener(
new LoggingDeploymentListener(runnerParameters, runningBuild.getBuildLogger(), runningBuild.getCheckoutDirectory().getAbsolutePath()));
new LoggingDeploymentListener(runnerParameters, runningBuild.getBuildLogger(), runningBuild.getCheckoutDirectory().getAbsolutePath()));

final String s3BucketName = runnerParameters.get(S3_BUCKET_NAME_PARAM);
String s3ObjectKey = runnerParameters.get(S3_OBJECT_KEY_PARAM);
Expand All @@ -62,8 +62,8 @@ protected BuildFinishedStatus runImpl() throws RunBuildException {
if (!m.problemOccurred && !isInterrupted()) {
if (ElasticBeanstalkUtil.isDeploymentWaitEnabled(runnerParameters)) {
awsClient.updateEnvironmentAndWait(environmentName, versionLabel,
Integer.parseInt(runnerParameters.get(WAIT_TIMEOUT_SEC_PARAM)),
getIntegerOrDefault(configParameters.get(WAIT_POLL_INTERVAL_SEC_CONFIG_PARAM), WAIT_POLL_INTERVAL_SEC_DEFAULT));
Integer.parseInt(runnerParameters.get(WAIT_TIMEOUT_SEC_PARAM)),
getIntegerOrDefault(configParameters.get(WAIT_POLL_INTERVAL_SEC_CONFIG_PARAM), WAIT_POLL_INTERVAL_SEC_DEFAULT));
} else {
awsClient.updateEnvironment(environmentName, versionLabel);
}
Expand Down Expand Up @@ -101,30 +101,29 @@ public boolean canRun(@NotNull BuildAgentConfiguration agentConfiguration) {

@NotNull
private AWSClient createAWSClient(final Map<String, String> runnerParameters, @NotNull final AgentRunningBuild runningBuild) {
final Map<String, String> params = new HashMap<String, String>(runnerParameters);
final Map<String, String> params = new HashMap<>(runnerParameters);
params.put(TEMP_CREDENTIALS_SESSION_NAME_PARAM, runningBuild.getBuildTypeExternalId() + runningBuild.getBuildId());
if (ElasticBeanstalkUtil.isDeploymentWaitEnabled(runnerParameters)) {
params.put(TEMP_CREDENTIALS_DURATION_SEC_PARAM, String.valueOf(2 * Integer.parseInt(runnerParameters.get(WAIT_TIMEOUT_SEC_PARAM))));
}

return new AWSClient(createAWSClients(params, true)).withDescription("TeamCity build \"" + runningBuild.getBuildTypeName() + "\" #" + runningBuild.getBuildNumber());
return new AWSClient(createAWSClients(params, true));
}

static class ElasticBeanstalkRunnerException extends RunBuildException {
public ElasticBeanstalkRunnerException(@NotNull String message, @Nullable Throwable cause) {
private static class ElasticBeanstalkRunnerException extends RunBuildException {
ElasticBeanstalkRunnerException(@NotNull String message, @Nullable Throwable cause) {
super(message, cause, ErrorData.BUILD_RUNNER_ERROR_TYPE);
this.setLogStacktrace(false);
}
}

private class Mutable {
public Mutable(@NotNull Map<String, String> configParameters) {
Mutable(@NotNull Map<String, String> configParameters) {
problemOccurred = false;
s3ObjectVersion = nullIfEmpty(configParameters.get(S3_OBJECT_VERSION_CONFIG_PARAM));
}

boolean problemOccurred;
String s3ObjectVersion;
String s3ObjectETag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class LoggingDeploymentListener extends AWSClient.Listener {
@NotNull
private static final Logger LOG = Logger.getInstance(Loggers.VCS_CATEGORY + ElasticBeanstalkRunner.class);

static final String CREATE_VERSION = "create version";
static final String UPDATE_ENVIRONMENT = "update environment";
static final String CREATE_VERSION = "Create version";
static final String UPDATE_ENVIRONMENT = "Update environment";

@NotNull
private final Map<String, String> myRunnerParameters;
Expand Down Expand Up @@ -65,24 +65,29 @@ void createVersionFinished(@NotNull String applicationName, @NotNull String vers
}

@Override
void deploymentStarted(@NotNull String environmentId, @NotNull String applicationName, @NotNull String versionLabel) {
void deploymentStarted(@NotNull String applicationName, @NotNull String environmentName, @NotNull String versionLabel) {
open(UPDATE_ENVIRONMENT);
log(String.format("Started deployment of application %s version %s to %s", applicationName, versionLabel, environmentId));
log(String.format("Started deployment of application %s version %s to %s", applicationName, versionLabel, environmentName));
}

@Override
void deploymentWaitStarted(@NotNull String environmentId) {
void deploymentWaitStarted(@NotNull String environmentName) {
log("Waiting for deployment finish");
log(String.format("Waiting for deployment on environment %s", environmentId));
log(String.format("Waiting for deployment on environment %s", environmentName));
}

@Override
void deploymentInProgress(@NotNull String environmentId) {
progress(String.format("Waiting for deployment on environment %s", environmentId));
void deploymentInProgress(@NotNull String environmentName) {
progress(String.format("Waiting for deployment on environment %s", environmentName));
}

@Override
void deploymentFailed(@NotNull String environmentId, @NotNull String applicationName, @NotNull String versionLabel,
void deploymentUpdate(@NotNull String message) {
progress(message);
}

@Override
void deploymentFailed(@NotNull String applicationName, @NotNull String environmentName, @NotNull String versionLabel,
@NotNull Boolean hasTimeout, @Nullable ErrorInfo errorInfo) {
String msg = (!hasTimeout ? "Error, " : "Timeout exceeded, ");

Expand All @@ -108,8 +113,8 @@ void deploymentFailed(@NotNull String environmentId, @NotNull String application
}

@Override
void deploymentSucceeded(@NotNull String environmentId, @NotNull String applicationName, @NotNull String versionLabel) {
String message = String.format("Application %s version %s was deployed successfully to %s", applicationName, versionLabel, environmentId);
void deploymentSucceeded(@NotNull String versionLabel) {
String message = String.format("Version %s was deployed successfully", versionLabel);
log(message);
statusText(message);
close(UPDATE_ENVIRONMENT);
Expand All @@ -135,11 +140,11 @@ private int getIdentity(String... parts) {
@NotNull
private Collection<String> getIdentityFormingParameters() {
return Arrays.asList(
myRunnerParameters.get(ElasticBeanstalkConstants.S3_OBJECT_KEY_PARAM),
myRunnerParameters.get(ElasticBeanstalkConstants.S3_BUCKET_NAME_PARAM),
myRunnerParameters.get(ElasticBeanstalkConstants.ENV_NAME_PARAM),
myRunnerParameters.get(ElasticBeanstalkConstants.APP_NAME_PARAM),
myRunnerParameters.get(ElasticBeanstalkConstants.APP_VERSION_PARAM));
myRunnerParameters.get(ElasticBeanstalkConstants.S3_OBJECT_KEY_PARAM),
myRunnerParameters.get(ElasticBeanstalkConstants.S3_BUCKET_NAME_PARAM),
myRunnerParameters.get(ElasticBeanstalkConstants.ENV_NAME_PARAM),
myRunnerParameters.get(ElasticBeanstalkConstants.APP_NAME_PARAM),
myRunnerParameters.get(ElasticBeanstalkConstants.APP_VERSION_PARAM));
}

protected void log(@NotNull String message) {
Expand Down Expand Up @@ -173,11 +178,11 @@ protected void statusText(@NotNull String text) {
@NotNull
private String escape(@NotNull String s) {
return s.
replace("|", "||").
replace("'", "|'").
replace("\n", "|n").
replace("\r", "|r").
replace("\\uNNNN", "|0xNNNN").
replace("[", "|[").replace("]", "|]");
replace("|", "||").
replace("'", "|'").
replace("\n", "|n").
replace("\r", "|r").
replace("\\uNNNN", "|0xNNNN").
replace("[", "|[").replace("]", "|]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

public class LoggingDeploymentListenerTest extends LoggingTestCase {

private static final String FAKE_ID = "ID-123XYZ";
private static final String FAKE_APP_NAME = "NAME-FOO";
private static final String FAKE_ENV_NAME = "ENV-NAME-FOO";
private static final String FAKE_APP_NAME = "APP-NAME-BAR";
private static final String FAKE_APP_VERSION = "1.0.0-alpha1";

@BeforeMethod(alwaysRun = true)
Expand All @@ -53,79 +53,79 @@ public void common_events() throws Exception {

listener.createVersionFinished(FAKE_APP_NAME, FAKE_APP_VERSION, bucketName, key);

listener.deploymentStarted(FAKE_ID, FAKE_APP_NAME, FAKE_APP_VERSION);
listener.deploymentStarted(FAKE_APP_NAME, FAKE_ENV_NAME, FAKE_APP_VERSION);

listener.deploymentWaitStarted(FAKE_ID);
listener.deploymentWaitStarted(FAKE_ENV_NAME);

listener.deploymentInProgress(FAKE_ID);
listener.deploymentInProgress(FAKE_ENV_NAME);

listener.deploymentSucceeded(FAKE_ID, FAKE_APP_NAME, FAKE_APP_VERSION);
listener.deploymentSucceeded(FAKE_APP_VERSION);

assertLog(
"OPEN " + LoggingDeploymentListener.CREATE_VERSION,
"LOG Creating application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " with bucket " + bucketName + " and key " + key,
"LOG Created application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " with bucket " + bucketName + " and key " + key,
"CLOSE " + LoggingDeploymentListener.CREATE_VERSION,
"OPEN " + LoggingDeploymentListener.UPDATE_ENVIRONMENT,
"LOG Started deployment of application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " to " + FAKE_ID,
"LOG Waiting for deployment finish",
"LOG Waiting for deployment on environment " + FAKE_ID,
"PROGRESS Waiting for deployment on environment " + FAKE_ID,
"LOG Application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " was deployed successfully to " + FAKE_ID,
"STATUS_TEXT Application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " was deployed successfully to " + FAKE_ID,
"CLOSE " + LoggingDeploymentListener.UPDATE_ENVIRONMENT);
"OPEN " + LoggingDeploymentListener.CREATE_VERSION,
"LOG Creating application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " with bucket " + bucketName + " and key " + key,
"LOG Created application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " with bucket " + bucketName + " and key " + key,
"CLOSE " + LoggingDeploymentListener.CREATE_VERSION,
"OPEN " + LoggingDeploymentListener.UPDATE_ENVIRONMENT,
"LOG Started deployment of application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " to " + FAKE_ENV_NAME,
"LOG Waiting for deployment finish",
"LOG Waiting for deployment on environment " + FAKE_ENV_NAME,
"PROGRESS Waiting for deployment on environment " + FAKE_ENV_NAME,
"LOG Version " + FAKE_APP_VERSION + " was deployed successfully",
"STATUS_TEXT Version " + FAKE_APP_VERSION + " was deployed successfully",
"CLOSE " + LoggingDeploymentListener.UPDATE_ENVIRONMENT);
}

@Test
public void deployment_progress() throws Exception {
create().deploymentInProgress(FAKE_ID);
assertLog("PROGRESS Waiting for deployment on environment " + FAKE_ID);
create().deploymentInProgress(FAKE_ENV_NAME);
assertLog("PROGRESS Waiting for deployment on environment " + FAKE_ENV_NAME);
}

@Test
public void deployment_succeeded() throws Exception {
create().deploymentSucceeded(FAKE_ID, FAKE_APP_NAME, FAKE_APP_VERSION);
create().deploymentSucceeded(FAKE_APP_VERSION);
assertLog(
"LOG Application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " was deployed successfully to " + FAKE_ID,
"STATUS_TEXT Application " + FAKE_APP_NAME + " version " + FAKE_APP_VERSION + " was deployed successfully to " + FAKE_ID,
"CLOSE " + LoggingDeploymentListener.UPDATE_ENVIRONMENT);
"LOG Version " + FAKE_APP_VERSION + " was deployed successfully",
"STATUS_TEXT Version " + FAKE_APP_VERSION + " was deployed successfully",
"CLOSE " + LoggingDeploymentListener.UPDATE_ENVIRONMENT);
}

@Test
public void deployment_failed_timeout() throws Exception {
create().deploymentFailed(FAKE_ID, FAKE_APP_NAME, FAKE_APP_VERSION, true, null);
create().deploymentFailed(FAKE_APP_NAME, FAKE_ENV_NAME, FAKE_APP_VERSION, true, null);
assertLog(
"PROBLEM identity: 3569038 type: ELASTICBEANSTALK_TIMEOUT descr: Timeout exceeded, ",
"CLOSE update environment");
"PROBLEM identity: 3569038 type: ELASTICBEANSTALK_TIMEOUT descr: Timeout exceeded, ",
"CLOSE " + LoggingDeploymentListener.UPDATE_ENVIRONMENT);
}

@Test
public void deployment_failed() throws Exception {
create().deploymentFailed(FAKE_ID, FAKE_APP_NAME, FAKE_APP_VERSION, false, createError("abc", "Some error message"));
create().deploymentFailed(FAKE_APP_NAME, FAKE_ENV_NAME, FAKE_APP_VERSION, false, createError("abc", "Some error message"));
assertLog(
"ERR Associated error: Some error message",
"ERR Error severity: abc",
"PROBLEM identity: 79914740 type: ELASTICBEANSTALK_FAILURE descr: Error, : Some error message",
"CLOSE update environment");
"ERR Associated error: Some error message",
"ERR Error severity: abc",
"PROBLEM identity: 79914740 type: ELASTICBEANSTALK_FAILURE descr: Error, : Some error message",
"CLOSE " + LoggingDeploymentListener.UPDATE_ENVIRONMENT);
}

@Test
public void deployment_exception_type() throws Exception {
create().exception(new AWSException("Some exception message", null, AWSException.EXCEPTION_BUILD_PROBLEM_TYPE, null));
assertLog(
"ERR Some exception message",
"PROBLEM identity: 2086901196 type: ELASTICBEANSTALK_EXCEPTION descr: Some exception message",
"CLOSE update environment");
"ERR Some exception message",
"PROBLEM identity: 2086901196 type: ELASTICBEANSTALK_EXCEPTION descr: Some exception message",
"CLOSE " + LoggingDeploymentListener.UPDATE_ENVIRONMENT);
}

@Test
public void deployment_exception_description_type() throws Exception {
create().exception(new AWSException("Some exception message", null, AWSException.CLIENT_PROBLEM_TYPE, "Some exception details"));
assertLog(
"ERR Some exception message",
"ERR Some exception details",
"PROBLEM identity: 2086901196 type: ELASTICBEANSTALK_CLIENT descr: Some exception message",
"CLOSE update environment");
"ERR Some exception message",
"ERR Some exception details",
"PROBLEM identity: 2086901196 type: ELASTICBEANSTALK_CLIENT descr: Some exception message",
"CLOSE " + LoggingDeploymentListener.UPDATE_ENVIRONMENT);
}

@Override
Expand All @@ -144,8 +144,8 @@ private AWSClient.Listener.ErrorInfo createError(@Nullable String severity, @Nul
@NotNull
private LoggingDeploymentListener create() {
return new LoggingDeploymentListener(Collections.<String, String>emptyMap(),
new NullBuildProgressLogger(),
"fake_checkout_dir") {
new NullBuildProgressLogger(),
"fake_checkout_dir") {
@Override
protected void log(@NotNull String message) {
logMessage("LOG " + message);
Expand Down
Loading

0 comments on commit 4a1a934

Please sign in to comment.