use of org.apache.nifi.web.api.entity.ProcessorEntity in project nifi by apache.
the class ProcessorResource method clearState.
/**
* Clears the state for a processor.
*
* @param httpServletRequest servlet request
* @param id The id of the processor
* @return a componentStateEntity
* @throws InterruptedException if interrupted
*/
@POST
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/state/clear-requests")
@ApiOperation(value = "Clears the state for a processor", response = ComponentStateEntity.class, authorizations = { @Authorization(value = "Write - /processors/{uuid}") })
@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 clearState(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The processor id.", required = true) @PathParam("id") final String id) throws InterruptedException {
if (isReplicateRequest()) {
return replicate(HttpMethod.POST);
}
final ProcessorEntity requestProcessorEntity = new ProcessorEntity();
requestProcessorEntity.setId(id);
return withWriteLock(serviceFacade, requestProcessorEntity, lookup -> {
final Authorizable processor = lookup.getProcessor(id).getAuthorizable();
processor.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
}, () -> serviceFacade.verifyCanClearProcessorState(id), (processorEntity) -> {
// get the component state
serviceFacade.clearProcessorState(processorEntity.getId());
// generate the response entity
final ComponentStateEntity entity = new ComponentStateEntity();
// generate the response
return generateOkResponse(entity).build();
});
}
use of org.apache.nifi.web.api.entity.ProcessorEntity in project nifi by apache.
the class EntityFactory method createProcessorEntity.
public ProcessorEntity createProcessorEntity(final ProcessorDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final ProcessorStatusDTO status, final List<BulletinEntity> bulletins) {
final ProcessorEntity entity = new ProcessorEntity();
entity.setRevision(revision);
if (dto != null) {
entity.setPermissions(permissions);
entity.setStatus(status);
entity.setId(dto.getId());
entity.setInputRequirement(dto.getInputRequirement());
entity.setPosition(dto.getPosition());
if (permissions != null && permissions.getCanRead()) {
entity.setComponent(dto);
entity.setBulletins(bulletins);
}
}
return entity;
}
use of org.apache.nifi.web.api.entity.ProcessorEntity in project nifi by apache.
the class ClusterReplicationComponentLifecycle method waitForProcessorStatus.
/**
* Periodically polls the process group with the given ID, waiting for all processors whose ID's are given to have the given Scheduled State.
*
* @param user the user making the request
* @param originalUri the original uri
* @param groupId the ID of the Process Group to poll
* @param processors the Processors whose state should be equal to the given desired state
* @param desiredState the desired state for all processors with the ID's given
* @param pause the Pause that can be used to wait between polling
* @return <code>true</code> if successful, <code>false</code> if unable to wait for processors to reach the desired state
*/
private boolean waitForProcessorStatus(final NiFiUser user, final URI originalUri, final String groupId, final Map<String, AffectedComponentEntity> processors, final ScheduledState desiredState, final Pause pause) throws InterruptedException {
URI groupUri;
try {
groupUri = new URI(originalUri.getScheme(), originalUri.getUserInfo(), originalUri.getHost(), originalUri.getPort(), "/nifi-api/process-groups/" + groupId + "/processors", "includeDescendantGroups=true", originalUri.getFragment());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
final Map<String, String> headers = new HashMap<>();
final MultivaluedMap<String, String> requestEntity = new MultivaluedHashMap<>();
boolean continuePolling = true;
while (continuePolling) {
// Determine whether we should replicate only to the cluster coordinator, or if we should replicate directly to the cluster nodes themselves.
final NodeResponse clusterResponse;
if (getReplicationTarget() == ReplicationTarget.CLUSTER_NODES) {
clusterResponse = getRequestReplicator().replicate(user, HttpMethod.GET, groupUri, requestEntity, headers).awaitMergedResponse();
} else {
clusterResponse = getRequestReplicator().forwardToCoordinator(getClusterCoordinatorNode(), user, HttpMethod.GET, groupUri, requestEntity, headers).awaitMergedResponse();
}
if (clusterResponse.getStatus() != Status.OK.getStatusCode()) {
return false;
}
final ProcessorsEntity processorsEntity = getResponseEntity(clusterResponse, ProcessorsEntity.class);
final Set<ProcessorEntity> processorEntities = processorsEntity.getProcessors();
if (isProcessorActionComplete(processorEntities, processors, desiredState)) {
logger.debug("All {} processors of interest now have the desired state of {}", processors.size(), desiredState);
return true;
}
// Not all of the processors are in the desired state. Pause for a bit and poll again.
continuePolling = pause.pause();
}
return false;
}
use of org.apache.nifi.web.api.entity.ProcessorEntity 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.ProcessorEntity in project nifi by apache.
the class ITConnectionAccessControl method createConnection.
private ConnectionEntity createConnection(final String name) throws Exception {
String url = helper.getBaseUrl() + "/process-groups/root/connections";
// get two processors
final ProcessorEntity one = ITProcessorAccessControl.createProcessor(helper, "one");
final ProcessorEntity two = ITProcessorAccessControl.createProcessor(helper, "two");
// create the source connectable
ConnectableDTO source = new ConnectableDTO();
source.setId(one.getId());
source.setGroupId(one.getComponent().getParentGroupId());
source.setType(ConnectableType.PROCESSOR.name());
// create the target connectable
ConnectableDTO target = new ConnectableDTO();
target.setId(two.getId());
target.setGroupId(two.getComponent().getParentGroupId());
target.setType(ConnectableType.PROCESSOR.name());
// create the relationships
Set<String> relationships = new HashSet<>();
relationships.add("success");
// create the connection
ConnectionDTO connection = new ConnectionDTO();
connection.setName(name);
connection.setSource(source);
connection.setDestination(target);
connection.setSelectedRelationships(relationships);
// create the revision
final RevisionDTO revision = new RevisionDTO();
revision.setClientId(READ_WRITE_CLIENT_ID);
revision.setVersion(0L);
// create the entity body
ConnectionEntity entity = new ConnectionEntity();
entity.setRevision(revision);
entity.setComponent(connection);
// 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(ConnectionEntity.class);
// verify creation
connection = entity.getComponent();
assertEquals(name, connection.getName());
// get the connection
return entity;
}
Aggregations