Search in sources :

Example 36 with TemplateDTO

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();
}
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 37 with TemplateDTO

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);
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) Snippet(org.apache.nifi.controller.Snippet) Date(java.util.Date) Template(org.apache.nifi.controller.Template)

Example 38 with TemplateDTO

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);
    }
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) Element(org.w3c.dom.Element) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 39 with TemplateDTO

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();
    });
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) TemplateEntity(org.apache.nifi.web.api.entity.TemplateEntity) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 40 with TemplateDTO

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);
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) Before(org.junit.Before)

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