{"action":"created","comment":{"url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/comments/37780045","id":37780045,"diff_hunk":"@@ -7,75 +17,154 @@\n import com.amazonaws.services.cloudformation.model.ResourceSignalStatus;\n import com.amazonaws.services.cloudformation.model.SignalResourceRequest;\n import com.amazonaws.util.EC2MetadataUtils;\n-import io.dropwizard.Bundle;\n-import io.dropwizard.lifecycle.ServerLifecycleListener;\n+import com.google.common.base.Throwables;\n+import io.dropwizard.Configuration;\n+import io.dropwizard.ConfiguredBundle;\n import io.dropwizard.setup.Bootstrap;\n import io.dropwizard.setup.Environment;\n-import org.eclipse.jetty.server.Server;\n+import org.eclipse.jetty.util.component.LifeCycle;\n import org.slf4j.Logger;\n import org.slf4j.LoggerFactory;\n \n /**\n  * Signal the AutoScalingGroup via CloudFormation Signal when running on an AWS EC2 instance.\n  */\n-public class CfSignalResourceBundle implements Bundle {\n+public class CfSignalResourceBundle<T extends Configuration> implements ConfiguredBundle<T> {\n \n   private static final Logger LOGGER = LoggerFactory.getLogger(CfSignalResourceBundle.class);\n \n-  private final String asgResourceName;\n-  private final String stackName;\n-  private final String awsRegion;\n-\n-  /**\n-   * Create a bundle to signal the AutoScalingGroup via CloudFormation Signal\n-   *\n-   * @param asgResourceName the name of the auto scaling group cloudformation resource to signal\n-   * @param stackName       the name of the stack containing the auto scaling group to signal\n-   * @param awsRegion       the aws region the stack is in, e.g. us-west-2\n-   */\n-  public CfSignalResourceBundle(String asgResourceName, String stackName, String awsRegion) {\n-    this.asgResourceName = asgResourceName;\n-    this.stackName = stackName;\n-    this.awsRegion = awsRegion;\n+  private final Supplier<Optional<String>> instanceIdProvider;\n+  private final Function<CfSignalResourceConfig, AmazonCloudFormation> cloudFormationSupplier;\n+  private final AtomicReference<AmazonCloudFormation> cloudFormationAtomicRef = new AtomicReference<>(null);\n+\n+  public CfSignalResourceBundle() {\n+    instanceIdProvider = () -> Optional.ofNullable(EC2MetadataUtils.getInstanceId());\n+\n+    cloudFormationSupplier = (cfSignalResourceConfig) -> {\n+      AmazonCloudFormation amazonCloudFormation = cloudFormationAtomicRef.get();\n+\n+      if (amazonCloudFormation != null) {\n+        return amazonCloudFormation;\n+      }\n+\n+      return cloudFormationAtomicRef.updateAndGet((unused) -> {\n+\n+        AmazonCloudFormationClient amazonCloudFormationClient = new AmazonCloudFormationClient();\n+\n+        amazonCloudFormationClient.setRegion(Region.getRegion(Regions.valueOf(cfSignalResourceConfig.getAwsRegion()\n+                                                                                                    .toUpperCase()\n+                                                                                                    .replace('-', '_'))));\n+        return amazonCloudFormationClient;\n+      });\n+    };\n+  }\n+\n+  @Inject\n+  public CfSignalResourceBundle(@CfSignalResourceInstanceId Optional<String> instanceId, AmazonCloudFormation amazonCloudFormation) {\n+    instanceIdProvider = () -> checkNotNull(instanceId);\n+    cloudFormationSupplier = (config) -> amazonCloudFormation;\n   }\n \n   @Override\n   public void initialize(Bootstrap<?> bootstrap) {\n+  }\n \n+  public CfSignalResourceConfig getConfiguration() {\n+    return new CfSignalResourceConfig();\n   }\n \n   @Override\n-  public void run(Environment environment) {\n+  public void run(T config, Environment environment) {\n \n-    final String instanceId = EC2MetadataUtils.getInstanceId();\n-    if (instanceId == null || instanceId.trim() == \"\") {\n+    final Optional<String> instanceId = instanceIdProvider.get();\n+    if (!instanceId.isPresent()) {\n       LOGGER.debug(\"Unable to fetch EC2 Instance ID, assuming not running on AWS and thus not signalling\");\n       return;\n     }\n \n-    environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {\n-      @Override\n-      public void serverStarted(Server server) {\n-        AmazonCloudFormation client = null;\n+    environment.lifecycle()\n+               .addLifeCycleListener(\n+                 new CfSignalResourceLifcycleListener(getCfResourceBundleConfig(config).orElseGet(this::getConfiguration),\n+                                                      instanceId.get()));","path":"src/main/java/net/eldeen/dropwizard/CfSignalResourceBundle.java","position":114,"original_position":114,"commit_id":"6b101bb8f1a40d32ce91f715df127d91a0f987e9","original_commit_id":"6b101bb8f1a40d32ce91f715df127d91a0f987e9","user":{"login":"qualidafial","id":38629,"avatar_url":"https://avatars.githubusercontent.com/u/38629?v=3","gravatar_id":"","url":"https://api.github.com/users/qualidafial","html_url":"https://github.com/qualidafial","followers_url":"https://api.github.com/users/qualidafial/followers","following_url":"https://api.github.com/users/qualidafial/following{/other_user}","gists_url":"https://api.github.com/users/qualidafial/gists{/gist_id}","starred_url":"https://api.github.com/users/qualidafial/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qualidafial/subscriptions","organizations_url":"https://api.github.com/users/qualidafial/orgs","repos_url":"https://api.github.com/users/qualidafial/repos","events_url":"https://api.github.com/users/qualidafial/events{/privacy}","received_events_url":"https://api.github.com/users/qualidafial/received_events","type":"User","site_admin":false},"body":"Not sure I like defaulting to an empty configuration. Would rather throw an exception or log a warning or something.\r\n\r\nEither that or sanity check the values in the config object before making a request based on it.","created_at":"2015-08-24T17:54:43Z","updated_at":"2015-08-24T17:54:43Z","html_url":"https://github.com/heldeen/cf-signal-resource-bundle/pull/3#discussion_r37780045","pull_request_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/comments/37780045"},"html":{"href":"https://github.com/heldeen/cf-signal-resource-bundle/pull/3#discussion_r37780045"},"pull_request":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/3","id":43197814,"html_url":"https://github.com/heldeen/cf-signal-resource-bundle/pull/3","diff_url":"https://github.com/heldeen/cf-signal-resource-bundle/pull/3.diff","patch_url":"https://github.com/heldeen/cf-signal-resource-bundle/pull/3.patch","issue_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues/3","number":3,"state":"open","locked":false,"title":"add compiler plugin and config","user":{"login":"heldeen","id":1727977,"avatar_url":"https://avatars.githubusercontent.com/u/1727977?v=3","gravatar_id":"","url":"https://api.github.com/users/heldeen","html_url":"https://github.com/heldeen","followers_url":"https://api.github.com/users/heldeen/followers","following_url":"https://api.github.com/users/heldeen/following{/other_user}","gists_url":"https://api.github.com/users/heldeen/gists{/gist_id}","starred_url":"https://api.github.com/users/heldeen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heldeen/subscriptions","organizations_url":"https://api.github.com/users/heldeen/orgs","repos_url":"https://api.github.com/users/heldeen/repos","events_url":"https://api.github.com/users/heldeen/events{/privacy}","received_events_url":"https://api.github.com/users/heldeen/received_events","type":"User","site_admin":false},"body":"Implement io.dropwizard.ConfiguredBundle\r\nAdd configuration object\r\nadd better support for having the external services (like com.amazonaws.services.cloudformation.AmazonCloudFormation) provided or creating/managing them internally\r\nadd support to dynamically lookup the config from the app config via reflection\r\nadd more and better tests\r\n\r\n@qualidafial, please take a look and let me know what you think.","created_at":"2015-08-24T17:06:51Z","updated_at":"2015-08-24T17:54:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7018ec3df12d2406c71a4719ebe590a6a7a2cedb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/3/commits","review_comments_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/3/comments","review_comment_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues/3/comments","statuses_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/statuses/6b101bb8f1a40d32ce91f715df127d91a0f987e9","head":{"label":"heldeen:improve-provided-vs-create-AWS-resources","ref":"improve-provided-vs-create-AWS-resources","sha":"6b101bb8f1a40d32ce91f715df127d91a0f987e9","user":{"login":"heldeen","id":1727977,"avatar_url":"https://avatars.githubusercontent.com/u/1727977?v=3","gravatar_id":"","url":"https://api.github.com/users/heldeen","html_url":"https://github.com/heldeen","followers_url":"https://api.github.com/users/heldeen/followers","following_url":"https://api.github.com/users/heldeen/following{/other_user}","gists_url":"https://api.github.com/users/heldeen/gists{/gist_id}","starred_url":"https://api.github.com/users/heldeen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heldeen/subscriptions","organizations_url":"https://api.github.com/users/heldeen/orgs","repos_url":"https://api.github.com/users/heldeen/repos","events_url":"https://api.github.com/users/heldeen/events{/privacy}","received_events_url":"https://api.github.com/users/heldeen/received_events","type":"User","site_admin":false},"repo":{"id":35864565,"name":"cf-signal-resource-bundle","full_name":"heldeen/cf-signal-resource-bundle","owner":{"login":"heldeen","id":1727977,"avatar_url":"https://avatars.githubusercontent.com/u/1727977?v=3","gravatar_id":"","url":"https://api.github.com/users/heldeen","html_url":"https://github.com/heldeen","followers_url":"https://api.github.com/users/heldeen/followers","following_url":"https://api.github.com/users/heldeen/following{/other_user}","gists_url":"https://api.github.com/users/heldeen/gists{/gist_id}","starred_url":"https://api.github.com/users/heldeen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heldeen/subscriptions","organizations_url":"https://api.github.com/users/heldeen/orgs","repos_url":"https://api.github.com/users/heldeen/repos","events_url":"https://api.github.com/users/heldeen/events{/privacy}","received_events_url":"https://api.github.com/users/heldeen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/heldeen/cf-signal-resource-bundle","description":"Dropwizard bundle to signal the AWS AutoScalingGroup via AWS CloudFormation SignalResource API when running on an AWS EC2 instance.","fork":false,"url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle","forks_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/forks","keys_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/teams","hooks_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/hooks","issue_events_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues/events{/number}","events_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/events","assignees_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/assignees{/user}","branches_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/branches{/branch}","tags_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/tags","blobs_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/statuses/{sha}","languages_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/languages","stargazers_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/stargazers","contributors_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/contributors","subscribers_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/subscribers","subscription_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/subscription","commits_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/contents/{+path}","compare_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/merges","archive_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/downloads","issues_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues{/number}","pulls_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls{/number}","milestones_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/milestones{/number}","notifications_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/labels{/name}","releases_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/releases{/id}","created_at":"2015-05-19T06:53:39Z","updated_at":"2015-08-20T16:42:32Z","pushed_at":"2015-08-24T17:31:19Z","git_url":"git://github.com/heldeen/cf-signal-resource-bundle.git","ssh_url":"git@github.com:heldeen/cf-signal-resource-bundle.git","clone_url":"https://github.com/heldeen/cf-signal-resource-bundle.git","svn_url":"https://github.com/heldeen/cf-signal-resource-bundle","homepage":null,"size":187,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":2,"default_branch":"master"}},"base":{"label":"heldeen:master","ref":"master","sha":"31bf6a3743a9a322439e6986ef9e03f1d81cf579","user":{"login":"heldeen","id":1727977,"avatar_url":"https://avatars.githubusercontent.com/u/1727977?v=3","gravatar_id":"","url":"https://api.github.com/users/heldeen","html_url":"https://github.com/heldeen","followers_url":"https://api.github.com/users/heldeen/followers","following_url":"https://api.github.com/users/heldeen/following{/other_user}","gists_url":"https://api.github.com/users/heldeen/gists{/gist_id}","starred_url":"https://api.github.com/users/heldeen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heldeen/subscriptions","organizations_url":"https://api.github.com/users/heldeen/orgs","repos_url":"https://api.github.com/users/heldeen/repos","events_url":"https://api.github.com/users/heldeen/events{/privacy}","received_events_url":"https://api.github.com/users/heldeen/received_events","type":"User","site_admin":false},"repo":{"id":35864565,"name":"cf-signal-resource-bundle","full_name":"heldeen/cf-signal-resource-bundle","owner":{"login":"heldeen","id":1727977,"avatar_url":"https://avatars.githubusercontent.com/u/1727977?v=3","gravatar_id":"","url":"https://api.github.com/users/heldeen","html_url":"https://github.com/heldeen","followers_url":"https://api.github.com/users/heldeen/followers","following_url":"https://api.github.com/users/heldeen/following{/other_user}","gists_url":"https://api.github.com/users/heldeen/gists{/gist_id}","starred_url":"https://api.github.com/users/heldeen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heldeen/subscriptions","organizations_url":"https://api.github.com/users/heldeen/orgs","repos_url":"https://api.github.com/users/heldeen/repos","events_url":"https://api.github.com/users/heldeen/events{/privacy}","received_events_url":"https://api.github.com/users/heldeen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/heldeen/cf-signal-resource-bundle","description":"Dropwizard bundle to signal the AWS AutoScalingGroup via AWS CloudFormation SignalResource API when running on an AWS EC2 instance.","fork":false,"url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle","forks_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/forks","keys_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/teams","hooks_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/hooks","issue_events_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues/events{/number}","events_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/events","assignees_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/assignees{/user}","branches_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/branches{/branch}","tags_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/tags","blobs_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/statuses/{sha}","languages_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/languages","stargazers_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/stargazers","contributors_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/contributors","subscribers_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/subscribers","subscription_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/subscription","commits_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/contents/{+path}","compare_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/merges","archive_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/downloads","issues_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues{/number}","pulls_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls{/number}","milestones_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/milestones{/number}","notifications_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/labels{/name}","releases_url":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/releases{/id}","created_at":"2015-05-19T06:53:39Z","updated_at":"2015-08-20T16:42:32Z","pushed_at":"2015-08-24T17:31:19Z","git_url":"git://github.com/heldeen/cf-signal-resource-bundle.git","ssh_url":"git@github.com:heldeen/cf-signal-resource-bundle.git","clone_url":"https://github.com/heldeen/cf-signal-resource-bundle.git","svn_url":"https://github.com/heldeen/cf-signal-resource-bundle","homepage":null,"size":187,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/3"},"html":{"href":"https://github.com/heldeen/cf-signal-resource-bundle/pull/3"},"issue":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues/3"},"comments":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/heldeen/cf-signal-resource-bundle/statuses/6b101bb8f1a40d32ce91f715df127d91a0f987e9"}}}}