Skip to content

Commit

Permalink
Merge pull request #362 from wttech/feature/install-cloud-mode
Browse files Browse the repository at this point in the history
Feature/install cloud mode
  • Loading branch information
dprzybyl authored Jun 1, 2022
2 parents b2b6a87 + 5be730e commit d6d72e0
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/aem/common.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -46,14 +45,18 @@ public class JobResultsCache {
private Cache<String, ExecutionSummary> cache;

@Activate
public void activate(final ComponentContext componentContext) {
public void activate() {
cache = CacheBuilder.newBuilder().expireAfterWrite(DEFAULT_EXPIRATION_TIME, TimeUnit.MINUTES).build();
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<td is="coral-table-cell" value="${item.executor}">
${item.executor}
</td>
<td is="coral-table-cell" value="${item.instanceName}">
${item.instanceName}
</td>
<td is="coral-table-cell" value="${item.mode}">
${item.mode}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
jcr:primaryType="nt:unstructured"
jcr:title="Executor"
sortable="{Boolean}true"/>
<instance
jcr:primaryType="nt:unstructured"
jcr:title="Instance"
sortable="{Boolean}true"/>
<mode
jcr:primaryType="nt:unstructured"
jcr:title="Mode"
Expand Down
12 changes: 9 additions & 3 deletions app/aem/ui.apps.cloud/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ aem {
tasks {
packageCompose {
mergePackageProject(":app:aem:ui.apps.base")
installBundleProject(":app:aem:api")
installBundleProject(":app:aem:core")
installBundleProject(":app:aem:actions.main")
installBundleProject(":app:aem:api") {
startLevel.set(20)
}
installBundleProject(":app:aem:core") {
startLevel.set(23)
}
installBundleProject(":app:aem:actions.main") {
startLevel.set(21)
}
installBundleProject(":app:aem:startup") {
startLevel.set(27)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scripts=["create path /apps/apm-flag"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scripts=["create path /content/apm-flag"]

0 comments on commit d6d72e0

Please sign in to comment.