From e48bf78eeb8559eede550e94b57f45825e8a1a3b Mon Sep 17 00:00:00 2001 From: Stratehm Date: Tue, 26 Aug 2014 21:02:16 +0200 Subject: [PATCH] Add an option to remove hash rate history when removing a pool (on the confirmation window) --- .../proxy/database/DatabaseManager.java | 32 +++ .../stratum/proxy/manager/ProxyManager.java | 8 +- .../stratum/proxy/rest/ProxyResources.java | 5 +- .../stratum/proxy/rest/dto/RemovePoolDTO.java | 27 +++ src/main/resources/webapp/index.html | 5 +- .../webapp/js/stratum-proxy-client.js | 193 ++++++++++-------- 6 files changed, 178 insertions(+), 92 deletions(-) create mode 100644 src/main/java/strat/mining/stratum/proxy/rest/dto/RemovePoolDTO.java diff --git a/src/main/java/strat/mining/stratum/proxy/database/DatabaseManager.java b/src/main/java/strat/mining/stratum/proxy/database/DatabaseManager.java index 0959a15..f8e87b7 100644 --- a/src/main/java/strat/mining/stratum/proxy/database/DatabaseManager.java +++ b/src/main/java/strat/mining/stratum/proxy/database/DatabaseManager.java @@ -220,4 +220,36 @@ private void removeNeodatisFiles(File databaseDirectory) { } } + /** + * Remove all entries for the pool with the given host + * + * @param host + */ + public void deletePool(String host) { + List hashrates = getPoolHashrate(host); + if (hashrates != null) { + for (HashrateModel model : hashrates) { + poolDatabase.delete(model); + } + } + + poolDatabase.commit(); + } + + /** + * Remove all entries for the user with the given name + * + * @param host + */ + public void deleteUser(String username) { + List hashrates = getUserHashrate(username); + if (hashrates != null) { + for (HashrateModel model : hashrates) { + userDatabase.delete(model); + } + } + + userDatabase.commit(); + } + } diff --git a/src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java b/src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java index f195c91..e83470b 100644 --- a/src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java +++ b/src/main/java/strat/mining/stratum/proxy/manager/ProxyManager.java @@ -42,6 +42,7 @@ import strat.mining.stratum.proxy.callback.ResponseReceivedCallback; import strat.mining.stratum.proxy.configuration.ConfigurationManager; import strat.mining.stratum.proxy.constant.Constants; +import strat.mining.stratum.proxy.database.DatabaseManager; import strat.mining.stratum.proxy.exception.AuthorizationException; import strat.mining.stratum.proxy.exception.BadParameterException; import strat.mining.stratum.proxy.exception.ChangeExtranonceNotSupportedException; @@ -682,7 +683,7 @@ public Pool addPool(AddPoolDTO addPoolDTO) throws BadParameterException, SocketE * @param poolName * @throws NoPoolAvailableException */ - public void removePool(String poolName) throws NoPoolAvailableException { + public void removePool(String poolName, Boolean keepHistory) throws NoPoolAvailableException { Pool pool = getPool(poolName); if (pool == null) { throw new NoPoolAvailableException("Pool with name " + poolName + " is not found"); @@ -696,6 +697,11 @@ public void removePool(String poolName) throws NoPoolAvailableException { poolWorkerConnections.remove(pool); LOGGER.info("Pool {} removed.", poolName); + + // Remove the history if requested + if (keepHistory != null && !keepHistory) { + DatabaseManager.getInstance().deletePool(pool.getHost()); + } } /** diff --git a/src/main/java/strat/mining/stratum/proxy/rest/ProxyResources.java b/src/main/java/strat/mining/stratum/proxy/rest/ProxyResources.java index 1555456..df789ee 100644 --- a/src/main/java/strat/mining/stratum/proxy/rest/ProxyResources.java +++ b/src/main/java/strat/mining/stratum/proxy/rest/ProxyResources.java @@ -58,6 +58,7 @@ import strat.mining.stratum.proxy.rest.dto.LogLevelDTO; import strat.mining.stratum.proxy.rest.dto.PoolDetailsDTO; import strat.mining.stratum.proxy.rest.dto.PoolNameDTO; +import strat.mining.stratum.proxy.rest.dto.RemovePoolDTO; import strat.mining.stratum.proxy.rest.dto.StatusDTO; import strat.mining.stratum.proxy.rest.dto.TimestampDTO; import strat.mining.stratum.proxy.rest.dto.UpdatePoolDTO; @@ -397,13 +398,13 @@ public Response addPool(AddPoolDTO addPoolDTO) { */ @POST @Path("pool/remove") - public Response removePool(PoolNameDTO poolName) { + public Response removePool(RemovePoolDTO dto) { Response response = null; StatusDTO status = new StatusDTO(); try { - stratumProxyManager.removePool(poolName.getPoolName()); + stratumProxyManager.removePool(dto.getPoolName(), dto.getKeepHistory()); status.setStatus(StatusDTO.DONE_STATUS); response = Response.status(Response.Status.OK).entity(status).build(); diff --git a/src/main/java/strat/mining/stratum/proxy/rest/dto/RemovePoolDTO.java b/src/main/java/strat/mining/stratum/proxy/rest/dto/RemovePoolDTO.java new file mode 100644 index 0000000..f6c9e58 --- /dev/null +++ b/src/main/java/strat/mining/stratum/proxy/rest/dto/RemovePoolDTO.java @@ -0,0 +1,27 @@ +package strat.mining.stratum.proxy.rest.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class RemovePoolDTO { + + private String poolName; + private Boolean keepHistory; + + public String getPoolName() { + return poolName; + } + + public void setPoolName(String poolName) { + this.poolName = poolName; + } + + public Boolean getKeepHistory() { + return keepHistory; + } + + public void setKeepHistory(Boolean keepHistory) { + this.keepHistory = keepHistory; + } + +} diff --git a/src/main/resources/webapp/index.html b/src/main/resources/webapp/index.html index 125385a..79a3a3b 100644 --- a/src/main/resources/webapp/index.html +++ b/src/main/resources/webapp/index.html @@ -275,7 +275,7 @@

- diff --git a/src/main/resources/webapp/js/stratum-proxy-client.js b/src/main/resources/webapp/js/stratum-proxy-client.js index 1770a82..a29a124 100644 --- a/src/main/resources/webapp/js/stratum-proxy-client.js +++ b/src/main/resources/webapp/js/stratum-proxy-client.js @@ -281,7 +281,7 @@ PoolsPageController.prototype.openEditPool = function(poolName) { weight : weight, enableExtranonceSubscribe : enableExtranonceSubscribe, appendWorkerNames : appendWorkerNames, - workerNameSeparator: workerNameSeparator, + workerNameSeparator : workerNameSeparator, useWorkerPassword : useWorkerPassword }), contentType : "application/json", @@ -368,41 +368,50 @@ PoolsPageController.prototype.setPoolEnabled = function(poolName, isEnabled) { * Remove the pool with the given name. Ask a confirmation. */ PoolsPageController.prototype.removePool = function(poolName) { - var modal = $('#confirmationModal').modal({ + var modal = $('#poolRemoveConfirmationModal').modal({ keyboard : true, backdrop : true - }), controller = this; - modal.find('.modal-title').text('Confirmation'); + }), controller = this, removePoolFunction; + modal.find('.modal-title').text('Keep history confirmation'); modal.find('.modal-body').text( - 'Do you really want to remove the pool ' + poolName + ' ?'); - modal.find('.yesButton').off('click').click( - function() { - modal.modal('hide'); - $.ajax({ - url : '/proxy/pool/remove', - dataType : "json", - type : "POST", - data : JSON.stringify({ - poolName : poolName, - }), - contentType : "application/json", - success : function(data) { - // When priority is set, refresh the list. - if (data.status != 'Done') { - window.alert('Failed to remove the pool. Message: ' - + data.message); - } else { - controller.refresh(); - } - }, - error : function(request, textStatus, errorThrown) { - var jsonObject = JSON.parse(request.responseText); - window.alert('Failed remove the pool. Status: ' - + textStatus + ', error: ' + errorThrown - + ', message: ' + jsonObject.message); - } - }); - }); + 'Do you want to keep the hash rate history for ' + poolName + ' ?'); + + removePoolFunction = function(keepHistory) { + modal.modal('hide'); + $.ajax({ + url : '/proxy/pool/remove', + dataType : "json", + type : "POST", + data : JSON.stringify({ + poolName : poolName, + keepHistory: keepHistory + }), + contentType : "application/json", + success : function(data) { + // When priority is set, refresh the list. + if (data.status != 'Done') { + window.alert('Failed to remove the pool. Message: ' + + data.message); + } else { + controller.refresh(); + } + }, + error : function(request, textStatus, errorThrown) { + var jsonObject = JSON.parse(request.responseText); + window.alert('Failed remove the pool. Status: ' + textStatus + + ', error: ' + errorThrown + ', message: ' + + jsonObject.message); + } + }); + }; + + modal.find('.yesButton').off('click').click(function() { + removePoolFunction(true); + }); + + modal.find('.noButton').off('click').click(function() { + removePoolFunction(false); + }); }; /** @@ -564,10 +573,6 @@ PoolsPageController.prototype.openAddPool = function() { }); }; - - - - /* * Controller of the logs page. */ @@ -735,8 +740,6 @@ LogsPageController.prototype.stopAutoRefresh = function() { } }; - - /* * Define the Users page controller */ @@ -794,12 +797,12 @@ UsersPageController.prototype.addUserInPage = function(user) { // Initialize all buttons handlers -//TODO -// item.getEnableDisableButton().click( -// function() { -// controller.setPoolEnabled(pool.name, item -// .getEnableDisableButton().text() == 'Enable'); -// }); + // TODO + // item.getEnableDisableButton().click( + // function() { + // controller.setPoolEnabled(pool.name, item + // .getEnableDisableButton().text() == 'Enable'); + // }); }; UsersPageController.prototype.getUserItemFromName = function(userName) { @@ -849,28 +852,32 @@ UsersPageController.prototype.refresh = function(onSuccess) { controller.items.removeItem(userItem); } }); - - // Once all users are present, sort them based on their names and if they are active. + + // Once all users are present, sort them based on their names and if + // they are active. controller.containerJquery.find('.userItemContainer > .userItem') - .sort(function(a, b) { - var result = 0; - if($(a).data('isActive') && !$(b).data('isActive')) { - result = -1; - } else if(!$(a).data('isActive') && $(b).data('isActive')) { - result = 1; - } else { - if($(a).data('name') < $(b).data('name')) { - result = -1; - } else if($(a).data('name') > $(b).data('name')){ - result = 1; - } else { - result = 0; - } - } - - - return result; - }); + .sort( + function(a, b) { + var result = 0; + if ($(a).data('isActive') + && !$(b).data('isActive')) { + result = -1; + } else if (!$(a).data('isActive') + && $(b).data('isActive')) { + result = 1; + } else { + if ($(a).data('name') < $(b).data('name')) { + result = -1; + } else if ($(a).data('name') > $(b).data( + 'name')) { + result = 1; + } else { + result = 0; + } + } + + return result; + }); controller.setIsRefreshing(false); @@ -965,7 +972,6 @@ UsersPageController.prototype.stopAutoRefresh = function() { autoRefreshCountDown.text('Auto refresh in -- seconds.'); }; - /* * Define a pool item linked to a view */ @@ -978,12 +984,16 @@ PoolItem.prototype.setPool = function(pool) { this.updatePool(pool); // Initialize a tooltip when the text overflows - this.poolItemJquery.find('.tooltipOnOverflow').bind('mouseenter', function() { - var $this = $(this); - if (this.offsetWidth < this.scrollWidth && !$this.attr('title')) { - $this.attr('title', $this.text()); - } - }); + this.poolItemJquery.find('.tooltipOnOverflow') + .bind( + 'mouseenter', + function() { + var $this = $(this); + if (this.offsetWidth < this.scrollWidth + && !$this.attr('title')) { + $this.attr('title', $this.text()); + } + }); // Reload the data of the chart this.reloadChartData(false); @@ -1146,7 +1156,7 @@ PoolItem.prototype.updatePool = function(pool) { this.poolItemJquery.find('.lastStopDateValue').text( pool.lastStopDate != undefined ? pool.lastStopDate : "Never stopped"); - + this.poolItemJquery.find('.appendWorkersNamesValue').text( pool.appendWorkerNames); this.poolItemJquery.find('.workerNameSeparatorValue').text( @@ -1310,7 +1320,6 @@ PoolItem.prototype.updateHashrateChartData = function(hashrates) { } }; - /* * Define a pool item linked to a view */ @@ -1323,12 +1332,16 @@ UserItem.prototype.setUser = function(user) { this.updateUser(user); // Initialize a tooltip when the text overflows - this.userItemJquery.find('.tooltipOnOverflow').bind('mouseenter', function() { - var $this = $(this); - if (this.offsetWidth < this.scrollWidth && !$this.attr('title')) { - $this.attr('title', $this.text()); - } - }); + this.userItemJquery.find('.tooltipOnOverflow') + .bind( + 'mouseenter', + function() { + var $this = $(this); + if (this.offsetWidth < this.scrollWidth + && !$this.attr('title')) { + $this.attr('title', $this.text()); + } + }); // Reload the data of the chart this.reloadChartData(false); @@ -1445,12 +1458,18 @@ UserItem.prototype.updateUser = function(user) { this.user = user; this.userItemJquery.find('.panel-title').text(user.name); - this.userItemJquery.find('.firstConnectionDateValue').text(user.firstConnectionDate != undefined ? user.firstConnectionDate : "Never"); - this.userItemJquery.find('.lastShareSubmittedValue').text(user.lastShareSubmitted != undefined ? user.lastShareSubmitted : "Never"); - this.userItemJquery.find('.acceptedHashrateValue').text(user.acceptedHashesPerSeconds); - this.userItemJquery.find('.rejectedHashrateValue').text(user.rejectedHashesPerSeconds); - this.userItemJquery.find('.numberOfConnectionsValue').text(user.connections.length); - + this.userItemJquery.find('.firstConnectionDateValue').text( + user.firstConnectionDate != undefined ? user.firstConnectionDate + : "Never"); + this.userItemJquery.find('.lastShareSubmittedValue').text( + user.lastShareSubmitted != undefined ? user.lastShareSubmitted + : "Never"); + this.userItemJquery.find('.acceptedHashrateValue').text( + user.acceptedHashesPerSeconds); + this.userItemJquery.find('.rejectedHashrateValue').text( + user.rejectedHashesPerSeconds); + this.userItemJquery.find('.numberOfConnectionsValue').text( + user.connections.length); // Apply the color of the panel header based on the user status // By default, the color is white (panel-default). This color is the