use of io.fabric8.karaf.checks.Check in project strimzi by strimzi.
the class KafkaClusterTest method testZookeeperScaleUpScaleDown.
@Test
@KafkaCluster(name = "my-cluster", kafkaNodes = 1, zkNodes = 1)
public void testZookeeperScaleUpScaleDown() {
// kafka cluster already deployed via annotation
String clusterName = "my-cluster";
LOGGER.info("Running zookeeperScaleUpScaleDown with cluster {}", clusterName);
// kubeClient.waitForStatefulSet(zookeeperStatefulSetName(clusterName), 1);
KubernetesClient client = new DefaultKubernetesClient();
final int initialReplicas = client.apps().statefulSets().inNamespace(NAMESPACE).withName(zookeeperStatefulSetName(clusterName)).get().getStatus().getReplicas();
assertEquals(1, initialReplicas);
// scale up
final int scaleTo = initialReplicas + 2;
final int[] newPodIds = { initialReplicas, initialReplicas + 1 };
final String[] newPodName = { zookeeperPodName(clusterName, newPodIds[0]), zookeeperPodName(clusterName, newPodIds[1]) };
final String firstPodName = zookeeperPodName(clusterName, 0);
LOGGER.info("Scaling zookeeper up to {}", scaleTo);
replaceCm(clusterName, "zookeeper-nodes", String.valueOf(scaleTo));
kubeClient.waitForPod(newPodName[0]);
kubeClient.waitForPod(newPodName[1]);
// check the new node is either in leader or follower state
waitForZkMntr(firstPodName, Pattern.compile("zk_server_state\\s+(leader|follower)"));
waitForZkMntr(newPodName[0], Pattern.compile("zk_server_state\\s+(leader|follower)"));
waitForZkMntr(newPodName[1], Pattern.compile("zk_server_state\\s+(leader|follower)"));
// TODO Check for k8s events, logs for errors
// scale down
LOGGER.info("Scaling down");
replaceCm(clusterName, "zookeeper-nodes", String.valueOf(1));
kubeClient.waitForResourceDeletion("po", zookeeperPodName(clusterName, 1));
// Wait for the one remaining node to enter standalone mode
waitForZkMntr(firstPodName, Pattern.compile("zk_server_state\\s+standalone"));
// TODO Check for k8s events, logs for errors
}
use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method testSuccessfulBuild.
@Test
public void testSuccessfulBuild() throws Exception {
int nTries = 0;
boolean bTestComplete = false;
do {
try {
nTries++;
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, false, false);
OpenShiftMockServer mockServer = collector.getMockServer();
DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.createOpenShiftClient();
LOG.info("Current write timeout is : {}", client.getHttpClient().writeTimeoutMillis());
LOG.info("Current read timeout is : {}", client.getHttpClient().readTimeoutMillis());
LOG.info("Retry on failure : {}", client.getHttpClient().retryOnConnectionFailure());
OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
service.build(image);
// we should Foadd a better way to assert that a certain call has been made
assertTrue(mockServer.getRequestCount() > 8);
collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
collector.assertEventsNotRecorded("patch-build-config");
bTestComplete = true;
} catch (Fabric8ServiceException exception) {
Throwable rootCause = getRootCause(exception);
logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
// Let's wait for a while, and then retry again
if (rootCause != null && rootCause instanceof IOException) {
continue;
}
}
} while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.
the class ProfileUtil method lookup.
/**
* Lookup profiles from a given directory and merge it with a profile of the
* same name found in the classpath
*
* @param name name of the profile to lookup
* @param directory directory to lookup
* @return Profile found or null
* @throws IOException if somethings fails during lookup
*/
public static Profile lookup(String name, File directory) throws IOException {
// First check from the classpath, these profiles are used as a basis
List<Profile> profiles = readProfileFromClasspath(name);
File profileFile = findProfileYaml(directory);
if (profileFile != null) {
List<Profile> fileProfiles = fromYaml(new FileInputStream(profileFile));
for (Profile profile : fileProfiles) {
if (profile.getName().equals(name)) {
profiles.add(profile);
break;
}
}
}
// "larger" orders are "earlier" in the list
Collections.sort(profiles, Collections.<Profile>reverseOrder());
return mergeProfiles(profiles);
}
use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.
the class KarafHealthCheckEnricher method discoverKarafProbe.
//
// Karaf has a readiness/health URL exposed if the fabric8-karaf-check feature is installed.
//
private Probe discoverKarafProbe(String path, int initialDelay) {
for (Plugin plugin : this.getProject().getBuildPlugins()) {
if ("karaf-maven-plugin".equals(plugin.getArtifactId())) {
Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
if (configuration == null)
return null;
Xpp3Dom startupFeatures = configuration.getChild("startupFeatures");
if (startupFeatures == null)
return null;
for (Xpp3Dom feature : startupFeatures.getChildren("feature")) {
if ("fabric8-karaf-checks".equals(feature.getValue())) {
// TODO: handle the case where the user changes the default port
return new ProbeBuilder().withNewHttpGet().withNewPort(DEFAULT_HEALTH_CHECK_PORT).withPath(path).endHttpGet().withInitialDelaySeconds(initialDelay).build();
}
}
}
}
return null;
}
use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.
the class VertxHealthCheckEnricher method discoverVertxHealthCheck.
private Probe discoverVertxHealthCheck(int initialDelay, boolean readiness) {
if (!isApplicable()) {
return null;
}
int port = getPort();
String path = null;
if (readiness) {
path = getReadinessPath();
if (path != null && path.isEmpty()) {
// Disabled.
return null;
}
}
if (path == null) {
path = getPath();
}
if (port <= 0 || path == null || path.isEmpty()) {
// Health check disabled
return null;
}
String scheme = getScheme();
return new ProbeBuilder().withNewHttpGet().withScheme(scheme).withNewPort(port).withPath(path).endHttpGet().withInitialDelaySeconds(initialDelay).build();
}
Aggregations