use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class FeedImporter method importFeed.
// Import
/**
* Import a feed zip file
*/
private ImportFeed importFeed() throws Exception {
// read the JSON into the Feed object
FeedMetadata metadata = importFeed.getFeedToImport();
// query for this feed.
String feedCategory = StringUtils.isNotBlank(importFeedOptions.getCategorySystemName()) ? importFeedOptions.getCategorySystemName() : metadata.getSystemCategoryName();
FeedMetadata existingFeed = metadataAccess.read(() -> metadataService.getFeedByName(feedCategory, metadata.getSystemFeedName()));
metadata.getCategory().setSystemName(feedCategory);
ImportTemplateOptions importTemplateOptions = new ImportTemplateOptions();
importTemplateOptions.setImportComponentOptions(importFeedOptions.getImportComponentOptions());
importTemplateOptions.findImportComponentOption(ImportComponent.TEMPLATE_DATA).setContinueIfExists(true);
ImportTemplate importTemplate = importFeed.getTemplate();
importTemplate.setImportOptions(importTemplateOptions);
importTemplateOptions.setUploadKey(importFeedOptions.getUploadKey());
importTemplate.setValid(true);
importTemplateOptions.setDeferCleanup(true);
// Import the Template
ImportTemplateRoutine importTemplateRoutine = importTemplateRoutineFactory.apply(importTemplate, importTemplateOptions, ImportTemplate.TYPE.ARCHIVE);
importTemplateRoutine.importTemplate();
if (importTemplate.isSuccess()) {
// import the feed
importFeed.setTemplate(importTemplate);
// now that we have the Feed object we need to create the instance of the feed
UploadProgressMessage uploadProgressMessage = uploadProgressService.addUploadStatus(importFeedOptions.getUploadKey(), "Saving and creating feed instance in NiFi");
metadata.setIsNew(existingFeed == null ? true : false);
metadata.setFeedId(existingFeed != null ? existingFeed.getFeedId() : null);
metadata.setId(existingFeed != null ? existingFeed.getId() : null);
// reassign the templateId to the newly registered template id
metadata.setTemplateId(importTemplate.getTemplateId());
if (metadata.getRegisteredTemplate() != null) {
metadata.getRegisteredTemplate().setNifiTemplateId(importTemplate.getNifiTemplateId());
metadata.getRegisteredTemplate().setId(importTemplate.getTemplateId());
}
// get/create category
FeedCategory category = metadataService.getCategoryBySystemName(metadata.getCategory().getSystemName());
if (category == null) {
metadata.getCategory().setId(null);
metadataService.saveCategory(metadata.getCategory());
} else {
metadata.setCategory(category);
}
if (importFeedOptions.isDisableUponImport()) {
metadata.setActive(false);
metadata.setState(FeedMetadata.STATE.DISABLED.name());
}
// remap any preconditions to this new feed/category name.
if (metadata.getSchedule().hasPreconditions()) {
metadata.getSchedule().getPreconditions().stream().flatMap(preconditionRule -> preconditionRule.getProperties().stream()).filter(fieldRuleProperty -> PolicyPropertyTypes.PROPERTY_TYPE.currentFeed.name().equals(fieldRuleProperty.getType())).forEach(fieldRuleProperty -> fieldRuleProperty.setValue(metadata.getCategoryAndFeedName()));
}
// //for all those properties where the template value is != userEditable and the template value has a metadata. property, remove that property from the feed properties so it can be imported and assigned correctly
RegisteredTemplate template1 = registeredTemplateService.findRegisteredTemplateById(importTemplate.getTemplateId());
if (template1 != null) {
// Find all the properties in the template that have ${metadata. and are not userEditable.
// These are the properties we need to replace on the feed metadata
List<NifiProperty> metadataProperties = template1.getProperties().stream().filter(nifiProperty -> {
return nifiProperty != null && StringUtils.isNotBlank(nifiProperty.getValue()) && !nifiProperty.isUserEditable() && nifiProperty.getValue().contains("${" + MetadataFieldAnnotationFieldNameResolver.metadataPropertyPrefix);
}).collect(Collectors.toList());
// Replace the Feed Metadata properties with those that match the template ones from above.
List<NifiProperty> updatedProperties = metadata.getProperties().stream().map(nifiProperty -> {
NifiProperty p = NifiPropertyUtil.findPropertyByProcessorName(metadataProperties, nifiProperty);
return p != null ? p : nifiProperty;
}).collect(Collectors.toList());
metadata.setProperties(updatedProperties);
}
NifiFeed nifiFeed = metadataService.createFeed(metadata);
if (nifiFeed != null) {
importFeed.setFeedName(nifiFeed.getFeedMetadata().getCategoryAndFeedName());
if (nifiFeed.isSuccess()) {
uploadProgressMessage.update("Successfully saved the feed " + importFeed.getFeedName(), true);
} else {
if (nifiFeed.getFeedProcessGroup() != null && nifiFeed.getFeedProcessGroup().isRolledBack()) {
if (importTemplateRoutine != null) {
importTemplateRoutine.rollback();
}
}
uploadProgressMessage.update("Errors were found importing the feed " + importFeed.getFeedName(), false);
}
importTemplateRoutine.cleanup();
}
importFeed.setNifiFeed(nifiFeed);
importFeed.setSuccess(nifiFeed != null && nifiFeed.isSuccess());
} else {
importFeed.setSuccess(false);
importFeed.setTemplate(importTemplate);
importFeed.addErrorMessage(existingFeed, "The feed " + FeedNameUtil.fullName(feedCategory, metadata.getSystemFeedName()) + " needs additional properties to be supplied before importing.");
}
uploadProgressService.completeSection(importFeedOptions, ImportSection.Section.IMPORT_FEED_DATA);
return importFeed;
}
use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class FeedRestController method populateFeed.
private void populateFeed(EditFeedEntity editFeedEntity) {
// fetch the feed
FeedMetadata feed = getMetadataService().getFeedById(editFeedEntity.getFeedMetadata().getFeedId());
FeedMetadata editFeed = editFeedEntity.getFeedMetadata();
switch(editFeedEntity.getAction()) {
case SUMMARY:
updateFeedMetadata(feed, editFeed, FeedPropertySection.SUMMARY);
break;
case NIFI_PROPERTIES:
updateFeedMetadata(feed, editFeed, FeedPropertySection.NIFI_PROPERTIES);
break;
case PROPERTIES:
updateFeedMetadata(feed, editFeed, FeedPropertySection.PROPERTIES);
break;
case TABLE_DATA:
updateFeedMetadata(feed, editFeed, FeedPropertySection.TABLE_DATA);
break;
case SCHEDULE:
updateFeedMetadata(feed, editFeed, FeedPropertySection.SCHEDULE);
break;
default:
break;
}
createFeed(feed);
}
use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class FeedRestController method getFeedFieldPoliciesByName.
@GET
@Path("/by-name/{feedName}/field-policies")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the specified feed.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the feed field policies (List<FieldPolicy>) as json.", response = List.class), @ApiResponse(code = 500, message = "The feed is unavailable.", response = RestResponseStatus.class) })
public Response getFeedFieldPoliciesByName(@PathParam("feedName") String feedName) {
String categorySystemName = FeedNameUtil.category(feedName);
String feedSystemName = FeedNameUtil.feed(feedName);
if (StringUtils.isNotBlank(categorySystemName) && StringUtils.isNotBlank(feedSystemName)) {
FeedMetadata feed = getMetadataService().getFeedByName(categorySystemName, feedSystemName);
if (feed != null && feed.getTable() != null) {
return Response.ok(feed.getTable().getFieldPoliciesJson()).build();
} else {
throw new NotFoundException("Unable to find the feed field policies for name: " + feedName);
}
} else {
throw new NotFoundException("Unable to find the feed field policies for name: " + feedName);
}
}
use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class FeedRestController method getNifiProperties.
private List<NifiProperty> getNifiProperties(String feedId) {
FeedMetadata feed = getMetadataService().getFeedById(feedId, false);
feed = registeredTemplateService.mergeTemplatePropertiesWithFeed(feed);
propertyExpressionResolver.resolvePropertyExpressions(feed);
return feed.getProperties();
}
use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.
the class FeedRestController method queryProfileInvalidResults.
@GET
@Path("/{feedId}/profile-invalid-results")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets statistics on the invalid rows for the specified job.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the invalid row statistics.", response = Map.class, responseContainer = "List"), @ApiResponse(code = 500, message = "The profile is unavailable.", response = RestResponseStatus.class) })
public Response queryProfileInvalidResults(@PathParam("feedId") String feedId, @QueryParam("processingdttm") String processingdttm, @QueryParam("limit") int limit, @QueryParam("filter") String filter) {
FeedMetadata feedMetadata = getMetadataService().getFeedById(feedId);
String condition = "";
if (StringUtils.isNotBlank(filter)) {
condition = " and dlp_reject_reason like " + HiveUtils.quoteString("%" + filter + "%") + " ";
}
return getPage(processingdttm, limit, feedMetadata.getInvalidTableName(), condition);
}
Aggregations