Skip to content

Commit

Permalink
Add an option to remove hash rate history when removing a pool (on the
Browse files Browse the repository at this point in the history
confirmation window)
  • Loading branch information
Stratehm committed Aug 26, 2014
1 parent 759a02c commit e48bf78
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashrateModel> 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<HashrateModel> hashrates = getUserHashrate(username);
if (hashrates != null) {
for (HashrateModel model : hashrates) {
userDatabase.delete(model);
}
}

userDatabase.commit();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
5 changes: 3 additions & 2 deletions src/main/resources/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ <h3 class="panel-title"></h3>
</div>
</div>

<div id="confirmationModal"
<div id="poolRemoveConfirmationModal"
class="modal fade bs-example-modal-sm removePoolConfirmation"
tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm">
Expand All @@ -289,7 +289,8 @@ <h4 class="modal-title"></h4>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default yesButton">Yes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
<button type="button" class="btn btn-default noButton">No</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit e48bf78

Please sign in to comment.