public JobControl getJobControl(int jobId) { EcsSync sync = syncCache.get(jobId); if (sync == null) return null; JobControl jobControl = new JobControl(); jobControl.setStatus(getJobStatus(sync)); jobControl.setThreadCount(sync.getSyncConfig().getOptions().getThreadCount()); return jobControl; }
public void setJobControl(int jobId, JobControl jobControl) { EcsSync sync = syncCache.get(jobId); if (sync == null) throw new JobNotFoundException("the specified job ID does not exist"); if (jobControl.getThreadCount() > 0) { sync.setThreadCount(jobControl.getThreadCount()); } if (jobControl.getStatus() != null) { switch (jobControl.getStatus()) { case Stopped: sync.terminate(); break; case Paused: sync.pause(); break; case Running: sync.resume(); break; } } }
private void setThreadCount(int jobId, Integer threadCount) { JobControl control = new JobControl(); if (threadCount != null) { control.setThreadCount(threadCount); } controlJob(jobId, control); }
private void stop(int jobId) { JobControl control = new JobControl(); control.setStatus(JobControlStatus.Stopped); controlJob(jobId, control); }
while (client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus() == JobControlStatus.Initializing) { Thread.sleep(500); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Stopped, 4)); Assert.assertEquals(JobControlStatus.Stopped, jobControl.getStatus()); } finally {
while (client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus() == JobControlStatus.Initializing) { Thread.sleep(200); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Paused, 0)); Assert.assertEquals(JobControlStatus.Paused, jobControl.getStatus()); Assert.assertEquals(2, jobControl.getThreadCount()); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Running, 0)); Assert.assertEquals(JobControlStatus.Running, jobControl.getStatus()); Assert.assertEquals(2, jobControl.getThreadCount()); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Running, 32)); while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); Assert.assertEquals(JobControlStatus.Complete, jobControl.getStatus());
@After public void stopRestServer() throws InterruptedException { if (restServer != null) restServer.stop(0); restServer = null; // wait for all jobs to stop to prevent leakage into other tests for (JobInfo jobInfo : SyncJobService.getInstance().getAllJobs().getJobs()) { while (!SyncJobService.getInstance().getJobControl(jobInfo.getJobId()).getStatus().isFinalState()) Thread.sleep(500); SyncJobService.getInstance().deleteJob(jobInfo.getJobId(), false); } }
while (client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus() == JobControlStatus.Initializing) { Thread.sleep(500); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Paused, 4)); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Stopped, 4)); Assert.assertEquals(JobControlStatus.Stopped, jobControl.getStatus());
private void resume(int jobId) { JobControl control = new JobControl(); control.setStatus(JobControlStatus.Running); controlJob(jobId, control); }
@Test public void testCreateDelete() throws Exception { SyncConfig syncConfig = new SyncConfig(); syncConfig.setSource(new TestConfig().withObjectCount(10).withMaxSize(10240).withDiscardData(false)); syncConfig.setTarget(new TestConfig().withReadData(true).withDiscardData(false)); // create sync job ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobIdStr = response.getHeaders().getFirst("x-emc-job-id"); try { Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); response.close(); // must close all responses Assert.assertNotNull(jobIdStr); int jobId = Integer.parseInt(jobIdStr); // wait for job to complete while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); } // get status (should be complete) JobControl jobControl = client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class); Assert.assertNotNull(jobControl); Assert.assertEquals(JobControlStatus.Complete, jobControl.getStatus()); } finally { // delete job response = client.resource(endpoint).path("/job/" + jobIdStr).delete(ClientResponse.class); if (response.getStatus() != 200) log.warn("could not delete job: {}", response.getEntity(String.class)); response.close(); // must close all responses } }
client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Running, 10)); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Running, 2)); Thread.sleep(300); totalCount = client.resource(endpoint).path("/job/" + jobId + "/progress").get(SyncProgress.class).getObjectsComplete(); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Running, 32)); while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); Assert.assertEquals(JobControlStatus.Complete, jobControl.getStatus()); } finally {
private void pause(int jobId) { JobControl control = new JobControl(); control.setStatus(JobControlStatus.Paused); controlJob(jobId, control); }
while (!client.resource(endpoint).path("/job/" + jobId1 + "/control").get(JobControl.class).getStatus().isFinalState() && !client.resource(endpoint).path("/job/" + jobId2 + "/control").get(JobControl.class).getStatus().isFinalState() && !client.resource(endpoint).path("/job/" + jobId3 + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000);
while (client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus() == JobControlStatus.Initializing) { Thread.sleep(500); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Stopped, 20));
@Test public void testGetJob() throws Exception { SyncConfig syncConfig = new SyncConfig(); syncConfig.setSource(new TestConfig().withObjectCount(10).withMaxSize(10240).withDiscardData(false)); syncConfig.setTarget(new TestConfig().withReadData(true).withDiscardData(false)); // create sync job ClientResponse response = client.resource(endpoint).path("/job").put(ClientResponse.class, syncConfig); String jobId = response.getHeaders().getFirst("x-emc-job-id"); try { Assert.assertEquals(response.getEntity(String.class), 201, response.getStatus()); response.close(); // must close all responses // get job SyncConfig syncConfig2 = client.resource(endpoint).path("/job/" + jobId).get(SyncConfig.class); Assert.assertNotNull(syncConfig2); Assert.assertEquals(syncConfig, syncConfig2); // wait for job to complete while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); } } finally { // delete job response = client.resource(endpoint).path("/job/" + jobId).delete(ClientResponse.class); if (response.getStatus() != 200) log.warn("could not delete job: {}", response.getEntity(String.class)); response.close(); // must close all responses } }
while (client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus() == JobControlStatus.Initializing) { Thread.sleep(500); client.resource(endpoint).path("/job/" + jobId + "/control").post(new JobControl(JobControlStatus.Running, 32)); while (!client.resource(endpoint).path("/job/" + jobId + "/control").get(JobControl.class).getStatus().isFinalState()) { Thread.sleep(1000); Assert.assertEquals(JobControlStatus.Complete, jobControl.getStatus());