Skip to content

Commit 63c0570

Browse files
committed
Fixed several bugs.
1 parent 9517b2a commit 63c0570

File tree

9 files changed

+64
-48
lines changed

9 files changed

+64
-48
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rtConsole=true

cluster/node/appnode/src/main/java/com/thefirstlineofcode/granite/cluster/node/appnode/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void main(String[] args) {
2828
}
2929

3030
// set log directory for logback(see logback.xml)
31-
System.setProperty("appnode.logs.dir", options.getHomeDir() + "/logs");
31+
System.setProperty("appnode.logs.dir", options.getConfigurationDir() + "/logs");
3232

3333
try {
3434
new Starter().start(options);

cluster/node/appnode/src/main/java/com/thefirstlineofcode/granite/cluster/node/appnode/Starter.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.io.IOException;
88
import java.io.InputStream;
99
import java.lang.ProcessBuilder.Redirect;
10+
import java.net.Inet4Address;
11+
import java.net.InetSocketAddress;
1012
import java.net.URL;
1113
import java.nio.file.Files;
1214
import java.nio.file.Path;
@@ -21,6 +23,7 @@
2123
import org.apache.ignite.cluster.ClusterGroup;
2224
import org.apache.ignite.cluster.ClusterNode;
2325
import org.apache.ignite.configuration.IgniteConfiguration;
26+
import org.apache.ignite.lang.IgnitePredicate;
2427
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
2528
import org.slf4j.Logger;
2629
import org.slf4j.LoggerFactory;
@@ -88,8 +91,7 @@ public void start(Options options) {
8891
}
8992

9093
private void preconfigureIgnite(Options options) {
91-
System.setProperty("IGNITE_REST_START_ON_CLIENT", "true");
92-
System.setProperty("java.net.preferIPv4Stack", "true");
94+
System.setProperty("java.net.preferIPv4Stack", "true");
9395
configureIgniteLogger(options);
9496
}
9597

@@ -195,6 +197,9 @@ private void startRuntime(Options options, String nodeType, String mgtnodeIp, St
195197
List<String> cmdList = new ArrayList<>();
196198
cmdList.add("java");
197199

200+
cmdList.add("-Xms512m");
201+
cmdList.add("-Xmx512m");
202+
198203
if (options.getRtJvmOptions() != null) {
199204
StringTokenizer st = new StringTokenizer(options.getRtJvmOptions(), " ");
200205
int tokens = st.countTokens();
@@ -479,7 +484,7 @@ private String tryToGetDeployPlanChecksum(String address, int port) {
479484

480485
return null;
481486
}
482-
487+
483488
private void joinCluster(Options options) {
484489
logger.info("Application node is trying to join the cluster...");
485490

@@ -489,6 +494,14 @@ private void joinCluster(Options options) {
489494

490495
configuration.setClientMode(true);
491496
TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
497+
discoverySpi.setAddressFilter(new IgnitePredicate<InetSocketAddress>() {
498+
private static final long serialVersionUID = 854489733198861318L;
499+
500+
@Override
501+
public boolean apply(InetSocketAddress address) {
502+
return address.getAddress() instanceof Inet4Address;
503+
}
504+
});
492505
configuration.setDiscoverySpi(discoverySpi);
493506

494507
Ignition.start(configuration);

cluster/node/commons/src/main/java/com/thefirstlineofcode/granite/cluster/node/commons/options/AbstractOptionsTool.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public T parseOptions(String[] args) {
8787
}
8888

8989
T options = readAndMergeConfigFile(commandLineOptions, new File(configurationDir, configFileName));
90-
9190
options.setHomeDir(homeDirPath);
9291

9392
return options;
@@ -112,29 +111,28 @@ protected String getHomeDir() {
112111
}
113112

114113
private T readAndMergeConfigFile(Map<String, String> commandLineOptions, File configFile) {
115-
if (!configFile.exists() || !configFile.isFile()) {
116-
throw new IllegalArgumentException(String.format("Configuration file '%s' doesn't exist or it isn't a file.", configFile.getPath()));
117-
}
118-
119-
Properties config = new Properties();
120-
try {
121-
config.load(configFile.toURI().toURL().openStream());
122-
} catch (Exception e) {
123-
throw new IllegalArgumentException("Can't read configuration file.");
124-
}
125-
126114
T options = createOptions();
127-
for (Map.Entry<Object, Object> entry : config.entrySet()) {
128-
String name = (String)entry.getKey();
129-
String value = (String)entry.getValue();
130-
131-
OptionRule rule = optionRules.get(name);
132-
if (rule == null || rule.getRange() == OptionRule.Range.COMMAND_LINE) {
133-
throw new IllegalArgumentException(String.format("Illegal configuration item '%s' from configuration file %s.",
134-
name, configFile));
115+
116+
if (configFile.exists() && configFile.isFile()) {
117+
Properties config = new Properties();
118+
try {
119+
config.load(configFile.toURI().toURL().openStream());
120+
} catch (Exception e) {
121+
throw new IllegalArgumentException("Can't read configuration file.");
135122
}
136123

137-
rule.getOptionSetter().setOption(options, name, replaceReferences(value));
124+
for (Map.Entry<Object, Object> entry : config.entrySet()) {
125+
String name = (String)entry.getKey();
126+
String value = (String)entry.getValue();
127+
128+
OptionRule rule = optionRules.get(name);
129+
if (rule == null || rule.getRange() == OptionRule.Range.COMMAND_LINE) {
130+
throw new IllegalArgumentException(String.format("Illegal configuration item '%s' from configuration file %s.",
131+
name, configFile));
132+
}
133+
134+
rule.getOptionSetter().setOption(options, name, replaceReferences(value));
135+
}
138136
}
139137

140138
List<String> usedOptions = new ArrayList<>();
@@ -157,7 +155,7 @@ private T readAndMergeConfigFile(Map<String, String> commandLineOptions, File co
157155

158156
return options;
159157
}
160-
158+
161159
private String replaceReferences(String value) {
162160
// TODO replace references of value
163161
return value;

cluster/node/mgtnode/configuration/mgtnode.ini

Lines changed: 0 additions & 1 deletion
This file was deleted.

cluster/node/mgtnode/src/main/java/com/thefirstlineofcode/granite/cluster/node/mgtnode/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void main(String[] args) throws Exception {
3636
}
3737

3838
// Set log directory for logback(see logback.xml)
39-
System.setProperty("mgtnode.logs.dir", options.getHomeDir() + "/logs");
39+
System.setProperty("mgtnode.logs.dir", options.getConfigurationDir() + "/logs");
4040

4141
if (options.isLanucherRunMode()) {
4242
lanuch(args, options);
@@ -46,7 +46,7 @@ public static void main(String[] args) throws Exception {
4646
throw new RuntimeException(String.format("Unknown run mode: %s.", options.getRunMode()));
4747
}
4848
}
49-
49+
5050
private static void lanuch(String[] args, Options options) {
5151
String javaVersion = System.getProperty("java.version");
5252
if (!javaVersion.startsWith("11.") && !javaVersion.startsWith("17.")) {

cluster/node/mgtnode/src/main/java/com/thefirstlineofcode/granite/cluster/node/mgtnode/Starter.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Starter {
3636
private static final String FILE_NAME_DEPLOY_PLAN = "deploy-plan.ini";
3737

3838
// Jetty HTTP Server
39-
private Server server;
39+
private Server httpServer;
4040
private ConsoleThread consoleThread;
4141

4242
public boolean start(Options options) throws Exception {
@@ -53,7 +53,7 @@ public boolean start(Options options) throws Exception {
5353
wait();
5454
}
5555

56-
if (server.isStarted()) {
56+
if (httpServer.isStarted()) {
5757
logger.info("HTTP Server has started.");
5858
} else {
5959
logger.error("Can't start HTTP Server.");
@@ -285,14 +285,14 @@ private String readCommand(BufferedReader in) throws IOException {
285285
}
286286

287287
private void exitSystem() {
288-
if (server != null) {
288+
if (httpServer != null) {
289289
try {
290-
server.stop();
290+
httpServer.stop();
291291
} catch (Exception e) {
292292
e.printStackTrace();
293293
}
294294

295-
server.destroy();
295+
httpServer.destroy();
296296
}
297297

298298
if (consoleThread != null) {
@@ -309,11 +309,11 @@ private void printConsoleHelp() {
309309
System.out.print("$");
310310
}
311311

312+
@SuppressWarnings("deprecation")
312313
private boolean joinCluster(Options options) {
313314
logger.info("Management node is trying to join the cluster...");
314315

315-
configureJavaUtilLogging(options);
316-
316+
configureIgniteLogger(options);
317317
System.setProperty("java.net.preferIPv4Stack", "true");
318318

319319
try {
@@ -338,11 +338,12 @@ private boolean joinCluster(Options options) {
338338
}
339339

340340
}
341-
342-
private void configureJavaUtilLogging(Options options) {
341+
342+
private static void configureIgniteLogger(Options options) {
343343
System.setProperty("java.util.logging.config.file", options.getConfigurationDir() + "/java_util_logging.ini");
344344
}
345345

346+
346347
private void startJettyServer(Options options) throws Exception {
347348
Thread httpServerThread = new Thread(new HttpServerThread(options), "Management Node HTTP Server Thread");
348349
httpServerThread.start();
@@ -358,23 +359,23 @@ public HttpServerThread(Options options) {
358359
@Override
359360
public void run() {
360361
try {
361-
server = new Server(options.getHttpPort());
362+
httpServer = new Server(options.getHttpPort());
362363

363364
HandlerList contextHandlers = new HandlerList();
364365
contextHandlers.setHandlers(new Handler[] {createDeployContextHandler(), createRuntimesContextHandler()});
365366

366-
server.setHandler(contextHandlers);
367+
httpServer.setHandler(contextHandlers);
367368
logger.info("Starting HTTP Server...");
368-
server.start();
369-
server.dumpStdErr();
369+
httpServer.start();
370+
httpServer.dumpStdErr();
370371
logger.info("HTTP Server has started on port {}.", options.getHttpPort());
371372
} catch (Exception e) {
372373
try {
373-
server.stop();
374+
httpServer.stop();
374375
} catch (Exception e1) {
375376
logger.error("Can't stop http server.", e);
376377
}
377-
server.destroy();
378+
httpServer.destroy();
378379
logger.error("Some exceptions occurred in http server thread. System will exit.", e);
379380
} finally {
380381
synchronized (Starter.this) {

cluster/pipeline/src/main/java/com/thefirstlineofcode/granite/cluster/pipeline/IgniteFactoryBean.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
import org.apache.ignite.Ignite;
1818
import org.apache.ignite.Ignition;
1919
import org.apache.ignite.cache.CacheAtomicityMode;
20+
import org.apache.ignite.cluster.ClusterState;
2021
import org.apache.ignite.configuration.CacheConfiguration;
2122
import org.apache.ignite.configuration.DataRegionConfiguration;
2223
import org.apache.ignite.configuration.DataStorageConfiguration;
2324
import org.apache.ignite.configuration.IgniteConfiguration;
24-
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsConsistentIdProcessor;
25+
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver;
2526
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
2627
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder;
2728
import org.pf4j.PluginWrapper;
@@ -75,7 +76,7 @@ private Ignite startIgnite() {
7576
Ignite ignite = Ignition.start(igniteConfiguration);
7677

7778
if (isSessionPersistenceEnabled()) {
78-
ignite.active(true);
79+
ignite.cluster().state(ClusterState.ACTIVE);
7980
}
8081

8182
return ignite;
@@ -144,7 +145,7 @@ private void deletePersistedSessionData() throws IOException {
144145

145146
String storagePath = dataStorageConfiguration.getStoragePath();
146147
if (storagePath == null)
147-
storagePath = PdsConsistentIdProcessor.DB_DEFAULT_FOLDER;
148+
storagePath = PdsFolderResolver.DB_DEFAULT_FOLDER;
148149

149150
if (storagePath.startsWith("/")) {
150151
IoUtils.deleteFileRecursively(new File(storagePath));

cluster/pipeline/src/main/java/com/thefirstlineofcode/granite/cluster/pipeline/LocalNodeIdProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.thefirstlineofcode.granite.cluster.pipeline;
22

33
import org.apache.ignite.Ignite;
4+
import org.apache.ignite.configuration.AtomicConfiguration;
45
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
67

@@ -26,7 +27,9 @@ public String getLocalNodeId() {
2627
if (localNodeId != null)
2728
return localNodeId;
2829

29-
localNodeId = Long.toString(ignite.atomicSequence("node-sequence", 0, true).getAndAdd(1));
30+
AtomicConfiguration configuration = new AtomicConfiguration();
31+
configuration.setBackups(0);
32+
localNodeId = Long.toString(ignite.atomicSequence("node-sequence", configuration, 0, true).getAndAdd(1));
3033
logger.info("Cluster node '{}' is assigned to a local node ID: {}.", ignite.cluster().localNode().id().toString(), localNodeId);
3134
}
3235

0 commit comments

Comments
 (0)