use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class UserEntityMerger method mergeComponents.
/**
* Merges the UserEntity responses.
*
* @param clientEntity the entity being returned to the client
* @param entityMap all node responses
*/
public void mergeComponents(final UserEntity clientEntity, final Map<NodeIdentifier, UserEntity> entityMap) {
final UserDTO clientDto = clientEntity.getComponent();
final Map<NodeIdentifier, UserDTO> dtoMap = new HashMap<>();
for (final Map.Entry<NodeIdentifier, UserEntity> entry : entityMap.entrySet()) {
final UserEntity nodeUserEntity = entry.getValue();
final UserDTO nodeUserDto = nodeUserEntity.getComponent();
dtoMap.put(entry.getKey(), nodeUserDto);
}
mergeDtos(clientDto, dtoMap);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class VersionControlInformationEntityMerger method merge.
public void merge(final VersionControlInformationEntity clientEntity, final Map<NodeIdentifier, VersionControlInformationEntity> entityMap) {
final VersionControlInformationDTO clientDto = clientEntity.getVersionControlInformation();
// We need to merge the 'current' and 'modified' flags because these are updated by nodes in the background. Since
// the nodes can synchronize with the Flow Registry at different intervals, we have to determine how to handle these
// flags if different nodes report different values for them.
entityMap.values().stream().filter(entity -> entity != clientEntity).forEach(entity -> {
final VersionControlInformationDTO dto = entity.getVersionControlInformation();
updateFlowState(clientDto, dto);
});
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class TestProcessorEndpointMerger method testMergeValidationErrors.
@Test
public void testMergeValidationErrors() {
final ProcessorEndpointMerger merger = new ProcessorEndpointMerger();
final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
final NodeIdentifier nodeId1234 = new NodeIdentifier("1234", "localhost", 9000, "localhost", 9001, "localhost", 9002, 9003, false);
final List<String> nodeValidationErrors1234 = new ArrayList<>();
nodeValidationErrors1234.add("error 1");
nodeValidationErrors1234.add("error 2");
ErrorMerger.mergeErrors(validationErrorMap, nodeId1234, nodeValidationErrors1234);
final NodeIdentifier nodeXyz = new NodeIdentifier("xyz", "localhost", 8000, "localhost", 8001, "localhost", 8002, 8003, false);
final List<String> nodeValidationErrorsXyz = new ArrayList<>();
nodeValidationErrorsXyz.add("error 1");
ErrorMerger.mergeErrors(validationErrorMap, nodeXyz, nodeValidationErrorsXyz);
assertEquals(2, validationErrorMap.size());
final Set<NodeIdentifier> idsError1 = validationErrorMap.get("error 1");
assertEquals(2, idsError1.size());
assertTrue(idsError1.contains(nodeId1234));
assertTrue(idsError1.contains(nodeXyz));
final Set<NodeIdentifier> idsError2 = validationErrorMap.get("error 2");
assertEquals(1, idsError2.size());
assertTrue(idsError2.contains(nodeId1234));
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class TestResponseUtils method testFindLongResponseTimes.
@Test
public void testFindLongResponseTimes() throws URISyntaxException {
final Map<NodeIdentifier, NodeResponse> responses = new HashMap<>();
final NodeIdentifier id1 = new NodeIdentifier("1", "localhost", 8000, "localhost", 8001, "localhost", 8002, 8003, false);
final NodeIdentifier id2 = new NodeIdentifier("2", "localhost", 8200, "localhost", 8201, "localhost", 8202, 8203, false);
final NodeIdentifier id3 = new NodeIdentifier("3", "localhost", 8300, "localhost", 8301, "localhost", 8302, 8303, false);
final NodeIdentifier id4 = new NodeIdentifier("4", "localhost", 8400, "localhost", 8401, "localhost", 8402, 8403, false);
final URI uri = new URI("localhost:8080");
final Response clientResponse = mock(Response.class);
responses.put(id1, new NodeResponse(id1, "GET", uri, clientResponse, TimeUnit.MILLISECONDS.toNanos(80), "1"));
responses.put(id2, new NodeResponse(id1, "GET", uri, clientResponse, TimeUnit.MILLISECONDS.toNanos(92), "1"));
responses.put(id3, new NodeResponse(id1, "GET", uri, clientResponse, TimeUnit.MILLISECONDS.toNanos(3), "1"));
responses.put(id4, new NodeResponse(id1, "GET", uri, clientResponse, TimeUnit.MILLISECONDS.toNanos(120), "1"));
final AsyncClusterResponse response = new AsyncClusterResponse() {
@Override
public String getRequestIdentifier() {
return "1";
}
@Override
public String getMethod() {
return "GET";
}
@Override
public String getURIPath() {
return null;
}
@Override
public Set<NodeIdentifier> getNodesInvolved() {
return new HashSet<>(responses.keySet());
}
@Override
public Set<NodeIdentifier> getCompletedNodeIdentifiers() {
return getNodesInvolved();
}
@Override
public boolean isComplete() {
return true;
}
@Override
public boolean isOlderThan(long time, TimeUnit timeUnit) {
return true;
}
@Override
public NodeResponse getMergedResponse() {
return null;
}
@Override
public NodeResponse awaitMergedResponse() throws InterruptedException {
return null;
}
@Override
public NodeResponse awaitMergedResponse(long timeout, TimeUnit timeUnit) throws InterruptedException {
return null;
}
@Override
public NodeResponse getNodeResponse(NodeIdentifier nodeId) {
return responses.get(nodeId);
}
@Override
public Set<NodeResponse> getCompletedNodeResponses() {
return new HashSet<>(responses.values());
}
};
Set<NodeIdentifier> slowResponses = ResponseUtils.findLongResponseTimes(response, 1.5D);
assertTrue(slowResponses.isEmpty());
responses.put(id4, new NodeResponse(id1, "GET", uri, clientResponse, TimeUnit.MILLISECONDS.toNanos(2500), "1"));
slowResponses = ResponseUtils.findLongResponseTimes(response, 1.5D);
assertEquals(1, slowResponses.size());
assertEquals(id4, slowResponses.iterator().next());
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class TestThreadPoolRequestReplicator method testMonitorNotifiedOnSuccessfulCompletion.
@Test(timeout = 5000)
public void testMonitorNotifiedOnSuccessfulCompletion() {
withReplicator(replicator -> {
final Object monitor = new Object();
final CountDownLatch preNotifyLatch = new CountDownLatch(1);
final CountDownLatch postNotifyLatch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
synchronized (monitor) {
while (true) {
// If monitor is not notified, this will block indefinitely, and the test will timeout
try {
preNotifyLatch.countDown();
monitor.wait();
break;
} catch (InterruptedException e) {
continue;
}
}
postNotifyLatch.countDown();
}
}
}).start();
// wait for the background thread to notify that it is synchronized on monitor.
preNotifyLatch.await();
final Set<NodeIdentifier> nodeIds = new HashSet<>();
final NodeIdentifier nodeId = new NodeIdentifier("1", "localhost", 8000, "localhost", 8001, "localhost", 8002, 8003, false);
nodeIds.add(nodeId);
final URI uri = new URI("http://localhost:8080/processors/1");
final Entity entity = new ProcessorEntity();
// set the user
final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(StandardNiFiUser.ANONYMOUS));
SecurityContextHolder.getContext().setAuthentication(authentication);
// ensure the proxied entities header is set
final Map<String, String> updatedHeaders = new HashMap<>();
replicator.updateRequestHeaders(updatedHeaders, NiFiUserUtils.getNiFiUser());
replicator.replicate(nodeIds, HttpMethod.GET, uri, entity, updatedHeaders, true, null, true, true, monitor);
// wait for monitor to be notified.
postNotifyLatch.await();
});
}
Aggregations