diff --git a/app/aem/common.gradle.kts b/app/aem/common.gradle.kts index 414883009..9cc63f0a5 100644 --- a/app/aem/common.gradle.kts +++ b/app/aem/common.gradle.kts @@ -31,7 +31,7 @@ plugins.withId("com.cognifide.aem.bundle") { } dependencies { - "implementation"("com.adobe.aem:uber-jar:6.4.0:apis") + "implementation"("com.adobe.aem:uber-jar:6.5.5:apis") "implementation"("org.osgi:osgi.cmpn:6.0.0") "implementation"("org.osgi:org.osgi.core:6.0.0") "implementation"("javax.jcr:jcr:2.0") diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryImpl.java b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryImpl.java index 5bd6c9e90..86f0716bb 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryImpl.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryImpl.java @@ -52,6 +52,7 @@ public class HistoryEntryImpl implements HistoryEntry { public static final String PROGRESS_LOG = "summaryJSON"; public static final String UPLOAD_TIME = "uploadTime"; public static final String SCRIPT_CONTENT_PATH = "scriptContentPath"; + public static final String INSTANCE_NAME = "instanceName"; public static final String COMPOSITE_NODE_STORE = "compositeNodeStore"; @Inject @@ -99,6 +100,10 @@ public class HistoryEntryImpl implements HistoryEntry { @Named(SCRIPT_CONTENT_PATH) private String scriptContentPath; + @Inject + @Named(INSTANCE_NAME) + private String instanceName; + @Inject @Named(COMPOSITE_NODE_STORE) private boolean compositeNodeStore; diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java index f1a0a9bd6..4de1abdd9 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java @@ -36,6 +36,7 @@ public class HistoryEntryWriter { private final Boolean isRunSuccessful; private final String mode; private final String progressLog; + private final String instanceName; private final boolean compositeNodeStore; public void writeTo(Resource historyLogResource) { @@ -48,6 +49,7 @@ public void writeTo(Resource historyLogResource) { valueMap.put(HistoryEntryImpl.IS_RUN_SUCCESSFUL, isRunSuccessful); valueMap.put(HistoryEntryImpl.EXECUTION_TIME, executionTime); valueMap.put(HistoryEntryImpl.EXECUTOR, executor); + valueMap.put(HistoryEntryImpl.INSTANCE_NAME, instanceName); valueMap.put(HistoryEntryImpl.COMPOSITE_NODE_STORE, compositeNodeStore); } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryImpl.java b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryImpl.java index e2673fb17..57ba35cc8 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryImpl.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryImpl.java @@ -35,6 +35,7 @@ import com.cognifide.apm.core.utils.RuntimeUtils; import com.cognifide.apm.core.utils.sling.ResolveCallback; import com.day.cq.commons.jcr.JcrConstants; +import java.lang.management.ManagementFactory; import java.util.Calendar; import java.util.LinkedList; import java.util.List; @@ -102,6 +103,7 @@ private HistoryEntryWriterBuilder createBuilder(ResourceResolver resolver, Scrip .isRunSuccessful(progressLogger.isSuccess()) .mode(mode.toString()) .progressLog(ProgressHelper.toJson(progressLogger.getEntries())) + .instanceName(ManagementFactory.getRuntimeMXBean().getName()) .compositeNodeStore(RuntimeUtils.determineCompositeNodeStore(resolver)); } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/jobs/JobResultsCache.java b/app/aem/core/src/main/java/com/cognifide/apm/core/jobs/JobResultsCache.java index 3f12d748f..ed8dbb402 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/jobs/JobResultsCache.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/jobs/JobResultsCache.java @@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; -import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; @@ -46,7 +45,7 @@ public class JobResultsCache { private Cache cache; @Activate - public void activate(final ComponentContext componentContext) { + public void activate() { cache = CacheBuilder.newBuilder().expireAfterWrite(DEFAULT_EXPIRATION_TIME, TimeUnit.MINUTES).build(); } @@ -54,6 +53,10 @@ public void put(String id, ExecutionSummary executionSummary) { cache.put(id, executionSummary); } + public void putIfAbsent(String id, ExecutionSummary executionSummary) { + cache.asMap().putIfAbsent(id, executionSummary); + } + public ExecutionSummary get(String id) { return cache.getIfPresent(id); } diff --git a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/services/async/AsyncScriptExecutorImpl.kt b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/services/async/AsyncScriptExecutorImpl.kt index 2c0725f59..1b38430c6 100644 --- a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/services/async/AsyncScriptExecutorImpl.kt +++ b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/services/async/AsyncScriptExecutorImpl.kt @@ -56,7 +56,7 @@ class AsyncScriptExecutorImpl : AsyncScriptExecutor { properties[USER_ID] = resourceResolver.userID!! properties[DEFINITIONS] = customDefinitions val job = jobManager.addJob(TOPIC, properties) - jobResultsCache.put(job.id, ExecutionSummary.running()) + jobResultsCache.putIfAbsent(job.id, ExecutionSummary.running()) return job.id } diff --git a/app/aem/simple/src/main/java/com/cognifide/apm/simple/ApmSimpleSessionService.java b/app/aem/simple/src/main/java/com/cognifide/apm/simple/ApmSimpleSessionService.java new file mode 100644 index 000000000..e4b65d61d --- /dev/null +++ b/app/aem/simple/src/main/java/com/cognifide/apm/simple/ApmSimpleSessionService.java @@ -0,0 +1,56 @@ +/*- + * ========================LICENSE_START================================= + * AEM Permission Management + * %% + * Copyright (C) 2013 Wunderman Thompson Technology + * %% + * Licensed 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. + * =========================LICENSE_END================================== + */ +package com.cognifide.apm.simple; + +import javax.jcr.Session; +import org.apache.sling.jcr.api.SlingRepository; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component( + immediate = true, + service = ApmSimpleSessionService.class +) +public class ApmSimpleSessionService { + + private static final Logger LOGGER = LoggerFactory.getLogger(ApmSimpleSessionService.class); + + @Reference + private SlingRepository slingRepository; + + @Activate + public void activate() { + Session session = null; + try { + session = slingRepository.loginService(null, null); + LogUtils.log(LOGGER, session, "test session service"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session != null) { + session.logout(); + } + } + } + +} diff --git a/app/aem/simple/src/main/java/com/cognifide/apm/simple/LogUtils.java b/app/aem/simple/src/main/java/com/cognifide/apm/simple/LogUtils.java index ddeb631af..3a48c4bf2 100644 --- a/app/aem/simple/src/main/java/com/cognifide/apm/simple/LogUtils.java +++ b/app/aem/simple/src/main/java/com/cognifide/apm/simple/LogUtils.java @@ -40,12 +40,25 @@ public static void log(Logger logger, ResourceResolver resolver, String message) saveLog(resolver, message, logger.getName()); } + public static void log(Logger logger, Session session, String message) { + logger.info(message); + saveLog(session, message, logger.getName()); + } + private static void saveLog(ResourceResolver resolver, String message, String className) { + try { + Session session = resolver.adaptTo(Session.class); + saveLog(session, message, className); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void saveLog(Session session, String message, String className) { String instanceName = getInstanceName(); String executionTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd hh:mm:ss.SSS")); try { - Session session = resolver.adaptTo(Session.class); - Node node = JcrUtils.getOrCreateByPath("/apps/apm/logs/log", true, JcrConstants.NT_UNSTRUCTURED, JcrConstants.NT_UNSTRUCTURED, session, true); + Node node = JcrUtils.getOrCreateByPath("/apps/apm-logs/log", true, JcrConstants.NT_UNSTRUCTURED, JcrConstants.NT_UNSTRUCTURED, session, true); node.setProperty("message", message); node.setProperty("instanceName", instanceName); node.setProperty("executionTime", executionTime); diff --git a/app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/components/historyRow/historyRow.html b/app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/components/historyRow/historyRow.html index 942e751c7..86f1dabe9 100644 --- a/app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/components/historyRow/historyRow.html +++ b/app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/components/historyRow/historyRow.html @@ -42,6 +42,9 @@ ${item.executor} + + ${item.instanceName} + ${item.mode} diff --git a/app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/views/history/.content.xml b/app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/views/history/.content.xml index ceb0b0898..2cccff8f6 100644 --- a/app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/views/history/.content.xml +++ b/app/aem/ui.apps.base/src/main/content/jcr_root/apps/apm/views/history/.content.xml @@ -58,6 +58,10 @@ jcr:primaryType="nt:unstructured" jcr:title="Executor" sortable="{Boolean}true"/> +