Commit ca0d5c4b authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Add a `guidinfo` command to decode the UUID v1s

parent 0d412d04
......@@ -122,7 +122,7 @@ public class JAliEnCOMMander implements Runnable {
*/
private static final String[] jAliEnCommandList = new String[] {
"cd", "pwd", "mkdir", "rmdir",
"ls", "find", "toXml", "cat", "whereis", "cp", "rm", "mv", "touch", "type", "lfn2guid", "guid2lfn", "access", "commit", "chown", "chmod", "deleteMirror", "md5sum", "mirror",
"ls", "find", "toXml", "cat", "whereis", "cp", "rm", "mv", "touch", "type", "lfn2guid", "guid2lfn", "guidinfo", "access", "commit", "chown", "chmod", "deleteMirror", "md5sum", "mirror",
"grep",
"changeDiff",
"listFilesFromCollection",
......
package alien.shell.commands;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import alien.catalogue.GUIDUtils;
import alien.shell.ErrNo;
import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
/**
* @author costing
* @since 2018-08-15
*/
public class JAliEnCommandguidinfo extends JAliEnBaseCommand {
private ArrayList<String> alPaths = null;
private boolean printGUIDInfo(final String guidName) {
commander.printOutln(guidName);
commander.printOut("guid", guidName);
UUID uuid;
try {
uuid = UUID.fromString(guidName);
}
catch (@SuppressWarnings("unused") final Exception e) {
commander.printErrln(" Invalid UUID");
commander.printOut("error", "Invalid UUID");
return false;
}
final long gTime = GUIDUtils.epochTime(uuid);
final String mac = GUIDUtils.getMacAddr(uuid);
commander.printOutln(" Created: " + (new Date(gTime)) + " (" + gTime + ") by " + mac);
commander.printOut("mtime", String.valueOf(gTime));
commander.printOut("mac", mac);
return true;
}
@Override
public void run() {
for (final String lfnName : this.alPaths) {
printGUIDInfo(lfnName);
commander.outNextResult();
}
}
private static final OptionParser parser = new OptionParser();
static {
parser.accepts("v");
}
@Override
public void printHelp() {
commander.printOutln();
commander.printOutln(helpUsage("stat", "[-v] <filename1> [<or uuid>] ..."));
commander.printOutln(helpOption("-v", "More details on the status."));
commander.printOutln();
}
@Override
public boolean canRunWithoutArguments() {
return false;
}
/**
* Constructor needed for the command factory in JAliEnCOMMander
*
* @param commander
*
* @param alArguments
* the arguments of the command
* @throws OptionException
*/
public JAliEnCommandguidinfo(final JAliEnCOMMander commander, final List<String> alArguments) throws OptionException {
super(commander, alArguments);
try {
final OptionSet options = parser.parse(alArguments.toArray(new String[] {}));
alPaths = new ArrayList<>(options.nonOptionArguments().size());
alPaths.addAll(optionToString(options.nonOptionArguments()));
}
catch (final OptionException e) {
commander.setReturnCode(ErrNo.EINVAL, e.getMessage());
setArgumentsOk(false);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment