Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Commit c9f945a

Browse files
committed
Clean up configs, machine name is generated on startup
1 parent 1cd0498 commit c9f945a

33 files changed

+100
-214
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For some of the tests, a running naming service is required. The naming service
99
# Current ToDos / Missing Functionality
1010

1111
## Startup
12-
- [ ] A machineName should be dynamically created on Startup (clean up configs)
12+
- [x] A machineName should be dynamically created on Startup (clean up configs)
1313
- [x] Run AddMachineToNodeTask (ended up not being a task)
1414

1515
## Subscription Management incl. Heartbeats

src/main/java/communication/MessageIdEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class MessageIdEvaluator {
3939
private static Logger logger = Logger.getLogger(MessageIdEvaluator.class.getName());
4040

4141
static {
42-
logger.setLevel(Level.INFO);
42+
logger.setLevel(Level.DEBUG);
4343
}
4444

4545
private FBase fBase;

src/main/java/control/Configuration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public Configuration(String configName) {
6161

6262
properties.load(is);
6363
// General
64-
machineName = properties.getProperty("machineName");
6564
nodeID = new NodeID(properties.getProperty("nodeID"));
6665
location = properties.getProperty("location", "Unknown");
6766
description = properties.getProperty("description", "Unknown");
@@ -101,7 +100,7 @@ private void checkConsistency() throws IOException {
101100
for (int i = 0; i < methods.length; i++) {
102101
Method m = methods[i];
103102
if (m.getName().startsWith("get")) {
104-
if (!m.getName().equals("getAlgorithm")) {
103+
if (!m.getName().equals("getAlgorithm") && !m.getName().equals("getMachineName")) {
105104
try {
106105
Object obj = m.invoke(this);
107106
if (obj == null) {
@@ -135,6 +134,10 @@ public NodeConfig buildNodeConfigBasedOnData() {
135134

136135
return config;
137136
}
137+
138+
public void setMachineName(String machineName) {
139+
this.machineName = machineName;
140+
}
138141

139142
public String getMachineName() {
140143
return machineName;

src/main/java/control/FBase.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,16 @@ public FBase(String configName) {
5555
publisher = new Publisher("tcp://0.0.0.0", configuration.getPublisherPort());
5656
}
5757

58-
public void startup(boolean announce) throws InterruptedException, ExecutionException,
59-
TimeoutException, FBaseStorageConnectorException, FBaseCommunicationException,
60-
FBaseNamingServiceException {
58+
public void startup(boolean announce, boolean backgroundTasks) throws InterruptedException,
59+
ExecutionException, TimeoutException, FBaseStorageConnectorException,
60+
FBaseCommunicationException, FBaseNamingServiceException {
6161
if (Connector.S3.equals(configuration.getDatabaseConnector())) {
6262
connector =
63-
new S3DBConnector(configuration.getNodeID(), configuration.getMachineName());
63+
new S3DBConnector(configuration.getNodeID());
6464
} else {
65-
connector = new OnHeapDBConnector(configuration.getNodeID(),
66-
configuration.getMachineName());
65+
connector = new OnHeapDBConnector(configuration.getNodeID());
6766
}
68-
connector.dbConnection_initiate();
67+
configuration.setMachineName(connector.dbConnection_initiate());
6968
configAccessHelper = new ConfigAccessHelper(this);
7069
taskmanager = new TaskManager(this);
7170
if (configuration.getRestPort() > 0) {
@@ -82,36 +81,41 @@ public void startup(boolean announce) throws InterruptedException, ExecutionExce
8281
subscriptionRegistry = new SubscriptionRegistry(this);
8382
messageIdEvaluator = new MessageIdEvaluator(this);
8483
messageIdEvaluator.startup();
85-
84+
8685
// start putting heartbeats (pulse 0 = default)
8786
taskmanager.startBackgroundPutHeartbeatTask(0);
88-
87+
8988
// add machine to node
9089
if (announce) {
9190
announceMachineAdditionToNode();
9291
}
93-
92+
9493
// start other background tasks (interval 0 = default)
95-
taskmanager.startBackgroundPollLatesConfigurationDataForResponsibleKeygroupsTask(0);
96-
taskmanager.startBackgroundCheckKeygroupConfigurationsOnUpdatesTask(0);
97-
taskmanager.startDetectMissingHeartbeatsTask(0, 0);
98-
taskmanager.startBackgroundDetectMissingResponsibility(0);
99-
taskmanager.startBackgroundDetectLostResponsibility(0);
94+
if (backgroundTasks) {
95+
taskmanager.startBackgroundPollLatesConfigurationDataForResponsibleKeygroupsTask(0);
96+
taskmanager.startBackgroundCheckKeygroupConfigurationsOnUpdatesTask(0);
97+
taskmanager.startDetectMissingHeartbeatsTask(0, 0);
98+
taskmanager.startBackgroundDetectMissingResponsibility(0);
99+
taskmanager.startBackgroundDetectLostResponsibility(0);
100+
}
100101

101102
Thread.sleep(50);
102103
logger.info("FBase started, all background tasks up and running.");
103104
}
104105

105-
private void announceMachineAdditionToNode()
106-
throws FBaseStorageConnectorException, FBaseCommunicationException,
107-
FBaseNamingServiceException {
108-
109-
// TODO 1: Tell a node that is already registered about addition (we need a one-to-one here)
106+
private void announceMachineAdditionToNode() throws FBaseStorageConnectorException,
107+
FBaseCommunicationException, FBaseNamingServiceException {
108+
109+
// TODO 1: Tell a node that is already registered about addition (we need a one-to-one
110+
// here)
110111

111112
}
112113

113114
public void tearDown() {
115+
// TODO 1: stop all background tasks
116+
subscriptionRegistry.deleteAllData();
114117
publisher.shutdown();
118+
namingServiceSender.shutdown();
115119
messageIdEvaluator.tearDown();
116120
directMessageReceiver.stopReception();
117121
if (server != null) {

src/main/java/control/Starter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static void main(String[] args)
1313
throws FBaseStorageConnectorException, InterruptedException, ExecutionException,
1414
TimeoutException, FBaseCommunicationException, FBaseNamingServiceException {
1515
FBase fbase = new FBase("local.properties");
16-
fbase.startup(true);
16+
fbase.startup(true, true); // TODO 2: parse from args
1717
fbase.fillWithData();
1818
}
1919

src/main/java/storageconnector/AbstractDBConnector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ protected AbstractDBConnector() {
4747
* called when initializing the connection
4848
*
4949
* @throws FBaseStorageConnectorException when something goes wrong
50+
* @return the random name for the initialized machine that did not exist yet
5051
*/
51-
public abstract void dbConnection_initiate() throws FBaseStorageConnectorException;
52+
public abstract String dbConnection_initiate() throws FBaseStorageConnectorException;
5253

5354
/**
5455
* CONNECTION ADMINISTRATION<br<br>

src/main/java/storageconnector/OnHeapDBConnector.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,21 @@ public class OnHeapDBConnector extends AbstractDBConnector {
7070
private NodeID nodeID = null;
7171
private String machineName = null;
7272

73-
public OnHeapDBConnector(NodeID nodeID, String machineName) {
73+
public OnHeapDBConnector(NodeID nodeID) {
7474
this.nodeID = nodeID;
75-
this.machineName = machineName;
7675
}
7776

7877
/*
7978
* (non-Javadoc)
8079
*
8180
* @see storageconnector.AbstractDBConnector#initiateDatabaseConnection()
81+
* Always returns the same name, because always only one machine exists for an on_heap node
8282
*/
8383
@Override
84-
public void dbConnection_initiate() throws FBaseStorageConnectorException {
84+
public String dbConnection_initiate() throws FBaseStorageConnectorException {
8585
log.info("Connector initialized.");
86-
86+
this.machineName = "M1";
87+
return this.machineName;
8788
}
8889

8990
/*

src/main/java/storageconnector/S3DBConnector.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ private enum Suffix {
5757
private NodeID nodeID = null;
5858
private String machineName = null;
5959

60-
public S3DBConnector(NodeID nodeID, String machineName) {
60+
public S3DBConnector(NodeID nodeID) {
6161
this.nodeID = nodeID;
62-
this.machineName = machineName;
6362
suffixMap = new HashMap<>();
6463
suffixMap.put(Suffix.DATA_RECORD, ".data-records");
6564
suffixMap.put(Suffix.KEYGROUP, ".keygroup-configs");
@@ -70,8 +69,8 @@ public S3DBConnector(NodeID nodeID, String machineName) {
7069
suffixMap.put(Suffix.MESSAGE_HISTORY, ".message-history");
7170
}
7271

73-
public S3DBConnector(NodeID nodeID, String machineName, String bucketName) {
74-
this(nodeID, machineName);
72+
public S3DBConnector(NodeID nodeID, String bucketName) {
73+
this(nodeID);
7574
this.bucketPrefix = bucketName;
7675
}
7776

@@ -106,6 +105,9 @@ public void dbConnection_initiate() throws FBaseStorageConnectorException {
106105
}
107106
}
108107
}
108+
// TODO S3: set this.machinename to generated name
109+
110+
return this.machineName;
109111
}
110112

111113
public void deleteBuckets() throws FBaseStorageConnectorException {

src/main/resources/sample_config.properties

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
! A sample configuration file for FBase
22
! You should create a local.properties based on this
33

4-
!!! Machine specific data (each machine of the node can have different values here) !!!
5-
machineName: <the machine name (MANDATORY)>
6-
messageHistorySize: <total number of last published messages stored>
7-
84
!!! Node specific data (has to be equal on all nodes) !!!
95

106
! General
117
nodeID: <nodeID of the node this machine is a part of (MANDATORY)>
128
location: <location of the node>
139
description: <description of the node>
1410
databaseConnector: <the used database connector (ON_HEAP or S3)>
11+
messageHistorySize: <total number of last published messages stored>
1512

1613
! Communication
1714
restPort: <the port on which the rest interface is available>

src/test/java/communication/DirectMessageSenderAndReceiverTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import model.data.DataRecord;
2323
import model.data.KeygroupID;
2424
import model.data.MessageID;
25+
import tasks.FBaseFactory;
2526

2627
/**
2728
* Test for {@link DirectMessageSender} and {@link DirectMessageReceiver}.
@@ -31,7 +32,8 @@
3132
*/
3233
public class DirectMessageSenderAndReceiverTest {
3334

34-
private static Logger logger = Logger.getLogger(DirectMessageSenderAndReceiverTest.class.getName());
35+
private static Logger logger =
36+
Logger.getLogger(DirectMessageSenderAndReceiverTest.class.getName());
3537

3638
FBase fBase = null;
3739
DirectMessageSender directMessageSender = null;
@@ -48,12 +50,11 @@ public static void tearDownAfterClass() throws Exception {
4850

4951
@Before
5052
public void setUp() throws Exception {
51-
fBase = new FBase("MessageSenderAndReceiverTest_Config.properties");
52-
fBase.startup(false);
53+
fBase = FBaseFactory.basic(1, false, false);
5354
myNode = fBase.configuration.buildNodeConfigBasedOnData();
5455
// put my own configuration in database
5556
fBase.connector.nodeConfig_put(myNode.getNodeID(), myNode);
56-
57+
5758
directMessageSender = new DirectMessageSender(myNode, fBase);
5859
KeygroupConfig keygroupConfig =
5960
new KeygroupConfig(keygroupID, "testscret", EncryptionAlgorithm.AES);

src/test/java/communication/NamingServiceSenderTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
import model.messages.Envelope;
4040
import model.messages.Message;
4141
import model.messages.ResponseCode;
42+
import tasks.FBaseFactory;
4243

4344
public class NamingServiceSenderTest {
4445

4546
private static Logger logger = Logger.getLogger(NamingServiceSenderTest.class.getName());
4647

4748
private static ExecutorService executor;
4849
private static FBase fbase;
49-
private static final String configName = "NamingServiceSenderTest_Config.properties";
5050
private static final String ownNodeConfigJSONPath =
5151
"src/test/resources/NamingServiceSenderTest_NodeConfig.json";
5252

@@ -61,8 +61,7 @@ public class NamingServiceSenderTest {
6161
@BeforeClass
6262
public static void setUpBeforeClass() throws Exception {
6363
executor = Executors.newCachedThreadPool();
64-
fbase = new FBase(configName);
65-
fbase.startup(false);
64+
fbase = FBaseFactory.namingService(1, false, false);
6665
localSender = new NamingServiceSender(localAddress, localPort, null);
6766
nsSender = new NamingServiceSender(fbase.configuration.getNamingServiceAddress(),
6867
fbase.configuration.getNamingServicePort(), fbase);

src/test/java/communication/SubscriberTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import model.data.DataIdentifier;
2424
import model.data.DataRecord;
2525
import model.messages.Message;
26+
import tasks.FBaseFactory;
2627

2728
public class SubscriberTest {
2829

@@ -47,8 +48,7 @@ public static void setUpBeforeClass() throws Exception {
4748
contextPub = ZMQ.context(1);
4849
publisher = contextPub.socket(ZMQ.PUB);
4950
publisher.bind(address + ":" + port);
50-
fBase = new FBase("SubscriberTest.properties");
51-
fBase.startup(false);
51+
fBase = FBaseFactory.basic(1, false, false);
5252
}
5353

5454
@Before

src/test/java/scenario/TwoNodeScenario.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import model.data.DataRecord;
3434
import model.data.KeygroupID;
3535
import model.data.MessageID;
36+
import tasks.FBaseFactory;
3637
import tasks.TaskManager.TaskName;
3738

3839
public class TwoNodeScenario {
@@ -59,12 +60,8 @@ public static void tearDownAfterClass() throws Exception {
5960

6061
@Before
6162
public void setUp() throws Exception {
62-
fbase1 = new FBase("TwoNodeScenario_1.properties");
63-
fbase1.startup(false);
64-
fbase1.taskmanager.storeHistory();
65-
fbase2 = new FBase("TwoNodeScenario_2.properties");
66-
fbase2.startup(false);
67-
fbase2.taskmanager.storeHistory();
63+
fbase1 = FBaseFactory.namingService(1, false, false);
64+
fbase2 = FBaseFactory.namingService(2, false, false);
6865

6966
nConfig1 = fbase1.configuration.buildNodeConfigBasedOnData();
7067
nConfig2 = fbase2.configuration.buildNodeConfigBasedOnData();

src/test/java/storageconnector/S3DBConnectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void tearDownAfterClass() throws Exception {
5050

5151
@Before
5252
public void setUp() throws Exception {
53-
connector = new S3DBConnector(new NodeID("N1"), "M1",
53+
connector = new S3DBConnector(new NodeID("N1"),
5454
"de.hasenburg.fbase.s3dbconnector-testbucket");
5555
connector.dbConnection_initiate();
5656
keygroupID1 = new KeygroupID("smartlight", "h1", "lightning");

src/test/java/tasks/B_CheckKeygroupConfigurationsOnUpdatesTaskTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public void test()
4949
throws FBaseStorageConnectorException, InterruptedException, ExecutionException,
5050
TimeoutException, FBaseCommunicationException, FBaseNamingServiceException {
5151
logger.debug("-------Starting test-------");
52-
FBase fbase = new FBase(null);
53-
fbase.startup(false);
54-
fbase.taskmanager.storeHistory();
52+
FBase fbase = FBaseFactory.basic(1, false, false);
5553
KeygroupID id = new KeygroupID("app", "tenant", "group");
5654
KeygroupConfig config = new KeygroupConfig(id, null, null);
5755
config.setVersion(1);
@@ -62,7 +60,8 @@ public void test()
6260
+ " should not have been executed so often, ",
6361
new Integer(1), fbase.taskmanager.getHistoricTaskNumbers()
6462
.get(TaskName.UPDATE_KEYGROUP_SUBSCRIPTIONS));
65-
Future<Boolean> task = fbase.taskmanager.startBackgroundCheckKeygroupConfigurationsOnUpdatesTask(1000);
63+
Future<Boolean> task =
64+
fbase.taskmanager.startBackgroundCheckKeygroupConfigurationsOnUpdatesTask(1000);
6665
config.setVersion(2);
6766
fbase.connector.keygroupConfig_put(id, config);
6867
Thread.sleep(2000);

src/test/java/tasks/FBaseFactory.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@
1111
public class FBaseFactory {
1212

1313
private static final String BASIC_PROPERTIES_FILE = "FBaseFactory_Basic";
14+
private static final String NAMING_SERVICE_PROPERTIES_FILE = "FBaseFactory_NamingService";
1415

15-
public static FBase basic(int instanceNumber)
16+
17+
public static FBase basic(int instanceNumber, boolean announce, boolean backgroundTasks)
1618
throws FBaseStorageConnectorException, InterruptedException, ExecutionException,
1719
TimeoutException, FBaseCommunicationException, FBaseNamingServiceException {
1820
FBase fBase = new FBase(BASIC_PROPERTIES_FILE + instanceNumber + ".properties");
19-
fBase.startup(false);
21+
fBase.startup(announce, backgroundTasks);
22+
fBase.taskmanager.storeHistory();
23+
return fBase;
24+
}
25+
26+
public static FBase namingService(int instanceNumber, boolean announce, boolean backgroundTasks)
27+
throws FBaseStorageConnectorException, FBaseCommunicationException,
28+
FBaseNamingServiceException, InterruptedException, ExecutionException,
29+
TimeoutException {
30+
FBase fBase = new FBase(NAMING_SERVICE_PROPERTIES_FILE + instanceNumber + ".properties");
31+
fBase.startup(announce, backgroundTasks);
2032
fBase.taskmanager.storeHistory();
2133
return fBase;
2234
}

src/test/java/tasks/PutAndDeleteDataRecordTaskTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public static void tearDownAfterClass() throws Exception {
4848

4949
@Before
5050
public void setUp() throws Exception {
51-
fBase = new FBase("PutAndDeleteDataRecordTask_Config.properties");
52-
fBase.startup(false);
51+
fBase = FBaseFactory.basic(1, false, false);
5352
KeygroupConfig keygroupConfig =
5453
new KeygroupConfig(keygroupID, "testscret", EncryptionAlgorithm.AES);
5554
fBase.taskmanager.runUpdateKeygroupConfigTask(keygroupConfig, false).get(2,

src/test/java/tasks/TaskManagerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public class TaskManagerTest {
3030

3131
@BeforeClass
3232
public static void setUpBeforeClass() throws Exception {
33-
fBase = new FBase(null);
34-
fBase.startup(false);
33+
fBase = FBaseFactory.basic(1, false, false);
3534
taskmanager = fBase.taskmanager;
3635
}
3736

0 commit comments

Comments
 (0)