public static OnlineModelInfo buildOnlineModelInfo()

in odps-console-xflow/src/main/java/com/aliyun/openservices/odps/console/xflow/CreateOnlineModelCommand.java [139:237]


  public static OnlineModelInfo buildOnlineModelInfo(String cmd, Pattern PATTERN,
                                                     ExecutionContext ctx)
      throws ODPSConsoleException {
    Matcher m = PATTERN.matcher(cmd);
    boolean match = m.matches();

    if (!match) {
      return null;
    }

    String input = m.group(1);
    String[] inputs = ODPSConsoleUtils.translateCommandline(input);
    CommandLine commandLine = getCommandLine(inputs);

    String projectName = null;
    OnlineModelInfo modelInfo = new OnlineModelInfo();
    modelInfo.resource = new Resource();

    if (commandLine.hasOption("p")) {
      modelInfo.project = commandLine.getOptionValue("p");
    }

    if (commandLine.hasOption("offlinemodelName") &&
        !commandLine.hasOption("id") &&
        !commandLine.hasOption("libName") &&
        !commandLine.hasOption("refResource") &&
        !commandLine.hasOption("target")) {
      modelInfo.offlineModelName = commandLine.getOptionValue("offlinemodelName");
      if (commandLine.hasOption("offlinemodelProject")) {
        modelInfo.offlineProject = commandLine.getOptionValue("offlinemodelProject");
      } else {
        modelInfo.offlineProject = ctx.getProjectName();
      }
    } else if (commandLine.hasOption("id") &&
               commandLine.hasOption("libName") &&
               commandLine.hasOption("refResource") &&
               commandLine.hasOption("target") &&
               !commandLine.hasOption("offlinemodelProject") &&
               !commandLine.hasOption("offlinemodelName")) {
      ModelPredictDesc desc = new ModelPredictDesc();
      ModelPipeline pipeline = new ModelPipeline();
      pipeline.processors = new ArrayList<ModelProcessor>();

      ModelProcessor processor = new ModelProcessor();
      processor.className = commandLine.getOptionValue("id");
      processor.libName = commandLine.getOptionValue("libName");
      processor.refResource = commandLine.getOptionValue("refResource").replace(',', ';');
      if (commandLine.hasOption("configuration")) {
        processor.configuration = commandLine.getOptionValue("configuration");
      }
      pipeline.processors.add(processor);

      desc.target = new Target();
      desc.target.name = commandLine.getOptionValue("target");
      desc.pipeline = pipeline;

      modelInfo.predictDesc = desc;
    } else {
      throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND
                                     + "invalid parameter for onlinemodel, please HELP ONLINEMODEL.");
    }

    if (commandLine.hasOption("qos")) {
      modelInfo.QOS = Short.parseShort(commandLine.getOptionValue("qos"));
    }
    if (commandLine.hasOption("instanceNum")) {
      modelInfo.instanceNum = Short.parseShort(commandLine.getOptionValue("instanceNum"));
    }
    if (commandLine.hasOption("cpu")) {
      modelInfo.resource.CPU = Integer.parseInt(commandLine.getOptionValue("cpu"));
    }
    if (commandLine.hasOption("gpu")) {
      modelInfo.resource.GPU = Integer.parseInt(commandLine.getOptionValue("gpu"));
    }
    if (commandLine.hasOption("memory")) {
      modelInfo.resource.memory = Long.parseLong(commandLine.getOptionValue("memory"));
    }
    if (commandLine.hasOption("serviceTag")) {
      modelInfo.serviceTag = commandLine.getOptionValue("serviceTag");
    }
    if (commandLine.hasOption("runtime")) {
      modelInfo.runtime = commandLine.getOptionValue("runtime");
      if (!modelInfo.runtime.equals("Jar") && !modelInfo.runtime.equals("Native")) {
        throw new ODPSConsoleException(
            ODPSConsoleConstants.BAD_COMMAND + "Parameter -runtime must be Jar or Native.");
      }
    }

    if (commandLine.getArgList().size() != 1) {
      throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Model name is ambiguous.");
    }

    String modelName = commandLine.getArgs()[0];
    if (!modelName.matches("[\\w]+")) {
      throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Invalid model name.");
    }
    modelInfo.modelName = modelName;
    return modelInfo;
  }