Search in sources :

Example 31 with FlowSpec

use of org.apache.gobblin.runtime.api.FlowSpec in project incubator-gobblin by apache.

the class FlowCatalogTest method initFlowSpec.

private FlowSpec initFlowSpec() {
    Properties properties = new Properties();
    properties.put("specStore.fs.dir", SPEC_STORE_DIR);
    properties.put("specExecInstance.capabilities", "source:destination");
    Config config = ConfigUtils.propertiesToConfig(properties);
    SpecExecutor specExecutorInstanceProducer = new InMemorySpecExecutor(config);
    FlowSpec.Builder flowSpecBuilder = null;
    try {
        flowSpecBuilder = FlowSpec.builder(computeFlowSpecURI()).withConfig(config).withDescription(SPEC_DESCRIPTION).withVersion(SPEC_VERSION).withTemplate(new URI("templateURI"));
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    return flowSpecBuilder.build();
}
Also used : Config(com.typesafe.config.Config) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) SpecExecutor(org.apache.gobblin.runtime.api.SpecExecutor) InMemorySpecExecutor(org.apache.gobblin.runtime.spec_executorInstance.InMemorySpecExecutor) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) InMemorySpecExecutor(org.apache.gobblin.runtime.spec_executorInstance.InMemorySpecExecutor) URI(java.net.URI)

Example 32 with FlowSpec

use of org.apache.gobblin.runtime.api.FlowSpec in project incubator-gobblin by apache.

the class FlowConfigsResource method get.

/**
 * Retrieve the flow configuration with the given key
 * @param key flow config id key containing group name and flow name
 * @return {@link FlowConfig} with flow configuration
 */
@Override
public FlowConfig get(ComplexResourceKey<FlowId, EmptyRecord> key) {
    String flowGroup = key.getKey().getFlowGroup();
    String flowName = key.getKey().getFlowName();
    LOG.info("Get called with flowGroup " + flowGroup + " flowName " + flowName);
    try {
        URI flowCatalogURI = new URI("gobblin-flow", null, "/", null, null);
        URI flowUri = new URI(flowCatalogURI.getScheme(), flowCatalogURI.getAuthority(), "/" + flowGroup + "/" + flowName, null, null);
        FlowSpec spec = (FlowSpec) getFlowCatalog().getSpec(flowUri);
        FlowConfig flowConfig = new FlowConfig();
        Properties flowProps = spec.getConfigAsProperties();
        Schedule schedule = null;
        if (flowProps.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) {
            schedule = new Schedule();
            schedule.setCronSchedule(flowProps.getProperty(ConfigurationKeys.JOB_SCHEDULE_KEY));
        }
        if (flowProps.containsKey(ConfigurationKeys.JOB_TEMPLATE_PATH)) {
            flowConfig.setTemplateUris(flowProps.getProperty(ConfigurationKeys.JOB_TEMPLATE_PATH));
        } else if (spec.getTemplateURIs().isPresent()) {
            flowConfig.setTemplateUris(StringUtils.join(spec.getTemplateURIs().get(), ","));
        } else {
            flowConfig.setTemplateUris("NA");
        }
        if (schedule != null) {
            if (flowProps.containsKey(ConfigurationKeys.FLOW_RUN_IMMEDIATELY)) {
                schedule.setRunImmediately(Boolean.valueOf(flowProps.getProperty(ConfigurationKeys.FLOW_RUN_IMMEDIATELY)));
            }
            flowConfig.setSchedule(schedule);
        }
        // remove keys that were injected as part of flowSpec creation
        flowProps.remove(ConfigurationKeys.JOB_SCHEDULE_KEY);
        flowProps.remove(ConfigurationKeys.JOB_TEMPLATE_PATH);
        StringMap flowPropsAsStringMap = new StringMap();
        flowPropsAsStringMap.putAll(Maps.fromProperties(flowProps));
        return flowConfig.setId(new FlowId().setFlowGroup(flowGroup).setFlowName(flowName)).setProperties(flowPropsAsStringMap);
    } catch (URISyntaxException e) {
        logAndThrowRestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowName, e);
    } catch (SpecNotFoundException e) {
        logAndThrowRestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Flow requested does not exist: " + flowName, null);
    }
    return null;
}
Also used : StringMap(com.linkedin.data.template.StringMap) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) URI(java.net.URI)

Aggregations

FlowSpec (org.apache.gobblin.runtime.api.FlowSpec)32 Spec (org.apache.gobblin.runtime.api.Spec)18 Test (org.testng.annotations.Test)16 URI (java.net.URI)12 TopologySpec (org.apache.gobblin.runtime.api.TopologySpec)12 SpecExecutor (org.apache.gobblin.runtime.api.SpecExecutor)10 Properties (java.util.Properties)9 Config (com.typesafe.config.Config)7 InMemorySpecExecutor (org.apache.gobblin.runtime.spec_executorInstance.InMemorySpecExecutor)7 URISyntaxException (java.net.URISyntaxException)6 ServiceNode (org.apache.gobblin.runtime.api.ServiceNode)6 JobSpec (org.apache.gobblin.runtime.api.JobSpec)5 RefSpec (org.eclipse.jgit.transport.RefSpec)5 FlowEdge (org.apache.gobblin.runtime.api.FlowEdge)4 Map (java.util.Map)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 JobException (org.apache.gobblin.runtime.JobException)2 SpecProducer (org.apache.gobblin.runtime.api.SpecProducer)2 BaseServiceNodeImpl (org.apache.gobblin.runtime.spec_executorInstance.BaseServiceNodeImpl)2