summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/node-manager/src/main
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2012-04-02 17:58:17 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2012-04-02 17:58:17 +0000
commitc33b36c46a763f6a3fa6b3ff0fad5213074b27e9 (patch)
tree35e9f9f82bac8da8b5d08c20eb123e08ab6a154e /sca-java-2.x/trunk/modules/node-manager/src/main
parenta6d8c8ff0c7d48e5e56728e3dc191ccb0a96418a (diff)
Enhancing management capability to allow setting warning, critical and unavailable tresholds
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1308444 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Status.java12
-rw-r--r--sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java51
2 files changed, 51 insertions, 12 deletions
diff --git a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Status.java b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Status.java
index f20f5e1b33..75d25734d8 100644
--- a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Status.java
+++ b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Status.java
@@ -20,12 +20,14 @@
package org.apache.tuscany.sca.node.manager;
public class Status {
- public static int SUCCESS = 0;
- public static int FAILURE = 1;
+ public static String OK ="ok";
+ public static String WARNING = "warning";
+ public static String CRITICAL = "critical";
+ public static String UNAVAILABLE = "unavailable";
private String name;
private String uri;
- private int status;
+ private String status;
private String statusMessage;
private long execution;
@@ -45,11 +47,11 @@ public class Status {
this.uri = uri;
}
- public int getStatus() {
+ public String getStatus() {
return status;
}
- public void setStatus(int status) {
+ public void setStatus(String status) {
this.status = status;
}
diff --git a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java
index 3b045b8d1b..46cbab0656 100644
--- a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java
+++ b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java
@@ -52,12 +52,24 @@ import org.apache.tuscany.sca.node.manager.ManageableResource;
import org.apache.tuscany.sca.node.manager.ManageableService;
import org.apache.tuscany.sca.node.manager.Status;
import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Property;
+import org.oasisopen.sca.annotation.Scope;
-public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAssetManagerResource {
+@Scope("COMPOSITE")
+public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAssetManagerResource {
private static Map<String, NodeExtension> nodeMap = new ConcurrentHashMap<String,NodeExtension>();
private HttpClientFactory httpClientFactory;
-
+
+ @Property
+ private int warningTreshold;
+
+ @Property
+ private int criticalTreshold;
+
+ @Property
+ private int unavailableTreshold;
+
public void nodeStarted(Node node) {
NodeExtension nodeExtension = (NodeExtension) node;
nodeMap.put(nodeExtension.getDomainURI(), nodeExtension);
@@ -70,6 +82,11 @@ public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAsse
@Init
public void init() {
+ System.out.println("Initializing Domain Asset Manager");
+ System.out.println(" - Warning threshold : " + warningTreshold + " ms" );
+ System.out.println(" - Critical threshold : " + criticalTreshold + " ms");
+ System.out.println(" - Unavailable threshold : " + unavailableTreshold + " ms");
+
NodeExtension node = (NodeExtension) nodeMap.values().iterator().next();
if(node != null) {
ExtensionPointRegistry extensionPoints = node.getExtensionPointRegistry();
@@ -103,9 +120,21 @@ public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAsse
Timer t = new Timer();
status = testResource(status);
status.setExecution(t.elapsed(TimeUnit.MILLISECONDS));
- status.setStatus(Status.SUCCESS);
+
+ if(status.getExecution() < warningTreshold) {
+ status.setStatus(status.OK);
+ }else if(status.getExecution() > warningTreshold) {
+ status.setStatus(Status.WARNING);
+ }else if(status.getExecution() > criticalTreshold) {
+ status.setStatus(Status.CRITICAL);
+ } else {
+ status.setStatus(Status.UNAVAILABLE);
+ }
+
+ System.out.println(">>> Execution : " + status.getExecution() + " ms -- " + status.getStatus());
+
} catch (Exception e) {
- status.setStatus(Status.FAILURE);
+ status.setStatus(Status.UNAVAILABLE);
status.setStatusMessage(e.getMessage());
}
@@ -138,14 +167,22 @@ public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAsse
status.setUri(service.getBindings().get(0).getURI());
try {
- String serviceName = component.getName() +"/" + service.getName();
ManageableService serviceInstance = node.getService(ManageableService.class, component.getName());
Timer t = new Timer();
serviceInstance.isAlive();
status.setExecution(t.elapsed(TimeUnit.MILLISECONDS));
- status.setStatus(Status.SUCCESS);
+
+ if(status.getExecution() < warningTreshold) {
+ status.setStatus(status.OK);
+ }else if(status.getExecution() > warningTreshold) {
+ status.setStatus(Status.WARNING);
+ }else if(status.getExecution() > criticalTreshold) {
+ status.setStatus(Status.CRITICAL);
+ } else {
+ status.setStatus(Status.UNAVAILABLE);
+ }
} catch (Exception e) {
- status.setStatus(Status.FAILURE);
+ status.setStatus(Status.UNAVAILABLE);
status.setStatusMessage(e.getMessage());
}