/** * Create a flow configuration * It differs from {@link FlowConfigClient} in a way that it returns FlowStatusId, * which can be used to find the FlowExecutionId * @param flowConfig FlowConfig to be used to create the flow * @return FlowStatusId * @throws RemoteInvocationException */ public FlowStatusId createFlowConfig(FlowConfig flowConfig) throws RemoteInvocationException { LOG.debug("createFlowConfig with groupName " + flowConfig.getId().getFlowGroup() + " flowName " + flowConfig.getId().getFlowName()); CreateIdRequest<ComplexResourceKey<FlowId, FlowStatusId>, FlowConfig> request = _flowconfigsV2RequestBuilders.create().input(flowConfig).build(); ResponseFuture<IdResponse<ComplexResourceKey<FlowId, FlowStatusId>>> flowConfigResponseFuture = _restClient.get().sendRequest(request); return createFlowStatusId(flowConfigResponseFuture.getResponse().getLocation().toString()); }
@AfterClass(alwaysRun = true) public void tearDown() throws Exception { if (_client != null) { _client.close(); } if (_server != null) { _server.stopAsync(); _server.awaitTerminated(); } _testDirectory.delete(); cleanUpDir(TEST_SPEC_STORE_DIR); } }
@Test public void testCheckFlowExecutionId() throws Exception { Map<String, String> flowProperties = Maps.newHashMap(); flowProperties.put("param1", "value1"); FlowConfig flowConfig = new FlowConfig().setId(new FlowId().setFlowGroup(TEST_GROUP_NAME).setFlowName(TEST_FLOW_NAME)) .setTemplateUris(TEST_TEMPLATE_URI).setProperties(new StringMap(flowProperties)); FlowStatusId flowStatusId =_client.createFlowConfig(flowConfig); Assert.assertEquals(TEST_GROUP_NAME, flowStatusId.getFlowGroup()); Assert.assertEquals(TEST_FLOW_NAME, flowStatusId.getFlowName()); Assert.assertTrue(flowStatusId.getFlowExecutionId() != -1); flowConfig = new FlowConfig().setId(new FlowId().setFlowGroup(TEST_GROUP_NAME).setFlowName(TEST_FLOW_NAME)) .setTemplateUris(TEST_TEMPLATE_URI).setProperties(new StringMap(flowProperties)) .setSchedule(new Schedule().setCronSchedule(TEST_SCHEDULE).setRunImmediately(true)); Assert.assertEquals(_client.createFlowConfig(flowConfig).getFlowExecutionId().longValue(), -1L); }
@BeforeClass public void setUp() throws Exception { ConfigBuilder configBuilder = ConfigBuilder.create(); _testDirectory = Files.createTempDir(); configBuilder .addPrimitive(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, _testDirectory.getAbsolutePath()) .addPrimitive(ConfigurationKeys.SPECSTORE_FS_DIR_KEY, TEST_SPEC_STORE_DIR); cleanUpDir(TEST_SPEC_STORE_DIR); Config config = configBuilder.build(); final FlowCatalog flowCatalog = new FlowCatalog(config); flowCatalog.startAsync(); flowCatalog.awaitRunning(); Injector injector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { binder.bind(FlowConfigsResourceHandler.class).annotatedWith(Names.named("flowConfigsV2ResourceHandler")).toInstance(new FlowConfigV2ResourceLocalHandler(flowCatalog)); // indicate that we are in unit testing since the resource is being blocked until flow catalog changes have // been made binder.bindConstant().annotatedWith(Names.named("readyToUse")).to(Boolean.TRUE); } }); _server = EmbeddedRestliServer.builder().resources( Lists.<Class<? extends BaseResource>>newArrayList(FlowConfigsV2Resource.class)).injector(injector).build(); _server.startAsync(); _server.awaitRunning(); _client = new FlowConfigV2Client(String.format("http://localhost:%s/", _server.getPort())); }
/** * Create a flow configuration * It differs from {@link FlowConfigClient} in a way that it returns FlowStatusId, * which can be used to find the FlowExecutionId * @param flowConfig FlowConfig to be used to create the flow * @return FlowStatusId * @throws RemoteInvocationException */ public FlowStatusId createFlowConfig(FlowConfig flowConfig) throws RemoteInvocationException { LOG.debug("createFlowConfig with groupName " + flowConfig.getId().getFlowGroup() + " flowName " + flowConfig.getId().getFlowName()); CreateIdRequest<ComplexResourceKey<FlowId, FlowStatusId>, FlowConfig> request = _flowconfigsV2RequestBuilders.create().input(flowConfig).build(); ResponseFuture<IdResponse<ComplexResourceKey<FlowId, FlowStatusId>>> flowConfigResponseFuture = _restClient.get().sendRequest(request); return createFlowStatusId(flowConfigResponseFuture.getResponse().getLocation().toString()); }