Skip to content

Commit

Permalink
add akamai agent
Browse files Browse the repository at this point in the history
  • Loading branch information
wildone committed Apr 11, 2021
1 parent 7e24e88 commit 817ffa1
Show file tree
Hide file tree
Showing 14 changed files with 1,112 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:rep="internal"
jcr:mixinTypes="[rep:AccessControllable]"
jcr:primaryType="sling:Folder"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
cq:defaultView="html"
jcr:primaryType="cq:Component"
sling:resourceSuperType="cq/replication/components/agent"
componentGroup=".hidden"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
cq:actions="[edit]"
cq:dialogMode="floating"
cq:disableTargeting="{Boolean}true"
cq:layout="editbar"
jcr:primaryType="cq:EditConfig">
<cq:formParameters
jcr:primaryType="nt:unstructured"/>
<cq:listeners
jcr:primaryType="cq:EditListenersConfig"
afteredit="REFRESH_PAGE"/>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<%@page session="false"%>
<%@page contentType="text/html"
pageEncoding="utf-8"
import="com.day.cq.replication.Agent,
com.day.cq.replication.AgentConfig,
com.day.cq.replication.AgentManager,
com.adobe.granite.ui.clientlibs.HtmlLibraryManager,
com.day.cq.i18n.I18n" %><%
%><%@include file="/libs/foundation/global.jsp"%><%
I18n i18n = new I18n(slingRequest);
String id = currentPage.getName();
String title = properties.get("jcr:title", id); // user generated content, no i18n
AgentManager agentMgr = sling.getService(AgentManager.class);
Agent agent = agentMgr.getAgents().get(id);
AgentConfig cfg = agent == null ? null : agent.getConfiguration();
if (cfg == null || !cfg.getConfigPath().equals(currentNode.getPath())) {
// agent not active
agent = null;
}
// get icons
String globalIcnCls = "cq-agent-header";
String statusIcnCls = "cq-agent-status";
if (agent == null) {
statusIcnCls += "-inactive";
globalIcnCls += "-off";
} else {
try {
agent.checkValid();
//there seems to be a problem somewhere in the AgentImpl class wherein it returns an erroneous true value if the enabled flag is removed.
//the way the components are currently implemented, if you 'disable' the replication agent, it removes the 'enabled' property from the node.
Boolean isEnabledFlagMissing = (properties.get("enabled", "").equals(""));
if (agent.isEnabled() && !isEnabledFlagMissing) {
globalIcnCls += "-on";
statusIcnCls += "-ok";
} else {
globalIcnCls += "-off";
statusIcnCls += "-disabled";
}
} catch (IllegalArgumentException e) {
globalIcnCls += "-off";
statusIcnCls += "-invalid";
}
}
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title><%= i18n.get("AEM Replication") %> | <%= xssAPI.encodeForHTML(title) %></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
HtmlLibraryManager htmlMgr = sling.getService(HtmlLibraryManager.class);
if (htmlMgr != null) {
htmlMgr.writeIncludes(slingRequest, out, "cq.wcm.edit", "cq.replication");
}
%>
<script src="/libs/cq/ui/resources/cq-ui.js" type="text/javascript"></script>
</head>
<body>
<h2 class="<%= globalIcnCls %>"><%= xssAPI.encodeForHTML(title) %> (<%= xssAPI.encodeForHTML(id) %>)</h2>
<%
String description = properties.get("jcr:description", ""); // user generated content, no i18n
%><p><%= xssAPI.encodeForHTML(description) %></p><%
%><div id="agent-details" class="cq-replication-agent-details"><cq:include path="<%= xssAPI.encodeForHTML(resource.getPath()) + ".details.html" %>" resourceType="<%= xssAPI.encodeForHTML(resource.getResourceType()) %>"/></div>
<div>
<br>
<%
// draw the 'edit' bar explicitly. since we want to be able to edit the
// settings on publish too. we are too late here for setting the WCMMode.
/*
out.flush();
if (editContext != null) {
editContext.getEditConfig().getToolbar().add(0, new Toolbar.Label("Settings"));
editContext.includeEpilog(slingRequest, slingResponse, WCMMode.EDIT);
}
*/
%>
<script type="text/javascript">
CQ.WCM.edit({
"path":"<%= xssAPI.encodeForJSString(resource.getPath()) %>",
"dialog":"/apps/aemdesign/components/replication/akamai/dialog",
"type":"aemdesign/components/replication/akamai",
"editConfig":{
"xtype":"editbar",
"listeners":{
"afteredit":"REFRESH_PAGE"
},
"inlineEditing":CQ.wcm.EditBase.INLINE_MODE_NEVER,
"disableTargeting": true,
"actions":[
{
"xtype":"tbtext",
"text":"Settings"
},
CQ.wcm.EditBase.EDIT
]
}
});
</script>
</div>

<%
if (agent != null) {
%>
<div id="CQ">
<div id="cq-queue">
</div>
</div>

<script type="text/javascript">
function reloadDetails() {
var url = CQ.HTTP.externalize("<%= xssAPI.encodeForJSString(currentPage.getPath()) %>.details.html");
var response = CQ.HTTP.get(url);
if (CQ.HTTP.isOk(response)) {
document.getElementById("agent-details").innerHTML = response.responseText;
}
}
function clearInvalidEntries() {
// this is a hack; removes items that are not publishable from the queue that is displayed here
// TODO: remove this after replication code is translated away from wcm and we have better control over what is displayed here
setInterval(function(){
$(".x-grid3-row tr:contains('/renditions')").remove();
$(".x-grid3-row tr:not(:contains('/content'))").remove();
}, 50);
}
CQ.Ext.onReady(function() {
var queue = new CQ.wcm.ReplicationQueue({
url: "<%= xssAPI.encodeForJSString(currentPage.getPath()) %>/jcr:content.queue.json",
applyTo: "cq-queue",
height: 400
});
queue.on("afterrefresh", function (queue) {
reloadDetails();
});
queue.on("aftercleared", function (queue) {
reloadDetails();
});
queue.on("afterretry", function (queue) {
reloadDetails();
});
queue.loadAgent("<%= xssAPI.encodeForJSString(id) %>");
clearInvalidEntries();
});
function test() {
CQ.shared.Util.open(CQ.HTTP.externalize('<%= xssAPI.encodeForJSString(currentPage.getPath()) %>.test.html'));
}
</script>
<%
} // if (agent != null)
%>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<%@page session="false"%>
<%@page contentType="text/html"
pageEncoding="utf-8"
import="com.day.cq.replication.Agent,
com.day.cq.replication.AgentConfig,
com.day.cq.replication.AgentManager,
com.day.cq.replication.ReplicationQueue,
com.day.cq.i18n.I18n,
org.apache.sling.api.resource.ValueMap,
javax.jcr.Node,
com.adobe.granite.crypto.CryptoSupport" %>
<%@ page import="javax.jcr.RepositoryException" %>
<%@ page import="com.adobe.granite.crypto.CryptoException" %>
<%@ page import="javax.jcr.Session" %>
<%
%><%@include file="/libs/foundation/global.jsp"%><%
String id = currentPage.getName();
I18n i18n = new I18n(slingRequest);
AgentManager agentMgr = sling.getService(AgentManager.class);
Agent agent = agentMgr.getAgents().get(id);
AgentConfig cfg = agent == null ? null : agent.getConfiguration();
ReplicationQueue queue = agent == null ? null : agent.getQueue();
if (cfg == null || !cfg.getConfigPath().equals(currentNode.getPath())) {
// agent not active
agent = null;
}
ValueMap agentValues = resource.adaptTo(ValueMap.class);
Node agentNode = resource.adaptTo(Node.class);
if (agentValues != null) {
String token = agentValues.get("token", "");
String accesstoken = agentValues.get("accesstoken", "");
String secret = agentValues.get("secret", "");
CryptoSupport cryptoSupport = sling.getService(CryptoSupport.class);
try {
if(token.length()!=0 && !cryptoSupport.isProtected(token) ){
log.error("Agent config [{}] has unprotected field {}, attempting to protect.", resource.getPath(), "token");
agentNode.setProperty("token", cryptoSupport.protect(token));
}
if(accesstoken.length()!=0 && !cryptoSupport.isProtected(accesstoken) ){
log.error("Agent config [{}] has unprotected field {}, attempting to protect.", resource.getPath(), "accesstoken");
agentNode.setProperty("accesstoken", cryptoSupport.protect(accesstoken));
}
if(secret.length()!=0 && !cryptoSupport.isProtected(secret) ){
log.error("Agent config [{}] has unprotected field {}, attempting to protect.", resource.getPath(), "secret");
agentNode.setProperty("secret", cryptoSupport.protect(secret));
}
Session resourceSession = resource.getResourceResolver().adaptTo(Session.class);
resourceSession.save();
} catch (RepositoryException | CryptoException e) {
e.printStackTrace();
}
}
String uri = xssAPI.encodeForHTML(properties.get("transportUri", i18n.get("(not configured)")));
String queueStr = i18n.get("Queue is <strong>not active</strong>");
String queueCls = "cq-agent-queue";
if (queue != null) {
int num = queue.entries().size();
if (queue.isPaused()) {
queueStr = i18n.get("Queue is <strong>paused</strong>");
queueCls += "-blocked";
} else if (queue.isBlocked()) {
queueStr = i18n.get("Queue is <strong>blocked - {0} pending</strong>", "{0} is the number of pending items", num);
queueCls += "-blocked";
} else {
if (num == 0) {
queueStr = i18n.get("Queue is <strong>idle</strong>");
queueCls += "-idle";
} else {
queueStr = i18n.get("Queue is <strong>active - {0} pending</strong>", "{0} is the number of pending items", num);
queueCls += "-active";
}
}
} else {
queueCls += "-inactive";
}
// get status
String status;
String message = i18n.get("Replicating to <strong>{0}</strong>", "{0} is an URL", uri);
String globalIcnCls = "cq-agent-header";
String statusIcnCls = "cq-agent-status";
if (agent == null) {
status = "not active";
statusIcnCls += "-inactive";
globalIcnCls += "-off";
} else {
try {
agent.checkValid();
if (agent.isEnabled()) {
status = i18n.get("Agent is <strong>enabled.</strong>");
globalIcnCls += "-on";
statusIcnCls += "-ok";
} else {
status = i18n.get("Agent is <strong>disabled.</strong>");
globalIcnCls += "-off";
statusIcnCls += "-disabled";
}
} catch (IllegalArgumentException e) {
message = e.getMessage();
status = i18n.get("Agent is <strong>not valid.</strong>");
globalIcnCls += "-off";
statusIcnCls += "-invalid";
}
}
%><ul>
<li><div class="li-bullet <%=statusIcnCls%>"><%= status %> <%= message %></div></li>
<li><div class="li-bullet <%=queueCls%>"><%= queueStr %></div></li>
<%
if (cfg != null && cfg.isSpecific()) {
%><li><%= i18n.get("Agent is ignored on normal replication") %></li><%
}
if (cfg != null && cfg.isTriggeredOnModification()) {
%><li><%= i18n.get("Agent is triggered on modification") %></li><%
}
if (cfg != null && cfg.isTriggeredOnOffTime()) {
%><li><%= i18n.get("Agent is triggered when on-/offtime reached") %></li><%
}
if (cfg != null && cfg.isTriggeredOnReceive()) {
%><li><%= i18n.get("Agent is triggered when receiving replication events") %></li><%
}
%>
<li><a href="<%= xssAPI.getValidHref(currentPage.getPath()) %>.log.html#end"><%= i18n.get("View log") %></a></li>
<li><a href="javascript:test()"><%= i18n.get("Test Connection") %></a></li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Dialog"
height="512"
title="Agent Settings">
<items jcr:primaryType="cq:WidgetCollection">
<tabs jcr:primaryType="cq:TabPanel">
<items jcr:primaryType="cq:WidgetCollection">
<tab1
jcr:primaryType="cq:Widget"
path="/apps/aemdesign/components/replication/akamai/tab_agent.infinity.json"
xtype="cqinclude"/>
<tab2
jcr:primaryType="cq:Widget"
path="/apps/aemdesign/components/replication/akamai/tab_config.infinity.json"
xtype="cqinclude"/>
</items>
</tabs>
</items>
</jcr:root>
Loading

0 comments on commit 817ffa1

Please sign in to comment.