Created
March 30, 2018 18:46
-
-
Save petershin/f026808b77ff47dffa6fde62cfd2d5b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright (c) 2000-present Liferay, Inc. All rights reserved. | |
* | |
* This library is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU Lesser General Public License as published by the Free | |
* Software Foundation; either version 2.1 of the License, or (at your option) | |
* any later version. | |
* | |
* This library is distributed in the hope that it will be useful, but WITHOUT | |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
* details. | |
*/ | |
package com.liferay.osb.lcs.admin.web.internal.portlet; | |
import com.liferay.lcs.security.KeyStoreFactory; | |
import com.liferay.osb.lcs.admin.web.internal.advisor.AdminAdvisor; | |
import com.liferay.osb.lcs.admin.web.internal.advisor.LCSMetadataDetailsAdvisor; | |
import com.liferay.osb.lcs.admin.web.internal.constants.AdminWebKeys; | |
import com.liferay.osb.lcs.advisor.CommandMessageAdvisor; | |
import com.liferay.osb.lcs.advisor.PatchAdvisor; | |
import com.liferay.osb.lcs.advisor.PortalInstanceAdvisor; | |
import com.liferay.osb.lcs.configuration.OSBLCSConfiguration; | |
import com.liferay.osb.lcs.configuration.OSBLCSConfigurationProvider; | |
import com.liferay.osb.lcs.constants.OSBLCSPortletKeys; | |
import com.liferay.osb.lcs.model.LCSClusterNode; | |
import com.liferay.osb.lcs.model.LCSMetadata; | |
import com.liferay.osb.lcs.nosql.model.LCSClusterNodeInstallationEnvironment; | |
import com.liferay.osb.lcs.nosql.service.LCSClusterNodeInstallationEnvironmentService; | |
import com.liferay.osb.lcs.nosql.service.LCSClusterNodeScriptService; | |
import com.liferay.osb.lcs.osbportlet.service.OSBPortletService; | |
import com.liferay.osb.lcs.report.Report; | |
import com.liferay.osb.lcs.report.ReportContext; | |
import com.liferay.osb.lcs.report.ReportFactory; | |
import com.liferay.osb.lcs.report.ReportType; | |
import com.liferay.osb.lcs.report.advisor.ReportAdvisor; | |
import com.liferay.osb.lcs.service.LCSClusterEntryLocalService; | |
import com.liferay.osb.lcs.service.LCSClusterNodeLocalService; | |
import com.liferay.osb.lcs.service.LCSClusterNodeService; | |
import com.liferay.osb.lcs.service.LCSMetadataLocalService; | |
import com.liferay.osb.lcs.service.LCSProjectLocalService; | |
import com.liferay.osb.lcs.service.LCSSubscriptionEntryService; | |
import com.liferay.osb.lcs.util.LCSClusterNodeStatus; | |
import com.liferay.osb.lcs.util.Quarter; | |
import com.liferay.petra.string.StringPool; | |
import com.liferay.portal.kernel.dao.orm.QueryUtil; | |
import com.liferay.portal.kernel.log.Log; | |
import com.liferay.portal.kernel.log.LogFactoryUtil; | |
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet; | |
import com.liferay.portal.kernel.servlet.BrowserSnifferUtil; | |
import com.liferay.portal.kernel.servlet.HttpHeaders; | |
import com.liferay.portal.kernel.servlet.SessionErrors; | |
import com.liferay.portal.kernel.servlet.SessionMessages; | |
import com.liferay.portal.kernel.theme.ThemeDisplay; | |
import com.liferay.portal.kernel.upload.UploadPortletRequest; | |
import com.liferay.portal.kernel.util.ArrayUtil; | |
import com.liferay.portal.kernel.util.GetterUtil; | |
import com.liferay.portal.kernel.util.ListUtil; | |
import com.liferay.portal.kernel.util.ParamUtil; | |
import com.liferay.portal.kernel.util.Portal; | |
import com.liferay.portal.kernel.util.StringUtil; | |
import com.liferay.portal.kernel.util.WebKeys; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.util.Date; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.TreeMap; | |
import javax.portlet.ActionRequest; | |
import javax.portlet.ActionResponse; | |
import javax.portlet.Portlet; | |
import javax.portlet.PortletException; | |
import javax.portlet.PortletPreferences; | |
import javax.portlet.RenderRequest; | |
import javax.portlet.RenderResponse; | |
import javax.portlet.ResourceRequest; | |
import javax.portlet.ResourceResponse; | |
import javax.servlet.http.HttpServletRequest; | |
import org.apache.commons.configuration.PropertiesConfiguration; | |
import org.osgi.service.component.annotations.Activate; | |
import org.osgi.service.component.annotations.Component; | |
import org.osgi.service.component.annotations.Deactivate; | |
import org.osgi.service.component.annotations.Reference; | |
/** | |
* @author Igor Beslic | |
* @author Marko Cikos | |
* @author Mateo Mustapic | |
*/ | |
@Component( | |
immediate = true, | |
property = { | |
"com.liferay.portlet.css-class-wrapper=osb-lcs-portlet osb-lcs-portlet-admin", | |
"com.liferay.portlet.display-category=category.hidden", | |
"com.liferay.portlet.footer-portlet-javascript=/js/lcs-admin.js", | |
"com.liferay.portlet.footer-portlet-javascript=/js/lcs-base.js", | |
"com.liferay.portlet.header-portlet-css=/css/main.css", | |
"com.liferay.portlet.preferences-company-wide=true", | |
"javax.portlet.display-name=LCS Admin", | |
"javax.portlet.expiration-cache=0", | |
"javax.portlet.info.keywords=LCS Admin", | |
"javax.portlet.info.short-title=LCS Admin", | |
"javax.portlet.info.title=LCS Admin", | |
"javax.portlet.init-param.template-path=/", | |
"javax.portlet.init-param.view-template=/view.jsp", | |
"javax.portlet.name=" + OSBLCSPortletKeys.ADMIN, | |
"javax.portlet.resource-bundle=content.Language", | |
"javax.portlet.security-role-ref=administrator,guest,power-user,user" | |
}, | |
service = Portlet.class | |
) | |
public class AdminPortlet extends MVCPortlet { | |
public void addLCSMetadata( | |
ActionRequest actionRequest, ActionResponse actionResponse) | |
throws Exception { | |
int buildNumber = ParamUtil.getInteger(actionRequest, "buildNumber"); | |
String gitTag = ParamUtil.getString(actionRequest, "gitTag"); | |
String portalEdition = ParamUtil.getString( | |
actionRequest, "portalEdition"); | |
int supportedLCSPortlet = ParamUtil.getInteger( | |
actionRequest, "supportedLCSPortlet"); | |
int supportedPatchingTool = ParamUtil.getInteger( | |
actionRequest, "supportedPatchingTool"); | |
LCSMetadata lcsMetadata = _lcsMetadataLocalService.addLCSMetadata( | |
buildNumber, gitTag, portalEdition, supportedLCSPortlet, | |
supportedPatchingTool); | |
uploadPortalPropertiesFile( | |
actionRequest, lcsMetadata.getLcsMetadataId()); | |
} | |
public void checkLCSProjects( | |
ActionRequest actionRequest, ActionResponse actionResponse) | |
throws Exception { | |
long[] localCorpProjectIds = | |
_lcsProjectLocalService.getLocalCorpProjectIds(); | |
int invalidRemoteCorpProjectsCount = | |
_osbPortletService.getInvalidRemoteCorpProjectsCount( | |
localCorpProjectIds); | |
if (invalidRemoteCorpProjectsCount == 0) { | |
SessionMessages.add(actionRequest, "synchronized"); | |
} | |
else { | |
SessionErrors.add(actionRequest, "notSynchronized"); | |
} | |
} | |
public void deleteCache( | |
ActionRequest actionRequest, ActionResponse actionResponse) { | |
_adminAdvisor.deleteCache(ParamUtil.getString(actionRequest, "key")); | |
} | |
public void enableLCSClusterNodeLogging( | |
ActionRequest actionRequest, ActionResponse actionResponse) { | |
_adminAdvisor.enableLCSClusterNodeLogging( | |
ParamUtil.getString(actionRequest, "key"), | |
ParamUtil.getBoolean(actionRequest, "enableLogging")); | |
} | |
@Override | |
public void render(RenderRequest request, RenderResponse response) | |
throws IOException, PortletException { | |
request.setAttribute(AdminAdvisor.class.getName(), _adminAdvisor); | |
request.setAttribute( | |
AdminWebKeys.LCS_PLATFORM_VERSION, | |
_osbLCSConfiguration.lcsPlatformVersion()); | |
request.setAttribute( | |
AdminWebKeys.LCS_PORTLET_BUILD_NUMBER_COUNTS, | |
_getLCSPortletBuildNumberStatsTemplateContext()); | |
request.setAttribute( | |
AdminWebKeys.OSB_PORTLET_HOST_NAME, | |
_osbLCSConfiguration.osbPortletHostName()); | |
request.setAttribute( | |
AdminWebKeys.OSB_PORTLET_HOST_PORT, | |
_osbLCSConfiguration.osbPortletHostPort()); | |
request.setAttribute( | |
AdminWebKeys.OSB_PORTLET_LOGIN, | |
_osbLCSConfiguration.osbPortletLogin()); | |
request.setAttribute( | |
AdminWebKeys.OSB_PORTLET_SYNCHRONIZATION_SAFE_HOST_NAMES, | |
_osbLCSConfiguration.osbPortletSynchronizationSafeHostNames()); | |
Date signingKeyExpirationDate = null; | |
try { | |
signingKeyExpirationDate = | |
KeyStoreFactory.getSigningKeyExpirationDate( | |
_osbLCSConfiguration.osbPortletKeyStorePath(), | |
_osbLCSConfiguration.osbPortletKeyStoreType(), | |
_osbLCSConfiguration. | |
osbPortletKeyStoreDigitalSignatureKeyName()); | |
} | |
catch (Exception e) { | |
_log.error(e, e); | |
} | |
request.setAttribute( | |
AdminWebKeys.SIGNING_KEY_EXPIRATION_DATE, signingKeyExpirationDate); | |
request.setAttribute( | |
LCSClusterNodeScriptService.class.getName(), | |
_lcsClusterNodeScriptService); | |
request.setAttribute( | |
OSBLCSConfiguration.class.getName(), _osbLCSConfiguration); | |
super.render(request, response); | |
} | |
public void resetInstallablePatches( | |
ActionRequest actionRequest, ActionResponse actionResponse) | |
throws Exception { | |
_patchAdvisor.resetInstallablePatches(); | |
} | |
public void resetLCSOrderEntries( | |
ActionRequest actionRequest, ActionResponse actionResponse) | |
throws Exception { | |
_lcsSubscriptionEntryService.refreshLCSProjectLCSSubscriptionEntries(); | |
} | |
public void saveLCSPortalPreferences( | |
ActionRequest actionRequest, ActionResponse actionResponse) | |
throws Exception { | |
PortletPreferences portletPreferences = | |
_adminAdvisor.getPortletPreferences(); | |
String billingEnabled = ParamUtil.getString( | |
actionRequest, "billingEnabled"); | |
portletPreferences.setValue("billing-enabled", billingEnabled); | |
_adminAdvisor.enableMessageForward( | |
"dev", | |
ParamUtil.getBoolean(actionRequest, "messageForwardDevEnabled")); | |
_adminAdvisor.enableMessageForward( | |
"qa", | |
ParamUtil.getBoolean(actionRequest, "messageForwardQAEnabled")); | |
String sendingEmailsEnabled = ParamUtil.getString( | |
actionRequest, "sendingEmailsEnabled"); | |
portletPreferences.setValue( | |
"sending-emails-enabled", sendingEmailsEnabled); | |
portletPreferences.store(); | |
} | |
public void sendLCSClusterNodeUptimesQuarterlyReports( | |
ActionRequest actionRequest, ActionResponse actionResponse) { | |
String quarter = ParamUtil.getString(actionRequest, "quarter"); | |
String recipientEmails = ParamUtil.getString( | |
actionRequest, "recipientEmails"); | |
int year = ParamUtil.getInteger(actionRequest, "year"); | |
_reportAdvisor.sendLCSClusterNodeUptimesQuarterlyReports( | |
Quarter.valueOf(quarter), recipientEmails.split(StringPool.COMMA), | |
year); | |
} | |
public void sendScript( | |
ActionRequest actionRequest, ActionResponse actionResponse) | |
throws Exception { | |
String key = actionRequest.getParameter("key"); | |
LCSClusterNode lcsClusterNode = | |
_lcsClusterNodeService.getLCSClusterNode(key); | |
String script = actionRequest.getParameter("script"); | |
_commandMessageAdvisor.executeScript(lcsClusterNode, script); | |
sendRedirect(actionRequest, actionResponse); | |
} | |
@Override | |
public void serveResource( | |
ResourceRequest resourceRequest, ResourceResponse resourceResponse) | |
throws IOException { | |
try { | |
String resourceId = resourceRequest.getResourceID(); | |
if (resourceId.equals("downloadLCSClusterNodesDelimitedReport")) { | |
downloadLCSClusterNodesDelimitedReport( | |
resourceRequest, resourceResponse); | |
} | |
else if (resourceId.equals( | |
"downloadLCSClusterNodeUptimesDelimitedReport")) { | |
downloadLCSClusterNodeUptimesDelimitedReport( | |
resourceRequest, resourceResponse); | |
} | |
else if (resourceId.equals( | |
"downloadLCSClusterNodeUptimesInvoicePDFReport")) { | |
downloadLCSClusterNodeUptimesInvoicePDFReport( | |
resourceRequest, resourceResponse); | |
} | |
else if (resourceId.equals( | |
"downloadLCSClusterNodeUptimesPDFReport")) { | |
downloadLCSClusterNodeUptimesPDFReport( | |
resourceRequest, resourceResponse); | |
} | |
else if (resourceId.equals("getPortalPropertiesDifference")) { | |
getPortalPropertiesDifference( | |
resourceRequest, resourceResponse); | |
} | |
} | |
catch (Exception e) { | |
_log.error("Unable to generate delimited file", e); | |
} | |
} | |
@Reference(unbind = "-") | |
public void setLcsClusterNodeLocalService( | |
LCSClusterNodeLocalService lcsClusterNodeLocalService) { | |
_lcsClusterNodeLocalService = lcsClusterNodeLocalService; | |
} | |
public void updateLCSMetadata( | |
ActionRequest actionRequest, ActionResponse actionResponse) | |
throws Exception { | |
long lcsMetadataId = ParamUtil.getLong(actionRequest, "lcsMetadataId"); | |
int supportedLCSPortlet = ParamUtil.getInteger( | |
actionRequest, "supportedLCSPortlet"); | |
int supportedPatchingTool = ParamUtil.getInteger( | |
actionRequest, "supportedPatchingTool"); | |
_lcsMetadataLocalService.updateSupportedLCSPortlet( | |
lcsMetadataId, supportedLCSPortlet); | |
_lcsMetadataLocalService.updateSupportedPatchingTool( | |
lcsMetadataId, supportedPatchingTool); | |
uploadPortalPropertiesFile(actionRequest, lcsMetadataId); | |
} | |
@Activate | |
protected void activate(Map<String, Object> properties) { | |
_osbLCSConfiguration = | |
_osbLCSConfigurationProvider.getOSBLCSConfiguration(); | |
} | |
@Deactivate | |
protected void deactivate() { | |
_osbLCSConfiguration = null; | |
} | |
protected void downloadLCSClusterNodesDelimitedReport( | |
ResourceRequest resourceRequest, ResourceResponse resourceResponse) | |
throws Exception { | |
Report report = _reportFactory.getReport( | |
ReportType.LCS_CLUSTER_NODES_DELIMITED); | |
ReportContext.ReportContextBuilder reportContextBuilder = | |
new ReportContext.ReportContextBuilder(); | |
reportContextBuilder.lcsClusterNodeObjectArrays( | |
_adminAdvisor.getLCSClusterNodeObjectArrays()); | |
reportContextBuilder.lineSeparator(getLineSeparator(resourceRequest)); | |
ByteArrayOutputStream byteArrayOutputStream = report.process( | |
reportContextBuilder.build()); | |
writeFile( | |
resourceResponse, byteArrayOutputStream, | |
"lcs-cluster-node-report-" + System.currentTimeMillis() + ".csv", | |
"text/csv"); | |
} | |
protected void downloadLCSClusterNodeUptimesDelimitedReport( | |
ResourceRequest resourceRequest, ResourceResponse resourceResponse) | |
throws Exception { | |
Report report = _reportFactory.getReport( | |
ReportType.LCS_CLUSTER_NODE_UPTIMES_DELIMITED); | |
ReportContext.ReportContextBuilder reportContextBuilder = | |
new ReportContext.ReportContextBuilder(); | |
ThemeDisplay themeDisplay = getThemeDisplay(resourceRequest); | |
reportContextBuilder.lcsClusterEntryId( | |
GetterUtil.getLong( | |
resourceRequest.getParameter("lcsClusterEntryId"))); | |
reportContextBuilder.lcsClusterNodeId( | |
GetterUtil.getLong( | |
resourceRequest.getParameter("lcsClusterNodeId"))); | |
reportContextBuilder.lcsProjectId( | |
GetterUtil.getLong(resourceRequest.getParameter("lcsProjectId"))); | |
reportContextBuilder.lineSeparator(getLineSeparator(resourceRequest)); | |
reportContextBuilder.locale(themeDisplay.getLocale()); | |
reportContextBuilder.month( | |
GetterUtil.getInteger(resourceRequest.getParameter("month"))); | |
reportContextBuilder.year( | |
GetterUtil.getInteger(resourceRequest.getParameter("year"))); | |
ByteArrayOutputStream byteArrayOutputStream = report.process( | |
reportContextBuilder.build()); | |
writeFile( | |
resourceResponse, byteArrayOutputStream, | |
"lcs-cluster-node-uptime-report-" + System.currentTimeMillis() + | |
".csv", | |
"text/csv"); | |
} | |
protected void downloadLCSClusterNodeUptimesInvoicePDFReport( | |
ResourceRequest resourceRequest, ResourceResponse resourceResponse) | |
throws Exception { | |
Report report = _reportFactory.getReport( | |
ReportType.LCS_CLUSTER_NODE_UPTIMES_INVOICE_PDF); | |
ReportContext.ReportContextBuilder reportContextBuilder = | |
new ReportContext.ReportContextBuilder(); | |
ThemeDisplay themeDisplay = getThemeDisplay(resourceRequest); | |
reportContextBuilder.lcsClusterEntryId( | |
GetterUtil.getLong( | |
resourceRequest.getParameter("lcsClusterEntryId"))); | |
reportContextBuilder.lcsClusterNodeId( | |
GetterUtil.getLong( | |
resourceRequest.getParameter("lcsClusterNodeId"))); | |
reportContextBuilder.lcsProjectId( | |
GetterUtil.getLong(resourceRequest.getParameter("lcsProjectId"))); | |
reportContextBuilder.locale(themeDisplay.getLocale()); | |
reportContextBuilder.month( | |
GetterUtil.getInteger(resourceRequest.getParameter("month"))); | |
reportContextBuilder.userId(themeDisplay.getUserId()); | |
reportContextBuilder.year( | |
GetterUtil.getInteger(resourceRequest.getParameter("year"))); | |
ByteArrayOutputStream byteArrayOutputStream = report.process( | |
reportContextBuilder.build()); | |
writeFile( | |
resourceResponse, byteArrayOutputStream, | |
"lcs-cluster-node-uptime-invoice-" + System.currentTimeMillis() + | |
".pdf", | |
"application/pdf"); | |
} | |
protected void downloadLCSClusterNodeUptimesPDFReport( | |
ResourceRequest resourceRequest, ResourceResponse resourceResponse) | |
throws Exception { | |
Report report = _reportFactory.getReport( | |
ReportType.LCS_CLUSTER_NODE_UPTIMES_PDF); | |
ReportContext.ReportContextBuilder reportContextBuilder = | |
new ReportContext.ReportContextBuilder(); | |
ThemeDisplay themeDisplay = getThemeDisplay(resourceRequest); | |
reportContextBuilder.lcsProjectId( | |
GetterUtil.getLong(resourceRequest.getParameter("lcsProjectId"))); | |
reportContextBuilder.locale(themeDisplay.getLocale()); | |
reportContextBuilder.month( | |
GetterUtil.getInteger(resourceRequest.getParameter("month"))); | |
reportContextBuilder.year( | |
GetterUtil.getInteger(resourceRequest.getParameter("year"))); | |
ByteArrayOutputStream byteArrayOutputStream = report.process( | |
reportContextBuilder.build()); | |
writeFile( | |
resourceResponse, byteArrayOutputStream, | |
"lcs-cluster-node-uptime-report-" + System.currentTimeMillis() + | |
".pdf", | |
"application/pdf"); | |
} | |
protected String getLineSeparator(ResourceRequest resourceRequest) { | |
HttpServletRequest httpServletRequest = _portal.getHttpServletRequest( | |
resourceRequest); | |
if (BrowserSnifferUtil.isWindows(httpServletRequest)) { | |
return StringPool.RETURN_NEW_LINE; | |
} | |
else { | |
return StringPool.NEW_LINE; | |
} | |
} | |
protected void getPortalPropertiesDifference( | |
ResourceRequest resourceRequest, ResourceResponse resourceResponse) | |
throws Exception { | |
String key = ParamUtil.getString(resourceRequest, "key"); | |
writeJSON( | |
resourceRequest, resourceResponse, | |
_portalInstanceAdvisor.getPortalPropertiesDifferenceJSONObject( | |
key)); | |
} | |
protected ThemeDisplay getThemeDisplay(ResourceRequest resourceRequest) { | |
return (ThemeDisplay)resourceRequest.getAttribute( | |
WebKeys.THEME_DISPLAY); | |
} | |
protected void uploadPortalPropertiesFile( | |
ActionRequest actionRequest, long lcsMetadataId) { | |
InputStream inputStream = null; | |
try { | |
UploadPortletRequest uploadPortletRequest = | |
_portal.getUploadPortletRequest(actionRequest); | |
inputStream = uploadPortletRequest.getFileAsStream( | |
"portalPropertiesFile"); | |
if (inputStream == null) { | |
return; | |
} | |
PropertiesConfiguration propertiesConfiguration = | |
new PropertiesConfiguration(); | |
propertiesConfiguration.load(inputStream); | |
Map<String, String> portalProperties = new HashMap<>(); | |
Iterator<String> iterator = propertiesConfiguration.getKeys(); | |
while (iterator.hasNext()) { | |
String key = iterator.next(); | |
Object property = propertiesConfiguration.getProperty(key); | |
if (property instanceof List) { | |
char delimiter = propertiesConfiguration.getListDelimiter(); | |
String value = StringUtil.merge( | |
(List<?>)property, Character.toString(delimiter)); | |
portalProperties.put(key, value); | |
} | |
else { | |
portalProperties.put(key, (String)property); | |
} | |
} | |
if (!portalProperties.isEmpty()) { | |
_lcsMetadataDetailsAdvisor. | |
updateLCSMetadataDetailsPortletProperties( | |
lcsMetadataId, portalProperties); | |
} | |
} | |
catch (Exception e) { | |
_log.error("Unable to upload properties file", e); | |
} | |
finally { | |
try { | |
if (inputStream != null) { | |
inputStream.close(); | |
} | |
} | |
catch (Exception e) { | |
_log.error(e, e); | |
} | |
} | |
} | |
protected void writeFile( | |
ResourceResponse resourceResponse, | |
ByteArrayOutputStream byteArrayOutputStream, String fileName, | |
String contentType) | |
throws Exception { | |
resourceResponse.addProperty( | |
HttpHeaders.CONTENT_DISPOSITION, | |
HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT + "; filename=" + | |
fileName); | |
resourceResponse.setContentLength(byteArrayOutputStream.size()); | |
resourceResponse.setContentType(contentType); | |
OutputStream outputStream = resourceResponse.getPortletOutputStream(); | |
byteArrayOutputStream.writeTo(outputStream); | |
outputStream.flush(); | |
outputStream.close(); | |
} | |
private int _getLCSPortletBuildNumber(LCSClusterNode lcsClusterNode) { | |
LCSClusterNodeInstallationEnvironment | |
lcsClusterNodeInstallationEnvironment = | |
_lcsClusterNodeInstallationEnvironmentService. | |
fetchLCSClusterNodeInstallationEnvironment( | |
lcsClusterNode.getKey()); | |
if (lcsClusterNodeInstallationEnvironment == null) { | |
return 0; | |
} | |
Map<String, String> softwareMetadata = | |
lcsClusterNodeInstallationEnvironment.getSoftwareMetadata(); | |
if (!softwareMetadata.containsKey("lcs.portlet.build.number")) { | |
return 0; | |
} | |
return Integer.parseInt( | |
softwareMetadata.get("lcs.portlet.build.number")); | |
} | |
private List<Map<String, Object>> | |
_getLCSPortletBuildNumberStatsTemplateContext() { | |
LCSClusterNodeStatus lcsClusterNodeStatus = LCSClusterNodeStatus.ACTIVE; | |
List<LCSClusterNode> lcsClusterNodes = | |
_lcsClusterNodeLocalService.getLCSClusterNodes( | |
lcsClusterNodeStatus.getStatus(), QueryUtil.ALL_POS, | |
QueryUtil.ALL_POS); | |
int lcsClusterNodesCount = lcsClusterNodes.size(); | |
Map<Integer, Map<String, Object>> | |
lcsPortletBuildNumberStatsTemplateContextMap = new TreeMap<>(); | |
for (LCSClusterNode lcsClusterNode : lcsClusterNodes) { | |
int lcsPortletBuildNumber = _getLCSPortletBuildNumber( | |
lcsClusterNode); | |
Map<String, Object> lcsPortletBuildNumberStats = | |
lcsPortletBuildNumberStatsTemplateContextMap.get( | |
lcsPortletBuildNumber); | |
Integer count = 0; | |
String[] keys = new String[0]; | |
if (lcsPortletBuildNumberStats != null) { | |
count = (Integer)lcsPortletBuildNumberStats.get("count"); | |
keys = StringUtil.split( | |
(String)lcsPortletBuildNumberStats.get("keys"), ", "); | |
} | |
count = count + 1; | |
keys = ArrayUtil.append(keys, lcsClusterNode.getKey()); | |
Double percentage = ((double)count / lcsClusterNodesCount) * 100; | |
lcsPortletBuildNumberStats.put( | |
"buildNumber", lcsPortletBuildNumber); | |
lcsPortletBuildNumberStats.put("count", count); | |
lcsPortletBuildNumberStats.put( | |
"keys", StringUtil.merge(keys, ", ")); | |
lcsPortletBuildNumberStats.put( | |
"percentage", String.format("%.1f%%", percentage)); | |
lcsPortletBuildNumberStatsTemplateContextMap.put( | |
lcsPortletBuildNumber, lcsPortletBuildNumberStats); | |
} | |
return ListUtil.fromCollection( | |
lcsPortletBuildNumberStatsTemplateContextMap.values()); | |
} | |
private static final Log _log = LogFactoryUtil.getLog(AdminPortlet.class); | |
@Reference(unbind = "-") | |
private AdminAdvisor _adminAdvisor; | |
@Reference(unbind = "-") | |
private CommandMessageAdvisor _commandMessageAdvisor; | |
@Reference(unbind = "-") | |
private LCSClusterEntryLocalService _lcsClusterEntryLocalService; | |
@Reference(unbind = "-") | |
private LCSClusterNodeInstallationEnvironmentService | |
_lcsClusterNodeInstallationEnvironmentService; | |
@Reference(unbind = "-") | |
private LCSClusterNodeLocalService _lcsClusterNodeLocalService; | |
@Reference(unbind = "-") | |
private LCSClusterNodeScriptService _lcsClusterNodeScriptService; | |
@Reference(unbind = "-") | |
private LCSClusterNodeService _lcsClusterNodeService; | |
@Reference(unbind = "-") | |
private LCSMetadataDetailsAdvisor _lcsMetadataDetailsAdvisor; | |
@Reference(unbind = "-") | |
private LCSMetadataLocalService _lcsMetadataLocalService; | |
@Reference(unbind = "-") | |
private LCSProjectLocalService _lcsProjectLocalService; | |
@Reference(unbind = "-") | |
private LCSSubscriptionEntryService _lcsSubscriptionEntryService; | |
private volatile OSBLCSConfiguration _osbLCSConfiguration; | |
@Reference(unbind = "-") | |
private OSBLCSConfigurationProvider _osbLCSConfigurationProvider; | |
@Reference(unbind = "-") | |
private OSBPortletService _osbPortletService; | |
@Reference(unbind = "-") | |
private PatchAdvisor _patchAdvisor; | |
@Reference(unbind = "-") | |
private Portal _portal; | |
@Reference(unbind = "-") | |
private PortalInstanceAdvisor _portalInstanceAdvisor; | |
@Reference(unbind = "-") | |
private ReportAdvisor _reportAdvisor; | |
@Reference(unbind = "-") | |
private ReportFactory _reportFactory; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment