use of com.thinkbiganalytics.metadata.api.template.export.ExportTemplate in project kylo by Teradata.
the class RepositoryMonitor method createMetadata.
private void createMetadata(Path templateFilePath, Map<String, RegisteredTemplate> registeredTemplateMap) {
RegisteredTemplate tmplt = null;
try {
File templateZipFile = templateFilePath.toFile();
byte[] content = ImportUtil.streamToByteArray(new FileInputStream(templateZipFile));
InputStream inputStream = new ByteArrayInputStream(content);
ImportTemplate importTemplate = ImportUtil.openZip(templateFilePath.getFileName().toString(), inputStream);
tmplt = importTemplate.getTemplateToImport();
File json = getMetadataFileName(templateFilePath).toFile();
String checksum = DigestUtils.md5DigestAsHex(content);
boolean updateAvailable = false;
TemplateMetadata metadata = new TemplateMetadata(tmplt.getTemplateName(), tmplt.getDescription(), templateFilePath.getFileName().toString(), checksum, tmplt.isStream(), updateAvailable, tmplt.getUpdateDate().getTime());
// startup or new template is published
if (!json.exists()) {
if (registeredTemplateMap.containsKey(tmplt.getTemplateName())) {
final String templateName = tmplt.getTemplateName();
ExportTemplate zipFile = metadataAccess.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_TEMPLATES);
return templateExporter.exportTemplate(registeredTemplateMap.get(templateName).getId());
}, MetadataAccess.SERVICE);
String digest = DigestUtils.md5DigestAsHex(zipFile.getFile());
updateAvailable = !StringUtils.equals(checksum, digest);
metadata.setUpdateAvailable(updateAvailable);
templateUpdateInfoCache.put(templateName, updateAvailable);
}
} else {
// if registered template was updated
metadata = mapper.readValue(json, TemplateMetadata.class);
templateUpdateInfoCache.put(tmplt.getTemplateName(), metadata.isUpdateAvailable());
if (metadata.getLastModified() >= tmplt.getUpdateDate().getTime()) {
return;
}
if (StringUtils.equals(metadata.getChecksum(), checksum)) {
return;
}
metadata.setUpdateAvailable(true);
templateUpdateInfoCache.put(tmplt.getTemplateName(), true);
}
log.info("Writing template metadata for {}.", tmplt.getTemplateName());
mapper.writerWithDefaultPrettyPrinter().writeValue(json, metadata);
} catch (Exception e) {
log.error("Error occurred trying to generate template metadata.", e);
if (tmplt != null) {
templateUpdateInfoCache.invalidate(tmplt.getTemplateName());
}
}
}
Aggregations