You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2016/04/08 15:26:14 UTC
[3/4] incubator-quarks git commit: QUARKS-116: MonitorAppEvent -->
JobMonitorAppEvent
QUARKS-116: MonitorAppEvent --> JobMonitorAppEvent
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/5d1f7c47
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/5d1f7c47
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/5d1f7c47
Branch: refs/heads/master
Commit: 5d1f7c4719d2011fa6c2eee087f4710fbc5333dc
Parents: 46b25cd
Author: Victor Dogaru <vd...@apache.org>
Authored: Thu Apr 7 17:17:56 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Thu Apr 7 17:17:56 2016 -0700
----------------------------------------------------------------------
.../java/quarks/apps/runtime/JobMonitorApp.java | 10 +-
.../quarks/apps/runtime/JobMonitorAppEvent.java | 113 +++++++++++++++++++
.../quarks/apps/runtime/MonitorAppEvent.java | 113 -------------------
3 files changed, 118 insertions(+), 118 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/5d1f7c47/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 84e9309..f09b660 100644
--- a/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorApp.java
+++ b/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorApp.java
@@ -148,7 +148,7 @@ public class JobMonitorApp {
Topology t = provider.newTopology(name);
TStream<JsonObject> jobEvents = JobEvents.source(
t,
- (evType, job) -> { return MonitorAppEvent.toJsonObject(evType, job); }
+ (evType, job) -> { return JobMonitorAppEvent.toJsonObject(evType, job); }
);
jobEvents = jobEvents.filter(
@@ -156,9 +156,9 @@ public class JobMonitorApp {
logger.trace("Filter: {}", value);
try {
- JsonObject job = MonitorAppEvent.getJob(value);
+ JsonObject job = JobMonitorAppEvent.getJob(value);
return (Job.Health.UNHEALTHY.name().equals(
- MonitorAppEvent.getJobHealth(job)));
+ JobMonitorAppEvent.getJobHealth(job)));
} catch (IllegalArgumentException e) {
logger.info("Invalid event filtered out, cause: {}", e.getMessage());
return false;
@@ -184,8 +184,8 @@ public class JobMonitorApp {
@Override
public void accept(JsonObject value) {
ControlService controlService = rts.get().getService(ControlService.class);
- JsonObject job = MonitorAppEvent.getJob(value);
- String applicationName = MonitorAppEvent.getJobName(job);
+ JsonObject job = JobMonitorAppEvent.getJob(value);
+ String applicationName = JobMonitorAppEvent.getJobName(job);
logger.info("Will restart monitored application {}, cause: {}", applicationName, value);
submitApplication(applicationName, controlService);
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/5d1f7c47/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
new file mode 100644
index 0000000..985e0cb
--- /dev/null
+++ b/apps/runtime/src/main/java/quarks/apps/runtime/JobMonitorAppEvent.java
@@ -0,0 +1,113 @@
+/*
+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.apps.runtime;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import quarks.execution.Job;
+import quarks.execution.services.job.JobRegistryService;
+
+/**
+ * Helpers for parsing generating and parsing a JSON representation of job
+ * monitoring events.
+ */
+class JobMonitorAppEvent {
+
+ /**
+ * Creates a JsonObject wrapping a {@code JobRegistryService} event type
+ * and Job info.
+ *
+ * @param evType the event type
+ * @param job the job
+ * @return the wrapped data
+ */
+ static JsonObject toJsonObject(JobRegistryService.EventType evType, Job job) {
+ JsonObject value = new JsonObject();
+ value.addProperty("time", (Number)System.currentTimeMillis());
+ value.addProperty("event", evType.toString());
+ JsonObject obj = new JsonObject();
+ obj.addProperty("id", job.getId());
+ obj.addProperty("name", job.getName());
+ obj.addProperty("state", job.getCurrentState().toString());
+ obj.addProperty("nextState", job.getNextState().toString());
+ obj.addProperty("health", job.getHealth().toString());
+ obj.addProperty("lastError", job.getLastError());
+ value.add("job", obj);
+ return value;
+ }
+
+ /**
+ * Gets the {@code job} JsonObject from the given JSON value.
+ *
+ * @param value a JSON object
+ * @return the job JsonObject
+ */
+ static JsonObject getJob(JsonObject value) {
+ JsonObject job = value.getAsJsonObject("job");
+ if (job == null) {
+ throw new IllegalArgumentException("Could not find the job object in: " + value);
+ }
+ return job;
+ }
+
+ /**
+ * Gets the {@code name} string property from the given job JSON object.
+ *
+ * @param job the job JSON object
+ * @return the job name
+ * @throws IllegalArgumentException if it could not find the property
+ */
+ static String getJobName(JsonObject job) {
+ return getProperty(job, "name");
+ }
+
+ /**
+ * Gets the {@code health} string property from the given job JSON object.
+ *
+ * @param job the job JSON object
+ * @return the job health
+ * @throws IllegalArgumentException if it could not find the property
+ */
+ static String getJobHealth(JsonObject job) {
+ return getProperty(job, "health");
+ }
+
+ /**
+ * Gets a string property with the specified name from the given JSON
+ * object.
+ *
+ * @param value a JSON object
+ * @param name the property name
+ * @return the property value
+ *
+ * @throws IllegalArgumentException if could not find a property with the
+ * given name
+ */
+ static String getProperty(JsonObject value, String name) {
+ JsonElement e = value.get(name);
+ if (e != null && e.isJsonPrimitive()) {
+ try {
+ return e.getAsString();
+ } catch (Exception ex) {
+ }
+ }
+ throw new IllegalArgumentException("Could not find the " + name + " property in: " + value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/5d1f7c47/apps/runtime/src/main/java/quarks/apps/runtime/MonitorAppEvent.java
----------------------------------------------------------------------
diff --git a/apps/runtime/src/main/java/quarks/apps/runtime/MonitorAppEvent.java b/apps/runtime/src/main/java/quarks/apps/runtime/MonitorAppEvent.java
deleted file mode 100644
index 531da3d..0000000
--- a/apps/runtime/src/main/java/quarks/apps/runtime/MonitorAppEvent.java
+++ /dev/null
@@ -1,113 +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.apps.runtime;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-
-import quarks.execution.Job;
-import quarks.execution.services.job.JobRegistryService;
-
-/**
- * Helpers for parsing generating and parsing a JSON representation of job
- * monitoring events.
- */
-class MonitorAppEvent {
-
- /**
- * Creates a JsonObject wrapping a {@code JobRegistryService} event type
- * and Job info.
- *
- * @param evType the event type
- * @param job the job
- * @return the wrapped data
- */
- static JsonObject toJsonObject(JobRegistryService.EventType evType, Job job) {
- JsonObject value = new JsonObject();
- value.addProperty("time", (Number)System.currentTimeMillis());
- value.addProperty("event", evType.toString());
- JsonObject obj = new JsonObject();
- obj.addProperty("id", job.getId());
- obj.addProperty("name", job.getName());
- obj.addProperty("state", job.getCurrentState().toString());
- obj.addProperty("nextState", job.getNextState().toString());
- obj.addProperty("health", job.getHealth().toString());
- obj.addProperty("lastError", job.getLastError());
- value.add("job", obj);
- return value;
- }
-
- /**
- * Gets the {@code job} JsonObject from the given JSON value.
- *
- * @param value a JSON object
- * @return the job JsonObject
- */
- static JsonObject getJob(JsonObject value) {
- JsonObject job = value.getAsJsonObject("job");
- if (job == null) {
- throw new IllegalArgumentException("Could not find the job object in: " + value);
- }
- return job;
- }
-
- /**
- * Gets the {@code name} string property from the given job JSON object.
- *
- * @param job the job JSON object
- * @return the job name
- * @throws IllegalArgumentException if it could not find the property
- */
- static String getJobName(JsonObject job) {
- return getProperty(job, "name");
- }
-
- /**
- * Gets the {@code health} string property from the given job JSON object.
- *
- * @param job the job JSON object
- * @return the job health
- * @throws IllegalArgumentException if it could not find the property
- */
- static String getJobHealth(JsonObject job) {
- return getProperty(job, "health");
- }
-
- /**
- * Gets a string property with the specified name from the given JSON
- * object.
- *
- * @param value a JSON object
- * @param name the property name
- * @return the property value
- *
- * @throws IllegalArgumentException if could not find a property with the
- * given name
- */
- static String getProperty(JsonObject value, String name) {
- JsonElement e = value.get(name);
- if (e != null && e.isJsonPrimitive()) {
- try {
- return e.getAsString();
- } catch (Exception ex) {
- }
- }
- throw new IllegalArgumentException("Could not find the " + name + " property in: " + value);
- }
-}