Skip to content
Merged
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
Expand Up @@ -58,6 +58,6 @@
</li>
<li ng-show="$ctrl.iostatus"><a ng-href="{{$ctrl.ioLinkHref}}">IO Status</a></li>
<li ng-show="$ctrl.scanner"><a ng-href="{{$ctrl.scannerLinkHref}}">Data Scanner</a></li>
<li ng-show="$ctrl.snapshot"><a ng-href="{{$ctrl.snapshotLinkHref}}">Ozone Snapshot</a></li>
<li ng-show="$ctrl.snapshot"><a ng-href="{{$ctrl.snapshotLinkHref}}">Snapshots</a></li>
</ul>
</div><!--/.nav-collapse -->
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public OzoneManagerHttpServer(MutableConfigurationSource conf,
super(conf, "ozoneManager");
addServlet("serviceList", OZONE_OM_SERVICE_LIST_HTTP_ENDPOINT,
ServiceListJSONServlet.class);
addServlet("snapshotList", "/snapshotList",
SnapshotListJSONServlet.class);
addServlet("dbCheckpoint", OZONE_DB_CHECKPOINT_HTTP_ENDPOINT,
OMDBCheckpointServlet.class);
addServlet("dbCheckpointv2", OZONE_DB_CHECKPOINT_HTTP_ENDPOINT_V2,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.ozone.om;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.snapshot.ListSnapshotResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Provides REST access to Ozone Snapshot List.
*/
public class SnapshotListJSONServlet extends HttpServlet {

private static final Logger LOG =
LoggerFactory.getLogger(SnapshotListJSONServlet.class);
private static final long serialVersionUID = 1L;

private transient OzoneManager om;

/**
* Jackson mix-in to ignore protobuf getter in SnapshotInfo.
*/
@JsonIgnoreProperties({"protobuf", "createTransactionInfo", "lastTransactionInfo"})
abstract static class SnapshotInfoMixin {
}

@Override
public void init() throws ServletException {
this.om = (OzoneManager) getServletContext()
.getAttribute(OzoneConsts.OM_CONTEXT_ATTRIBUTE);
}

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
String volume = request.getParameter("volume");
String bucket = request.getParameter("bucket");

if (volume == null || volume.isEmpty() || bucket == null || bucket.isEmpty()) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().write("Both volume and bucket parameters are required.");
return;
}

String prefix = request.getParameter("prefix");

final int maxKeys = 1000;

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.addMixIn(SnapshotInfo.class, SnapshotInfoMixin.class);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
response.setContentType("application/json; charset=utf8");
try (PrintWriter writer = response.getWriter()) {
String lastSnapshot = null;
do {
ListSnapshotResponse listSnapshotResponse = om.listSnapshot(volume, bucket, prefix, lastSnapshot, maxKeys);
writer.write(objectMapper.writeValueAsString(listSnapshotResponse.getSnapshotInfos()));
lastSnapshot = listSnapshotResponse.getLastSnapshot();
} while (StringUtils.isNotEmpty(lastSnapshot));
Comment on lines +82 to +86
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still a bit concerned about this logic.

This runs on OM. If there are tons of snapshots and/or client requests this endpoint a ton of times it would consume a lot of CPU and worsen young gen churn. Potential DoS.

The ideal way is for the client (web page) to request batch of snapshot on demand. OM can return only the ones that needs to be displayed on the web UI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on-demand itself right, The OM web UI access should only be with the admin so only when admin inputs the vol/bucket it will do a list snapshot request.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sadanand48 Good point. Let's merge it first then

}
} catch (IOException e) {
LOG.error("Caught an exception while processing SnapshotList request", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} catch (Exception e) {
LOG.error("Unexpected error while processing SnapshotList request", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,59 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<h1>Snapshots</h1>
<div class="row">
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">Volume</span>
<input type="text" class="form-control" ng-model="searchVolume" placeholder="volume">
</div>
</div>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">Bucket</span>
<input type="text" class="form-control" ng-model="searchBucket" placeholder="bucket">
</div>
</div>
<div class="col-md-2">
<button class="btn btn-primary" ng-click="$ctrl.listSnapshots(searchVolume, searchBucket)" ng-disabled="!searchVolume || !searchBucket">Search</button>
</div>
</div>

<div ng-if="!searchVolume || !searchBucket" style="color: grey; margin-top: 5px;">
<i>Please enter both volume and bucket to search snapshots.</i>
</div>

<div style="margin-bottom: 20px;"></div>

<table class="table table-bordered table-striped" ng-if="$ctrl.snapshots && $ctrl.snapshots.length > 0">
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th>Creation Time</th>
<th title="Total size of all files and directories visible in this snapshot.">Referenced Size</th>
<th title="Size of data held exclusively by this snapshot. Deleting this snapshot will reclaim this much space.">Exclusive Size</th>
<th>Snapshot ID</th>
<th>Snapshot Path</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="snapshot in $ctrl.snapshots">
<td>{{snapshot.name}}</td>
<td title="{{snapshot.snapshotStatus === 'SNAPSHOT_ACTIVE' ? 'active' : 'deletion in progress'}}">
{{snapshot.snapshotStatus === 'SNAPSHOT_ACTIVE' ? 'active' : 'deletion in progress'}}
</td>
<td>{{snapshot.creationTime | date:'yyyy-MM-dd HH:mm:ss'}}</td>
<td>{{$ctrl.formatBytes(snapshot.referencedSize)}}</td>
<td>{{$ctrl.formatBytes(snapshot.exclusiveSize + snapshot.exclusiveSizeDeltaFromDirDeepCleaning)}}</td>
<td>{{snapshot.snapshotId}}</td>
<td>{{snapshot.snapshotPath}}</td>
</tr>
</tbody>
</table>

<div style="margin-bottom: 20px;"></div>

<h1>Snapshot Diff Jobs</h1>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,38 @@
var ctrl = this;
ctrl.snapshotMetrics = [];
ctrl.snapshotDiffJobs = [];
ctrl.snapshots = [];
ctrl.snapshotUsageMetrics = {
'NumSnapshotActive': 0,
'NumSnapshotDeleted': 0,
'NumSnapshotCacheSize': 0
};

ctrl.listSnapshots = function(volume, bucket) {
if (volume && bucket) {
$http.get("snapshotList?volume=" + volume + "&bucket=" + bucket)
.then(function (result) {
ctrl.snapshots = result.data;
})
.catch(function (error) {
console.error("Error fetching snapshots:", error);
ctrl.snapshots = [];
});
} else {
ctrl.snapshots = [];
}
};

ctrl.formatBytes = function(bytes, decimals) {
if (bytes == 0) return '0 Bytes';
if (!bytes) return 'N/A';
var k = 1024,
dm = decimals + 1 || 3,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}

$scope.reverse = false;
$scope.columnName = "jobId";
let snapDiffJobsCopy = [];
Expand All @@ -57,6 +84,11 @@
ctrl.snapshotUsageMetrics.NumSnapshotActive = metrics.NumSnapshotActive || 0;
ctrl.snapshotUsageMetrics.NumSnapshotDeleted = metrics.NumSnapshotDeleted || 0;
ctrl.snapshotUsageMetrics.NumSnapshotCacheSize = metrics.NumSnapshotCacheSize || 0;
for (var key in metrics) {
if (key.match(/NumSnapshot|NumCancelSnapshotDiff|NumListSnapshotDiffJob/)) {
ctrl.snapshotMetrics.push({key: key, value: metrics[key]});
}
}
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.ozone.om;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Collections;
import java.util.UUID;
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.util.Time;
import org.junit.jupiter.api.Test;

/**
* Test for SnapshotListJSONServlet.
*/
public class TestSnapshotListJSONServlet {

@Test
public void testSerialization() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.addMixIn(SnapshotInfo.class,
SnapshotListJSONServlet.SnapshotInfoMixin.class);

String snapName = "snap1";
SnapshotInfo snapshotInfo = SnapshotInfo.newInstance("vol1", "bucket1",
snapName, UUID.randomUUID(), Time.now());

String json = assertDoesNotThrow(() ->
objectMapper.writeValueAsString(Collections.singletonList(snapshotInfo)));

// Verify that the problematic fields are NOT in the JSON
assertFalse(json.contains("protobuf"), "JSON should not contain protobuf field");
assertFalse(json.contains("createTransactionInfo"), "JSON should not contain createTransactionInfo field");
assertFalse(json.contains("lastTransactionInfo"), "JSON should not contain lastTransactionInfo field");

// Verify that the expected fields ARE in the JSON
assertTrue(json.contains("\"name\":\"" + snapName + "\""), "JSON should contain snapshot name");
}
}