use of com.hazelcast.jet.config.ResourceConfig in project hazelcast-jet by hazelcast.
the class JobRepository method uploadJobResources.
/**
* Uploads job resources and returns a unique job id generated for the job.
* If the upload process fails for any reason, such as being unable to access a resource,
* uploaded resources are cleaned up.
*/
public long uploadJobResources(JobConfig jobConfig) {
long jobId = newJobId();
IMap<String, Object> jobResourcesMap = getJobResources(jobId);
for (ResourceConfig rc : jobConfig.getResourceConfigs()) {
Map<String, byte[]> tmpMap = new HashMap<>();
if (rc.isArchive()) {
try {
loadJar(tmpMap, rc.getUrl());
} catch (IOException e) {
cleanupJobResourcesAndSnapshots(jobId, jobResourcesMap);
randomIds.remove(jobId);
throw new JetException("Job resource upload failed", e);
}
} else {
try {
InputStream in = rc.getUrl().openStream();
readStreamAndPutCompressedToMap(rc.getId(), tmpMap, in);
} catch (IOException e) {
cleanupJobResourcesAndSnapshots(jobId, jobResourcesMap);
randomIds.remove(jobId);
throw new JetException("Job resource upload failed", e);
}
}
// now upload it all
jobResourcesMap.putAll(tmpMap);
}
// the marker object will be used to decide when to clean up job resources
jobResourcesMap.put(RESOURCE_MARKER, System.currentTimeMillis());
return jobId;
}
use of com.hazelcast.jet.config.ResourceConfig in project hazelcast-jet by hazelcast.
the class ResourceConfigTest method testAddJar_with_Path.
@Test
public void testAddJar_with_Path() throws Exception {
JobConfig config = new JobConfig();
String path = "/path/to/jarfile";
config.addJar(path);
ResourceConfig resourceConfig = config.getResourceConfigs().iterator().next();
assertNull(resourceConfig.getId());
assertTrue(resourceConfig.isArchive());
assertEquals(new File(path).toURI().toURL(), resourceConfig.getUrl());
}
use of com.hazelcast.jet.config.ResourceConfig in project hazelcast-jet by hazelcast.
the class ResourceConfigTest method testAddResource_with_Path_and_ResourceName.
@Test
public void testAddResource_with_Path_and_ResourceName() throws Exception {
JobConfig config = new JobConfig();
String resourceName = "resourceFileName";
String path = "/path/to/jarfile";
config.addResource(path, resourceName);
ResourceConfig resourceConfig = config.getResourceConfigs().iterator().next();
assertEquals(resourceName, resourceConfig.getId());
assertFalse(resourceConfig.isArchive());
assertEquals(new File(path).toURI().toURL(), resourceConfig.getUrl());
}
use of com.hazelcast.jet.config.ResourceConfig in project hazelcast-jet by hazelcast.
the class ResourceConfigTest method testAddResource_with_File_and_ResourceName.
@Test
public void testAddResource_with_File_and_ResourceName() throws Exception {
JobConfig config = new JobConfig();
String resourceName = "resourceFileName";
File file = new File("/path/to/resource");
config.addResource(file, resourceName);
ResourceConfig resourceConfig = config.getResourceConfigs().iterator().next();
assertEquals(resourceName, resourceConfig.getId());
assertFalse(resourceConfig.isArchive());
assertEquals(file.toURI().toURL(), resourceConfig.getUrl());
}
use of com.hazelcast.jet.config.ResourceConfig in project hazelcast-jet by hazelcast.
the class ResourceConfigTest method testAddJar_with_Url.
@Test
public void testAddJar_with_Url() throws Exception {
JobConfig config = new JobConfig();
String urlString = "file://path/to/jarfile";
config.addJar(new URL(urlString));
ResourceConfig resourceConfig = config.getResourceConfigs().iterator().next();
assertNull(resourceConfig.getId());
assertTrue(resourceConfig.isArchive());
assertEquals(urlString, resourceConfig.getUrl().toString());
}
Aggregations