use of fish.payara.nucleus.hazelcast.HazelcastConfigSpecificConfiguration in project Payara by payara.
the class GetHazelcastConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config named: " + target);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
HazelcastConfigSpecificConfiguration nodeConfiguration = config.getExtensionByType(HazelcastConfigSpecificConfiguration.class);
HazelcastRuntimeConfiguration runtimeConfiguration = domain.getExtensionByType(HazelcastRuntimeConfiguration.class);
final ActionReport actionReport = context.getActionReport();
if (checkEncrypted) {
if (!Boolean.parseBoolean(runtimeConfiguration.getDatagridEncryptionEnabled())) {
actionReport.setMessage("Data Grid Not Encrypted");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
} else {
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
return;
}
String[] headers = { "Property Name", "PropertyValue", "Scope" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
columnFormatter.addRow(new Object[] { "Configuration File", runtimeConfiguration.getHazelcastConfigurationFile(), "Domain" });
columnFormatter.addRow(new Object[] { "Interfaces", runtimeConfiguration.getInterface(), "Domain" });
columnFormatter.addRow(new Object[] { "Auto Increment Port", runtimeConfiguration.getAutoIncrementPort(), "Domain" });
columnFormatter.addRow(new Object[] { "Start Port", runtimeConfiguration.getStartPort(), "Domain" });
columnFormatter.addRow(new Object[] { "Cluster Name", runtimeConfiguration.getClusterGroupName(), "Domain" });
columnFormatter.addRow(new Object[] { "License Key", runtimeConfiguration.getLicenseKey(), "Domain" });
columnFormatter.addRow(new Object[] { "Host Aware Partitioning", runtimeConfiguration.getHostAwarePartitioning(), "Domain" });
columnFormatter.addRow(new Object[] { "DAS Public Address", runtimeConfiguration.getDASPublicAddress(), "Domain" });
columnFormatter.addRow(new Object[] { "DAS Bind Address", runtimeConfiguration.getDASBindAddress(), "Domain" });
columnFormatter.addRow(new Object[] { "DAS Port", runtimeConfiguration.getDasPort(), "Domain" });
columnFormatter.addRow(new Object[] { "Cluster Mode", runtimeConfiguration.getDiscoveryMode(), "Domain" });
columnFormatter.addRow(new Object[] { "Tcpip Members", runtimeConfiguration.getTcpipMembers(), "Domain" });
columnFormatter.addRow(new Object[] { "DNS Members", runtimeConfiguration.getDnsMembers(), "Domain" });
columnFormatter.addRow(new Object[] { "MulticastGroup", runtimeConfiguration.getMulticastGroup(), "Domain" });
columnFormatter.addRow(new Object[] { "MulticastPort", runtimeConfiguration.getMulticastPort(), "Domain" });
columnFormatter.addRow(new Object[] { "Kubernetes Namespace", runtimeConfiguration.getKubernetesNamespace(), "Domain" });
columnFormatter.addRow(new Object[] { "Kubernetes Service Name", runtimeConfiguration.getKubernetesServiceName(), "Domain" });
columnFormatter.addRow(new Object[] { "Encrypt Datagrid", runtimeConfiguration.getDatagridEncryptionEnabled(), "Domain" });
columnFormatter.addRow(new Object[] { "Enabled", nodeConfiguration.getEnabled(), "Config" });
columnFormatter.addRow(new Object[] { "JNDIName", nodeConfiguration.getJNDIName(), "Config" });
columnFormatter.addRow(new Object[] { "Cache Manager JNDI Name", nodeConfiguration.getCacheManagerJNDIName(), "Config" });
columnFormatter.addRow(new Object[] { "Caching Provider JNDI Name", nodeConfiguration.getCachingProviderJNDIName(), "Config" });
columnFormatter.addRow(new Object[] { "Lite Member", nodeConfiguration.getLite(), "Config" });
columnFormatter.addRow(new Object[] { "Member Name", nodeConfiguration.getMemberName(), "Config" });
columnFormatter.addRow(new Object[] { "Member Group", nodeConfiguration.getMemberGroup(), "Config" });
columnFormatter.addRow(new Object[] { "Executor Pool Size", nodeConfiguration.getExecutorPoolSize(), "Config" });
columnFormatter.addRow(new Object[] { "Executor Queue Capacity", nodeConfiguration.getExecutorQueueCapacity(), "Config" });
columnFormatter.addRow(new Object[] { "Scheduled Executor Pool Size", nodeConfiguration.getScheduledExecutorPoolSize(), "Config" });
columnFormatter.addRow(new Object[] { "Scheduled Executor Queue Capacity", nodeConfiguration.getScheduledExecutorQueueCapacity(), "Config" });
columnFormatter.addRow(new Object[] { "Public Address", nodeConfiguration.getPublicAddress(), "Config" });
columnFormatter.addRow(new Object[] { "Config Specific Data Grid Start Port", nodeConfiguration.getConfigSpecificDataGridStartPort(), "Config" });
Map<String, Object> map = new HashMap<>(26);
Properties extraProps = new Properties();
map.put("hazelcastConfigurationFile", runtimeConfiguration.getHazelcastConfigurationFile());
map.put("enabled", nodeConfiguration.getEnabled());
map.put("autoIncrementPort", runtimeConfiguration.getAutoIncrementPort());
map.put("startPort", runtimeConfiguration.getStartPort());
map.put("multicastGroup", runtimeConfiguration.getMulticastGroup());
map.put("multicastPort", runtimeConfiguration.getMulticastPort());
map.put("jndiName", nodeConfiguration.getJNDIName());
map.put("lite", nodeConfiguration.getLite());
map.put("clusterName", runtimeConfiguration.getClusterGroupName());
map.put("licenseKey", runtimeConfiguration.getLicenseKey());
map.put("hostAwarePartitioning", runtimeConfiguration.getHostAwarePartitioning());
map.put("dasPublicAddress", runtimeConfiguration.getDASPublicAddress());
map.put("dasBindAddress", runtimeConfiguration.getDASBindAddress());
map.put("dasPort", runtimeConfiguration.getDasPort());
map.put("tcpipMembers", runtimeConfiguration.getTcpipMembers());
map.put("dnsMembers", runtimeConfiguration.getDnsMembers());
map.put("clusterMode", runtimeConfiguration.getDiscoveryMode());
map.put("memberName", nodeConfiguration.getMemberName());
map.put("memberGroup", nodeConfiguration.getMemberGroup());
map.put("interfaces", runtimeConfiguration.getInterface());
map.put("cacheManagerJndiName", nodeConfiguration.getCacheManagerJNDIName());
map.put("cachingProviderJndiName", nodeConfiguration.getCachingProviderJNDIName());
map.put("executorPoolSize", nodeConfiguration.getExecutorPoolSize());
map.put("executorQueueCapacity", nodeConfiguration.getExecutorQueueCapacity());
map.put("scheduledExecutorPoolSize", nodeConfiguration.getScheduledExecutorPoolSize());
map.put("scheduledExecutorQueueCapacity", nodeConfiguration.getScheduledExecutorQueueCapacity());
map.put("publicAddress", nodeConfiguration.getPublicAddress());
map.put("kubernetesNamespace", runtimeConfiguration.getKubernetesNamespace());
map.put("kubernetesServiceName", runtimeConfiguration.getKubernetesServiceName());
map.put("configSpecificDataGridStartPort", nodeConfiguration.getConfigSpecificDataGridStartPort());
map.put("encryptDatagrid", runtimeConfiguration.getDatagridEncryptionEnabled());
extraProps.put("getHazelcastConfiguration", map);
actionReport.setExtraProperties(extraProps);
actionReport.setMessage(columnFormatter.toString());
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of fish.payara.nucleus.hazelcast.HazelcastConfigSpecificConfiguration in project Payara by payara.
the class SetHazelcastConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Properties extraProperties = actionReport.getExtraProperties();
if (extraProperties == null) {
extraProperties = new Properties();
actionReport.setExtraProperties(extraProperties);
}
if (!validate(actionReport)) {
return;
}
HazelcastRuntimeConfiguration hazelcastRuntimeConfiguration = domain.getExtensionByType(HazelcastRuntimeConfiguration.class);
if (hazelcastRuntimeConfiguration != null) {
try {
ConfigSupport.apply(new SingleConfigCode<HazelcastRuntimeConfiguration>() {
@Override
public Object run(final HazelcastRuntimeConfiguration hazelcastRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
if (startPort != null) {
hazelcastRuntimeConfigurationProxy.setStartPort(startPort);
}
if (multiCastGroup != null) {
hazelcastRuntimeConfigurationProxy.setMulticastGroup(multiCastGroup);
}
if (multicastPort != null) {
hazelcastRuntimeConfigurationProxy.setMulticastPort(multicastPort);
}
if (configFile != null) {
hazelcastRuntimeConfigurationProxy.setHazelcastConfigurationFile(configFile);
}
if (hostawarePartitioning != null) {
hazelcastRuntimeConfigurationProxy.setHostAwarePartitioning(hostawarePartitioning.toString());
}
if (hzClusterName != null) {
hazelcastRuntimeConfigurationProxy.setClusterGroupName(hzClusterName);
}
if (licenseKey != null) {
hazelcastRuntimeConfigurationProxy.setLicenseKey(licenseKey);
}
if (dasPublicAddress != null) {
hazelcastRuntimeConfigurationProxy.setDASPublicAddress(dasPublicAddress);
}
if (dasBindAddress != null) {
hazelcastRuntimeConfigurationProxy.setDASBindAddress(dasBindAddress);
}
if (dasPort != null) {
hazelcastRuntimeConfigurationProxy.setDasPort(dasPort);
}
if (clusterMode != null) {
hazelcastRuntimeConfigurationProxy.setDiscoveryMode(clusterMode);
}
if (tcpipMembers != null) {
hazelcastRuntimeConfigurationProxy.setTcpipMembers(tcpipMembers);
}
if (dnsMembers != null) {
hazelcastRuntimeConfigurationProxy.setDnsMembers(dnsMembers);
}
if (interfaces != null) {
hazelcastRuntimeConfigurationProxy.setInterface(interfaces);
}
if (kubernetesNamespace != null) {
hazelcastRuntimeConfigurationProxy.setKubernetesNamespace(kubernetesNamespace);
}
if (kubernetesServiceName != null) {
hazelcastRuntimeConfigurationProxy.setKubernetesServiceName(kubernetesServiceName);
}
if (autoIncrementPort != null) {
hazelcastRuntimeConfigurationProxy.setAutoIncrementPort(autoIncrementPort.toString());
}
if (encryptDatagrid != null) {
hazelcastRuntimeConfigurationProxy.setDatagridEncryptionEnabled(encryptDatagrid.toString());
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return null;
}
}, hazelcastRuntimeConfiguration);
// get the configs that need the change applied if target is domain it is all configs
Config config = targetUtil.getConfig(target);
List<Config> configsToApply = new ArrayList<>(5);
if (config == null && target.equals("domain")) {
configsToApply.addAll(domain.getConfigs().getConfig());
} else if (config != null) {
configsToApply.add(config);
}
for (Config configToApply : configsToApply) {
HazelcastConfigSpecificConfiguration nodeConfiguration = configToApply.getExtensionByType(HazelcastConfigSpecificConfiguration.class);
ConfigSupport.apply(new SingleConfigCode<HazelcastConfigSpecificConfiguration>() {
@Override
public Object run(final HazelcastConfigSpecificConfiguration hazelcastRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
if (jndiName != null) {
hazelcastRuntimeConfigurationProxy.setJNDIName(jndiName);
}
if (enabled != null) {
hazelcastRuntimeConfigurationProxy.setEnabled(enabled.toString());
}
if (lite != null) {
hazelcastRuntimeConfigurationProxy.setLite(lite.toString());
}
if (cacheManagerJndiName != null) {
hazelcastRuntimeConfigurationProxy.setCacheManagerJNDIName(cacheManagerJndiName);
}
if (cachingProviderJndiName != null) {
hazelcastRuntimeConfigurationProxy.setCachingProviderJNDIName(cachingProviderJndiName);
}
if (executorPoolSize != null) {
hazelcastRuntimeConfigurationProxy.setExecutorPoolSize(executorPoolSize);
}
if (executorQueueCapacity != null) {
hazelcastRuntimeConfigurationProxy.setExecutorQueueCapacity(executorQueueCapacity);
}
if (scheduledExecutorPoolSize != null) {
hazelcastRuntimeConfigurationProxy.setScheduledExecutorPoolSize(scheduledExecutorPoolSize);
}
if (scheduledExecutorQueueCapacity != null) {
hazelcastRuntimeConfigurationProxy.setScheduledExecutorQueueCapacity(scheduledExecutorQueueCapacity);
}
if (memberName != null) {
hazelcastRuntimeConfigurationProxy.setMemberName(memberName);
}
if (memberGroup != null) {
hazelcastRuntimeConfigurationProxy.setMemberGroup(memberGroup);
}
if (publicAddress != null) {
hazelcastRuntimeConfigurationProxy.setPublicAddress(publicAddress);
}
if (configSpecificDataGridStartPort != null) {
if (!configToApply.isDas()) {
hazelcastRuntimeConfigurationProxy.setConfigSpecificDataGridStartPort(configSpecificDataGridStartPort);
}
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return null;
}
}, nodeConfiguration);
}
} catch (TransactionFailure ex) {
logger.log(Level.WARNING, "Exception during command ", ex);
Throwable cause = ex.getCause();
if (cause != null) {
actionReport.setMessage(ex.getCause().getMessage());
} else {
actionReport.setMessage(ex.getMessage());
}
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (dynamic) {
boolean isEnabled = false;
if (enabled != null) {
isEnabled = enabled;
} else {
isEnabled = hazelcast.isEnabled();
}
// this command runs on all instances so they can update their configuration.
if ("domain".equals(target)) {
hazelcast.setEnabled(isEnabled);
} else {
for (Server targetServer : targetUtil.getInstances(target)) {
if (server.getInstanceName().equals(targetServer.getName())) {
hazelcast.setEnabled(isEnabled);
}
}
}
}
if (encryptDatagrid != null && encryptDatagrid) {
checkForDatagridKey(actionReport);
}
}
}
Aggregations