protected void display(Action action) throws Exception { System.out.print("[" + getLink(action.getLink(), "replay")); System.out.println("] " + action.getStatus()); if (Status.FAILED.equals(action.getStatus()) && action.isSetFault()) { System.out.println("[" + action.getFault().getReason() + "]"); if (detail) { System.out.println("[" + action.getFault().getDetail() + "]"); } } } }
private void perform(AbstractActionTask task) { task.action.setStatus(StatusUtils.create(CreationStatus.IN_PROGRESS)); if (task.action.getGracePeriod() != null) { try { Thread.sleep(task.action.getGracePeriod().getExpiry()); } catch (Exception e) { // ignore } } task.run(); }
public void doAction(String verb, Action action, Link link, boolean detail) throws Exception { Response r = null; Exception failure = null; try { WebClient post = getClient(link.getHref()); r = post.path("/").post(action); } catch (Exception e) { failure = e; } int expectedStatus = action.isAsync() ? 202 : 200; if (failure != null || r.getStatus() != expectedStatus) { diagnose(verb + " failed with ", failure, r, expectedStatus); } else { Action reaction = unmarshall(r, Action.class); String monitor = Status.COMPLETE.equals(reaction.getStatus()) || Status.FAILED.equals(reaction.getStatus()) ? "" : ", monitor @ " + reaction.getHref(); System.out.println(verb + " " + reaction.getStatus() + monitor); if (Status.FAILED.equals(reaction.getStatus()) && reaction.isSetFault()) { System.out.println("[" + reaction.getFault().getReason() + "]"); if (detail) { System.out.println("[" + reaction.getFault().getDetail() + "]"); } } } }
Response.Status status = null; final ActionResource actionResource = new BaseActionResource<R>(uriInfo, task.action, getModel()); if (action.isSetAsync() && action.isAsync()) { action.setStatus(StatusUtils.create(CreationStatus.PENDING)); actions.put(action.getId(), actionResource); executor.execute(new Runnable() { public void run() { if (!action.getStatus().getState().equals(CreationStatus.FAILED.value())) { status = Status.OK; } else {
public void run() { try { execute(); if (!action.getStatus().getState().equals(com.redhat.rhevm.api.model.CreationStatus.FAILED.value())) { action.setStatus(StatusUtils.create(com.redhat.rhevm.api.model.CreationStatus.COMPLETE)); } } catch (Throwable t) { String message = t.getMessage() != null ? t.getMessage() : t.getClass().getName(); setFault(MessageFormat.format(t.getCause() != null ? t.getCause().getMessage() : reason, message), t); } }
protected void handleOutput(String output) { if (FenceType.fromValue(action.getFenceType()) == FenceType.STATUS) { List<PowerShellPowerManagementStatus> statuses = PowerShellPowerManagementStatus.parse(getParser(), output); if (statuses.isEmpty()) { handleFailure("Unknown status"); } else { PowerShellPowerManagementStatus status = statuses.get(0); //there can be only one status if (status.isSuccess() && status.getStatus() != null) { action.setStatus(StatusUtils.create(CreationStatus.COMPLETE)); PowerManagement pm = new PowerManagement(); pm.setStatus(StatusUtils.create(status.getStatus())); action.setPowerManagement(pm); } else { handleFailure(status.getMessage()); } } } }
@Override public Response migrate(Action action) { StringBuilder buf = new StringBuilder(); String hostArg = ""; if (action.isSetHost()) { hostArg = getHostArg(buf, action.getHost()); } buf.append("migrate-vm"); buf.append(" -vmid " + PowerShellUtils.escape(getId())); if (action.isSetHost()) { buf.append(" -desthostid " + hostArg); } return doAction(getUriInfo(), new CommandRunner(action, buf.toString(), getPool())); }
protected Response doImport(Action action, String type) { validateParameters(action, "cluster.id|name", "storageDomain.id|name"); StringBuilder buf = new StringBuilder(); String clusterVariable = getClusterVariable(buf, action.getCluster()); String dataCenterArg = getDataCenterArg(buf, clusterVariable); String destDomainArg = getDestDomainArg(buf, action.getStorageDomain()); buf.append("import-" + type); buf.append(" -datacenterid " + dataCenterArg); buf.append(" -sourcedomainid " + PowerShellUtils.escape(getStorageDomainId())); buf.append(" -destdomainid " + destDomainArg); buf.append(" -clusterid " + clusterVariable + ".clusterid"); buf.append(" -" + type + "id " + PowerShellUtils.escape(getId())); return doAction(getUriInfo(), new CommandRunner(action, buf.toString(), getPool())); }
protected Object doExecute() throws Exception { doAction("shutdown", new Action()); return null; } }
protected Object doExecute() throws Exception { doAction("suspend", new Action()); return null; } }
protected Object doExecute() throws Exception { doAction("stop", new Action()); return null; } }
protected Object doExecute() throws Exception { doAction("start", new Action()); return null; } }
protected Object doExecute() throws Exception { doAction("detach", new Action()); return null; } }