Permalink
Browse files

--print-pending is gone, replaced by --print-ctx-status which will pr…

…int out every node, see rest of commit msg

Usage:

$ ./bin/cloud-client.sh --print-ctx-status --handle cluster-002
118.135.125.1     [CTX_CHECKED_IN_PENDING]
118.135.125.17    [CTX_CHECKED_IN_PENDING]
118.135.125.28    [CTX_NOT_CHECKED_IN]

There are two fields, you can use awk to isolate:

$ ./bin/cloud-client.sh --print-ctx-status --handle cluster-002 | awk '{print $2}'

Exit code will be zero only when all are OK.  Otherwise will be 6
unless there is an issue with input or it failed to query, etc.,
then it will be some other non-zero code.
  • Loading branch information...
1 parent 3fa192b commit f04bff75b52c7ec008c15524ad5619c86cb98855 @timf timf committed Jun 15, 2010
@@ -23,45 +23,66 @@
import org.globus.workspace.client.Opts;
import org.globus.workspace.client.modes.aux.CommonLogs;
import org.globus.workspace.client_common.BaseClient;
-import org.globus.workspace.client_common.CommonStrings;
import org.globus.workspace.client_core.ExecutionProblem;
import org.globus.workspace.client_core.ExitNow;
import org.globus.workspace.client_core.ParameterProblem;
import org.globus.workspace.client_core.StubConfigurator;
import org.globus.workspace.client_core.actions.Ctx_Identities;
-import org.globus.workspace.client_core.actions.Ctx_RPQuery;
import org.globus.workspace.client_core.print.PrCodes;
import org.globus.workspace.client_core.utils.EPRUtils;
import org.globus.workspace.common.print.Print;
import org.nimbustools.ctxbroker.generated.gt4_0.broker.NimbusContextualizationFault;
import org.nimbustools.ctxbroker.generated.gt4_0.description.IdentityProvides_Type;
-import org.nimbustools.ctxbroker.generated.gt4_0.types.ContextualizationContext;
import org.nimbustools.ctxbroker.generated.gt4_0.types.Node_Type;
import org.nimbustools.messaging.gt4_0.common.CommonUtil;
-import org.oasis.wsrf.faults.BaseFaultType;
import java.io.File;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
public class ContextPrintStatus extends Mode {
+
+ // -------------------------------------------------------------------------
+ // INNER CLASS
+ // -------------------------------------------------------------------------
+
+ // tuple...
+ protected static class IpAndStatus {
+ public final String ip;
+ public final String status;
+
+ protected IpAndStatus(String ip, String status) {
+ if (ip == null) {
+ throw new IllegalArgumentException("ip is missing");
+ }
+ if (status == null) {
+ throw new IllegalArgumentException("status is missing");
+ }
+ this.ip = ip;
+ this.status = status;
+ }
+ }
+
// -------------------------------------------------------------------------
// STATIC VARIABLES
// -------------------------------------------------------------------------
private static final Log logger =
LogFactory.getLog(ContextPrintStatus.class.getName());
+ public static final String CTX_SUCCESS = "[CTX_SUCCESS]";
+ public static final String CTX_ERROR = "[CTX_ERROR]";
+ public static final String CTX_CHECKED_IN_PENDING = "[CTX_CHECKED_IN_PENDING]";
+ public static final String CTX_NOT_CHECKED_IN = "[CTX_NOT_CHECKED_IN]";
+
// -------------------------------------------------------------------------
// INSTANCE VARIABLES
// -------------------------------------------------------------------------
- private String nameToPrint;
- private Ctx_RPQuery rpQuery;
private Ctx_Identities identitiesQuery;
- private EndpointReferenceType epr;
private boolean dryrun;
@@ -87,7 +108,6 @@ public String name() {
public void validateOptionsImpl() throws ParameterProblem {
this.validateEndpoint();
- this.setName();
this.validateIpDir();
this.dryrun = this.args.dryrun;
CommonLogs.logBoolean(this.dryrun, "dryrun mode", this.pr, logger);
@@ -104,15 +124,15 @@ public void runImpl() throws ParameterProblem, ExecutionProblem, ExitNow {
private void validateEndpoint() throws ParameterProblem {
- this.epr = this.stubConf.getEPR();
+ final EndpointReferenceType epr = this.stubConf.getEPR();
- if (this.epr == null) {
+ if (epr == null) {
throw new ParameterProblem(name() + " requires EPR");
}
final String eprStr;
try {
- eprStr = EPRUtils.eprToString(this.epr);
+ eprStr = EPRUtils.eprToString(epr);
} catch (Exception e) {
final String err = CommonUtil.genericExceptionMessageWrapper(e);
throw new ParameterProblem(err, e);
@@ -130,10 +150,8 @@ private void validateEndpoint() throws ParameterProblem {
}
}
- this.rpQuery =
- new Ctx_RPQuery(this.epr, this.stubConf, this.pr);
this.identitiesQuery =
- new Ctx_Identities(this.epr, this.stubConf, this.pr);
+ new Ctx_Identities(epr, this.stubConf, this.pr);
}
private void validateIpDir() throws ParameterProblem {
@@ -178,106 +196,68 @@ private void _runImpl() throws ParameterProblem, ExecutionProblem, ExitNow {
return; // *** EARLY RETURN ***
}
- final ContextualizationContext contextRP;
- try {
- contextRP = this.rpQuery.query();
- } catch (BaseFaultType e) {
- final String err =
- CommonStrings.faultStringOrCommonCause(e, "context");
- throw new ExecutionProblem(err, e);
- }
-
- if (contextRP.isErrorPresent()) {
-
+ final List<String> knownIps = this.gatherIpAddressesFromFilesystem();
+
+ if (knownIps.isEmpty()) {
if (this.pr.enabled()) {
final String msg =
- "Error reported to context broker for " + this.nameToPrint;
+ "Could not find any IP addresses to analyze, is this directory " +
+ "empty? '" + this.args.eprIdDir + '\'';
if (this.pr.useThis()) {
this.pr.errln(PrCodes.CTXPRINTSTATUS__ONE_ERROR, msg);
} else if (this.pr.useLogging()) {
logger.error(msg);
}
}
throw new ExitNow(BaseClient.APPLICATION_EXIT_CODE);
+ }
- } else if (contextRP.isAllOK()) {
+ final Node_Type[] nodes = this.queryContextBroker();
- if (this.pr.enabled()) {
- final String msg = "Context broker reports that all nodes for '" +
- this.nameToPrint + "' have contextualized.";
- if (this.pr.useThis()) {
- this.pr.infoln(PrCodes.CTXPRINTSTATUS__ALL_OK, msg);
- } else if (this.pr.useLogging()) {
- logger.info(msg);
- }
+ final List<IpAndStatus> results = this.analyze(knownIps, nodes);
+
+ // if all are OK, it exits normally
+ boolean notAllOK = false;
+
+ String longestString = "";
+ for (IpAndStatus result : results) {
+ if (longestString.length() < result.ip.length()) {
+ longestString = result.ip;
}
- throw new ExitNow(BaseClient.SUCCESS_EXIT_CODE);
}
-
- final List<String> knownIps = new ArrayList<String>(10);
- final File idDir = new File(this.args.eprIdDir);
- final File[] idFiles = idDir.listFiles();
- for (File idFile : idFiles) {
- final String[] parts = idFile.getName().split("-");
- if (parts == null || parts.length != 2) {
- if (this.pr.enabled()) {
- final String msg =
- "id directory " + this.args.eprIdDir +
- " contains unexpected file name: " + idFile.getName();
- if (this.pr.useThis()) {
- this.pr.errln(PrCodes.CTXPRINTSTATUS__ONE_ERROR, msg);
- } else if (this.pr.useLogging()) {
- logger.error(msg);
- }
- }
- throw new ExitNow(BaseClient.APPLICATION_EXIT_CODE);
- }
- knownIps.add(parts[1]);
- final String dbg = "Found locally known node ip " + parts[1];
- if (this.pr.useThis()) {
- this.pr.dbg(dbg);
- } else if (this.pr.useLogging()) {
- logger.debug(dbg);
+ final int longestStringLen = longestString.length();
+
+ for (IpAndStatus result : results) {
+
+ if (!result.status.equals(CTX_SUCCESS)) {
+ notAllOK = true;
}
- }
- if (knownIps.isEmpty()) {
if (this.pr.enabled()) {
- final String msg =
- "Could not find any IP addresses to analyze, is this directory " +
- "empty? '" + this.args.eprIdDir + '\'';
+
+ final StringBuilder printIp = new StringBuilder(result.ip);
+ while (printIp.length() < longestStringLen) {
+ printIp.append(' ');
+ }
+ printIp.append(" ").append(result.status);
+
if (this.pr.useThis()) {
- this.pr.errln(PrCodes.CTXPRINTSTATUS__ONE_ERROR, msg);
+ this.pr.infoln(PrCodes.CTXPRINTSTATUS__ONE_IP, printIp.toString());
} else if (this.pr.useLogging()) {
- logger.error(msg);
+ logger.info(printIp.toString());
}
}
- throw new ExitNow(BaseClient.APPLICATION_EXIT_CODE);
}
- final Node_Type[] nodes;
- try {
- this.identitiesQuery.setQueryAll(true);
- nodes = this.identitiesQuery.identities();
- } catch (NimbusContextualizationFault e) {
- final String err = CommonUtil.genericExceptionMessageWrapper(e);
- if (this.pr.enabled()) {
- final String errMsg = "Problem querying ctx nodes: " + err;
- if (this.pr.useThis()) {
- this.pr.errln(errMsg);
- } else if (this.pr.useLogging()) {
- logger.error(errMsg);
- }
- }
- throw new ExitNow(1);
+ if (notAllOK) {
+ throw new ExitNow(BaseClient.CTX_PENDING_RESULTS);
}
+ }
+ private List<IpAndStatus> analyze(Collection<String> knownIps, Node_Type[] nodes) {
+
+ final List<IpAndStatus> results = new ArrayList<IpAndStatus>(knownIps.size());
- final List<String> printIps = new ArrayList<String>(knownIps.size());
-
- // this is finally what the end user is asking for, print each IP address that we
- // know about locally but does not exist in context or is in context without an OK
-
for (String knownIp : knownIps) {
final String dbg = "Analyzing known ip " + knownIp;
@@ -287,62 +267,111 @@ private void _runImpl() throws ParameterProblem, ExecutionProblem, ExitNow {
logger.debug(dbg);
}
- boolean printThis = true;
+ boolean foundIp = false;
+
for (Node_Type node : nodes) {
final IdentityProvides_Type[] identities = node.getIdentity();
for (IdentityProvides_Type identity : identities) {
final String ip = identity.getIp();
if (ip != null && ip.equals(knownIp)) {
- String tail = " [not OK]";
- if (node.isOk()) {
- tail = " [OK]";
- printThis = false;
- }
- final String dbg2 = " - found context node with that ip " + tail;
+ final String status = this.getNodeState(node);
+ results.add(new IpAndStatus(knownIp, status));
+
+ final String dbg2 = " - found context node with that ip: " + status;
if (this.pr.useThis()) {
this.pr.dbg(dbg2);
} else if (this.pr.useLogging()) {
logger.debug(dbg2);
}
+
+ foundIp = true;
+ break;
}
}
}
- if (printThis) {
- printIps.add(knownIp);
- }
- }
+ if (!foundIp) {
- for (String printIp : printIps) {
- if (this.pr.enabled()) {
+ results.add(new IpAndStatus(knownIp, CTX_NOT_CHECKED_IN));
+
+ final String dbg2 = " - did not find context node with that ip";
if (this.pr.useThis()) {
- this.pr.infoln(PrCodes.CTXPRINTSTATUS__ONE_IP, printIp);
+ this.pr.dbg(dbg2);
} else if (this.pr.useLogging()) {
- logger.info(printIp);
+ logger.debug(dbg2);
}
}
+
}
- throw new ExitNow(BaseClient.CTX_PENDING_RESULTS);
+ return results;
}
- private void setName() {
-
- if (this.args.shortName != null) {
- this.nameToPrint = this.args.shortName;
+ private String getNodeState(Node_Type node) {
+ if (node == null) {
+ throw new IllegalArgumentException("node is missing");
+ }
+ if (!node.isExited()) {
+ return CTX_CHECKED_IN_PENDING;
+ } else if (node.isOk()) {
+ return CTX_SUCCESS;
} else {
- this.nameToPrint = '\"' +
- EPRUtils.getContextIdFromEPR(this.epr) + '\"';
+ return CTX_ERROR;
}
+ }
- if (this.pr.enabled()) {
- final String dbg = "Name to print: '" + this.nameToPrint + '\'';
+ private Node_Type[] queryContextBroker() throws ExitNow,
+ ExecutionProblem,
+ ParameterProblem {
+ final Node_Type[] nodes;
+ try {
+ this.identitiesQuery.setQueryAll(true);
+ nodes = this.identitiesQuery.identities();
+ } catch (NimbusContextualizationFault e) {
+ final String err = CommonUtil.genericExceptionMessageWrapper(e);
+ if (this.pr.enabled()) {
+ final String errMsg = "Problem querying context broker: " + err;
+ if (this.pr.useThis()) {
+ this.pr.errln(errMsg);
+ } else if (this.pr.useLogging()) {
+ logger.error(errMsg);
+ }
+ }
+ throw new ExitNow(1);
+ }
+ return nodes;
+ }
+
+ private List<String> gatherIpAddressesFromFilesystem() throws ExitNow {
+
+ final List<String> knownIps = new ArrayList<String>(10);
+ final File idDir = new File(this.args.eprIdDir);
+ final File[] idFiles = idDir.listFiles();
+ for (File idFile : idFiles) {
+ final String[] parts = idFile.getName().split("-");
+ if (parts == null || parts.length != 2) {
+ if (this.pr.enabled()) {
+ final String msg =
+ "id directory " + this.args.eprIdDir +
+ " contains unexpected file name: " + idFile.getName();
+ if (this.pr.useThis()) {
+ this.pr.errln(PrCodes.CTXPRINTSTATUS__ONE_ERROR, msg);
+ } else if (this.pr.useLogging()) {
+ logger.error(msg);
+ }
+ }
+ throw new ExitNow(BaseClient.APPLICATION_EXIT_CODE);
+ }
+ knownIps.add(parts[1]);
+ final String dbg = "Found locally known node ip " + parts[1];
if (this.pr.useThis()) {
this.pr.dbg(dbg);
} else if (this.pr.useLogging()) {
logger.debug(dbg);
}
}
+
+ return knownIps;
}
}
Oops, something went wrong.

0 comments on commit f04bff7

Please sign in to comment.