You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by vd...@apache.org on 2016/04/12 00:20:47 UTC
[1/7] incubator-quarks git commit: QUARKS-XXXX description vdogaru
closes #85
Repository: incubator-quarks
Updated Branches:
refs/heads/master 9c6dc130e -> 03b8df172
QUARKS-XXXX description vdogaru closes #85
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/0a95f309
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/0a95f309
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/0a95f309
Branch: refs/heads/master
Commit: 0a95f3091afdc4f62abb9ffe82afa45d4a39781c
Parents: 6cef2eb
Author: Victor Dogaru <vd...@apache.org>
Authored: Mon Apr 11 12:57:58 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Apr 11 12:57:58 2016 -0700
----------------------------------------------------------------------
.../execution/services/JobRegistryService.java | 125 +++++++++++++++++++
.../services/job/JobRegistryService.java | 125 -------------------
.../java/quarks/apps/runtime/JobMonitorApp.java | 2 +-
.../quarks/apps/runtime/JobMonitorAppEvent.java | 2 +-
.../java/quarks/runtime/etiao/EtiaoJob.java | 2 +-
.../quarks/runtime/jobregistry/JobEvents.java | 4 +-
.../quarks/runtime/jobregistry/JobRegistry.java | 2 +-
.../runtime/jobregistry/JobRegistryTest.java | 4 +-
.../samples/topology/JobEventsSample.java | 2 +-
9 files changed, 134 insertions(+), 134 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/api/execution/src/main/java/quarks/execution/services/JobRegistryService.java
----------------------------------------------------------------------
diff --git a/api/execution/src/main/java/quarks/execution/services/JobRegistryService.java b/api/execution/src/main/java/quarks/execution/services/JobRegistryService.java
new file mode 100644
index 0000000..d379f17
--- /dev/null
+++ b/api/execution/src/main/java/quarks/execution/services/JobRegistryService.java
@@ -0,0 +1,125 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package quarks.execution.services;
+
+import java.util.Set;
+
+import quarks.execution.Job;
+import quarks.function.BiConsumer;
+
+/**
+ * Job registry service.
+ * <p>
+ * Keeps the list of {@link Job} instances registered by the runtime and
+ * provides the necessary methods to register and remove jobs, access
+ * registered jobs, as well as register listeners which are notified on job
+ * registrations, removals, and updates.
+ * The following event types are sent to registered listeners:
+ * <ul>
+ * <li>An {@link EventType#ADD} event is sent when a job is added.</li>
+ * <li>An {@link EventType#REMOVE} event is sent when a job is removed.</li>
+ * <li>An {@link EventType#UPDATE} event is sent when a job is updated.</li>
+ * </ul>
+ * <p>
+ * <h3>Event dispatch</h3>
+ * If a listener invocation throws an Exception, then the exception
+ * will not prevent the remaining listeners from being invoked. However,
+ * if the invocation throws an Error, then it is recommended that
+ * the event dispatch stop.
+ */
+public interface JobRegistryService {
+ /**
+ * Job event types.
+ */
+ enum EventType {
+ /** A Job has been added to the registry. */
+ ADD,
+ /** A Job has been removed from the registry. */
+ REMOVE,
+ /** A registered Job has been updated. */
+ UPDATE
+ }
+
+ /**
+ * Adds a handler to a collection of listeners that will be notified
+ * on job registration and state changes. Listeners will be notified
+ * in the order in which they are added.
+ * <p>
+ * A listener is notified of all existing jobs when it is first added.
+ *
+ * @param listener the listener that will be added
+ * @throws IllegalArgumentException if the listener parameter is
+ * {@code null}
+ */
+ void addListener(BiConsumer<JobRegistryService.EventType, Job> listener)
+ throws IllegalArgumentException;
+
+ /**
+ * Removes a handler from this registry's collection of listeners.
+ *
+ * @param listener the listener that will be removed
+ * @return whether or not the listener has been removed
+ */
+ boolean removeListener(
+ BiConsumer<JobRegistryService.EventType, Job> listener);
+
+ /**
+ * Returns a set of all the registered job identifiers.
+ *
+ * @return the identifiers of all the jobs
+ */
+ Set<String> getJobIds();
+
+ /**
+ * Returns a job given its identifier.
+ *
+ * @return the job or {@code null} if no job is registered with that
+ * identifier.
+ */
+ Job getJob(String id);
+
+ /**
+ * Adds the specified job.
+ *
+ * @param job the job to register
+ *
+ * @throws IllegalArgumentException if a job is null, or if a job with
+ * the same identifier is already registered
+ */
+ void addJob(Job job) throws IllegalArgumentException;
+
+ /**
+ * Removes the job specified by the given identifier.
+ *
+ * @param jobId the identifier of the job to remove
+ * @return whether or not the job was removed
+ */
+ boolean removeJob(String jobId);
+
+ /**
+ * Notifies listeners that the specified registered job has
+ * been updated.
+ *
+ * @param job the job
+ * @return whether or not the job was found in the registry
+ */
+ boolean updateJob(Job job);
+
+ // TODO add job retrieval given its name
+}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/api/execution/src/main/java/quarks/execution/services/job/JobRegistryService.java
----------------------------------------------------------------------
diff --git a/api/execution/src/main/java/quarks/execution/services/job/JobRegistryService.java b/api/execution/src/main/java/quarks/execution/services/job/JobRegistryService.java
deleted file mode 100644
index 0233128..0000000
--- a/api/execution/src/main/java/quarks/execution/services/job/JobRegistryService.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-package quarks.execution.services.job;
-
-import java.util.Set;
-
-import quarks.execution.Job;
-import quarks.function.BiConsumer;
-
-/**
- * Job registry service.
- * <p>
- * Keeps the list of {@link Job} instances registered by the runtime and
- * provides the necessary methods to register and remove jobs, access
- * registered jobs, as well as register listeners which are notified on job
- * registrations, removals, and updates.
- * The following event types are sent to registered listeners:
- * <ul>
- * <li>An {@link EventType#ADD} event is sent when a job is added.</li>
- * <li>An {@link EventType#REMOVE} event is sent when a job is removed.</li>
- * <li>An {@link EventType#UPDATE} event is sent when a job is updated.</li>
- * </ul>
- * <p>
- * <h3>Event dispatch</h3>
- * If a listener invocation throws an Exception, then the exception
- * will not prevent the remaining listeners from being invoked. However,
- * if the invocation throws an Error, then it is recommended that
- * the event dispatch stop.
- */
-public interface JobRegistryService {
- /**
- * Job event types.
- */
- enum EventType {
- /** A Job has been added to the registry. */
- ADD,
- /** A Job has been removed from the registry. */
- REMOVE,
- /** A registered Job has been updated. */
- UPDATE
- }
-
- /**
- * Adds a handler to a collection of listeners that will be notified
- * on job registration and state changes. Listeners will be notified
- * in the order in which they are added.
- * <p>
- * A listener is notified of all existing jobs when it is first added.
- *
- * @param listener the listener that will be added
- * @throws IllegalArgumentException if the listener parameter is
- * {@code null}
- */
- void addListener(BiConsumer<JobRegistryService.EventType, Job> listener)
- throws IllegalArgumentException;
-
- /**
- * Removes a handler from this registry's collection of listeners.
- *
- * @param listener the listener that will be removed
- * @return whether or not the listener has been removed
- */
- boolean removeListener(
- BiConsumer<JobRegistryService.EventType, Job> listener);
-
- /**
- * Returns a set of all the registered job identifiers.
- *
- * @return the identifiers of all the jobs
- */
- Set<String> getJobIds();
-
- /**
- * Returns a job given its identifier.
- *
- * @return the job or {@code null} if no job is registered with that
- * identifier.
- */
- Job getJob(String id);
-
- /**
- * Adds the specified job.
- *
- * @param job the job to register
- *
- * @throws IllegalArgumentException if a job is null, or if a job with
- * the same identifier is already registered
- */
- void addJob(Job job) throws IllegalArgumentException;
-
- /**
- * Removes the job specified by the given identifier.
- *
- * @param jobId the identifier of the job to remove
- * @return whether or not the job was removed
- */
- boolean removeJob(String jobId);
-
- /**
- * Notifies listeners that the specified registered job has
- * been updated.
- *
- * @param job the job
- * @return whether or not the job was found in the registry
- */
- boolean updateJob(Job job);
-
- // TODO add job retrieval given its name
-}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorApp.java
----------------------------------------------------------------------
diff --git a/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorApp.java b/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorApp.java
index f09b660..8e798c9 100644
--- a/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorApp.java
+++ b/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorApp.java
@@ -31,8 +31,8 @@ import com.google.gson.JsonObject;
import quarks.execution.DirectSubmitter;
import quarks.execution.Job;
import quarks.execution.services.ControlService;
+import quarks.execution.services.JobRegistryService;
import quarks.execution.services.RuntimeServices;
-import quarks.execution.services.job.JobRegistryService;
import quarks.function.Consumer;
import quarks.function.Supplier;
import quarks.runtime.jobregistry.JobEvents;
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorAppEvent.java
----------------------------------------------------------------------
diff --git a/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorAppEvent.java b/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorAppEvent.java
index 985e0cb..9ab95fb 100644
--- a/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorAppEvent.java
+++ b/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorAppEvent.java
@@ -22,7 +22,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import quarks.execution.Job;
-import quarks.execution.services.job.JobRegistryService;
+import quarks.execution.services.JobRegistryService;
/**
* Helpers for parsing generating and parsing a JSON representation of job
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java
----------------------------------------------------------------------
diff --git a/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java b/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java
index 2574923..b5c1088 100644
--- a/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java
+++ b/runtime/etiao/src/main/java/quarks/runtime/etiao/EtiaoJob.java
@@ -27,8 +27,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import quarks.execution.mbeans.JobMXBean;
import quarks.execution.services.ControlService;
+import quarks.execution.services.JobRegistryService;
import quarks.execution.services.ServiceContainer;
-import quarks.execution.services.job.JobRegistryService;
import quarks.graph.spi.execution.AbstractGraphJob;
import quarks.oplet.JobContext;
import quarks.runtime.etiao.graph.DirectGraph;
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobEvents.java
----------------------------------------------------------------------
diff --git a/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobEvents.java b/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobEvents.java
index 24fffd1..298450f 100644
--- a/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobEvents.java
+++ b/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobEvents.java
@@ -19,9 +19,9 @@ under the License.
package quarks.runtime.jobregistry;
import quarks.execution.Job;
+import quarks.execution.services.JobRegistryService;
import quarks.execution.services.RuntimeServices;
-import quarks.execution.services.job.JobRegistryService;
-import quarks.execution.services.job.JobRegistryService.EventType;
+import quarks.execution.services.JobRegistryService.EventType;
import quarks.function.BiConsumer;
import quarks.function.BiFunction;
import quarks.function.Consumer;
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobRegistry.java
----------------------------------------------------------------------
diff --git a/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobRegistry.java b/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobRegistry.java
index 316d28c..c0a9804 100644
--- a/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobRegistry.java
+++ b/runtime/jobregistry/src/main/java/quarks/runtime/jobregistry/JobRegistry.java
@@ -29,8 +29,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import quarks.execution.Job;
+import quarks.execution.services.JobRegistryService;
import quarks.execution.services.ServiceContainer;
-import quarks.execution.services.job.JobRegistryService;
import quarks.function.BiConsumer;
/**
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java
----------------------------------------------------------------------
diff --git a/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java b/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java
index 7f00039..449c362 100644
--- a/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java
+++ b/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java
@@ -28,8 +28,8 @@ import java.util.concurrent.TimeoutException;
import org.junit.Test;
import quarks.execution.Job;
-import quarks.execution.services.job.JobRegistryService;
-import quarks.execution.services.job.JobRegistryService.EventType;
+import quarks.execution.services.JobRegistryService;
+import quarks.execution.services.JobRegistryService.EventType;
import quarks.function.BiConsumer;
import quarks.runtime.jobregistry.JobRegistry;
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/0a95f309/samples/topology/src/main/java/quarks/samples/topology/JobEventsSample.java
----------------------------------------------------------------------
diff --git a/samples/topology/src/main/java/quarks/samples/topology/JobEventsSample.java b/samples/topology/src/main/java/quarks/samples/topology/JobEventsSample.java
index f0d4f28..df4e221 100644
--- a/samples/topology/src/main/java/quarks/samples/topology/JobEventsSample.java
+++ b/samples/topology/src/main/java/quarks/samples/topology/JobEventsSample.java
@@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit;
import com.google.gson.JsonObject;
import quarks.execution.Job;
-import quarks.execution.services.job.JobRegistryService;
+import quarks.execution.services.JobRegistryService;
import quarks.providers.direct.DirectProvider;
import quarks.runtime.jobregistry.JobEvents;
import quarks.runtime.jobregistry.JobRegistry;
[4/7] incubator-quarks git commit: QUARKS-13-vdogaru Script and
crontab entry for Quarks jvm monitoring
Posted by vd...@apache.org.
QUARKS-13-vdogaru Script and crontab entry for Quarks jvm monitoring
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/9a67449b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/9a67449b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/9a67449b
Branch: refs/heads/master
Commit: 9a67449b2624dce92b0f23d61e36353fed2cb94f
Parents: 3a535e8
Author: Victor Dogaru <vd...@apache.org>
Authored: Thu Apr 7 13:09:50 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Apr 11 14:57:38 2016 -0700
----------------------------------------------------------------------
scripts/cron/README | 38 +++++++++++++
scripts/cron/startapp.cron | 27 +++++++++
scripts/cron/startapp.sh | 119 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 184 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/9a67449b/scripts/cron/README
----------------------------------------------------------------------
diff --git a/scripts/cron/README b/scripts/cron/README
new file mode 100644
index 0000000..e53f21f
--- /dev/null
+++ b/scripts/cron/README
@@ -0,0 +1,38 @@
+Script for restarting Quarks if the JVM crashes
+
+The startapp.sh script is setup to run as a cron job every minute in order
+to monitor a JVM running a Quarks application and restart Quarks if the
+JVM crashes. The script checks whether the pid of the JVM indicates
+a process which is still running. If the pid is not there, it executes the
+command to start the application in the first place.
+
+The JVM's standard output and standard error are written to the directory
+passed as a command line argument for the script. The script also saves the
+process id (pid) of the JVM in a file. If the pid file already exists and
+contains the id of a running process, then the script will not start Quarks.
+
+The script is currently setup to execute the quarks.samples.topology.Terminated
+sample, which throws an exception after processing a preset number of
+tuples.
+
+The crontab entry file startapp.cron contains information which cron uses to
+schedule the job.
+
+To setup the script to run as a cron job:
+
+1. Edit the startapp.cron file:
+ - Set the QUARKS environment variable to point to your quarks installation,
+ for example: QUARKS=/home/your_userid/quarks-release/quarks/java8
+ - Make sure java is in the path; cron provides a default PATH environment
+ variable which is probably different from the one you use for development.
+
+2. Install startapp.cron:
+
+$ crontab ./startapp.cron
+
+ Note: if you wish to have your ~/.profile executed you must explicitly
+ do so in the crontab entry or in a script called by the entry.
+
+3. To remove the current crontab entries:
+
+$ crontab -r
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/9a67449b/scripts/cron/startapp.cron
----------------------------------------------------------------------
diff --git a/scripts/cron/startapp.cron b/scripts/cron/startapp.cron
new file mode 100644
index 0000000..a086a4c
--- /dev/null
+++ b/scripts/cron/startapp.cron
@@ -0,0 +1,27 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Crontab file which contains settings for scheduling the execution of a
+# monitoring script every minute using cron.
+#
+# You must set the QUARKS environment variable to point to your Quarks
+# installation:
+# QUARKS=/home/your_userid/quarks/java8
+#
+# Make sure that java is in the PATH environment used by cron:
+# PATH=/opt/my_java/bin:$PATH
+
+* * * * * $QUARKS/scripts/cron/startapp.sh /tmp >> /tmp/quarks-cron.log
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/9a67449b/scripts/cron/startapp.sh
----------------------------------------------------------------------
diff --git a/scripts/cron/startapp.sh b/scripts/cron/startapp.sh
new file mode 100755
index 0000000..903010f
--- /dev/null
+++ b/scripts/cron/startapp.sh
@@ -0,0 +1,119 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+[ ! -n "${QUARKS:-}" ] && QUARKS=../..
+
+#
+# Application name identifies the running process. For the scope of this
+# script it is also the name of the main application class.
+#
+APP=TerminateAfterNTuples
+
+#
+# Command to start the application.
+#
+COMMAND="java -cp ${QUARKS}/samples/lib/quarks.samples.topology.jar \
+quarks.samples.topology.${APP}"
+
+
+_usage() {
+ echo -e "Usage: ${0} [dir] \n\
+ Runs an application while saving its stdout to dir/${APP}.out, its stderr to dir/${APP}.err, and its process id to dir/${APP}.pid.\n\
+ \n\
+ This script starts the application only if it cannot find its pid. If the process id indicated by dir/${APP}.pid exists, then the script will not start the application.\n\
+ \n\
+ If dir is not specified, then the stdout, stderr, and pid files are saved into the current directory.\n\
+"
+}
+
+# _get_pid program [pidfile]
+# Set $pid to pids from /tmp* for {program}.
+# $pid should be declared local in the caller.
+_get_pid() {
+ local base=${1##*/}
+ local pid_file=${2:-/tmp/$base.pid}
+
+ pid=
+ if [ -f "$pid_file" ] ; then
+ local p
+
+ [ ! -r "$pid_file" ] && return 1 # "Cannot access pid file"
+
+ p=$(cat "$pid_file")
+ [ -z "${p//[0-9]/}" ] && [ -d "/proc/$p" ] && pid="$p"
+ if [ -n "$pid" ]; then
+ return 0
+ fi
+ return 2 # "Program is not running but pid file exists"
+ fi
+ return 3 # "Program pid file does not exist"
+}
+
+# _readlink path
+# Output the full path, replacement for readlink -f
+_readlink() {
+ (
+ pushd ${1%/*} > /dev/null 2>&1
+ echo $PWD/${1##*/}
+ popd > /dev/null 2>&1
+ )
+}
+
+# _dirname path
+# Get the directory name, replacement for dirname.
+_dirname() {
+ echo ${1%/*}
+}
+
+_error() {
+ echo $1; exit 1
+}
+
+
+if [ "${1:-.}" == "--help" ]; then
+ _usage
+ exit 1
+fi
+
+out_dir=${1:-.}
+
+if [[ ! -d ${out_dir} || ${out_dir:0:1} != '/' ]]; then
+ ## out_dir as absolute path
+ out_dir=$(_readlink ${out_dir})
+ out_dir=$(_dirname ${out_dir})
+fi
+
+pid_file=${out_dir}/${APP}.pid
+out_file=${out_dir}/${APP}.out
+err_file=${out_dir}/${APP}.err
+pid=
+
+_get_pid $APP $pid_file
+RC="$?"
+[ $RC == "1" ] && _error "Cannot access pid file $pid_file"
+
+if [ -z "$pid" ]; then
+ ${COMMAND} >> $out_file 2>> $err_file &
+ pid="$!"
+ echo $pid >| $pid_file
+ echo -e "The program was restarted with command:\n\
+${COMMAND}\n\
+Process id: $pid"
+else
+ echo "The program's process id is $pid"
+fi
[7/7] incubator-quarks git commit: QUARKS-13-vdogaru Sample app which
terminates the JVM after N tuples
Posted by vd...@apache.org.
QUARKS-13-vdogaru Sample app which terminates the JVM after N tuples
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/3a535e86
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/3a535e86
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/3a535e86
Branch: refs/heads/master
Commit: 3a535e86e59b2934b30ec71aceb8a6023c41ae0e
Parents: 8c4f6e1
Author: Victor Dogaru <vd...@apache.org>
Authored: Thu Apr 7 13:08:24 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Apr 11 14:57:38 2016 -0700
----------------------------------------------------------------------
.../samples/topology/TerminateAfterNTuples.java | 67 ++++++++++++++++++++
1 file changed, 67 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/3a535e86/samples/topology/src/main/java/quarks/samples/topology/TerminateAfterNTuples.java
----------------------------------------------------------------------
diff --git a/samples/topology/src/main/java/quarks/samples/topology/TerminateAfterNTuples.java b/samples/topology/src/main/java/quarks/samples/topology/TerminateAfterNTuples.java
new file mode 100644
index 0000000..bffee69
--- /dev/null
+++ b/samples/topology/src/main/java/quarks/samples/topology/TerminateAfterNTuples.java
@@ -0,0 +1,67 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package quarks.samples.topology;
+
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import quarks.providers.direct.DirectProvider;
+import quarks.topology.TStream;
+import quarks.topology.Topology;
+
+/**
+ * This application simulates a crash and terminates the JVM after processing
+ * a preset number of tuples. This application is used in conjunction with a
+ * monitoring script to demonstrate the restart of a JVM which has terminated
+ * because of a Quarks application crash.
+ */
+public class TerminateAfterNTuples {
+ /** The application will terminate the JVM after this tuple count */
+ public final static int TERMINATE_COUNT = 15;
+
+ public static void main(String[] args) throws Exception {
+
+ DirectProvider tp = new DirectProvider();
+
+ Topology t = tp.newTopology("PeriodicSource");
+
+ // Since this is the Direct provider the graph can access
+ // objects created while the topology is being defined
+ // (in this case the Random object r).
+ Random r = new Random();
+ TStream<Double> gaussian = t.poll(() -> r.nextGaussian(), 1, TimeUnit.SECONDS);
+
+ // Program termination
+ AtomicInteger count = new AtomicInteger(0);
+ gaussian = gaussian.peek(g -> {
+ if (count.incrementAndGet() >= TERMINATE_COUNT) {
+ System.err.println("The JVM terminates after processing " +
+ TERMINATE_COUNT + " tuples");
+ System.exit(1);
+ }
+ });
+
+ // Peek at the value on the Stream printing it to System.out
+ gaussian = gaussian.peek(g -> System.out.println("R:" + g));
+
+ tp.submit(t);
+ }
+}
[2/7] incubator-quarks git commit: Merge branch 'master' of
github.com:vdogaru/incubator-quarks
Posted by vd...@apache.org.
Merge branch 'master' of github.com:vdogaru/incubator-quarks
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/a993f041
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/a993f041
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/a993f041
Branch: refs/heads/master
Commit: a993f04176611ba40b835c808893bebc4aff8589
Parents: cef5958 0a95f30
Author: Victor Dogaru <vd...@apache.org>
Authored: Mon Apr 11 13:21:36 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Apr 11 13:21:36 2016 -0700
----------------------------------------------------------------------
----------------------------------------------------------------------
[6/7] incubator-quarks git commit: QUARKS-13 update crontab and
instructions to use the updated startapp.sh
Posted by vd...@apache.org.
QUARKS-13 update crontab and instructions to use the updated startapp.sh
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/03b8df17
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/03b8df17
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/03b8df17
Branch: refs/heads/master
Commit: 03b8df1722fcc1166073ed878c8e5b7d539b4fa9
Parents: 57ab58c
Author: Victor Dogaru <vd...@apache.org>
Authored: Mon Apr 11 11:40:18 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Apr 11 14:57:38 2016 -0700
----------------------------------------------------------------------
scripts/cron/README | 34 +++++++++++++---------------------
scripts/cron/startapp.cron | 6 +++---
2 files changed, 16 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/03b8df17/scripts/cron/README
----------------------------------------------------------------------
diff --git a/scripts/cron/README b/scripts/cron/README
index e53f21f..8b1e1f2 100644
--- a/scripts/cron/README
+++ b/scripts/cron/README
@@ -1,38 +1,30 @@
-Script for restarting Quarks if the JVM crashes
+Restarting Quarks if the JVM crashes
-The startapp.sh script is setup to run as a cron job every minute in order
+The startapp.sh script can be setup to run as a cron job every minute in order
to monitor a JVM running a Quarks application and restart Quarks if the
JVM crashes. The script checks whether the pid of the JVM indicates
a process which is still running. If the pid is not there, it executes the
command to start the application in the first place.
-The JVM's standard output and standard error are written to the directory
-passed as a command line argument for the script. The script also saves the
-process id (pid) of the JVM in a file. If the pid file already exists and
-contains the id of a running process, then the script will not start Quarks.
+A crontab entry file contains information which cron uses to schedule the job.
+The sample startapp.cron file is configured to execute the
+quarks.samples.topology.Terminated sample application, which terminates the
+JVM after processing a preset number of tuples.
-The script is currently setup to execute the quarks.samples.topology.Terminated
-sample, which throws an exception after processing a preset number of
-tuples.
-
-The crontab entry file startapp.cron contains information which cron uses to
-schedule the job.
-
-To setup the script to run as a cron job:
+To setup cron to restart quarks.samples.topology.Terminated every minute:
1. Edit the startapp.cron file:
- - Set the QUARKS environment variable to point to your quarks installation,
- for example: QUARKS=/home/your_userid/quarks-release/quarks/java8
- - Make sure java is in the path; cron provides a default PATH environment
- variable which is probably different from the one you use for development.
+ - Set the QUARKS environment variable to point to your quarks installation,
+ for example: QUARKS=/home/your_userid/quarks-release/quarks/java8
+ - Set JAVA_HOME to point to your Java install directory.
-2. Install startapp.cron:
+2. Install startapp.cron:
-$ crontab ./startapp.cron
+ $ crontab ./startapp.cron
Note: if you wish to have your ~/.profile executed you must explicitly
do so in the crontab entry or in a script called by the entry.
3. To remove the current crontab entries:
-$ crontab -r
+ $ crontab -r
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/03b8df17/scripts/cron/startapp.cron
----------------------------------------------------------------------
diff --git a/scripts/cron/startapp.cron b/scripts/cron/startapp.cron
index a086a4c..4b5d5c2 100644
--- a/scripts/cron/startapp.cron
+++ b/scripts/cron/startapp.cron
@@ -21,7 +21,7 @@
# installation:
# QUARKS=/home/your_userid/quarks/java8
#
-# Make sure that java is in the PATH environment used by cron:
-# PATH=/opt/my_java/bin:$PATH
+# Make sure that JAVA_HOME is set in the environment used by cron:
+# JAVA_HOME=/usr/lib/jvm/jre
-* * * * * $QUARKS/scripts/cron/startapp.sh /tmp >> /tmp/quarks-cron.log
+* * * * * $QUARKS/scripts/cron/startapp.sh $QUARKS/samples/lib/quarks.samples.topology.jar quarks.samples.topology.TerminateAfterNTuples /tmp >> /tmp/quarks-cron.log
[3/7] incubator-quarks git commit: Merge branch 'master' of
github.com:vdogaru/incubator-quarks
Posted by vd...@apache.org.
Merge branch 'master' of github.com:vdogaru/incubator-quarks
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/8c4f6e14
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/8c4f6e14
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/8c4f6e14
Branch: refs/heads/master
Commit: 8c4f6e1495bd5bbd70f755d383a62b0758a14b53
Parents: 9c6dc13 a993f04
Author: Victor Dogaru <vd...@apache.org>
Authored: Mon Apr 11 14:50:25 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Apr 11 14:50:25 2016 -0700
----------------------------------------------------------------------
----------------------------------------------------------------------
[5/7] incubator-quarks git commit: QUARKS-13 startapp.sh starts
applications passed on the command line
Posted by vd...@apache.org.
QUARKS-13 startapp.sh starts applications passed on the command line
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/57ab58c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/57ab58c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/57ab58c2
Branch: refs/heads/master
Commit: 57ab58c27c81e6c5b61bca3ef01da45e5d37104b
Parents: 9a67449
Author: Victor Dogaru <vd...@apache.org>
Authored: Mon Apr 11 11:04:45 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Apr 11 14:57:38 2016 -0700
----------------------------------------------------------------------
scripts/cron/startapp.sh | 56 +++++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/57ab58c2/scripts/cron/startapp.sh
----------------------------------------------------------------------
diff --git a/scripts/cron/startapp.sh b/scripts/cron/startapp.sh
index 903010f..73500af 100755
--- a/scripts/cron/startapp.sh
+++ b/scripts/cron/startapp.sh
@@ -16,28 +16,17 @@
# limitations under the License.
#
-[ ! -n "${QUARKS:-}" ] && QUARKS=../..
-
-#
-# Application name identifies the running process. For the scope of this
-# script it is also the name of the main application class.
-#
-APP=TerminateAfterNTuples
-
-#
-# Command to start the application.
-#
-COMMAND="java -cp ${QUARKS}/samples/lib/quarks.samples.topology.jar \
-quarks.samples.topology.${APP}"
-
-
_usage() {
- echo -e "Usage: ${0} [dir] \n\
- Runs an application while saving its stdout to dir/${APP}.out, its stderr to dir/${APP}.err, and its process id to dir/${APP}.pid.\n\
- \n\
- This script starts the application only if it cannot find its pid. If the process id indicated by dir/${APP}.pid exists, then the script will not start the application.\n\
- \n\
- If dir is not specified, then the stdout, stderr, and pid files are saved into the current directory.\n\
+ echo -e "Usage: ${0} {classpath} {mainclass} [dir]\n\n\
+Runs a Java application while saving its stdout to dir/mainclass.out, its stderr to dir/mainclass.err, and its process id to dir/mainclass.pid.\n\
+\n\
+This script starts a Java application only if it cannot find its pid. If the process id specified by dir/mainclass.pid exists, then the script will not start the application.\n\
+\n\
+ classpath The application's class path.\n\
+ classname The name of the class to be launched.\n\
+ dir The directory where the process stdout, stderr and pid files are\n\
+ written. If dir is not specified, then the files are saved into\n\
+ the current directory.\n\
"
}
@@ -85,12 +74,21 @@ _error() {
}
-if [ "${1:-.}" == "--help" ]; then
+## Main script
+[ ! -n "${QUARKS:-}" ] && QUARKS=../..
+[ ! -n "${JAVA_HOME:-}" ] && _error "JAVA_HOME must be set"
+
+if [ $# -lt 2 ]; then
_usage
exit 1
fi
-out_dir=${1:-.}
+classpath=${1}
+main_class=${2}
+out_dir=${3:-.}
+
+# Command to start the application.
+command="${JAVA_HOME}/bin/java -cp ${classpath} ${main_class}"
if [[ ! -d ${out_dir} || ${out_dir:0:1} != '/' ]]; then
## out_dir as absolute path
@@ -98,21 +96,21 @@ if [[ ! -d ${out_dir} || ${out_dir:0:1} != '/' ]]; then
out_dir=$(_dirname ${out_dir})
fi
-pid_file=${out_dir}/${APP}.pid
-out_file=${out_dir}/${APP}.out
-err_file=${out_dir}/${APP}.err
+pid_file=${out_dir}/${main_class}.pid
+out_file=${out_dir}/${main_class}.out
+err_file=${out_dir}/${main_class}.err
pid=
-_get_pid $APP $pid_file
+_get_pid $main_class $pid_file
RC="$?"
[ $RC == "1" ] && _error "Cannot access pid file $pid_file"
if [ -z "$pid" ]; then
- ${COMMAND} >> $out_file 2>> $err_file &
+ $command >> $out_file 2>> $err_file &
pid="$!"
echo $pid >| $pid_file
echo -e "The program was restarted with command:\n\
-${COMMAND}\n\
+${command}\n\
Process id: $pid"
else
echo "The program's process id is $pid"