This is an automated email from the ASF dual-hosted git repository.

wuzhiguo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git


The following commit(s) were added to refs/heads/main by this push:
     new 24cc1e08 BIGTOP-4299: Add basic Grafana service (#121)
24cc1e08 is described below

commit 24cc1e085d205acb58bae897b1baee7ba027426c
Author: haopeng <[email protected]>
AuthorDate: Wed Dec 11 13:50:35 2024 +0800

    BIGTOP-4299: Add basic Grafana service (#121)
---
 .../resources/mapper/postgresql/ClusterMapper.xml  |   3 +-
 .../services/grafana/configuration/grafana.xml     |  33 ++++++
 .../infra/1.0.0/services/grafana/metainfo.xml      |  67 +++++++++++++
 .../stacks/infra/1.0.0/services/grafana/order.json |   1 +
 .../stack/infra/v1_0_0/grafana/GrafanaParams.java  |  50 ++++++++++
 .../infra/v1_0_0/grafana/GrafanaServerScript.java  | 111 +++++++++++++++++++++
 .../stack/infra/v1_0_0/grafana/GrafanaSetup.java   |  43 ++++++++
 7 files changed, 307 insertions(+), 1 deletion(-)

diff --git 
a/bigtop-manager-dao/src/main/resources/mapper/postgresql/ClusterMapper.xml 
b/bigtop-manager-dao/src/main/resources/mapper/postgresql/ClusterMapper.xml
index 7d72590c..829713c6 100644
--- a/bigtop-manager-dao/src/main/resources/mapper/postgresql/ClusterMapper.xml
+++ b/bigtop-manager-dao/src/main/resources/mapper/postgresql/ClusterMapper.xml
@@ -38,10 +38,11 @@
         count(h.id) as total_host, sum(h.available_processors) as 
total_processor,
         sum(h.total_memory_size) as total_memory, sum(h.total_disk) as 
total_disk, count(s.id) as total_service
         from
-        cluster c left join user u on c.create_by = u.id
+        cluster c left join "user" u on c.create_by = u.id
         left join host h on c.id = h.cluster_id
         left join service s on c.id = s.cluster_id
         where c.id = #{id}
+        group by c.id, u.nickname
         limit 1
     </select>
 
diff --git 
a/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/configuration/grafana.xml
 
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/configuration/grafana.xml
new file mode 100644
index 00000000..d15db89e
--- /dev/null
+++ 
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/configuration/grafana.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    https://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.
+-->
+
+<configuration>
+    <property>
+        <name>content</name>
+        <description>This is the freemarker template for grafana.ini 
file</description>
+        <value><![CDATA[
+# TODO
+]]>
+        </value>
+        <attrs>
+            <type>longtext</type>
+        </attrs>
+    </property>
+</configuration>
\ No newline at end of file
diff --git 
a/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/metainfo.xml
 
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/metainfo.xml
new file mode 100644
index 00000000..1670a9bb
--- /dev/null
+++ 
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/metainfo.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~    https://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.
+-->
+
+<metainfo>
+    <service>
+        <name>grafana</name>
+        <display-name>Grafana</display-name>
+        <desc>
+            The open and composable observability and data visualization 
platform. 
+            Visualize metrics, logs, and traces from multiple sources like 
Prometheus, 
+            Loki, Elasticsearch, InfluxDB, Postgres and many more.
+        </desc>
+        <version>11.4.0</version>
+        <user>grafana</user>
+
+        <components>
+            <component>
+                <name>grafana_server</name>
+                <display-name>Grafana Server</display-name>
+                <category>server</category>
+                <cardinality>1+</cardinality>
+            </component>
+        </components>
+
+        <package-specifics>
+            <package-specific>
+                <architectures>
+                    <arch>x86_64</arch>
+                </architectures>
+                <packages>
+                    <package>
+                        <name>grafana-11.4.0.linux-amd64.tar.gz</name>
+                        
<checksum>SHA-256:3550c73f4455435642976e82cc89aa354f076a75b766a408781107f4f5d4744c</checksum>
+                    </package>
+                </packages>
+            </package-specific>
+            <package-specific>
+                <architectures>
+                    <arch>aarch64</arch>
+                </architectures>
+                <packages>
+                    <package>
+                        <name>grafana-11.4.0.linux-arm64.tar.gz</name>
+                        
<checksum>SHA-256:c978b46a61d92883119131641c03b8a1323a284e74ab9a20e7e48207dc1a11e1</checksum>
+                    </package>
+                </packages>
+            </package-specific>
+        </package-specifics>
+    </service>
+</metainfo>
\ No newline at end of file
diff --git 
a/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/order.json
 
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/order.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ 
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/order.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git 
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParams.java
 
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParams.java
new file mode 100644
index 00000000..6a9f1c06
--- /dev/null
+++ 
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParams.java
@@ -0,0 +1,50 @@
+/*
+ * 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
+ *
+ *    https://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.bigtop.manager.stack.infra.v1_0_0.grafana;
+
+import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload;
+import org.apache.bigtop.manager.stack.core.spi.param.Params;
+import org.apache.bigtop.manager.stack.infra.param.InfraParams;
+
+import com.google.auto.service.AutoService;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+import java.text.MessageFormat;
+
+@Getter
+@Slf4j
+@AutoService(Params.class)
+@NoArgsConstructor
+public class GrafanaParams extends InfraParams {
+
+    public GrafanaParams(CommandPayload commandPayload) {
+        super(commandPayload);
+    }
+
+    public String dataDir() {
+        return MessageFormat.format("{0}/data", serviceHome());
+    }
+
+    @Override
+    public String getServiceName() {
+        return "grafana";
+    }
+}
diff --git 
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
 
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
new file mode 100644
index 00000000..23209b8d
--- /dev/null
+++ 
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    https://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.bigtop.manager.stack.infra.v1_0_0.grafana;
+
+import org.apache.bigtop.manager.common.shell.ShellResult;
+import org.apache.bigtop.manager.stack.core.exception.StackException;
+import org.apache.bigtop.manager.stack.core.spi.param.Params;
+import org.apache.bigtop.manager.stack.core.spi.script.AbstractServerScript;
+import org.apache.bigtop.manager.stack.core.spi.script.Script;
+import org.apache.bigtop.manager.stack.core.utils.linux.LinuxOSUtils;
+
+import com.google.auto.service.AutoService;
+import lombok.extern.slf4j.Slf4j;
+
+import java.text.MessageFormat;
+import java.util.Properties;
+
+@AutoService(Script.class)
+@Slf4j
+public class GrafanaServerScript extends AbstractServerScript {
+
+    @Override
+    public ShellResult add(Params params) {
+        Properties properties = new Properties();
+        properties.setProperty(PROPERTY_KEY_SKIP_LEVELS, "1");
+
+        return super.add(params, properties);
+    }
+
+    @Override
+    public ShellResult configure(Params params) {
+        return GrafanaSetup.config(params);
+    }
+
+    @Override
+    public ShellResult start(Params params) {
+        configure(params);
+        GrafanaParams grafanaParams = (GrafanaParams) params;
+        String cmd = MessageFormat.format(
+                "nohup {0}/bin/grafana server --homepath {0} > {0}/nohup.out 
2>&1 &", grafanaParams.serviceHome());
+        log.info(cmd);
+        try {
+            ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd, 
grafanaParams.user());
+            if (shellResult.getExitCode() != 0) {
+                throw new StackException("Failed to start Grafana: {0}", 
shellResult.getErrMsg());
+            }
+            long startTime = System.currentTimeMillis();
+            long maxWaitTime = 5000;
+            long pollInterval = 500;
+
+            while (System.currentTimeMillis() - startTime < maxWaitTime) {
+                ShellResult statusResult = status(params);
+                if (statusResult.getExitCode() == 0) {
+                    return statusResult;
+                }
+                Thread.sleep(pollInterval);
+            }
+            return status(params);
+        } catch (Exception e) {
+            throw new StackException(e);
+        }
+    }
+
+    @Override
+    public ShellResult stop(Params params) {
+        GrafanaParams grafanaParams = (GrafanaParams) params;
+        String cmd = MessageFormat.format("pkill -f {0}/bin/grafana", 
grafanaParams.serviceHome());
+        try {
+            return LinuxOSUtils.sudoExecCmd(cmd, grafanaParams.user());
+        } catch (Exception e) {
+            throw new StackException(e);
+        }
+    }
+
+    @Override
+    public ShellResult status(Params params) {
+        GrafanaParams grafanaParams = (GrafanaParams) params;
+        String cmd = MessageFormat.format("pgrep -f {0}/bin/grafana", 
grafanaParams.serviceHome());
+        try {
+            ShellResult result = LinuxOSUtils.execCmd(cmd);
+            if (result.getExitCode() == 0) {
+                return ShellResult.success();
+            } else {
+                return new ShellResult(-1, "", "Grafana is not running");
+            }
+        } catch (Exception e) {
+            throw new StackException(e);
+        }
+    }
+
+    @Override
+    public String getComponentName() {
+        return "grafana_server";
+    }
+}
diff --git 
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaSetup.java
 
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaSetup.java
new file mode 100644
index 00000000..7a61555c
--- /dev/null
+++ 
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaSetup.java
@@ -0,0 +1,43 @@
+/*
+ * 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
+ *
+ *    https://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.bigtop.manager.stack.infra.v1_0_0.grafana;
+
+import org.apache.bigtop.manager.common.constants.Constants;
+import org.apache.bigtop.manager.common.shell.ShellResult;
+import org.apache.bigtop.manager.stack.core.spi.param.Params;
+import org.apache.bigtop.manager.stack.core.utils.linux.LinuxFileUtils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class GrafanaSetup {
+
+    public static ShellResult config(Params params) {
+        GrafanaParams grafanaParams = (GrafanaParams) params;
+        String user = grafanaParams.user();
+        String group = grafanaParams.group();
+
+        LinuxFileUtils.createDirectories(grafanaParams.dataDir(), user, group, 
Constants.PERMISSION_755, true);
+
+        return ShellResult.success("Grafana Configure success!");
+    }
+}

Reply via email to