diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 53daf4e..7da746a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,58 +1,59 @@
name: CI
on:
push:
- branches:
- - master
- tags:
- - v*
- pull_request:
+ workflow_dispatch:
env:
- GRADLE_OPTS: "-Dorg.gradle.project.org.alfresco.artifacts.username=${{ secrets.ALFRESCO_NEXUS_USERNAME }} -Dorg.gradle.project.org.alfresco.artifacts.password=${{ secrets.ALFRESCO_NEXUS_PASSWORD }}"
+ GRADLE_OPTS: >-
+ -Dorg.gradle.project.org.alfresco.maven.nexus.username=${{ secrets.ALFRESCO_NEXUS_USERNAME }}
+ -Dorg.gradle.project.org.alfresco.maven.nexus.password=${{ secrets.ALFRESCO_NEXUS_PASSWORD }}
jobs:
test:
runs-on: ubuntu-latest
strategy:
+ fail-fast: false
matrix:
flavour: [ "community", "enterprise" ]
version: [ "61", "62", "70", "71", "72", "73" ]
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
+ - name: Set up JDK 11
+ uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3
with:
- fetch-depth: 0
- - uses: actions/setup-java@v1
+ distribution: 'temurin'
+ java-version: '11'
+ - name: Login to Docker
+ run: echo "${{ secrets.CLOUDSMITH_APIKEY }}" | docker login private.docker.xenit.eu --username "${{ secrets.CLOUDSMITH_USER }}" --password-stdin
+ - name: Integration Test
+ uses: gradle/gradle-build-action@v2
with:
- java-version: 11
- - name: Login to CloudSmith docker registry
- env:
- DOCKER_USER: ${{ secrets.CLOUDSMITH_USER }}
- DOCKER_PASSWORD: ${{ secrets.CLOUDSMITH_APIKEY }}
- run: echo "$DOCKER_PASSWORD" | docker login docker.xenit.eu --username "$DOCKER_USER" --password-stdin
- - name: Integration test
- run: ./gradlew :integration-tests:alfresco-${{ matrix.flavour }}-${{ matrix.version }}:integrationTest --parallel
- - name: 'Upload Artifact'
+ cache-read-only: false
+ arguments: :integration-tests:alfresco-${{ matrix.flavour }}-${{ matrix.version }}:integrationTest --parallel
+ - name: 'Upload Test Reports'
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: test-result-${{ matrix.flavour }}-${{ matrix.version }}
- path: /home/runner/work/**/build/reports
- retention-days: 2
+ path: /home/runner/**/build/reports
+ retention-days: 14
publish:
needs: [ test ]
runs-on: ubuntu-latest
- if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/') }}
+ if: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- - uses: actions/checkout@v2
- with:
- fetch-depth: 0
- - uses: actions/setup-java@v1
+ - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
+ - name: Set up JDK 11
+ uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3
with:
- java-version: 11
+ distribution: 'temurin'
+ java-version: '11'
+ - name: Add TAG_VERSION env property
+ run: echo "TAG_VERSION=`echo ${GITHUB_REF#refs/tags/}`" >> $GITHUB_ENV
- name: Publish
env:
- ORG_GRADLE_PROJECT_publish_username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
- ORG_GRADLE_PROJECT_publish_password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
- SIGNING_PRIVATE_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_KEY }}
- SIGNING_PASSWORD: ${{ secrets.MAVEN_CENTRAL_GPG_PASSWORD }}
+ ORG_GRADLE_PROJECT_sonatype_username: ${{ secrets.SONATYPE_S01_USERNAME }}
+ ORG_GRADLE_PROJECT_sonatype_password: ${{ secrets.SONATYPE_S01_PASSWORD }}
+ ORG_GRADLE_PROJECT_signingKey: ${{ secrets.MAVEN_CENTRAL_GPG_KEY }}
+ ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.MAVEN_CENTRAL_GPG_PASSWORD }}
run: ./gradlew publish --info
diff --git a/README.md b/README.md
index 73b37af..7c80862 100644
--- a/README.md
+++ b/README.md
@@ -4,38 +4,59 @@ Health endpoint, unauthenticated, to be used as docker and load balancer health
The webscript is available at:
+```
alfresco/s/xenit/actuators/health
+ alfresco/s/xenit/actuators/health/details
+```
+
+with both having request parameter disabled with values :
+
+* `SystemInfoService`
+* `AlfrescoInfoService`
+* `ContentInfoService`
+* `LicenseInfoService`
+* `StatusInfoService`
+
+example:
+
+* `alfresco/s/xenit/actuators/health?disabled=SystemInfoService,LicenseInfoService`
+* `alfresco/s/xenit/actuators/health/details?disabled=SystemInfoService`
## Usage
Status code is to be used for the health check.
-The output of the check is:
+The output of the health check is:
```
+
{"status":"UP"}
+
```
or
```
-{"status":"DOWN"}
+
+{"status":"DOWN" , "message":"error message"}
+
```
Currently the check looks at:
* system
- * os
- * java
- * cpu
+ * os
+ * java
+ * cpu
* alfresco
- * id
- * version
- * edition
- * license
- * warManifest
- * modules
- * status
+ * id
+ * version
+ * edition
+ * license
+ * warManifest
+ * modules
+ * status
+ * content store
# Development
@@ -46,5 +67,7 @@ See [TODO.md](TODO.md)
## How to run integration tests
```
+
./gradlew integrationTest
+
```
diff --git a/alfresco-actuators/build.gradle b/alfresco-actuators/build.gradle
index 8b7b3d0..65e501a 100644
--- a/alfresco-actuators/build.gradle
+++ b/alfresco-actuators/build.gradle
@@ -2,7 +2,6 @@ plugins {
id 'java'
id 'maven-publish'
id 'eu.xenit.amp'
- id 'org.hidetake.swagger.generator' version '2.19.2'
id "com.github.johnrengelman.shadow" version "7.1.2"
}
@@ -10,13 +9,10 @@ description = "Xenit webscripts to retrieve health of the application"
// compile against alfresco 5.2
ext {
- alfrescoVersion = '5.2.7'
+ alfrescoVersion = '6.1.1.11'
servletApiVersion = '2.5'
}
-tasks.withType(JavaCompile) {
- options.encoding = 'UTF-8'
-}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -25,57 +21,19 @@ java {
}
dependencies {
- alfrescoProvided("org.alfresco:alfresco-repository:$alfrescoVersion")
- alfrescoProvided("org.alfresco:alfresco-enterprise-repository:$alfrescoVersion")
- alfrescoProvided("javax.servlet:servlet-api:$servletApiVersion")
+ alfrescoProvided platform("org.alfresco:acs-packaging:${alfrescoVersion}")
+ alfrescoProvided("org.alfresco:alfresco-repository")
+ alfrescoProvided("org.alfresco:alfresco-enterprise-repository")
- // Add dependency for Swagger Codegen CLI
- swaggerCodegen 'io.swagger:swagger-codegen-cli:2.2.3'
+ alfrescoProvided("javax.servlet:servlet-api:$servletApiVersion")
compileOnly 'io.swagger:swagger-annotations:1.5.6'
compileOnly 'javax.validation:validation-api:1.1.0.Final'
compileOnly 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
}
-swaggerSources {
-
- model {
- inputFile = file("src/main/resources/swagger.yaml")
- code {
- language = 'spring'
- additionalProperties = [
- "modelPackage" : "eu.xenit.actuators.model.gen",
- "serializableModel": "true"
- ]
- // Only generate model:
- components = ['models']
- }
- }
-
-}
-
-processResources {
- filesMatching("**/module.properties") {
- expand project.properties
- }
-}
-
-sourceSets {
- main {
- java {
- srcDirs = ["src/main/java", "$generateSwaggerCodeModel.outputDir/src/main/java"]
- }
- resources {
- srcDirs = ['src/main/resources']
- }
- amp {
- module("src/main/resources/alfresco/module/alfresco-actuators/module.properties")
- }
- }
-}
-
+apply from: "${rootProject.projectDir}/swaggerCodeGen.gradle"
-compileJava.dependsOn generateSwaggerCodeModel
publishing {
publications {
diff --git a/alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/alfresco-global.properties b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/alfresco-global.properties
similarity index 100%
rename from alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/alfresco-global.properties
rename to alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/alfresco-global.properties
diff --git a/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/bootstrap/AlfrescoActuatorsACP.acp b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/bootstrap/AlfrescoActuatorsACP.acp
new file mode 100644
index 0000000..76fc722
Binary files /dev/null and b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/bootstrap/AlfrescoActuatorsACP.acp differ
diff --git a/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/bootstrap/bootstrap.xml b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/bootstrap/bootstrap.xml
new file mode 100644
index 0000000..7998d4d
--- /dev/null
+++ b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/bootstrap/bootstrap.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+ eu.xenit.alfresco-actuators.alfresco-actuators.filesLoader
+
+
+
+ 0
+
+
+ ${version.schema}
+
+
+ 99999
+
+
+
+
+ UPDATE_EXISTING
+ /${spaces.company_home.childname}/${spaces.dictionary.childname}
+ alfresco/module/alfresco-actuators/bootstrap/AlfrescoActuatorsACP.acp
+
+
+
+
diff --git a/alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/context/services-context.xml b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/context/services-context.xml
similarity index 66%
rename from alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/context/services-context.xml
rename to alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/context/services-context.xml
index a361644..0f92791 100644
--- a/alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/context/services-context.xml
+++ b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/context/services-context.xml
@@ -9,12 +9,14 @@
-
+
+
+ class="eu.xenit.actuators.services.LicenseInfoService">
+ class="eu.xenit.actuators.services.StatusInfoService">
\ No newline at end of file
diff --git a/alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/context/webscripts-context.xml b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/context/webscripts-context.xml
similarity index 72%
rename from alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/context/webscripts-context.xml
rename to alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/context/webscripts-context.xml
index 185cd0a..48e2992 100644
--- a/alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/context/webscripts-context.xml
+++ b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/context/webscripts-context.xml
@@ -4,9 +4,9 @@
+ parent="webscript"/>
+ class="eu.xenit.actuators.webscripts.classical.HealthDetailsWebScript"
+ parent="webscript"/>
\ No newline at end of file
diff --git a/alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/log4j.properties b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/log4j.properties
similarity index 100%
rename from alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/log4j.properties
rename to alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/log4j.properties
diff --git a/alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/module-context.xml b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/module-context.xml
similarity index 72%
rename from alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/module-context.xml
rename to alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/module-context.xml
index d79f960..72c1ae2 100644
--- a/alfresco-actuators/src/main/resources/alfresco/module/alfresco-actuators/module-context.xml
+++ b/alfresco-actuators/src/main/amp/config/alfresco/module/alfresco-actuators/module-context.xml
@@ -2,4 +2,5 @@
+
diff --git a/alfresco-actuators/src/main/resources/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/health.get.desc.xml b/alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/health.get.desc.xml
similarity index 100%
rename from alfresco-actuators/src/main/resources/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/health.get.desc.xml
rename to alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/health.get.desc.xml
diff --git a/alfresco-actuators/src/main/resources/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.json.ftl b/alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/health.get.json.ftl
similarity index 100%
rename from alfresco-actuators/src/main/resources/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.json.ftl
rename to alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/health.get.json.ftl
diff --git a/alfresco-actuators/src/main/resources/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.desc.xml b/alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.desc.xml
similarity index 100%
rename from alfresco-actuators/src/main/resources/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.desc.xml
rename to alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.desc.xml
diff --git a/alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.json.ftl b/alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.json.ftl
new file mode 100644
index 0000000..7227312
--- /dev/null
+++ b/alfresco-actuators/src/main/amp/config/alfresco/templates/webscripts/eu/xenit/actuators/webscripts/healthdetails.get.json.ftl
@@ -0,0 +1 @@
+${json}
\ No newline at end of file
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/Health.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/Health.java
deleted file mode 100644
index 477f019..0000000
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/Health.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package eu.xenit.actuators;
-
-public class Health {
-
- private HealthStatus status;
- private Object details;
-
- public Object getDetails() {
- return details;
- }
-
- public void setDetails(Object details) {
- this.details = details;
- }
-
-
- public HealthStatus getStatus() {
- return status;
- }
-
- public void setStatus(HealthStatus status) {
- this.status = status;
- }
-
-}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthDetailsError.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthDetailsError.java
deleted file mode 100644
index d668f13..0000000
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthDetailsError.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package eu.xenit.actuators;
-
-public class HealthDetailsError {
-
- private final String error;
-
- public HealthDetailsError(String error) {
- this.error = error;
- }
-
- public String getError() {
- return this.error;
- }
-
-}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthIndicator.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthIndicator.java
index 76167cd..94a7e6b 100644
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthIndicator.java
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthIndicator.java
@@ -1,5 +1,22 @@
package eu.xenit.actuators;
-public interface HealthIndicator {
- Health isHealthy();
+import eu.xenit.actuators.model.gen.HealthInfo;
+import eu.xenit.actuators.model.gen.StatusEnum;
+
+
+public abstract class HealthIndicator {
+ public HealthInfo isHealthy() {
+ HealthInfo health = new HealthInfo();
+ health.setName(this.getClass().getSimpleName());
+ try {
+ health.setDetails(getHealthDetails());
+ health.setStatus(StatusEnum.UP);
+ } catch (Exception exception) {
+ health.setStatus(StatusEnum.DOWN);
+ health.setError(exception.getMessage());
+ }
+ return health;
+ }
+
+ protected abstract Object getHealthDetails() throws Exception;
}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthStatus.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthStatus.java
deleted file mode 100644
index 194746e..0000000
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/HealthStatus.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package eu.xenit.actuators;
-
-public enum HealthStatus {
- UP,
- DOWN
-}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/AlfrescoInfoService.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/AlfrescoInfoService.java
index 6b70385..1eba600 100644
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/AlfrescoInfoService.java
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/AlfrescoInfoService.java
@@ -1,19 +1,8 @@
package eu.xenit.actuators.services;
-import eu.xenit.actuators.Health;
-import eu.xenit.actuators.HealthDetailsError;
import eu.xenit.actuators.HealthIndicator;
-import eu.xenit.actuators.HealthStatus;
import eu.xenit.actuators.model.gen.AlfrescoInfo;
import eu.xenit.actuators.model.gen.ModuleInfo;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.stream.Collectors;
-
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.service.cmr.module.ModuleService;
import org.alfresco.service.descriptor.Descriptor;
@@ -24,9 +13,17 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
@Service
-public class AlfrescoInfoService implements HealthIndicator {
+public class AlfrescoInfoService extends HealthIndicator {
private static final Logger logger = LoggerFactory.getLogger(AlfrescoInfoService.class);
@@ -39,7 +36,8 @@ public class AlfrescoInfoService implements HealthIndicator {
@Qualifier("global-properties")
private Properties globalProperties;
- AlfrescoInfo getAlfrescoInfo() {
+ @Override
+ protected AlfrescoInfo getHealthDetails() {
ManifestInfo manifestInfo = ManifestInfo.getInstance();
Descriptor serverDescriptor = descriptorService.getServerDescriptor();
@@ -58,20 +56,6 @@ AlfrescoInfo getAlfrescoInfo() {
}
- String getVersion() {
- Descriptor serverDescriptor = descriptorService.getServerDescriptor();
- return serverDescriptor.getVersion();
- }
-
- String getEdition() {
- Descriptor serverDescriptor = descriptorService.getServerDescriptor();
- return serverDescriptor.getEdition();
- }
-
- Map getManifestProperties() {
- return ManifestInfo.getInstance().getManifestProperties();
- }
-
private Map retrieveFilteredProperties() {
final String PROP_FILTERED_PREFIX = "prefix.properties.filtered";
@@ -107,16 +91,4 @@ private static ModuleInfo toAlfrescoModule(ModuleDetails moduleDetails) {
.version(moduleDetails.getProperties().getProperty(ModuleDetails.PROP_VERSION));
}
- @Override
- public Health isHealthy() {
- Health health = new Health();
- try {
- health.setDetails(getAlfrescoInfo());
- health.setStatus(HealthStatus.UP);
- } catch (Exception exception) {
- health.setStatus(HealthStatus.DOWN);
- health.setDetails(new HealthDetailsError(exception.getMessage()));
- }
- return health;
- }
}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/ContentInfoService.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/ContentInfoService.java
new file mode 100644
index 0000000..4cf579e
--- /dev/null
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/ContentInfoService.java
@@ -0,0 +1,43 @@
+package eu.xenit.actuators.services;
+
+import eu.xenit.actuators.HealthIndicator;
+import eu.xenit.actuators.model.gen.ContentStoreInfo;
+import org.alfresco.model.ContentModel;
+import org.alfresco.service.cmr.repository.ContentData;
+import org.alfresco.service.cmr.repository.ContentReader;
+import org.alfresco.service.cmr.repository.ContentService;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.NodeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+
+@Service
+public class ContentInfoService extends HealthIndicator {
+
+ @Autowired
+ private NodeService nodeService;
+ @Autowired
+ private ContentService contentService;
+
+ @Override
+ protected ContentStoreInfo getHealthDetails() throws IOException {
+ long start = System.currentTimeMillis();
+ //it is fixed node ref for a file uploaded using acp
+ //under path /app:company_home/app:dictionary/cm:Alfresco_x0020_Actuators/cm:alfresco-actuators.txt
+ NodeRef node = new NodeRef("workspace://SpacesStore/b9da637d-c86b-4ecc-b676-ea1cd60e61b0");
+ AccessContentForNode(node);
+ return new ContentStoreInfo().accessTime(System.currentTimeMillis() - start);
+ }
+
+ private boolean AccessContentForNode(NodeRef node) throws IOException {
+ final ContentData contentData = (ContentData) nodeService.getProperty(node, ContentModel.PROP_CONTENT);
+ ContentReader contentReader = contentService.getRawReader(contentData.getContentUrl());
+ try (InputStream ignored = contentReader.getContentInputStream()) {
+ return true;
+ }
+ }
+}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/LicenseInfoService.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/LicenseInfoService.java
index 63deb22..445e4f4 100644
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/LicenseInfoService.java
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/LicenseInfoService.java
@@ -1,24 +1,17 @@
package eu.xenit.actuators.services;
-import eu.xenit.actuators.Health;
-import eu.xenit.actuators.HealthDetailsError;
import eu.xenit.actuators.HealthIndicator;
-import eu.xenit.actuators.HealthStatus;
import eu.xenit.actuators.model.gen.LicenseInfo;
import org.alfresco.service.descriptor.DescriptorService;
import org.alfresco.service.license.LicenseDescriptor;
import org.alfresco.service.license.LicenseService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
@Service
-public class LicenseInfoService implements HealthIndicator {
-
- private static final Logger logger = LoggerFactory.getLogger(LicenseInfoService.class);
+public class LicenseInfoService extends HealthIndicator {
@Autowired(required = false)
private LicenseService licenseService;
@@ -28,7 +21,18 @@ public class LicenseInfoService implements HealthIndicator {
@Qualifier("DescriptorService")
private DescriptorService descriptorService;
- public LicenseInfo retrieveLicenseInfo() {
+ @Override
+ protected Object getHealthDetails() {
+ LicenseInfo licenseInfo = retrieveLicenseInfo();
+ //community
+ if (licenseInfo != null) {
+ return licenseInfo;
+ } else {
+ return "No license required for community";
+ }
+ }
+
+ private LicenseInfo retrieveLicenseInfo() {
if (licenseService == null) {
licenseService = appContext.getBeansOfType(LicenseService.class).get("licenseService");
}
@@ -50,23 +54,5 @@ public LicenseInfo retrieveLicenseInfo() {
.heartbeatDisabled(licenseDescriptor.isHeartBeatDisabled());
}
- @Override
- public Health isHealthy() {
- Health health = new Health();
- try {
- LicenseInfo licenseInfo = retrieveLicenseInfo();
- //community
- if (licenseInfo != null) {
- health.setDetails(licenseInfo);
- } else {
- health.setDetails(new HealthDetailsError("No license required for community"));
- }
- health.setStatus(HealthStatus.UP);
- } catch (Exception exception) {
- logger.error("Problem retrieving license info",exception);
- health.setStatus(HealthStatus.DOWN);
- health.setDetails(new HealthDetailsError(exception.getMessage()));
- }
- return health;
- }
+
}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/StatusInfoService.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/StatusInfoService.java
index b7b6ea4..7644e43 100644
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/StatusInfoService.java
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/StatusInfoService.java
@@ -1,26 +1,18 @@
package eu.xenit.actuators.services;
-import eu.xenit.actuators.Health;
-import eu.xenit.actuators.HealthDetailsError;
import eu.xenit.actuators.HealthIndicator;
-import eu.xenit.actuators.HealthStatus;
import eu.xenit.actuators.model.gen.StatusInfo;
-import java.util.Properties;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.admin.RepoAdminService;
import org.alfresco.service.cmr.audit.AuditService;
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service
-public class StatusInfoService implements HealthIndicator {
+public class StatusInfoService extends HealthIndicator {
- private static final Logger logger = LoggerFactory.getLogger(StatusInfoService.class);
@Autowired
private RepoAdminService repoAdminService;
@@ -30,12 +22,11 @@ public class StatusInfoService implements HealthIndicator {
private ThumbnailService thumbnailService;
@Autowired
private RetryingTransactionHelper retryingTransactionHelper;
- @Autowired
- @Qualifier("global-properties")
- private Properties globalProperties;
+
// needs authentication
- protected StatusInfo retrieveStatusInfo() {
+ @Override
+ protected StatusInfo getHealthDetails() {
final StatusInfo statusInfo = new StatusInfo();
retryingTransactionHelper.doInTransaction(() -> {
AuthenticationUtil.runAs(() -> {
@@ -50,18 +41,4 @@ protected StatusInfo retrieveStatusInfo() {
return statusInfo;
}
- @Override
- public Health isHealthy() {
- Health health = new Health();
- try {
- StatusInfo statusInfo = retrieveStatusInfo();
- health.setDetails(statusInfo);
- health.setStatus(HealthStatus.UP);
- } catch (Exception exception) {
- logger.error("Problem retrieving Status info", exception);
- health.setStatus(HealthStatus.DOWN);
- health.setDetails(new HealthDetailsError(exception.getMessage()));
- }
- return health;
- }
}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/SystemInfoService.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/SystemInfoService.java
index 4f5d8f8..44248fb 100644
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/services/SystemInfoService.java
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/services/SystemInfoService.java
@@ -1,13 +1,12 @@
package eu.xenit.actuators.services;
-import eu.xenit.actuators.Health;
-import eu.xenit.actuators.HealthDetailsError;
import eu.xenit.actuators.HealthIndicator;
-import eu.xenit.actuators.HealthStatus;
import eu.xenit.actuators.model.gen.CpuInfo;
import eu.xenit.actuators.model.gen.JavaInfo;
import eu.xenit.actuators.model.gen.OperatingSystemInfo;
import eu.xenit.actuators.model.gen.SystemInfo;
+import org.springframework.stereotype.Service;
+
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
@@ -16,17 +15,14 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
@Service
-public class SystemInfoService implements HealthIndicator {
+public class SystemInfoService extends HealthIndicator {
- private static final Logger logger = LoggerFactory.getLogger(SystemInfoService.class);
- private SystemInfo getSystemInfo() {
+ @Override
+ protected SystemInfo getHealthDetails() {
return new SystemInfo()
.os(osInfo())
.java(javaInfo())
@@ -34,9 +30,8 @@ private SystemInfo getSystemInfo() {
}
- private static OperatingSystemInfo osInfo() {
+ private OperatingSystemInfo osInfo() {
OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
-
return new OperatingSystemInfo()
.name(osMXBean.getName())
.version(osMXBean.getVersion())
@@ -44,7 +39,7 @@ private static OperatingSystemInfo osInfo() {
}
- private static JavaInfo javaInfo() {
+ private JavaInfo javaInfo() {
List gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
@@ -69,24 +64,10 @@ private static JavaInfo javaInfo() {
.systemProperties(javaProperties);
}
- private static CpuInfo cpuInfo() {
+ private CpuInfo cpuInfo() {
OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
return new CpuInfo()
.processors(osMXBean.getAvailableProcessors());
}
- @Override
- public Health isHealthy() {
- Health health = new Health();
- try {
- SystemInfo systemInfo = getSystemInfo();
- health.setStatus(HealthStatus.UP);
- health.setDetails(systemInfo);
- } catch (Exception e) {
- logger.error("Problem retrieving system info", e);
- health.setStatus(HealthStatus.DOWN);
- health.setDetails(new HealthDetailsError(e.getMessage()));
- }
- return health;
- }
}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/AbstractHealthWebScript.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/AbstractHealthWebScript.java
new file mode 100644
index 0000000..9a25857
--- /dev/null
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/AbstractHealthWebScript.java
@@ -0,0 +1,65 @@
+package eu.xenit.actuators.webscripts.classical;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import eu.xenit.actuators.HealthIndicator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.extensions.webscripts.Cache;
+import org.springframework.extensions.webscripts.DeclarativeWebScript;
+import org.springframework.extensions.webscripts.Status;
+import org.springframework.extensions.webscripts.WebScriptRequest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public abstract class AbstractHealthWebScript extends DeclarativeWebScript implements ManifestSettingWebScript {
+ private static final Logger logger = LoggerFactory.getLogger(AbstractHealthWebScript.class);
+
+ @Autowired
+ protected ApplicationContext applicationContext;
+ protected final ObjectMapper objectMapper = new ObjectMapper();
+
+ AbstractHealthWebScript() {
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ }
+
+ protected Map getHealthIndicators() {
+ return applicationContext.getBeansOfType(HealthIndicator.class);
+ }
+
+ protected Map fillModel(Status status, Object object) {
+ final Map model = new HashMap<>();
+ try {
+ model.put("json", objectMapper.writeValueAsString(object));
+ } catch (JsonProcessingException e) {
+ String message = "Exception writing health to json";
+ logger.error(message, e);
+ status.setCode(Status.STATUS_INTERNAL_SERVER_ERROR, "Exception writing health to json");
+ }
+ return model;
+ }
+
+ @Override
+ protected Map executeImpl(WebScriptRequest request, Status status, Cache cache) {
+ setManifestProperties(request);
+ Map indicators = getHealthIndicators();
+ String disableParam = request.getParameter("disabled");
+ if (disableParam != null && !disableParam.isEmpty()) {
+ for (String indicatorName : disableParam.split(",")) {
+ if (indicators.containsKey(indicatorName)) {
+ logger.debug("disabling indicator with name {}", indicatorName);
+ indicators.remove(indicatorName);
+ } else {
+ logger.info("indicator with name {} was not found nothing will be removed", indicatorName);
+ }
+ }
+ }
+ return fillModel(status, executeHealth(indicators, status));
+ }
+
+ protected abstract Object executeHealth(Map indicators, Status status);
+}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthDetailsWebScript.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthDetailsWebScript.java
new file mode 100644
index 0000000..a162015
--- /dev/null
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthDetailsWebScript.java
@@ -0,0 +1,20 @@
+package eu.xenit.actuators.webscripts.classical;
+
+import eu.xenit.actuators.HealthIndicator;
+import eu.xenit.actuators.model.gen.HealthInfo;
+import org.springframework.extensions.webscripts.Status;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class HealthDetailsWebScript extends AbstractHealthWebScript {
+ @Override
+ protected List executeHealth(Map indicators, Status status) {
+ return indicators
+ .values()
+ .stream()
+ .map(HealthIndicator::isHealthy)
+ .collect(Collectors.toList());
+ }
+}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthWebScript.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthWebScript.java
index e7df04f..9cef4ae 100644
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthWebScript.java
+++ b/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthWebScript.java
@@ -1,42 +1,31 @@
package eu.xenit.actuators.webscripts.classical;
-import eu.xenit.actuators.Health;
-import eu.xenit.actuators.HealthDetailsError;
import eu.xenit.actuators.HealthIndicator;
-import eu.xenit.actuators.HealthStatus;
-import java.util.HashMap;
-import java.util.Map;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
-import org.springframework.extensions.webscripts.Cache;
-import org.springframework.extensions.webscripts.DeclarativeWebScript;
+import eu.xenit.actuators.model.gen.HealthInfo;
+import eu.xenit.actuators.model.gen.HealthStatus;
+import eu.xenit.actuators.model.gen.StatusEnum;
import org.springframework.extensions.webscripts.Status;
-import org.springframework.extensions.webscripts.WebScriptRequest;
-public class HealthWebScript extends DeclarativeWebScript implements ManifestSettingWebScript {
+import java.util.Map;
- @Autowired
- private ApplicationContext applicationContext;
+public class HealthWebScript extends AbstractHealthWebScript {
- @Override
- protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) {
- setManifestProperties(req);
- final Map model = new HashMap<>();
- model.put("health", "UP");
- String message = "";
- Map indicators = applicationContext.getBeansOfType(HealthIndicator.class);
+ @Override
+ protected HealthStatus executeHealth(Map indicators, Status status) {
+ HealthStatus healthStatus = new HealthStatus();
+ healthStatus.setStatus(StatusEnum.UP);
for (HealthIndicator indicator : indicators.values()) {
- Health health = indicator.isHealthy();
- if (health.getStatus().equals(HealthStatus.DOWN)) {
- model.put("health", health.getStatus());
+ HealthInfo health = indicator.isHealthy();
+ if (StatusEnum.DOWN.equals(health.getStatus())) {
+ healthStatus.setStatus(health.getStatus());
status.setCode(Status.STATUS_INTERNAL_SERVER_ERROR);
- status.setMessage(((HealthDetailsError) health.getDetails()).getError());
+ healthStatus.setMessage(health.getName() + " failed with error: " + health.getError());
+ status.setMessage(health.getError());
break;
}
}
- model.put("message", message);
-
- return model;
+ return healthStatus;
}
+
}
diff --git a/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthdetailsWebScript.java b/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthdetailsWebScript.java
deleted file mode 100644
index 31de195..0000000
--- a/alfresco-actuators/src/main/java/eu/xenit/actuators/webscripts/classical/HealthdetailsWebScript.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package eu.xenit.actuators.webscripts.classical;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import eu.xenit.actuators.Health;
-import eu.xenit.actuators.HealthIndicator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
-import org.springframework.extensions.webscripts.Cache;
-import org.springframework.extensions.webscripts.DeclarativeWebScript;
-import org.springframework.extensions.webscripts.Status;
-import org.springframework.extensions.webscripts.WebScriptRequest;
-
-public class HealthdetailsWebScript extends DeclarativeWebScript implements ManifestSettingWebScript {
-
- private static final Logger logger = LoggerFactory.getLogger(HealthdetailsWebScript.class);
-
- private final ApplicationContext applicationContext;
- private final ObjectMapper objectMapper = new ObjectMapper();
-
- @Autowired
- public HealthdetailsWebScript(ApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
- }
-
- @Override
- protected Map executeImpl(WebScriptRequest request, Status status, Cache cache) {
- setManifestProperties(request);
- final Map model = new HashMap<>();
- Map indicators = applicationContext.getBeansOfType(HealthIndicator.class);
- List