Skip to content

Commit c1686bd

Browse files
committed
Working in ability to enable and disable units
- Introduced a Struct and Pair class as needed by dbus-java - Updated various versions I am labeling this version as 2.2.0-eks so if this commit is accepted, be sure to remove -eks. --- In a working state. Needed to also use a special struct class for the disableUnitFiles call (+3 squashed commit) Squashed commit: [9dde539] Found that `enableUnitFiles` may perform what I need to get units started. The `List<UnitFileChange>` is not the proper return type. Some research lead me to AgNO3 project that uses a Tuple type of structure to hold the return type: https://github.com/AgNO3/code/blob/main/orchestrator/agent/system/eu.agno3.orchestrator.system.init.systemd/src/main/java/org/freedesktop/systemd1/Manager.java Still experimenting... [7197b50] WIP: TDD and fleshing out unit creation with dbus [fb4e92d] Starting work towards creating/update/delete units - Specifically service units for now. - Using my own version number - Using lombok to reduce builder code. thjomnx#6 (comment)
1 parent 6364cee commit c1686bd

File tree

5 files changed

+73
-18
lines changed

5 files changed

+73
-18
lines changed

pom.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.thjomnx</groupId>
77
<artifactId>java-systemd</artifactId>
8-
<version>2.2.0-SNAPSHOT</version>
8+
<version>2.2.0-eks</version>
99
<packaging>jar</packaging>
1010

1111
<name>${project.artifactId}</name>
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>com.github.hypfvieh</groupId>
4949
<artifactId>dbus-java</artifactId>
50-
<version>3.3.0</version>
50+
<version>3.3.1</version>
5151
</dependency>
5252
<dependency>
5353
<groupId>javax.xml.bind</groupId>
@@ -57,29 +57,29 @@
5757
<dependency>
5858
<groupId>org.slf4j</groupId>
5959
<artifactId>slf4j-api</artifactId>
60-
<version>1.7.30</version>
60+
<version>1.7.36</version>
6161
</dependency>
6262
<dependency>
6363
<groupId>org.slf4j</groupId>
6464
<artifactId>slf4j-simple</artifactId>
65-
<version>1.7.30</version>
65+
<version>1.7.36</version>
6666
</dependency>
6767
<dependency>
6868
<groupId>org.testng</groupId>
6969
<artifactId>testng</artifactId>
70-
<version>7.4.0</version>
70+
<version>7.5</version>
7171
<scope>test</scope>
7272
</dependency>
7373
<dependency>
7474
<groupId>org.mockito</groupId>
7575
<artifactId>mockito-inline</artifactId>
76-
<version>3.8.0</version>
76+
<version>4.3.1</version>
7777
<scope>test</scope>
7878
</dependency>
7979
<dependency>
8080
<groupId>org.awaitility</groupId>
8181
<artifactId>awaitility</artifactId>
82-
<version>4.0.3</version>
82+
<version>4.2.0</version>
8383
<scope>test</scope>
8484
</dependency>
8585
</dependencies>

src/main/java/de/thjom/java/systemd/Manager.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.math.BigInteger;
1515
import java.util.List;
1616

17+
import de.thjom.java.systemd.types.*;
1718
import org.freedesktop.dbus.DBusPath;
1819
import org.freedesktop.dbus.connections.impl.DBusConnection;
1920
import org.freedesktop.dbus.exceptions.DBusException;
@@ -22,12 +23,6 @@
2223
import de.thjom.java.systemd.Unit.Mode;
2324
import de.thjom.java.systemd.Unit.Who;
2425
import de.thjom.java.systemd.interfaces.ManagerInterface;
25-
import de.thjom.java.systemd.types.DynamicUser;
26-
import de.thjom.java.systemd.types.UnitFileChange;
27-
import de.thjom.java.systemd.types.UnitFileInstallChange;
28-
import de.thjom.java.systemd.types.UnitFileType;
29-
import de.thjom.java.systemd.types.UnitProcessType;
30-
import de.thjom.java.systemd.types.UnitType;
3126

3227
public class Manager extends InterfaceAdapter {
3328

@@ -195,15 +190,15 @@ public void clearJobs() {
195190
getInterface().clearJobs();
196191
}
197192

198-
public List<UnitFileChange> disableUnitFiles(final List<String> names, final boolean runtime) {
193+
public List<StructForUnitEnableAndDisable> disableUnitFiles(final List<String> names, final boolean runtime) {
199194
return getInterface().disableUnitFiles(names, runtime);
200195
}
201196

202197
public String dump() {
203198
return getInterface().dump();
204199
}
205200

206-
public List<UnitFileChange> enableUnitFiles(final List<String> names, final boolean runtime, final boolean force) {
201+
public Pair<Boolean, List<StructForUnitEnableAndDisable>> enableUnitFiles(final List<String> names, final boolean runtime, final boolean force) {
207202
return getInterface().enableUnitFiles(names, runtime, force);
208203
}
209204

src/main/java/de/thjom/java/systemd/interfaces/ManagerInterface.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
package de.thjom.java.systemd.interfaces;
1313

14+
import de.thjom.java.systemd.types.Pair;
1415
import de.thjom.java.systemd.Signal;
16+
import de.thjom.java.systemd.types.StructForUnitEnableAndDisable;
1517
import de.thjom.java.systemd.types.*;
1618
import org.freedesktop.dbus.DBusPath;
1719
import org.freedesktop.dbus.annotations.DBusInterfaceName;
@@ -37,13 +39,13 @@ public interface ManagerInterface extends DBusInterface {
3739
void clearJobs();
3840

3941
@DBusMemberName(value = "DisableUnitFiles")
40-
List<UnitFileChange> disableUnitFiles(List<String> names, boolean runtime);
42+
List<StructForUnitEnableAndDisable> disableUnitFiles(List<String> names, boolean runtime);
4143

4244
@DBusMemberName(value = "Dump")
4345
String dump();
4446

4547
@DBusMemberName(value = "EnableUnitFiles")
46-
List<UnitFileChange> enableUnitFiles(List<String> names, boolean runtime, boolean force);
48+
Pair<Boolean, List<StructForUnitEnableAndDisable>> enableUnitFiles(List<String> names, boolean runtime, boolean force);
4749

4850
@DBusMemberName(value = "Exit")
4951
void exit();
@@ -245,7 +247,7 @@ public boolean isActive() {
245247
class StartupFinished extends Signal {
246248

247249
public StartupFinished(String objectPath, long firmware, long loader, long kernel, long initrd,
248-
long userspace, long total) throws DBusException {
250+
long userspace, long total) throws DBusException {
249251
super(objectPath, firmware, loader, kernel, initrd, userspace, total);
250252
}
251253

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Java-systemd implementation
3+
* Copyright (c) 2016 Markus Enax
4+
*
5+
* This program is free software; you can redistribute it and/or modify it under
6+
* the terms of either the GNU Lesser General Public License Version 2 or the
7+
* Academic Free Licence Version 3.0.
8+
*
9+
* Full licence texts are included in the COPYING file with this program.
10+
*/
11+
12+
package de.thjom.java.systemd.types;
13+
14+
import org.freedesktop.dbus.Tuple;
15+
import org.freedesktop.dbus.annotations.Position;
16+
17+
public final class Pair<A, B> extends Tuple {
18+
19+
@Position(0)
20+
public final A a;
21+
@Position(1)
22+
public final B b;
23+
24+
public Pair(A a, B b) {
25+
this.a = a;
26+
this.b = b;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Java-systemd implementation
3+
* Copyright (c) 2016 Markus Enax
4+
*
5+
* This program is free software; you can redistribute it and/or modify it under
6+
* the terms of either the GNU Lesser General Public License Version 2 or the
7+
* Academic Free Licence Version 3.0.
8+
*
9+
* Full licence texts are included in the COPYING file with this program.
10+
*/
11+
12+
package de.thjom.java.systemd.types;
13+
14+
import org.freedesktop.dbus.Struct;
15+
import org.freedesktop.dbus.annotations.Position;
16+
17+
public final class StructForUnitEnableAndDisable extends Struct {
18+
@Position(0)
19+
public final String a;
20+
@Position(1)
21+
public final String b;
22+
@Position(2)
23+
public final String c;
24+
25+
public StructForUnitEnableAndDisable(String a, String b, String c) {
26+
this.a = a;
27+
this.b = b;
28+
this.c = c;
29+
}
30+
}

0 commit comments

Comments
 (0)