use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by jboss-fuse.
the class AutoScaleController method stopContainers.
protected void stopContainers(List<Container> containers, ContainerAutoScaler autoScaler, FabricRequirements requirements, ProfileRequirements profileRequirement, AutoScaleStatus status, int delta) {
final String profile = profileRequirement.getProfile();
AutoScaleProfileStatus profileStatus = status.profileStatus(profile);
// TODO sort the containers using some kind of requirements sorting order
List<Container> sorted = new ArrayList<>(containers);
// lets stop the ones at the end of the list by default
Collections.reverse(sorted);
List<String> stoppingContainerIds = new ArrayList<>();
for (int i = 0; i < delta; i++) {
if (i >= sorted.size()) {
break;
}
Container container = sorted.get(i);
stoppingContainerIds.add(container.getId());
profileStatus.stoppingContainers(stoppingContainerIds);
container.stop(true);
}
}
use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by jboss-fuse.
the class Activator method stop.
/**
* Performs cleanup:<br/>
* * Unregister handler;<br/>
* * Unregister managed service;<br/>
* * Release bundle context.
*
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(final BundleContext bundleContext) {
if (m_handlerReg != null) {
m_handlerReg.unregister();
m_handlerReg = null;
}
if (m_managedServiceReg != null) {
m_managedServiceReg.unregister();
m_managedServiceReg = null;
}
ServiceRegistration<MavenResolver> registration = m_resolverReg.getAndSet(null);
if (registration != null) {
registration.unregister();
}
MavenResolver resolver = m_resolver.getAndSet(null);
if (resolver != null) {
try {
resolver.close();
} catch (IOException e) {
// Ignore
}
}
m_bundleContext = null;
LOG.debug("Handler for protocols " + PROTOCOL + " stopped");
}
use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by jboss-fuse.
the class ContainerBuilder method stop.
/**
* Stop the given containers.
* The container directory will not get deleted.
*/
public static void stop(Set<? extends Container> containers) {
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(getBundleContext(), FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
for (Container aux : containers) {
try {
// We want to use the latest metadata
Container updated = fabricService.getContainer(aux.getId());
updated.stop(true);
} catch (Exception ex) {
ex.printStackTrace(System.err);
// noop
}
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8-maven-plugin by fabric8io.
the class PodLogService method tailAppPodsLogs.
public void tailAppPodsLogs(final KubernetesClient kubernetes, final String namespace, final Set<HasMetadata> entities, boolean watchAddedPodsOnly, String onExitOperation, boolean followLog, Date ignorePodsOlderThan, boolean waitInCurrentThread) {
LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(entities);
if (selector != null) {
String ctrlCMessage = "stop tailing the log";
if (Strings.isNotBlank(onExitOperation)) {
final String onExitOperationLower = onExitOperation.toLowerCase().trim();
if (onExitOperationLower.equals(OPERATION_UNDEPLOY)) {
ctrlCMessage = "undeploy the app";
} else if (onExitOperationLower.equals(OPERATION_STOP)) {
ctrlCMessage = "scale down the app and stop tailing the log";
} else {
log.warn("Unknown on-exit command: `%s`", onExitOperationLower);
}
resizeApp(kubernetes, namespace, entities, 1, log);
Runtime.getRuntime().addShutdownHook(new Thread("pod log service shutdown hook") {
@Override
public void run() {
if (onExitOperationLower.equals(OPERATION_UNDEPLOY)) {
log.info("Undeploying the app:");
deleteEntities(kubernetes, namespace, entities, context.getS2iBuildNameSuffix(), log);
} else if (onExitOperationLower.equals(OPERATION_STOP)) {
log.info("Stopping the app:");
resizeApp(kubernetes, namespace, entities, 0, log);
}
if (podWatcher != null) {
podWatcher.close();
}
closeLogWatcher();
}
});
}
waitAndLogPods(kubernetes, namespace, selector, watchAddedPodsOnly, ctrlCMessage, followLog, ignorePodsOlderThan, waitInCurrentThread);
} else {
log.warn("No selector in deployment so cannot watch pods!");
}
}
use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8-maven-plugin by fabric8io.
the class PodLogService method waitAndLogPods.
private void waitAndLogPods(final KubernetesClient kubernetes, final String namespace, LabelSelector selector, final boolean watchAddedPodsOnly, final String ctrlCMessage, final boolean followLog, Date ignorePodsOlderThan, boolean waitInCurrentThread) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> pods = withSelector(kubernetes.pods().inNamespace(namespace), selector, log);
if (context.getPodName() != null) {
log.info("Watching pod with selector %s, and name %s waiting for a running pod...", selector, context.getPodName());
pods = pods.withField("metadata.name", context.getPodName());
} else {
log.info("Watching pods with selector %s waiting for a running pod...", selector);
}
Pod latestPod = null;
boolean runningPod = false;
PodList list = pods.list();
if (list != null) {
List<Pod> items = list.getItems();
if (items != null) {
for (Pod pod : items) {
PodStatusType status = getPodStatus(pod);
switch(status) {
case WAIT:
case OK:
if (latestPod == null || KubernetesResourceUtil.isNewerResource(pod, latestPod)) {
if (ignorePodsOlderThan != null) {
Date podCreateTime = KubernetesResourceUtil.getCreationTimestamp(pod);
if (podCreateTime != null && podCreateTime.compareTo(ignorePodsOlderThan) > 0) {
latestPod = pod;
}
} else {
latestPod = pod;
}
}
runningPod = true;
break;
case ERROR:
default:
continue;
}
}
}
}
// we may have missed the ADDED event so lets simulate one
if (latestPod != null) {
onPod(Watcher.Action.ADDED, latestPod, kubernetes, namespace, ctrlCMessage, followLog);
}
if (!watchAddedPodsOnly) {
// lets watch the current pods then watch for changes
if (!runningPod) {
log.warn("No pod is running yet. Are you sure you deployed your app via `fabric8:deploy`?");
log.warn("Or did you stop it via `fabric8:stop`? If so try running the `fabric8:start` goal");
}
}
podWatcher = pods.watch(new Watcher<Pod>() {
@Override
public void eventReceived(Action action, Pod pod) {
onPod(action, pod, kubernetes, namespace, ctrlCMessage, followLog);
}
@Override
public void onClose(KubernetesClientException e) {
// ignore
}
});
if (waitInCurrentThread) {
while (terminateLatch.getCount() > 0) {
try {
terminateLatch.await();
} catch (InterruptedException e) {
// ignore
}
}
}
}
Aggregations