use of io.fabric8.common.util.Filter in project vertx-openshift-it by cescoffier.
the class CircuitBreakerIT method deployApp.
/**
* @param name
* @param templatePath
* @return the app route
* @throws IOException
*/
private static String deployApp(String name, String templatePath) throws IOException {
String appName = "";
List<? extends HasMetadata> entities = OPENSHIFT.deploy(name, new File(templatePath));
Optional<String> first = entities.stream().filter(hm -> hm instanceof DeploymentConfig).map(hm -> (DeploymentConfig) hm).map(dc -> dc.getMetadata().getName()).findFirst();
if (first.isPresent()) {
appName = first.get();
} else {
throw new IllegalStateException("Application deployment config not found");
}
Route route = OPENSHIFT.client().routes().inNamespace(OPENSHIFT.project()).withName(appName).get();
assertThat(route).isNotNull();
return "http://" + route.getSpec().getHost();
}
use of io.fabric8.common.util.Filter in project vertx-openshift-it by cescoffier.
the class WebSessionIT method testClusteredWebSession.
@Test
public void testClusteredWebSession() throws Exception {
HttpClient httpClient = vertx.createHttpClient();
AtomicReference<Map.Entry<String, String>> cookie = new AtomicReference<>();
int loops = 30;
for (int i = 0; i < loops; i++) {
String key = getKey(i);
String value = getValue(i);
URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/web-session/" + key);
CountDownLatch latch = new CountDownLatch(1);
HttpClientRequest request = httpClient.putAbs(url.toString());
Optional.ofNullable(cookie.get()).ifPresent(c -> request.headers().add("cookie", c.getKey() + "=" + c.getValue()));
request.handler(resp -> {
resp.cookies().stream().map(c -> c.split("=", 2)).map(split -> new SimpleImmutableEntry<>(split[0], split[1].split(";")[0])).filter(entry -> "vertx-web.session".equals(entry.getKey())).forEach(cookie::set);
latch.countDown();
}).exceptionHandler(t -> {
t.printStackTrace();
latch.countDown();
}).end(value);
latch.await(1, TimeUnit.MINUTES);
// Give some time to the replication operation
TimeUnit.SECONDS.sleep(1);
}
scaleTo(2);
// Give some time to the rebalancing process
TimeUnit.SECONDS.sleep(10);
assertNotNull("No session cookie", cookie.get());
for (int i = 0; i < loops; i++) {
String key = getKey(i);
String value = getValue(i);
URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/web-session/" + key);
given().cookie(cookie.get().getKey(), cookie.get().getValue()).when().get(url).then().assertThat().statusCode(200).body(equalTo(value));
}
}
use of io.fabric8.common.util.Filter in project vertx-openshift-it by cescoffier.
the class Kube method setReplicasAndWait.
public static DeploymentConfig setReplicasAndWait(KubernetesClient client, String name, int number) {
OpenShiftClient oc = oc(client);
DeploymentConfig config = oc.deploymentConfigs().withName(name).get();
if (config == null) {
fail("Unable to find the deployment config " + name);
return null;
}
if (config.getSpec().getReplicas() == number) {
return config;
}
config = oc.deploymentConfigs().withName(name).edit().editSpec().withReplicas(number).endSpec().done();
if (number == 0) {
// Wait until no pods
await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == 0);
} else {
// Wait until the right number of pods
await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).size() == number);
// Wait for readiness
await().atMost(duration()).until(() -> getPodsForDeploymentConfig(client, name).stream().filter(KubernetesHelper::isPodReady).count() == number);
}
return config;
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class ZooKeeperClusterBootstrapImpl method cleanInternal.
private BootstrapConfiguration cleanInternal(final BundleContext syscontext, final BootstrapConfiguration bootConfig, RuntimeProperties runtimeProps) throws TimeoutException {
LOGGER.debug("Begin clean fabric");
try {
Configuration zkClientCfg = null;
Configuration zkServerCfg = null;
Configuration[] configsSet = configAdmin.get().listConfigurations("(|(service.factoryPid=io.fabric8.zookeeper.server)(service.pid=io.fabric8.zookeeper))");
if (configsSet != null) {
for (Configuration cfg : configsSet) {
// let's explicitly delete client config first
if ("io.fabric8.zookeeper".equals(cfg.getPid())) {
zkClientCfg = cfg;
}
if ("io.fabric8.zookeeper.server".equals(cfg.getFactoryPid())) {
zkServerCfg = cfg;
}
}
}
File karafData = new File(data);
// Setup the listener for unregistration of {@link BootstrapConfiguration}
final CountDownLatch unregisterLatch = new CountDownLatch(1);
ServiceListener listener = new ServiceListener() {
@Override
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.UNREGISTERING) {
LOGGER.debug("Unregistering BootstrapConfiguration");
bootConfig.getComponentContext().getBundleContext().removeServiceListener(this);
unregisterLatch.countDown();
}
}
};
String filter = "(objectClass=" + BootstrapConfiguration.class.getName() + ")";
// FABRIC-1052: register listener using the same bundle context that is used for listeners related to SCR
bootConfig.getComponentContext().getBundleContext().addServiceListener(listener, filter);
CountDownLatch unregisterLatch2 = null;
if (syscontext.getServiceReference(CuratorComplete.class) != null) {
unregisterLatch2 = new CountDownLatch(1);
final CountDownLatch finalUnregisterLatch = unregisterLatch2;
listener = new ServiceListener() {
@Override
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.UNREGISTERING) {
LOGGER.debug("Unregistering CuratorComplete");
bootConfig.getComponentContext().getBundleContext().removeServiceListener(this);
finalUnregisterLatch.countDown();
}
}
};
bootConfig.getComponentContext().getBundleContext().addServiceListener(listener, "(objectClass=" + CuratorComplete.class.getName() + ")");
}
// Disable the BootstrapConfiguration component
// ENTESB-4827: disabling BootstrapConfiguration leads to deactivation of FabricService and ProfileUrlHandler
// and we have race condition if we're --cleaning after recently created fabric. previous fabric
// started FabricConfigAdminBridge which scheduled CM updates for tens of PIDs - among others,
// org.ops4j.pax.web, which leads to an attempt to reconfigure Jetty with "profile:jetty.xml"
// and if we disable ProfileUrlHandler we may loose Jetty instance
LOGGER.debug("Disable BootstrapConfiguration");
ComponentContext componentContext = bootConfig.getComponentContext();
componentContext.disableComponent(BootstrapConfiguration.COMPONENT_NAME);
if (!unregisterLatch.await(30, TimeUnit.SECONDS))
throw new TimeoutException("Timeout for unregistering BootstrapConfiguration service");
if (unregisterLatch2 != null && !unregisterLatch2.await(30, TimeUnit.SECONDS))
throw new TimeoutException("Timeout for unregistering CuratorComplete service");
// Do the cleanup
runtimeProps.clearRuntimeAttributes();
cleanConfigurations(syscontext, zkClientCfg, zkServerCfg);
cleanZookeeperDirectory(karafData);
cleanGitDirectory(karafData);
// Setup the registration listener for the new {@link BootstrapConfiguration}
final CountDownLatch registerLatch = new CountDownLatch(1);
final AtomicReference<ServiceReference<?>> sref = new AtomicReference<ServiceReference<?>>();
listener = new ServiceListener() {
@Override
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.REGISTERED) {
LOGGER.debug("Registered BootstrapConfiguration");
syscontext.removeServiceListener(this);
sref.set(event.getServiceReference());
registerLatch.countDown();
}
}
};
syscontext.addServiceListener(listener, "(objectClass=" + BootstrapConfiguration.class.getName() + ")");
// Enable the {@link BootstrapConfiguration} component and await the registration of the respective service
LOGGER.debug("Enable BootstrapConfiguration");
componentContext.enableComponent(BootstrapConfiguration.COMPONENT_NAME);
if (!registerLatch.await(30, TimeUnit.SECONDS))
throw new TimeoutException("Timeout for registering BootstrapConfiguration service");
return (BootstrapConfiguration) syscontext.getService(sref.get());
} catch (RuntimeException rte) {
throw rte;
} catch (TimeoutException toe) {
throw toe;
} catch (Exception ex) {
throw new FabricException("Unable to delete zookeeper configuration", ex);
} finally {
LOGGER.debug("End clean fabric");
}
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class ArchetypeServiceImpl method listArchetypes.
@Override
public List<Archetype> listArchetypes(String filter, boolean artifactIdOnly) {
List<Archetype> answer = new ArrayList<Archetype>();
if (Strings.isNullOrBlank(filter)) {
answer.addAll(listArchetypes());
return answer;
}
filter = filter.toLowerCase();
for (Archetype archetype : archetypes.values()) {
if (artifactIdOnly && archetype.artifactId.toLowerCase().contains(filter)) {
answer.add(archetype);
} else {
if (archetype.groupId.toLowerCase().contains(filter) || archetype.artifactId.toLowerCase().contains(filter) || archetype.version.toLowerCase().contains(filter)) {
answer.add(archetype);
}
}
}
return answer;
}
Aggregations