use of io.fabric8.kubernetes.api.model.Event 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.kubernetes.api.model.Event in project fabric8 by jboss-fuse.
the class FabricDiscoveryAgent method initGroup.
private synchronized void initGroup() throws Exception {
group = (MultiGroup) factory.createMultiGroup("/fabric/registry/clusters/amq/" + groupName, ActiveMQNode.class, new NamedThreadFactory("zkgroup-fabric-mq-discovery"));
group.add(new GroupListener<ActiveMQNode>() {
@Override
public void groupEvent(Group<ActiveMQNode> group, GroupEvent event) {
LOG.debug("Event: " + event);
Map<String, ActiveMQNode> masters = new HashMap<String, ActiveMQNode>();
for (ActiveMQNode node : group.members().values()) {
if (!masters.containsKey(node.id)) {
masters.put(node.id, node);
}
}
update(masters.values());
}
});
}
use of io.fabric8.kubernetes.api.model.Event in project fabric8 by jboss-fuse.
the class KarafContainerRegistration method configurationEvent.
/**
* Receives notification of a Configuration that has changed.
*
* @param event The <code>ConfigurationEvent</code>.
*/
@Override
public void configurationEvent(ConfigurationEvent event) {
if (isValid()) {
try {
Container current = new ImmutableContainerBuilder().id(runtimeIdentity).ip(ip).build();
RuntimeProperties sysprops = runtimeProperties.get();
String runtimeIdentity = sysprops.getRuntimeIdentity();
if (event.getPid().equals(SSH_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(SSH_PID, null);
int sshPort = Integer.parseInt((String) config.getProperties().get(SSH_BINDING_PORT_KEY));
int sshConnectionPort = getSshConnectionPort(current, sshPort);
String sshUrl = getSshUrl(runtimeIdentity, sshConnectionPort);
setData(curator.get(), CONTAINER_SSH.getPath(runtimeIdentity), sshUrl);
if (portService.get().lookupPort(current, SSH_PID, SSH_BINDING_PORT_KEY) != sshPort) {
portService.get().unregisterPort(current, SSH_PID);
portService.get().registerPort(current, SSH_PID, SSH_BINDING_PORT_KEY, sshPort);
}
}
if (event.getPid().equals(HTTP_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(HTTP_PID, null);
boolean httpEnabled = isHttpEnabled();
boolean httpsEnabled = isHttpsEnabled();
String protocol = httpsEnabled && !httpEnabled ? "https" : "http";
int httpConnectionPort = -1;
if (httpEnabled) {
int httpPort = Integer.parseInt((String) config.getProperties().get(HTTP_BINDING_PORT_KEY));
httpConnectionPort = getHttpConnectionPort(current, httpPort);
if (portService.get().lookupPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY) != httpPort) {
portService.get().unregisterPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY);
portService.get().registerPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY, httpPort);
}
}
if (httpsEnabled) {
int httpsPort = Integer.parseInt((String) config.getProperties().get(HTTPS_BINDING_PORT_KEY));
if (httpConnectionPort == -1) {
httpConnectionPort = getHttpsConnectionPort(current, httpsPort);
}
if (portService.get().lookupPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY) != httpsPort) {
portService.get().unregisterPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY);
portService.get().registerPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY, httpsPort);
}
}
String httpUrl = getHttpUrl(protocol, runtimeIdentity, httpConnectionPort);
setData(curator.get(), CONTAINER_HTTP.getPath(runtimeIdentity), httpUrl);
}
if (event.getPid().equals(MANAGEMENT_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(MANAGEMENT_PID, null);
int rmiServerPort = Integer.parseInt((String) config.getProperties().get(RMI_SERVER_BINDING_PORT_KEY));
int rmiServerConnectionPort = getRmiServerConnectionPort(current, rmiServerPort);
int rmiRegistryPort = Integer.parseInt((String) config.getProperties().get(RMI_REGISTRY_BINDING_PORT_KEY));
int rmiRegistryConnectionPort = getRmiRegistryConnectionPort(current, rmiRegistryPort);
String jmxUrl = getJmxUrl(runtimeIdentity, rmiServerConnectionPort, rmiRegistryConnectionPort);
setData(curator.get(), CONTAINER_JMX.getPath(runtimeIdentity), jmxUrl);
// Whenever the JMX URL changes we need to make sure that the java.rmi.server.hostname points to a valid address.
System.setProperty(SystemProperties.JAVA_RMI_SERVER_HOSTNAME, current.getIp());
if (portService.get().lookupPort(current, MANAGEMENT_PID, RMI_REGISTRY_BINDING_PORT_KEY) != rmiRegistryPort || portService.get().lookupPort(current, MANAGEMENT_PID, RMI_SERVER_BINDING_PORT_KEY) != rmiServerPort) {
portService.get().unregisterPort(current, MANAGEMENT_PID);
portService.get().registerPort(current, MANAGEMENT_PID, RMI_SERVER_BINDING_PORT_KEY, rmiServerPort);
portService.get().registerPort(current, MANAGEMENT_PID, RMI_REGISTRY_BINDING_PORT_KEY, rmiRegistryPort);
}
}
} catch (Exception ex) {
LOGGER.error("Cannot reconfigure container", ex);
}
}
}
use of io.fabric8.kubernetes.api.model.Event in project fabric8 by fabric8io.
the class Fabric8Extension method afterDiscovery.
public void afterDiscovery(@Observes final AfterBeanDiscovery event, BeanManager beanManager) {
KubernetesHolder.useBeanManager(beanManager);
// Only add the bean if no other bean is found.
if (beanManager.getBeans(KubernetesClient.class).isEmpty()) {
event.addBean(new KubernetesClientBean());
}
// We need to process factories in reverse order so that we make feasible forwarding for service id etc.
List<FactoryMethodContext> reverseFactories = new ArrayList<>(FactoryMethodContext.sort(factories));
Collections.reverse(reverseFactories);
for (final FactoryMethodContext factoryMethodContext : reverseFactories) {
ServiceBean.doWith(factoryMethodContext.getReturnType(), new ServiceBean.Callback() {
@Override
public ServiceBean apply(ServiceBean bean) {
String serviceId = bean.getServiceName();
String serviceProtocol = or(bean.getServiceProtocol(), getFactoryMethodProtocol(factoryMethodContext.getFactoryMethod().getJavaMember()));
String servicePort = or(bean.getServicePort(), getFactoryMethodPort(factoryMethodContext.getFactoryMethod().getJavaMember()));
String servicePath = or(bean.getServicePath(), getFactoryMethodPath(factoryMethodContext.getFactoryMethod().getJavaMember()));
Boolean serviceExternal = bean.getServiceExternal();
Boolean serviceEndpoint = bean.getServiceEndpoint();
// Ensure that there is a factory String -> sourceType before adding producer.
if (!String.class.equals(factoryMethodContext.getSourceType())) {
ServiceBean.getBean(serviceId, serviceProtocol, servicePort, servicePath, null, serviceEndpoint, serviceExternal, factoryMethodContext.getSourceType());
}
return bean.withProducer(new FactoryMethodProducer(factoryMethodContext.getBean(), factoryMethodContext.getFactoryMethod(), serviceId, serviceProtocol, servicePort, servicePath));
}
});
}
for (ServiceUrlBean bean : ServiceUrlBean.getBeans()) {
event.addBean(bean);
}
for (ServiceUrlCollectionBean bean : ServiceUrlCollectionBean.getBeans()) {
event.addBean(bean);
}
for (ServiceBean bean : ServiceBean.getBeans()) {
if (bean.getProducer() != null) {
event.addBean(bean);
}
}
for (ConfigurationBean b : ConfigurationBean.getBeans()) {
event.addBean(b);
}
}
use of io.fabric8.kubernetes.api.model.Event in project fabric8 by fabric8io.
the class Fabric8Extension method onManagedBean.
public <X> void onManagedBean(@Observes final ProcessManagedBean<X> event) {
for (final AnnotatedMethod<?> method : event.getAnnotatedBeanClass().getMethods()) {
final Factory factory = method.getAnnotation(Factory.class);
if (factory != null) {
final Type sourceType = getSourceType(method);
final Type returnType = method.getJavaMember().getReturnType();
factories.add(new FactoryMethodContext(event.getBean(), sourceType, returnType, method));
}
}
}
Aggregations