From 9fcd8db2b9b707bd1bcb7f953e16036f44cf3453 Mon Sep 17 00:00:00 2001 From: lprimak Date: Tue, 8 Dec 2020 12:29:14 -0600 Subject: [PATCH] Upgrade Payara to Hazelcast 4.1 --- .../HazelcastPersistenceService.java | 14 +-- .../ClusteredSingletonLookupImplBase.java | 18 ++-- .../common/spi/ClusteredSingletonLookup.java | 8 +- .../AbstractSingletonContainer.java | 4 +- .../ejb/containers/CMCSingletonContainer.java | 22 ++++- .../fish/payara/micro/PayaraInstance.java | 13 +-- .../payara/micro/data/InstanceDescriptor.java | 5 +- .../micro/impl/PayaraMicroRuntimeImpl.java | 31 +++---- .../store/HazelcastBackingStore.java | 2 +- .../runtime/MonitoringConsoleRuntimeImpl.java | 2 +- .../HazelcastTopicRemoteConnection.java | 3 +- .../timer/hazelcast/HazelcastTimerStore.java | 62 ++++++------- .../mphealth/MicroProfileHealthChecker.java | 3 +- .../cluster/ClusterScopedInterceptor.java | 2 +- .../micro/services/PayaraInstanceImpl.java | 21 ++--- .../services/asadmin/SendAsadminCommand.java | 17 ++-- .../services/data/InstanceDescriptorImpl.java | 13 +-- .../payara/nucleus/cluster/MemberEvent.java | 18 ++-- .../payara/nucleus/cluster/PayaraCluster.java | 54 ++++++------ .../nucleus/config/ClusteredConfig.java | 15 ++-- .../payara/nucleus/eventbus/EventBus.java | 7 +- .../nucleus/eventbus/TopicListener.java | 16 ++-- .../nucleus/exec/ClusterExecutionService.java | 29 +++--- .../hazelcast/DnsDiscoveryService.java | 6 +- .../hazelcast/DomainDiscoveryService.java | 9 +- .../DomainDiscoveryServiceProvider.java | 60 ------------- .../nucleus/hazelcast/HazelcastCore.java | 88 ++++++++++++++----- .../hazelcast/PayaraHazelcastSerializer.java | 2 +- .../hazelcast/PayaraMicroNameGenerator.java | 9 +- .../nucleus/hazelcast/admin/ClearCache.java | 4 +- .../hazelcast/admin/ListCacheKeys.java | 8 +- .../nucleus/hazelcast/admin/ListCaches.java | 4 +- .../hazelcast/admin/ListHazelcastMembers.java | 8 +- .../HazelcastSymmetricEncryptor.java | 2 +- .../payara/nucleus/store/ClusteredStore.java | 7 +- .../cpool/ConnectionPoolHealthCheck.java | 4 +- pom.xml | 4 +- 37 files changed, 306 insertions(+), 288 deletions(-) delete mode 100644 nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DomainDiscoveryServiceProvider.java diff --git a/appserver/batch/hazelcast-jbatch-store/src/main/java/fish/payara/jbatch/persistence/hazelcast/HazelcastPersistenceService.java b/appserver/batch/hazelcast-jbatch-store/src/main/java/fish/payara/jbatch/persistence/hazelcast/HazelcastPersistenceService.java index 4956d225769..c87919b3d8c 100644 --- a/appserver/batch/hazelcast-jbatch-store/src/main/java/fish/payara/jbatch/persistence/hazelcast/HazelcastPersistenceService.java +++ b/appserver/batch/hazelcast-jbatch-store/src/main/java/fish/payara/jbatch/persistence/hazelcast/HazelcastPersistenceService.java @@ -1,7 +1,7 @@ /* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - Copyright (c) 2016 Payara Foundation and/or its affiliates. All rights reserved. + Copyright (c) 2016-2020 Payara Foundation and/or its affiliates. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You @@ -17,8 +17,8 @@ and Distribution License("CDDL") (collectively, the "License"). You package fish.payara.jbatch.persistence.hazelcast; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; -import com.hazelcast.core.IdGenerator; +import com.hazelcast.flakeidgen.FlakeIdGenerator; +import com.hazelcast.map.IMap; import com.ibm.jbatch.container.context.impl.StepContextImpl; import com.ibm.jbatch.container.jobinstance.JobInstanceImpl; import com.ibm.jbatch.container.jobinstance.RuntimeFlowInSplitExecution; @@ -56,8 +56,8 @@ public class HazelcastPersistenceService implements IPersistenceManagerService{ private IMap jobInstanceMap; private IMap checkpointMAP; private HazelcastInstance theInstance; - private IdGenerator jobInstanceIdGenerator; - private IdGenerator checkpointIdGenerator; + private FlakeIdGenerator jobInstanceIdGenerator; + private FlakeIdGenerator checkpointIdGenerator; @Override public int jobOperatorGetJobInstanceCount(String jobName) { @@ -274,8 +274,8 @@ public void init(IBatchConfig batchConfig) { theInstance = HazelcastInstance.class.cast(ctx.lookup(hazelcastJNDIName)); jobInstanceMap = theInstance.getMap(JOB_INSTANCE_MAP); checkpointMAP = theInstance.getMap(CHECKPOINTMAP); - jobInstanceIdGenerator = theInstance.getIdGenerator(JOB_INSTANCE_MAP+"ID"); - checkpointIdGenerator = theInstance.getIdGenerator(CHECKPOINTMAP + "ID"); + jobInstanceIdGenerator = theInstance.getFlakeIdGenerator(JOB_INSTANCE_MAP+"ID"); + checkpointIdGenerator = theInstance.getFlakeIdGenerator(CHECKPOINTMAP + "ID"); } catch (NamingException ex) { Logger.getLogger(HazelcastPersistenceService.class.getName()).log(Level.SEVERE, "Unable to find the Hazelcast Instance for JBatch Persistence", ex); } diff --git a/appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/util/ClusteredSingletonLookupImplBase.java b/appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/util/ClusteredSingletonLookupImplBase.java index e4828842ff6..2a0d78d6daa 100644 --- a/appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/util/ClusteredSingletonLookupImplBase.java +++ b/appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/util/ClusteredSingletonLookupImplBase.java @@ -41,9 +41,9 @@ package com.sun.enterprise.container.common.impl.util; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IAtomicLong; -import com.hazelcast.core.ILock; -import com.hazelcast.core.IMap; +import com.hazelcast.cp.IAtomicLong; +import com.hazelcast.cp.lock.FencedLock; +import com.hazelcast.map.IMap; import com.sun.enterprise.container.common.spi.ClusteredSingletonLookup; import fish.payara.nucleus.hazelcast.HazelcastCore; @@ -63,7 +63,7 @@ public abstract class ClusteredSingletonLookupImplBase implements ClusteredSingl private final String keyPrefix; private final String mapKey; private final AtomicReference sessionHzKey = new AtomicReference<>(); - private final AtomicReference lock = new AtomicReference<>(); + private final AtomicReference lock = new AtomicReference<>(); private final AtomicReference count = new AtomicReference<>(); @@ -87,8 +87,9 @@ public final String getSessionHzKey() { } @Override - public ILock getDistributedLock() { - return lock.updateAndGet(v -> v != null ? v : getHazelcastInstance().getLock(makeLockKey())); + public FencedLock getDistributedLock() { + return lock.updateAndGet(v -> v != null ? v : getHazelcastInstance().getCPSubsystem() + .getLock(makeLockKey())); } @Override @@ -97,8 +98,9 @@ public IMap getClusteredSingletonMap() { } @Override - public IAtomicLong getClusteredUsageCount() { - return count.updateAndGet(v -> v != null ? v : getHazelcastInstance().getAtomicLong(makeCountKey())); + public IAtomicLong getClusteredUsageCount() { + return count.updateAndGet(v -> v != null ? v : getHazelcastInstance().getCPSubsystem() + .getAtomicLong(makeCountKey())); } private HazelcastInstance getHazelcastInstance() { diff --git a/appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/spi/ClusteredSingletonLookup.java b/appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/spi/ClusteredSingletonLookup.java index caa8fc667d0..19fae268c37 100644 --- a/appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/spi/ClusteredSingletonLookup.java +++ b/appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/spi/ClusteredSingletonLookup.java @@ -39,9 +39,9 @@ */ package com.sun.enterprise.container.common.spi; -import com.hazelcast.core.IAtomicLong; -import com.hazelcast.core.ILock; -import com.hazelcast.core.IMap; +import com.hazelcast.cp.IAtomicLong; +import com.hazelcast.cp.lock.FencedLock; +import com.hazelcast.map.IMap; import fish.payara.nucleus.hazelcast.HazelcastCore; /** @@ -51,7 +51,7 @@ * @author lprimak */ public interface ClusteredSingletonLookup { - ILock getDistributedLock(); + FencedLock getDistributedLock(); boolean isDistributedLockEnabled(); IMap getClusteredSingletonMap(); String getClusteredSessionKey(); diff --git a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java index 12dfe41829e..cd28f8655c6 100644 --- a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java +++ b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java @@ -41,8 +41,8 @@ package com.sun.ejb.containers; -import com.hazelcast.core.IAtomicLong; -import com.hazelcast.core.IMap; +import com.hazelcast.cp.IAtomicLong; +import com.hazelcast.map.IMap; import com.sun.ejb.ComponentContext; import com.sun.ejb.Container; import com.sun.ejb.EjbInvocation; diff --git a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/CMCSingletonContainer.java b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/CMCSingletonContainer.java index b7a8e566f36..ad3291d856d 100644 --- a/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/CMCSingletonContainer.java +++ b/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/CMCSingletonContainer.java @@ -41,13 +41,17 @@ package com.sun.ejb.containers; +import com.hazelcast.cp.lock.FencedLock; import com.sun.ejb.ComponentContext; import com.sun.ejb.EjbInvocation; import com.sun.ejb.InvocationInfo; import com.sun.ejb.MethodLockInfo; +import static com.sun.ejb.containers.BaseContainer._logger; import com.sun.enterprise.security.SecurityManager; +import java.lang.reflect.Proxy; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.logging.Level; import javax.ejb.ConcurrentAccessException; import javax.ejb.ConcurrentAccessTimeoutException; import javax.ejb.IllegalLoopbackException; @@ -121,7 +125,21 @@ protected ComponentContext _getContext(EjbInvocation inv) { ? defaultMethodLockInfo : invInfo.methodLockInfo; Lock theLock; if(lockInfo.isDistributed()) { - theLock = clusteredLookup.getDistributedLock(); + if (_logger.isLoggable(Level.FINE)) { + // log all lock operations + theLock = (Lock) Proxy.newProxyInstance(loader, new Class[]{Lock.class}, + (proxy, method, args) -> { + FencedLock fencedLock = clusteredLookup.getDistributedLock(); + _logger.log(Level.FINE, "DistributedLock, about to call {0}, Locked: {1}, Locked by Us: {2}, thread ID {3}", + new Object[]{method.getName(), fencedLock.isLocked(), fencedLock.isLockedByCurrentThread(), Thread.currentThread().getId()}); + Object rv = method.invoke(fencedLock, args); + _logger.log(Level.FINE, "DistributedLock, after to call {0}, Locked: {1}, Locked by Us: {2}, thread ID {3}", + new Object[]{method.getName(), fencedLock.isLocked(), fencedLock.isLockedByCurrentThread(), Thread.currentThread().getId()}); + return rv; + }); + } else { + theLock = clusteredLookup.getDistributedLock(); + } } else { theLock = lockInfo.isReadLockedMethod() ? readLock : writeLock; @@ -171,7 +189,7 @@ protected ComponentContext _getContext(EjbInvocation inv) { //Now that we have acquired the lock, remember it inv.setCMCLock(theLock); - + //Now that we have the lock return the singletonCtx return singletonCtx; } diff --git a/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/PayaraInstance.java b/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/PayaraInstance.java index 3cd0581fbf8..5af47d88c03 100644 --- a/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/PayaraInstance.java +++ b/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/PayaraInstance.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2017 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2017-2020 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -47,6 +47,7 @@ import java.util.Collection; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.jvnet.hk2.annotations.Contract; @@ -65,15 +66,15 @@ public interface PayaraInstance { void addCDIListener(CDIEventListener listener); - Map> executeClusteredASAdmin(String command, String... parameters); + Map> executeClusteredASAdmin(String command, String... parameters); - Map> executeClusteredASAdmin(Collection memberGUIDs, String command, String... parameters); + Map> executeClusteredASAdmin(Collection memberGUIDs, String command, String... parameters); ClusterCommandResult executeLocalAsAdmin(String command, String... parameters); Set getClusteredPayaras(); - InstanceDescriptor getDescriptor(String member); + InstanceDescriptor getDescriptor(UUID member); String getInstanceName(); @@ -91,9 +92,9 @@ public interface PayaraInstance { void removeCDIListener(CDIEventListener listener); - Map> runCallable(Collection memberUUIDS, Callable callable); + Map> runCallable(Collection memberUUIDS, Callable callable); - Map> runCallable(Callable callable); + Map> runCallable(Callable callable); void setInstanceName(String instanceName); diff --git a/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/data/InstanceDescriptor.java b/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/data/InstanceDescriptor.java index b04c62dd8bd..76eb53d9468 100644 --- a/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/data/InstanceDescriptor.java +++ b/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/data/InstanceDescriptor.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2020 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -44,6 +44,7 @@ import java.net.URL; import java.util.Collection; import java.util.List; +import java.util.UUID; /** * Class describing an instance of Payara @@ -107,7 +108,7 @@ public interface InstanceDescriptor extends Serializable { /** * @return the memberUUID */ - String getMemberUUID(); + UUID getMemberUUID(); /** * Checks whether or not this instance is described as a Lite Hazelcast diff --git a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroRuntimeImpl.java b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroRuntimeImpl.java index e4011e89972..de06badf0ac 100644 --- a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroRuntimeImpl.java +++ b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroRuntimeImpl.java @@ -2,7 +2,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - Copyright (c) 2016 Payara Foundation. All rights reserved. + Copyright (c) 2016-2020 Payara Foundation. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You @@ -33,6 +33,7 @@ and Distribution License("CDDL") (collectively, the "License"). You import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.logging.Level; @@ -140,10 +141,10 @@ public Map> run (Stri // NEEDS TO HANDLE THE CASE FOR LOCAL RUNNING IF NO CLUSTER ENABLED - Map> commandResult = instanceService.executeClusteredASAdmin(command, args); + Map> commandResult = instanceService.executeClusteredASAdmin(command, args); Map> result = new HashMap<>(commandResult.size()); - for (Entry> entry : commandResult.entrySet()) { - String uuid = entry.getKey(); + for (Entry> entry : commandResult.entrySet()) { + UUID uuid = entry.getKey(); InstanceDescriptor id = instanceService.getDescriptor(uuid); if (id != null) { result.put(id, entry.getValue()); @@ -164,15 +165,15 @@ public Map> run (Stri @Override public Map> run (Collection members, String command, String... args ) { - HashSet memberUUIDs = new HashSet<>(members.size()); + HashSet memberUUIDs = new HashSet<>(members.size()); for (InstanceDescriptor member : members) { memberUUIDs.add(member.getMemberUUID()); } - Map> commandResult = instanceService.executeClusteredASAdmin(memberUUIDs,command, args); + Map> commandResult = instanceService.executeClusteredASAdmin(memberUUIDs,command, args); Map> result = new HashMap<>(commandResult.size()); - for (Entry> entry : commandResult.entrySet()) { - String uuid = entry.getKey(); + for (Entry> entry : commandResult.entrySet()) { + UUID uuid = entry.getKey(); InstanceDescriptor id = instanceService.getDescriptor(uuid); if (id != null) { result.put(id, entry.getValue()); @@ -198,10 +199,10 @@ public Map> run (Callable // NEEDS TO HANDLE THE CASE FOR LOCAL RUNNING IF NO CLUSTER ENABLED - Map> runCallable = instanceService.runCallable(callable); + Map> runCallable = instanceService.runCallable(callable); Map> result = new HashMap<>(runCallable.size()); - for (Entry> entry : runCallable.entrySet()) { - String uuid = entry.getKey(); + for (Entry> entry : runCallable.entrySet()) { + UUID uuid = entry.getKey(); InstanceDescriptor id = instanceService.getDescriptor(uuid); if (id != null) { result.put(id, entry.getValue()); @@ -228,15 +229,15 @@ public Map> run (Callable @Deprecated public Map> run (Collection members, Callable callable) { - HashSet memberUUIDs = new HashSet<>(members.size()); + HashSet memberUUIDs = new HashSet<>(members.size()); for (InstanceDescriptor member : members) { memberUUIDs.add(member.getMemberUUID()); } - Map> runCallable = instanceService.runCallable(memberUUIDs,callable); + Map> runCallable = instanceService.runCallable(memberUUIDs,callable); Map> result = new HashMap<>(runCallable.size()); - for (Entry> entry : runCallable.entrySet()) { - String uuid = entry.getKey(); + for (Entry> entry : runCallable.entrySet()) { + UUID uuid = entry.getKey(); InstanceDescriptor id = instanceService.getDescriptor(uuid); if (id != null) { result.put(id, entry.getValue()); diff --git a/appserver/ha/ha-hazelcast-store/src/main/java/fish/payara/ha/hazelcast/store/HazelcastBackingStore.java b/appserver/ha/ha-hazelcast-store/src/main/java/fish/payara/ha/hazelcast/store/HazelcastBackingStore.java index 4ad9694c00c..e22a14d664e 100644 --- a/appserver/ha/ha-hazelcast-store/src/main/java/fish/payara/ha/hazelcast/store/HazelcastBackingStore.java +++ b/appserver/ha/ha-hazelcast-store/src/main/java/fish/payara/ha/hazelcast/store/HazelcastBackingStore.java @@ -113,6 +113,6 @@ private void init() throws BackingStoreException { if (!clusteredStore.isEnabled()) { throw new BackingStoreException("Hazelcast is not enabled, please enable Hazelcast"); } - instanceName = clusteredStore.getInstanceId(); + instanceName = clusteredStore.getInstanceId().toString(); } } diff --git a/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/runtime/MonitoringConsoleRuntimeImpl.java b/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/runtime/MonitoringConsoleRuntimeImpl.java index 9c2983f873b..15d40a1c51d 100644 --- a/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/runtime/MonitoringConsoleRuntimeImpl.java +++ b/appserver/monitoring-console/core/src/main/java/fish/payara/monitoring/runtime/MonitoringConsoleRuntimeImpl.java @@ -81,7 +81,7 @@ import org.jvnet.hk2.config.UnprocessedChangeEvents; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.ITopic; +import com.hazelcast.topic.ITopic; import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.config.serverbeans.MonitoringService; diff --git a/appserver/payara-appserver-modules/hazelcast-eclipselink-coordination/src/main/java/fish/payara/persistence/eclipselink/cache/coordination/HazelcastTopicRemoteConnection.java b/appserver/payara-appserver-modules/hazelcast-eclipselink-coordination/src/main/java/fish/payara/persistence/eclipselink/cache/coordination/HazelcastTopicRemoteConnection.java index fb6d4190191..4643ba342eb 100644 --- a/appserver/payara-appserver-modules/hazelcast-eclipselink-coordination/src/main/java/fish/payara/persistence/eclipselink/cache/coordination/HazelcastTopicRemoteConnection.java +++ b/appserver/payara-appserver-modules/hazelcast-eclipselink-coordination/src/main/java/fish/payara/persistence/eclipselink/cache/coordination/HazelcastTopicRemoteConnection.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2020 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -39,7 +39,6 @@ */ package fish.payara.persistence.eclipselink.cache.coordination; -import com.hazelcast.core.MessageListener; import fish.payara.nucleus.eventbus.ClusterMessage; import fish.payara.nucleus.eventbus.MessageReceiver; import org.eclipse.persistence.internal.sessions.coordination.broadcast.BroadcastRemoteConnection; diff --git a/appserver/payara-appserver-modules/hazelcast-ejb-timer/src/main/java/fish/payara/ejb/timer/hazelcast/HazelcastTimerStore.java b/appserver/payara-appserver-modules/hazelcast-ejb-timer/src/main/java/fish/payara/ejb/timer/hazelcast/HazelcastTimerStore.java index 49c9ae3f31f..fc0833443e1 100644 --- a/appserver/payara-appserver-modules/hazelcast-ejb-timer/src/main/java/fish/payara/ejb/timer/hazelcast/HazelcastTimerStore.java +++ b/appserver/payara-appserver-modules/hazelcast-ejb-timer/src/main/java/fish/payara/ejb/timer/hazelcast/HazelcastTimerStore.java @@ -40,8 +40,8 @@ package fish.payara.ejb.timer.hazelcast; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.ILock; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; +import com.hazelcast.cp.lock.FencedLock; import com.sun.ejb.containers.BaseContainer; import com.sun.ejb.containers.EJBTimerSchedule; import com.sun.ejb.containers.EJBTimerService; @@ -100,14 +100,14 @@ static void init(HazelcastCore core) { HazelcastTimerStore store = new HazelcastTimerStore(core); Globals.getDefaultBaseServiceLocator().getService(PayaraCluster.class).addClusterListener(store); EJBTimerService.setPersistentTimerService(store); - + } catch (Exception ex) { Logger.getLogger(HazelcastTimerStore.class.getName()).log(Level.WARNING, "Problem when initialising Timer Store", ex); } } public HazelcastTimerStore(HazelcastCore core) throws Exception { - + if (!core.isEnabled()) { throw new Exception("Hazelcast MUST be enabled when using the HazelcastTimerStore"); } @@ -115,9 +115,9 @@ public HazelcastTimerStore(HazelcastCore core) throws Exception { pkCache = hazelcast.getMap(EJB_TIMER_CACHE_NAME); containerCache = hazelcast.getMap(EJB_TIMER_CONTAINER_CACHE_NAME); applicationCache = hazelcast.getMap(EJB_TIMER_APPLICAION_CACHE_NAME); - serverName = hazelcast.getCluster().getLocalMember().getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE); + serverName = core.getAttribute(core.getInstance().getCluster().getLocalMember().getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE); this.ownerIdOfThisServer_ = serverName; - this.domainName_ = core.getInstance().getConfig().getGroupConfig().getName(); + this.domainName_ = core.getInstance().getConfig().getClusterName(); super.enableRescheduleTimers(); } @@ -130,7 +130,7 @@ private void removeTimers(Set timerIdsToRemove) { @Override protected void _createTimer(TimerPrimaryKey timerId, long containerId, long applicationId, Object timedObjectPrimaryKey, String server_name, Date initialExpiration, long intervalDuration, EJBTimerSchedule schedule, TimerConfig timerConfig) throws Exception { if (timerConfig.isPersistent()) { - + pkCache.put(timerId.timerId, new HZTimer(timerId, containerId, applicationId, timedObjectPrimaryKey, server_name, server_name, initialExpiration, intervalDuration, schedule, timerConfig)); // add to container cache @@ -280,7 +280,7 @@ protected Date getNextTimeout(TimerPrimaryKey timerId) throws FinderException { protected void cancelTimersByKey(long containerId, Object primaryKey) { // Get *all* timers for this entity bean identity. This includes - // even timers *not* owned by this server instance, but that + // even timers *not* owned by this server instance, but that // are associated with the same entity bean and primary key. Set timers = containerCache.get(containerId); @@ -376,9 +376,9 @@ protected Collection getTimerIds(long containerId, Object timed // The results should include all timers for the given ejb // and/or primary key, including timers owned by other server instances. - // @@@ Might want to consider cases where we can use + // @@@ Might want to consider cases where we can use // timer cache to avoid some database access in PE/SE, or - // even in EE with the appropriate consistency tradeoff. + // even in EE with the appropriate consistency tradeoff. Collection timerIdsForTimedObject = new HashSet<>(); if (timedObjectPrimaryKey == null) { @@ -439,9 +439,9 @@ protected boolean isCancelledByAnotherInstance(RuntimeTimerState timerState) { if (!checkForTimerValidity(timerState.getTimerId())) { // The timer for which a ejbTimeout is about to be delivered - // is not present in the database. This could happen in the + // is not present in the database. This could happen in the // SE/EE case as other server instances (other than the owner) - // could call a cancel on the timer - deleting the timer from + // could call a cancel on the timer - deleting the timer from // the database. // Also it is possible that the timer is now owned by some other // server instance @@ -564,7 +564,7 @@ public int migrateTimers(String fromOwnerId) { logger.log(Level.FINE, "timer restoration error", e); - //Propogate any exceptions caught as part of the transaction + //Propogate any exceptions caught as part of the transaction EJBException ejbEx = createEJBException(e); throw ejbEx; @@ -656,8 +656,8 @@ protected Map recoverAndCreateSchedules(long containerI } } - - + + try { if (!schedules.isEmpty()) { createSchedules(containerId, applicationId, schedules, result, serverName, true, @@ -691,7 +691,7 @@ protected void resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState ti // Since timer was successfully delivered, update // last delivery time in database if that option is - // enabled. + // enabled. // @@@ add configuration for update-db-on-delivery if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "Setting last expiration for periodic timer {0} to {1}", new Object[]{timerState, now}); @@ -814,7 +814,7 @@ private void _notifyContainers(Collection timers) { private void restoreTimers() throws Exception { // Optimization. Skip timer restoration if there aren't any - // applications with timed objects deployed. + // applications with timed objects deployed. if (totalTimedObjectsInitialized_ == 0) { return; } @@ -832,7 +832,7 @@ private Collection _restoreTimers(Collection timersEligibleFor // Do timer restoration in two passes. The first pass updates // the timer cache with each timer. The second pass schedules - // the JDK timer tasks. + // the JDK timer tasks. Map timersToRestore = new HashMap<>(); Set timerIdsToRemove = new HashSet<>(); Set result = new HashSet<>(); @@ -865,7 +865,7 @@ private Collection _restoreTimers(Collection timersEligibleFor Date initialExpiration = timer.getInitialExpiration(); - // Create an instance of RuntimeTimerState. + // Create an instance of RuntimeTimerState. // Only access timedObjectPrimaryKey if timed object is // an entity bean. That allows us to lazily load the underlying // blob for stateless session and message-driven bean timers. @@ -884,7 +884,7 @@ private Collection _restoreTimers(Collection timersEligibleFor timerCache_.addTimer(timerId, timerState); // If a single-action timer is still in the database it never - // successfully delivered, so always reschedule a timer task + // successfully delivered, so always reschedule a timer task // for it. For periodic timers, we use the last known // expiration time to decide whether we need to fire one // ejbTimeout to make up for any missed ones. @@ -904,7 +904,7 @@ private Collection _restoreTimers(Collection timersEligibleFor // However, for now assume we do update the db on each // ejbTimeout. Therefore, if (lastExpirationTime == null), // it means the timer didn't successfully complete any - // timer expirations. + // timer expirations. if ((lastExpiration == null) && now.after(initialExpiration)) { @@ -936,7 +936,7 @@ private Collection _restoreTimers(Collection timersEligibleFor // In this case, at least one expiration has occurred // but that was less than one period ago so there were - // no missed expirations. + // no missed expirations. expirationTime = calcNextFixedRateExpiration(timerState); } @@ -985,7 +985,7 @@ private Set _restoreTimers(Set timersEligibleForRestoration) { // Do timer restoration in two passes. The first pass updates // the timer cache with each timer. The second pass schedules - // the JDK timer tasks. + // the JDK timer tasks. Map timersToRestore = new HashMap<>(); Set timerIdsToRemove = new HashSet<>(); Set result = new HashSet<>(); @@ -1015,7 +1015,7 @@ private Set _restoreTimers(Set timersEligibleForRestoration) { Date initialExpiration = timer.getInitialExpiration(); - // Create an instance of RuntimeTimerState. + // Create an instance of RuntimeTimerState. // Only access timedObjectPrimaryKey if timed object is // an entity bean. That allows us to lazily load the underlying // blob for stateless session and message-driven bean timers. @@ -1034,7 +1034,7 @@ private Set _restoreTimers(Set timersEligibleForRestoration) { timerCache_.addTimer(timerId, timerState); // If a single-action timer is still in the database it never - // successfully delivered, so always reschedule a timer task + // successfully delivered, so always reschedule a timer task // for it. For periodic timers, we use the last known // expiration time to decide whether we need to fire one // ejbTimeout to make up for any missed ones. @@ -1054,7 +1054,7 @@ private Set _restoreTimers(Set timersEligibleForRestoration) { // However, for now assume we do update the db on each // ejbTimeout. Therefore, if (lastExpirationTime == null), // it means the timer didn't successfully complete any - // timer expirations. + // timer expirations. if ((lastExpiration == null) && now.after(initialExpiration)) { @@ -1086,7 +1086,7 @@ private Set _restoreTimers(Set timersEligibleForRestoration) { // In this case, at least one expiration has occurred // but that was less than one period ago so there were - // no missed expirations. + // no missed expirations. expirationTime = calcNextFixedRateExpiration(timerState); } @@ -1168,7 +1168,7 @@ public void memberAdded(MemberEvent event) { @Override public void memberRemoved(MemberEvent event) { - ILock hazelcastLock = hazelcast.getLock("EJB-TIMER-LOCK"); + FencedLock hazelcastLock = hazelcast.getCPSubsystem().getLock("EJB-TIMER-LOCK"); hazelcastLock.lock(); try { Collection allTimers = pkCache.values(); @@ -1178,9 +1178,9 @@ public void memberRemoved(MemberEvent event) { removedTimers.add(timer); } } - - - + + + if (!removedTimers.isEmpty()) { logger.log(Level.INFO, "==> Restoring Timers ... "); Collection restored = _restoreTimers(removedTimers); diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java index e69568c7552..70e8948a8c4 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java @@ -74,6 +74,7 @@ import java.net.URL; import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -221,7 +222,7 @@ public void collect(MonitoringDataCollector collector) { */ private Map> pingAllInstances(long timeoutMillis) { Map> tasks = new ConcurrentHashMap<>(); - Map> configs = payaraMicro.executeClusteredASAdmin(GET_MP_CONFIG_STRING); + Map> configs = payaraMicro.executeClusteredASAdmin(GET_MP_CONFIG_STRING); for (Server server : domain.getServers().getServer()) { diff --git a/appserver/payara-appserver-modules/payara-micro-cdi/src/main/java/fish/payara/micro/cdi/extension/cluster/ClusterScopedInterceptor.java b/appserver/payara-appserver-modules/payara-micro-cdi/src/main/java/fish/payara/micro/cdi/extension/cluster/ClusterScopedInterceptor.java index 0676e8c94d7..936d900ac7d 100644 --- a/appserver/payara-appserver-modules/payara-micro-cdi/src/main/java/fish/payara/micro/cdi/extension/cluster/ClusterScopedInterceptor.java +++ b/appserver/payara-appserver-modules/payara-micro-cdi/src/main/java/fish/payara/micro/cdi/extension/cluster/ClusterScopedInterceptor.java @@ -39,7 +39,7 @@ */ package fish.payara.micro.cdi.extension.cluster; -import com.hazelcast.core.IAtomicLong; +import com.hazelcast.cp.IAtomicLong; import fish.payara.cluster.Clustered; import fish.payara.cluster.DistributedLockType; import static fish.payara.micro.cdi.extension.cluster.ClusterScopeContext.getAnnotation; diff --git a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java index d8bff1b05d5..fb9a2ba2f32 100644 --- a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java +++ b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java @@ -93,6 +93,7 @@ import fish.payara.nucleus.events.HazelcastEvents; import fish.payara.nucleus.executorservice.PayaraExecutorService; import fish.payara.nucleus.hazelcast.HazelcastCore; +import java.util.UUID; import java.util.concurrent.TimeUnit; /** @@ -134,7 +135,7 @@ public class PayaraInstanceImpl implements EventListener, MessageReceiver, Payar private HashSet myCDIListeners; - private String myCurrentID; + private UUID myCurrentID; private String instanceName; private String instanceGroup; @@ -172,12 +173,12 @@ public void setInstanceName(String instanceName) { } @Override - public Map> runCallable(Collection memberUUIDS, Callable callable) { + public Map> runCallable(Collection memberUUIDS, Callable callable) { return cluster.getExecService().runCallable(memberUUIDS, callable); } @Override - public Map> runCallable(Callable callable) { + public Map> runCallable(Callable callable) { return cluster.getExecService().runCallableAllMembers(callable); } @@ -187,16 +188,16 @@ public ClusterCommandResult executeLocalAsAdmin(String command, String... parame } @Override - public Map> executeClusteredASAdmin(String command, String... parameters) { + public Map> executeClusteredASAdmin(String command, String... parameters) { AsAdminCallable callable = new AsAdminCallable(command, parameters); - Map> result = cluster.getExecService().runCallableAllMembers(callable); + Map> result = cluster.getExecService().runCallableAllMembers(callable); return result; } @Override - public Map> executeClusteredASAdmin(Collection memberGUIDs, String command, String... parameters) { + public Map> executeClusteredASAdmin(Collection memberGUIDs, String command, String... parameters) { AsAdminCallable callable = new AsAdminCallable(command, parameters); - Map> result = cluster.getExecService().runCallable(memberGUIDs, callable); + Map> result = cluster.getExecService().runCallable(memberGUIDs, callable); return result; } @@ -319,9 +320,9 @@ else if (event.is(Deployment.APPLICATION_UNLOADED)) { @Override public Set getClusteredPayaras() { - Set members = cluster.getClusterMembers(); + Set members = cluster.getClusterMembers(); HashSet result = new HashSet<>(members.size()); - for (String member : members) { + for (UUID member : members) { InstanceDescriptor id = (InstanceDescriptor) cluster.getClusteredStore().get(INSTANCE_STORE_NAME, member); if (id != null) { result.add(id); @@ -365,7 +366,7 @@ public InstanceDescriptor getLocalDescriptor() { } @Override - public InstanceDescriptorImpl getDescriptor(String member) { + public InstanceDescriptorImpl getDescriptor(UUID member) { InstanceDescriptorImpl result = null; if (cluster.isEnabled()) { result = (InstanceDescriptorImpl) cluster.getClusteredStore().get(INSTANCE_STORE_NAME, member); diff --git a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/asadmin/SendAsadminCommand.java b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/asadmin/SendAsadminCommand.java index 5bc47b40739..600dc3e28d1 100644 --- a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/asadmin/SendAsadminCommand.java +++ b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/asadmin/SendAsadminCommand.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2019] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -48,6 +48,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.logging.Level; @@ -119,7 +120,7 @@ public void execute(AdminCommandContext context) if (payaraMicro.isClustered()) { // Get the subset of targets if provided, otherwise just get all clustered Micro instances - Map targetInstanceDescriptors = getTargetInstanceDescriptors(targets); + Map targetInstanceDescriptors = getTargetInstanceDescriptors(targets); // Add any explicit targets to our list of target GUIDS targetInstanceDescriptors.putAll(getExplicitTargetInstanceDescriptors(explicitTargets)); @@ -137,7 +138,7 @@ public void execute(AdminCommandContext context) } // Run the asadmin command against the targets (or all instances if no targets given) - Map> results = payaraMicro.executeClusteredASAdmin( + Map> results = payaraMicro.executeClusteredASAdmin( targetInstanceDescriptors.keySet(), command, parameters); // Check the command results for any failures @@ -146,7 +147,7 @@ public void execute(AdminCommandContext context) List warningMessages = new ArrayList<>(); List failureMessages = new ArrayList<>(); - for (Map.Entry> result : results.entrySet()) { + for (Map.Entry> result : results.entrySet()) { try { ClusterCommandResult commandResult = result.getValue().get(); @@ -303,8 +304,8 @@ private String processException(ClusterCommandResult commandResult) { * @param targets The targets to match * @return A map of the target instance GUIDs and their respective InstanceDescriptors */ - private Map getTargetInstanceDescriptors(String targets) { - Map targetInstanceDescriptors = new HashMap<>(); + private Map getTargetInstanceDescriptors(String targets) { + Map targetInstanceDescriptors = new HashMap<>(); // Get all of the clustered instances Set instances = payaraMicro.getClusteredPayaras(); @@ -393,8 +394,8 @@ private Map getTargetInstanceDescriptors(String targ * @param explicitTargets The explicit targets * @return A map of the target instance GUIDs and their respective InstanceDescriptors */ - private Map getExplicitTargetInstanceDescriptors(String[] explicitTargets) { - Map targetInstanceDescriptors = new HashMap<>(); + private Map getExplicitTargetInstanceDescriptors(String[] explicitTargets) { + Map targetInstanceDescriptors = new HashMap<>(); if (explicitTargets == null) { return targetInstanceDescriptors; } diff --git a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/data/InstanceDescriptorImpl.java b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/data/InstanceDescriptorImpl.java index 63e967db2ee..4d690d79c0b 100644 --- a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/data/InstanceDescriptorImpl.java +++ b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/data/InstanceDescriptorImpl.java @@ -2,7 +2,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - Copyright (c) 2016-2019 Payara Foundation. All rights reserved. + Copyright (c) 2016-2020 Payara Foundation. All rights reserved. The contents of this file are subject to the terms of the Common Development and Distribution License("CDDL") (collectively, the "License"). You @@ -46,6 +46,7 @@ and Distribution License("CDDL") (collectively, the "License"). You import fish.payara.micro.data.ApplicationDescriptor; import fish.payara.micro.data.InstanceDescriptor; import fish.payara.micro.data.ModuleDescriptor; +import java.util.UUID; /** * @@ -55,7 +56,7 @@ public class InstanceDescriptorImpl implements InstanceDescriptor { private static final long serialVersionUID = 1L; - private final String memberUUID; + private final UUID memberUUID; private String instanceName; private final List httpPorts; private final List httpsPorts; @@ -68,9 +69,9 @@ public class InstanceDescriptorImpl implements InstanceDescriptor { private String instanceGroup; private long heartBeatTS; - public InstanceDescriptorImpl(String UUID) throws UnknownHostException { + public InstanceDescriptorImpl(UUID uuid) throws UnknownHostException { hostName = InetAddress.getLocalHost(); - memberUUID = UUID; + memberUUID = uuid; httpPorts = new ArrayList<>(); httpsPorts = new ArrayList<>(); heartBeatTS = System.currentTimeMillis(); @@ -106,7 +107,7 @@ public void setInstanceName(String instanceName) { * @return the memberUUID */ @Override - public String getMemberUUID() { + public UUID getMemberUUID() { return memberUUID; } @@ -315,7 +316,7 @@ private JsonObject toJsonObject(boolean verbose) { configBuilder.add("Instance Name", this.instanceName); configBuilder.add("Instance Group", this.instanceGroup); if (memberUUID != null) { - configBuilder.add("Hazelcast Member UUID", this.memberUUID); + configBuilder.add("Hazelcast Member UUID", this.memberUUID.toString()); } // Create array of applications diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/cluster/MemberEvent.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/cluster/MemberEvent.java index 49368254e29..6bb26c21b92 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/cluster/MemberEvent.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/cluster/MemberEvent.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2017 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2017-2020 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -39,8 +39,9 @@ */ package fish.payara.nucleus.cluster; -import com.hazelcast.core.Member; +import com.hazelcast.cluster.Member; import fish.payara.nucleus.hazelcast.HazelcastCore; +import java.util.UUID; /** * @@ -48,22 +49,23 @@ */ public class MemberEvent { - public MemberEvent(Member member) { + public MemberEvent(HazelcastCore hzCore, Member member) { + this.hzCore = hzCore; this.member = member; } - public String getUuid() { + public UUID getUuid() { return member.getUuid(); } public String getServer() { - return member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE); + return hzCore.getAttribute(member.getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE); } public String getServerGroup() { - return member.getStringAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); + return member.getAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); } - private Member member; - + private final HazelcastCore hzCore; + private final Member member; } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/cluster/PayaraCluster.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/cluster/PayaraCluster.java index b9507ea2b6d..97c403d4d99 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/cluster/PayaraCluster.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/cluster/PayaraCluster.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2019] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -39,11 +39,10 @@ */ package fish.payara.nucleus.cluster; -import com.hazelcast.core.Cluster; -import com.hazelcast.core.Member; -import com.hazelcast.core.MemberAttributeEvent; -import com.hazelcast.core.MembershipEvent; -import com.hazelcast.core.MembershipListener; +import com.hazelcast.cluster.Cluster; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MembershipEvent; +import com.hazelcast.cluster.MembershipListener; import fish.payara.nucleus.eventbus.EventBus; import fish.payara.nucleus.events.HazelcastEvents; import fish.payara.nucleus.exec.ClusterExecutionService; @@ -51,6 +50,7 @@ import fish.payara.nucleus.store.ClusteredStore; import java.util.HashSet; import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -90,7 +90,7 @@ public class PayaraCluster implements MembershipListener, EventListener { private Set myListeners; - private String localUUID; + private UUID localUUID; public boolean isEnabled() { return hzCore.isEnabled(); @@ -115,29 +115,25 @@ public EventBus getEventBus() { @Override public void memberAdded(MembershipEvent me) { for (ClusterListener myListener : myListeners) { - myListener.memberAdded(new MemberEvent(me.getMember())); + myListener.memberAdded(new MemberEvent(hzCore, me.getMember())); } - logger.log(Level.INFO, "Data Grid Instance Added {0} at Address {1}", new String[]{me.getMember().getUuid(), me.getMember().getSocketAddress().toString()}); + logger.log(Level.INFO, "Data Grid Instance Added {0} at Address {1}", new String[]{me.getMember().getUuid().toString(), me.getMember().getSocketAddress().toString()}); logClusterStatus(); } @Override public void memberRemoved(MembershipEvent me) { for (ClusterListener myListener : myListeners) { - myListener.memberRemoved(new MemberEvent(me.getMember())); + myListener.memberRemoved(new MemberEvent(hzCore, me.getMember())); } - logger.log(Level.INFO, "Data Grid Instance Removed {0} from Address {1}", new String []{me.getMember().getUuid(), me.getMember().getSocketAddress().toString()}); + logger.log(Level.INFO, "Data Grid Instance Removed {0} from Address {1}", new String []{me.getMember().getUuid().toString(), me.getMember().getSocketAddress().toString()}); logClusterStatus(); } - public String getLocalUUID() { + public UUID getLocalUUID() { return localUUID; } - @Override - public void memberAttributeChanged(MemberAttributeEvent mae) { - } - public void removeClusterListener(ClusterListener listener) { myListeners.remove(listener); } @@ -146,8 +142,8 @@ public void addClusterListener(ClusterListener listener) { myListeners.add(listener); } - public Set getClusterMembers() { - HashSet result = new HashSet(5); + public Set getClusterMembers() { + HashSet result = new HashSet<>(5); if (hzCore.isEnabled()) { Set members = hzCore.getInstance().getCluster().getMembers(); @@ -158,26 +154,26 @@ public Set getClusterMembers() { return result; } - public String getMemberName(String memberUUID) { + public String getMemberName(UUID memberUUID) { String result = null; if (hzCore.isEnabled()) { Set members = hzCore.getInstance().getCluster().getMembers(); for (Member member : members) { if (member.getUuid().equals(memberUUID)) { - result = member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE); + result = hzCore.getAttribute(member.getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE); } } } return result; } - public String getMemberGroup(String memberUUID) { + public String getMemberGroup(UUID memberUUID) { String result = null; if (hzCore.isEnabled()) { Set members = hzCore.getInstance().getCluster().getMembers(); for (Member member : members) { if (member.getUuid().equals(memberUUID)) { - result = member.getStringAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); + result = member.getAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); } } } @@ -190,7 +186,7 @@ public Set getMemberNames() { if (hzCore.isEnabled()) { Set members = hzCore.getInstance().getCluster().getMembers(); for (Member member : members) { - String memberName = member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE); + String memberName = hzCore.getAttribute(member.getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE); if (memberName != null) { result.add(memberName); } @@ -204,8 +200,8 @@ public Set getMemberNamesInGroup(String groupName) { if (hzCore.isEnabled()) { Set members = hzCore.getInstance().getCluster().getMembers(); for (Member member : members) { - String memberName = member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE); - String memberGroupName = member.getStringAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); + String memberName = hzCore.getAttribute(member.getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE); + String memberGroupName = member.getAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); if (memberName != null && memberGroupName != null && groupName.equals(memberGroupName)) { result.add(memberName); } @@ -238,17 +234,17 @@ private void logClusterStatus() { String NL = System.lineSeparator(); message.append(NL); if (hzCore.isEnabled()) { - String dataGridName = hzCore.getInstance().getConfig().getGroupConfig().getName(); + String dataGridName = hzCore.getInstance().getConfig().getClusterName(); Cluster cluster = hzCore.getInstance().getCluster(); Set members = hzCore.getInstance().getCluster().getMembers(); - message.append("Payara Data Grid State: DG Version: ").append(cluster.getClusterVersion().getId()); + message.append("Payara Data Grid State: DG Version: ").append(cluster.getClusterVersion().getMajor()); message.append(" DG Name: ").append(dataGridName); message.append(" DG Size: ").append(members.size()); message.append(NL); message.append("Instances: {").append(NL); for (Member member : members) { - String name = member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE); - String group = member.getStringAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); + String name = hzCore.getAttribute(member.getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE); + String group = hzCore.getAttribute(member.getUuid(), HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); message.append(" DataGrid: ").append(dataGridName); if (group != null) { message.append(" Instance Group: ").append(group); diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/config/ClusteredConfig.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/config/ClusteredConfig.java index 1a45f144aa9..a6ecf129c47 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/config/ClusteredConfig.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/config/ClusteredConfig.java @@ -37,6 +37,9 @@ */ package fish.payara.nucleus.config; +import com.hazelcast.cluster.Member; +import com.hazelcast.cluster.MembershipAdapter; +import com.hazelcast.cluster.MembershipEvent; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiFunction; @@ -50,12 +53,10 @@ import org.jvnet.hk2.annotations.Service; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.Member; -import com.hazelcast.core.MembershipAdapter; -import com.hazelcast.core.MembershipEvent; -import com.hazelcast.core.ReplicatedMap; +import com.hazelcast.replicatedmap.ReplicatedMap; import fish.payara.nucleus.hazelcast.HazelcastCore; +import java.util.UUID; /** * The {@link ClusteredConfig} can hold configurations that should have a common values that is based on local @@ -85,7 +86,7 @@ public class ClusteredConfig extends MembershipAdapter { @Inject private HazelcastCore hzCore; - private String membershipListenerRegistrationId; + private UUID membershipListenerRegistrationId; /** * The names of the {@link ReplicatedMap}s holding the instances values of shared configurations. @@ -169,7 +170,7 @@ public void memberRemoved(MembershipEvent event) { } } - private static String instanceName(Member member) { - return member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE); + private String instanceName(Member member) { + return hzCore.getAttribute(member.getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE); } } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/eventbus/EventBus.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/eventbus/EventBus.java index a7a484ae504..aa68894a523 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/eventbus/EventBus.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/eventbus/EventBus.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2020 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -56,8 +56,9 @@ import com.hazelcast.core.DistributedObject; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.monitor.LocalTopicStats; +import com.hazelcast.topic.LocalTopicStats; import com.hazelcast.topic.impl.TopicService; +import java.util.UUID; /** * A Hazelcast based Event Bus for Payara @@ -130,7 +131,7 @@ public boolean addMessageReceiver(String topic, MessageReceiver mr) { if (tl == null) { // create a topic listener on the specified topic TopicListener newTL = new TopicListener(topic); - String regId = hzCore.getInstance().getTopic(topic).addMessageListener(newTL); + UUID regId = hzCore.getInstance().getTopic(topic).addMessageListener(newTL); messageReceivers.put(topic, newTL); tl = newTL; tl.setRegistrationID(regId); diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/eventbus/TopicListener.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/eventbus/TopicListener.java index 68dcba5e97d..eb9beb2721c 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/eventbus/TopicListener.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/eventbus/TopicListener.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2020 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -39,9 +39,10 @@ */ package fish.payara.nucleus.eventbus; -import com.hazelcast.core.Message; -import com.hazelcast.core.MessageListener; +import com.hazelcast.topic.Message; +import com.hazelcast.topic.MessageListener; import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; /** @@ -51,7 +52,7 @@ public class TopicListener implements MessageListener { private final String topicName; - private String registrationID; + private UUID registrationID; private final Set receivers; public TopicListener(String topicName) { @@ -63,11 +64,11 @@ public String getTopicName() { return topicName; } - public String getRegistrationID() { + public UUID getRegistrationID() { return registrationID; } - public void setRegistrationID(String registrationID) { + public void setRegistrationID(UUID registrationID) { this.registrationID = registrationID; } @@ -91,7 +92,4 @@ int removeMessageReceiver(MessageReceiver mr) { receivers.remove(mr); return receivers.size(); } - - - } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java index 5f6d70d936d..d30cb9e1e2c 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -39,8 +39,8 @@ */ package fish.payara.nucleus.exec; +import com.hazelcast.cluster.Member; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.Member; import com.hazelcast.scheduledexecutor.IScheduledExecutorService; import com.hazelcast.scheduledexecutor.IScheduledFuture; import fish.payara.nucleus.events.HazelcastEvents; @@ -52,6 +52,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -123,8 +124,8 @@ public Future runCallable(String memberUUID, Callabl * @param callable The Callable to run * @return A map of Futures keyed by Member UUID */ - public Map> runCallable(Collection memberUUIDS, Callable callable) { - HashMap> result = new HashMap<>(2); + public Map> runCallable(Collection memberUUIDS, Callable callable) { + HashMap> result = new HashMap<>(2); if (hzCore.isEnabled()) { Set membersToSubmit = selectMembers(memberUUIDS); @@ -143,8 +144,8 @@ public Map> runCallable(Collection Map> runCallableAllMembers(Callable callable) { - HashMap> result = new HashMap<>(2); + public Map> runCallableAllMembers(Callable callable) { + HashMap> result = new HashMap<>(2); if (hzCore.isEnabled()) { // work out which members correspond to cluster UUIDS. HazelcastInstance instance = hzCore.getInstance(); @@ -205,8 +206,8 @@ public ScheduledTaskFuture schedule(String memberUUI * @param unit The time unit of the delay * @return A Future containing the result */ - public Map> schedule(Collection memberUUIDs, Callable callable, long delay, TimeUnit unit) { - HashMap> result = new HashMap<>(2); + public Map> schedule(Collection memberUUIDs, Callable callable, long delay, TimeUnit unit) { + HashMap> result = new HashMap<>(2); if (hzCore.isEnabled()) { Collection toSubmitTo = selectMembers(memberUUIDs); @@ -268,14 +269,14 @@ public ScheduledTaskFuture scheduleAtFixedRate(String memberUUID, Runnable ru * @param unit The time unit of the delay * @return A Future containing the result */ - public Map> scheduleAtFixedRate(Collection memberUUIDs, Runnable runnable, long delay, long period, TimeUnit unit) { - HashMap> result = new HashMap<>(2); + public Map> scheduleAtFixedRate(Collection memberUUIDs, Runnable runnable, long delay, long period, TimeUnit unit) { + HashMap> result = new HashMap<>(2); if (hzCore.isEnabled()) { Collection toSubmitTo = selectMembers(memberUUIDs); IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME); - Map> schedule = scheduledExecutorService.scheduleOnMembersAtFixedRate(runnable, toSubmitTo, delay, period, unit); - for (Entry> entry : schedule.entrySet()) { + Map> schedule = scheduledExecutorService.scheduleOnMembersAtFixedRate(runnable, toSubmitTo, delay, period, unit); + for (Entry> entry : schedule.entrySet()) { Member member = entry.getKey(); result.put(member.getUuid(), new ScheduledTaskFuture<>(entry.getValue())); } @@ -304,7 +305,7 @@ private Member selectMember(String memberUUID) { return toSubmitTo; } - private Set selectMembers(Collection memberUUIDS) { + private Set selectMembers(Collection memberUUIDS) { // work out which members correspond to cluster UUIDS. HazelcastInstance instance = hzCore.getInstance(); Set members = instance.getCluster().getMembers(); @@ -316,6 +317,4 @@ private Set selectMembers(Collection memberUUIDS) { } return membersToSubmit; } - - } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DnsDiscoveryService.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DnsDiscoveryService.java index 00da686befa..75b4091d98a 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DnsDiscoveryService.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DnsDiscoveryService.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2018] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2018-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -42,7 +42,7 @@ */ package fish.payara.nucleus.hazelcast; -import com.hazelcast.nio.Address; +import com.hazelcast.cluster.Address; import com.hazelcast.spi.discovery.DiscoveryNode; import com.hazelcast.spi.discovery.SimpleDiscoveryNode; import com.hazelcast.spi.discovery.integration.DiscoveryService; @@ -138,7 +138,7 @@ public void destroy() { } @Override - public Map discoverLocalMetadata() { + public Map discoverLocalMetadata() { return Collections.emptyMap(); } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DomainDiscoveryService.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DomainDiscoveryService.java index ae02948f047..f3d9ed2f469 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DomainDiscoveryService.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DomainDiscoveryService.java @@ -39,10 +39,11 @@ */ package fish.payara.nucleus.hazelcast; -import com.hazelcast.nio.Address; +import com.hazelcast.cluster.Address; import com.hazelcast.spi.discovery.DiscoveryNode; import com.hazelcast.spi.discovery.SimpleDiscoveryNode; import com.hazelcast.spi.discovery.integration.DiscoveryService; +import com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings; import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.config.serverbeans.Node; import com.sun.enterprise.util.io.InstanceDirs; @@ -75,6 +76,10 @@ public class DomainDiscoveryService implements DiscoveryService { private static Logger logger = Logger.getLogger(DomainDiscoveryService.class.getName()); private final Holder.LazyHolder chosenAddress = Holder.LazyHolder.lazyHolder(MemberAddressPicker::findMyAddress); + public DomainDiscoveryService(DiscoveryServiceSettings settings) { + + } + @Override public void start() { // @@ -186,7 +191,7 @@ public void destroy() { } @Override - public Map discoverLocalMetadata() { + public Map discoverLocalMetadata() { return Collections.emptyMap(); } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DomainDiscoveryServiceProvider.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DomainDiscoveryServiceProvider.java deleted file mode 100644 index 423040db3e0..00000000000 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/DomainDiscoveryServiceProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://github.com/payara/Payara/blob/master/LICENSE.txt - * See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * The Payara Foundation designates this particular file as subject to the "Classpath" - * exception as provided by the Payara Foundation in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ -package fish.payara.nucleus.hazelcast; - -import com.hazelcast.spi.discovery.integration.DiscoveryService; -import com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider; -import com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings; - -/** - * - * @author steve - */ -public class DomainDiscoveryServiceProvider implements DiscoveryServiceProvider { - - public DomainDiscoveryServiceProvider() { - } - - @Override - public DiscoveryService newDiscoveryService(DiscoveryServiceSettings dss) { - return new DomainDiscoveryService(); - } - -} diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java index 38ea255b76e..db58c3fb43f 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java @@ -43,10 +43,8 @@ import com.hazelcast.cache.impl.HazelcastServerCachingProvider; import com.hazelcast.config.Config; -import com.hazelcast.config.ConfigLoader; import com.hazelcast.config.ExecutorConfig; import com.hazelcast.config.GlobalSerializerConfig; -import com.hazelcast.config.GroupConfig; import com.hazelcast.config.MemberAddressProviderConfig; import com.hazelcast.config.MulticastConfig; import com.hazelcast.config.NetworkConfig; @@ -56,9 +54,12 @@ import com.hazelcast.config.TcpIpConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.internal.config.ConfigLoader; import com.hazelcast.kubernetes.KubernetesProperties; +import com.hazelcast.map.IMap; import com.hazelcast.nio.serialization.Serializer; import com.hazelcast.nio.serialization.StreamSerializer; +import static com.hazelcast.spi.properties.ClusterProperty.WAIT_SECONDS_BEFORE_JOIN; import com.sun.enterprise.util.Utility; import fish.payara.nucleus.events.HazelcastEvents; import fish.payara.nucleus.hazelcast.contextproxy.CachingProviderProxy; @@ -91,8 +92,12 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.TreeMap; import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -106,6 +111,7 @@ @RunLevel(StartupRunLevel.VAL) public class HazelcastCore implements EventListener, ConfigListener { + public final static String INSTANCE_ATTRIBUTE_MAP = "payara-instance-map"; public final static String INSTANCE_ATTRIBUTE = "GLASSFISH-INSTANCE"; public final static String INSTANCE_GROUP_ATTRIBUTE = "GLASSFISH_INSTANCE_GROUP"; public static final String CLUSTER_EXECUTOR_SERVICE_NAME="payara-cluster-execution"; @@ -203,10 +209,10 @@ public String getMemberGroup() { * @return a 128-bit immutable universally unique identifier * @since 4.1.1.171 */ - public String getUUID() { + public UUID getUUID() { bootstrapHazelcast(); if (!enabled) { - return UUID.randomUUID().toString(); + return UUID.randomUUID(); } return theInstance.getCluster().getLocalMember().getUuid(); } @@ -337,6 +343,19 @@ private Config buildConfiguration() { } } else { // there is no config override config.setClassLoader(clh.getCommonClassLoader()); + + // The below are to test split-brain scenario, + // see https://github.com/hazelcast/hazelcast/issues/17586 + // and https://github.com/hazelcast/hazelcast/issues/17260 +// config.setProperty(MAX_NO_HEARTBEAT_SECONDS.getName(), "5"); +// config.setProperty(HEARTBEAT_INTERVAL_SECONDS.getName(), "1"); +// config.setProperty(MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "5"); +// config.setProperty(MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "5"); + + // can't quite set it to zero yet because of: + // https://github.com/hazelcast/hazelcast/issues/17586 + config.setProperty(WAIT_SECONDS_BEFORE_JOIN.getName(), "1"); + if(ctxUtil != null) { SerializationConfig serializationConfig = new SerializationConfig(); setPayaraSerializerConfig(serializationConfig); @@ -349,10 +368,7 @@ private Config buildConfiguration() { config.setLiteMember(Boolean.parseBoolean(nodeConfig.getLite())); - // set group config - GroupConfig gc = config.getGroupConfig(); - gc.setName(configuration.getClusterGroupName()); - gc.setPassword(configuration.getClusterGroupPassword()); + config.setClusterName(configuration.getClusterGroupName()); // build the configuration if ("true".equals(configuration.getHostAwarePartitioning())) { @@ -374,6 +390,9 @@ private Config buildConfiguration() { config.setProperty("hazelcast.jmx", "true"); } + if (config.getCPSubsystemConfig().getCPMemberCount() == 0) { + config.getCPSubsystemConfig().setCPMemberCount(Integer.getInteger("hazelcast.cp-subsystem.cp-member-count", 0)); + } } catch (MalformedURLException ex) { Logger.getLogger(HazelcastCore.class.getName()).log(Level.WARNING, "Unable to parse server config URL", ex); } catch (IOException ex) { @@ -446,7 +465,7 @@ private void buildNetworkConfiguration(Config config) throws NumberFormatExcepti } else { //build the domain discovery config config.setProperty("hazelcast.discovery.enabled", "true"); - config.getNetworkConfig().getJoin().getDiscoveryConfig().setDiscoveryServiceProvider(new DomainDiscoveryServiceProvider()); + config.getNetworkConfig().getJoin().getDiscoveryConfig().setDiscoveryServiceProvider(DomainDiscoveryService::new); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); } @@ -478,20 +497,29 @@ private void shutdownHazelcast() { private synchronized void bootstrapHazelcast() { if (!booted && isEnabled()) { Config config = buildConfiguration(); - theInstance = Hazelcast.newHazelcastInstance(config); + Logger cpSubsystemLogger = Logger.getLogger("com.hazelcast.cp.CPSubsystem"); + Level cpSubsystemLevel = cpSubsystemLogger.getLevel(); + try { + // remove "CP Subsystem Unsafe" warning on startup + cpSubsystemLogger.setLevel(Level.SEVERE); + theInstance = Hazelcast.newHazelcastInstance(config); + } finally { + cpSubsystemLogger.setLevel(cpSubsystemLevel); + } if (env.isMicro()) { if (Boolean.valueOf(configuration.getGenerateNames()) || memberName == null) { memberName = PayaraMicroNameGenerator.generateName(); - Set clusterMembers = theInstance.getCluster().getMembers(); + Set clusterMembers = theInstance.getCluster().getMembers(); // If the instance name was generated, we need to compile a list of all the instance names in use within // the instance group, excluding this local instance List takenNames = new ArrayList<>(); - for (com.hazelcast.core.Member member : clusterMembers) { + for (com.hazelcast.cluster.Member member : clusterMembers) { + Map attributes = getAttributes(member.getUuid()); if (member != theInstance.getCluster().getLocalMember() - && member.getStringAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE) != null - && member.getStringAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE).equalsIgnoreCase(memberGroup)) { - takenNames.add(member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE)); + && attributes.get(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE) != null + && attributes.get(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE).equalsIgnoreCase(memberGroup)) { + takenNames.add(attributes.get(HazelcastCore.INSTANCE_ATTRIBUTE)); } } @@ -500,14 +528,13 @@ private synchronized void bootstrapHazelcast() { if (takenNames.contains(memberName)) { memberName = PayaraMicroNameGenerator.generateUniqueName(takenNames, theInstance.getCluster().getLocalMember().getUuid()); - theInstance.getCluster().getLocalMember().setStringAttribute( - HazelcastCore.INSTANCE_ATTRIBUTE, memberName); + setAttribute(theInstance.getCluster().getLocalMember().getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE, memberName); } } } - theInstance.getCluster().getLocalMember().setStringAttribute(INSTANCE_ATTRIBUTE, memberName); - theInstance.getCluster().getLocalMember().setStringAttribute(INSTANCE_GROUP_ATTRIBUTE, memberGroup); - hazelcastCachingProvider = new CachingProviderProxy(HazelcastServerCachingProvider.createCachingProvider(theInstance), context); + setAttribute(theInstance.getCluster().getLocalMember().getUuid(), INSTANCE_ATTRIBUTE, memberName); + setAttribute(theInstance.getCluster().getLocalMember().getUuid(), INSTANCE_GROUP_ATTRIBUTE, memberGroup); + hazelcastCachingProvider = new CachingProviderProxy(new HazelcastServerCachingProvider(theInstance), context); bindToJNDI(); if(env.getStatus() == Status.started) { // only issue this event if the server is already running, @@ -518,6 +545,27 @@ private synchronized void bootstrapHazelcast() { } } + public String getAttribute(UUID memberUUID, String key) { + return getAttributes(memberUUID).get(key); + } + + public void setAttribute(UUID memberUUID, String key, String value) { + IMap> instanceAttributeMap = theInstance.getMap(INSTANCE_ATTRIBUTE_MAP); + instanceAttributeMap.compute(memberUUID, + (uuid, map) -> { + if (map == null) { + map = new HashMap<>(); + } + map.put(HazelcastCore.INSTANCE_ATTRIBUTE, memberName); + return map; + }); + } + + public Map getAttributes(UUID memberUUID) { + IMap> instanceAttributeMap = theInstance.getMap(INSTANCE_ATTRIBUTE_MAP); + return instanceAttributeMap.getOrDefault(memberUUID, Collections.unmodifiableMap(new TreeMap<>())); + } + private void bindToJNDI() { try { InitialContext ctx; diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/PayaraHazelcastSerializer.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/PayaraHazelcastSerializer.java index a7c394fdcae..9fbcdd32efb 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/PayaraHazelcastSerializer.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/PayaraHazelcastSerializer.java @@ -39,8 +39,8 @@ */ package fish.payara.nucleus.hazelcast; +import com.hazelcast.internal.serialization.impl.defaultserializers.JavaDefaultSerializers; import org.glassfish.internal.api.JavaEEContextUtil; -import com.hazelcast.internal.serialization.impl.JavaDefaultSerializers; import com.hazelcast.nio.ObjectDataInput; import com.hazelcast.nio.ObjectDataOutput; import com.hazelcast.nio.serialization.StreamSerializer; diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/PayaraMicroNameGenerator.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/PayaraMicroNameGenerator.java index 20580cec001..8e91acda516 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/PayaraMicroNameGenerator.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/PayaraMicroNameGenerator.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2019] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; /** * Class to generate random names for Payara Micro instances. @@ -64,10 +65,10 @@ public static String generateName() { * returns the UUID. * This method is more computationally expensive then fish.payara.api.admin.config.NameGenerator.generateName() * @param takenNames a list of all names of instances that already exist - * @param UUID The UUID of the instance + * @param uuid The UUID of the instance * @return a unique name */ - public static String generateUniqueName(List takenNames, String UUID) { + public static String generateUniqueName(List takenNames, UUID uuid) { String name = ""; // Generate a Map of all available names @@ -95,7 +96,7 @@ public static String generateUniqueName(List takenNames, String UUID) { // If a unique name was not found, just set it to the instance UUID if (name.equals("")) { - name = UUID; + name = uuid.toString(); } return name; diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ClearCache.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ClearCache.java index ac96c9b57dc..02e0e569b01 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ClearCache.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ClearCache.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -41,7 +41,7 @@ import com.hazelcast.core.DistributedObject; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; import com.sun.enterprise.config.serverbeans.Domain; import fish.payara.nucleus.hazelcast.HazelcastCore; import javax.cache.Cache; diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCacheKeys.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCacheKeys.java index ef991d5e25d..c7ecfcedd4b 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCacheKeys.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCacheKeys.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2018] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -40,11 +40,11 @@ package fish.payara.nucleus.hazelcast.admin; import com.hazelcast.cache.impl.CacheEntry; +import com.hazelcast.cache.impl.CachePartitionsIterator; import com.hazelcast.cache.impl.CacheProxy; -import com.hazelcast.cache.impl.ClusterWideIterator; import com.hazelcast.core.DistributedObject; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; import com.sun.enterprise.config.serverbeans.Domain; import fish.payara.nucleus.hazelcast.HazelcastCore; import java.util.Iterator; @@ -118,7 +118,7 @@ public void execute(AdminCommandContext context) { CacheProxy jcache = (CacheProxy) dobject; if (cacheName == null || cacheName.isEmpty() || cacheName.equals(jcache.getName())) { builder.append("JCache ").append(jcache.getName()).append("\n{"); - keyIterator = new ClusterWideIterator<>(jcache, 10, true); + keyIterator = new CachePartitionsIterator<>(jcache, 10, true); } } while (keyIterator != null && keyIterator.hasNext()) { diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCaches.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCaches.java index fb1ba6c1d79..b4f0352e782 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCaches.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListCaches.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -41,7 +41,7 @@ import com.hazelcast.core.DistributedObject; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; import com.sun.enterprise.config.serverbeans.Domain; import fish.payara.nucleus.hazelcast.HazelcastCore; import java.util.Properties; diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListHazelcastMembers.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListHazelcastMembers.java index e4c2f1b4b48..ad04f2785c9 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListHazelcastMembers.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/admin/ListHazelcastMembers.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -38,8 +38,8 @@ */ package fish.payara.nucleus.hazelcast.admin; +import com.hazelcast.cluster.Member; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.Member; import com.sun.enterprise.config.serverbeans.Domain; import fish.payara.nucleus.hazelcast.HazelcastCore; import java.util.Properties; @@ -99,11 +99,11 @@ public void execute(AdminCommandContext context) { StringBuilder builder = new StringBuilder(); builder.append("{ "); for (Member member : instance.getCluster().getMembers()) { - String memberName = member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE); + String memberName = hazelcast.getAttribute(member.getUuid(), HazelcastCore.INSTANCE_ATTRIBUTE); if (memberName != null) { builder.append(memberName).append("-"); } - String groupName = member.getStringAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); + String groupName = member.getAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE); if (groupName != null) { builder.append(groupName).append("-"); } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/encryption/HazelcastSymmetricEncryptor.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/encryption/HazelcastSymmetricEncryptor.java index 601978289ef..a46b5a5ff77 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/encryption/HazelcastSymmetricEncryptor.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/encryption/HazelcastSymmetricEncryptor.java @@ -40,7 +40,7 @@ package fish.payara.nucleus.hazelcast.encryption; import com.hazelcast.core.HazelcastException; -import com.hazelcast.nio.IOUtil; +import com.hazelcast.internal.nio.IOUtil; import com.sun.enterprise.security.ssl.impl.MasterPasswordImpl; import fish.payara.nucleus.hazelcast.HazelcastCore; import org.glassfish.api.admin.ServerEnvironment; diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/store/ClusteredStore.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/store/ClusteredStore.java index 56f53acd81d..cca5201fc7f 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/store/ClusteredStore.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/store/ClusteredStore.java @@ -41,9 +41,9 @@ import com.hazelcast.config.MapConfig; import com.hazelcast.core.DistributedObject; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; +import com.hazelcast.map.LocalMapStats; import com.hazelcast.map.impl.MapService; -import com.hazelcast.monitor.LocalMapStats; import fish.payara.monitoring.collect.MonitoringDataCollector; import fish.payara.monitoring.collect.MonitoringDataSource; import fish.payara.nucleus.events.HazelcastEvents; @@ -62,6 +62,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.logging.Logger; /** @@ -106,7 +107,7 @@ public void collect(MonitoringDataCollector collector) { } } - public String getInstanceId() { + public UUID getInstanceId() { return hzCore.getUUID(); } diff --git a/nucleus/payara-modules/healthcheck-cpool/src/main/java/fish/payara/nucleus/healthcheck/cpool/ConnectionPoolHealthCheck.java b/nucleus/payara-modules/healthcheck-cpool/src/main/java/fish/payara/nucleus/healthcheck/cpool/ConnectionPoolHealthCheck.java index 9dee630cc74..a5c5116f9a1 100644 --- a/nucleus/payara-modules/healthcheck-cpool/src/main/java/fish/payara/nucleus/healthcheck/cpool/ConnectionPoolHealthCheck.java +++ b/nucleus/payara-modules/healthcheck-cpool/src/main/java/fish/payara/nucleus/healthcheck/cpool/ConnectionPoolHealthCheck.java @@ -39,8 +39,6 @@ */ package fish.payara.nucleus.healthcheck.cpool; -import com.hazelcast.util.function.BiConsumer; -import com.hazelcast.util.function.Consumer; import com.sun.enterprise.config.serverbeans.*; import com.sun.enterprise.connectors.util.ResourcesUtil; import com.sun.enterprise.resource.pool.PoolManager; @@ -68,6 +66,8 @@ import javax.inject.Inject; import java.text.DecimalFormat; import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * @author mertcaliskan diff --git a/pom.xml b/pom.xml index 0fbe3efa468..75affd2bdee 100644 --- a/pom.xml +++ b/pom.xml @@ -143,8 +143,8 @@ 1.0-2 2.10.2 1.25 - 3.12.6 - 1.3.1 + 4.1 + 2.2 2.3.2 2.3.2 3.2.6