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

Commit

Permalink
Changed WorkspaceRequest execute method's return type from void to St…
Browse files Browse the repository at this point in the history
…ring, because we have to get the output from query command.
  • Loading branch information
carlasouza committed Jul 14, 2011
1 parent 0136e63 commit bb80114
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
import edu.emory.mathcs.backport.java.util.concurrent.Callable;
import edu.emory.mathcs.backport.java.util.concurrent.FutureTask;
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
import edu.emory.mathcs.backport.java.util.concurrent.Semaphore;
import org.apache.xpath.operations.String;



public class WorkspaceUtil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

import com.google.gson.Gson;
import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
import edu.emory.mathcs.backport.java.util.concurrent.FutureTask;
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.globus.workspace.Lager;
import org.globus.workspace.scheduler.defaults.ResourcepoolEntry;
import org.globus.workspace.service.InstanceResource;
import org.globus.workspace.service.Sweepable;
import org.globus.workspace.service.WorkspaceHome;
import org.globus.workspace.service.impls.async.RequestFactory;
import org.globus.workspace.service.impls.async.RequestFactoryImpl;
import org.globus.workspace.service.impls.async.WorkspaceRequest;
import org.globus.workspace.xen.xenssh.Query;
import org.nimbustools.api.services.rm.ManageException;

Expand All @@ -45,6 +45,7 @@ public class VMMReaper implements Runnable {
private static final Log logger =
LogFactory.getLog(VMMReaper.class.getName());

protected final RequestFactory reqFactory;
private final Gson gson = new Gson();

// -------------------------------------------------------------------------
Expand Down Expand Up @@ -78,6 +79,8 @@ public VMMReaper(ExecutorService executorService,
throw new IllegalArgumentException("lagerImpl may not be null");
}
this.lager = lagerImpl;

this.reqFactory = new RequestFactoryImpl(lager);
}


Expand Down Expand Up @@ -115,6 +118,14 @@ protected void reaperVMM() throws ManageException {

// These are the libvirt guest states
// 1 = running; 2 = idle; 3 = paused; 4 = shutdown; 5 = shut off; 6 = crashed; 7 = dying
WorkspaceRequest req = reqFactory.query();
String state = null;
try{
state = req.execute();
} catch (Exception e) {
//do something
}

HashMap<String,Integer> result = gson.fromJson("query vmm", HashMap.class);//TODO get returned json
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.globus.workspace.service.impls.async;

import org.globus.workspace.WorkspaceException;

// TODO: move to executor
public interface WorkspaceRequest {

Expand All @@ -25,7 +27,7 @@ public interface WorkspaceRequest {
* WorkspaceRequestQueue just knows how to dequeue work requests
* and call execute.
*/
public void execute();
public String execute() throws WorkspaceException;

/**
* Information needed by request is supplied in context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,29 @@ protected Exception postExecute(Exception e, boolean fake) {
return e;
}

public void execute() {
public String execute() throws WorkspaceException {

if (this.ctx == null) {
logger.fatal("request had null request ctx: " + this.name +
" [[ " + this.getClass().getName() + " ]]");
return;
return null;
}

try {
this.init();
} catch (WorkspaceException e) {
this.done(e);
return;
return null;
}

final boolean fake = this.ctx.getLocator().getGlobalPolicies().isFake();

Exception e = this.preExecute(fake);

String ret = null;

if (e == null) {
e = this._execute(fake);
ret = this._execute(fake);
e = this.postExecute(e, fake);
}

Expand All @@ -100,7 +102,7 @@ public void execute() {
logger.trace(Lager.id(ctx.getId()) + ": " +
this.name + " async task started");
}
return;
return null;
}

if (e == null) {
Expand All @@ -120,9 +122,10 @@ public void execute() {
}

this.done(e);
return ret;
}

private Exception _execute(boolean fake) {
private String _execute(boolean fake) throws WorkspaceException {

final int id = this.ctx.getId();
final boolean traceLog = this.ctx.lager().traceLog;
Expand Down Expand Up @@ -224,22 +227,24 @@ private Exception _execute(boolean fake) {
err = "Do not run have rights to run " +
this.name + " with ctx ID = " + id;
}
return new WorkspaceException(err);
throw new WorkspaceException(err);
}

// while developing it is sometimes helpful to set cmd to null
// before it is implemented (i.e., make just this one thing fake
// for the timebeing without using the fakeness infrastructure
// for other commands...).

//TODO: add json content here
String ret = null;
if (this.cmd != null) {
WorkspaceUtil.runCommand(this.cmd, eventLog, traceLog, id);
ret = WorkspaceUtil.runCommand(this.cmd, eventLog, traceLog, id);
}
return null;
return ret;
} catch (ReturnException e) {
return XenUtil.translateReturnException(e);
throw XenUtil.translateReturnException(e);
} catch (WorkspaceException e) {
return e;
throw e;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.globus.workspace.xen.xenlocal;

import org.globus.workspace.WorkspaceException;
import org.globus.workspace.cmdutils.SSHUtil;
import org.globus.workspace.service.binding.vm.VirtualMachine;
import org.globus.workspace.xen.XenTask;
import org.globus.workspace.xen.XenUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected void init() throws WorkspaceException {
this.doFakeLag = true;

final VirtualMachine vm = this.ctx.getVm();
final ArrayList ssh = SSHUtil.constructSshCommand(vm.getVmm());
final ArrayList ssh = SSHUtil.constructSshCommand(vm.getNode());
final ArrayList exe = XenUtil.constructQueryCommand();
ssh.addAll(exe);
this.cmd = (String[]) ssh.toArray(new String[ssh.size()]);
Expand Down

0 comments on commit bb80114

Please sign in to comment.