public static FlowSpec createFlowSpecForConfig(FlowConfig flowConfig) {
    ConfigBuilder configBuilder = ConfigBuilder.create()
        .addPrimitive(ConfigurationKeys.FLOW_GROUP_KEY, flowConfig.getId().getFlowGroup())
        .addPrimitive(ConfigurationKeys.FLOW_NAME_KEY, flowConfig.getId().getFlowName());

    if (flowConfig.hasSchedule()) {
      Schedule schedule = flowConfig.getSchedule();
      configBuilder.addPrimitive(ConfigurationKeys.JOB_SCHEDULE_KEY, schedule.getCronSchedule());
      configBuilder.addPrimitive(ConfigurationKeys.FLOW_RUN_IMMEDIATELY, schedule.isRunImmediately());
    } else {
      // If the job does not have schedule, it is a run-once job.
      // In this case, we add flow execution id to the flow spec now to be able to send this id back to the user for
      // flow status tracking purpose.
      // If it is not a run-once job, we should not add flow execution id here,
      // because execution id is generated for every scheduled execution of the flow and cannot be materialized to
      // the flow catalog. In this case, this id is added during flow compilation.
      configBuilder.addPrimitive(ConfigurationKeys.FLOW_EXECUTION_ID_KEY, String.valueOf(System.currentTimeMillis()));
    }

    if (flowConfig.hasExplain()) {
      configBuilder.addPrimitive(ConfigurationKeys.FLOW_EXPLAIN_KEY, flowConfig.isExplain());
    }

    Config config = configBuilder.build();

    Config configWithFallback;
    //We first attempt to process the REST.li request as a HOCON string. If the request is not a valid HOCON string
    // (e.g. when certain special characters such as ":" or "*" are not properly escaped), we catch the Typesafe ConfigException and
    // fallback to assuming that values are literal strings.
    try {
      // We first convert the StringMap object to a String object and then use ConfigFactory#parseString() to parse the
      // HOCON string.
      configWithFallback = config.withFallback(ConfigFactory.parseString(flowConfig.getProperties().toString()).resolve());
    } catch (Exception e) {
      configWithFallback = config.withFallback(ConfigFactory.parseMap(flowConfig.getProperties()));
    }

    try {
      URI templateURI = new URI(flowConfig.getTemplateUris());
      return FlowSpec.builder().withConfig(configWithFallback).withTemplate(templateURI).build();
    } catch (URISyntaxException e) {
      throw new FlowConfigLoggedException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowConfig.getTemplateUris(), e);
    }
  }
public static FlowSpec createFlowSpecForConfig ( FlowConfig flowConfig ) { ConfigBuilder configBuilder = ConfigBuilder . create ( ) . addPrimitive ( ConfigurationKeys . FLOW_GROUP_KEY , flowConfig . getId ( ) . getFlowGroup ( ) ) . addPrimitive ( ConfigurationKeys . FLOW_NAME_KEY , flowConfig . getId ( ) . getFlowName ( ) ) ; if ( flowConfig . hasSchedule ( ) ) { Schedule schedule = flowConfig . getSchedule ( ) ; configBuilder . addPrimitive ( ConfigurationKeys . JOB_SCHEDULE_KEY , schedule . getCronSchedule ( ) ) ; configBuilder . addPrimitive ( ConfigurationKeys . FLOW_RUN_IMMEDIATELY , schedule . isRunImmediately ( ) ) ; } else { configBuilder . addPrimitive ( ConfigurationKeys . FLOW_EXECUTION_ID_KEY , String . valueOf ( System . currentTimeMillis ( ) ) ) ; } if ( flowConfig . hasExplain ( ) ) { configBuilder . addPrimitive ( ConfigurationKeys . FLOW_EXPLAIN_KEY , flowConfig . isExplain ( ) ) ; } Config config = configBuilder . build ( ) ; Config configWithFallback ; try { configWithFallback = config . withFallback ( ConfigFactory . parseString ( flowConfig . getProperties ( ) . toString ( ) ) . resolve ( ) ) ; } catch ( Exception e ) { configWithFallback = config . withFallback ( ConfigFactory . parseMap ( flowConfig . getProperties ( ) ) ) ; } try { URI templateURI = new URI ( flowConfig . getTemplateUris ( ) ) ; return FlowSpec . builder ( ) . withConfig ( configWithFallback ) . withTemplate ( templateURI ) . build ( ) ; } catch ( URISyntaxException e ) { throw new FlowConfigLoggedException ( HttpStatus . S_400_BAD_REQUEST , "bad URI " + flowConfig . getTemplateUris ( ) , e ) ; } }
Build a {@link FlowSpec} from a {@link FlowConfig}
@param flowConfig flow configuration
@return {@link FlowSpec} created with attributes from flowConfig