Search in sources :

Example 26 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project nifi by apache.

the class NiFiWebApiTest method populateFlow.

public static void populateFlow(Client client, String baseUrl, NiFiTestUser user, String clientId) throws Exception {
    // -----------------------------------------------
    // Create a source processor
    // -----------------------------------------------
    // create the local selection processor
    ProcessorDTO processorDTO = new ProcessorDTO();
    processorDTO.setName("Pick up");
    processorDTO.setType(SourceTestProcessor.class.getName());
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(clientId);
    revision.setVersion(0l);
    // create the local selection processor entity
    ProcessorEntity processorEntity = new ProcessorEntity();
    processorEntity.setRevision(revision);
    processorEntity.setComponent(processorDTO);
    // add the processor
    Response response = user.testPost(baseUrl + "/process-groups/root/processors", processorEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // get the processors id
    processorEntity = response.readEntity(ProcessorEntity.class);
    processorDTO = processorEntity.getComponent();
    String localSelectionId = processorDTO.getId();
    String localSelectionGroupId = processorDTO.getParentGroupId();
    // -----------------------------------------------
    // Create a termination processor
    // -----------------------------------------------
    // create the termination processor
    processorDTO = new ProcessorDTO();
    processorDTO.setName("End");
    processorDTO.setType(TerminationTestProcessor.class.getName());
    // create the termination processor entity
    processorEntity = new ProcessorEntity();
    processorEntity.setRevision(revision);
    processorEntity.setComponent(processorDTO);
    // add the processor
    response = user.testPost(baseUrl + "/process-groups/root/processors", processorEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // get the processors id
    processorEntity = response.readEntity(ProcessorEntity.class);
    processorDTO = processorEntity.getComponent();
    String terminationId = processorDTO.getId();
    String terminationGroupId = processorDTO.getParentGroupId();
    // -----------------------------------------------
    // Connect the two processors
    // -----------------------------------------------
    ConnectableDTO source = new ConnectableDTO();
    source.setId(localSelectionId);
    source.setGroupId(localSelectionGroupId);
    source.setType(ConnectableType.PROCESSOR.name());
    ConnectableDTO target = new ConnectableDTO();
    target.setId(terminationId);
    target.setGroupId(terminationGroupId);
    target.setType(ConnectableType.PROCESSOR.name());
    // create the relationships
    Set<String> relationships = new HashSet<>();
    relationships.add("success");
    // create the connection
    ConnectionDTO connectionDTO = new ConnectionDTO();
    connectionDTO.setSource(source);
    connectionDTO.setDestination(target);
    connectionDTO.setSelectedRelationships(relationships);
    // create the connection entity
    ConnectionEntity connectionEntity = new ConnectionEntity();
    connectionEntity.setRevision(revision);
    connectionEntity.setComponent(connectionDTO);
    // add the processor
    response = user.testPost(baseUrl + "/process-groups/root/connections", connectionEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a label
    // -----------------------------------------------
    // create the label
    LabelDTO labelDTO = new LabelDTO();
    labelDTO.setLabel("Test label");
    // create the label entity
    LabelEntity labelEntity = new LabelEntity();
    labelEntity.setRevision(revision);
    labelEntity.setComponent(labelDTO);
    // add the label
    response = user.testPost(baseUrl + "/process-groups/root/labels", labelEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a funnel
    // -----------------------------------------------
    // create the funnel
    FunnelDTO funnelDTO = new FunnelDTO();
    // create the funnel entity
    FunnelEntity funnelEntity = new FunnelEntity();
    funnelEntity.setRevision(revision);
    funnelEntity.setComponent(funnelDTO);
    // add the funnel
    response = user.testPost(baseUrl + "/process-groups/root/funnels", funnelEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a process group
    // -----------------------------------------------
    // create the process group
    ProcessGroupDTO processGroup = new ProcessGroupDTO();
    processGroup.setName("group name");
    // create the process group entity
    ProcessGroupEntity processGroupEntity = new ProcessGroupEntity();
    processGroupEntity.setRevision(revision);
    processGroupEntity.setComponent(processGroup);
    // add the process group
    response = user.testPost(baseUrl + "/process-groups/root/process-groups", processGroupEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create an input port
    // -----------------------------------------------
    // create the input port
    PortDTO inputPort = new PortDTO();
    inputPort.setName("input");
    // create the input port entity
    PortEntity inputPortEntity = new PortEntity();
    inputPortEntity.setRevision(revision);
    inputPortEntity.setComponent(inputPort);
    // add the input port
    response = user.testPost(baseUrl + "/process-groups/root/input-ports", inputPortEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a output ports
    // -----------------------------------------------
    // create the process group
    PortDTO outputPort = new PortDTO();
    outputPort.setName("output");
    // create the process group entity
    PortEntity outputPortEntity = new PortEntity();
    outputPortEntity.setRevision(revision);
    outputPortEntity.setComponent(outputPort);
    // add the output port
    response = user.testPost(baseUrl + "/process-groups/root/output-ports", outputPortEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Response(javax.ws.rs.core.Response) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) TerminationTestProcessor(org.apache.nifi.integration.util.TerminationTestProcessor) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) SourceTestProcessor(org.apache.nifi.integration.util.SourceTestProcessor) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) HashSet(java.util.HashSet) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 27 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project nifi by apache.

the class ITProcessorAccessControl method createExecuteCodeRestrictedProcessor.

private void createExecuteCodeRestrictedProcessor(final NiFiTestUser user) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/processors";
    // create the processor
    ProcessorDTO processor = new ProcessorDTO();
    processor.setName("execute code restricted");
    processor.setType(ExecuteCodeRestrictedProcessor.class.getName());
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    ProcessorEntity entity = new ProcessorEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);
    // perform the request as a user with read/write but no restricted access
    Response response = helper.getReadWriteUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(403, response.getStatus());
    // perform the request as a user with read/write and restricted access
    response = user.testPost(url, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    final ProcessorEntity responseEntity = response.readEntity(ProcessorEntity.class);
    // remove the restricted component
    deleteRestrictedComponent(responseEntity, user);
}
Also used : Response(javax.ws.rs.core.Response) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ExecuteCodeRestrictedProcessor(org.apache.nifi.integration.util.ExecuteCodeRestrictedProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 28 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project nifi by apache.

the class ITProcessorAccessControl method createProcessor.

public static ProcessorEntity createProcessor(final AccessControlHelper ach, final String name) throws Exception {
    String url = ach.getBaseUrl() + "/process-groups/root/processors";
    // create the processor
    ProcessorDTO processor = new ProcessorDTO();
    processor.setName(name);
    processor.setType(SourceTestProcessor.class.getName());
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    ProcessorEntity entity = new ProcessorEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);
    // perform the request
    Response response = ach.getReadWriteUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    // get the entity body
    entity = response.readEntity(ProcessorEntity.class);
    // verify creation
    processor = entity.getComponent();
    assertEquals(name, processor.getName());
    assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
    // get the processor
    return entity;
}
Also used : Response(javax.ws.rs.core.Response) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) SourceTestProcessor(org.apache.nifi.integration.util.SourceTestProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 29 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project nifi by apache.

the class ITProcessorAccessControl method testWriteUserPutProcessor.

/**
 * Ensures the WRITE user can put a processor.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutProcessor() throws Exception {
    final ProcessorEntity entity = getRandomProcessor(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedName = "Updated Name";
    // attempt to update the name
    final ProcessorDTO requestDto = new ProcessorDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);
    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);
    final ProcessorEntity requestEntity = new ProcessorEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateProcessor(helper.getWriteUser(), requestEntity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final ProcessorEntity responseEntity = response.readEntity(ProcessorEntity.class);
    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
Also used : Response(javax.ws.rs.core.Response) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 30 with ProcessorDTO

use of org.apache.nifi.web.api.dto.ProcessorDTO in project nifi by apache.

the class ProcessorEntityMerger method mergeComponents.

/**
 * Merges the ProcessorEntity responses.
 *
 * @param clientEntity the entity being returned to the client
 * @param entityMap all node responses
 */
public void mergeComponents(final ProcessorEntity clientEntity, final Map<NodeIdentifier, ProcessorEntity> entityMap) {
    final ProcessorDTO clientDto = clientEntity.getComponent();
    final Map<NodeIdentifier, ProcessorDTO> dtoMap = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, ProcessorEntity> entry : entityMap.entrySet()) {
        final ProcessorEntity nodeProcEntity = entry.getValue();
        final ProcessorDTO nodeProcDto = nodeProcEntity.getComponent();
        dtoMap.put(entry.getKey(), nodeProcDto);
    }
    mergeDtos(clientDto, dtoMap);
}
Also used : HashMap(java.util.HashMap) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)69 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)24 ArrayList (java.util.ArrayList)21 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)19 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)19 HashMap (java.util.HashMap)17 HashSet (java.util.HashSet)16 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)15 PortDTO (org.apache.nifi.web.api.dto.PortDTO)15 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)15 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)13 Map (java.util.Map)11 Response (javax.ws.rs.core.Response)11 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)11 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)11 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)10 List (java.util.List)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)9 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)9