use of org.apache.twill.api.TwillRunnableSpecification in project cdap by caskdata.
the class KubeTwillPreparer method saveSpecification.
/**
* Creates and saves a {@link TwillRunnableSpecification} to a given path.
*/
private void saveSpecification(TwillSpecification spec, Path targetFile) throws IOException {
Map<String, Collection<LocalFile>> runnableLocalFiles = populateRunnableLocalFiles(spec);
// Rewrite LocalFiles inside twillSpec
Map<String, RuntimeSpecification> runtimeSpec = spec.getRunnables().entrySet().stream().map(e -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), new DefaultRuntimeSpecification(e.getValue().getName(), e.getValue().getRunnableSpecification(), e.getValue().getResourceSpecification(), runnableLocalFiles.get(e.getKey())))).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
LOG.debug("Saving twill specification for {} to {}", spec.getName(), targetFile);
TwillSpecification newTwillSpec = new DefaultTwillSpecification(spec.getName(), runtimeSpec, spec.getOrders(), spec.getPlacementPolicies(), new LogOnlyEventHandler().configure());
TwillRuntimeSpecification twillRuntimeSpec = new TwillRuntimeSpecification(newTwillSpec, appLocation.getLocationFactory().getHomeLocation().getName(), appLocation.toURI(), "", twillRunId, twillSpec.getName(), "", Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
try (Writer writer = Files.newBufferedWriter(targetFile, StandardCharsets.UTF_8)) {
TwillRuntimeSpecificationAdapter.create().toJson(twillRuntimeSpec, writer);
}
}
Aggregations