From 33b585957ddcb1ddfcc698618343767cbd6ca697 Mon Sep 17 00:00:00 2001 From: cdebojit <62727046+cdebojit@users.noreply.github.com> Date: Fri, 17 Apr 2020 11:39:15 -0700 Subject: [PATCH] removed redundant state maintainence (#31) --- .../amazon/logs/loggroup/CreateHandler.java | 18 +++++-------- .../amazon/logs/loggroup/ReadHandler.java | 13 ---------- .../amazon/logs/loggroup/UpdateHandler.java | 26 ++++++------------- 3 files changed, 14 insertions(+), 43 deletions(-) diff --git a/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/CreateHandler.java b/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/CreateHandler.java index a4b687c..c31b033 100644 --- a/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/CreateHandler.java +++ b/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/CreateHandler.java @@ -15,10 +15,6 @@ public class CreateHandler extends BaseHandler { private static final String DEFAULT_LOG_GROUP_NAME_PREFIX = "LogGroup"; private static final int MAX_LENGTH_LOG_GROUP_NAME = 512; - private AmazonWebServicesClientProxy proxy; - private ResourceHandlerRequest request; - private Logger logger; - @Override public ProgressEvent handleRequest( final AmazonWebServicesClientProxy proxy, @@ -26,11 +22,7 @@ public ProgressEvent handleRequest( final CallbackContext callbackContext, final Logger logger) { - this.proxy = proxy; - this.request = request; - this.logger = logger; - - prepareResourceModel(); + prepareResourceModel(request); final ResourceModel model = request.getDesiredResourceState(); @@ -47,7 +39,7 @@ public ProgressEvent handleRequest( logger.log(createMessage); if (model.getRetentionInDays() != null) { - updateRetentionInDays(); + updateRetentionInDays(proxy, request, logger); } return ProgressEvent.defaultSuccessHandler(model); @@ -62,7 +54,7 @@ public ProgressEvent handleRequest( * 2. Generating a log name if one is not given. This is a createOnly property, * but we generate one if one is not provided. */ - private void prepareResourceModel() { + private void prepareResourceModel(final ResourceHandlerRequest request) { if (request.getDesiredResourceState() == null) { request.setDesiredResourceState(new ResourceModel()); } @@ -83,7 +75,9 @@ private void prepareResourceModel() { } } - private void updateRetentionInDays() { + private void updateRetentionInDays(final AmazonWebServicesClientProxy proxy, + final ResourceHandlerRequest request, + final Logger logger) { final ResourceModel model = request.getDesiredResourceState(); proxy.injectCredentialsAndInvokeV2(Translator.translateToPutRetentionPolicyRequest(model), ClientBuilder.getClient()::putRetentionPolicy); diff --git a/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/ReadHandler.java b/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/ReadHandler.java index 1f3ca04..5a52b11 100644 --- a/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/ReadHandler.java +++ b/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/ReadHandler.java @@ -11,10 +11,6 @@ public class ReadHandler extends BaseHandler { - private AmazonWebServicesClientProxy proxy; - private ResourceHandlerRequest request; - private Logger logger; - @Override public ProgressEvent handleRequest( final AmazonWebServicesClientProxy proxy, @@ -22,21 +18,12 @@ public ProgressEvent handleRequest( final CallbackContext callbackContext, final Logger logger) { - this.proxy = proxy; - this.request = request; - this.logger = logger; - - return fetchLogGroupAndAssertExists(); - } - - private ProgressEvent fetchLogGroupAndAssertExists() { final ResourceModel model = request.getDesiredResourceState(); if (model == null || model.getLogGroupName() == null) { throwNotFoundException(model); } - DescribeLogGroupsResponse response = null; try { response = proxy.injectCredentialsAndInvokeV2(Translator.translateToReadRequest(model), diff --git a/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/UpdateHandler.java b/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/UpdateHandler.java index eb257b5..8844b79 100644 --- a/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/UpdateHandler.java +++ b/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/UpdateHandler.java @@ -12,11 +12,6 @@ public class UpdateHandler extends BaseHandler { - private AmazonWebServicesClientProxy proxy; - private ResourceHandlerRequest request; - private CallbackContext callbackContext; - private Logger logger; - @Override public ProgressEvent handleRequest( final AmazonWebServicesClientProxy proxy, @@ -24,28 +19,21 @@ public ProgressEvent handleRequest( final CallbackContext callbackContext, final Logger logger) { - this.proxy = proxy; - this.request = request; - this.callbackContext = callbackContext; - this.logger = logger; - // RetentionPolicyInDays is the only attribute that is not createOnly - return updateRetentionPolicy(); - } - - private ProgressEvent updateRetentionPolicy() { final ResourceModel model = request.getDesiredResourceState(); if (model.getRetentionInDays() == null) { - deleteRetentionPolicy(); + deleteRetentionPolicy(proxy, request, logger); } else { - putRetentionPolicy(); + putRetentionPolicy(proxy, request, logger); } return ProgressEvent.defaultSuccessHandler(model); } - private void deleteRetentionPolicy() { + private void deleteRetentionPolicy(final AmazonWebServicesClientProxy proxy, + final ResourceHandlerRequest request, + final Logger logger) { final ResourceModel model = request.getDesiredResourceState(); final DeleteRetentionPolicyRequest deleteRetentionPolicyRequest = Translator.translateToDeleteRetentionPolicyRequest(model); @@ -62,7 +50,9 @@ private void deleteRetentionPolicy() { logger.log(retentionPolicyMessage); } - private void putRetentionPolicy() { + private void putRetentionPolicy(final AmazonWebServicesClientProxy proxy, + final ResourceHandlerRequest request, + final Logger logger) { final ResourceModel model = request.getDesiredResourceState(); final PutRetentionPolicyRequest putRetentionPolicyRequest = Translator.translateToPutRetentionPolicyRequest(model);