Search in sources :

Example 61 with FeedMetadata

use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.

the class FeedRestController method getFeedByName.

@GET
@Path("/by-name/{feedName}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the specified feed.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the feed.", response = FeedMetadata.class), @ApiResponse(code = 500, message = "The feed is unavailable.", response = RestResponseStatus.class) })
public Response getFeedByName(@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);
        return Response.ok(feed).build();
    } else {
        throw new NotFoundException("Unable to find the feed for name: " + feedName);
    }
}
Also used : FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) VersionNotFoundException(com.thinkbiganalytics.metadata.modeshape.versioning.VersionNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 62 with FeedMetadata

use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.

the class FeedRestController method profileStats.

@GET
@Path("/{feedId}/profile-stats")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the profile statistics for the specified job.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the profile statistics.", response = Map.class, responseContainer = "List"), @ApiResponse(code = 500, message = "The profile is unavailable.", response = RestResponseStatus.class) })
public Response profileStats(@PathParam("feedId") String feedId, @QueryParam("processingdttm") String processingdttm) {
    FeedMetadata feedMetadata = getMetadataService().getFeedById(feedId);
    String profileTable = feedMetadata.getProfileTableName();
    String query = "SELECT * from " + HiveUtils.quoteIdentifier(profileTable) + " where processing_dttm = " + HiveUtils.quoteString(processingdttm);
    QueryResult rows = hiveService.query(query);
    return Response.ok(rows.getRows()).build();
}
Also used : QueryResult(com.thinkbiganalytics.discovery.schema.QueryResult) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 63 with FeedMetadata

use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.

the class RegisteredTemplateService method mergeTemplatePropertiesWithFeed.

public FeedMetadata mergeTemplatePropertiesWithFeed(FeedMetadata feedMetadata) {
    // gets the feed data and then gets the latest template associated with that feed and merges the properties into the feed
    RegisteredTemplate registeredTemplate = findRegisteredTemplate(new RegisteredTemplateRequest.Builder().templateId(feedMetadata.getTemplateId()).isFeedEdit(true).nifiTemplateId(feedMetadata.getTemplateId()).includeAllProperties(true).build());
    if (registeredTemplate != null) {
        feedMetadata.setTemplateId(registeredTemplate.getId());
        List<NifiProperty> templateProperties = registeredTemplate.getProperties().stream().map(nifiProperty -> new NifiProperty(nifiProperty)).collect(Collectors.toList());
        NifiPropertyUtil.matchAndSetPropertyByProcessorName(templateProperties, feedMetadata.getProperties(), NifiPropertyUtil.PROPERTY_MATCH_AND_UPDATE_MODE.FEED_DETAILS_MATCH_TEMPLATE);
        // detect template properties that dont match the feed.properties from the registeredtemplate
        ensureFeedPropertiesExistInTemplate(feedMetadata, templateProperties);
        feedMetadata.setProperties(templateProperties);
        registeredTemplate.setProperties(templateProperties);
        registeredTemplate.initializeProcessors();
        feedMetadata.setRegisteredTemplate(registeredTemplate);
    }
    return feedMetadata;
}
Also used : Action(com.thinkbiganalytics.security.action.Action) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) TEMPLATE_TRANSFORMATION_TYPE(com.thinkbiganalytics.feedmgr.service.template.TemplateModelTransform.TEMPLATE_TRANSFORMATION_TYPE) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) HashMap(java.util.HashMap) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) NifiFeedConstants(com.thinkbiganalytics.nifi.rest.support.NifiFeedConstants) StringUtils(org.apache.commons.lang3.StringUtils) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) NiFiRemoteProcessGroup(com.thinkbiganalytics.nifi.rest.model.NiFiRemoteProcessGroup) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) TemplateAccessControl(com.thinkbiganalytics.metadata.api.template.security.TemplateAccessControl) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) NifiTemplateUtil(com.thinkbiganalytics.nifi.rest.support.NifiTemplateUtil) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) FeedManagerTemplateProvider(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplateProvider) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Logger(org.slf4j.Logger) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Principal(java.security.Principal) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) AccessControlException(java.security.AccessControlException) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)

Example 64 with FeedMetadata

use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.

the class ImportUtil method applyImportPropertiesToFeed.

public static boolean applyImportPropertiesToFeed(FeedMetadata metadata, ImportFeed importFeed, ImportComponent component) {
    ImportComponentOption option = importFeed.getImportOptions().findImportComponentOption(component);
    if (!option.getProperties().isEmpty() && option.getProperties().stream().anyMatch(importProperty -> StringUtils.isBlank(importProperty.getPropertyValue()))) {
        importFeed.setSuccess(false);
        if (importFeed.getTemplate() == null) {
            ImportTemplate importTemplate = new ImportTemplate(importFeed.getFileName());
            importFeed.setTemplate(importTemplate);
        }
        String feedCategory = importFeed.getImportOptions().getCategorySystemName() != null ? importFeed.getImportOptions().getCategorySystemName() : metadata.getSystemCategoryName();
        String msg = "The feed " + FeedNameUtil.fullName(feedCategory, metadata.getSystemFeedName()) + " needs additional properties to be supplied before importing.";
        importFeed.addErrorMessage(metadata, msg);
        option.getErrorMessages().add(msg);
        return false;
    } else {
        metadata.getSensitiveProperties().forEach(nifiProperty -> {
            ImportProperty userSuppliedValue = importFeed.getImportOptions().getProperties(ImportComponent.FEED_DATA).stream().filter(importFeedProperty -> {
                return nifiProperty.getProcessorId().equalsIgnoreCase(importFeedProperty.getProcessorId()) && nifiProperty.getKey().equalsIgnoreCase(importFeedProperty.getPropertyKey());
            }).findFirst().orElse(null);
            // deal with nulls?
            if (userSuppliedValue != null) {
                nifiProperty.setValue(userSuppliedValue.getPropertyValue());
            }
        });
        return true;
    }
}
Also used : FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) StringUtils(org.apache.commons.lang3.StringUtils) ImportOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportOptions) HashSet(java.util.HashSet) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) ImportProperty(com.thinkbiganalytics.feedmgr.rest.model.ImportProperty) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImportType(com.thinkbiganalytics.feedmgr.rest.ImportType) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) ZipEntry(java.util.zip.ZipEntry) Nonnull(javax.annotation.Nonnull) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ZipFileUtil(com.thinkbiganalytics.feedmgr.support.ZipFileUtil) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ImportFeed(com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed) Optional(java.util.Optional) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) InputStream(java.io.InputStream) ImportProperty(com.thinkbiganalytics.feedmgr.rest.model.ImportProperty) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)

Example 65 with FeedMetadata

use of com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata in project kylo by Teradata.

the class ImportUtil method replaceDatasource.

/**
 * Replaces the specified data source id with a new data source id.
 *
 * @param metadata the feed metadata
 * @param oldDatasourceId the id of the data source to be replaced
 * @param newDatasourceId the id of the new data source
 */
@SuppressWarnings("unchecked")
public static void replaceDatasource(@Nonnull final FeedMetadata metadata, @Nonnull final String oldDatasourceId, @Nonnull final String newDatasourceId) {
    // Update data transformation
    final FeedDataTransformation transformation = metadata.getDataTransformation();
    if (transformation != null) {
        // Update chart view model
        Optional.of(transformation.getChartViewModel()).map(model -> (List<Map<String, Object>>) model.get("nodes")).ifPresent(nodes -> nodes.forEach(node -> {
            final String nodeDatasourceId = (String) node.get("datasourceId");
            if (nodeDatasourceId != null && oldDatasourceId.equals(nodeDatasourceId)) {
                node.put("datasourceId", newDatasourceId);
            }
        }));
        // Update data source id list
        transformation.getDatasourceIds().replaceAll(id -> oldDatasourceId.equals(id) ? newDatasourceId : id);
        // Update transform script
        final String updatedDataTransformScript = transformation.getDataTransformScript().replace(oldDatasourceId, newDatasourceId);
        transformation.setDataTransformScript(updatedDataTransformScript);
    }
    // Update processor properties
    metadata.getProperties().forEach(property -> {
        final String value = property.getValue();
        if (value != null && !value.isEmpty()) {
            property.setValue(value.replace(oldDatasourceId, newDatasourceId));
        }
    });
}
Also used : FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) StringUtils(org.apache.commons.lang3.StringUtils) ImportOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportOptions) HashSet(java.util.HashSet) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) ImportProperty(com.thinkbiganalytics.feedmgr.rest.model.ImportProperty) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImportType(com.thinkbiganalytics.feedmgr.rest.ImportType) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) ZipEntry(java.util.zip.ZipEntry) Nonnull(javax.annotation.Nonnull) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ZipFileUtil(com.thinkbiganalytics.feedmgr.support.ZipFileUtil) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ImportFeed(com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed) Optional(java.util.Optional) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) InputStream(java.io.InputStream) FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) List(java.util.List)

Aggregations

FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)76 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)26 NifiFeed (com.thinkbiganalytics.feedmgr.rest.model.NifiFeed)23 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)21 ArrayList (java.util.ArrayList)21 List (java.util.List)20 Collectors (java.util.stream.Collectors)20 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)18 Set (java.util.Set)18 StringUtils (org.apache.commons.lang3.StringUtils)18 UIFeed (com.thinkbiganalytics.feedmgr.rest.model.UIFeed)17 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)17 FeedSummary (com.thinkbiganalytics.feedmgr.rest.model.FeedSummary)16 Map (java.util.Map)16 Inject (javax.inject.Inject)16 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)15 AccessController (com.thinkbiganalytics.security.AccessController)15 Optional (java.util.Optional)15