@Test public void testRawServerNameToNode() { Properties props = new Properties(); props.put("nifi.remote.route.raw.name-to-node.when", "${X-ProxyHost:contains('.example.com')" + ":or(${s2s.source.hostname:contains('.example.com')})}"); props.put("nifi.remote.route.raw.name-to-node.hostname", "${s2s.target.hostname}.example.com"); props.put("nifi.remote.route.raw.name-to-node.port", "17491"); props.put("nifi.remote.route.raw.name-to-node.secure", "true"); props.put("nifi.remote.input.host", "node0"); props.put("nifi.remote.input.secure", "true"); props.put("nifi.remote.input.socket.port", "8081"); props.put("nifi.remote.input.http.enabled", "true"); final NiFiProperties properties = new StandardNiFiProperties(props); final PeerDescriptionModifier modifier = new PeerDescriptionModifier(properties); PeerDescription source = new PeerDescription("nifi0.example.com", 12345, true); PeerDescription target = new PeerDescription("nifi0", 8081, true); PeerDescription modifiedTarget = modifier.modify(source, target, SiteToSiteTransportProtocol.RAW, PeerDescriptionModifier.RequestType.SiteToSiteDetail, new HashMap<>()); assertNotNull(modifiedTarget); assertEquals("nifi0.example.com", modifiedTarget.getHostname()); assertEquals(17491, modifiedTarget.getPort()); assertEquals(true, modifiedTarget.isSecure()); target = new PeerDescription("nifi1", 8081, true); modifiedTarget = modifier.modify(source, target, SiteToSiteTransportProtocol.RAW, PeerDescriptionModifier.RequestType.SiteToSiteDetail, new HashMap<>()); assertNotNull(modifiedTarget); assertEquals("nifi1.example.com", modifiedTarget.getHostname()); assertEquals(17491, modifiedTarget.getPort()); assertEquals(true, modifiedTarget.isSecure()); source = new PeerDescription("192.168.1.101", 23456, true); modifiedTarget = modifier.modify(source, target, SiteToSiteTransportProtocol.RAW, PeerDescriptionModifier.RequestType.SiteToSiteDetail, new HashMap<>()); assertNotNull(modifiedTarget); assertEquals(target, modifiedTarget); }
public PeerDescription modify(final PeerDescription source, final PeerDescription target, final SiteToSiteTransportProtocol protocol, final RequestType requestType, final Map<String, String> variables) { addVariables(variables, "s2s.source", source); addVariables(variables, "s2s.target", target); variables.put("s2s.protocol", protocol.name()); variables.put("s2s.request", requestType.name()); logger.debug("Modifying PeerDescription, variables={}", variables); return routes.get(protocol).stream().filter(r -> r.predicate == null || Boolean.valueOf(r.predicate.evaluateExpressions(variables, null))) .map(r -> { final PeerDescription t = r.getTarget(variables); logger.debug("Route definition {} matched, {}", r.name, t); return t; }) .findFirst().orElse(target); }
PeerDescriptionModifier { public PeerDescription modify(final PeerDescription source, final PeerDescription target, final SiteToSiteTransportProtocol protocol, final RequestType requestType, final Map<String, String> variables) { addVariables(variables, "s2s.source", source); addVariables(variables, "s2s.target", target); variables.put("s2s.protocol", protocol.name()); variables.put("s2s.request", requestType.name()); logger.debug("Modifying PeerDescription, variables={}", variables); return routes.get(protocol).stream().filter(r -> r.predicate == null || Boolean.valueOf(r.predicate.evaluateExpressions(variables, null))) .map(r -> { final PeerDescription t = r.getTarget(variables); logger.debug("Route definition {} matched, {}", r.name, t); return t; }) .findFirst().orElse(target); } }
PeerDescriptionModifier { public PeerDescription modify(final PeerDescription source, final PeerDescription target, final SiteToSiteTransportProtocol protocol, final RequestType requestType, final Map<String, String> variables) { addVariables(variables, "s2s.source", source); addVariables(variables, "s2s.target", target); variables.put("s2s.protocol", protocol.name()); variables.put("s2s.request", requestType.name()); logger.debug("Modifying PeerDescription, variables={}", variables); return routes.get(protocol).stream().filter(r -> r.predicate == null || Boolean.valueOf(r.predicate.evaluateExpressions(variables, null))) .map(r -> { final PeerDescription t = r.getTarget(variables); logger.debug("Route definition {} matched, {}", r.name, t); return t; }) .findFirst().orElse(target); } PeerDescriptionModifier(final NiFiProperties properties); }
PeerDescriptionModifier { public PeerDescription modify(final PeerDescription source, final PeerDescription target, final SiteToSiteTransportProtocol protocol, final RequestType requestType, final Map<String, String> variables) { addVariables(variables, "s2s.source", source); addVariables(variables, "s2s.target", target); variables.put("s2s.protocol", protocol.name()); variables.put("s2s.request", requestType.name()); logger.debug("Modifying PeerDescription, variables={}", variables); return routes.get(protocol).stream().filter(r -> r.predicate == null || Boolean.valueOf(r.predicate.evaluateExpressions(variables, null))) .map(r -> { final PeerDescription t = r.getTarget(variables); logger.debug("Route definition {} matched, {}", r.name, t); return t; }) .findFirst().orElse(target); } PeerDescriptionModifier(final NiFiProperties properties); boolean isModificationNeeded(final SiteToSiteTransportProtocol protocol); PeerDescription modify(final PeerDescription source, final PeerDescription target,
                                  final SiteToSiteTransportProtocol protocol, final RequestType requestType,
                                  final Map<String, String> variables); }
PeerDescriptionModifier { public PeerDescription modify(final PeerDescription source, final PeerDescription target, final SiteToSiteTransportProtocol protocol, final RequestType requestType, final Map<String, String> variables) { addVariables(variables, "s2s.source", source); addVariables(variables, "s2s.target", target); variables.put("s2s.protocol", protocol.name()); variables.put("s2s.request", requestType.name()); logger.debug("Modifying PeerDescription, variables={}", variables); return routes.get(protocol).stream().filter(r -> r.predicate == null || Boolean.valueOf(r.predicate.evaluateExpressions(variables, null))) .map(r -> { final PeerDescription t = r.getTarget(variables); logger.debug("Route definition {} matched, {}", r.name, t); return t; }) .findFirst().orElse(target); } PeerDescriptionModifier(final NiFiProperties properties); boolean isModificationNeeded(final SiteToSiteTransportProtocol protocol); PeerDescription modify(final PeerDescription source, final PeerDescription target,
                                  final SiteToSiteTransportProtocol protocol, final RequestType requestType,
                                  final Map<String, String> variables);  }