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;
}
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);
}
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();
}
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();
}
}
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());
}
Aggregations