/** * Creates a new client with the host and port specified. */ public AdminClient(String host, int port) { this.closer = Closer.create(); URI serverUri = URI.create(String.format("http://%s:%d/", host, port)); this.client = new JobExecutionInfoClient(serverUri.toString()); this.closer.register(this.client); }
/** * Execute a query and coerce the result into a java List * @param query Query to execute * @return List of jobs that matched the query. (Empty list if none did). * @throws RemoteInvocationException If the server throws an error */ private List<JobExecutionInfo> executeQuery(JobExecutionQuery query) throws RemoteInvocationException { JobExecutionQueryResult result = this.client.get(query); if (result != null && result.hasJobExecutions()) { return result.getJobExecutions(); } return Collections.emptyList(); }
@AfterClass(alwaysRun = true) public void tearDown() throws Exception { if (this.client != null) { this.client.close(); } if (this.server != null) { this.server.shutDown(); } if (this.jobHistoryStore != null) { this.jobHistoryStore.close(); } if (this.testMetastoreDatabase != null) { this.testMetastoreDatabase.close(); } }
@Test public void testBatchGet() throws Exception { JobExecutionQuery queryByJobId1 = new JobExecutionQuery(); queryByJobId1.setIdType(QueryIdTypeEnum.JOB_ID); queryByJobId1.setId(JobExecutionQuery.Id.create(this.expected1.getJobId())); JobExecutionQuery queryByJobId2 = new JobExecutionQuery(); queryByJobId2.setIdType(QueryIdTypeEnum.JOB_ID); queryByJobId2.setId(JobExecutionQuery.Id.create(this.expected2.getJobId())); List<JobExecutionQuery> queries = Lists.newArrayList(queryByJobId1, queryByJobId2); List<JobExecutionQueryResult> result = Lists.newArrayList(this.client.batchGet(queries)); Assert.assertEquals(result.size(), 2); Assert.assertEquals(result.get(0).getJobExecutions().size(), 1); Assert.assertEquals(result.get(1).getJobExecutions().size(), 1); JobExecutionInfo actual1 = result.get(0).getJobExecutions().get(0); JobExecutionInfo actual2 = result.get(1).getJobExecutions().get(0); if (actual1.getJobName().equals(this.expected1.getJobName())) { assertJobExecution(actual1, this.expected1); assertJobExecution(actual2, this.expected2); } else { assertJobExecution(actual1, this.expected2); assertJobExecution(actual2, this.expected1); } }
@Test public void testBadGet() throws Exception { JobExecutionQuery queryByJobId = new JobExecutionQuery(); queryByJobId.setIdType(QueryIdTypeEnum.JOB_ID); queryByJobId.setId(JobExecutionQuery.Id.create(this.expected1.getJobId() + "1")); JobExecutionQueryResult result = this.client.get(queryByJobId); Assert.assertTrue(result.getJobExecutions().isEmpty()); }
@BeforeClass public void setUp() throws Exception { testMetastoreDatabase = TestMetastoreDatabaseFactory.get(); Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_HISTORY_STORE_URL_KEY, testMetastoreDatabase.getJdbcUrl()); int randomPort = chooseRandomPort(); properties.setProperty(ConfigurationKeys.REST_SERVER_PORT_KEY, Integer.toString(randomPort)); Injector injector = Guice.createInjector(new MetaStoreModule(properties)); this.jobHistoryStore = injector.getInstance(JobHistoryStore.class); this.client = new JobExecutionInfoClient(String.format("http://%s:%s/", "localhost", randomPort)); this.server = new JobExecutionInfoServer(properties); this.server.startUp(); this.expected1 = createJobExecutionInfo(1); this.expected2 = createJobExecutionInfo(2); this.jobHistoryStore.put(this.expected1); this.jobHistoryStore.put(this.expected2); }
@Test public void testGet() throws Exception { JobExecutionQuery queryByJobId = new JobExecutionQuery(); queryByJobId.setIdType(QueryIdTypeEnum.JOB_ID); queryByJobId.setId(JobExecutionQuery.Id.create(this.expected1.getJobId())); JobExecutionQueryResult result = this.client.get(queryByJobId); JobExecutionInfoArray jobExecutionInfos = result.getJobExecutions(); Assert.assertEquals(jobExecutionInfos.size(), 1); JobExecutionInfo actual = jobExecutionInfos.get(0); assertJobExecution(actual, this.expected1); }
/** * Creates a new client with the host and port specified. */ public AdminClient(String host, int port) { this.closer = Closer.create(); URI serverUri = URI.create(String.format("http://%s:%d/", host, port)); this.client = new JobExecutionInfoClient(serverUri.toString()); this.closer.register(this.client); }
/** * Execute a query and coerce the result into a java List * @param query Query to execute * @return List of jobs that matched the query. (Empty list if none did). * @throws RemoteInvocationException If the server throws an error */ private List<JobExecutionInfo> executeQuery(JobExecutionQuery query) throws RemoteInvocationException { JobExecutionQueryResult result = this.client.get(query); if (result != null && result.hasJobExecutions()) { return result.getJobExecutions(); } return Collections.emptyList(); }