Search in sources :

Example 21 with PortDTO

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

the class ITInputPortAccessControl method createInputPort.

private PortEntity createInputPort(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/input-ports";
    final String updatedName = name + count++;
    // create the input port
    PortDTO inputPort = new PortDTO();
    inputPort.setName(updatedName);
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    PortEntity entity = new PortEntity();
    entity.setRevision(revision);
    entity.setComponent(inputPort);
    // perform the request
    Response response = helper.getReadWriteUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    // get the entity body
    entity = response.readEntity(PortEntity.class);
    // verify creation
    inputPort = entity.getComponent();
    assertEquals(updatedName, inputPort.getName());
    // get the input port
    return entity;
}
Also used : Response(javax.ws.rs.core.Response) PortDTO(org.apache.nifi.web.api.dto.PortDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 22 with PortDTO

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

the class ITInputPortAccessControl method testWriteUserPutInputPort.

/**
 * Ensures the WRITE user can put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedName = "Updated Name" + count++;
    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateInputPort(helper.getWriteUser(), requestEntity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final PortEntity responseEntity = response.readEntity(PortEntity.class);
    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
Also used : Response(javax.ws.rs.core.Response) PortDTO(org.apache.nifi.web.api.dto.PortDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Test(org.junit.Test)

Example 23 with PortDTO

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

the class ITOutputPortAccessControl method testWriteUserPutOutputPort.

/**
 * Ensures the WRITE user can put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedName = "Updated Name" + count++;
    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    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 PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateOutputPort(helper.getWriteUser(), requestEntity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final PortEntity responseEntity = response.readEntity(PortEntity.class);
    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
Also used : Response(javax.ws.rs.core.Response) PortDTO(org.apache.nifi.web.api.dto.PortDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Test(org.junit.Test)

Example 24 with PortDTO

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

the class StandardRemoteProcessGroup method convertRemotePort.

/**
 * Converts a set of ports into a set of remote process group ports.
 *
 * @param ports to convert
 * @return descriptors of ports
 */
private Set<RemoteProcessGroupPortDescriptor> convertRemotePort(final Set<PortDTO> ports) {
    Set<RemoteProcessGroupPortDescriptor> remotePorts = null;
    if (ports != null) {
        remotePorts = new LinkedHashSet<>(ports.size());
        for (final PortDTO port : ports) {
            final StandardRemoteProcessGroupPortDescriptor descriptor = new StandardRemoteProcessGroupPortDescriptor();
            final ScheduledState scheduledState = ScheduledState.valueOf(port.getState());
            descriptor.setId(generatePortId(port.getId()));
            descriptor.setTargetId(port.getId());
            descriptor.setName(port.getName());
            descriptor.setComments(port.getComments());
            descriptor.setTargetRunning(ScheduledState.RUNNING.equals(scheduledState));
            remotePorts.add(descriptor);
        }
    }
    return remotePorts;
}
Also used : RemoteProcessGroupPortDescriptor(org.apache.nifi.groups.RemoteProcessGroupPortDescriptor) ScheduledState(org.apache.nifi.controller.ScheduledState) PortDTO(org.apache.nifi.web.api.dto.PortDTO)

Example 25 with PortDTO

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

the class PortEntityMerger method mergeDtos.

public static void mergeDtos(final PortDTO clientDto, final Map<NodeIdentifier, PortDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }
    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, PortDTO> nodeEntry : dtoMap.entrySet()) {
        final PortDTO nodePort = nodeEntry.getValue();
        // merge the validation errors if authorized
        if (nodePort != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodePort.getValidationErrors());
        }
    }
    // set the merged the validation errors
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) PortDTO(org.apache.nifi.web.api.dto.PortDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

PortDTO (org.apache.nifi.web.api.dto.PortDTO)71 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)30 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)29 HashSet (java.util.HashSet)28 ArrayList (java.util.ArrayList)27 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)26 HashMap (java.util.HashMap)24 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)22 Map (java.util.Map)21 Set (java.util.Set)20 List (java.util.List)18 Collectors (java.util.stream.Collectors)18 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)18 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)15 Collection (java.util.Collection)14 Optional (java.util.Optional)14 PortEntity (org.apache.nifi.web.api.entity.PortEntity)14