Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
minor changes and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pdmars authored and labisso committed Oct 23, 2010
1 parent e7e3fdb commit 0a1ef4a
Showing 1 changed file with 67 additions and 27 deletions.
94 changes: 67 additions & 27 deletions service/service/java/source/src/org/globus/workspace/Backfill.java
Expand Up @@ -181,12 +181,6 @@ public void setDelegatingManager(DelegatingManager manager) {
this.manager = manager;
}

public void cancelBackfillRequest() {
logger.info("Cancelling backfill request");
this.backfillTimer.cancel();
this.backfillReqFile.delete();
}

/**
* This method should be called on service startup. It is responsible for
* starting the backfill timer (if the backfill feature is enabled).
Expand All @@ -196,14 +190,15 @@ public void cancelBackfillRequest() {
* changed then it cancels the previous backfill request and submits a new
* one.
*/
public void initiateBackfill() throws Exception {
public void initiateBackfill() {

if (this.backfillDisabled == false) {
logger.debug("Backfill is enabled");

if (this.backfillReqFile.exists()) {
String curBackfillStr = buildCurBackfillReqStrB().toString();
String prevBackfillStr = readPrevBackfillReqStrB().toString();

if ((curBackfillStr.compareTo(prevBackfillStr)) == 0) {
logger.debug("Current and previous backfill requests " +
"match");
Expand All @@ -213,12 +208,17 @@ public void initiateBackfill() throws Exception {

this.cancelBackfillRequest();
this.writeCurBackfillReq();

logger.debug("New backfill request file written.");
}
} else {
this.writeCurBackfillReq();
}

logger.debug("Launching backfill timer.");
this.launchBackfillTimer();
logger.debug("Backfill timer launched.");

} else {
logger.info("Backfill is disabled");
}
Expand All @@ -233,6 +233,7 @@ public void launchBackfillTimer() {
if (this.backfillTimer != null) {
this.backfillTimer.cancel();
}

BackfillTimer backfillTimer;
backfillTimer = new BackfillTimer(this);
Date backfillStart = new Date();
Expand All @@ -241,8 +242,27 @@ public void launchBackfillTimer() {
this.retryPeriod * 1000);
}

// Returns true if a backfill node was successfully killed.
// False, if it wasn't able to kill a backfill node.
public void cancelBackfillRequest() {
logger.info("Cancelling backfill request");

try {
this.backfillTimer.cancel();
} catch (Exception e) {
logger.debug("Failed to kill backfill timer, error: " +
e.getMessage());
}

try {
this.backfillReqFile.delete();
} catch (Exception e) {
logger.debug("Problem deleting backfill request file: " +
e.getMessage());
}

logger.debug("Backfill request cancelled.");
}

// Returns the number of nodes successfully terminated
public int terminateBackfillNode(int numNodes) {

int vmid;
Expand All @@ -258,18 +278,23 @@ public int terminateBackfillNode(int numNodes) {
vmid = this.slotManager.getMostRecentBackfillVMID();
}

String vmidStr = Integer.toString(vmid);
logger.debug("Terminating backfill node with ID: " + vmidStr);

Caller caller = this.getBackfillCaller();
try {
this.manager.trash(vmidStr, 0, caller);
this.subCurInstances(1);
successfulTerminations += 1;
} catch (Exception e) {
logger.error("Problem terminating backfill node: " +
e.getMessage());
if (vmid != -1) {
String vmidStr = Integer.toString(vmid);
logger.debug("Terminating backfill node with ID: " + vmidStr);

Caller caller = this.getBackfillCaller();
try {
this.manager.trash(vmidStr, 0, caller);
this.subCurInstances(1);
successfulTerminations += 1;
} catch (Exception e) {
logger.error("Problem terminating backfill node: " +
e.getMessage());
}
} else {
logger.debug("No backfill VM to terminate");
}

count += 1;
}

Expand Down Expand Up @@ -305,29 +330,39 @@ public void createBackfillNode() throws Exception {
* obsolete once the backfill feature is integrated with support for Spot
* Instances.
*/
private void writeCurBackfillReq() throws Exception {
private void writeCurBackfillReq() {

if (this.backfillReqFile.exists()) {
logger.debug("Backfill request file already exists");
logger.debug("Skipping write to backfill request file");
} else {
logger.debug("Attempting to write backfill file:\n" +
this.backfillReqFile.toString());
this.backfillReqFile.createNewFile();
FileWriter backfillFW = new FileWriter(this.backfillReqFile);
BufferedWriter backfillBW = new BufferedWriter(backfillFW);
backfillBW.write(this.buildCurBackfillReqStrB().toString());
backfillBW.close();

try {
FileWriter backfillFW = new FileWriter(this.backfillReqFile);
BufferedWriter backfillBW = new BufferedWriter(backfillFW);

this.backfillReqFile.createNewFile();

backfillBW.write(this.buildCurBackfillReqStrB().toString());

backfillBW.close();
} catch (Exception e) {
logger.debug("Error creating and writing a new backfill " +
"request file: " + e.getMessage());
}
}
}

private StringBuilder readPrevBackfillReqStrB() throws Exception {
private StringBuilder readPrevBackfillReqStrB() {

StringBuilder prevBackfillStrB = new StringBuilder();

try {
logger.debug("Attempting to read backfill request file:\n" +
this.backfillReqFile.toString());

FileReader backfillFR = new FileReader(this.backfillReqFile);
BufferedReader backfillBR = new BufferedReader(backfillFR);
String line;
Expand All @@ -336,12 +371,17 @@ private StringBuilder readPrevBackfillReqStrB() throws Exception {
prevBackfillStrB.append(line);
prevBackfillStrB.append("\n");
}

logger.debug("For the previous backfill request file," +
" we read:\n" + prevBackfillStrB.toString());

backfillBR.close();
} catch (FileNotFoundException e) {
logger.debug("Can't read a file that doesn't exist:\n" +
this.backfillReqFile.toString());
} catch (Exception e) {
logger.info("Unknown problem reading backfill request file: " +
e.getMessage());
}

return prevBackfillStrB;
Expand Down

0 comments on commit 0a1ef4a

Please sign in to comment.