mirror of
https://github.com/apache/jclouds.git
synced 2025-02-17 15:35:44 +00:00
Factored JobExecutionContext utility functions into a helper class
This commit is contained in:
parent
8e74a1e029
commit
e737e45d36
@ -43,25 +43,27 @@ public class HttpRequestJob implements Job {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||||
PlatformServices platform = getPlatform(context);
|
PlatformServices platform = JobContexts.getPlatform(context);
|
||||||
RunnableHttpRequest request = platform.getScheduler().getHttpRequestFactory().create(
|
RunnableHttpRequest request = platform.getScheduler().getHttpRequestFactory().create(
|
||||||
HttpRequest.builder()
|
HttpRequest.builder()
|
||||||
.endpoint(getTargetUrl(platform.getBaseUrl(), context))
|
.endpoint(JobContexts.getTargetUrl(platform.getBaseUrl(), context))
|
||||||
.method("GET").build());
|
.method("GET").build());
|
||||||
request.run();
|
request.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static URI getTargetUrl(String baseUrl, JobExecutionContext context) {
|
private static class JobContexts {
|
||||||
return URI.create(baseUrl + (String) checkNotNull(
|
private static URI getTargetUrl(String baseUrl, JobExecutionContext context) {
|
||||||
context.getMergedJobDataMap().get(URL_ATTRIBUTE_NAME), URL_ATTRIBUTE_NAME));
|
return URI.create(baseUrl + (String) checkNotNull(
|
||||||
}
|
context.getMergedJobDataMap().get(URL_ATTRIBUTE_NAME), URL_ATTRIBUTE_NAME));
|
||||||
|
}
|
||||||
private static PlatformServices getPlatform(JobExecutionContext jobContext) throws JobExecutionException {
|
|
||||||
try {
|
private static PlatformServices getPlatform(JobExecutionContext jobContext) throws JobExecutionException {
|
||||||
return PlatformServices.get((ServletContext) checkNotNull(
|
try {
|
||||||
jobContext.getScheduler().getContext().get(SERVLET_CONTEXT_KEY), SERVLET_CONTEXT_KEY));
|
return PlatformServices.get((ServletContext) checkNotNull(
|
||||||
} catch (SchedulerException exception) {
|
jobContext.getScheduler().getContext().get(SERVLET_CONTEXT_KEY), SERVLET_CONTEXT_KEY));
|
||||||
throw new JobExecutionException("Unable to get platform services from the job execution context", exception);
|
} catch (SchedulerException exception) {
|
||||||
|
throw new JobExecutionException("Unable to get platform services from the job execution context", exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user