-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CloudWatch] Refactor getMetrics in validation
- Loading branch information
Showing
3 changed files
with
171 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...cloudwatch/src/main/java/software/tnb/aws/cloudwatch/validation/model/MetricsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package software.tnb.aws.cloudwatch.validation.model; | ||
|
||
import org.apache.commons.lang3.RandomStringUtils; | ||
|
||
import java.time.Instant; | ||
|
||
public class MetricsRequest { | ||
private String metricName; | ||
private String namespace; | ||
private String stat; | ||
private int maxDataPoints; | ||
private int period; | ||
private Instant start; | ||
private Instant end; | ||
private String queryId; | ||
|
||
public String metricName() { | ||
return metricName; | ||
} | ||
|
||
public String namespace() { | ||
return namespace; | ||
} | ||
|
||
public String stat() { | ||
return stat; | ||
} | ||
|
||
public int maxDataPoints() { | ||
return maxDataPoints; | ||
} | ||
|
||
public int period() { | ||
return period; | ||
} | ||
|
||
public Instant start() { | ||
return start; | ||
} | ||
|
||
public Instant end() { | ||
return end; | ||
} | ||
|
||
public String queryId() { | ||
return queryId; | ||
} | ||
|
||
public static final class MetricsRequestBuilder { | ||
private String metricName; | ||
private String namespace; | ||
private String stat; | ||
private int maxDataPoints = 100; | ||
private int period = 60; | ||
private Instant start; | ||
private Instant end = Instant.now(); | ||
private String queryId = RandomStringUtils.randomAlphabetic(8).toLowerCase(); | ||
|
||
public MetricsRequestBuilder() { | ||
} | ||
|
||
public MetricsRequestBuilder metricName(String metricName) { | ||
this.metricName = metricName; | ||
return this; | ||
} | ||
|
||
public MetricsRequestBuilder namespace(String namespace) { | ||
this.namespace = namespace; | ||
return this; | ||
} | ||
|
||
public MetricsRequestBuilder stat(Stat stat) { | ||
this.stat = stat.value(); | ||
return this; | ||
} | ||
|
||
public MetricsRequestBuilder stat(String stat) { | ||
this.stat = stat; | ||
return this; | ||
} | ||
|
||
public MetricsRequestBuilder maxDataPoints(int maxDataPoints) { | ||
this.maxDataPoints = maxDataPoints; | ||
return this; | ||
} | ||
|
||
public MetricsRequestBuilder period(int period) { | ||
this.period = period; | ||
return this; | ||
} | ||
|
||
public MetricsRequestBuilder start(Instant start) { | ||
this.start = start; | ||
return this; | ||
} | ||
|
||
public MetricsRequestBuilder end(Instant end) { | ||
this.end = end; | ||
return this; | ||
} | ||
|
||
public MetricsRequestBuilder queryId(String queryId) { | ||
this.queryId = queryId; | ||
return this; | ||
} | ||
|
||
public MetricsRequest build() { | ||
if (metricName == null || namespace == null || stat == null || start == null) { | ||
throw new IllegalArgumentException( | ||
"At least one required parameter missing. Required parameters are metricName, namespace, stat, start"); | ||
} | ||
|
||
MetricsRequest metricsRequest = new MetricsRequest(); | ||
metricsRequest.maxDataPoints = this.maxDataPoints; | ||
metricsRequest.start = this.start; | ||
metricsRequest.metricName = this.metricName; | ||
metricsRequest.end = this.end; | ||
metricsRequest.namespace = this.namespace; | ||
metricsRequest.stat = this.stat; | ||
metricsRequest.queryId = this.queryId; | ||
metricsRequest.period = this.period; | ||
return metricsRequest; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...vices/aws/cloudwatch/src/main/java/software/tnb/aws/cloudwatch/validation/model/Stat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package software.tnb.aws.cloudwatch.validation.model; | ||
|
||
public enum Stat { | ||
AVERAGE("Average"), | ||
MINIMUM("Minimum"), | ||
MAXIMUM("Maximum"), | ||
SUM("Sum"), | ||
SAMPLE_COUNT("SampleCount"), | ||
IQM("IQM"); | ||
// Others like percentile, trimmed mean, etc. require a value, so those can be supplied via a plain string for now | ||
|
||
private final String value; | ||
|
||
Stat(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String value() { | ||
return value; | ||
} | ||
} |