Search in sources :

Example 11 with ProcessGroupEntity

use of org.apache.nifi.web.api.entity.ProcessGroupEntity in project nifi by apache.

the class PGStatus method doExecute.

@Override
public ProcessGroupResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
    final ProcessGroupEntity entity = client.getProcessGroupClient().getProcessGroup(pgId);
    return new ProcessGroupResult(getResultType(properties), entity);
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) ProcessGroupResult(org.apache.nifi.toolkit.cli.impl.result.ProcessGroupResult)

Example 12 with ProcessGroupEntity

use of org.apache.nifi.web.api.entity.ProcessGroupEntity 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 13 with ProcessGroupEntity

use of org.apache.nifi.web.api.entity.ProcessGroupEntity in project nifi by apache.

the class ITProcessGroupAccessControl method testReadWriteUserPutProcessGroup.

/**
 * Ensures the READ_WRITE user can put a process group.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserPutProcessGroup() throws Exception {
    final ProcessGroupEntity entity = getRandomProcessGroup(helper.getReadWriteUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    final String updatedName = "Updated Name" + count++;
    // attempt to update the name
    final long version = entity.getRevision().getVersion();
    entity.getRevision().setClientId(AccessControlHelper.READ_WRITE_CLIENT_ID);
    entity.getComponent().setName(updatedName);
    // perform the request
    final Response response = updateProcessGroup(helper.getReadWriteUser(), entity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final ProcessGroupEntity responseEntity = response.readEntity(ProcessGroupEntity.class);
    // verify
    assertEquals(READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
    assertEquals(updatedName, responseEntity.getComponent().getName());
}
Also used : Response(javax.ws.rs.core.Response) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) Test(org.junit.Test)

Example 14 with ProcessGroupEntity

use of org.apache.nifi.web.api.entity.ProcessGroupEntity in project nifi by apache.

the class ITProcessGroupAccessControl method getRandomProcessGroup.

private ProcessGroupEntity getRandomProcessGroup(final NiFiTestUser user) throws Exception {
    final String url = helper.getBaseUrl() + "/flow/process-groups/root";
    // get the process groups
    final Response response = user.testGet(url);
    // ensure the response was successful
    assertEquals(200, response.getStatus());
    // unmarshal
    final ProcessGroupFlowEntity flowEntity = response.readEntity(ProcessGroupFlowEntity.class);
    final FlowDTO flowDto = flowEntity.getProcessGroupFlow().getFlow();
    final Set<ProcessGroupEntity> processGroups = flowDto.getProcessGroups();
    // ensure the correct number of process groups
    assertFalse(processGroups.isEmpty());
    // use the first process group as the target
    Iterator<ProcessGroupEntity> processGroupIter = processGroups.iterator();
    assertTrue(processGroupIter.hasNext());
    return processGroupIter.next();
}
Also used : Response(javax.ws.rs.core.Response) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity)

Example 15 with ProcessGroupEntity

use of org.apache.nifi.web.api.entity.ProcessGroupEntity in project nifi by apache.

the class ITProcessGroupAccessControl method testNoneUserGetProcessGroup.

/**
 * Ensures the NONE user can get a process group.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserGetProcessGroup() throws Exception {
    final ProcessGroupEntity entity = getRandomProcessGroup(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) Test(org.junit.Test)

Aggregations

ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)37 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)17 Response (javax.ws.rs.core.Response)15 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)15 RemoteProcessGroupEntity (org.apache.nifi.web.api.entity.RemoteProcessGroupEntity)15 Authorizable (org.apache.nifi.authorization.resource.Authorizable)14 ApiOperation (io.swagger.annotations.ApiOperation)11 ApiResponses (io.swagger.annotations.ApiResponses)11 Consumes (javax.ws.rs.Consumes)11 Path (javax.ws.rs.Path)11 Produces (javax.ws.rs.Produces)11 ComponentAuthorizable (org.apache.nifi.authorization.ComponentAuthorizable)10 ProcessGroupAuthorizable (org.apache.nifi.authorization.ProcessGroupAuthorizable)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 Test (org.junit.Test)9 VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)8 FlowDTO (org.apache.nifi.web.api.dto.flow.FlowDTO)8 Set (java.util.Set)7 Bucket (org.apache.nifi.registry.bucket.Bucket)7