47
47
import java .util .function .Supplier ;
48
48
import java .util .stream .Collectors ;
49
49
import lombok .Getter ;
50
+ import org .apache .commons .lang3 .StringUtils ;
50
51
import org .apache .pulsar .client .admin .ListTopicsOptions ;
51
52
import org .apache .pulsar .client .admin .LongRunningProcessStatus ;
52
53
import org .apache .pulsar .client .admin .OffloadProcessStatus ;
@@ -2018,20 +2019,20 @@ private class SetOffloadPolicies extends CliCommand {
2018
2019
@ Parameter (names = {"-m" , "--maxBlockSizeInBytes" },
2019
2020
description = "ManagedLedger offload max block Size in bytes,"
2020
2021
+ "s3 and google-cloud-storage requires this parameter" )
2021
- private int maxBlockSizeInBytes ;
2022
+ private String maxBlockSizeInBytesStr ;
2022
2023
2023
2024
@ Parameter (names = {"-rb" , "--readBufferSizeInBytes" },
2024
2025
description = "ManagedLedger offload read buffer size in bytes,"
2025
2026
+ "s3 and google-cloud-storage requires this parameter" )
2026
- private int readBufferSizeInBytes ;
2027
+ private String readBufferSizeInBytesStr ;
2027
2028
2028
2029
@ Parameter (names = {"-t" , "--offloadThresholdInBytes" }
2029
2030
, description = "ManagedLedger offload threshold in bytes" , required = true )
2030
- private long offloadThresholdInBytes ;
2031
+ private String offloadThresholdInBytesStr ;
2031
2032
2032
2033
@ Parameter (names = {"-dl" , "--offloadDeletionLagInMillis" }
2033
2034
, description = "ManagedLedger offload deletion lag in bytes" )
2034
- private Long offloadDeletionLagInMillis ;
2035
+ private String offloadDeletionLagInMillisStr ;
2035
2036
2036
2037
@ Parameter (names = {"--offloadedReadPriority" , "-orp" },
2037
2038
description = "Read priority for offloaded messages. "
@@ -2043,13 +2044,27 @@ private class SetOffloadPolicies extends CliCommand {
2043
2044
)
2044
2045
private String offloadReadPriorityStr ;
2045
2046
2047
+ public boolean positiveCheck (String paramName , long value ) {
2048
+ if (value <= 0 ) {
2049
+ throw new ParameterException (paramName + " is not be negative or 0!" );
2050
+ }
2051
+ return true ;
2052
+ }
2053
+
2054
+ public boolean maxValueCheck (String paramName , long value , long maxValue ) {
2055
+ if (value > maxValue ) {
2056
+ throw new ParameterException (paramName + " is not bigger than " + maxValue + "!" );
2057
+ }
2058
+ return true ;
2059
+ }
2060
+
2046
2061
@ Override
2047
2062
void run () throws PulsarAdminException {
2048
2063
String persistentTopic = validatePersistentTopic (params );
2049
2064
2050
2065
OffloadedReadPriority offloadedReadPriority = OffloadPoliciesImpl .DEFAULT_OFFLOADED_READ_PRIORITY ;
2051
2066
2052
- if (this . offloadReadPriorityStr != null ) {
2067
+ if (StringUtils . isNotBlank ( offloadReadPriorityStr ) ) {
2053
2068
try {
2054
2069
offloadedReadPriority = OffloadedReadPriority .fromString (this .offloadReadPriorityStr );
2055
2070
} catch (Exception e ) {
@@ -2061,6 +2076,48 @@ void run() throws PulsarAdminException {
2061
2076
}
2062
2077
}
2063
2078
2079
+ int maxBlockSizeInBytes = OffloadPoliciesImpl .DEFAULT_MAX_BLOCK_SIZE_IN_BYTES ;
2080
+ if (StringUtils .isNotBlank (maxBlockSizeInBytesStr )) {
2081
+ long maxBlockSize = validateSizeString (maxBlockSizeInBytesStr );
2082
+ if (positiveCheck ("MaxBlockSizeInBytes" , maxBlockSize )
2083
+ && maxValueCheck ("MaxBlockSizeInBytes" , maxBlockSize , Integer .MAX_VALUE )) {
2084
+ maxBlockSizeInBytes = Long .valueOf (maxBlockSize ).intValue ();
2085
+ }
2086
+ }
2087
+
2088
+ int readBufferSizeInBytes = OffloadPoliciesImpl .DEFAULT_READ_BUFFER_SIZE_IN_BYTES ;
2089
+ if (StringUtils .isNotBlank (readBufferSizeInBytesStr )) {
2090
+ long readBufferSize = validateSizeString (readBufferSizeInBytesStr );
2091
+ if (positiveCheck ("readBufferSizeInBytes" , readBufferSize )
2092
+ && maxValueCheck ("readBufferSizeInBytes" , readBufferSize , Integer .MAX_VALUE )) {
2093
+ readBufferSizeInBytes = Long .valueOf (readBufferSize ).intValue ();
2094
+ }
2095
+ }
2096
+
2097
+ Long offloadThresholdInBytes = OffloadPoliciesImpl .DEFAULT_OFFLOAD_THRESHOLD_IN_BYTES ;
2098
+ if (StringUtils .isNotBlank (offloadThresholdInBytesStr )) {
2099
+ long offloadThreshold = validateSizeString (offloadThresholdInBytesStr );
2100
+ if (positiveCheck ("offloadThresholdInBytes" , offloadThreshold )
2101
+ && maxValueCheck ("offloadThresholdInBytes" , offloadThreshold , Long .MAX_VALUE )) {
2102
+ offloadThresholdInBytes = offloadThreshold ;
2103
+ }
2104
+ }
2105
+
2106
+ Long offloadDeletionLagInMillis = OffloadPoliciesImpl .DEFAULT_OFFLOAD_DELETION_LAG_IN_MILLIS ;
2107
+ if (StringUtils .isNotBlank (offloadDeletionLagInMillisStr )) {
2108
+ Long offloadThreshold ;
2109
+ try {
2110
+ offloadThreshold = TimeUnit .SECONDS .toMillis (
2111
+ RelativeTimeUtil .parseRelativeTimeInSeconds (offloadDeletionLagInMillisStr ));
2112
+ } catch (IllegalArgumentException exception ) {
2113
+ throw new ParameterException (exception .getMessage ());
2114
+ }
2115
+ if (positiveCheck ("offloadDeletionLagInMillis" , offloadThreshold )
2116
+ && maxValueCheck ("offloadDeletionLagInMillis" , offloadThreshold , Long .MAX_VALUE )) {
2117
+ offloadDeletionLagInMillis = offloadThreshold ;
2118
+ }
2119
+ }
2120
+
2064
2121
OffloadPoliciesImpl offloadPolicies = OffloadPoliciesImpl .create (driver , region , bucket , endpoint ,
2065
2122
s3Role , s3RoleSessionName ,
2066
2123
awsId , awsSecret ,
0 commit comments