Search in sources :

Example 1 with ImportException

use of com.thinkbiganalytics.feedmgr.service.template.importing.ImportException in project kylo by Teradata.

the class FeedImporter method init.

private void init() {
    this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.IMPORT_FEEDS);
    UploadProgressMessage feedImportStatusMessage = uploadProgressService.addUploadStatus(importFeedOptions.getUploadKey(), "Initialize feed import.");
    try {
        boolean isValid = isValidFileImport(fileName) && ZipFileUtil.validateZipEntriesWithRequiredEntries(file, getValidZipFileEntries(), Sets.newHashSet(ImportFeed.FEED_JSON_FILE));
        if (!isValid) {
            feedImportStatusMessage.update("Validation error. Feed import error. The zip file you uploaded is not valid feed export.", false);
            throw new ImportFeedException("The zip file you uploaded is not valid feed export.");
        }
        // get the Feed Data
        importFeed = readFeedJson(fileName, file);
        // initially mark as valid.
        importFeed.setValid(true);
        // merge in the file components to the user options
        Set<ImportComponentOption> componentOptions = ImportUtil.inspectZipComponents(file, ImportType.FEED);
        importFeedOptions.addOptionsIfNotExists(componentOptions);
        // importFeedOptions.findImportComponentOption(ImportComponent.TEMPLATE_CONNECTION_INFORMATION).addConnectionInfo(importFeed.getReusableTemplateConnections());
        importFeed.setImportOptions(importFeedOptions);
        feedImportStatusMessage.complete(true);
    } catch (Exception e) {
        throw new ImportException("Unable to import feed. ", e);
    }
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) ImportException(com.thinkbiganalytics.feedmgr.service.template.importing.ImportException) ImportFeedException(com.thinkbiganalytics.feedmgr.service.feed.ImportFeedException) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ImportFeedException(com.thinkbiganalytics.feedmgr.service.feed.ImportFeedException) IOException(java.io.IOException) ImportException(com.thinkbiganalytics.feedmgr.service.template.importing.ImportException)

Example 2 with ImportException

use of com.thinkbiganalytics.feedmgr.service.template.importing.ImportException in project kylo by Teradata.

the class AbstractImportTemplateRoutine method importIntoNiFi.

/**
 * Import a template string into NiFi as a template to use
 */
public NiFiTemplateImport importIntoNiFi(ImportTemplate template, ImportTemplateOptions importOptions) throws ImportException {
    TemplateDTO dto = null;
    String templateName = null;
    String oldTemplateXml = null;
    ImportComponentOption nifiTemplateImport = importOptions.findImportComponentOption(ImportComponent.NIFI_TEMPLATE);
    if (nifiTemplateImport.isValidForImport()) {
        try {
            templateName = NifiTemplateParser.getTemplateName(template.getNifiTemplateXml());
            template.setTemplateName(templateName);
            dto = nifiRestClient.getTemplateByName(templateName);
            if (dto != null) {
                oldTemplateXml = nifiRestClient.getTemplateXml(dto.getId());
                template.setNifiTemplateId(dto.getId());
                if (importOptions.isImportAndOverwrite(ImportComponent.NIFI_TEMPLATE) && nifiTemplateImport.isValidForImport()) {
                    nifiRestClient.deleteTemplate(dto.getId());
                } else if (!template.isZipFile()) {
                    // if its not a zip file we need to error out if the user has decided not to overwrite when it already exists
                    uploadProgressService.addUploadStatus(importOptions.getUploadKey(), "The template " + templateName + " already exists in NiFi. Please choose the option to replace the template and try again.", true, false);
                    template.setValid(false);
                }
            }
        } catch (ParserConfigurationException | XPathExpressionException | IOException | SAXException e) {
            throw new ImportException("The xml file you are trying to import is not a valid NiFi template.  Please try again. " + e.getMessage());
        }
        boolean register = (dto == null || (importOptions.isImportAndOverwrite(ImportComponent.NIFI_TEMPLATE) && nifiTemplateImport.isValidForImport()));
        // attempt to import the xml into NiFi if its new, or if the user said to overwrite
        if (register) {
            UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importOptions.getUploadKey(), "Importing " + templateName + " into NiFi");
            log.info("Attempting to import Nifi Template: {} for file {}", templateName, template.getFileName());
            dto = nifiRestClient.importTemplate(template.getTemplateName(), template.getNifiTemplateXml());
            template.setNifiTemplateId(dto.getId());
            statusMessage.update("Imported " + templateName + " into NiFi", true);
        }
    }
    uploadProgressService.completeSection(importOptions, ImportSection.Section.IMPORT_NIFI_TEMPLATE);
    return new NiFiTemplateImport(oldTemplateXml, dto);
}
Also used : ImportException(com.thinkbiganalytics.feedmgr.service.template.importing.ImportException) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NiFiTemplateImport(com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 3 with ImportException

use of com.thinkbiganalytics.feedmgr.service.template.importing.ImportException in project kylo by Teradata.

the class AbstractImportTemplateRoutine method initializeImportTemplateFromXml.

private void initializeImportTemplateFromXml(String fileName, byte[] xmlFile) throws ImportException {
    try {
        InputStream inputStream = new ByteArrayInputStream(xmlFile);
        this.importTemplate = ImportUtil.getNewNiFiTemplateImport(fileName, inputStream);
        importTemplate.setImportOptions(this.importTemplateOptions);
    } catch (IOException e) {
        throw new ImportException(e);
    }
}
Also used : ImportException(com.thinkbiganalytics.feedmgr.service.template.importing.ImportException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Aggregations

ImportException (com.thinkbiganalytics.feedmgr.service.template.importing.ImportException)3 IOException (java.io.IOException)3 ImportComponentOption (com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)2 UploadProgressMessage (com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)2 ImportFeedException (com.thinkbiganalytics.feedmgr.service.feed.ImportFeedException)1 NiFiTemplateImport (com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)1 SAXException (org.xml.sax.SAXException)1