use of org.apache.nifi.web.api.dto.TemplateDTO in project kylo by Teradata.
the class NifiRestTest method testCreateFeed.
// @Test
public void testCreateFeed() throws Exception {
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 by apache.
the class StandardNiFiServiceFacade method createTemplate.
@Override
public TemplateDTO createTemplate(final String name, final String description, final String snippetId, final String groupId, final Optional<String> idGenerationSeed) {
// get the specified snippet
final Snippet snippet = snippetDAO.getSnippet(snippetId);
// create the template
final TemplateDTO templateDTO = new TemplateDTO();
templateDTO.setName(name);
templateDTO.setDescription(description);
templateDTO.setTimestamp(new Date());
templateDTO.setSnippet(snippetUtils.populateFlowSnippet(snippet, true, true, true));
templateDTO.setEncodingVersion(TemplateDTO.MAX_ENCODING_VERSION);
// set the id based on the specified seed
final String uuid = idGenerationSeed.isPresent() ? (UUID.nameUUIDFromBytes(idGenerationSeed.get().getBytes(StandardCharsets.UTF_8))).toString() : UUID.randomUUID().toString();
templateDTO.setId(uuid);
// create the template
final Template template = templateDAO.createTemplate(templateDTO, groupId);
// drop the snippet
snippetDAO.dropSnippet(snippetId);
// save the flow
controllerFacade.save();
return dtoFactory.createTemplateDTO(template);
}
use of org.apache.nifi.web.api.dto.TemplateDTO in project nifi by apache.
the class StandardFlowSynchronizer method addLocalTemplates.
private void addLocalTemplates(final Element processGroupElement, final ProcessGroup processGroup, final FlowEncodingVersion encodingVersion) {
// Replace the templates with those from the proposed flow
final List<Element> templateNodeList = getChildrenByTagName(processGroupElement, "template");
if (templateNodeList != null) {
for (final Element templateElement : templateNodeList) {
final TemplateDTO templateDto = TemplateUtils.parseDto(templateElement);
final Template template = new Template(templateDto);
// If the Process Group does not have the template, add it.
if (processGroup.getTemplate(template.getIdentifier()) == null) {
processGroup.addTemplate(template);
}
}
}
final List<Element> childGroupElements = getChildrenByTagName(processGroupElement, "processGroup");
for (final Element childGroupElement : childGroupElements) {
final String childGroupId = getString(childGroupElement, "id");
final ProcessGroup childGroup = processGroup.getProcessGroup(childGroupId);
addLocalTemplates(childGroupElement, childGroup, encodingVersion);
}
}
use of org.apache.nifi.web.api.dto.TemplateDTO in project nifi by apache.
the class ProcessGroupResource method createTemplate.
/**
* Creates a new template based off of the specified template.
*
* @param httpServletRequest request
* @param requestCreateTemplateRequestEntity request to create the template
* @return A templateEntity
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/templates")
@ApiOperation(value = "Creates a template and discards the specified snippet.", response = TemplateEntity.class, authorizations = { @Authorization(value = "Write - /process-groups/{uuid}"), @Authorization(value = "Read - /{component-type}/{uuid} - For each component in the snippet and their descendant components") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response createTemplate(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId, @ApiParam(value = "The create template request.", required = true) final CreateTemplateRequestEntity requestCreateTemplateRequestEntity) {
if (requestCreateTemplateRequestEntity.getSnippetId() == null) {
throw new IllegalArgumentException("The snippet identifier must be specified.");
}
if (isReplicateRequest()) {
return replicate(HttpMethod.POST, requestCreateTemplateRequestEntity);
}
return withWriteLock(serviceFacade, requestCreateTemplateRequestEntity, lookup -> {
authorizeSnippetUsage(lookup, groupId, requestCreateTemplateRequestEntity.getSnippetId(), true);
}, () -> serviceFacade.verifyCanAddTemplate(groupId, requestCreateTemplateRequestEntity.getName()), createTemplateRequestEntity -> {
// create the template and generate the json
final TemplateDTO template = serviceFacade.createTemplate(createTemplateRequestEntity.getName(), createTemplateRequestEntity.getDescription(), createTemplateRequestEntity.getSnippetId(), groupId, getIdGenerationSeed());
templateResource.populateRemainingTemplateContent(template);
// build the response entity
final TemplateEntity entity = new TemplateEntity();
entity.setTemplate(template);
// build the response
return generateCreatedResponse(URI.create(template.getUri()), entity).build();
});
}
use of org.apache.nifi.web.api.dto.TemplateDTO in project nifi-minifi by apache.
the class FlowControllerSchemaTest method setup.
@Before
public void setup() {
dto = new TemplateDTO();
dto.setName(testName);
dto.setDescription(testComment);
map = new HashMap<>();
map.put(CommonPropertyKeys.NAME_KEY, testName);
map.put(CommonPropertyKeys.COMMENT_KEY, testComment);
}
Aggregations