You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2013/07/11 11:28:10 UTC
[6/7] Applying 0001-Refactor-status-monitor-module.patch
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/GadgetServerClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/GadgetServerClient.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/GadgetServerClient.java
new file mode 100644
index 0000000..8e95acc
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/GadgetServerClient.java
@@ -0,0 +1,111 @@
+/*
+ * 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 org.apache.stratos.status.monitor.agent.clients.service;
+
+import org.apache.stratos.status.monitor.agent.clients.common.ServiceLoginClient;
+import org.apache.stratos.status.monitor.agent.constants.StatusMonitorAgentConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.registry.app.RemoteRegistry;
+import org.wso2.carbon.registry.core.Resource;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.apache.stratos.status.monitor.agent.internal.core.MySQLConnector;
+import org.apache.stratos.status.monitor.core.StatusMonitorConfigurationBuilder;
+import org.apache.stratos.status.monitor.core.beans.AuthConfigBean;
+import org.apache.stratos.status.monitor.core.constants.StatusMonitorConstants;
+import org.apache.stratos.status.monitor.core.jdbc.MySQLConnectionInitializer;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.SQLException;
+import java.text.ParseException;
+
+/**
+ * Status Monitor Agent client class for Gadget Server
+ */
+public class GadgetServerClient extends Thread{
+
+ private static final Log log = LogFactory.getLog(GadgetServerClient.class);
+ private static final AuthConfigBean authConfigBean =
+ StatusMonitorConfigurationBuilder.getAuthConfigBean();
+
+ public void run() {
+ while (true) {
+ try {
+ executeService();
+
+ // return from while loop if the thread is interrupted
+ if (isInterrupted()) {
+ break;
+ }
+ // let the thread sleep for 15 mins
+ try {
+ sleep(StatusMonitorConstants.SLEEP_TIME);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ } catch (IOException e) {
+ log.error(e);
+ } catch (SQLException e) {
+ log.error(e);
+ } catch (ParseException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ static RemoteRegistry registry = null;
+
+ private static void executeService() throws IOException, SQLException, ParseException {
+ int serviceID = MySQLConnectionInitializer.getServiceID(StatusMonitorConstants.GADGET);
+
+ if (ServiceLoginClient.loginChecker(StatusMonitorConstants.GADGETS_HOST, serviceID)) {
+ try {
+ registry = new RemoteRegistry(new URL(StatusMonitorConstants.GADGETS_HTTP +
+ "/t/" + authConfigBean.getTenant() + "/registry"),
+ authConfigBean.getUserName(), authConfigBean.getPassword());
+ } catch (RegistryException e) {
+ log.error(e);
+ } catch (MalformedURLException e) {
+ log.error(e);
+ }
+
+ /*get resource */
+ try {
+ Resource r2 = registry.get(StatusMonitorAgentConstants.GS_SAMPLE_TEST_RESOURCE_PATH);
+ if(log.isDebugEnabled()) {
+ log.debug("MediaType in the executeService() of GadgetServerClient in Status" +
+ " Monitor Agent: " + r2.getMediaType());
+ }
+
+ if (r2.getMediaType().equalsIgnoreCase("application/vnd.wso2-gadget+xml")) {
+ MySQLConnector.insertStats(serviceID, true);
+ MySQLConnector.insertState(serviceID, true, "");
+ }
+ } catch (RegistryException e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "Exception in executing the service for GadgetServerClient - Status Monitor Agent";
+ log.error(msg, e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/GovernanceRegistryServerClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/GovernanceRegistryServerClient.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/GovernanceRegistryServerClient.java
new file mode 100644
index 0000000..3f1ff5e
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/GovernanceRegistryServerClient.java
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.stratos.status.monitor.agent.clients.service;
+
+import org.apache.stratos.status.monitor.agent.clients.common.ServiceLoginClient;
+import org.apache.stratos.status.monitor.agent.constants.StatusMonitorAgentConstants;
+import org.apache.stratos.status.monitor.agent.internal.core.MySQLConnector;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.registry.app.RemoteRegistry;
+import org.wso2.carbon.registry.core.Resource;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.apache.stratos.status.monitor.core.StatusMonitorConfigurationBuilder;
+import org.apache.stratos.status.monitor.core.beans.AuthConfigBean;
+import org.apache.stratos.status.monitor.core.constants.StatusMonitorConstants;
+import org.apache.stratos.status.monitor.core.jdbc.MySQLConnectionInitializer;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.SQLException;
+import java.text.ParseException;
+
+/**
+ * Status Monitor Agent client class for Governance Registry
+ */
+public class GovernanceRegistryServerClient extends Thread{
+ private static final Log log = LogFactory.getLog(GovernanceRegistryServerClient.class);
+ private static final AuthConfigBean authConfigBean =
+ StatusMonitorConfigurationBuilder.getAuthConfigBean();
+
+ public void run() {
+ while (true) {
+ try {
+ executeService();
+
+ // return from while loop if the thread is interrupted
+ if (isInterrupted()) {
+ break;
+ }
+ // let the thread sleep for 15 mins
+ try {
+ sleep(StatusMonitorConstants.SLEEP_TIME);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ } catch (IOException e) {
+ log.error(e);
+ } catch (SQLException e) {
+ log.error(e);
+ } catch (ParseException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ static RemoteRegistry registry = null;
+
+ private static void executeService() throws IOException, SQLException, ParseException {
+ boolean getValue = false;
+ boolean putValue = false;
+ boolean deleteValue = false;
+ int serviceID = MySQLConnectionInitializer.getServiceID(StatusMonitorConstants.GOVERNANCE);
+
+ if (ServiceLoginClient.loginChecker(StatusMonitorConstants.GOVERNANCE_HOST, serviceID)) {
+ try {
+
+ registry = new RemoteRegistry(new URL(StatusMonitorConstants.GOVERNANCE_HTTP +
+ "/t/" + authConfigBean.getTenant() + "/registry"),
+ authConfigBean.getUserName(), authConfigBean.getPassword());
+ } catch (RegistryException e) {
+ log.error(e);
+ } catch (MalformedURLException e) {
+ log.error(e);
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ /*put resource */
+ Resource r1;
+
+ try {
+ r1 = registry.newResource();
+ r1.setContent("test content".getBytes());
+ r1.setMediaType("text/plain");
+ String pathValue = registry.put(
+ StatusMonitorAgentConstants.GREG_SAMPLE_TEST_RESOURCE_PATH, r1);
+
+ if (pathValue.equalsIgnoreCase(
+ StatusMonitorAgentConstants.GREG_SAMPLE_TEST_RESOURCE_PATH)) {
+ putValue = true;
+ }
+ } catch (RegistryException e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ log.warn(e);
+ } catch (Exception e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ log.warn(e);
+ }
+
+ /*get resource */
+ try {
+ if (putValue) {
+ Resource r2 = registry.get(
+ StatusMonitorAgentConstants.GREG_SAMPLE_TEST_RESOURCE_PATH);
+ if (log.isDebugEnabled()) {
+ log.debug("Media Type: " + r2.getMediaType());
+ }
+
+ if (r2.getMediaType().equalsIgnoreCase("text/plain")) {
+ getValue = true;
+ }
+ }
+ } catch (RegistryException e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ log.warn(e);
+ } catch (Exception e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ log.warn(e);
+ }
+
+ /*Delete resource */
+ try {
+ if (getValue) {
+ registry.delete(StatusMonitorAgentConstants.GREG_SAMPLE_TEST_RESOURCE_PATH);
+
+ if (!registry.resourceExists(
+ StatusMonitorAgentConstants.GREG_SAMPLE_TEST_RESOURCE_PATH)) {
+ deleteValue = true;
+ }
+ }
+
+ } catch (RegistryException e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ log.warn(e);
+ } catch (Exception e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ log.warn(e);
+ }
+
+ //write to mysql db
+ try {
+ if (getValue & putValue & deleteValue) {
+ if (log.isDebugEnabled()) {
+ log.debug("Governance Registry Status Monitor agent: Writing to the database");
+ }
+ MySQLConnector.insertStats(serviceID, true);
+ MySQLConnector.insertState(serviceID, true, "");
+ }
+ } catch (SQLException e) {
+ String msg = "Error in writing to the database for Governance Registry - status monitor agent";
+ log.error(msg, e);
+ }
+ }
+ }
+}
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/IdentityServerClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/IdentityServerClient.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/IdentityServerClient.java
new file mode 100644
index 0000000..9e16137
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/IdentityServerClient.java
@@ -0,0 +1,116 @@
+/*
+ * 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 org.apache.stratos.status.monitor.agent.clients.service;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.stratos.status.monitor.agent.constants.StatusMonitorAgentConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub;
+import org.apache.stratos.status.monitor.agent.internal.core.MySQLConnector;
+import org.apache.stratos.status.monitor.core.StatusMonitorConfigurationBuilder;
+import org.apache.stratos.status.monitor.core.beans.AuthConfigBean;
+import org.apache.stratos.status.monitor.core.constants.StatusMonitorConstants;
+import org.apache.stratos.status.monitor.core.jdbc.MySQLConnectionInitializer;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.SQLException;
+
+/**
+ * Status Monitor Agent client class for Identity Server
+ */
+public class IdentityServerClient extends Thread{
+ private static final Log log = LogFactory.getLog(IdentityServerClient.class);
+ private static AuthConfigBean authConfigBean =
+ StatusMonitorConfigurationBuilder.getAuthConfigBean();
+
+ public void run() {
+ while (true) {
+ try {
+ executeService();
+
+ // return from while loop if the thread is interrupted
+ if (isInterrupted()) {
+ break;
+ }
+ // let the thread sleep for 15 mins
+ try {
+ sleep(StatusMonitorConstants.SLEEP_TIME);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ } catch (IOException e) {
+ log.error(e);
+ } catch (SQLException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ private static void executeService() throws SQLException, IOException {
+
+ System.setProperty(StatusMonitorAgentConstants.TRUST_STORE, authConfigBean.getJksLocation());
+ System.setProperty(StatusMonitorAgentConstants.TRUST_STORE_PASSWORD, "wso2carbon");
+ System.setProperty(StatusMonitorAgentConstants.TRUST_STORE_TYPE, "JKS");
+
+ File newFile = new File(authConfigBean.getJksLocation());
+ if(log.isDebugEnabled()){
+ log.debug("Canonical Path: " + newFile.getCanonicalPath());
+ }
+
+ int serviceID = MySQLConnectionInitializer.getServiceID(StatusMonitorConstants.IDENTITY);
+ String authenticationServiceURL = StatusMonitorConstants.IDENTITY_HTTPS +
+ StatusMonitorAgentConstants.AUTHENTICATION_ADMIN_PATH;
+ AuthenticationAdminStub authenticationAdminStub;
+ try {
+ authenticationAdminStub = new AuthenticationAdminStub(authenticationServiceURL);
+ ServiceClient client = authenticationAdminStub._getServiceClient();
+ Options options = client.getOptions();
+ options.setManageSession(true);
+
+ Boolean status;
+ status = authenticationAdminStub.login(authConfigBean.getUserName(),
+ authConfigBean.getPassword(), StatusMonitorConstants.IDENTITY_HOST);
+ ServiceContext serviceContext = authenticationAdminStub.
+ _getServiceClient().getLastOperationContext().getServiceContext();
+ // String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
+
+ if (status) {
+ MySQLConnector.insertStats(serviceID, true);
+ MySQLConnector.insertState(serviceID, true, "");
+ }
+ } catch (AxisFault e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "Fault in executing the service for IS client - Status Monitor Agent";
+ log.warn(msg, e);
+
+ } catch (Exception e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "Exception in executing the service for IS client - Status Monitor Agent";
+ log.warn(msg, e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/ManagerServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/ManagerServiceClient.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/ManagerServiceClient.java
new file mode 100644
index 0000000..47316af
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/ManagerServiceClient.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 org.apache.stratos.status.monitor.agent.clients.service;
+
+import org.apache.axis2.client.Options;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub;
+import org.apache.stratos.status.monitor.agent.constants.StatusMonitorAgentConstants;
+import org.apache.stratos.status.monitor.agent.internal.core.MySQLConnector;
+import org.apache.stratos.status.monitor.core.StatusMonitorConfigurationBuilder;
+import org.apache.stratos.status.monitor.core.beans.AuthConfigBean;
+import org.apache.stratos.status.monitor.core.constants.StatusMonitorConstants;
+import org.apache.stratos.status.monitor.core.jdbc.MySQLConnectionInitializer;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+/**
+ * Status Monitor Agent client class for Stratos Manager
+ */
+public class ManagerServiceClient extends Thread{
+
+ private static final Log log = LogFactory.getLog(ManagerServiceClient.class);
+ private static final AuthConfigBean authConfigBean =
+ StatusMonitorConfigurationBuilder.getAuthConfigBean();
+
+ public void run() {
+ while (true) {
+ try {
+ executeService();
+
+ // return from while loop if the thread is interrupted
+ if (isInterrupted()) {
+ break;
+ }
+ // let the thread sleep for 15 mins
+ try {
+ sleep(StatusMonitorConstants.SLEEP_TIME);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ } catch (IOException e) {
+ log.error(e);
+ } catch (SQLException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ private static void executeService() throws SQLException, IOException {
+
+ System.setProperty(StatusMonitorAgentConstants.TRUST_STORE, authConfigBean.getJksLocation());
+ System.setProperty(StatusMonitorAgentConstants.TRUST_STORE_PASSWORD, "wso2carbon");
+ System.setProperty(StatusMonitorAgentConstants.TRUST_STORE_TYPE, "JKS");
+
+ String userName = authConfigBean.getUserName();
+ String password = authConfigBean.getPassword();
+ int serviceID = MySQLConnectionInitializer.getServiceID(StatusMonitorConstants.MANAGER);
+ String authenticationServiceURL = StatusMonitorConstants.MANAGER_HTTPS +
+ StatusMonitorAgentConstants.AUTHENTICATION_ADMIN_PATH;
+ AuthenticationAdminStub authenticationAdminStub;
+ try {
+ authenticationAdminStub = new AuthenticationAdminStub(authenticationServiceURL);
+ ServiceClient client = authenticationAdminStub._getServiceClient();
+ Options options = client.getOptions();
+ options.setManageSession(true);
+
+ Boolean status;
+ status = authenticationAdminStub.login(userName, password,
+ StatusMonitorConstants.MANAGER_HOST);
+ ServiceContext serviceContext = authenticationAdminStub.
+ _getServiceClient().getLastOperationContext().getServiceContext();
+ // String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
+
+ if (status) {
+ MySQLConnector.insertStats(serviceID, true);
+ MySQLConnector.insertState(serviceID, true, "");
+ }
+ } catch (AxisFault e) {
+ MySQLConnector.insertStats(serviceID, false);
+
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "Fault in executing the service - Status Monitor Agent for Manager";
+ log.warn(msg, e);
+ } catch (Exception e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "Exception in executing the service - Status Monitor Agent for Manager";
+ log.warn(msg, e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/MashupServerClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/MashupServerClient.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/MashupServerClient.java
new file mode 100644
index 0000000..61d3963
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/MashupServerClient.java
@@ -0,0 +1,192 @@
+/*
+ * 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 org.apache.stratos.status.monitor.agent.clients.service;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.stratos.status.monitor.agent.clients.common.ServiceLoginClient;
+import org.apache.stratos.status.monitor.agent.constants.StatusMonitorAgentConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.status.monitor.agent.internal.core.MySQLConnector;
+import org.apache.stratos.status.monitor.core.StatusMonitorConfigurationBuilder;
+import org.apache.stratos.status.monitor.core.beans.AuthConfigBean;
+import org.apache.stratos.status.monitor.core.beans.SampleTenantConfigBean;
+import org.apache.stratos.status.monitor.core.constants.StatusMonitorConstants;
+import org.apache.stratos.status.monitor.core.jdbc.MySQLConnectionInitializer;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.text.ParseException;
+
+/**
+ * Status Monitor Agent client class for Mashup Server
+ */
+public class MashupServerClient extends Thread{
+
+ private static final Log log = LogFactory.getLog(MashupServerClient.class);
+ private static final AuthConfigBean authConfigBean =
+ StatusMonitorConfigurationBuilder.getAuthConfigBean();
+ private static final SampleTenantConfigBean sampleTenantConfigBean =
+ StatusMonitorConfigurationBuilder.getSampleTenantConfigBean();
+ private static int serviceID;
+
+ public void run() {
+ while (true) {
+ try {
+ executeService();
+
+ // return from while loop if the thread is interrupted
+ if (isInterrupted()) {
+ break;
+ }
+ // let the thread sleep for 15 mins
+ try {
+ sleep(StatusMonitorConstants.SLEEP_TIME);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ } catch (IOException e) {
+ log.error(e);
+ } catch (SQLException e) {
+ log.error(e);
+ } catch (ParseException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ private static OMElement createPayLoad() {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace("http://services.mashup.wso2.org/schemaTest1", "ns1");
+ OMElement method = fac.createOMElement("echoJSString", omNs);
+ OMElement value = fac.createOMElement("param", null);
+ value.addChild(fac.createOMText(value, "Hello World"));
+ method.addChild(value);
+ return method;
+ }
+
+ private static void executeService() throws IOException, SQLException, ParseException {
+
+ serviceID = MySQLConnectionInitializer.getServiceID(StatusMonitorConstants.MASHUP);
+
+ OMElement result;
+ OMElement payload = createPayLoad();
+ ServiceClient serviceclient = new ServiceClient();
+ Options opts = new Options();
+
+ opts.setTo(new EndpointReference(StatusMonitorConstants.MASHUP_HTTP +
+ StatusMonitorAgentConstants.TENANT_SERVICES + authConfigBean.getTenant() +
+ "/test123/schemaTest1/ "));
+ opts.setAction("http://services.mashup.wso2.org/schemaTest1");
+
+ if (ServiceLoginClient.loginChecker(StatusMonitorConstants.MASHUP_HOST, serviceID)) {
+ serviceclient.setOptions(opts);
+ try {
+ result = serviceclient.sendReceive(payload);
+
+ if ((result.toString().indexOf("Hello World")) > 0) {
+ if (executeRelatedProductsService()) {
+ MySQLConnector.insertStats(serviceID, true);
+ MySQLConnector.insertState(serviceID, true, "");
+ }
+ } else {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, "Service Invocation failed");
+ }
+
+ } catch (AxisFault e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "Error in executing the service - Status Monitor Agent for MashupServerClient";
+ log.warn(msg, e);
+ }
+ catch (NullPointerException e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "NPE in executing the service - Status Monitor Agent for MashupServerClient";
+ log.warn(msg, e);
+ } catch (XMLStreamException e) {
+ String msg = "XMLStreamException in execting the service - Status Monitor Agent for MashupServerClient";
+ log.warn(msg, e);
+ }
+ }
+ }
+
+ private static Boolean executeRelatedProductsService() throws IOException, SQLException, ParseException, XMLStreamException {
+
+ Boolean relatedProductsServiceStatus = false;
+
+ OMElement result;
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace("http://services.mashup.wso2.org/RelatedProducts?xsd", "rel");
+ OMElement payload = fac.createOMElement("getRelatedProducts", omNs);
+ OMElement value1 = fac.createOMElement("query", null);
+ OMElement value2 = fac.createOMElement("count", null);
+ OMElement value3 = fac.createOMElement("format", null);
+ value1.addChild(fac.createOMText(value1, "mac"));
+ value2.addChild(fac.createOMText(value2, "2"));
+ value3.addChild(fac.createOMText(value3, "xml"));
+
+ payload.addChild(value1);
+ payload.addChild(value2);
+ payload.addChild(value3);
+
+ ServiceClient serviceclient = new ServiceClient();
+ Options opts = new Options();
+ opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
+
+ opts.setTo(new EndpointReference(StatusMonitorConstants.MASHUP_HTTP +
+ StatusMonitorAgentConstants.TENANT_SERVICES +
+ sampleTenantConfigBean.getTenant() + "/carbon/RelatedProducts"));
+ opts.setAction("http://services.mashup.wso2.org/RelatedProducts?xsd/RelatedProducts");
+
+ serviceclient.setOptions(opts);
+ try {
+ result = serviceclient.sendReceive(payload);
+
+ if ((result.toString().contains("New USB Graphics Drawing Tablet Mouse Pad"))) {
+ relatedProductsServiceStatus = true;
+ } else {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, "Platform Sample: RelatedProducts service Invocation failed");
+ }
+ } catch (AxisFault e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, "Platform Sample: RelatedProducts - " + e.getMessage());
+ String msg = "Error in executing the related products service";
+ log.warn(msg, e);
+ }
+ catch (NullPointerException e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, "Platform Sample: RelatedProducts - " + e.getMessage());
+ String msg = "NPE in executing the related products service";
+ log.warn(msg, e);
+ }
+ return relatedProductsServiceStatus;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/MessageBrokerServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/MessageBrokerServiceClient.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/MessageBrokerServiceClient.java
new file mode 100644
index 0000000..a0f8459
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/clients/service/MessageBrokerServiceClient.java
@@ -0,0 +1,158 @@
+/*
+ * 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 org.apache.stratos.status.monitor.agent.clients.service;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.status.monitor.agent.clients.common.ServiceLoginClient;
+import org.apache.stratos.status.monitor.agent.constants.StatusMonitorAgentConstants;
+import org.apache.stratos.status.monitor.agent.internal.core.MySQLConnector;
+import org.apache.stratos.status.monitor.core.StatusMonitorConfigurationBuilder;
+import org.apache.stratos.status.monitor.core.beans.AuthConfigBean;
+import org.apache.stratos.status.monitor.core.constants.StatusMonitorConstants;
+import org.apache.stratos.status.monitor.core.jdbc.MySQLConnectionInitializer;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.jms.QueueConnectionFactory;
+
+/**
+ * Status Monitor Agent client class for Message Broker Service
+ */
+public class MessageBrokerServiceClient extends Thread{
+
+ private static final Log log = LogFactory.getLog(MessageBrokerServiceClient.class);
+ private static String tcpUserName;
+
+ public void run() {
+ while (true) {
+ try {
+ executeService();
+
+ // return from while loop if the thread is interrupted
+ if (isInterrupted()) {
+ break;
+ }
+ // let the thread sleep for 15 mins
+ try {
+ sleep(StatusMonitorConstants.SLEEP_TIME);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ } catch (SQLException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ private static void executeService() throws SQLException {
+ int serviceID = MySQLConnectionInitializer.getServiceID(StatusMonitorConstants.MESSAGING);
+ AuthConfigBean authConfigBean = StatusMonitorConfigurationBuilder.getAuthConfigBean();
+
+ String userName = authConfigBean.getUserName();
+ tcpUserName = userName.replace('@','!');
+
+ //check whether login success
+ if (ServiceLoginClient.loginChecker(StatusMonitorConstants.MESSAGING_HOST, serviceID)) {
+
+ Properties properties = new Properties();
+ properties.put(Context.INITIAL_CONTEXT_FACTORY, StatusMonitorAgentConstants.QPID_ICF);
+ properties.put(StatusMonitorAgentConstants.CF_NAME_PREFIX +
+ StatusMonitorAgentConstants.CF_NAME,
+ getTCPConnectionURL(tcpUserName,
+ authConfigBean.getPassword()));
+
+ if (log.isDebugEnabled()) {
+ log.debug("getTCPConnectionURL(username,password) = " +
+ getTCPConnectionURL(tcpUserName,
+ authConfigBean.getPassword()));
+ }
+ try {
+ InitialContext ctx = new InitialContext(properties);
+ // Lookup connection factory
+ QueueConnectionFactory connFactory =
+ (QueueConnectionFactory) ctx.lookup(StatusMonitorAgentConstants.CF_NAME);
+ QueueConnection queueConnection = connFactory.createQueueConnection();
+ queueConnection.start();
+ QueueSession queueSession =
+ queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+ // Send message
+ Queue queue = queueSession.createQueue(StatusMonitorAgentConstants.QUEUE_NAME_MB +
+ ";{create:always, node:{durable: True}}");
+
+ // create the message to send
+ TextMessage textMessage = queueSession.createTextMessage("Test Message Hello");
+ javax.jms.QueueSender queueSender = queueSession.createSender(queue);
+ queueSender.setTimeToLive(100000000);
+
+ QueueReceiver queueReceiver = queueSession.createReceiver(queue);
+ queueSender.send(textMessage);
+
+ TextMessage message = (TextMessage) queueReceiver.receiveNoWait();
+
+ if (message.getText().equals("Test Message Hello")) {
+ MySQLConnector.insertStats(serviceID, true);
+ MySQLConnector.insertState(serviceID, true, "");
+ } else {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, "Send and retrieve messages failed");
+ }
+ queueSender.close();
+ queueSession.close();
+ queueConnection.close();
+
+ } catch (JMSException e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "Exception in executing the client - " +
+ "Status Monitor Agent for MessageBrokerServiceClient";
+ log.warn(msg, e);
+
+ } catch (NamingException e) {
+ MySQLConnector.insertStats(serviceID, false);
+ MySQLConnector.insertState(serviceID, false, e.getMessage());
+ String msg = "Naming exception in executing the client - " +
+ "Status Monitor agent for MessageBrokerServiceClient";
+ log.warn(msg, e);
+ }
+ }
+ }
+
+ private static String getTCPConnectionURL(String username, String password) {
+ return new StringBuffer()
+ .append("amqp://").append(tcpUserName).append(":").append(password).
+ append("@").append(StatusMonitorAgentConstants.CARBON_CLIENT_ID).
+ append("/").append(StatusMonitorAgentConstants.CARBON_VIRTUAL_HOST_NAME).
+ append("?brokerlist='tcp://").append(StatusMonitorConstants.MESSAGING_HOST).
+ append(":").append(StatusMonitorConstants.MESSAGING_DEFAULT_PORT).
+ append("'").toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/constants/StatusMonitorAgentConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/constants/StatusMonitorAgentConstants.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/constants/StatusMonitorAgentConstants.java
new file mode 100644
index 0000000..4e650ba
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/constants/StatusMonitorAgentConstants.java
@@ -0,0 +1,55 @@
+/*
+ * 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 org.apache.stratos.status.monitor.agent.constants;
+
+/**
+ * Constants specific to the Status Monitor Agents
+ */
+public class StatusMonitorAgentConstants {
+
+ /*CEP and MB Specific constants*/
+ public static final String QPID_ICF = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory";
+ public static final String CF_NAME_PREFIX = "connectionfactory.";
+ public static final String CF_NAME = "qpidConnectionfactory";
+
+ public static final String CARBON_CLIENT_ID = "carbon";
+ public static final String CARBON_VIRTUAL_HOST_NAME = "carbon";
+
+ /*CEP Server client specific constants*/
+ public static final String CEP_DEFAULT_PORT = "5674";
+ public static final String QUEUE_NAME_CEP = "testQueueQACEP1";
+
+ /*MB Server client specific constants*/
+ public static final String QUEUE_NAME_MB = "testQueueQA6";
+
+ /*Gadget Server specific constants*/
+ public static final String GS_SAMPLE_TEST_RESOURCE_PATH =
+ "/_system/config/repository/gadget-server/gadgets/AmazonSearchGadget/amazon-search.xml";
+ public static final String GREG_SAMPLE_TEST_RESOURCE_PATH =
+ "/_system/local/registry.txt";
+
+ /*TrustStore and Identity constants*/
+ public static final String TRUST_STORE = "javax.net.ssl.trustStore";
+ public static final String TRUST_STORE_PASSWORD = "javax.net.ssl.trustStorePassword";
+ public static final String TRUST_STORE_TYPE = "javax.net.ssl.trustStoreType";
+ public static final String AUTHENTICATION_ADMIN_PATH = "/services/AuthenticationAdmin";
+
+ /*Common constants*/
+ public static final String TENANT_SERVICES = "/services/t/";
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/internal/StatusMonitorAgentComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/internal/StatusMonitorAgentComponent.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/internal/StatusMonitorAgentComponent.java
new file mode 100644
index 0000000..bc07b30
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/internal/StatusMonitorAgentComponent.java
@@ -0,0 +1,110 @@
+/*
+ * 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 org.apache.stratos.status.monitor.agent.internal;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.apache.stratos.status.monitor.agent.clients.ClientThreadsInitializer;
+import org.apache.stratos.status.monitor.agent.internal.core.MySQLConnector;
+import org.apache.stratos.status.monitor.core.exception.StatusMonitorException;
+import org.apache.stratos.status.monitor.core.util.StatusMonitorUtil;
+import org.wso2.carbon.utils.ConfigurationContextService;
+
+/**
+ * @scr.component name="org.apache.stratos.status.monitor.agent" immediate="true"
+ * @scr.reference name="configuration.context.service"
+ * interface="org.wso2.carbon.utils.ConfigurationContextService"
+ * cardinality="1..1" policy="dynamic"
+ * bind="setConfigurationContextService"
+ * unbind="unsetConfigurationContextService"
+ */
+public class StatusMonitorAgentComponent {
+ private static Log log = LogFactory.getLog(StatusMonitorAgentComponent.class);
+
+ private static BundleContext bundleContext;
+ private static ConfigurationContextService configurationContextService;
+
+ protected void activate(ComponentContext context) {
+ try {
+ bundleContext = context.getBundleContext();
+ if (StatusMonitorUtil.getStatusMonitorConfiguration() == null) {
+ StatusMonitorUtil.initStatusMonitor(context.getBundleContext());
+ if (log.isDebugEnabled()) {
+ log.debug("Status Monitor Agent initialized");
+ }
+ }
+ initConnector();
+ if (log.isDebugEnabled()) {
+ log.debug("******* Status Monitor agent bundle is activated ******* ");
+ }
+ ClientThreadsInitializer.initializeThreads();
+ if (log.isDebugEnabled()) {
+ log.debug("Client threads of the Status Monitor Agent are started.");
+ }
+ } catch (Exception e) {
+ log.error("******* Status Monitor agent bundle failed activating ****", e);
+ }
+ }
+
+ private void initConnector() throws StatusMonitorException {
+ try {
+ MySQLConnector.initialize();
+ } catch (Exception e) {
+ String msg = "Error in initializing the mysql connection for the health monitoring";
+ log.error(msg, e);
+ throw new StatusMonitorException(msg, e);
+ }
+ }
+
+ protected void deactivate(ComponentContext context) {
+ log.debug("******* Status Monitor bundle is deactivated ******* ");
+ }
+
+ protected void setConfigurationContextService(
+ ConfigurationContextService configurationContextService) {
+ log.debug("Receiving ConfigurationContext Service");
+ StatusMonitorAgentComponent.
+ configurationContextService = configurationContextService;
+
+ }
+
+ protected void unsetConfigurationContextService(
+ ConfigurationContextService configurationContextService) {
+ log.debug("Unsetting ConfigurationContext Service");
+ setConfigurationContextService(null);
+ }
+
+ public static BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public static ConfigurationContextService getConfigurationContextService() {
+ return configurationContextService;
+ }
+
+ public static ConfigurationContext getConfigurationContext() {
+ if (configurationContextService.getServerConfigContext() == null) {
+ return null;
+ }
+ return configurationContextService.getServerConfigContext();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/internal/core/MySQLConnector.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/internal/core/MySQLConnector.java b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/internal/core/MySQLConnector.java
new file mode 100644
index 0000000..099ea14
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.agent/src/main/java/org/apache/stratos/status/monitor/agent/internal/core/MySQLConnector.java
@@ -0,0 +1,277 @@
+/*
+ * 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 org.apache.stratos.status.monitor.agent.internal.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.status.monitor.core.constants.StatusMonitorConstants;
+import org.apache.stratos.status.monitor.core.jdbc.MySQLConnectionInitializer;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * The class connecting with the mysql database for the Status Monitor Agent
+ */
+public class MySQLConnector {
+ private static Connection conn;
+ private static final Log log = LogFactory.getLog(MySQLConnector.class);
+
+ private static List<String> serviceList = new ArrayList<String>();
+ private static List<String> statusList = new ArrayList<String>();
+
+ private static int resolvedNotFixed = 0;
+ private static int resolvedWSLID;
+
+ /**
+ * gets the sql connection and initializes the MySQLConnectionInitializer.
+ *
+ * @return Static Connection
+ * @throws Exception, throws exception
+ */
+ public static Connection initialize() throws Exception {
+ //gets the sql connection.
+ conn = MySQLConnectionInitializer.initialize();
+
+ //initializes the service and state lists.
+ serviceList = MySQLConnectionInitializer.getServiceList();
+ statusList = MySQLConnectionInitializer.getStatusList();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Connection to the status database is initialized from status.monitor");
+ }
+
+ return conn;
+ }
+
+ /**
+ * Inserts into the heartbeats table
+ *
+ * @param serviceID serviceId
+ * @param status - status of the service
+ * @throws SQLException, if inserting the stats failed
+ */
+ public static void insertStats(int serviceID, Boolean status) throws SQLException {
+ String sql = StatusMonitorConstants.INSERT_STAT_SQL;
+ PreparedStatement pstmt = conn.prepareStatement(sql);
+ try {
+ pstmt.setString(1, null);
+ pstmt.setInt(2, serviceID);
+ pstmt.setBoolean(3, status);
+ pstmt.setString(4, null);
+ pstmt.executeUpdate();
+ } catch (SQLException e) {
+ String msg = "Inserting stats failed";
+ log.error(msg, e);
+ throw new SQLException(msg, e);
+ } finally {
+ pstmt.close();
+ }
+ }
+
+ /**
+ * Inserting state into the state table.
+ *
+ * @param serviceID, service id
+ * @param status, status of the service {"Up & Running", "Broken", "Down", and "Fixed"}
+ * @param details, the service state details.
+ * @throws SQLException, if writing to the database failed.
+ */
+ public static void insertState(int serviceID, Boolean status, String details) throws SQLException {
+
+ int stateID = MySQLConnectionInitializer.getServiceStateID(serviceID);
+ if (!status) {
+ insertStateDetails(stateID, status, details);
+ }
+
+ // boolean insertStatus = getInsertStatus(serviceID);
+ if (/*insertStatus & */(resolvedNotFixed == 0 || resolvedNotFixed == 1)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Inserting data into the state database");
+ }
+ String sql = StatusMonitorConstants.INSERT_STATE_SQL;
+ PreparedStatement pstmt = conn.prepareStatement(sql);
+ try {
+
+ pstmt.setString(1, null);
+ pstmt.setInt(2, serviceID);
+ if (status) {
+ pstmt.setInt(3, 1);
+ } else {
+ pstmt.setInt(3, 2);
+ }
+ pstmt.setString(4, null);
+ pstmt.executeUpdate();
+ } catch (SQLException e) {
+ String msg = "Inserting state failed";
+ log.error(msg, e);
+ throw new SQLException(msg, e);
+ } finally {
+ resolvedWSLID = 0;
+ resolvedNotFixed = 0;
+ pstmt.close();
+ }
+ }
+
+ if (/*insertStatus & */resolvedNotFixed == 2) {
+ String sql = StatusMonitorConstants.UPDATE_STATE_SQL;
+ PreparedStatement pstmtUpdate = conn.prepareStatement(sql);
+ try {
+ if (status) {
+ pstmtUpdate.setInt(1, 1);
+ } else {
+ pstmtUpdate.setInt(1, 2);
+ }
+ pstmtUpdate.setInt(2, resolvedWSLID);
+ pstmtUpdate.executeUpdate();
+ } catch (SQLException e) {
+ String msg = "Inserting state failed";
+ log.error(msg, e);
+ throw new SQLException(msg, e);
+ } finally {
+ resolvedNotFixed = 0;
+ resolvedWSLID = 0;
+ pstmtUpdate.close();
+ }
+ }
+ }
+
+ /**
+ * Inserts the state details into the
+ *
+ * @param serviceStateID, service state ID
+ * @param status, boolean: status of the service
+ * @param detail, service state detail
+ * @throws SQLException, if writing to the database failed.
+ */
+ public static void insertStateDetails(int serviceStateID, boolean status, String detail) throws SQLException {
+
+ String sql = StatusMonitorConstants.INSERT_STATE_DETAIL_SQL;
+ PreparedStatement pstmt = conn.prepareStatement(sql);
+
+ try {
+ pstmt.setString(1, null);
+ pstmt.setInt(2, serviceStateID);
+ if (!status) {
+ pstmt.setString(3, detail);
+ }
+ pstmt.setString(4, null);
+ pstmt.executeUpdate();
+ } catch (SQLException e) {
+ String msg = "Inserting state details failed";
+ log.error(msg, e);
+ throw new SQLException(msg, e);
+ } finally {
+ pstmt.close();
+ }
+ }
+
+ /**
+ * Gets the insert status
+ *
+ * @param ServiceID, id of the service
+ * @return true, if insert status was successful
+ * @throws SQLException, if writing to the database failed.
+ */
+ public static boolean getInsertStatus(int ServiceID) throws SQLException {
+
+ ResultSet rs = null;
+ Statement stmtCon = null;
+ boolean currentStatus = false;
+ String sqlGetStateID = StatusMonitorConstants.SELECT_ALL_FROM_WSL_SERVICE_STATE_SQL + ServiceID +
+ StatusMonitorConstants.ORDER_BY_TIMESTAMP_SQL_DESC_LIMIT_01_SQL;
+
+ DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+ Date SystemDate = new Date();
+ dateFormat.format(SystemDate);
+
+ int state_id;
+ Date date;
+ try {
+ stmtCon = conn.createStatement();
+ stmtCon.executeQuery(sqlGetStateID);
+ rs = stmtCon.getResultSet();
+ if (rs != null) {
+
+ while (rs.next()) {
+ state_id = rs.getInt(StatusMonitorConstants.STATE_ID);
+
+ if (state_id == 1) {
+ if (log.isDebugEnabled()) {
+ log.debug("Up and Running :" + state_id);
+ }
+ currentStatus = true;
+ }
+
+ if (state_id == 2) {
+ if (log.isDebugEnabled()) {
+ log.debug("Broken :" + state_id);
+ }
+ currentStatus = true;
+ }
+
+ if (state_id == 4) {
+ currentStatus = true;
+ date = rs.getTimestamp(StatusMonitorConstants.TIMESTAMP);
+ resolvedWSLID = rs.getInt(StatusMonitorConstants.ID);
+
+ long currentTimeMs = SystemDate.getTime();
+ long resolvedTimeMs = date.getTime();
+
+ double time_diff = ((currentTimeMs - resolvedTimeMs) / (double) StatusMonitorConstants.HOUR_IN_MILLIS);
+ if (log.isDebugEnabled()) {
+ log.debug("State ID: " + state_id);
+ }
+ if (time_diff >= 1.0) {
+ resolvedNotFixed = 1;
+ } else {
+ resolvedNotFixed = 2;
+ }
+ }
+ }
+
+ } else {
+ currentStatus = true;
+ }
+ } catch (SQLException e) {
+ String msg = "Getting Insert state failed";
+ log.error(msg, e);
+ throw new SQLException(msg, e);
+ } finally {
+ if (rs != null) {
+ rs.close();
+ }
+ if (stmtCon != null) {
+ stmtCon.close();
+ }
+ }
+ return currentStatus;
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.core/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.core/pom.xml b/components/org.apache.stratos.status.monitor.core/pom.xml
new file mode 100644
index 0000000..ecbcb02
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.core/pom.xml
@@ -0,0 +1,81 @@
+<!--
+ # 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-components-parent</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.status.monitor.core</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos - Stratos Status Monitor Core</name>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.apache.stratos.status.monitor.core.*,
+ </Export-Package>
+ <Private-Package>
+ org.apache.stratos.status.monitor.core.internal.*,
+ </Private-Package>
+ <Import-Package>
+ org.wso2.carbon.registry.core.*;version=1.0.1,
+ javax.xml.namespace; version=0.0.0,
+ javax.servlet;version="${imp.pkg.version.javax.servlet}",
+ javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+ *;resolution:=optional
+ </Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.common</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/StatusMonitorConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/StatusMonitorConfigurationBuilder.java b/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/StatusMonitorConfigurationBuilder.java
new file mode 100644
index 0000000..071d995
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/StatusMonitorConfigurationBuilder.java
@@ -0,0 +1,247 @@
+/*
+ * 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 org.apache.stratos.status.monitor.core;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.stratos.status.monitor.core.beans.AuthConfigBean;
+import org.apache.stratos.status.monitor.core.beans.SampleTenantConfigBean;
+import org.apache.stratos.status.monitor.core.constants.StatusMonitorConstants;
+import org.apache.stratos.status.monitor.core.exception.StatusMonitorException;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+/**
+ * Builds the status monitor configurations from the configuration file, status-monitor-config.xml.
+ */
+public class StatusMonitorConfigurationBuilder {
+ private static final Log log = LogFactory.getLog(StatusMonitorConfigurationBuilder.class);
+ private static BasicDataSource dataSource;
+ private static AuthConfigBean authConfigBean;
+ private static SampleTenantConfigBean sampleTenantConfigBean;
+
+
+ public StatusMonitorConfigurationBuilder(String statusConfigFile) throws StatusMonitorException {
+ try {
+ OMElement statusConfig = buildOMElement(new FileInputStream(statusConfigFile));
+ deserialize(statusConfig);
+ if (log.isDebugEnabled()) {
+ log.debug("********Status Monitor Configuration Builder**********" + statusConfigFile);
+ }
+ } catch (FileNotFoundException e) {
+ String msg = "Unable to find the file responsible for status monitor configs: "
+ + statusConfigFile;
+ log.error(msg, e);
+ throw new StatusMonitorException(msg, e);
+ }
+ }
+
+ private OMElement buildOMElement(InputStream inputStream) throws StatusMonitorException {
+ XMLStreamReader parser;
+ try {
+ parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
+ } catch (XMLStreamException e) {
+ String msg = "Error in initializing the parser to build the OMElement.";
+ log.error(msg, e);
+ throw new StatusMonitorException(msg, e);
+ }
+
+ StAXOMBuilder builder = new StAXOMBuilder(parser);
+ return builder.getDocumentElement();
+ }
+
+ /*
+ Deserialize the following
+ <billingConfig xmlns="http://wso2.com/carbon/status.monitor.config">
+ <dbConfig>
+ ...
+ </dbConfig>
+ </billingConfig>
+ */
+ private void deserialize(OMElement statusMonitorConfigEle) throws StatusMonitorException {
+ Iterator statusMonitorConfigChildIt = statusMonitorConfigEle.getChildElements();
+
+ while (statusMonitorConfigChildIt.hasNext()) {
+ OMElement statusMonitorConfigChildEle = (OMElement) statusMonitorConfigChildIt.next();
+
+ if (new QName(StatusMonitorConstants.CONFIG_NS, StatusMonitorConstants.DB_CONFIG,
+ StatusMonitorConstants.NS_PREFIX).equals(statusMonitorConfigChildEle.getQName())) {
+ //element is "dbConfig"
+ initDataSource(statusMonitorConfigChildEle);
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.AUTH_CONFIG,
+ StatusMonitorConstants.NS_PREFIX).equals(statusMonitorConfigChildEle.getQName())) {
+ //element is "authConfig"
+ initAuthentication(statusMonitorConfigChildEle);
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS, StatusMonitorConstants.PS_CONFIG,
+ StatusMonitorConstants.NS_PREFIX).equals(statusMonitorConfigChildEle.getQName())) {
+ //element is "psConfig"
+ initSampleServicesMonitoring(statusMonitorConfigChildEle);
+ } else {
+ String msg = "Unknown element in Status Monitor Configuration: " +
+ statusMonitorConfigChildEle.getQName().getLocalPart();
+ log.warn(msg);
+ }
+ }
+ }
+
+ /*
+ * Deserialise dbConfigElement (Given below) and initialize data source
+ <dbConfig>
+ <url>jdbc:mysql://localhost:3306/stratos_stat</url>
+ <userName>monitor</userName>
+ <password>monitor</password>
+ <driverName>com.mysql.jdbc.Driver</driverName>
+ <maxActive>80</maxActive>
+ <maxWait>60000</maxWait>
+ <minIdle>5</minIdle>
+ <validationQuery>SELECT 1</validationQuery>
+ </dbConfig>
+ */
+ private void initDataSource(OMElement dbConfigEle) throws StatusMonitorException {
+ // initializing the data source and load the database configurations
+ Iterator dbConfigChildIt = dbConfigEle.getChildElements();
+ dataSource = new BasicDataSource();
+
+ while (dbConfigChildIt.hasNext()) {
+
+ OMElement dbConfigChildEle = (OMElement) dbConfigChildIt.next();
+ if (new QName(StatusMonitorConstants.CONFIG_NS, StatusMonitorConstants.DBCONFIG_URL,
+ StatusMonitorConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+ dataSource.setUrl(dbConfigChildEle.getText());
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.DBCONFIG_USER_NAME,
+ StatusMonitorConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+ dataSource.setUsername(dbConfigChildEle.getText());
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.DBCONFIG_PASSWORD,
+ StatusMonitorConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+ dataSource.setPassword(dbConfigChildEle.getText());
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.DBCONFIG_DRIVER_NAME,
+ StatusMonitorConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+ dataSource.setDriverClassName(dbConfigChildEle.getText());
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.DBCONFIG_MAX_ACTIVE,
+ StatusMonitorConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+ dataSource.setMaxActive(Integer.parseInt(dbConfigChildEle.getText()));
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.DBCONFIG_MAX_WAIT,
+ StatusMonitorConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+ dataSource.setMaxWait(Integer.parseInt(dbConfigChildEle.getText()));
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.DBCONFIG_MIN_IDLE,
+ StatusMonitorConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+ dataSource.setMinIdle(Integer.parseInt(dbConfigChildEle.getText()));
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.DBCONFIG_VALIDATION_QUERY,
+ StatusMonitorConstants.NS_PREFIX)
+ .equals(dbConfigChildEle.getQName())) {
+ dataSource.setValidationQuery(dbConfigChildEle.getText());
+ } else {
+ String msg = "Unknown element in DBConfig of Status Monitor Configuration: " +
+ dbConfigChildEle.getQName().getLocalPart();
+ log.warn(msg);
+ }
+ }
+ }
+
+ /*
+ * Deserialise authConfigElement (Given below) and initializes authConfigBean
+ <authConfig>
+ <jksLocation>/home/carbon/automation/projects/src/resources/wso2carbon.jks</jksLocation>
+ <userName>admin@wso2-heartbeat-checker.org</userName>
+ <password>password123</password>
+ </authConfig>
+ */
+ private void initAuthentication(OMElement authConfigEle) throws StatusMonitorException {
+ // initializing the and loading the authentication configurations
+ Iterator authConfigChildIt = authConfigEle.getChildElements();
+ authConfigBean = new AuthConfigBean();
+
+ while (authConfigChildIt.hasNext()) {
+ OMElement authConfigChildEle = (OMElement) authConfigChildIt.next();
+ if (new QName(StatusMonitorConstants.CONFIG_NS, StatusMonitorConstants.JKS_LOCATION,
+ StatusMonitorConstants.NS_PREFIX).equals(authConfigChildEle.getQName())) {
+ authConfigBean.setJksLocation(authConfigChildEle.getText());
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.AUTHCONFIG_USER_NAME,
+ StatusMonitorConstants.NS_PREFIX).equals(authConfigChildEle.getQName())) {
+ authConfigBean.setUserName(authConfigChildEle.getText());
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.AUTHCONFIG_PASSWORD,
+ StatusMonitorConstants.NS_PREFIX).equals(authConfigChildEle.getQName())) {
+ authConfigBean.setPassword(authConfigChildEle.getText());
+ } else if (new QName(StatusMonitorConstants.CONFIG_NS,
+ StatusMonitorConstants.AUTHCONFIG_TENANT,
+ StatusMonitorConstants.NS_PREFIX).equals(authConfigChildEle.getQName())) {
+ authConfigBean.setTenant(authConfigChildEle.getText());
+ } else {
+ String msg = "Unknown element in AuthConfig of Status Monitor Configuration: " +
+ authConfigChildEle.getQName().getLocalPart();
+ log.warn(msg);
+ }
+ }
+ }
+
+ /**
+ <platformSample>
+ <tenantDomain>wso2.org</tenantDomain>
+ </platformSample>
+ */
+ private void initSampleServicesMonitoring (OMElement psConfigEle) throws StatusMonitorException {
+ // initializing the and loading the authentication configurations
+ Iterator psConfigChildIt = psConfigEle.getChildElements();
+ sampleTenantConfigBean = new SampleTenantConfigBean();
+
+ while (psConfigChildIt.hasNext()) {
+ OMElement psConfigChildEle = (OMElement) psConfigChildIt.next();
+ if (new QName(StatusMonitorConstants.CONFIG_NS, StatusMonitorConstants.PSCONFIG_TENANT,
+ StatusMonitorConstants.NS_PREFIX).equals(psConfigChildEle.getQName())) {
+ sampleTenantConfigBean.setTenant(psConfigChildEle.getText());
+ } else {
+ String msg = "Unknown element in PSConfig of Status Monitor Configuration: " +
+ psConfigChildEle.getQName().getLocalPart();
+ log.warn(msg);
+ }
+ }
+ }
+
+ public static BasicDataSource getDataSource() {
+ return dataSource;
+ }
+
+ public static AuthConfigBean getAuthConfigBean() {
+ return authConfigBean;
+ }
+
+ public static SampleTenantConfigBean getSampleTenantConfigBean() {
+ return sampleTenantConfigBean;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/beans/AuthConfigBean.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/beans/AuthConfigBean.java b/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/beans/AuthConfigBean.java
new file mode 100644
index 0000000..a98d94a
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/beans/AuthConfigBean.java
@@ -0,0 +1,61 @@
+/*
+ * 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 org.apache.stratos.status.monitor.core.beans;
+
+/**
+ * Authentication Configuration object that is read from the startus-monitor-config.xml.
+ */
+public class AuthConfigBean {
+ private String jksLocation;
+ private String userName;
+ private String password;
+ private String tenant;
+
+ public String getTenant() {
+ return tenant;
+ }
+
+ public void setTenant(String tenant) {
+ this.tenant = tenant;
+ }
+
+ public String getJksLocation() {
+ return jksLocation;
+ }
+
+ public void setJksLocation(String jksLocation) {
+ this.jksLocation = jksLocation;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fcb90b18/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/beans/SampleTenantConfigBean.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/beans/SampleTenantConfigBean.java b/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/beans/SampleTenantConfigBean.java
new file mode 100644
index 0000000..5c25e0c
--- /dev/null
+++ b/components/org.apache.stratos.status.monitor.core/src/main/java/org/apache/stratos/status/monitor/core/beans/SampleTenantConfigBean.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.stratos.status.monitor.core.beans;
+
+/**
+ * The tenant with the sample services installed.
+ */
+public class SampleTenantConfigBean {
+ private String tenant;
+
+ public String getTenant() {
+ return tenant;
+ }
+
+ public void setTenant(String tenant) {
+ this.tenant = tenant;
+ }
+}