Search in sources :

Example 21 with TemplateDTO

use of org.apache.nifi.web.api.dto.TemplateDTO in project kylo by Teradata.

the class ImportTemplateArchive method create.

@Override
public NifiProcessGroup create(NiFiTemplateImport niFiTemplateImport, UploadProgressMessage importStatusMessage) {
    log.info("Importing Zip file template {}, overwrite: {}, reusableFlow: {}", importTemplate.getFileName(), this.importTemplateOptions.isImportAndOverwrite(ImportComponent.TEMPLATE_DATA), importTemplateOptions.isImport(ImportComponent.REUSABLE_TEMPLATE));
    if (importTemplate.isValid()) {
    }
    TemplateDTO dto = niFiTemplateImport.getDto();
    String templateName = importTemplate.getTemplateName();
    String fileName = importTemplate.getFileName();
    importStatusMessage.update("Importing the NiFi flow, " + templateName);
    log.info("Creating a template instance in Nifi. Template: {} for file {}", templateName, fileName);
    Map<String, Object> configProperties = propertyExpressionResolver.getStaticConfigProperties();
    List<NifiProperty> templateProperties = importTemplate.getTemplateToImport() != null ? importTemplate.getTemplateToImport().getProperties() : Collections.emptyList();
    this.newTemplateInstance = nifiRestClient.createNewTemplateInstance(dto.getId(), templateProperties, configProperties, false, null, importTemplate.getVersionIdentifier());
    importTemplate.setTemplateResults(newTemplateInstance);
    if (newTemplateInstance.getVersionedProcessGroup() != null && StringUtils.isNotBlank(newTemplateInstance.getVersionedProcessGroup().getVersionedProcessGroupName())) {
        uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Versioned off previous flow with the name: " + newTemplateInstance.getVersionedProcessGroup().getVersionedProcessGroupName(), true, true);
    }
    return newTemplateInstance;
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty)

Example 22 with TemplateDTO

use of org.apache.nifi.web.api.dto.TemplateDTO in project kylo by Teradata.

the class ValidateImportTemplatesArchive method validateReusableTemplate.

/**
 * Validate any reusable templates as part of a zip file upload are valid for importing
 */
private void validateReusableTemplate() {
    // validate the reusable template
    if (this.importTemplate.hasConnectingReusableTemplate()) {
        ImportComponentOption reusableTemplateOption = this.importTemplateOptions.findImportComponentOption(ImportComponent.REUSABLE_TEMPLATE);
        UploadProgressMessage reusableTemplateStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Validating Reusable Template. ");
        if (reusableTemplateOption.isShouldImport()) {
            boolean validForImport = true;
            // for each of the connecting template
            for (String reusableTemplateXml : this.importTemplate.getNifiConnectingReusableTemplateXmls()) {
                try {
                    String templateName = NifiTemplateParser.getTemplateName(reusableTemplateXml);
                    UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Validating Reusable Template. " + templateName);
                    TemplateDTO dto = nifiRestClient.getTemplateByName(templateName);
                    // if there is a match and it has not been acknowledged by the user to overwrite or not, error out
                    if (dto != null && !reusableTemplateOption.isUserAcknowledged()) {
                        // error out it exists
                        this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.REUSABLE_TEMPLATE, "A reusable template with the same name " + templateName + " exists.");
                        this.importTemplate.setValid(false);
                        statusMessage.update("Reusable template, " + templateName + ", already exists.", false);
                        validForImport = false;
                    } else if (dto != null && reusableTemplateOption.isUserAcknowledged() && !reusableTemplateOption.isOverwrite()) {
                        validForImport = false;
                        // user has asked to not import the template.
                        uploadProgressService.removeMessage(importTemplateOptions.getUploadKey(), statusMessage);
                    } else {
                        uploadProgressService.removeMessage(importTemplateOptions.getUploadKey(), statusMessage);
                        // statusMessage.update("Validated Reusable Template", true);
                        validForImport &= true;
                    }
                } catch (Exception e) {
                    log.error("Error parsing template name from file {} ", fileName, e);
                    validForImport = false;
                }
            }
            reusableTemplateOption.setValidForImport(validForImport);
            reusableTemplateStatusMessage.update("Validated Reusable Templates ", !reusableTemplateOption.hasErrorMessages());
        } else if (!reusableTemplateOption.isUserAcknowledged()) {
            this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.REUSABLE_TEMPLATE, "The file " + this.importTemplate.getFileName() + " has a reusable template to import.");
            this.importTemplate.setValid(false);
            reusableTemplateStatusMessage.update("A reusable template was found. Additional input needed.", false);
        } else {
            reusableTemplateStatusMessage.update("Reusable template found in import, but it is not marked for importing", true);
        }
    }
    this.uploadProgressService.completeSection(this.importTemplateOptions, ImportSection.Section.VALIDATE_REUSABLE_TEMPLATE);
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)

Example 23 with TemplateDTO

use of org.apache.nifi.web.api.dto.TemplateDTO in project kylo by Teradata.

the class NifiRestTest method testCreateFeed1.

// @Test
public void testCreateFeed1() {
    TemplateDTO templateDTO = restClient.getTemplateByName("New Data Ingest");
    String inputType = "org.apache.nifi.processors.standard.GetFile";
    NifiProcessorSchedule schedule = new NifiProcessorSchedule();
    schedule.setSchedulingStrategy("TIMER_DRIVEN");
    schedule.setSchedulingPeriod("10 sec");
    String inputPortName = "From Data Ingest Feed";
    String feedOutputPortName = "To Data Ingest";
    FeedMetadata feedMetadata = new FeedMetadata();
    feedMetadata.setCategory(new FeedCategory());
    feedMetadata.getCategory().setSystemName("online");
    feedMetadata.setSystemFeedName("Scotts Feed");
    CreateFeedBuilder.newFeed(restClient, nifiFlowCache, feedMetadata, templateDTO.getId(), new PropertyExpressionResolver(), propertyDescriptorTransform, createFeedBuilderCache, templateConnectionUtil).inputProcessorType(inputType).feedSchedule(schedule).addInputOutputPort(new InputOutputPort(inputPortName, feedOutputPortName)).build();
}
Also used : FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) InputOutputPort(com.thinkbiganalytics.nifi.feedmgr.InputOutputPort) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) NifiProcessorSchedule(com.thinkbiganalytics.nifi.rest.model.NifiProcessorSchedule)

Example 24 with TemplateDTO

use of org.apache.nifi.web.api.dto.TemplateDTO in project nifi-minifi by apache.

the class ConfigMain method transformTemplateToSchema.

public static ConfigSchema transformTemplateToSchema(InputStream source) throws JAXBException, IOException {
    try {
        TemplateDTO templateDTO = (TemplateDTO) JAXBContext.newInstance(TemplateDTO.class).createUnmarshaller().unmarshal(source);
        FlowSnippetDTOEnricher enricher = new FlowSnippetDTOEnricher();
        enricher.enrich(templateDTO.getSnippet(), templateDTO.getEncodingVersion());
        ConfigSchema configSchema = new ConfigSchemaFunction().apply(templateDTO);
        return configSchema;
    } finally {
        source.close();
    }
}
Also used : NiFiRegConfigSchemaFunction(org.apache.nifi.minifi.toolkit.configuration.registry.NiFiRegConfigSchemaFunction) ConfigSchemaFunction(org.apache.nifi.minifi.toolkit.configuration.dto.ConfigSchemaFunction) FlowSnippetDTOEnricher(org.apache.nifi.minifi.toolkit.configuration.dto.FlowSnippetDTOEnricher) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema)

Example 25 with TemplateDTO

use of org.apache.nifi.web.api.dto.TemplateDTO in project kylo by Teradata.

the class AbstractNiFiTemplatesRestClientTest method findByName.

/**
 * Verifies finding templates by matching the template name
 */
@Test
public void findByName() {
    // Mock templates
    final TemplateDTO template1 = new TemplateDTO();
    template1.setName("temp1");
    final TemplateDTO template2 = new TemplateDTO();
    template2.setName("temp2");
    final TemplateDTO template3 = new TemplateDTO();
    template3.setName("temp3");
    // Mock the NiFi Templates REST client
    final NiFiTemplatesRestClient client = Mockito.mock(AbstractNiFiTemplatesRestClient.class, Mockito.CALLS_REAL_METHODS);
    Mockito.when(client.findAll()).thenReturn(ImmutableSet.of(template1, template2, template3));
    // Test finding matching template
    Assert.assertEquals(template2, client.findByName("temp2").get());
    Assert.assertFalse(client.findByName("invalid").isPresent());
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) Test(org.junit.Test)

Aggregations

TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)40 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 HashSet (java.util.HashSet)7 Produces (javax.ws.rs.Produces)7 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)7 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)6 HashMap (java.util.HashMap)6 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)6 Path (javax.ws.rs.Path)5 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)5 UploadProgressMessage (com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)4 Consumes (javax.ws.rs.Consumes)4 JAXBContext (javax.xml.bind.JAXBContext)4 JAXBException (javax.xml.bind.JAXBException)4 Unmarshaller (javax.xml.bind.Unmarshaller)4