Skip to content

Commit

Permalink
AdminClient: add getDataUsageInfo API (#1382)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Raska <[email protected]>
  • Loading branch information
lukasraska committed Nov 17, 2022
1 parent b84d7a1 commit 3a87a2a
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 0 deletions.
22 changes: 22 additions & 0 deletions adminapi/src/main/java/io/minio/admin/MinioAdminClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand All @@ -29,6 +30,7 @@
import io.minio.S3Escaper;
import io.minio.Signer;
import io.minio.Time;
import io.minio.admin.messages.DataUsageInfo;
import io.minio.credentials.Credentials;
import io.minio.credentials.Provider;
import io.minio.credentials.StaticProvider;
Expand Down Expand Up @@ -74,6 +76,7 @@ private enum Command {
REMOVE_CANNED_POLICY("remove-canned-policy"),
SET_BUCKET_QUOTA("set-bucket-quota"),
GET_BUCKET_QUOTA("get-bucket-quota"),
DATA_USAGE_INFO("datausageinfo"),
ADD_UPDATE_REMOVE_GROUP("update-group-members"),
GROUP_INFO("group"),
LIST_GROUPS("groups");
Expand All @@ -92,6 +95,10 @@ public String toString() {
private static final MediaType DEFAULT_MEDIA_TYPE = MediaType.parse("application/octet-stream");
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

static {
OBJECT_MAPPER.registerModule(new JavaTimeModule());
}

private String userAgent = MinioProperties.INSTANCE.getDefaultUserAgent();
private PrintWriter traceStream;

Expand Down Expand Up @@ -575,6 +582,21 @@ public void removeCannedPolicy(@Nonnull String name)
null)) {}
}

/**
* Get server/cluster data usage info
*
* @return DataUsageInfo object
* @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library.
* @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library.
* @throws IOException thrown to indicate I/O error on MinIO REST operation.
*/
public DataUsageInfo getDataUsageInfo()
throws IOException, NoSuchAlgorithmException, InvalidKeyException {
try (Response response = execute(Method.GET, Command.DATA_USAGE_INFO, null, null)) {
return OBJECT_MAPPER.readValue(response.body().bytes(), DataUsageInfo.class);
}
}

/**
* Sets HTTP connect, write and read timeouts. A value of 0 means no timeout, otherwise values
* must be between 1 and Integer.MAX_VALUE when converted to milliseconds.
Expand Down
39 changes: 39 additions & 0 deletions adminapi/src/main/java/io/minio/admin/messages/AllTierStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage,
* (C) 2022 MinIO, Inc.
*
* Licensed 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 io.minio.admin.messages;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collections;
import java.util.Map;

/**
* Collection of per-tier stats across all configured remote tiers
*
* @see <a
* href="https://github.com/minio/minio/blob/master/cmd/data-usage-cache.go#L63">data-usage-cache.go</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class AllTierStats {
@JsonProperty("Tiers")
private Map<String, TierStats> tiers;

public Map<String, TierStats> tiers() {
return Collections.unmodifiableMap(this.tiers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage,
* (C) 2022 MinIO, Inc.
*
* Licensed 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 io.minio.admin.messages;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Represents bucket replica stats of the current object APi.
*
* @see <a
* href="https://github.com/minio/minio/blob/master/cmd/data-usage-utils.go#L34">data-usage-utils.go</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class BucketTargetUsageInfo {
@JsonProperty("objectsPendingReplicationTotalSize")
private long objectsPendingReplicationTotalSize;

@JsonProperty("objectsFailedReplicationTotalSize")
private long objectsFailedReplicationTotalSize;

@JsonProperty("objectsReplicatedTotalSize")
private long objectsReplicatedTotalSize;

@JsonProperty("objectReplicaTotalSize")
private long objectReplicaTotalSize;

@JsonProperty("objectsPendingReplicationCount")
private long objectsPendingReplicationCount;

@JsonProperty("objectsFailedReplicationCount")
private long objectsFailedReplicationCount;

public long objectsPendingReplicationTotalSize() {
return objectsPendingReplicationTotalSize;
}

public long objectsFailedReplicationTotalSize() {
return objectsFailedReplicationTotalSize;
}

public long objectsReplicatedTotalSize() {
return objectsReplicatedTotalSize;
}

public long objectReplicaTotalSize() {
return objectReplicaTotalSize;
}

public long objectsPendingReplicationCount() {
return objectsPendingReplicationCount;
}

public long objectsFailedReplicationCount() {
return objectsFailedReplicationCount;
}
}
109 changes: 109 additions & 0 deletions adminapi/src/main/java/io/minio/admin/messages/BucketUsageInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage,
* (C) 2022 MinIO, Inc.
*
* Licensed 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 io.minio.admin.messages;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collections;
import java.util.Map;

/**
* Represents bucket usage stats of the current object APi.
*
* @see <a
* href="https://github.com/minio/minio/blob/master/cmd/data-usage-utils.go#L47">data-usage-utils.go</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class BucketUsageInfo {
@JsonProperty("size")
private long size;

@JsonProperty("objectsPendingReplicationTotalSize")
private long objectsPendingReplicationTotalSize;

@JsonProperty("objectsFailedReplicationTotalSize")
private long objectsFailedReplicationTotalSize;

@JsonProperty("objectsReplicatedTotalSize")
private long objectsReplicatedTotalSize;

@JsonProperty("objectsPendingReplicationCount")
private long objectsPendingReplicationCount;

@JsonProperty("objectsFailedReplicationCount")
private long objectsFailedReplicationCount;

@JsonProperty("objectsCount")
private long objectsCount;

@JsonProperty("objectsSizesHistogram")
private Map<String, Long> objectsSizesHistogram;

@JsonProperty("versionsCount")
private long versionsCount;

@JsonProperty("objectReplicaTotalSize")
private long objectReplicaTotalSize;

@JsonProperty("objectsReplicationInfo")
private Map<String, BucketTargetUsageInfo> objectsReplicationInfo;

public long size() {
return size;
}

public long objectsPendingReplicationTotalSize() {
return objectsPendingReplicationTotalSize;
}

public long objectsFailedReplicationTotalSize() {
return objectsFailedReplicationTotalSize;
}

public long objectsReplicatedTotalSize() {
return objectsReplicatedTotalSize;
}

public long objectsPendingReplicationCount() {
return objectsPendingReplicationCount;
}

public long objectsFailedReplicationCount() {
return objectsFailedReplicationCount;
}

public long objectsCount() {
return objectsCount;
}

public Map<String, Long> objectsSizesHistogram() {
return Collections.unmodifiableMap(this.objectsSizesHistogram);
}

public long versionsCount() {
return versionsCount;
}

public long objectReplicaTotalSize() {
return objectReplicaTotalSize;
}

public Map<String, BucketTargetUsageInfo> objectsReplicationInfo() {
return Collections.unmodifiableMap(this.objectsReplicationInfo);
}
}
97 changes: 97 additions & 0 deletions adminapi/src/main/java/io/minio/admin/messages/DataUsageInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage,
* (C) 2022 MinIO, Inc.
*
* Licensed 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 io.minio.admin.messages;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.Map;

/**
* Represents data usage stats of the current object APi.
*
* @see <a
* href="https://github.com/minio/minio/blob/master/cmd/data-usage-utils.go#L69">data-usage-utils.go</a>
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DataUsageInfo {

@JsonProperty("lastUpdate")
private ZonedDateTime lastUpdate;

@JsonProperty("objectsCount")
private long objectsCount;

@JsonProperty("versionsCount")
private long versionsCount;

@JsonProperty("objectsTotalSize")
private long objectsTotalSize;

@JsonProperty("objectsReplicationInfo")
private Map<String, BucketTargetUsageInfo> objectsReplicationInfo;

@JsonProperty("bucketsCount")
private long bucketsCount;

@JsonProperty("bucketsUsageInfo")
private Map<String, BucketUsageInfo> bucketsUsageInfo;

@JsonProperty("bucketsSizes")
private Map<String, Long> bucketsSizes;

@JsonProperty("tierStats")
private AllTierStats tierStats;

public ZonedDateTime lastUpdate() {
return lastUpdate;
}

public long objectsCount() {
return objectsCount;
}

public long versionsCount() {
return versionsCount;
}

public long objectsTotalSize() {
return objectsTotalSize;
}

public Map<String, BucketTargetUsageInfo> objectsReplicationInfo() {
return Collections.unmodifiableMap(this.objectsReplicationInfo);
}

public long bucketsCount() {
return bucketsCount;
}

public Map<String, BucketUsageInfo> bucketsUsageInfo() {
return Collections.unmodifiableMap(this.bucketsUsageInfo);
}

public Map<String, Long> bucketsSizes() {
return bucketsSizes;
}

public AllTierStats tierStats() {
return tierStats;
}
}
Loading

0 comments on commit 3a87a2a

Please sign in to comment.