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);
}
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);
}
}
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());
}
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();
}
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());
}
Aggregations