Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hdds.client;

import org.apache.hadoop.ozone.OzoneConsts;

/**
* OzoneRecoverWindow that can be applied to bucket.
*/
public class OzoneRecoverWindow {

public static final String OZONE_RECOVER_WINDOW_MIN = "MIN";
public static final String OZONE_RECOVER_WINDOW_HR = "HR";
public static final String OZONE_RECOVER_WINDOW_DAY = "DAY";

private Units unit;
private long windowLength;

/** Recover-window Units.*/
public enum Units {UNDEFINED, MIN, HR, DAY}

/**
* Returns recover-window length.
*/
public long getWindowLength() {
return windowLength;
}

/**
* Returns Units.
*
* @return Unit in MIN, HR or DAY
*/
public Units getUnit() {
return unit;
}

/**
* Constructs a default OzoneRecoverWindow object.
*/
public OzoneRecoverWindow() {
this.windowLength = 0;
this.unit = Units.UNDEFINED;
}

/**
* Constructor for OzoneRecoverWindow.
* @param windowLength recover-window length
* @param unit MIN, HR or DAY
*/
public OzoneRecoverWindow(long windowLength, Units unit) {
this.windowLength = windowLength;
this.unit = unit;
}

/**
* Formats recover-window as a string.
*/
public static String formatWindow(OzoneRecoverWindow window) {
return String.valueOf(window.windowLength) + window.unit;
}

/**
* Parses user provided string and returns the OzoneRecoverWindow.
*/
public static OzoneRecoverWindow parseWindow(String windowString) {

if ((windowString == null) || (windowString.isEmpty())) {
throw new IllegalArgumentException(
"Recover-Window string cannot be null or empty.");
}

String uppercase = windowString.toUpperCase().replaceAll("\\s+", "");
String length = "";
int nLength;
Units currUnit = Units.MIN;
boolean found = false;
if (uppercase.endsWith(OZONE_RECOVER_WINDOW_MIN)) {
length = uppercase
.substring(0, uppercase.length() - OZONE_RECOVER_WINDOW_MIN.length());
currUnit = Units.MIN;
found = true;
}

if (uppercase.endsWith(OZONE_RECOVER_WINDOW_HR)) {
length = uppercase
.substring(0, uppercase.length() - OZONE_RECOVER_WINDOW_HR.length());
currUnit = Units.HR;
found = true;
}

if (uppercase.endsWith(OZONE_RECOVER_WINDOW_DAY)) {
length = uppercase
.substring(0, uppercase.length() - OZONE_RECOVER_WINDOW_DAY.length());
currUnit = Units.DAY;
found = true;
}

if (!found) {
throw new IllegalArgumentException("Window-length unit not recognized. " +
"Supported values are MIN, HR and DAY.");
}

nLength = Integer.parseInt(length);
if (nLength < 0) {
throw new IllegalArgumentException("Window-length cannot be negative.");
}

return new OzoneRecoverWindow(nLength, currUnit);
}


/**
* Returns length in seconds or -1 if there is no Window.
*/
public long lengthInSeconds() {
switch (this.unit) {
case MIN:
return this.getWindowLength() * OzoneConsts.MIN;
case HR:
return this.getWindowLength() * OzoneConsts.HR;
case DAY:
return this.getWindowLength() * OzoneConsts.DAY;
case UNDEFINED:
default:
return -1;
}
}


/**
* Returns OzoneRecoverWindow corresponding to window length in seconds.
*/
public static OzoneRecoverWindow getOzoneRecoverWindow(long windowInSeconds) {
long length;
Units unit;
if (windowInSeconds % OzoneConsts.DAY == 0) {
length = windowInSeconds / OzoneConsts.DAY;
unit = Units.DAY;
} else if (windowInSeconds % OzoneConsts.HR == 0) {
length = windowInSeconds / OzoneConsts.HR;
unit = Units.HR;
} else if (windowInSeconds % OzoneConsts.MIN == 0) {
length = windowInSeconds / OzoneConsts.MIN;
unit = Units.MIN;
} else {
length = 0;
unit = Units.MIN;
}
return new OzoneRecoverWindow((int)length, unit);
}

@Override
public String toString() {
return windowLength + " " + unit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@ public final class OzoneConfigKeys {
"ozone.client.list.trash.keys.max";
public static final int OZONE_CLIENT_LIST_TRASH_KEYS_MAX_DEFAULT = 1000;

public static final String OZONE_TRASH_ENABLED_KEY = "ozone.trash.enabled";
public static final boolean OZONE_TRASH_ENABLED_KEY_DEFAULT = false;
public static final String OZONE_TRASH_RECOVER_WINDOW =
"ozone.trash.recover.window";
// Default is disabled.
public static final String OZONE_TRASH_RECOVER_WINDOW_DEFAULT = "0MIN";

public static final String OZONE_HTTP_BASEDIR = "ozone.http.basedir";

public static final String OZONE_HTTP_POLICY_KEY =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public final class OzoneConsts {
public static final long GB = MB * 1024L;
public static final long TB = GB * 1024L;

// Used by Ozone Recover-Window.
public static final long MIN = 60L * 1000L; // 60 seconds
public static final long HR = MIN * 60L;
public static final long DAY = HR * 24L;

/**
* level DB names used by SCM and data nodes.
*/
Expand Down Expand Up @@ -279,6 +284,8 @@ private OzoneConsts() {
public static final String STORAGE_TYPE = "storageType";
public static final String RESOURCE_TYPE = "resourceType";
public static final String IS_VERSION_ENABLED = "isVersionEnabled";
public static final String IS_TRASH_ENABLED = "isTrashEnabled";
public static final String RECOVER_WINDOW = "recoverWindow";
public static final String CREATION_TIME = "creationTime";
public static final String DATA_SIZE = "dataSize";
public static final String REPLICATION_TYPE = "replicationType";
Expand Down
16 changes: 16 additions & 0 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,22 @@
The maximum number of keys to return for a list trash request.
</description>
</property>
<property>
<name>ozone.trash.enabled</name>
<value>false</value>
<tag>OZONE, OM</tag>
<description>
Globally enable trash ability of buckets.
</description>
</property>
<property>
<name>ozone.trash.recover.window</name>
<value>0MIN</value>
<tag>OZONE, OM</tag>
<description>
Window of recovering trash, default is 0 for trash-disabled.
</description>
</property>
<property>
<name>ozone.http.basedir</name>
<value></value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,37 @@ public final class BucketArgs {
*/
private String bucketEncryptionKey;

/**
* Bucket is trash enabled or not.
*/
private boolean trashEnabled;

/**
* recover-window of the bucket for deleted key (trash).
*/
private String recoverWindow;

/**
* Private constructor, constructed via builder.
* @param versioning Bucket version flag.
* @param storageType Storage type to be used.
* @param acls list of ACLs.
* @param metadata map of bucket metadata
* @param bucketEncryptionKey bucket encryption key name
* @param trashEnabled bucket is trash enabled or not.
* @param recoverWindow recover-window of the bucket for deleted key (trash).
*/
private BucketArgs(Boolean versioning, StorageType storageType,
List<OzoneAcl> acls, Map<String, String> metadata,
String bucketEncryptionKey) {
String bucketEncryptionKey, boolean trashEnabled,
String recoverWindow) {
this.acls = acls;
this.versioning = versioning;
this.storageType = storageType;
this.metadata = metadata;
this.bucketEncryptionKey = bucketEncryptionKey;
this.trashEnabled = trashEnabled;
this.recoverWindow = recoverWindow;
}

/**
Expand Down Expand Up @@ -114,6 +129,22 @@ public String getEncryptionKey() {
return bucketEncryptionKey;
}

/**
* Returns the bucket is trash enabled or not.
* @return boolean
*/
public boolean isTrashEnabled() {
return trashEnabled;
}

/**
* Return the recover-window of the bucket.
* @return String
*/
public String getRecoverWindow() {
return recoverWindow;
}

/**
* Returns new builder class that builds a OmBucketInfo.
*
Expand All @@ -132,6 +163,8 @@ public static class Builder {
private List<OzoneAcl> acls;
private Map<String, String> metadata;
private String bucketEncryptionKey;
private boolean trashEnabled;
private String recoverWindow;

public Builder() {
metadata = new HashMap<>();
Expand Down Expand Up @@ -161,13 +194,24 @@ public BucketArgs.Builder setBucketEncryptionKey(String bek) {
this.bucketEncryptionKey = bek;
return this;
}

public BucketArgs.Builder setTrashEnabled(boolean trashEnabledSetting) {
this.trashEnabled = trashEnabledSetting;
return this;
}

public BucketArgs.Builder setRecoverWindow(String recoverWindowSetting) {
this.recoverWindow = recoverWindowSetting;
return this;
}

/**
* Constructs the BucketArgs.
* @return instance of BucketArgs.
*/
public BucketArgs build() {
return new BucketArgs(versioning, storageType, acls, metadata,
bucketEncryptionKey);
bucketEncryptionKey, trashEnabled, recoverWindow);
}
}
}
Loading