tast app modified
This commit is contained in:
parent
2b375b835d
commit
47436a8a8d
|
@ -0,0 +1 @@
|
||||||
|
/target/
|
2
.project
2
.project
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<projectDescription>
|
<projectDescription>
|
||||||
<name>smartgears-management</name>
|
<name>test-app</name>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
# Changelog for Smartgears Monitor WebApp
|
# Changelog for Test WebApp
|
||||||
|
|
||||||
## [v1.0.0-SNAPSHOT] - 2022-05-11
|
## [v1.0.0-SNAPSHOT] - 2022-05-11
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
FROM luciolelii/smartgears:4.0.0-SNAPSHOT
|
||||||
|
COPY logback.xml /etc/
|
||||||
|
COPY container.ini /etc/
|
||||||
|
COPY target/test-app.war /tomcat/webapps
|
|
@ -1,4 +1,4 @@
|
||||||
# Smartgears Monitor
|
# Test App
|
||||||
|
|
||||||
An Application to add monitoring to all smartgears node
|
An Application to add monitoring to all smartgears node
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
[node]
|
||||||
|
; mandatory
|
||||||
|
; optional fields: mode (=online), publication-frequency-seconds (=60), authorizeChildrenContext (=false)
|
||||||
|
mode = online
|
||||||
|
hostname = dlib29.isti.cnr.it
|
||||||
|
protocol= http
|
||||||
|
port = 8080
|
||||||
|
infrastructure = gcube
|
||||||
|
authorizeChildrenContext = true
|
||||||
|
publicationFrequencyInSeconds = 60
|
||||||
|
|
||||||
|
[properties]
|
||||||
|
; not mandatory
|
||||||
|
SmartGearsDistribution = 0.0.1
|
||||||
|
SmartGearsDistributionBundle = UnBundled
|
||||||
|
|
||||||
|
[site]
|
||||||
|
; mandatory
|
||||||
|
; optional fields: latitude, logitude
|
||||||
|
country = it
|
||||||
|
location = rome
|
||||||
|
|
||||||
|
;[proxy]
|
||||||
|
; not mandatory
|
||||||
|
;protocol = https
|
||||||
|
;hostname = proxy
|
||||||
|
;port = 80
|
||||||
|
|
||||||
|
[authorization]
|
||||||
|
; mandatory
|
||||||
|
; optional fields: provider factory (=org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory)
|
||||||
|
factory = org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory
|
||||||
|
credentials.class = org.gcube.smartgears.security.SimpleCredentials
|
||||||
|
credentials.clientID = node-whn-test-uno-d-d4s.d4science.org
|
||||||
|
credentials.secret = 979bd3bc-5cc4-11ec-bf63-0242ac130002
|
||||||
|
credentials.endpoint = https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token
|
||||||
|
|
||||||
|
;[persistence]
|
||||||
|
; not mandatory (default is LocalPersistence writing in the ghn home)
|
||||||
|
;class = utils.PersistenceWriterTest
|
||||||
|
;location = /tmp
|
|
@ -0,0 +1,70 @@
|
||||||
|
<configuration scan="true" debug="false">
|
||||||
|
|
||||||
|
<appender name="FILE"
|
||||||
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>/smartgears-distribution/ghn.log</file>
|
||||||
|
<append>true</append>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>/smartgears-distribution/ghn.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<maxHistory>30</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="ACCOUNT_FILE"
|
||||||
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>/smartgears-distribution/accounting.log</file>
|
||||||
|
<append>true</append>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>/smartgears-distribution/accounting.%d{yyyy-MM-dd}.log
|
||||||
|
</fileNamePattern>
|
||||||
|
<maxHistory>30</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="ACCESS_FILE"
|
||||||
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>/smartgears-distribution/access.log</file>
|
||||||
|
<append>true</append>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>/smartgears-distribution/access.%d{yyyy-MM-dd}.log
|
||||||
|
</fileNamePattern>
|
||||||
|
<maxHistory>30</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
<logger name="org.gcube.data.publishing" level="ERROR">
|
||||||
|
<appender-ref ref="ACCOUNT_FILE" />
|
||||||
|
</logger>
|
||||||
|
<logger name="org.gcube.documentstore" level="ERROR">
|
||||||
|
<appender-ref ref="ACCOUNT_FILE" />
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<logger name="org.gcube.smartgears.handlers.application.request"
|
||||||
|
level="INFO">
|
||||||
|
<appender-ref ref="ACCESS_FILE" />
|
||||||
|
</logger>
|
||||||
|
|
||||||
|
<logger name="org.gcube" level="INFO" />
|
||||||
|
<logger name="org.gcube.smartgears" level="INFO" />
|
||||||
|
<logger name="org.gcube.common.events" level="WARN" />
|
||||||
|
<logger name="org.gcube.data.publishing" level="ERROR" />
|
||||||
|
<logger name="org.gcube.documentstore" level="ERROR" />
|
||||||
|
|
||||||
|
|
||||||
|
<root level="WARN">
|
||||||
|
<appender-ref ref="FILE" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
15
pom.xml
15
pom.xml
|
@ -9,10 +9,10 @@
|
||||||
<version>1.1.0</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.test</groupId>
|
||||||
<artifactId>smartgears-management</artifactId>
|
<artifactId>test-app</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<name>smartgears management servlet</name>
|
<name>test app servlet</name>
|
||||||
|
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
@ -42,12 +42,7 @@
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-smartgears-app</artifactId>
|
<artifactId>common-smartgears-app</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- javamelody-core -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.bull.javamelody</groupId>
|
|
||||||
<artifactId>javamelody-core</artifactId>
|
|
||||||
<version>1.91.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-smartgears</artifactId>
|
<artifactId>common-smartgears</artifactId>
|
||||||
|
@ -55,6 +50,6 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>management</finalName>
|
<finalName>test-app</finalName>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
|
@ -1,144 +0,0 @@
|
||||||
package org.gcube.core.smartgears.monitor;
|
|
||||||
|
|
||||||
import static org.gcube.smartgears.Constants.frontpage_file_path;
|
|
||||||
import static org.gcube.smartgears.handlers.application.request.RequestError.application_error;
|
|
||||||
import static org.gcube.smartgears.provider.ProviderFactory.provider;
|
|
||||||
import static org.gcube.smartgears.utils.Utils.closeSafely;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.servlet.annotation.WebServlet;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.smartgears.ContextProvider;
|
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
@WebServlet(urlPatterns = "/", name = "smartgearsManagementServlet")
|
|
||||||
public class SmartgearsMonitorServlet extends HttpServlet {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
// the variable replacement pattern
|
|
||||||
private static Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}");
|
|
||||||
|
|
||||||
// log on behalf of extension
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(SmartgearsMonitorServlet.class);
|
|
||||||
|
|
||||||
|
|
||||||
public static final String mapping = "/";
|
|
||||||
|
|
||||||
|
|
||||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
||||||
throws IOException {
|
|
||||||
InputStream page = getClass().getResourceAsStream(frontpage_file_path);
|
|
||||||
|
|
||||||
if (page == null) {
|
|
||||||
log.error("invalid distribution: missing {}", frontpage_file_path);
|
|
||||||
application_error.fire("invalid distribution: missing " + frontpage_file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, String> values = values();
|
|
||||||
|
|
||||||
BufferedReader reader = null;
|
|
||||||
try {
|
|
||||||
|
|
||||||
String line = null;
|
|
||||||
reader = new BufferedReader(new InputStreamReader(page));
|
|
||||||
while ((line = reader.readLine()) != null)
|
|
||||||
response.getWriter().write(interpolate(line, values));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
application_error.fire("could not read " + frontpage_file_path, e);
|
|
||||||
} finally {
|
|
||||||
closeSafely(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> values() {
|
|
||||||
|
|
||||||
ApplicationContext context = ContextProvider.get();
|
|
||||||
|
|
||||||
Map<String, String> values = new HashMap<String, String>();
|
|
||||||
|
|
||||||
values.put("profile_link", "[profile link]");
|
|
||||||
values.put("config_link", "[config link]");
|
|
||||||
|
|
||||||
values.put("name", context.name());
|
|
||||||
values.put("version", context.configuration().version());
|
|
||||||
|
|
||||||
String infrastructure = context.container().configuration().infrastructure();
|
|
||||||
StringBuilder voValue = new StringBuilder();
|
|
||||||
|
|
||||||
Collection<String> scopes = context.profile().scopes().asCollection();
|
|
||||||
Set<String> vos = new HashSet<String>();
|
|
||||||
|
|
||||||
//pre-process
|
|
||||||
for (String scope : scopes) {
|
|
||||||
ScopeBean bean = new ScopeBean(scope);
|
|
||||||
switch (bean.type()) {
|
|
||||||
case INFRASTRUCTURE:
|
|
||||||
infrastructure = bean.name();
|
|
||||||
break;
|
|
||||||
case VO:
|
|
||||||
vos.add(bean.name());
|
|
||||||
break;
|
|
||||||
case VRE:
|
|
||||||
vos.add(bean.enclosingScope().name());
|
|
||||||
infrastructure=bean.enclosingScope().enclosingScope().name();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//build vo value
|
|
||||||
int i = 0;
|
|
||||||
int max = vos.size()-1;
|
|
||||||
for (String vo : vos) {
|
|
||||||
String voPrefix = i == 0 ? "" : (i==max?" and ":", ");
|
|
||||||
voValue.append(voPrefix+"<em>" + vo + "</em>");
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
values.put("infra", infrastructure);
|
|
||||||
values.put("vos", voValue.toString());
|
|
||||||
|
|
||||||
values.put("status", context.lifecycle().state().toString());
|
|
||||||
|
|
||||||
values.put("smartgears-version", provider().smartgearsConfiguration().version());
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String interpolate(String text, Map<String, String> replacements) {
|
|
||||||
|
|
||||||
Matcher matcher = pattern.matcher(text);
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
while (matcher.find()) {
|
|
||||||
String replacement = replacements.get(matcher.group(1));
|
|
||||||
if (replacement != null) {
|
|
||||||
matcher.appendReplacement(buffer, ""); // safer in case replacements include some of the variable
|
|
||||||
// characters
|
|
||||||
buffer.append(replacement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
matcher.appendTail(buffer);
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.gcube.test.app;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@WebServlet(urlPatterns = "/*", name = "testAppServlet")
|
||||||
|
public class TestAppServlet extends HttpServlet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
|
// log on behalf of extension
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(TestAppServlet.class);
|
||||||
|
|
||||||
|
|
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws IOException {
|
||||||
|
log.info("testApp call received");
|
||||||
|
response.getWriter().write("test app started");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<application>
|
||||||
|
<name>TestApp</name>
|
||||||
|
<group>Test</group>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<description>Test webapp</description>
|
||||||
|
<local-persistence location='target' />
|
||||||
|
<exclude handlers='request-validation,context-retriever'>/*</exclude>
|
||||||
|
</application>
|
Loading…
Reference in New Issue