use of io.fabric8.groups.internal.ChildData in project fabric8 by jboss-fuse.
the class ZooKeeperGroupTest method putChildData.
private static void putChildData(ZooKeeperGroup<NodeState> group, String path, String container) throws Exception {
NodeState node = new NodeState("test", container);
ByteArrayOutputStream data = new ByteArrayOutputStream();
new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).writeValue(data, node);
ChildData<NodeState> child = new ChildData<>(path, new Stat(), data.toByteArray(), node);
group.currentData.put(path, child);
}
use of io.fabric8.groups.internal.ChildData 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.groups.internal.ChildData 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.groups.internal.ChildData in project fabric8 by jboss-fuse.
the class HttpMappingZooKeeperTreeCache method treeCacheEvent.
protected void treeCacheEvent(PathChildrenCacheEvent event) {
String zkPath = zooKeeperPath;
ChildData childData = event.getData();
if (childData == null) {
return;
}
String path = childData.getPath();
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());
}
// TODO should we remove the version too and pick that one?
// and include the version in the service chooser?
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);
List<String> services = dto.getServices();
Map<String, String> params = new HashMap<String, String>();
params.put("id", paramValue(dto.getId()));
params.put("container", paramValue(dto.getContainer()));
params.put("version", paramValue(dto.getVersion()));
params.put("bundleName", paramValue(dto.getBundleName()));
params.put("bundleVersion", paramValue(dto.getBundleVersion()));
mappingRuleConfiguration.updateMappingRules(remove, path, services, params, 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.groups.internal.ChildData in project fabric8 by jboss-fuse.
the class ZooKeeperMultiGroup method isMaster.
@Override
public boolean isMaster(String name) {
List<ChildData<T>> children = getActiveChildren();
Collections.sort(children, sequenceComparator);
for (ChildData child : children) {
NodeState node = (NodeState) child.getNode();
if (node.id.equals(name)) {
if (child.getPath().equals(getId())) {
return true;
} else {
return false;
}
}
}
return false;
}
Aggregations