Skip to content

Commit

Permalink
Unable to use Systemd module with tar distribution (#3755) (#3903)
Browse files Browse the repository at this point in the history
* Fix #3666

Signed-off-by: Florent David <florent.david@gmail.com>

* Fix linter issues

Signed-off-by: Florent David <florent.david@gmail.com>

* Add systemd module in linux and freebsd archives

Signed-off-by: Florent David <florent.david@gmail.com>
(cherry picked from commit 2858eb1)

Co-authored-by: Ripolin <florent.david@gmail.com>
  • Loading branch information
opensearch-trigger-bot[bot] and Ripolin authored Jul 14, 2022
1 parent 60379e5 commit ea55054
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
4 changes: 2 additions & 2 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ ext.restTestExpansions = [
// loop over modules to also setup cross task dependencies and increment our modules counter
project.rootProject.subprojects.findAll { it.parent.path == ':modules' }.each { Project module ->
if (module.name == 'systemd') {
// the systemd module is only included in the package distributions
// the systemd module is only included in the package distributions or in linux and freebsd archives
return
}
File licenses = new File(module.projectDir, 'licenses')
Expand Down Expand Up @@ -367,7 +367,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
if (BuildParams.isSnapshotBuild()) {
from(buildExternalTestModulesTaskProvider)
}
if (project.path.startsWith(':distribution:packages')) {
if (project.path.startsWith(':distribution:packages') || ['freebsd-x64','linux-x64', 'linux-arm64'].contains(platform)) {
from(buildSystemdModuleTaskProvider)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.SetOnce;
import org.opensearch.Build;
import org.opensearch.client.Client;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.service.ClusterService;
Expand Down Expand Up @@ -68,20 +67,10 @@ final boolean isEnabled() {

@SuppressWarnings("unused")
public SystemdPlugin() {
this(true, Build.CURRENT.type(), System.getenv("OPENSEARCH_SD_NOTIFY"));
this(System.getenv("OPENSEARCH_SD_NOTIFY"));
}

SystemdPlugin(final boolean assertIsPackageDistribution, final Build.Type buildType, final String esSDNotify) {
final boolean isPackageDistribution = buildType == Build.Type.DEB || buildType == Build.Type.RPM;
if (assertIsPackageDistribution) {
// our build is configured to only include this module in the package distributions
assert isPackageDistribution : buildType;
}
if (isPackageDistribution == false) {
logger.debug("disabling sd_notify as the build type [{}] is not a package distribution", buildType);
enabled = false;
return;
}
SystemdPlugin(final String esSDNotify) {
logger.trace("OPENSEARCH_SD_NOTIFY is set to [{}]", esSDNotify);
if (esSDNotify == null) {
enabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.systemd;

import org.opensearch.Build;
import org.opensearch.common.CheckedConsumer;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.test.OpenSearchTestCase;
Expand All @@ -58,13 +57,6 @@
import static org.mockito.Mockito.when;

public class SystemdPluginTests extends OpenSearchTestCase {

private final Build.Type randomPackageBuildType = randomFrom(Build.Type.DEB, Build.Type.RPM);
private final Build.Type randomNonPackageBuildType = randomValueOtherThanMany(
t -> t == Build.Type.DEB || t == Build.Type.RPM,
() -> randomFrom(Build.Type.values())
);

final Scheduler.Cancellable extender = mock(Scheduler.Cancellable.class);
final ThreadPool threadPool = mock(ThreadPool.class);

Expand All @@ -74,29 +66,15 @@ public class SystemdPluginTests extends OpenSearchTestCase {
.thenReturn(extender);
}

public void testIsEnabled() {
final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, Boolean.TRUE.toString());
plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
assertTrue(plugin.isEnabled());
assertNotNull(plugin.extender());
}

public void testIsNotPackageDistribution() {
final SystemdPlugin plugin = new SystemdPlugin(false, randomNonPackageBuildType, Boolean.TRUE.toString());
plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
assertFalse(plugin.isEnabled());
assertNull(plugin.extender());
}

public void testIsImplicitlyNotEnabled() {
final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, null);
final SystemdPlugin plugin = new SystemdPlugin(null);
plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
assertFalse(plugin.isEnabled());
assertNull(plugin.extender());
}

public void testIsExplicitlyNotEnabled() {
final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, Boolean.FALSE.toString());
final SystemdPlugin plugin = new SystemdPlugin(Boolean.FALSE.toString());
plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
assertFalse(plugin.isEnabled());
assertNull(plugin.extender());
Expand All @@ -107,7 +85,7 @@ public void testInvalid() {
s -> Boolean.TRUE.toString().equals(s) || Boolean.FALSE.toString().equals(s),
() -> randomAlphaOfLength(4)
);
final RuntimeException e = expectThrows(RuntimeException.class, () -> new SystemdPlugin(false, randomPackageBuildType, esSDNotify));
final RuntimeException e = expectThrows(RuntimeException.class, () -> new SystemdPlugin(esSDNotify));
assertThat(e, hasToString(containsString("OPENSEARCH_SD_NOTIFY set to unexpected value [" + esSDNotify + "]")));
}

Expand Down Expand Up @@ -174,7 +152,7 @@ private void runTest(
final AtomicBoolean invoked = new AtomicBoolean();
final AtomicInteger invokedUnsetEnvironment = new AtomicInteger();
final AtomicReference<String> invokedState = new AtomicReference<>();
final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, esSDNotify) {
final SystemdPlugin plugin = new SystemdPlugin(esSDNotify) {

@Override
int sd_notify(final int unset_environment, final String state) {
Expand Down

0 comments on commit ea55054

Please sign in to comment.