Skip to content
Permalink
Browse files

Merge branch 'release-24.1.0' into develop

  • Loading branch information...
RangerRick committed May 14, 2019
2 parents d4e00be + 2fe4df1 commit e30967da52bcd1cd0ea656545a9fc4453cd6d828
@@ -76,4 +76,8 @@ public void setError(String errorMessage) {
public String getErrorMessage() {
return errorMessage;
}

public List<Response> getResponses() {
return new ArrayList<>(responses);
}
}
@@ -25,6 +25,11 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.core</artifactId>
@@ -52,5 +57,15 @@
<artifactId>guava</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opennms.core.test-api</groupId>
<artifactId>org.opennms.core.test-api.lib</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -66,7 +66,7 @@
private static final Logger LOG = LoggerFactory.getLogger(DefaultHealthCheckService.class);

// HealthChecks are performed asynchronously with this executor.
private final ExecutorService executorService = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setNameFormat("health-check-%d").build());
private final ExecutorService executorService = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("health-check-%d").build());

// Context to load the services
private BundleContext bundleContext;
@@ -76,7 +76,7 @@ public DefaultHealthCheckService(BundleContext bundleContext) {
}

// Resolve all HealthChecks from the OSGi registry
private List<HealthCheck> getHealthChecks() throws InvalidSyntaxException {
protected List<HealthCheck> getHealthChecks() throws InvalidSyntaxException {
final Collection<ServiceReference<HealthCheck>> serviceReferences = bundleContext.getServiceReferences(HealthCheck.class, null);
return serviceReferences.stream()
.sorted(Comparator.comparingLong(ref -> ref.getBundle().getBundleId()))
@@ -0,0 +1,112 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2019-2019 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2019 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.core.health.impl;

import static org.hamcrest.CoreMatchers.is;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.opennms.core.health.api.Context;
import org.opennms.core.health.api.Health;
import org.opennms.core.health.api.HealthCheck;
import org.opennms.core.health.api.Response;
import org.opennms.core.health.api.SimpleHealthCheck;
import org.opennms.core.health.api.Status;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Lists;

public class DefaultHealthCheckServiceTest {

private static class BlockingHealthCheck implements HealthCheck {
@Override
public String getDescription() {
return getClass().getSimpleName();
}

@Override
public Response perform(Context context) {
long start = System.currentTimeMillis();
long spent = 0;
while (spent < 5000) {
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
}
spent += System.currentTimeMillis() - start;
}
return new Response(Status.Success, "\\o/");
}
}

private static final Logger LOG = LoggerFactory.getLogger(DefaultHealthCheckServiceTest.class);

@Rule
public Timeout timeout = new Timeout(60, TimeUnit.SECONDS);

@Test
public void verifyHealthCheckServiceDoesNotBlock() throws InvalidSyntaxException, ExecutionException, InterruptedException {
final BlockingHealthCheck blockingHealthCheck = new BlockingHealthCheck();
final SimpleHealthCheck successHealthCheck = new SimpleHealthCheck(() -> "Always green :)");
successHealthCheck.markSucess();

final DefaultHealthCheckService healthCheckService = new DefaultHealthCheckService(EasyMock.createNiceMock(BundleContext.class)) {
@Override
protected List<HealthCheck> getHealthChecks() {
return Lists.newArrayList(blockingHealthCheck, successHealthCheck);
}
};

final Context context = new Context();
context.setTimeout(1000); // ms

for (int i=0; i<2; i++) {
final CompletableFuture<Health> future = healthCheckService
.performAsyncHealthCheck(context,
healthCheck -> LOG.info("Executing: {}", healthCheck.getDescription()),
response -> LOG.info("=> {} : {}", response.getStatus().name(), response.getMessage()));
final Health health = future.get();
final List<Response> timedOutResponsed = health.getResponses().stream().filter(r -> r.getStatus() == Status.Timeout).collect(Collectors.toList());
Assert.assertThat(timedOutResponsed.size(), is(1));
}
}

}
@@ -1264,7 +1264,7 @@
<commonsLoggingVersion>99.99.99-use-jcl-over-slf4j</commonsLoggingVersion>
<commonsMath3Version>3.5</commonsMath3Version>
<commonsValidatorVersion>1.6</commonsValidatorVersion>
<c3p0Version>0.9.5.2</c3p0Version>
<c3p0Version>0.9.5.4</c3p0Version>
<curatorVersion>3.2.1</curatorVersion>
<cxfVersion>3.2.8</cxfVersion>
<cxfXjcVersion>3.3.0</cxfXjcVersion>
@@ -1356,7 +1356,7 @@
<xercesVersion>2.9.1</xercesVersion>
<xmlApisVersion>1.4.01</xmlApisVersion>
<wsdl4jVersion>1.6.3</wsdl4jVersion>
<wsmanVersion>1.2.2</wsmanVersion>
<wsmanVersion>1.2.3</wsmanVersion>

<springVersion>4.2.9.RELEASE_1</springVersion>
<!-- ALWAYS change aspectj to match the version referenced in the spring poms -->
@@ -167,11 +167,27 @@ mv "%{buildroot}%{minioninstprefix}/etc/minion.conf" "%{buildroot}%{_sysconfdir}
# container package files
find %{buildroot}%{minioninstprefix} ! -type d | \
grep -v %{minioninstprefix}/bin | \
grep -v %{minioninstprefix}/etc | \
grep -v %{minionrepoprefix} | \
grep -v %{minioninstprefix}/etc/featuresBoot.d | \
grep -v %{minioninstprefix}/etc/org.opennms.minion.controller.cfg | \
sed -e "s|^%{buildroot}|%attr(644,minion,minion) |" | \
sort > %{_tmppath}/files.container

# org.apache.karaf.features.cfg and org.ops4j.pax.logging.cfg should
# be special-cased to not be replaced by default (and create .rpmnew files)
find %{buildroot}%{minioninstprefix}/etc ! -type d | \
grep -E 'etc/(org.apache.karaf.features.cfg|org.ops4j.pax.logging.cfg)$' | \
sed -e "s|^%{buildroot}|%attr(644,minion,minion) %config(noreplace) |" | \
sort >> %{_tmppath}/files.container

# all other etc files should replace by default (and create .rpmsave files)
find %{buildroot}%{minioninstprefix}/etc ! -type d | \
grep -v etc/org.opennms. | \
grep -v etc/org.apache.karaf.features.cfg | \
grep -v etc/org.ops4j.pax.logging.cfg | \
grep -v etc/featuresBoot.d | \
sed -e "s|^%{buildroot}|%attr(644,minion,minion) %config |" | \
sort >> %{_tmppath}/files.container

find %{buildroot}%{minioninstprefix}/bin ! -type d | \
sed -e "s|^%{buildroot}|%attr(755,minion,minion) |" | \
sort >> %{_tmppath}/files.container
@@ -621,6 +621,8 @@ cd %{buildroot}
# core package files
find %{buildroot}%{instprefix}/etc ! -type d | \
sed -e "s,^%{buildroot},%config(noreplace) ," | \
grep -v -E 'etc/.*.cfg$' | \
grep -v 'etc/custom.properties' | \
grep -v '%{_initrddir}/opennms-remote-poller' | \
grep -v '%{_sysconfdir}/sysconfig/opennms-remote-poller' | \
grep -v 'jira.properties' | \
@@ -639,6 +641,14 @@ find %{buildroot}%{instprefix}/etc ! -type d | \
grep -v 'xmp-datacollection-config.xml' | \
grep -v 'tca-datacollection-config.xml' | \
sort > %{_tmppath}/files.main
find %{buildroot}%{instprefix}/etc ! -type d -name \*.cfg | \
grep -v 'etc/org.opennms' | \
sed -e "s,^%{buildroot},%config ," | \
sort >> %{_tmppath}/files.main
find %{buildroot}%{instprefix}/etc ! -type d -name \*.cfg | \
grep 'etc/org.opennms' | \
sed -e "s,^%{buildroot},%config(noreplace) ," | \
sort >> %{_tmppath}/files.main
find %{buildroot}%{sharedir}/etc-pristine ! -type d | \
sed -e "s,^%{buildroot},," | \
grep -v '%{_initrddir}/opennms-remote-poller' | \
@@ -739,6 +749,7 @@ rm -rf %{buildroot}
%defattr(664 root root 775)
%attr(755,root,root) %{profiledir}/%{name}.sh
%attr(755,root,root) %{logdir}
%config %{instprefix}/etc/custom.properties
%attr(640,root,root) %config(noreplace) %{instprefix}/etc/users.xml
%{instprefix}/data
%{instprefix}/deploy
@@ -125,13 +125,30 @@ mv "%{buildroot}%{sentinelinstprefix}/etc/sentinel.conf" "%{buildroot}%{_sysconf
# sentinel package files
find %{buildroot}%{sentinelinstprefix} ! -type d | \
grep -v %{sentinelinstprefix}/bin | \
grep -v %{sentinelinstprefix}/etc | \
grep -v %{sentinelrepoprefix} | \
grep -v %{sentinelinstprefix}/etc/featuresBoot.d | \
sed -e "s|^%{buildroot}|%attr(644,sentinel,sentinel) |" | \
sort > %{_tmppath}/files.sentinel

# org.apache.karaf.features.cfg and org.ops4j.pax.logging.cfg should
# be special-cased to not be replaced by default (and create .rpmnew files)
find %{buildroot}%{sentinelinstprefix}/etc ! -type d | \
grep -E 'etc/(org.apache.karaf.features.cfg|org.ops4j.pax.logging.cfg)$' | \
sed -e "s|^%{buildroot}|%attr(644,sentinel,sentinel) %config(noreplace) |" | \
sort >> %{_tmppath}/files.sentinel

# all other etc files should replace by default (and create .rpmsave files)
find %{buildroot}%{sentinelinstprefix}/etc ! -type d | \
grep -v etc/org.apache.karaf.features.cfg | \
grep -v etc/org.ops4j.pax.logging.cfg | \
grep -v etc/featuresBoot.d | \
sed -e "s|^%{buildroot}|%attr(644,sentinel,sentinel) %config |" | \
sort >> %{_tmppath}/files.sentinel

find %{buildroot}%{sentinelinstprefix}/bin ! -type d | \
sed -e "s|^%{buildroot}|%attr(755,sentinel,sentinel) |" | \
sort >> %{_tmppath}/files.sentinel

# Exclude subdirs of the repository directory
find %{buildroot}%{sentinelinstprefix} -type d | \
grep -v %{sentinelrepoprefix}/ | \

0 comments on commit e30967d

Please sign in to comment.
You can’t perform that action at this time.