use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8-maven-plugin by fabric8io.
the class DebugMojo method portForward.
private void portForward(Controller controller, String podName) throws MojoExecutionException {
try {
getFabric8ServiceHub(controller).getPortForwardService().forwardPort(createExternalProcessLogger("[[B]]port-forward[[B]] "), podName, portToInt(remoteDebugPort, "remoteDebugPort"), portToInt(localDebugPort, "localDebugPort"));
log.info("");
log.info("Now you can start a Remote debug execution in your IDE by using localhost and the debug port " + localDebugPort);
log.info("");
} catch (Fabric8ServiceException e) {
throw new MojoExecutionException("Failed to start port forwarding" + e, e);
}
}
use of io.fabric8.arquillian.kubernetes.event.Start 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
}
}
}
}
use of io.fabric8.arquillian.kubernetes.event.Start in project watchdog by isdream.
the class KubernetesListener method start.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void start(Object client, Configure config) throws Exception {
// System.out.println(config.getApiVersion());
if (ObjectUtils.isNull(client) && ObjectUtils.isNull(config)) {
throw new Exception("Invalid paremeters");
}
// it may throw Exception if wrong PROPERTY_KIND values
Object model = getModelParamtersGenerator().getKindModel(client, config.getKind());
if (model instanceof Namespaceable || model instanceof AnyNamespaceable) {
String namespace = config.getProperties().getOrDefault(PROPERTY_NAMESPACE, ALL_NAMESPACE);
if (ALL_NAMESPACE.equals(namespace)) {
model = ((AnyNamespaceable) model).inAnyNamespace();
} else {
model = ((Namespaceable) model).inNamespace(namespace);
}
}
List<String> handlers = config.getHandlers();
if (handlers.isEmpty()) {
throw new Exception("No handlers");
}
Handler handler = (Handler) Class.forName(handlers.remove(0)).newInstance();
Handler thisHandler = handler;
for (String name : handlers) {
Handler nextHandler = (Handler) Class.forName(name).newInstance();
thisHandler.setNextHandler(nextHandler);
thisHandler = nextHandler;
}
System.out.println(model.getClass());
((Watchable) model).watch(new KubernetesWatcher(handler));
}
use of io.fabric8.arquillian.kubernetes.event.Start in project syndesis-qe by syndesisio.
the class SyndesisDB method deploy.
@Override
public void deploy() {
List<ContainerPort> ports = new LinkedList<>();
ports.add(new ContainerPortBuilder().withName("psql-cmd").withContainerPort(5432).withProtocol("TCP").build());
List<EnvVar> templateParams = new ArrayList<>();
templateParams.add(new EnvVar("POSTGRESQL_USER", DB_ROOT_USER, null));
templateParams.add(new EnvVar("POSTGRESQL_PASSWORD", DB_PASSWORD, null));
// sample DB schema is created by post start script, this DB is not important
templateParams.add(new EnvVar("POSTGRESQL_DATABASE", "whatever", null));
templateParams.add(new EnvVar("POSTGRESQL_SAMPLEDB_PASSWORD", DB_PASSWORD, null));
// config map with the post start script
if (OpenShiftUtils.getInstance().getConfigMap("syndesis-sampledb-config") == null) {
try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-sampledb-config.yml")) {
ConfigMap cm = OpenShiftUtils.getInstance().configMaps().load(is).get();
OpenShiftUtils.getInstance().createConfigMap(cm);
} catch (IOException ex) {
throw new IllegalArgumentException("Unable to read config map ", ex);
}
}
OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("quay.io/syndesis_qe/postgresql-10-centos7:latest").addAllToPorts(ports).addAllToEnv(templateParams).editOrNewLifecycle().editOrNewPostStart().editOrNewExec().addNewCommand("/bin/sh").addNewCommand("-c").addNewCommand("/var/lib/pgsql/sampledb/postStart.sh").endExec().endPostStart().endLifecycle().addNewVolumeMount().withNewMountPath("/var/lib/pgsql/sampledb").withName("syndesis-sampledb-config").endVolumeMount().endContainer().addNewVolume().editOrNewConfigMap().withName("syndesis-sampledb-config").withDefaultMode(511).endConfigMap().withName("syndesis-sampledb-config").endVolume().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("psql-cmd").withPort(5432).withTargetPort(new IntOrString(5432)).build());
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
try {
OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
Thread.sleep(20 * 1000);
} catch (InterruptedException | TimeoutException e) {
log.error("Wait for {} deployment failed ", APP_NAME, e);
}
Account syndesisDbAccount = new Account();
syndesisDbAccount.setService("SyndesisDB");
Map<String, String> accountParameters = new HashMap<>();
accountParameters.put("url", DB_URL);
accountParameters.put("user", DB_SAMPLE_DB_USER);
accountParameters.put("password", DB_PASSWORD);
accountParameters.put("schema", DB_SCHEMA);
syndesisDbAccount.setProperties(accountParameters);
AccountsDirectory.getInstance().addAccount(Account.Name.SYNDESIS_DB.getId(), syndesisDbAccount);
Connection defaultPostgresDBConnection = connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_ORIGINAL);
// (When the test suite was killed before, the backup can exist and original connection was already changed, ignore in that case
if (connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_BACKUP) == null) {
connectionsEndpoint.create(defaultPostgresDBConnection.builder().name(DEFAULT_PSQL_CONNECTION_BACKUP).id("1000").build());
}
// config prop for new instance
Map<String, String> configuredProperties = new HashMap<>(defaultPostgresDBConnection.getConfiguredProperties());
configuredProperties.put("schema", DB_SCHEMA);
configuredProperties.put("password", DB_PASSWORD);
configuredProperties.put("user", DB_SAMPLE_DB_USER);
configuredProperties.put("url", DB_URL);
Connection build = defaultPostgresDBConnection.builder().configuredProperties(configuredProperties).build();
connectionsEndpoint.update(defaultPostgresDBConnection.getId().get(), build);
}
use of io.fabric8.arquillian.kubernetes.event.Start in project docker-maven-plugin by fabric8io.
the class StartMojo method executeInternal.
/**
* {@inheritDoc}
*/
@Override
public synchronized void executeInternal(final ServiceHub hub) throws DockerAccessException, ExecException, MojoExecutionException {
if (skipRun) {
return;
}
getPluginContext().put(CONTEXT_KEY_START_CALLED, true);
this.follow = followLogs();
QueryService queryService = hub.getQueryService();
final RunService runService = hub.getRunService();
PortMapping.PropertyWriteHelper portMappingPropertyWriteHelper = new PortMapping.PropertyWriteHelper(portPropertyFile);
boolean success = false;
final ExecutorService executorService = getExecutorService();
final ExecutorCompletionService<StartedContainer> containerStartupService = new ExecutorCompletionService<>(executorService);
try {
// All aliases which are provided in the image configuration:
final Set<String> imageAliases = new HashSet<>();
// Remember all aliases which has been started
final Set<String> startedContainerAliases = new HashSet<>();
// All images to to start
Queue<ImageConfiguration> imagesWaitingToStart = prepareStart(hub, queryService, runService, imageAliases);
// Queue of images to start as containers
final Queue<ImageConfiguration> imagesStarting = new ArrayDeque<>();
// of the containers so that partial or aborted starts will behave the same as fully-successful ones.
if (follow) {
runService.addShutdownHookForStoppingContainers(keepContainer, removeVolumes, autoCreateCustomNetworks);
}
// Loop until every image has been started and the start of all images has been completed
while (!hasBeenAllImagesStarted(imagesWaitingToStart, imagesStarting)) {
final List<ImageConfiguration> imagesReadyToStart = getImagesWhoseDependenciesHasStarted(imagesWaitingToStart, startedContainerAliases, imageAliases);
for (final ImageConfiguration image : imagesReadyToStart) {
startImage(image, hub, containerStartupService, portMappingPropertyWriteHelper);
// Move from waiting to starting status
imagesStarting.add(image);
imagesWaitingToStart.remove(image);
if (!startParallel) {
waitForStartedContainer(containerStartupService, startedContainerAliases, imagesStarting);
}
}
if (startParallel) {
waitForStartedContainer(containerStartupService, startedContainerAliases, imagesStarting);
}
}
portMappingPropertyWriteHelper.write();
if (follow) {
wait();
}
success = true;
} catch (InterruptedException e) {
log.warn("Interrupted");
Thread.currentThread().interrupt();
throw new MojoExecutionException("interrupted", e);
} catch (IOException e) {
throw new MojoExecutionException("I/O Error", e);
} finally {
shutdownExecutorService(executorService);
// Rollback if not all could be started
if (!success) {
log.error("Error occurred during container startup, shutting down...");
runService.stopStartedContainers(keepContainer, removeVolumes, autoCreateCustomNetworks, getGavLabel());
}
}
}
Aggregations