diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/.project b/.project index 57f0b56..bb1c038 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - smartgears-management + test-app diff --git a/CHANGELOG.md b/CHANGELOG.md index c269005..4043b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ 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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d85c107 --- /dev/null +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 56fad33..4738aa1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Smartgears Monitor +# Test App An Application to add monitoring to all smartgears node diff --git a/container.ini b/container.ini new file mode 100644 index 0000000..4014816 --- /dev/null +++ b/container.ini @@ -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 diff --git a/logback.xml b/logback.xml new file mode 100644 index 0000000..094d4c7 --- /dev/null +++ b/logback.xml @@ -0,0 +1,70 @@ + + + + /smartgears-distribution/ghn.log + true + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n + + + + /smartgears-distribution/ghn.%d{yyyy-MM-dd}.log + 30 + + + + + /smartgears-distribution/accounting.log + true + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n + + + + /smartgears-distribution/accounting.%d{yyyy-MM-dd}.log + + 30 + + + + + /smartgears-distribution/access.log + true + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n + + + + /smartgears-distribution/access.%d{yyyy-MM-dd}.log + + 30 + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e75314e..25f2604 100644 --- a/pom.xml +++ b/pom.xml @@ -9,10 +9,10 @@ 1.1.0 - org.gcube.core - smartgears-management + org.gcube.test + test-app 1.0.0-SNAPSHOT - smartgears management servlet + test app servlet war @@ -42,12 +42,7 @@ org.gcube.core common-smartgears-app - - - net.bull.javamelody - javamelody-core - 1.91.0 - + org.gcube.core common-smartgears @@ -55,6 +50,6 @@ - management + test-app \ No newline at end of file diff --git a/src/main/java/org/gcube/core/smartgears/monitor/SmartgearsMonitorServlet.java b/src/main/java/org/gcube/core/smartgears/monitor/SmartgearsMonitorServlet.java deleted file mode 100644 index 0fbd323..0000000 --- a/src/main/java/org/gcube/core/smartgears/monitor/SmartgearsMonitorServlet.java +++ /dev/null @@ -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 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 values() { - - ApplicationContext context = ContextProvider.get(); - - Map values = new HashMap(); - - 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 scopes = context.profile().scopes().asCollection(); - Set vos = new HashSet(); - - //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+"" + vo + ""); - 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 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(); - } -} \ No newline at end of file diff --git a/src/main/java/org/gcube/test/app/TestAppServlet.java b/src/main/java/org/gcube/test/app/TestAppServlet.java new file mode 100644 index 0000000..10e455e --- /dev/null +++ b/src/main/java/org/gcube/test/app/TestAppServlet.java @@ -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"); + } + +} \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/gcube-app.xml b/src/main/webapp/WEB-INF/gcube-app.xml new file mode 100644 index 0000000..91965ff --- /dev/null +++ b/src/main/webapp/WEB-INF/gcube-app.xml @@ -0,0 +1,8 @@ + + TestApp + Test + 1.0.0-SNAPSHOT + Test webapp + + /* + \ No newline at end of file