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 07:18:16 UTC
[25/27] aplying 0001-Refactor-usage-module-to-apache-stratos.patch
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.agent/src/main/java/org/apache/stratos/usage/agent/util/UsageAgentConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.agent/src/main/java/org/apache/stratos/usage/agent/util/UsageAgentConstants.java b/components/org.apache.stratos.usage.agent/src/main/java/org/apache/stratos/usage/agent/util/UsageAgentConstants.java
new file mode 100644
index 0000000..94cddc5
--- /dev/null
+++ b/components/org.apache.stratos.usage.agent/src/main/java/org/apache/stratos/usage/agent/util/UsageAgentConstants.java
@@ -0,0 +1,52 @@
+/*
+ *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.usage.agent.util;
+
+/**
+ * this class define constants for UsageAgent component
+ */
+public class UsageAgentConstants {
+ public static final String ELEMENT_NAME_DATA = "Data";
+ public static final String ELEMENT_NAME_KEY = "Key";
+ public static final String ELEMENT_NAME_VALUE = "Value";
+
+ public static final String STATISTICS_DATA_NS_URI = "http://wso2.org/ns/2009/09/bam/server/user-defined/data";
+ public static final String STATISTICS_DATA_NS_PREFIX = "svrusrdata";
+
+ // OM element names
+ public static final String STATISTICS_DATA_ELEMENT_NAME_EVENT = "Event";
+ public static final String STATISTICS_DATA_ELEMENT_NAME_SERVICE_STATISTICS_DATA = "ServerUserDefinedData";
+ public static final String STATISTICS_DATA_ELEMENT_NAME_TENANT_ID = "TenantID";
+ public static final String STATISTICS_DATA_ELEMENT_NAME_SERVER_NAME = "ServerName";
+
+ public static final String BAM_SERVER_URL = "BamServerURL";
+ public static final String BAM_SERVER_STAT_SERVICE = "BAMServerUserDefinedDataSubscriberService";
+ public static final String BAM_SERVER_STAT_FILTER = "carbon/bam/data/publishers/bandwidth-stat";
+
+ public static final String TOPIC_SEPARATOR = "/";
+ public static final String EVENT_NAME = "UsageMeteringEvent";
+
+ public static final String BANDWIDTH_USAGE_TOPIC = BAM_SERVER_STAT_FILTER;
+// public static final String BANDWIDTH_USAGE_TOPIC = BAM_SERVER_STAT_FILTER + TOPIC_SEPARATOR + EVENT_NAME;
+
+
+ public static final String BANDWIDTH_USAGE_SERVICES_CONTEXT = "services";
+ public static final String BANDWIDTH_USAGE_WEBAPPS_CONTEXT = "webapps";
+ public static final String BANDWIDTH_CARBON = "carbon";
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.agent/src/main/java/org/apache/stratos/usage/agent/util/Util.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.agent/src/main/java/org/apache/stratos/usage/agent/util/Util.java b/components/org.apache.stratos.usage.agent/src/main/java/org/apache/stratos/usage/agent/util/Util.java
new file mode 100644
index 0000000..0397869
--- /dev/null
+++ b/components/org.apache.stratos.usage.agent/src/main/java/org/apache/stratos/usage/agent/util/Util.java
@@ -0,0 +1,178 @@
+/*
+ *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.usage.agent.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.base.ServerConfiguration;
+import org.wso2.carbon.base.api.ServerConfigurationService;
+import org.wso2.carbon.event.core.EventBroker;
+import org.wso2.carbon.event.core.exception.EventBrokerException;
+import org.wso2.carbon.event.core.subscription.Subscription;
+import org.wso2.carbon.event.core.util.EventBrokerConstants;
+import org.wso2.carbon.registry.core.config.RegistryContext;
+import org.wso2.carbon.statistics.services.SystemStatisticsUtil;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.usage.agent.beans.BandwidthUsage;
+import org.apache.stratos.usage.agent.config.UsageAgentConfiguration;
+import org.apache.stratos.usage.agent.listeners.RegistryUsageListener;
+import org.apache.stratos.usage.agent.persist.UsageDataPersistenceManager;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.utils.CarbonUtils;
+import org.wso2.carbon.utils.ConfigurationContextService;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import java.io.File;
+
+
+/**
+ * this class provide utility methods to set and get RealmService, initializing listeners,
+ * initializing PersistenceManager etc
+ * Further it provide methods to create statistics event subscription
+ */
+
+public class Util {
+ private static final Log log = LogFactory.getLog(Util.class);
+ private static final String USAGE_THROTTLING_AGENT_CONFIG_FILE = "usage-throttling-agent-config.xml";
+ private static RealmService realmService;
+ private static ConfigurationContextService contextService;
+ private static UsageDataPersistenceManager persistenceManager;
+ //private static EventBrokerService eventBrokerService;
+ private static EventBroker eventBrokerService;
+ private static ServerConfigurationService serverConfiguration;
+
+ private static SystemStatisticsUtil systemStatisticsUtil;
+
+ public static synchronized void setRealmService(RealmService service) {
+ if (realmService == null) {
+ realmService = service;
+ }
+ }
+
+ public static RealmService getRealmService() {
+ return realmService;
+ }
+
+ public static void initializeAllListeners() throws Exception {
+ RegistryUsageListener.registerRegistryUsagePersistingListener(
+ RegistryContext.getBaseInstance());
+ }
+
+ public static void setConfigurationContextService(ConfigurationContextService contextService) {
+ Util.contextService = contextService;
+ }
+
+ public static ConfigurationContextService getConfigurationContextService() {
+ return Util.contextService;
+ }
+
+ /**
+ * this method create a PersistenceManager instance and start a thread for persisting statistics
+ */
+
+ public static void initializePersistenceManager() {
+ File usageAgentConfigFile = new File(CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ StratosConstants.MULTITENANCY_CONFIG_FOLDER + File.separator + Util.USAGE_THROTTLING_AGENT_CONFIG_FILE);
+ persistenceManager = new UsageDataPersistenceManager(new UsageAgentConfiguration(usageAgentConfigFile));
+ //start a thread for persisting bandwidth Usage statistics
+ if("true".equals(ServerConfiguration.getInstance().getFirstProperty("EnableMetering"))){
+ persistenceManager.scheduleBandwidthUsageDataRetrievalTask();
+ persistenceManager.scheduleUsageDataPersistenceTask();
+ }
+ }
+
+ public static void addToPersistingControllerQueue(BandwidthUsage usage) {
+ persistenceManager.addToQueue(usage);
+ }
+
+ public static EventBroker getEventBrokerService() {
+ return eventBrokerService;
+ }
+
+ public static void setEventBrokerService(EventBroker eventBrokerService) {
+ Util.eventBrokerService = eventBrokerService;
+ }
+
+ public static ServerConfigurationService getServerConfiguration() {
+ return serverConfiguration;
+ }
+
+ public static void setServerConfiguration(ServerConfigurationService serverConfiguration) {
+ Util.serverConfiguration = serverConfiguration;
+ }
+
+ public static SystemStatisticsUtil getSystemStatisticsUtil() {
+ return systemStatisticsUtil;
+ }
+
+ public static void setSystemStatisticsUtil(SystemStatisticsUtil systemStatisticsUtil) {
+ Util.systemStatisticsUtil = systemStatisticsUtil;
+ }
+
+ /**
+ * method to create static subscription to BAM
+ *
+ * @throws EventBrokerException, if creating the static subscription to BAM failed.
+ */
+ public static void createStaticEventSubscription() throws EventBrokerException {
+
+ //Get BAM URL from carbon.xml
+ ServerConfigurationService serverConfiguration = getServerConfiguration();
+ if (serverConfiguration == null) {
+ throw new IllegalArgumentException("Invalid server configuration");
+ }
+ String serverURL = serverConfiguration.getFirstProperty(UsageAgentConstants.BAM_SERVER_URL);
+
+ if(log.isDebugEnabled()){
+ log.debug("Bam url = " + serverURL);
+ }
+
+ //Add static subscription only if bam url is set
+ if (serverURL != null) {
+ String serviceURL = serverURL + UsageAgentConstants.BAM_SERVER_STAT_SERVICE;
+
+ EventBroker eventBrokerService = getEventBrokerService();
+ Subscription subscription = new Subscription();
+ // set the subscription end point to the service url
+ subscription.setEventSinkURL(serviceURL);
+ subscription.setTopicName(UsageAgentConstants.BAM_SERVER_STAT_FILTER);
+ subscription.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
+ subscription.setEventDispatcherName(EventBrokerConstants.WS_EVENT_DISPATCHER_NAME);
+
+ try {
+ eventBrokerService.subscribe(subscription);
+ } catch (EventBrokerException e) {
+ String msg = "Cannot subscribe to the event broker ";
+ log.error(msg);
+ throw e;
+ }
+ }
+ }
+
+ public static int getTenantId(String toAddress) throws Exception {
+ int index = toAddress.indexOf("/t/");
+ int tenantId = MultitenantConstants.INVALID_TENANT_ID;
+ if(index >= 0){
+ String tenantDomain = toAddress.substring(index+2, toAddress.indexOf("/", index+3));
+ tenantId = getRealmService().getTenantManager().getTenantId(tenantDomain);
+ }
+ return tenantId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/component.xml
new file mode 100644
index 0000000..0654318
--- /dev/null
+++ b/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/component.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<component xmlns="http://products.wso2.org/carbon">
+ <ManagementPermissions>
+ <ManagementPermission>
+ <DisplayName>Monitor</DisplayName>
+ <ResourceId>/permission/admin/monitor</ResourceId>
+ </ManagementPermission>
+ <ManagementPermission>
+ <DisplayName>Tenant-Usage</DisplayName>
+ <ResourceId>/permission/admin/monitor/tenantUsage</ResourceId>
+ </ManagementPermission>
+ <ManagementPermission>
+ <DisplayName>Tenant-Usage</DisplayName>
+ <ResourceId>/permission/admin/monitor/tenantUsage/customUsage</ResourceId>
+ </ManagementPermission>
+ </ManagementPermissions>
+</component>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/module.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/module.xml b/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/module.xml
new file mode 100644
index 0000000..1b09002
--- /dev/null
+++ b/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/module.xml
@@ -0,0 +1,51 @@
+<!--
+ ~ 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.
+ -->
+<module name="metering" class="org.apache.stratos.usage.agent.listeners.axis2.RequestMeteringModule">
+ <InFlow>
+
+ <!--<handler name="InFlowMeteringHandler"
+ class="org.wso2.carbon.usage.agent.listeners.StatisticsInHandler">
+ <order phase="OpPhase"/>
+ </handler>-->
+ </InFlow>
+
+ <InFaultFlow>
+
+ <!--<handler name="InFlowMeteringHandler"
+ class="org.wso2.carbon.usage.agent.listeners.StatisticsInHandler">
+ <order phase="OpPhase"/>
+ </handler>-->
+ </InFaultFlow>
+
+ <OutFlow>
+ <handler name="OutFlowMeteringHandler"
+ class="org.apache.stratos.usage.agent.listeners.StatisticsOutHandler">
+ <order phase="StatReporting"/>
+ </handler>
+ </OutFlow>
+
+ <OutFaultFlow>
+ <handler name="OutFlowMeteringHandler"
+ class="org.apache.stratos.usage.agent.listeners.StatisticsOutHandler">
+ <order phase="StatReporting"/>
+ </handler>
+
+ </OutFaultFlow>
+ <parameter name="adminModule" locked="true">true</parameter>
+</module>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/services.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/services.xml
new file mode 100644
index 0000000..a0c68b1
--- /dev/null
+++ b/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/services.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<serviceGroup>
+
+ <service name="CustomMeteringService" scope="transportsession">
+ <transports>
+ <transport>https</transport>
+ </transports>
+ <parameter name="ServiceClass" locked="false">
+ org.apache.stratos.usage.agent.services.CustomMeteringService
+ </parameter>
+ </service>
+ <parameter name="adminService" locked="true">true</parameter>
+ <parameter name="hiddenService" locked="true">true</parameter>
+</serviceGroup>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/usage-throttling-agent-config.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/usage-throttling-agent-config.xml b/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/usage-throttling-agent-config.xml
new file mode 100644
index 0000000..ac3084a
--- /dev/null
+++ b/components/org.apache.stratos.usage.agent/src/main/resources/META-INF/usage-throttling-agent-config.xml
@@ -0,0 +1,33 @@
+<!--
+ ~ 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.
+ -->
+<UsageAndThrottlingAgentConfiguration xmlns="http://wso2.com/carbon/multitenancy/usage-throttling-agent/config">
+ <UsageAgent>
+ <UsageDataPersistenceTask>
+ <StartupDelayInMilliSeconds>60000</StartupDelayInMilliSeconds>
+ <NumberOfRecordsPerExecution>100</NumberOfRecordsPerExecution>
+ <ExecutionIntervalInMilliSeconds>100</ExecutionIntervalInMilliSeconds>
+ </UsageDataPersistenceTask>
+ </UsageAgent>
+ <ThrottlingAgent>
+ <ThrottlingInfoCacheUpdaterTask>
+ <StartupDelayInSeconds></StartupDelayInSeconds>
+ <ExecutionIntervalInSeconds></ExecutionIntervalInSeconds>
+ </ThrottlingInfoCacheUpdaterTask>
+ </ThrottlingAgent>
+</UsageAndThrottlingAgentConfiguration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/pom.xml b/components/org.apache.stratos.usage.summary.helper/pom.xml
new file mode 100644
index 0000000..3cbe53c
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/pom.xml
@@ -0,0 +1,139 @@
+<!--
+# 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">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.stratos</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ <artifactId>org.apache.stratos.usage.summary.helper</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos Usage Summary Generation Helper</name>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ <version>1.7.2</version>
+ <executions>
+ <execution>
+ <id>generate-scr-scrdescriptor</id>
+ <goals>
+ <goal>scr</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Axis2Module>${project.artifactId}-${project.version}</Axis2Module>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.apache.stratos.usage.summary.*,
+ </Export-Package>
+ <Import-Package>
+ *;resolution:=optional
+ </Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.hive.wso2</groupId>
+ <artifactId>hive</artifactId>
+ <version>0.8.1.wso2v3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-exec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-shims</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-builtins</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-service</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-serde</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-metastore</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-cassandra</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-jdbc</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>hive-jdbc-handler</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.analytics.hive</artifactId>
+ <version>4.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-core</artifactId>
+ <version>0.20.2</version>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>wso2-nexus</id>
+ <name>WSO2 internal Repository</name>
+ <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>daily</updatePolicy>
+ <checksumPolicy>ignore</checksumPolicy>
+ </releases>
+ </repository>
+ </repositories>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailyCartridgeStatsSummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailyCartridgeStatsSummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailyCartridgeStatsSummarizerHelper.java
new file mode 100644
index 0000000..370faed
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailyCartridgeStatsSummarizerHelper.java
@@ -0,0 +1,58 @@
+/*
+ *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.usage.summary.helper;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the hour range for the next daily summarization cycle in the hive config.
+ * This is important to select the data slice corresponding the current daily summarization cycle
+ * from the usage hourly tables.
+ */
+public class DailyCartridgeStatsSummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlySummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos cartridge stats daily summarization.");
+ try {
+ String lastDailyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastCartridgeStatsDailyTimestamp();
+ Long lastDailyTimestampSecs = Timestamp.valueOf(lastDailyTimestampStr).getTime() / 1000;
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+ Long currentTsSecs = Timestamp.valueOf(currentTsStr).getTime() / 1000;
+
+ log.info("Running daily cartridge stats analytics from " + lastDailyTimestampStr + " to " + currentTsStr);
+ setProperty("last_daily_ts", lastDailyTimestampSecs.toString());
+ setProperty("current_daily_ts", currentTsSecs.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting date range for daily cartridge stats analysis. ", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailyServiceStatsSummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailyServiceStatsSummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailyServiceStatsSummarizerHelper.java
new file mode 100644
index 0000000..c688713
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailyServiceStatsSummarizerHelper.java
@@ -0,0 +1,58 @@
+/*
+ *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.usage.summary.helper;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the hour range for the next daily summarization cycle in the hive config.
+ * This is important to select the data slice corresponding the current daily summarization cycle
+ * from the usage hourly tables.
+ */
+public class DailyServiceStatsSummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlySummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos service stats daily summarization.");
+ try {
+ String lastDailyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastServiceStatsDailyTimestamp();
+ Long lastDailyTimestampSecs = Timestamp.valueOf(lastDailyTimestampStr).getTime() / 1000;
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+ Long currentTsSecs = Timestamp.valueOf(currentTsStr).getTime() / 1000;
+
+ log.info("Running daily service stats analytics from " + lastDailyTimestampStr + " to " + currentTsStr);
+ setProperty("last_daily_ts", lastDailyTimestampSecs.toString());
+ setProperty("current_daily_ts", currentTsSecs.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting date range for daily service stats analysis. ", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailySummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailySummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailySummarizerHelper.java
new file mode 100644
index 0000000..2043337
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/DailySummarizerHelper.java
@@ -0,0 +1,58 @@
+/*
+ *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.usage.summary.helper;
+
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the hour range for the next daily summarization cycle in the hive config.
+ * This is important to select the data slice corresponding the current daily summarization cycle
+ * from the usage hourly tables.
+ */
+public class DailySummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlySummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos usage daily summarization.");
+ try {
+ String lastDailyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastUsageDailyTimestamp();
+ Long lastDailyTimestampSecs = Timestamp.valueOf(lastDailyTimestampStr).getTime() / 1000;
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+ Long currentTsSecs = Timestamp.valueOf(currentTsStr).getTime() / 1000;
+
+ log.info("Running daily usage analytics from " + lastDailyTimestampStr + " to " + currentTsStr);
+ setProperty("last_daily_ts", lastDailyTimestampSecs.toString());
+ setProperty("current_daily_ts", currentTsSecs.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting date range for daily usage analysis. ", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlyCartridgeStatsSummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlyCartridgeStatsSummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlyCartridgeStatsSummarizerHelper.java
new file mode 100644
index 0000000..fde59df
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlyCartridgeStatsSummarizerHelper.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.usage.summary.helper;
+
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the timestamp of the last hourly summarization cycle in hive config.
+ * This is needed to excluded the already summarized usage stats in the current summarization cycle.
+ */
+public class HourlyCartridgeStatsSummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlyCartridgeStatsSummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos cartridge stats hourly summarization.");
+ try {
+ String lastHourlyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastCartridgeStatsHourlyTimestamp();
+ Long lastHourlyTimestamp = Timestamp.valueOf(lastHourlyTimestampStr).getTime();
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+
+ log.info("Running hourly cartridge stats analytics from " + lastHourlyTimestampStr + " to " + currentTsStr);
+ setProperty("last_hourly_ts", lastHourlyTimestamp.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting hour range for hourly cartridge stats analysis. ", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlyServiceStatsSummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlyServiceStatsSummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlyServiceStatsSummarizerHelper.java
new file mode 100644
index 0000000..0a13245
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlyServiceStatsSummarizerHelper.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.usage.summary.helper;
+
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the timestamp of the last hourly summarization cycle in hive config.
+ * This is needed to excluded the already summarized usage stats in the current summarization cycle.
+ */
+public class HourlyServiceStatsSummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlyServiceStatsSummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos service stats hourly summarization.");
+ try {
+ String lastHourlyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastServiceStatsHourlyTimestamp();
+ Long lastHourlyTimestamp = Timestamp.valueOf(lastHourlyTimestampStr).getTime();
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+
+ log.info("Running hourly service stats analytics from " + lastHourlyTimestampStr + " to " + currentTsStr);
+ setProperty("last_hourly_ts", lastHourlyTimestamp.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting hour range for hourly service stats analysis. ", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlySummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlySummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlySummarizerHelper.java
new file mode 100644
index 0000000..f41fe9f
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/HourlySummarizerHelper.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.usage.summary.helper;
+
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the timestamp of the last hourly summarization cycle in hive config.
+ * This is needed to excluded the already summarized usage stats in the current summarization cycle.
+ */
+public class HourlySummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlySummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos usage hourly summarization.");
+ try {
+ String lastHourlyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastUsageHourlyTimestamp();
+ Long lastHourlyTimestamp = Timestamp.valueOf(lastHourlyTimestampStr).getTime();
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+
+ log.info("Running hourly usage analytics from " + lastHourlyTimestampStr + " to " + currentTsStr);
+ setProperty("last_hourly_ts", lastHourlyTimestamp.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting hour range for hourly usage analysis. ", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlyCartridgeStatsSummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlyCartridgeStatsSummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlyCartridgeStatsSummarizerHelper.java
new file mode 100644
index 0000000..30e2ad4
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlyCartridgeStatsSummarizerHelper.java
@@ -0,0 +1,60 @@
+/*
+ *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.usage.summary.helper;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the date range for the next monthly summarization cycle in the hive config.
+ * This is important to select the data slice corresponding the current monthly summarization cycle
+ * from the usage hourly tables.
+ */
+public class MonthlyCartridgeStatsSummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlySummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos cartridge stats monthly summarization.");
+ try {
+ String lastMonthlyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastCartridgeStatsMonthlyTimestamp();
+ Long lastMonthlyTimestampSecs = Timestamp.valueOf(lastMonthlyTimestampStr).getTime() / 1000;
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+ Long currentTsSecs = Timestamp.valueOf(currentTsStr).getTime() / 1000;
+
+ log.info("Running monthly cartridge stats analytics from " + lastMonthlyTimestampStr + " to " + currentTsStr);
+ setProperty("last_monthly_ts", lastMonthlyTimestampSecs.toString());
+ setProperty("current_monthly_ts", currentTsSecs.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting month range for monthly cartridge stats analytics. ", e);
+ }
+
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlyServiceStatsSummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlyServiceStatsSummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlyServiceStatsSummarizerHelper.java
new file mode 100644
index 0000000..8c81a83
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlyServiceStatsSummarizerHelper.java
@@ -0,0 +1,60 @@
+/*
+ *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.usage.summary.helper;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the date range for the next monthly summarization cycle in the hive config.
+ * This is important to select the data slice corresponding the current monthly summarization cycle
+ * from the usage hourly tables.
+ */
+public class MonthlyServiceStatsSummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlySummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos service stats monthly summarization.");
+ try {
+ String lastMonthlyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastUsageMonthlyTimestamp();
+ Long lastMonthlyTimestampSecs = Timestamp.valueOf(lastMonthlyTimestampStr).getTime() / 1000;
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+ Long currentTsSecs = Timestamp.valueOf(currentTsStr).getTime() / 1000;
+
+ log.info("Running monthly service stats analytics from " + lastMonthlyTimestampStr + " to " + currentTsStr);
+ setProperty("last_monthly_ts", lastMonthlyTimestampSecs.toString());
+ setProperty("current_monthly_ts", currentTsSecs.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting month range for monthly service stats analytics. ", e);
+ }
+
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlySummarizerHelper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlySummarizerHelper.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlySummarizerHelper.java
new file mode 100644
index 0000000..b35fbb7
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/MonthlySummarizerHelper.java
@@ -0,0 +1,60 @@
+/*
+ *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.usage.summary.helper;
+
+import org.apache.stratos.usage.summary.helper.util.DataAccessObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.extension.AbstractHiveAnalyzer;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to set the date range for the next monthly summarization cycle in the hive config.
+ * This is important to select the data slice corresponding the current monthly summarization cycle
+ * from the usage hourly tables.
+ */
+public class MonthlySummarizerHelper extends AbstractHiveAnalyzer {
+
+ private static Log log = LogFactory.getLog(HourlySummarizerHelper.class);
+
+ public void execute() {
+ log.info("Running custom analyzer for Stratos usage monthly summarization.");
+ try {
+ String lastMonthlyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastServiceStatsMonthlyTimestamp();
+ Long lastMonthlyTimestampSecs = Timestamp.valueOf(lastMonthlyTimestampStr).getTime() / 1000;
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+ String currentTsStr = formatter.format(new Date().getTime());
+ Long currentTsSecs = Timestamp.valueOf(currentTsStr).getTime() / 1000;
+
+ log.info("Running monthly service stats analytics from " + lastMonthlyTimestampStr + " to " + currentTsStr);
+ setProperty("last_monthly_ts", lastMonthlyTimestampSecs.toString());
+ setProperty("current_monthly_ts", currentTsSecs.toString());
+ } catch (Exception e) {
+ log.error("An error occurred while setting month range for monthly service stats analysis. ", e);
+ }
+
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/internal/UsageSummaryHelperServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/internal/UsageSummaryHelperServiceComponent.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/internal/UsageSummaryHelperServiceComponent.java
new file mode 100644
index 0000000..28bd055
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/internal/UsageSummaryHelperServiceComponent.java
@@ -0,0 +1,84 @@
+/*
+ *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.usage.summary.helper.internal;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.analytics.hive.service.HiveExecutorService;
+import org.wso2.carbon.ndatasource.core.DataSourceService;
+import org.apache.stratos.usage.summary.helper.util.DataHolder;
+
+import javax.sql.DataSource;
+
+/**
+ *
+ * @scr.component name="org.wso2.carbon.usage.summary" immediate="true"
+ * @scr.reference name="hive.executor.service"
+ * interface="org.wso2.carbon.analytics.hive.service.HiveExecutorService" cardinality="1..1"
+ * policy="dynamic" bind="setHiveExecutorService" unbind="unsetHiveExecutorService"
+ * @scr.reference name="datasources.service"
+ * interface="org.wso2.carbon.ndatasource.core.DataSourceService"
+ * cardinality="1..1" policy="dynamic"
+ * bind="setDataSourceService" unbind="unsetDataSourceService"
+ */
+public class UsageSummaryHelperServiceComponent {
+
+ private static Log log = LogFactory.getLog(UsageSummaryHelperServiceComponent.class);
+
+ protected void activate(ComponentContext context){
+
+ log.info("Stratos usage summary helper bundle started");
+ /*try{
+
+ }catch (Throwable t){
+ log.error("Error occurred while activating the usage summary helper bundle..", t);
+ }*/
+ }
+
+ protected void deactivate(){
+ log.debug("Usage summary helper bundle was deactivated..");
+ }
+
+ protected void setHiveExecutorService(HiveExecutorService executorService){
+ //DataHolder.setExecutorService(executorService);
+ }
+
+ protected void unsetHiveExecutorService(HiveExecutorService executorService){
+ //DataHolder.setExecutorService(null);
+ }
+
+ protected void setDataSourceService(DataSourceService dataSourceService){
+ DataHolder.setDataSourceService(dataSourceService);
+ try {
+ DataHolder.setDataSource((DataSource)dataSourceService.getDataSource(DataHolder.BILLING_DATA_SOURCE_NAME).getDSObject());
+ log.info("Data source set to data holder");
+ } catch (Exception e) {
+ log.error("Error occurred while retrieving the data source: " + DataHolder.BILLING_DATA_SOURCE_NAME, e); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ protected void unsetDataSourceService(DataSourceService dataSourceService){
+ DataHolder.setDataSourceService(null);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/util/DataAccessObject.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/util/DataAccessObject.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/util/DataAccessObject.java
new file mode 100644
index 0000000..3af9706
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/util/DataAccessObject.java
@@ -0,0 +1,399 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.usage.summary.helper.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Helper class to retrieve relevant timestamps from relational database tables.
+ */
+public class DataAccessObject {
+
+ private static Log log = LogFactory.getLog(DataAccessObject.class);
+
+ private static DataSource dataSource = null;
+
+ private static DataAccessObject usageDataAccessObj = null;
+
+ private DataAccessObject() {
+ }
+
+ public static DataAccessObject getInstance() throws Exception {
+ if (usageDataAccessObj == null) {
+ usageDataAccessObj = new DataAccessObject();
+ }
+
+ if (usageDataAccessObj.dataSource == null) {
+ if (DataHolder.getDataSource() != null) {
+ try {
+ dataSource = DataHolder.getDataSource();
+ //dataSource = (DataSource) DataHolder.getDataSourceService().
+ // getDataSource(DataHolder.BILLING_DATA_SOURCE_NAME).getDSObject();
+ } catch (Exception e) {
+ log.error("Error occurred while obtaining " + DataHolder.BILLING_DATA_SOURCE_NAME +
+ " datasource from data source service.", e);
+ throw new Exception(e);
+ }
+ } else {
+ log.error("Cannot obtain data source " + DataHolder.BILLING_DATA_SOURCE_NAME +
+ ". Datasource service is null");
+ throw new Exception("Datasource service not available");
+ }
+
+ }
+
+ return usageDataAccessObj;
+ }
+
+ public String getAndUpdateLastUsageHourlyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM USAGE_LAST_HOURLY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO USAGE_LAST_HOURLY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last hourly timestamp. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+ public String getAndUpdateLastUsageDailyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM USAGE_LAST_DAILY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO USAGE_LAST_DAILY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last daily timestamp. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+ public String getAndUpdateLastUsageMonthlyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM USAGE_LAST_MONTHLY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO USAGE_LAST_MONTHLY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last monthly timestamp. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+ public String getAndUpdateLastServiceStatsHourlyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM SERVICE_STATS_LAST_HOURLY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO SERVICE_STATS_LAST_HOURLY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last hourly timestamp. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+ public String getAndUpdateLastServiceStatsDailyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM SERVICE_STATS_LAST_DAILY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO SERVICE_STATS_LAST_DAILY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last daily timestamp. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+ public String getAndUpdateLastServiceStatsMonthlyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM SERVICE_STATS_LAST_MONTHLY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO SERVICE_STATS_LAST_MONTHLY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last monthly timestamp. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+ public String getAndUpdateLastCartridgeStatsHourlyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM CARTRIDGE_STATS_LAST_HOURLY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO CARTRIDGE_STATS_LAST_HOURLY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last hourly timestamp for cartridge stats. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+ public String getAndUpdateLastCartridgeStatsDailyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM CARTRIDGE_STATS_LAST_DAILY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO CARTRIDGE_STATS_LAST_DAILY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last daily timestamp for cartridge stats. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+ public String getAndUpdateLastCartridgeStatsMonthlyTimestamp() throws SQLException {
+
+ Timestamp lastSummaryTs = null;
+ Connection connection = null;
+
+ try {
+ connection = dataSource.getConnection();
+ String sql = "SELECT TIMESTMP FROM CARTRIDGE_STATS_LAST_MONTHLY_TS WHERE ID='LatestTS'";
+ PreparedStatement ps = connection.prepareStatement(sql);
+ ResultSet resultSet = ps.executeQuery();
+ if (resultSet.next()) {
+ lastSummaryTs = resultSet.getTimestamp("TIMESTMP");
+ } else {
+ lastSummaryTs = new Timestamp(0);
+ }
+
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
+ Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date()));
+
+ String currentSql = "INSERT INTO CARTRIDGE_STATS_LAST_MONTHLY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?";
+ PreparedStatement ps1 = connection.prepareStatement(currentSql);
+ ps1.setTimestamp(1, currentTs);
+ ps1.setTimestamp(2, currentTs);
+ ps1.execute();
+
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get and update the last monthly timestamp for cartridge stats. ", e);
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ return lastSummaryTs.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/util/DataHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/util/DataHolder.java b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/util/DataHolder.java
new file mode 100644
index 0000000..f4889a6
--- /dev/null
+++ b/components/org.apache.stratos.usage.summary.helper/src/main/java/org/apache/stratos/usage/summary/helper/util/DataHolder.java
@@ -0,0 +1,50 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.usage.summary.helper.util;
+
+import org.wso2.carbon.ndatasource.core.DataSourceService;
+
+import javax.sql.DataSource;
+
+public class DataHolder {
+
+ private static DataSourceService dataSourceService;
+
+ private static DataSource dataSource;
+
+ public static final String BILLING_DATA_SOURCE_NAME = "WSO2BillingDS";
+ //public static final String BILLING_DATA_SOURCE_NAME = "WSO2USAGE_DS";
+
+
+ public static DataSource getDataSource() {
+ return dataSource;
+ }
+
+ public static void setDataSource(DataSource dataSource) {
+ DataHolder.dataSource = dataSource;
+ }
+
+ public static DataSourceService getDataSourceService() {
+ return dataSourceService;
+ }
+
+ public static void setDataSourceService(DataSourceService dataSourceService) {
+ DataHolder.dataSourceService = dataSourceService;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/pom.xml b/components/org.apache.stratos.usage.ui/pom.xml
new file mode 100644
index 0000000..3cd0ec8
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/pom.xml
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+# 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>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.usage.ui</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos - Usage - User Interface</name>
+
+ <build>
+
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </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.wso2.carbon.usage.ui.*,
+ </Export-Package>
+ <Import-Package>
+ org.wso2.carbon.usage.stub.*; version="${carbon.platform.package.import.version.range}",
+ javax.servlet;version="${imp.pkg.version.javax.servlet}",
+ javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+ !javax.xml.namespace,
+ javax.xml.namespace; version=0.0.0,
+ org.apache.lucene.*,
+ *;resolution:=optional
+ </Import-Package>
+ <Carbon-Component>UIBundle</Carbon-Component>
+ </instructions>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec.wso2</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.4.0.wso2v1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.common.ui</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>javax.servlet</artifactId>
+ <version>3.0.0.v201112011016</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom.wso2</groupId>
+ <artifactId>axiom</artifactId>
+ <version>1.2.11.wso2v2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.ui</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.common</artifactId>
+ <version>2.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.usage.stub</artifactId>
+ <version>4.1.3</version>
+ </dependency>
+ </dependencies>
+
+</project>