Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DURACLOUD-1279: Adds snapshot totals information to the UI, companion PR to DURACLOUD-1150 #152

Merged
merged 4 commits into from
Nov 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ public String getSnapshotList(@PathVariable("storeId") String storeId) {
}
}

@RequestMapping(value = "/spaces/snapshots/totals/{storeId}", method = RequestMethod.GET)
@ResponseBody
public String getSnapshotTotals(@PathVariable("storeId") String storeId,
@RequestParam(value = "status", required = false) String status) {
try {
return getTaskClient(storeId).getSnapshotsTotals(status).serialize();
} catch (ContentStoreException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}

@RequestMapping(value = "/spaces/snapshots/{storeId}/{snapshotId:.+}", method = RequestMethod.GET)
@ResponseBody
public String getSnapshot(@PathVariable("storeId") String storeId,
Expand Down
11 changes: 10 additions & 1 deletion duradmin/src/main/webapp/jquery/dc/api/durastore-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,16 @@ var dc;
type: "get",
});
};


dc.store.GetSnapshotTotals = function(storeId, status) {
return dc.ajax2({
url: "/duradmin/spaces/snapshots/totals/" + storeId + "?status=" + status,
async: true,
dataType: 'json',
type: "get",
});
};

dc.store.GetSnapshot = function(params){

return dc.ajax2({
Expand Down
34 changes: 34 additions & 0 deletions duradmin/src/main/webapp/js/spaces-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2979,6 +2979,12 @@ $(function() {
this._storeId = storeId;

if (this._isAdmin()) {
if (this._isSnapshot(storeId)) {
var totalsDiv = $.fn.create("div").addClass("totals-table");
this._appendToCenter(totalsDiv);
this._loadSnapshotsTotals(totalsDiv);
}

var history = $.fn.create("div");
this._appendToCenter(history);
history.historypanel({
Expand All @@ -2987,6 +2993,34 @@ $(function() {
}

},

_loadSnapshotsTotals : function(totalsDiv) {
$.when(this._getTotals()).done(function(result) {
var totals = result;

var props = [];

props.push([ 'Snapshots', totals.totalCount ]);

size_formatted = dc.formatBytes(totals.totalSize, true);
props.push([ 'Size', size_formatted ]);

props.push([ 'Files', totals.totalFiles ]);

totalsDiv.tabularexpandopanel({
title : "Snapshot Totals",
data : props
});
}).fail(function(err){
alert("Failed to retrieve snapshot totals.");
});
},

_getTotals: function() {
return dc.store.GetSnapshotTotals(
this._storeId,
'SNAPSHOT_COMPLETE');
},
}));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private SnapshotConstants() {
public static final String CLEANUP_SNAPSHOT_TASK_NAME = "cleanup-snapshot";
public static final String COMPLETE_SNAPSHOT_TASK_NAME = "complete-snapshot";
public static final String GET_SNAPSHOTS_TASK_NAME = "get-snapshots";
public static final String GET_SNAPSHOTS_TOTALS_TASK_NAME = "get-snapshots-totals";

public static final String GET_SNAPSHOT_TASK_NAME = "get-snapshot";
public static final String GET_SNAPSHOT_CONTENTS_TASK_NAME = "get-snapshot-contents";
public static final String GET_SNAPSHOT_HISTORY_TASK_NAME = "get-snapshot-history";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://duracloud.org/license/
*/
package org.duracloud.snapshot.dto.task;

import java.io.IOException;
import javax.xml.bind.annotation.XmlValue;

import org.duracloud.common.json.JaxbJsonSerializer;
import org.duracloud.snapshot.dto.BaseDTO;
import org.duracloud.snapshot.error.SnapshotDataException;

/**
* @author Nicholas Woodward
* Date: 7/26/21
*/
public class GetSnapshotsTotalsTaskParameters extends BaseDTO {

@XmlValue
private String status;

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

/**
* Creates a serialized version of task parameters
*
* @return JSON formatted task result info
*/
public String serialize() {
JaxbJsonSerializer<GetSnapshotsTotalsTaskParameters> serializer =
new JaxbJsonSerializer<>(GetSnapshotsTotalsTaskParameters.class);
try {
return serializer.serialize(this);
} catch (IOException e) {
throw new SnapshotDataException(
"Unable to create task parameters due to: " + e.getMessage());
}
}

/**
* Parses properties from task parameter string
*
* @param taskParameters - JSON formatted set of parameters
*/
public static GetSnapshotsTotalsTaskParameters deserialize(String taskParameters) {
JaxbJsonSerializer<GetSnapshotsTotalsTaskParameters> serializer =
new JaxbJsonSerializer<>(GetSnapshotsTotalsTaskParameters.class);
try {
GetSnapshotsTotalsTaskParameters params =
serializer.deserialize(taskParameters);
// Verify expected parameters
if (null == params.getStatus() || params.getStatus().isEmpty()) {
throw new SnapshotDataException("Task parameter values may not be empty");
}
return params;
} catch (IOException e) {
throw new SnapshotDataException(
"Unable to parse task parameters due to: " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://duracloud.org/license/
*/
package org.duracloud.snapshot.dto.task;

import java.io.IOException;

import org.duracloud.common.json.JaxbJsonSerializer;
import org.duracloud.snapshot.dto.bridge.GetSnapshotTotalsBridgeResult;
import org.duracloud.snapshot.error.SnapshotDataException;

/**
* @author Nicholas Woodward
* Date: 7/26/21
*/
public class GetSnapshotsTotalsTaskResult extends GetSnapshotTotalsBridgeResult {

public GetSnapshotsTotalsTaskResult() {
}

public GetSnapshotsTotalsTaskResult(Long totalCount, Long totalSize, Long totalFiles) {
super(totalCount, totalSize, totalFiles);
}

/**
* Parses properties from task result
*
* @param taskResult - JSON formatted set of properties
*/
public static GetSnapshotsTotalsTaskResult deserialize(String taskResult) {
JaxbJsonSerializer<GetSnapshotsTotalsTaskResult> serializer =
new JaxbJsonSerializer<>(GetSnapshotsTotalsTaskResult.class);
try {
return serializer.deserialize(taskResult);
} catch (IOException e) {
throw new SnapshotDataException(
"Unable to create task result due to: " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.duracloud.snapshottask.snapshot.GetSnapshotHistoryTaskRunner;
import org.duracloud.snapshottask.snapshot.GetSnapshotTaskRunner;
import org.duracloud.snapshottask.snapshot.GetSnapshotsTaskRunner;
import org.duracloud.snapshottask.snapshot.GetSnapshotsTotalsTaskRunner;
import org.duracloud.snapshottask.snapshot.RequestRestoreSnapshotTaskRunner;
import org.duracloud.snapshottask.snapshot.RestartSnapshotTaskRunner;
import org.duracloud.snapshottask.snapshot.RestoreSnapshotTaskRunner;
Expand Down Expand Up @@ -84,6 +85,13 @@ public SnapshotTaskProvider(StorageProvider snapshotProvider,
bridgeUser,
bridgePass,
snapshotProvider));
taskList.add(new GetSnapshotsTotalsTaskRunner(dcHost,
dcStoreId,
bridgeHost,
bridgePort,
bridgeUser,
bridgePass,
snapshotProvider));
taskList.add(new GetSnapshotContentsTaskRunner(bridgeHost,
bridgePort,
bridgeUser,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://duracloud.org/license/
*/
package org.duracloud.snapshottask.snapshot;

import java.text.MessageFormat;

import org.duracloud.common.web.RestHttpHelper;
import org.duracloud.snapshot.SnapshotConstants;
import org.duracloud.snapshot.dto.task.GetSnapshotsTotalsTaskParameters;
import org.duracloud.storage.error.TaskException;
import org.duracloud.storage.provider.StorageProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Get total count, size and files of snapshots which are accessible to this account.
*
* @author Nicholas Woodward
* Date: 8/2/21
*/
public class GetSnapshotsTotalsTaskRunner extends AbstractSnapshotTaskRunner {

private Logger log = LoggerFactory.getLogger(GetSnapshotsTotalsTaskRunner.class);

private String dcHost;
private String dcStoreId;
private StorageProvider storageProvider;

public GetSnapshotsTotalsTaskRunner(String dcHost,
String dcStoreId,
String bridgeAppHost,
String bridgeAppPort,
String bridgeAppUser,
String bridgeAppPass,
StorageProvider storageProvider) {
super(bridgeAppHost, bridgeAppPort, bridgeAppUser, bridgeAppPass);
this.dcHost = dcHost;
this.dcStoreId = dcStoreId;
this.storageProvider = storageProvider;
}

@Override
public String getName() {
return SnapshotConstants.GET_SNAPSHOTS_TOTALS_TASK_NAME;
}

@Override
public String performTask(String taskParameters) {
GetSnapshotsTotalsTaskParameters taskParams =
GetSnapshotsTotalsTaskParameters.deserialize(taskParameters);

// get bridge results
String result = callBridge(createRestHelper(), buildBridgeURL(taskParams));

return result;
}

/*
* Create URL to call bridge app
*/
protected String buildBridgeURL(GetSnapshotsTotalsTaskParameters taskParams) {
String status = taskParams.getStatus();

return MessageFormat.format("{0}/snapshot/total?host={1}&storeId={2}&status={3}",
buildBridgeBaseURL(),
dcHost,
dcStoreId,
status);
}

/*
* Calls the bridge application to get snapshot listing
*/
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) {
log.info("Making bridge call to get total count, size, and files of snapshots. URL: {}", bridgeURL);

try {
RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL);
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new RuntimeException("Unexpected response code: " +
statusCode);
}
return response.getResponseBody();
} catch (Exception e) {
throw new TaskException("Exception encountered attempting to " +
"get total count, size, and files of snapshots. " +
"Error reported: " + e.getMessage(), e);
}
}

}