use of org.apache.nifi.web.api.dto.DropRequestDTO in project kylo by Teradata.
the class AbstractNiFiConnectionsRestClient method deleteQueueWithRetries.
/**
* Sends a request to drop the contents of a queue and waits for it to finish.
*
* @param processGroupId the process group id
* @param connectionId the connection id
* @param retries number of retries, at least 0; will try {@code retries} + 1 times
* @param timeout duration to wait between retries
* @param timeUnit unit of time for {@code timeout}
* @return the drop request, if finished
* @throws NifiClientRuntimeException if the operation times out
* @throws NifiComponentNotFoundException if the process group or connection does not exist
*/
protected DropRequestDTO deleteQueueWithRetries(@Nonnull final String processGroupId, @Nonnull final String connectionId, final int retries, final int timeout, @Nonnull final TimeUnit timeUnit) {
// Request queue drop
DropRequestDTO dropRequest = createDropRequest(processGroupId, connectionId);
// Wait for finished
for (int count = 0; !dropRequest.isFinished() && count < retries; ++count) {
Uninterruptibles.sleepUninterruptibly(timeout, timeUnit);
dropRequest = getDropRequest(processGroupId, connectionId, dropRequest.getId()).orElseThrow(() -> new NifiComponentNotFoundException(connectionId, NifiConstants.NIFI_COMPONENT_TYPE.CONNECTION, null));
}
if (!dropRequest.isFinished()) {
throw new NifiClientRuntimeException("Timeout waiting for queue to delete for connection: " + connectionId);
}
// Cleanup
return deleteDropRequest(processGroupId, connectionId, dropRequest.getId()).orElseThrow(() -> new NifiComponentNotFoundException(connectionId, NifiConstants.NIFI_COMPONENT_TYPE.CONNECTION, null));
}
use of org.apache.nifi.web.api.dto.DropRequestDTO in project kylo by Teradata.
the class AbstractNiFiConnectionsRestClientTest method deleteQueueWithRetries.
/**
* Verify deleting a queue.
*/
@Test
public void deleteQueueWithRetries() {
// Mock drop requests
final DropRequestDTO request1 = new DropRequestDTO();
request1.setId("33d0b0c1-88b4-4c75-b61a-83223df79d8c");
request1.setFinished(false);
final DropRequestDTO request2 = new DropRequestDTO();
request2.setId("33d0b0c1-88b4-4c75-b61a-83223df79d8c");
request2.setFinished(true);
// Mock NiFi Connections REST client
final AbstractNiFiConnectionsRestClient client = Mockito.mock(AbstractNiFiConnectionsRestClient.class, Mockito.CALLS_REAL_METHODS);
Mockito.when(client.createDropRequest("group", "connection")).thenReturn(request1);
Mockito.when(client.getDropRequest("group", "connection", request1.getId())).thenReturn(Optional.of(request2));
Mockito.when(client.deleteDropRequest("group", "connection", request1.getId())).thenReturn(Optional.of(request2));
// Test deleting queue
Assert.assertEquals(request2, client.deleteQueueWithRetries("group", "connection", 1, 0, TimeUnit.NANOSECONDS));
}
use of org.apache.nifi.web.api.dto.DropRequestDTO in project nifi by apache.
the class FlowFileQueueResource method removeDropRequest.
/**
* Deletes the specified drop request.
*
* @param httpServletRequest request
* @param connectionId The connection id
* @param dropRequestId The drop request id
* @return A dropRequestEntity
*/
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/drop-requests/{drop-request-id}")
@ApiOperation(value = "Cancels and/or removes a request to drop the contents of this connection.", response = DropRequestEntity.class, authorizations = { @Authorization(value = "Write Source Data - /data/{component-type}/{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 removeDropRequest(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The connection id.", required = true) @PathParam("id") final String connectionId, @ApiParam(value = "The drop request id.", required = true) @PathParam("drop-request-id") final String dropRequestId) {
if (isReplicateRequest()) {
return replicate(HttpMethod.DELETE);
}
return withWriteLock(serviceFacade, new DropEntity(connectionId, dropRequestId), lookup -> {
final ConnectionAuthorizable connAuth = lookup.getConnection(connectionId);
final Authorizable dataAuthorizable = connAuth.getSourceData();
dataAuthorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
}, null, (dropEntity) -> {
// delete the drop request
final DropRequestDTO dropRequest = serviceFacade.deleteFlowFileDropRequest(dropEntity.getConnectionId(), dropEntity.getDropRequestId());
dropRequest.setUri(generateResourceUri("flowfile-queues", dropEntity.getConnectionId(), "drop-requests", dropEntity.getDropRequestId()));
// create the response entity
final DropRequestEntity entity = new DropRequestEntity();
entity.setDropRequest(dropRequest);
return generateOkResponse(entity).build();
});
}
use of org.apache.nifi.web.api.dto.DropRequestDTO in project nifi by apache.
the class DropRequestEndpointMerger method mergeResponses.
@Override
protected void mergeResponses(DropRequestDTO clientDto, Map<NodeIdentifier, DropRequestDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
boolean nodeWaiting = false;
int originalCount = 0;
long originalSize = 0;
int currentCount = 0;
long currentSize = 0;
int droppedCount = 0;
long droppedSize = 0;
DropFlowFileState state = null;
boolean allFinished = true;
String failureReason = null;
for (final Map.Entry<NodeIdentifier, DropRequestDTO> nodeEntry : dtoMap.entrySet()) {
final DropRequestDTO nodeDropRequest = nodeEntry.getValue();
if (!nodeDropRequest.isFinished()) {
allFinished = false;
}
if (nodeDropRequest.getFailureReason() != null) {
failureReason = nodeDropRequest.getFailureReason();
}
currentCount += nodeDropRequest.getCurrentCount();
currentSize += nodeDropRequest.getCurrentSize();
droppedCount += nodeDropRequest.getDroppedCount();
droppedSize += nodeDropRequest.getDroppedSize();
if (nodeDropRequest.getOriginalCount() == null) {
nodeWaiting = true;
} else {
originalCount += nodeDropRequest.getOriginalCount();
originalSize += nodeDropRequest.getOriginalSize();
}
final DropFlowFileState nodeState = DropFlowFileState.valueOfDescription(nodeDropRequest.getState());
if (state == null || state.ordinal() > nodeState.ordinal()) {
state = nodeState;
}
}
clientDto.setCurrentCount(currentCount);
clientDto.setCurrentSize(currentSize);
clientDto.setCurrent(FormatUtils.formatCount(currentCount) + " / " + FormatUtils.formatDataSize(currentSize));
clientDto.setDroppedCount(droppedCount);
clientDto.setDroppedSize(droppedSize);
clientDto.setDropped(FormatUtils.formatCount(droppedCount) + " / " + FormatUtils.formatDataSize(droppedSize));
clientDto.setFinished(allFinished);
clientDto.setFailureReason(failureReason);
if (originalCount == 0) {
clientDto.setPercentCompleted(allFinished ? 100 : 0);
} else {
clientDto.setPercentCompleted((int) ((double) droppedCount / (double) originalCount * 100D));
}
if (!nodeWaiting) {
clientDto.setOriginalCount(originalCount);
clientDto.setOriginalSize(originalSize);
clientDto.setOriginal(FormatUtils.formatCount(originalCount) + " / " + FormatUtils.formatDataSize(originalSize));
}
if (state != null) {
clientDto.setState(state.toString());
}
}
use of org.apache.nifi.web.api.dto.DropRequestDTO in project kylo by Teradata.
the class AbstractNiFiConnectionsRestClientTest method deleteQueueWithTimeout.
/**
* Verify failure to delete due to timeout error.
*/
@Test(expected = NifiClientRuntimeException.class)
public void deleteQueueWithTimeout() {
// Mock drop request
final DropRequestDTO request = new DropRequestDTO();
request.setId("33d0b0c1-88b4-4c75-b61a-83223df79d8c");
request.setFinished(false);
// Mock NiFi Connections REST client
final AbstractNiFiConnectionsRestClient client = Mockito.mock(AbstractNiFiConnectionsRestClient.class, Mockito.CALLS_REAL_METHODS);
Mockito.when(client.createDropRequest("group", "connection")).thenReturn(request);
Mockito.when(client.getDropRequest("group", "connection", request.getId())).thenReturn(Optional.empty());
Mockito.when(client.deleteDropRequest("group", "connection", request.getId())).thenReturn(Optional.empty());
// Test failure
client.deleteQueueWithRetries("group", "connection", 0, 0, TimeUnit.NANOSECONDS);
}
Aggregations