in odps-console-xflow/src/main/java/com/aliyun/openservices/odps/console/xflow/UpdateOnlineModelAbtestCommand.java [104:164]
public static UpdateOnlineModelAbtestCommand parse(String cmd, ExecutionContext ctx)
throws ODPSConsoleException {
if (cmd == null || ctx == null) {
return null;
}
Matcher m = PATTERN.matcher(cmd);
boolean match = m.matches();
if (!match) {
return null;
}
String input = m.group(1);
String[] inputs = new AntlrObject(input).getTokenStringArray();
CommandLine commandLine = getCommandLine(inputs);
String projectName = null;
ModelAbTestInfo modelInfo = new ModelAbTestInfo();
if (commandLine.hasOption("p")) {
modelInfo.project = commandLine.getOptionValue("p");
}
if (commandLine.hasOption("targetProject") &&
commandLine.hasOption("targetModel") &&
commandLine.hasOption("percentage")) {
ModelAbTestItem item = new ModelAbTestItem();
item.project = commandLine.getOptionValue("targetProject");
item.targetModel = commandLine.getOptionValue("targetModel");
item.Pct = commandLine.getOptionValue("percentage");
ModelAbTestConf abTestConf = new ModelAbTestConf();
abTestConf.items = new ArrayList<ModelAbTestItem>();
abTestConf.items.add(item);
modelInfo.abTestConf = abTestConf;
} else if (!commandLine.hasOption("targetProject") &&
!commandLine.hasOption("targetModel") &&
!commandLine.hasOption("percentage")) {
//clean abTest
ModelAbTestConf abTestConf = new ModelAbTestConf();
modelInfo.abTestConf = abTestConf;
} else {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND
+ "invalid parameter for onlinemodel abtest, please HELP ONLINEMODEL.");
}
if (commandLine.getArgList().size() != 1) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Model name not found.");
}
String modelName = commandLine.getArgs()[0];
if (!modelName.matches("[\\w]+")) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Invalid model name.");
}
modelInfo.modelName = modelName;
if (modelInfo.project == null) {
modelInfo.project = ctx.getProjectName();
}
return new UpdateOnlineModelAbtestCommand(modelInfo, cmd, ctx);
}