Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.2.2 BACKPORT] Enable instance tracking by default for NLC builds #19278

Merged
merged 2 commits into from Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -41,4 +41,8 @@ public static NetworkConfig getActiveMemberNetworkConfig(Config config) {
public static ServicesConfig getServicesConfig(Config config) {
return config.getServicesConfig();
}

public static boolean isInstanceTrackingEnabledSet(Config config) {
return config.getInstanceTrackingConfig().isEnabledSet;
}
}
Expand Up @@ -16,6 +16,10 @@

package com.hazelcast.config;

import com.hazelcast.internal.util.EmptyStatement;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
Expand All @@ -41,16 +45,24 @@ public class InstanceTrackingConfig {
*/
public static final Path DEFAULT_FILE = Paths.get(System.getProperty("java.io.tmpdir"), "Hazelcast.process");

/**
* Default setting whether instance tracking should be enabled or not.
* It depends on whether the instance is an OEM/NLC build or not.
*/
public static final boolean DEFAULT_ENABLED = isOEMBuild();

/**
* Namespace for the placeholders in the file name and format pattern to
* distinguish between different types of placeholders.
*/
public static final String PLACEHOLDER_NAMESPACE = "HZ_INSTANCE_TRACKING";

private boolean enabled;
private boolean enabled = DEFAULT_ENABLED;
private String fileName;
private String formatPattern;

boolean isEnabledSet;

public InstanceTrackingConfig() {
super();
}
Expand All @@ -76,6 +88,7 @@ public boolean isEnabled() {
*/
public InstanceTrackingConfig setEnabled(boolean enabled) {
this.enabled = enabled;
this.isEnabledSet = true;
return this;
}

Expand Down Expand Up @@ -311,4 +324,21 @@ public String getModeName() {
return modeName;
}
}

/**
* Returns whether this build is an OEM/NLC build or not.
*/
private static boolean isOEMBuild() {
try {
Class<?> helper = Class.forName("com.hazelcast.license.util.LicenseHelper");
Method getLicense = helper.getMethod("getBuiltInLicense");
// enabled for OEM/NLC build
return getLicense.invoke(null) != null;
} catch (ClassNotFoundException | NoSuchMethodException
| IllegalAccessException | InvocationTargetException e) {
// running OS, instance tracking is disabled by default
EmptyStatement.ignore(e);
}
return false;
}
}
Expand Up @@ -48,6 +48,7 @@
import static com.hazelcast.internal.config.DomConfigHelper.cleanNodeName;
import static com.hazelcast.internal.config.DomConfigHelper.getBooleanValue;
import static com.hazelcast.internal.config.DomConfigHelper.getIntegerValue;
import static com.hazelcast.internal.util.StringUtil.isNullOrEmptyAfterTrim;
import static com.hazelcast.internal.util.StringUtil.upperCaseInternal;

/**
Expand Down Expand Up @@ -404,8 +405,10 @@ protected LoginModuleConfig handleLoginModule(Node node) {

protected void handleInstanceTracking(Node node, InstanceTrackingConfig trackingConfig) {
Node attrEnabled = getNamedItemNode(node, "enabled");
boolean enabled = getBooleanValue(getTextContent(attrEnabled));
trackingConfig.setEnabled(enabled);
String textContent = getTextContent(attrEnabled);
if (!isNullOrEmptyAfterTrim(textContent)) {
trackingConfig.setEnabled(getBooleanValue(textContent));
}

for (Node n : childElements(node)) {
final String name = cleanNodeName(n);
Expand Down
4 changes: 0 additions & 4 deletions hazelcast/src/main/resources/hazelcast-default.xml
Expand Up @@ -329,10 +329,6 @@
<collection-frequency-seconds>5</collection-frequency-seconds>
</metrics>

<instance-tracking enabled="false">

</instance-tracking>

<sql>
<executor-pool-size>-1</executor-pool-size>
<statement-timeout-millis>0</statement-timeout-millis>
Expand Down
3 changes: 0 additions & 3 deletions hazelcast/src/main/resources/hazelcast-default.yaml
Expand Up @@ -331,9 +331,6 @@ hazelcast:
enabled: true
collection-frequency-seconds: 5

instance-tracking:
enabled: false

sql:
executor-pool-size: -1
statement-timeout-millis: 0