Repository: stratos
Updated Branches:
  refs/heads/stratos-4.1.x 7656e2028 -> 581d345c6


http://git-wip-us.apache.org/repos/asf/stratos/blob/9d7226a7/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberStatusFilter/Member_Status_Filter/js/member-status-filter.js
----------------------------------------------------------------------
diff --git 
a/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberStatusFilter/Member_Status_Filter/js/member-status-filter.js
 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberStatusFilter/Member_Status_Filter/js/member-status-filter.js
new file mode 100644
index 0000000..da08330
--- /dev/null
+++ 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberStatusFilter/Member_Status_Filter/js/member-status-filter.js
@@ -0,0 +1,140 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+var applicationId;
+var clusterId;
+var time = '30 Min';
+$(document).ready(function () {
+    loadApplication();
+
+    setTimeout(function () {
+        if (applicationId != null) {
+            loadCluster(applicationId);
+            $('#' + window.frameElement.id).ready(function () {
+                
$(this).contents().find('body').contents().find('#application-filter').val(applicationId);
+                publish(time);
+            });
+        }
+    }, 2000);
+
+    setTimeout(function () {
+        if (clusterId != null) {
+            $('#' + window.frameElement.id).ready(function () {
+                
$(this).contents().find('body').contents().find('#cluster-filter').val(clusterId);
+                publish(time);
+            });
+        }
+    }, 3000);
+
+
+});
+
+gadgets.HubSettings.onConnect = function () {
+    gadgets.Hub.subscribe("request-params", function (topic, data) {
+        applicationId = data.applicationId;
+        clusterId = data.clusterId;
+        console.log("Application Id: " + applicationId);
+        console.log("Cluster Id: " + clusterId);
+    });
+};
+
+$('body').on('change', '#application-filter', function () {
+    var e = document.getElementById("application-filter");
+    applicationId = e.options[e.selectedIndex].value;
+    loadCluster(applicationId);
+    publish(time);
+});
+
+$('body').on('change', '#cluster-filter', function () {
+    var e = document.getElementById("cluster-filter");
+    clusterId = e.options[e.selectedIndex].value;
+    publish(time);
+});
+
+function loadApplication() {
+    console.log("Getting Application Ids");
+    $.ajax({
+        url: '/portal/apis/applications',
+        dataType: 'json',
+        success: function (result) {
+            console.log(JSON.stringify(result));
+            var applicationIds = [];
+            var records = JSON.parse(JSON.stringify(result));
+            records.forEach(function (record, i) {
+                applicationIds.push(record.ApplicationId);
+            });
+
+            var elem = document.getElementById('application-filter');
+            for (i = 0; i < applicationIds.length; i = i + 1) {
+                var option = document.createElement("option");
+                option.text = applicationIds[i];
+                option.value = applicationIds[i];
+                elem.appendChild(option);
+            }
+            document.getElementById('application').appendChild(elem);
+        }
+    });
+}
+
+function loadCluster(application) {
+    $.ajax({
+        url: '/portal/apis/clusters?applicationId=' + application,
+        dataType: 'json',
+        success: function (result) {
+            var elem = document.getElementById('cluster-filter');
+            var clusterAlias = [];
+            var records = JSON.parse(JSON.stringify(result));
+            records.forEach(function (record, i) {
+                clusterAlias.push(record.ClusterAlias);
+            });
+
+            if (elem != null) {
+                elem.parentNode.removeChild(elem);
+            }
+
+            var clusterList = document.createElement('select');
+            clusterList.id = "cluster-filter";
+
+            var optionList = "";
+
+            optionList += "<option value= 'All Clusters'>All 
Clusters</option>";
+            for (i = 0; i < clusterAlias.length; i = i + 1) {
+                optionList += "<option value='" + clusterAlias[i] + "'>" + 
clusterAlias[i] + "</option>";
+            }
+
+            clusterList.innerHTML = optionList;
+            document.getElementById('cluster').appendChild(clusterList);
+        }
+    });
+    if (clusterId == null) {
+        var e = document.getElementById("cluster-filter");
+        clusterId = e.options[e.selectedIndex].value;
+    }
+
+}
+
+function publish(timeInterval) {
+    time = timeInterval;
+    var data = {applicationId: applicationId, clusterId: clusterId, 
timeInterval: time};
+    gadgets.Hub.publish("member-status-filter", data);
+    console.log("Publishing filter values: " + JSON.stringify(data));
+}
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/9d7226a7/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberStatusFilter/artifact.xml
----------------------------------------------------------------------
diff --git 
a/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberStatusFilter/artifact.xml
 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberStatusFilter/artifact.xml
new file mode 100644
index 0000000..79e046d
--- /dev/null
+++ 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/GadgetMemberStatusFilter/artifact.xml
@@ -0,0 +1,24 @@
+<?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.
+
+-->
+<artifact name="GadgetMemberStatusFilter" version="1.0.0" 
type="dashboards/gadget" serverRole="DataAnalyticsServer">
+    <file>Member_Status_Filter</file>
+</artifact>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/9d7226a7/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberInfo/artifact.xml
----------------------------------------------------------------------
diff --git 
a/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberInfo/artifact.xml
 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberInfo/artifact.xml
new file mode 100644
index 0000000..f6ae7ee
--- /dev/null
+++ 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberInfo/artifact.xml
@@ -0,0 +1,24 @@
+<?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.
+
+-->
+<artifact name="SparkscriptsMemberInfo" version="1.0.0" type="analytics/spark" 
serverRole="DataAnalyticsServer">
+    <file>member_information.xml</file>
+</artifact>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/9d7226a7/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberInfo/member_information.xml
----------------------------------------------------------------------
diff --git 
a/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberInfo/member_information.xml
 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberInfo/member_information.xml
new file mode 100644
index 0000000..ef838b6
--- /dev/null
+++ 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberInfo/member_information.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<Analytics>
+    <Name>member_information</Name>
+    <Script>
+        CREATE TEMPORARY TABLE memberinfo
+        USING CarbonAnalytics
+        OPTIONS (tableName "MEMBER_INFO");
+
+        create temporary table member_details
+        using CarbonJDBC options (dataSource 
"WSO2_ANALYTICS_PROCESSED_DATA_STORE_DB", tableName "MEMBER_INFORMATION");
+
+        INSERT OVERWRITE TABLE member_details select member_id, instance_type, 
image_id, host_name,
+        private_IP_addresses, public_IP_addresses, hypervisor, cpu, ram, 
os_name, os_version from memberinfo;
+    </Script>
+    <CronExpression>29 * * * * ?</CronExpression>
+</Analytics>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/9d7226a7/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberLifecycle/artifact.xml
----------------------------------------------------------------------
diff --git 
a/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberLifecycle/artifact.xml
 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberLifecycle/artifact.xml
new file mode 100644
index 0000000..153da46
--- /dev/null
+++ 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberLifecycle/artifact.xml
@@ -0,0 +1,24 @@
+<?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.
+
+-->
+<artifact name="SparkscriptsMemberLifecycle" version="1.0.0" 
type="analytics/spark" serverRole="DataAnalyticsServer">
+    <file>member_count.xml</file>
+</artifact>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/9d7226a7/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberLifecycle/member_count.xml
----------------------------------------------------------------------
diff --git 
a/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberLifecycle/member_count.xml
 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberLifecycle/member_count.xml
new file mode 100644
index 0000000..efebc24
--- /dev/null
+++ 
b/extensions/das/modules/artifacts/metering-dashboard/capps/stratos-metering-service/SparkscriptsMemberLifecycle/member_count.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<Analytics>
+    <Name>member_count</Name>
+    <Script>
+        CREATE TEMPORARY TABLE memberstatus
+        USING CarbonAnalytics
+        OPTIONS (tableName "MEMBER_LIFECYCLE");
+
+        create temporary table member_count
+        using CarbonJDBC options (dataSource 
"WSO2_ANALYTICS_PROCESSED_DATA_STORE_DB", tableName "MEMBER_COUNT");
+
+        ;WITH MemberCount as
+        (select application_id, cluster_alias,
+        count(case when member_status='Created' and timestamp &gt; 
current_time(null)-10000 and
+        timestamp&lt;= current_time(null) then 1 else NULL end) as 
created_instance_count,
+        count(case when member_status='Initialized' and timestamp &gt; 
current_time(null)-10000 and
+        timestamp&lt;= current_time(null) then 1 else NULL end) as 
initialized_instance_count,
+        count(case when member_status='Active' and timestamp &gt; 
current_time(null)-10000 and
+        timestamp&lt;= current_time(null) then 1 else NULL end) as 
active_instance_count,
+        count(case when member_status='Terminated' and timestamp &gt; 
current_time(null)-10000 and
+        timestamp&lt;= current_time(null) then 1 else NULL end) as 
terminated_instance_count
+        from memberstatus group by application_id, cluster_alias)
+        INSERT INTO table member_count
+        select current_time(null), application_id, cluster_alias,
+        
created_instance_count,initialized_instance_count,active_instance_count,
+        terminated_instance_count from MemberCount;
+
+        create temporary table member_status_new
+        using CarbonJDBC options (dataSource 
"WSO2_ANALYTICS_PROCESSED_DATA_STORE_DB", tableName "MEMBER_STATUS");
+
+        INSERT OVERWRITE TABLE member_status_new select timestamp, 
application_id, cluster_alias, member_id,
+        member_status from memberstatus;
+    </Script>
+    <CronExpression>0/10 * * * * ?</CronExpression>
+</Analytics>
\ No newline at end of file

Reply via email to