use of io.fabric8.gateway.ServiceDTO in project fabric8 by jboss-fuse.
the class ExtendedBurnIn method startHttpGateway.
public HttpGatewayServer startHttpGateway() {
if (restEndpointServer != null) {
LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
ServiceDTO serviceDetails = new ServiceDTO();
serviceDetails.setContainer("local");
serviceDetails.setVersion("1");
mappedServices.put("/hello/world", new MappedServices("http://localhost:8181", serviceDetails, loadBalancer, false));
}
DetectingGatewayWebSocketHandler websocketHandler = new DetectingGatewayWebSocketHandler();
HttpGatewayHandler handler = new HttpGatewayHandler(vertx, new HttpGateway() {
@Override
public void addMappingRuleConfiguration(HttpMappingRule mappingRule) {
}
@Override
public void removeMappingRuleConfiguration(HttpMappingRule mappingRule) {
}
@Override
public Map<String, MappedServices> getMappedServices() {
return mappedServices;
}
@Override
public boolean isEnableIndex() {
return true;
}
@Override
public InetSocketAddress getLocalAddress() {
return new InetSocketAddress("0.0.0.0", 8080);
}
@Override
public void addCallDetailRecord(CallDetailRecord cdr) {
}
});
websocketHandler.setPathPrefix("");
httpGatewayServer = new HttpGatewayServer(vertx, handler, websocketHandler, 8080);
httpGatewayServer.setHost("localhost");
httpGatewayServer.init();
return httpGatewayServer;
}
use of io.fabric8.gateway.ServiceDTO in project fabric8 by jboss-fuse.
the class GatewayServiceTreeCache method treeCacheEvent.
protected void treeCacheEvent(PathChildrenCacheEvent event) {
ChildData childData = event.getData();
if (childData == null) {
return;
}
String path = childData.getPath();
LOG.trace("Event {} on path {}", event.getType().toString(), path);
PathChildrenCacheEvent.Type type = event.getType();
byte[] data = childData.getData();
if (data == null || data.length == 0 || path == null) {
return;
}
if (path.startsWith(zkPath)) {
path = path.substring(zkPath.length());
}
List<String> split = Strings.splitAndTrimAsList(path, "/");
// Lets just use the group name as the service path.
path = split.get(0);
String zNode = split.get(1);
boolean remove = false;
switch(type) {
case CHILD_ADDED:
case CHILD_UPDATED:
break;
case CHILD_REMOVED:
remove = true;
break;
default:
return;
}
ServiceDTO dto = null;
try {
dto = mapper.readValue(data, ServiceDTO.class);
expandPropertyResolvers(dto);
dto.setContainer(dto.getContainer() + "_zNode_" + zNode);
if (remove) {
LOG.info("Removed gateway service: " + path + ": " + dto);
serviceMap.serviceRemoved(path, dto);
} else {
LOG.info("Updated gateway service: " + path + ": " + dto);
serviceMap.serviceUpdated(path, dto);
}
} catch (IOException e) {
LOG.warn("Failed to parse the JSON: " + new String(data) + ". Reason: " + e, e);
} catch (URISyntaxException e) {
LOG.warn("Failed to update URI for dto: " + dto + ", .Reason: " + e, e);
}
}
use of io.fabric8.gateway.ServiceDTO in project fabric8 by jboss-fuse.
the class GatewayServiceTreeCache method treeCacheEvent.
protected void treeCacheEvent(PathChildrenCacheEvent event) {
ChildData childData = event.getData();
if (childData == null) {
return;
}
String path = childData.getPath();
PathChildrenCacheEvent.Type type = event.getType();
byte[] data = childData.getData();
if (data == null || data.length == 0 || path == null) {
return;
}
if (path.startsWith(zkPath)) {
path = path.substring(zkPath.length());
}
boolean remove = false;
switch(type) {
case CHILD_ADDED:
case CHILD_UPDATED:
break;
case CHILD_REMOVED:
remove = true;
break;
default:
return;
}
ServiceDTO dto = null;
try {
dto = mapper.readValue(data, ServiceDTO.class);
expandPropertyResolvers(dto);
if (remove) {
serviceMap.serviceRemoved(path, dto);
} else {
serviceMap.serviceUpdated(path, dto);
}
} catch (IOException e) {
LOG.warn("Failed to parse the JSON: " + new String(data) + ". Reason: " + e, e);
} catch (URISyntaxException e) {
LOG.warn("Failed to update URI for dto: " + dto + ", .Reason: " + e, e);
}
}
use of io.fabric8.gateway.ServiceDTO in project fabric8 by jboss-fuse.
the class MappingConfigurationTest method addService.
protected void addService(String path, String service, String version) {
Map<String, String> params = new HashMap<String, String>();
params.put("version", version);
String container = path.contains("HelloWorld") ? "soapy" : "resty";
params.put("container", container);
ServiceDTO serviceDetails = new ServiceDTO();
serviceDetails.setContainer(container);
serviceDetails.setVersion(version);
config.updateMappingRules(false, path, Arrays.asList(service), params, serviceDetails);
}
use of io.fabric8.gateway.ServiceDTO in project fabric8 by jboss-fuse.
the class DetectingGatewayTest method startBrokers.
@Before
public void startBrokers() {
for (int i = 0; i < 2; i++) {
// create a broker..
String name = "broker" + i;
Broker broker = createBroker(name);
ServiceControl.start(broker);
brokers.add(broker);
// Add a service map entry for the broker.
ServiceDTO details = new ServiceDTO();
details.setId(name);
details.setVersion("1.0");
details.setContainer("testing");
details.setBundleName("none");
details.setBundleVersion("1.0");
List<String> services = Arrays.asList("stomp://localhost:" + portOfBroker(i), "mqtt://localhost:" + portOfBroker(i), "amqp://localhost:" + portOfBroker(i), "tcp://localhost:" + portOfBroker(i));
details.setServices(services);
serviceMap.serviceUpdated(name, details);
println(String.format("Broker %s is exposing: %s", name, services));
}
}
Aggregations