You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2016/10/06 15:56:37 UTC
[2/2] ambari git commit: AMBARI-18539 - Remove Unnecessary Locks
Inside Of Host Business Object Implementations (jonathanhurley)
AMBARI-18539 - Remove Unnecessary Locks Inside Of Host Business Object Implementations (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/38700445
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/38700445
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/38700445
Branch: refs/heads/branch-feature-AMBARI-18456
Commit: 38700445bd793d27a8747d4c1d06b70f531ab677
Parents: 42c6126
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed Oct 5 15:44:18 2016 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Thu Oct 6 11:33:46 2016 -0400
----------------------------------------------------------------------
.../orm/dao/ConfigGroupHostMappingDAO.java | 137 +--
.../org/apache/ambari/server/state/Host.java | 9 -
.../server/state/cluster/ClustersImpl.java | 4 +-
.../ambari/server/state/host/HostFactory.java | 2 +-
.../ambari/server/state/host/HostImpl.java | 933 ++++++-------------
.../ambari/server/topology/TopologyManager.java | 1 -
.../ExecutionCommandWrapperTest.java | 1 -
.../actionmanager/TestActionDBAccessorImpl.java | 9 -
.../server/actionmanager/TestActionManager.java | 8 +-
.../ambari/server/agent/AgentResourceTest.java | 2 +
.../server/agent/HeartbeatProcessorTest.java | 1 -
.../server/agent/HeartbeatTestHelper.java | 1 -
.../server/agent/TestHeartbeatMonitor.java | 8 -
.../server/checks/InstallPackagesCheckTest.java | 5 +-
.../AmbariCustomCommandExecutionHelperTest.java | 1 -
.../AmbariManagementControllerTest.java | 26 +-
.../BackgroundCustomCommandExecutionTest.java | 1 -
...hYarnCapacitySchedulerReleaseConfigTest.java | 7 +-
.../internal/JMXHostProviderTest.java | 6 -
.../StackDefinedPropertyProviderTest.java | 1 -
.../UpgradeResourceProviderHDP22Test.java | 1 -
.../internal/UpgradeResourceProviderTest.java | 2 -
.../UpgradeSummaryResourceProviderTest.java | 47 +-
.../DefaultServiceCalculatedStateTest.java | 6 +-
.../state/FlumeServiceCalculatedStateTest.java | 7 +-
.../state/HBaseServiceCalculatedStateTest.java | 7 +-
.../state/HDFSServiceCalculatedStateTest.java | 7 +-
.../state/HiveServiceCalculatedStateTest.java | 7 +-
.../state/OozieServiceCalculatedStateTest.java | 7 +-
.../state/YarnServiceCalculatedStateTest.java | 7 +-
.../apache/ambari/server/events/EventsTest.java | 1 -
.../HostVersionOutOfSyncListenerTest.java | 3 -
.../apache/ambari/server/orm/OrmTestHelper.java | 1 -
.../ComponentVersionCheckActionTest.java | 2 -
.../upgrades/ConfigureActionTest.java | 1 -
.../upgrades/UpgradeActionTest.java | 4 -
.../ambari/server/state/ConfigGroupTest.java | 2 -
.../ambari/server/state/ConfigHelperTest.java | 2 -
.../server/state/RequestExecutionTest.java | 3 -
.../server/state/ServiceComponentTest.java | 30 +-
.../apache/ambari/server/state/ServiceTest.java | 5 +-
.../ambari/server/state/UpgradeHelperTest.java | 8 -
.../state/cluster/ClusterDeadlockTest.java | 1 -
.../server/state/cluster/ClusterImplTest.java | 46 +-
.../server/state/cluster/ClusterTest.java | 6 -
.../state/cluster/ClustersDeadlockTest.java | 9 +-
.../server/state/cluster/ClustersTest.java | 10 -
.../ConcurrentServiceConfigVersionTest.java | 1 -
...omponentHostConcurrentWriteDeadlockTest.java | 1 -
.../ambari/server/state/host/HostImplTest.java | 50 +-
.../ambari/server/state/host/HostTest.java | 22 +-
.../svccomphost/ServiceComponentHostTest.java | 1 -
52 files changed, 510 insertions(+), 960 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
index 71d93cc..28b9fea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
@@ -17,10 +17,16 @@
*/
package org.apache.ambari.server.orm.dao;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.Singleton;
-import com.google.inject.persist.Transactional;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.orm.RequiresSession;
@@ -40,16 +46,10 @@ import org.apache.ambari.server.state.host.HostFactory;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
-import javax.persistence.EntityManager;
-import javax.persistence.TypedQuery;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.HashMap;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
@Singleton
public class ConfigGroupHostMappingDAO {
@@ -65,16 +65,16 @@ public class ConfigGroupHostMappingDAO {
private HostFactory hostFactory;
@Inject
Clusters clusters;
-
+
private final ReadWriteLock gl = new ReentrantReadWriteLock();
-
+
private Map<Long, Set<ConfigGroupHostMapping>> configGroupHostMappingByHost;
-
+
private volatile boolean cacheLoaded;
-
+
private void populateCache() {
-
+
if (!cacheLoaded) {
gl.writeLock().lock();
try {
@@ -106,10 +106,10 @@ public class ConfigGroupHostMappingDAO {
} finally {
gl.writeLock().unlock();
}
-
+
}
-
+
}
/**
@@ -121,50 +121,51 @@ public class ConfigGroupHostMappingDAO {
@RequiresSession
public ConfigGroupHostMappingEntity findByPK(final ConfigGroupHostMappingEntityPK
configGroupHostMappingEntityPK) {
-
+
return entityManagerProvider.get()
.find(ConfigGroupHostMappingEntity.class, configGroupHostMappingEntityPK);
}
@RequiresSession
public Set<ConfigGroupHostMapping> findByHostId(Long hostId) {
-
+
populateCache();
-
- if (!configGroupHostMappingByHost.containsKey(hostId))
+
+ if (!configGroupHostMappingByHost.containsKey(hostId)) {
return null;
-
+ }
+
Set<ConfigGroupHostMapping> set = new HashSet<ConfigGroupHostMapping>(configGroupHostMappingByHost.get(hostId));
-
+
return set;
-
+
}
@RequiresSession
public Set<ConfigGroupHostMapping> findByGroup(final Long groupId) {
-
+
populateCache();
-
+
Set<ConfigGroupHostMapping> result = new HashSet<ConfigGroupHostMapping>();
-
+
for (Set<ConfigGroupHostMapping> item : configGroupHostMappingByHost.values()) {
-
+
Set<ConfigGroupHostMapping> setByHost = new HashSet<ConfigGroupHostMapping>(item);
-
+
CollectionUtils.filter(setByHost, new Predicate() {
-
+
@Override
public boolean evaluate(Object arg0) {
return ((ConfigGroupHostMapping) arg0).getConfigGroupId().equals(groupId);
}
});
-
+
result.addAll(setByHost);
-
+
}
-
+
return result;
-
+
}
@RequiresSession
@@ -178,33 +179,33 @@ public class ConfigGroupHostMappingDAO {
populateCache();
entityManagerProvider.get().persist(configGroupHostMappingEntity);
-
+
//create in cache
Set<ConfigGroupHostMapping> set = configGroupHostMappingByHost.get(configGroupHostMappingEntity.getHostId());
if (set == null){
set = new HashSet<ConfigGroupHostMapping>();
configGroupHostMappingByHost.put(configGroupHostMappingEntity.getHostId(), set);
}
-
+
set.add(buildConfigGroupHostMapping(configGroupHostMappingEntity));
}
@Transactional
public ConfigGroupHostMappingEntity merge(ConfigGroupHostMappingEntity configGroupHostMappingEntity) {
-
+
populateCache();
-
+
Set<ConfigGroupHostMapping> set = configGroupHostMappingByHost.get(configGroupHostMappingEntity.getHostId());
if (set == null){
set = new HashSet<ConfigGroupHostMapping>();
configGroupHostMappingByHost.put(configGroupHostMappingEntity.getHostId(), set);
}
-
+
//Update object in set
set.remove(buildConfigGroupHostMapping(configGroupHostMappingEntity));
set.add(buildConfigGroupHostMapping(configGroupHostMappingEntity));
-
-
+
+
return entityManagerProvider.get().merge(configGroupHostMappingEntity);
}
@@ -213,23 +214,23 @@ public class ConfigGroupHostMappingDAO {
configGroupHostMappingEntity) {
cacheLoaded = false;
populateCache();
-
+
entityManagerProvider.get().refresh(configGroupHostMappingEntity);
}
@Transactional
public void remove(final ConfigGroupHostMappingEntity
configGroupHostMappingEntity) {
-
+
populateCache();
-
+
entityManagerProvider.get().remove(merge(configGroupHostMappingEntity));
-
+
Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost.get(configGroupHostMappingEntity.getHostId());
-
+
if (setByHost != null) {
CollectionUtils.filter(setByHost, new Predicate() {
-
+
@Override
public boolean evaluate(Object arg0) {
return !((ConfigGroupHostMapping) arg0).getConfigGroupId().
@@ -243,14 +244,14 @@ public class ConfigGroupHostMappingDAO {
public void removeByPK(final ConfigGroupHostMappingEntityPK
configGroupHostMappingEntityPK) {
populateCache();
-
+
entityManagerProvider.get().remove(findByPK(configGroupHostMappingEntityPK));
-
+
Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost.get(configGroupHostMappingEntityPK.getHostId());
-
+
if (setByHost != null) {
CollectionUtils.filter(setByHost, new Predicate() {
-
+
@Override
public boolean evaluate(Object arg0) {
return !((ConfigGroupHostMapping) arg0).getConfigGroupId().
@@ -258,7 +259,7 @@ public class ConfigGroupHostMappingDAO {
}
});
}
-
+
}
@Transactional
@@ -273,18 +274,18 @@ public class ConfigGroupHostMappingDAO {
// Flush to current transaction required in order to avoid Eclipse link
// from re-ordering delete
entityManagerProvider.get().flush();
-
+
for (Set<ConfigGroupHostMapping> setByHost : configGroupHostMappingByHost.values()) {
-
+
CollectionUtils.filter(setByHost, new Predicate() {
-
+
@Override
public boolean evaluate(Object arg0) {
return !((ConfigGroupHostMapping) arg0).getConfigGroupId().equals(groupId);
}
});
}
-
+
}
@Transactional
@@ -294,22 +295,22 @@ public class ConfigGroupHostMappingDAO {
"confighosts.hostId = ?1", String.class);
daoUtils.executeUpdate(query, hostId);
-
-
+
+
Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost.get(hostId);
-
+
setByHost.clear();
}
-
+
private ConfigGroupHostMapping buildConfigGroupHostMapping(
ConfigGroupHostMappingEntity configGroupHostMappingEntity) {
-
+
ConfigGroupHostMappingImpl configGroupHostMapping = new ConfigGroupHostMappingImpl();
configGroupHostMapping.setConfigGroup(buildConfigGroup(configGroupHostMappingEntity.getConfigGroupEntity()));
configGroupHostMapping.setConfigGroupId(configGroupHostMappingEntity.getConfigGroupId());
configGroupHostMapping.setHost(buildHost(configGroupHostMappingEntity.getHostEntity()));
configGroupHostMapping.setHostId(configGroupHostMappingEntity.getHostId());
-
+
return configGroupHostMapping;
}
@@ -321,12 +322,12 @@ public class ConfigGroupHostMappingDAO {
//almost impossible
}
ConfigGroup configGroup = configGroupFactory.createExisting(cluster, configGroupEntity);
-
+
return configGroup;
}
private Host buildHost(HostEntity hostEntity) {
- Host host = hostFactory.create(hostEntity, false);
+ Host host = hostFactory.create(hostEntity);
return host;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
index bd3f8bf..0a9c82a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
@@ -43,11 +43,6 @@ public interface Host extends Comparable {
Long getHostId();
/**
- * @param hostName the hostName to set
- */
- void setHostName(String hostName);
-
- /**
* @return the currentPingPort
*/
Integer getCurrentPingPort();
@@ -338,10 +333,6 @@ public interface Host extends Comparable {
HostResponse convertToResponse();
- boolean isPersisted();
-
- void persist();
-
void refresh();
void importHostInfo(HostInfo hostInfo);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index 7b119f2..aff3a3b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -185,7 +185,7 @@ public class ClustersImpl implements Clusters {
private void loadClustersAndHosts() {
List<HostEntity> hostEntities = hostDAO.findAll();
for (HostEntity hostEntity : hostEntities) {
- Host host = hostFactory.create(hostEntity, true);
+ Host host = hostFactory.create(hostEntity);
hosts.put(hostEntity.getHostName(), host);
hostsById.put(hostEntity.getHostId(), host);
}
@@ -411,7 +411,7 @@ public class ClustersImpl implements Clusters {
hostEntity.setClusterEntities(new ArrayList<ClusterEntity>());
// not stored to DB
- Host host = hostFactory.create(hostEntity, false);
+ Host host = hostFactory.create(hostEntity);
host.setAgentVersion(new AgentVersion(""));
List<DiskInfo> emptyDiskList = new ArrayList<DiskInfo>();
host.setDisksInfo(emptyDiskList);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostFactory.java
index 5cfbbef..ae22c79 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostFactory.java
@@ -21,5 +21,5 @@ import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.state.Host;
public interface HostFactory {
- Host create(HostEntity hostEntity, boolean persisted);
+ Host create(HostEntity hostEntity);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
index 91b6360..ec8873a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
@@ -22,6 +22,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -65,13 +67,13 @@ import org.apache.ambari.server.state.fsm.SingleArcTransition;
import org.apache.ambari.server.state.fsm.StateMachine;
import org.apache.ambari.server.state.fsm.StateMachineFactory;
import org.apache.ambari.server.topology.TopologyManager;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
-import com.google.inject.Injector;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.persist.Transactional;
@@ -96,11 +98,12 @@ public class HostImpl implements Host {
private static final String TIMEZONE = "timezone";
private static final String OS_RELEASE_VERSION = "os_release_version";
-
+ @Inject
private final Gson gson;
private static final Type hostAttributesType =
new TypeToken<Map<String, String>>() {}.getType();
+
private static final Type maintMapType =
new TypeToken<Map<Long, MaintenanceState>>() {}.getType();
@@ -108,26 +111,43 @@ public class HostImpl implements Host {
private final Lock readLock;
private final Lock writeLock;
- // TODO : caching the JPA entities here causes issues if they become stale and get re-merged.
- private HostEntity hostEntity;
- private HostStateEntity hostStateEntity;
-
+ @Inject
private HostDAO hostDAO;
+
+ @Inject
private HostStateDAO hostStateDAO;
+
+ @Inject
private HostVersionDAO hostVersionDAO;
+
+ @Inject
private ClusterDAO clusterDAO;
+
+ @Inject
private Clusters clusters;
+
+ @Inject
private HostConfigMappingDAO hostConfigMappingDAO;
+ /**
+ * The ID of the host which is to retrieve it from JPA.
+ */
+ private final long hostId;
+
+ /**
+ * The name of the host, stored inside of this business object to prevent JPA
+ * lookups since it never changes.
+ */
+ private final String hostName;
+
private long lastHeartbeatTime = 0L;
private AgentEnv lastAgentEnv = null;
private List<DiskInfo> disksInfo = new ArrayList<DiskInfo>();
private RecoveryReport recoveryReport = new RecoveryReport();
- private boolean persisted = false;
private Integer currentPingPort = null;
private final StateMachine<HostState, HostEventType, HostEvent> stateMachine;
- private Map<Long, MaintenanceState> maintMap = null;
+ private final ConcurrentMap<Long, MaintenanceState> maintMap;
// In-memory status, based on host components states
private String status = HealthStatus.UNKNOWN.name();
@@ -141,7 +161,8 @@ public class HostImpl implements Host {
@Inject
private AmbariEventPublisher eventPublisher;
- private static TopologyManager topologyManager;
+ @Inject
+ private TopologyManager topologyManager;
private static final StateMachineFactory
<HostImpl, HostState, HostEventType, HostEvent>
@@ -229,38 +250,49 @@ public class HostImpl implements Host {
.installTopology();
@Inject
- public HostImpl(@Assisted HostEntity hostEntity,
- @Assisted boolean persisted, Injector injector) {
+ public HostImpl(@Assisted HostEntity hostEntity, Gson gson, HostDAO hostDAO, HostStateDAO hostStateDAO) {
+ this.gson = gson;
+ this.hostDAO = hostDAO;
+ this.hostStateDAO = hostStateDAO;
+
stateMachine = stateMachineFactory.make(this);
rwLock = new ReentrantReadWriteLock();
readLock = rwLock.readLock();
writeLock = rwLock.writeLock();
- this.hostEntity = hostEntity;
- this.persisted = persisted;
- hostDAO = injector.getInstance(HostDAO.class);
- hostStateDAO = injector.getInstance(HostStateDAO.class);
- hostVersionDAO = injector.getInstance(HostVersionDAO.class);
- gson = injector.getInstance(Gson.class);
- clusterDAO = injector.getInstance(ClusterDAO.class);
- clusters = injector.getInstance(Clusters.class);
- hostConfigMappingDAO = injector.getInstance(HostConfigMappingDAO.class);
- //todo: proper static injection
- HostImpl.topologyManager = injector.getInstance(TopologyManager.class);
-
- hostStateEntity = hostEntity.getHostStateEntity();
+ HostStateEntity hostStateEntity = hostEntity.getHostStateEntity();
if (hostStateEntity == null) {
hostStateEntity = new HostStateEntity();
hostStateEntity.setHostEntity(hostEntity);
hostEntity.setHostStateEntity(hostStateEntity);
hostStateEntity.setHealthStatus(gson.toJson(new HostHealthStatus(HealthStatus.UNKNOWN, "")));
- if (persisted) {
- hostStateDAO.create(hostStateEntity);
- }
} else {
stateMachine.setCurrentState(hostStateEntity.getCurrentState());
}
+ // persist the host
+ if (null == hostEntity.getHostId()) {
+ persistEntities(hostEntity);
+
+ refresh();
+
+ for (ClusterEntity clusterEntity : hostEntity.getClusterEntities()) {
+ try {
+ clusters.getClusterById(clusterEntity.getClusterId()).refresh();
+ } catch (AmbariException e) {
+ LOG.error("Error while looking up the cluster", e);
+ throw new RuntimeException("Cluster '" + clusterEntity.getClusterId() + "' was removed",
+ e);
+ }
+ }
+ }
+
+ // set the host ID which will be used to retrieve it from JPA
+ hostId = hostEntity.getHostId();
+ hostName = hostEntity.getHostName();
+
+ // populate the maintenance map
+ maintMap = ensureMaintMap(hostEntity.getHostStateEntity());
}
@Override
@@ -296,7 +328,6 @@ public class HostImpl implements Host {
+ ", registrationTime=" + e.registrationTime
+ ", agentVersion=" + agentVersion);
- host.persist();
host.clusters.updateHostMappings(host);
//todo: proper host joined notification
@@ -307,10 +338,10 @@ public class HostImpl implements Host {
associatedWithCluster = false;
} catch (AmbariException e1) {
// only HostNotFoundException is thrown
- e1.printStackTrace();
+ LOG.error("Unable to determine the clusters for host", e1);
}
- topologyManager.onHostRegistered(host, associatedWithCluster);
+ host.topologyManager.onHostRegistered(host, associatedWithCluster);
}
}
@@ -405,7 +436,7 @@ public class HostImpl implements Host {
+ ", lastHeartbeatTime=" + host.getLastHeartbeatTime());
host.setHealthStatus(new HostHealthStatus(HealthStatus.UNKNOWN, host.getHealthStatus().getHealthReport()));
- topologyManager.onHostHeartBeatLost(host);
+ host.topologyManager.onHostHeartBeatLost(host);
}
}
@@ -413,160 +444,120 @@ public class HostImpl implements Host {
* @param hostInfo the host information
*/
@Override
+ @Transactional
public void importHostInfo(HostInfo hostInfo) {
- try {
- writeLock.lock();
-
- if (hostInfo.getIPAddress() != null
- && !hostInfo.getIPAddress().isEmpty()) {
- setIPv4(hostInfo.getIPAddress());
- setIPv6(hostInfo.getIPAddress());
- }
+ if (hostInfo.getIPAddress() != null && !hostInfo.getIPAddress().isEmpty()) {
+ setIPv4(hostInfo.getIPAddress());
+ setIPv6(hostInfo.getIPAddress());
+ }
- setCpuCount(hostInfo.getProcessorCount());
- setPhCpuCount(hostInfo.getPhysicalProcessorCount());
- setTotalMemBytes(hostInfo.getMemoryTotal());
- setAvailableMemBytes(hostInfo.getFreeMemory());
+ setCpuCount(hostInfo.getProcessorCount());
+ setPhCpuCount(hostInfo.getPhysicalProcessorCount());
+ setTotalMemBytes(hostInfo.getMemoryTotal());
+ setAvailableMemBytes(hostInfo.getFreeMemory());
- if (hostInfo.getArchitecture() != null
- && !hostInfo.getArchitecture().isEmpty()) {
- setOsArch(hostInfo.getArchitecture());
- }
+ if (hostInfo.getArchitecture() != null && !hostInfo.getArchitecture().isEmpty()) {
+ setOsArch(hostInfo.getArchitecture());
+ }
- if (hostInfo.getOS() != null
- && !hostInfo.getOS().isEmpty()) {
- String osType = hostInfo.getOS();
- if (hostInfo.getOSRelease() != null) {
- String[] release = hostInfo.getOSRelease().split("\\.");
- if (release.length > 0) {
- osType += release[0];
- }
+ if (hostInfo.getOS() != null && !hostInfo.getOS().isEmpty()) {
+ String osType = hostInfo.getOS();
+ if (hostInfo.getOSRelease() != null) {
+ String[] release = hostInfo.getOSRelease().split("\\.");
+ if (release.length > 0) {
+ osType += release[0];
}
- setOsType(osType.toLowerCase());
- }
-
- if (hostInfo.getMounts() != null
- && !hostInfo.getMounts().isEmpty()) {
- setDisksInfo(hostInfo.getMounts());
}
+ setOsType(osType.toLowerCase());
+ }
- // FIXME add all other information into host attributes
- setAgentVersion(new AgentVersion(
- hostInfo.getAgentUserId()));
-
- Map<String, String> attrs = new HashMap<String, String>();
- if (hostInfo.getHardwareIsa() != null) {
- attrs.put(HARDWAREISA, hostInfo.getHardwareIsa());
- }
- if (hostInfo.getHardwareModel() != null) {
- attrs.put(HARDWAREMODEL, hostInfo.getHardwareModel());
- }
- if (hostInfo.getInterfaces() != null) {
- attrs.put(INTERFACES, hostInfo.getInterfaces());
- }
- if (hostInfo.getKernel() != null) {
- attrs.put(KERNEL, hostInfo.getKernel());
- }
- if (hostInfo.getKernelMajVersion() != null) {
- attrs.put(KERNELMAJOREVERSON, hostInfo.getKernelMajVersion());
- }
- if (hostInfo.getKernelRelease() != null) {
- attrs.put(KERNELRELEASE, hostInfo.getKernelRelease());
- }
- if (hostInfo.getKernelVersion() != null) {
- attrs.put(KERNELVERSION, hostInfo.getKernelVersion());
- }
- if (hostInfo.getMacAddress() != null) {
- attrs.put(MACADDRESS, hostInfo.getMacAddress());
- }
- if (hostInfo.getNetMask() != null) {
- attrs.put(NETMASK, hostInfo.getNetMask());
- }
- if (hostInfo.getOSFamily() != null) {
- attrs.put(OSFAMILY, hostInfo.getOSFamily());
- }
- if (hostInfo.getPhysicalProcessorCount() != 0) {
- attrs.put(PHYSICALPROCESSORCOUNT,
- Long.toString(hostInfo.getPhysicalProcessorCount()));
- }
- if (hostInfo.getProcessorCount() != 0) {
- attrs.put(PROCESSORCOUNT,
- Long.toString(hostInfo.getProcessorCount()));
- }
- if (Boolean.toString(hostInfo.getSeLinux()) != null) {
- attrs.put(SELINUXENABLED, Boolean.toString(hostInfo.getSeLinux()));
- }
- if (hostInfo.getSwapSize() != null) {
- attrs.put(SWAPSIZE, hostInfo.getSwapSize());
- }
- if (hostInfo.getSwapFree() != null) {
- attrs.put(SWAPFREE, hostInfo.getSwapFree());
- }
- if (hostInfo.getTimeZone() != null) {
- attrs.put(TIMEZONE, hostInfo.getTimeZone());
- }
- if (hostInfo.getOSRelease() != null) {
- attrs.put(OS_RELEASE_VERSION, hostInfo.getOSRelease());
- }
+ if (hostInfo.getMounts() != null && !hostInfo.getMounts().isEmpty()) {
+ setDisksInfo(hostInfo.getMounts());
+ }
- setHostAttributes(attrs);
+ // FIXME add all other information into host attributes
+ setAgentVersion(new AgentVersion(hostInfo.getAgentUserId()));
- saveIfPersisted();
+ Map<String, String> attrs = new HashMap<String, String>();
+ if (hostInfo.getHardwareIsa() != null) {
+ attrs.put(HARDWAREISA, hostInfo.getHardwareIsa());
}
- finally {
- writeLock.unlock();
+ if (hostInfo.getHardwareModel() != null) {
+ attrs.put(HARDWAREMODEL, hostInfo.getHardwareModel());
+ }
+ if (hostInfo.getInterfaces() != null) {
+ attrs.put(INTERFACES, hostInfo.getInterfaces());
+ }
+ if (hostInfo.getKernel() != null) {
+ attrs.put(KERNEL, hostInfo.getKernel());
+ }
+ if (hostInfo.getKernelMajVersion() != null) {
+ attrs.put(KERNELMAJOREVERSON, hostInfo.getKernelMajVersion());
+ }
+ if (hostInfo.getKernelRelease() != null) {
+ attrs.put(KERNELRELEASE, hostInfo.getKernelRelease());
+ }
+ if (hostInfo.getKernelVersion() != null) {
+ attrs.put(KERNELVERSION, hostInfo.getKernelVersion());
+ }
+ if (hostInfo.getMacAddress() != null) {
+ attrs.put(MACADDRESS, hostInfo.getMacAddress());
+ }
+ if (hostInfo.getNetMask() != null) {
+ attrs.put(NETMASK, hostInfo.getNetMask());
+ }
+ if (hostInfo.getOSFamily() != null) {
+ attrs.put(OSFAMILY, hostInfo.getOSFamily());
}
+ if (hostInfo.getPhysicalProcessorCount() != 0) {
+ attrs.put(PHYSICALPROCESSORCOUNT, Long.toString(hostInfo.getPhysicalProcessorCount()));
+ }
+ if (hostInfo.getProcessorCount() != 0) {
+ attrs.put(PROCESSORCOUNT, Long.toString(hostInfo.getProcessorCount()));
+ }
+ if (Boolean.toString(hostInfo.getSeLinux()) != null) {
+ attrs.put(SELINUXENABLED, Boolean.toString(hostInfo.getSeLinux()));
+ }
+ if (hostInfo.getSwapSize() != null) {
+ attrs.put(SWAPSIZE, hostInfo.getSwapSize());
+ }
+ if (hostInfo.getSwapFree() != null) {
+ attrs.put(SWAPFREE, hostInfo.getSwapFree());
+ }
+ if (hostInfo.getTimeZone() != null) {
+ attrs.put(TIMEZONE, hostInfo.getTimeZone());
+ }
+ if (hostInfo.getOSRelease() != null) {
+ attrs.put(OS_RELEASE_VERSION, hostInfo.getOSRelease());
+ }
+
+ setHostAttributes(attrs);
}
@Override
public void setLastAgentEnv(AgentEnv env) {
- writeLock.lock();
- try {
- lastAgentEnv = env;
- } finally {
- writeLock.unlock();
- }
-
+ lastAgentEnv = env;
}
@Override
public AgentEnv getLastAgentEnv() {
- readLock.lock();
- try {
- return lastAgentEnv;
- } finally {
- readLock.unlock();
- }
-
+ return lastAgentEnv;
}
@Override
public HostState getState() {
- try {
- readLock.lock();
- return stateMachine.getCurrentState();
- }
- finally {
- readLock.unlock();
- }
+ return stateMachine.getCurrentState();
}
@Override
public void setState(HostState state) {
- try {
- writeLock.lock();
- stateMachine.setCurrentState(state);
-
- HostStateEntity hostStateEntity = getHostStateEntity();
+ stateMachine.setCurrentState(state);
+ HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- hostStateEntity.setCurrentState(state);
- hostStateEntity.setTimeInState(System.currentTimeMillis());
- saveIfPersisted();
- }
- }
- finally {
- writeLock.unlock();
+ if (hostStateEntity != null) {
+ hostStateEntity.setCurrentState(state);
+ hostStateEntity.setTimeInState(System.currentTimeMillis());
+ hostStateDAO.merge(hostStateEntity);
}
}
@@ -608,268 +599,146 @@ public class HostImpl implements Host {
@Override
public String getHostName() {
- // Not an updatable attribute - No locking necessary
- return hostEntity.getHostName();
+ return hostName;
}
@Override
public Long getHostId() {
- return hostEntity.getHostId();
- }
-
- @Override
- public void setHostName(String hostName) {
- try {
- writeLock.lock();
- if (!isPersisted()) {
- hostEntity.setHostName(hostName);
- } else {
- throw new UnsupportedOperationException("PK of persisted entity cannot be modified");
- }
- } finally {
- writeLock.unlock();
- }
+ return hostId;
}
@Override
public Integer getCurrentPingPort() {
- try {
- readLock.lock();
- return currentPingPort;
- }
- finally {
- readLock.unlock();
- }
+ return currentPingPort;
}
@Override
public void setCurrentPingPort(Integer currentPingPort) {
- try {
- writeLock.lock();
- this.currentPingPort = currentPingPort;
- }
- finally {
- writeLock.unlock();
- }
+ this.currentPingPort = currentPingPort;
}
@Override
public void setPublicHostName(String hostName) {
- try {
- writeLock.lock();
- getHostEntity().setPublicHostName(hostName);
- saveIfPersisted();
- }
- finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setPublicHostName(hostName);
+ hostDAO.merge(hostEntity);
}
@Override
public String getPublicHostName() {
- try {
- readLock.lock();
- return getHostEntity().getPublicHostName();
- }
- finally {
- readLock.unlock();
- }
+ return getHostEntity().getPublicHostName();
}
@Override
public String getIPv4() {
- try {
- readLock.lock();
- return getHostEntity().getIpv4();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getIpv4();
}
@Override
public void setIPv4(String ip) {
- try {
- writeLock.lock();
- getHostEntity().setIpv4(ip);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setIpv4(ip);
+ hostDAO.merge(hostEntity);
}
@Override
public String getIPv6() {
- try {
- readLock.lock();
- return getHostEntity().getIpv6();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getIpv6();
}
@Override
public void setIPv6(String ip) {
- try {
- writeLock.lock();
- getHostEntity().setIpv6(ip);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setIpv6(ip);
+ hostDAO.merge(hostEntity);
}
@Override
public int getCpuCount() {
- try {
- readLock.lock();
- return getHostEntity().getCpuCount();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getCpuCount();
}
@Override
public void setCpuCount(int cpuCount) {
- try {
- writeLock.lock();
- getHostEntity().setCpuCount(cpuCount);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setCpuCount(cpuCount);
+ hostDAO.merge(hostEntity);
}
@Override
public int getPhCpuCount() {
- try {
- readLock.lock();
- return getHostEntity().getPhCpuCount();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getPhCpuCount();
}
@Override
public void setPhCpuCount(int phCpuCount) {
- try {
- writeLock.lock();
- getHostEntity().setPhCpuCount(phCpuCount);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setPhCpuCount(phCpuCount);
+ hostDAO.merge(hostEntity);
}
@Override
public long getTotalMemBytes() {
- try {
- readLock.lock();
- return getHostEntity().getTotalMem();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getTotalMem();
}
@Override
public void setTotalMemBytes(long totalMemBytes) {
- try {
- writeLock.lock();
- getHostEntity().setTotalMem(totalMemBytes);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setTotalMem(totalMemBytes);
+ hostDAO.merge(hostEntity);
}
@Override
public long getAvailableMemBytes() {
- try {
- readLock.lock();
- HostStateEntity hostStateEntity = getHostStateEntity();
- return hostStateEntity != null ? hostStateEntity.getAvailableMem() : null;
- }
- finally {
- readLock.unlock();
- }
+ HostStateEntity hostStateEntity = getHostStateEntity();
+ return hostStateEntity != null ? hostStateEntity.getAvailableMem() : null;
}
@Override
public void setAvailableMemBytes(long availableMemBytes) {
- try {
- writeLock.lock();
- HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- getHostStateEntity().setAvailableMem(availableMemBytes);
- saveIfPersisted();
- }
- }
- finally {
- writeLock.unlock();
+ HostStateEntity hostStateEntity = getHostStateEntity();
+ if (hostStateEntity != null) {
+ hostStateEntity.setAvailableMem(availableMemBytes);
+ hostStateDAO.merge(hostStateEntity);
}
}
@Override
public String getOsArch() {
- try {
- readLock.lock();
- return getHostEntity().getOsArch();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getOsArch();
}
@Override
public void setOsArch(String osArch) {
- try {
- writeLock.lock();
- getHostEntity().setOsArch(osArch);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setOsArch(osArch);
+ hostDAO.merge(hostEntity);
}
@Override
public String getOsInfo() {
- try {
- readLock.lock();
- return getHostEntity().getOsInfo();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getOsInfo();
}
@Override
public void setOsInfo(String osInfo) {
- try {
- writeLock.lock();
- getHostEntity().setOsInfo(osInfo);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setOsInfo(osInfo);
+ hostDAO.merge(hostEntity);
}
@Override
public String getOsType() {
- try {
- readLock.lock();
- return getHostEntity().getOsType();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getOsType();
}
@Override
public void setOsType(String osType) {
- try {
- writeLock.lock();
- getHostEntity().setOsType(osType);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setOsType(osType);
+ hostDAO.merge(hostEntity);
}
@Override
@@ -881,212 +750,129 @@ public class HostImpl implements Host {
@Override
public List<DiskInfo> getDisksInfo() {
- try {
- readLock.lock();
- return disksInfo;
- } finally {
- readLock.unlock();
- }
+ return disksInfo;
}
@Override
public void setDisksInfo(List<DiskInfo> disksInfo) {
- try {
- writeLock.lock();
- this.disksInfo = disksInfo;
- } finally {
- writeLock.unlock();
- }
+ this.disksInfo = disksInfo;
}
@Override
public RecoveryReport getRecoveryReport() {
- try {
- readLock.lock();
- return recoveryReport;
- } finally {
- readLock.unlock();
- }
+ return recoveryReport;
}
@Override
public void setRecoveryReport(RecoveryReport recoveryReport) {
- try {
- writeLock.lock();
- this.recoveryReport = recoveryReport;
- } finally {
- writeLock.unlock();
- }
+ this.recoveryReport = recoveryReport;
}
@Override
public HostHealthStatus getHealthStatus() {
- try {
- readLock.lock();
- HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- return gson.fromJson(hostStateEntity.getHealthStatus(), HostHealthStatus.class);
- }
- return null;
- } finally {
- readLock.unlock();
+ HostStateEntity hostStateEntity = getHostStateEntity();
+ if (hostStateEntity != null) {
+ return gson.fromJson(hostStateEntity.getHealthStatus(), HostHealthStatus.class);
}
+
+ return null;
}
@Override
public void setHealthStatus(HostHealthStatus healthStatus) {
- try {
- writeLock.lock();
- HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- hostStateEntity.setHealthStatus(gson.toJson(healthStatus));
-
- if (healthStatus.getHealthStatus().equals(HealthStatus.UNKNOWN)) {
- setStatus(HealthStatus.UNKNOWN.name());
- }
+ HostStateEntity hostStateEntity = getHostStateEntity();
+ if (hostStateEntity != null) {
+ hostStateEntity.setHealthStatus(gson.toJson(healthStatus));
- saveIfPersisted();
+ if (healthStatus.getHealthStatus().equals(HealthStatus.UNKNOWN)) {
+ setStatus(HealthStatus.UNKNOWN.name());
}
- } finally {
- writeLock.unlock();
+
+ hostStateDAO.merge(hostStateEntity);
}
}
@Override
- public String getPrefix() { return prefix; }
+ public String getPrefix() {
+ return prefix;
+ }
@Override
public void setPrefix(String prefix) {
- if (prefix != null && !prefix.equals(this.prefix)) {
- try {
- writeLock.lock();
- this.prefix = prefix;
- } finally {
- writeLock.unlock();
- }
+ if (StringUtils.isNotBlank(prefix) && !StringUtils.equals(this.prefix, prefix)) {
+ this.prefix = prefix;
}
}
@Override
public Map<String, String> getHostAttributes() {
- try {
- readLock.lock();
- return gson.fromJson(getHostEntity().getHostAttributes(),
- hostAttributesType);
- } finally {
- readLock.unlock();
- }
+ return gson.fromJson(getHostEntity().getHostAttributes(), hostAttributesType);
}
@Override
public void setHostAttributes(Map<String, String> hostAttributes) {
- try {
- writeLock.lock();
- HostEntity hostEntity = getHostEntity();
- Map<String, String> hostAttrs = gson.fromJson(hostEntity.getHostAttributes(), hostAttributesType);
- if (hostAttrs == null) {
- hostAttrs = new HashMap<String, String>();
- }
- hostAttrs.putAll(hostAttributes);
- hostEntity.setHostAttributes(gson.toJson(hostAttrs,hostAttributesType));
- saveIfPersisted();
- } finally {
- writeLock.unlock();
+ HostEntity hostEntity = getHostEntity();
+ Map<String, String> hostAttrs = gson.fromJson(hostEntity.getHostAttributes(), hostAttributesType);
+
+ if (hostAttrs == null) {
+ hostAttrs = new ConcurrentHashMap<String, String>();
}
+
+ hostAttrs.putAll(hostAttributes);
+ hostEntity.setHostAttributes(gson.toJson(hostAttrs,hostAttributesType));
+ hostDAO.merge(hostEntity);
}
@Override
public String getRackInfo() {
- try {
- readLock.lock();
- return getHostEntity().getRackInfo();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getRackInfo();
}
@Override
public void setRackInfo(String rackInfo) {
- try {
- writeLock.lock();
- getHostEntity().setRackInfo(rackInfo);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setRackInfo(rackInfo);
+ hostDAO.merge(hostEntity);
}
@Override
public long getLastRegistrationTime() {
- try {
- readLock.lock();
- return getHostEntity().getLastRegistrationTime();
- } finally {
- readLock.unlock();
- }
+ return getHostEntity().getLastRegistrationTime();
}
@Override
public void setLastRegistrationTime(long lastRegistrationTime) {
- try {
- writeLock.lock();
- getHostEntity().setLastRegistrationTime(lastRegistrationTime);
- saveIfPersisted();
- } finally {
- writeLock.unlock();
- }
+ HostEntity hostEntity = getHostEntity();
+ hostEntity.setLastRegistrationTime(lastRegistrationTime);
+ hostDAO.merge(hostEntity);
}
@Override
public long getLastHeartbeatTime() {
- try {
- readLock.lock();
- return lastHeartbeatTime;
- }
- finally {
- readLock.unlock();
- }
+ return lastHeartbeatTime;
}
@Override
public void setLastHeartbeatTime(long lastHeartbeatTime) {
- try {
- writeLock.lock();
- this.lastHeartbeatTime = lastHeartbeatTime;
- }
- finally {
- writeLock.unlock();
- }
+ this.lastHeartbeatTime = lastHeartbeatTime;
}
@Override
public AgentVersion getAgentVersion() {
- try {
- readLock.lock();
- HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- return gson.fromJson(getHostStateEntity().getAgentVersion(),
- AgentVersion.class);
- }
- return null;
- }
- finally {
- readLock.unlock();
+ HostStateEntity hostStateEntity = getHostStateEntity();
+ if (hostStateEntity != null) {
+ return gson.fromJson(hostStateEntity.getAgentVersion(), AgentVersion.class);
}
+
+ return null;
}
@Override
public void setAgentVersion(AgentVersion agentVersion) {
- try {
- writeLock.lock();
- HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- getHostStateEntity().setAgentVersion(gson.toJson(agentVersion));
- saveIfPersisted();
- }
- }
- finally {
- writeLock.unlock();
+ HostStateEntity hostStateEntity = getHostStateEntity();
+ if (hostStateEntity != null) {
+ hostStateEntity.setAgentVersion(gson.toJson(agentVersion));
+ hostStateDAO.merge(hostStateEntity);
}
}
@@ -1098,16 +884,10 @@ public class HostImpl implements Host {
@Override
public void setTimeInState(long timeInState) {
- try {
- writeLock.lock();
- HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- getHostStateEntity().setTimeInState(timeInState);
- saveIfPersisted();
- }
- }
- finally {
- writeLock.unlock();
+ HostStateEntity hostStateEntity = getHostStateEntity();
+ if (hostStateEntity != null) {
+ hostStateEntity.setTimeInState(timeInState);
+ hostStateDAO.merge(hostStateEntity);
}
}
@@ -1119,14 +899,7 @@ public class HostImpl implements Host {
@Override
public void setStatus(String status) {
- if (status != null && !status.equals(this.status)) {
- try {
- writeLock.lock();
- this.status = status;
- } finally {
- writeLock.unlock();
- }
- }
+ this.status = status;
}
@Override
@@ -1148,95 +921,38 @@ public class HostImpl implements Host {
return (null == getHostName() ? 0 : getHostName().hashCode());
}
- public int compareTo(HostEntity other) {
- return getHostName().compareTo(other.getHostName());
- }
-
@Override
public HostResponse convertToResponse() {
- try {
- readLock.lock();
- HostResponse r = new HostResponse(getHostName());
-
- r.setAgentVersion(getAgentVersion());
- r.setAvailableMemBytes(getAvailableMemBytes());
- r.setPhCpuCount(getPhCpuCount());
- r.setCpuCount(getCpuCount());
- r.setDisksInfo(getDisksInfo());
- r.setHealthStatus(getHealthStatus());
- r.setHostAttributes(getHostAttributes());
- r.setIpv4(getIPv4());
- r.setIpv6(getIPv6());
- r.setLastHeartbeatTime(getLastHeartbeatTime());
- r.setLastAgentEnv(lastAgentEnv);
- r.setLastRegistrationTime(getLastRegistrationTime());
- r.setOsArch(getOsArch());
- r.setOsInfo(getOsInfo());
- r.setOsType(getOsType());
- r.setRackInfo(getRackInfo());
- r.setTotalMemBytes(getTotalMemBytes());
- r.setPublicHostName(getPublicHostName());
- r.setHostState(getState().toString());
- r.setStatus(getStatus());
- r.setRecoveryReport(getRecoveryReport());
- r.setRecoverySummary(getRecoveryReport().getSummary());
-
- return r;
- }
- finally {
- readLock.unlock();
- }
- }
-
- /**
- * Shows if Host is persisted to database
- *
- * @return true if persisted
- */
- @Override
- public boolean isPersisted() {
- readLock.lock();
- try {
- return persisted;
- } finally {
- readLock.unlock();
- }
- }
-
- /**
- * Save host to database and make all changes to be saved afterwards
- */
- @Override
- public void persist() {
- writeLock.lock();
- try {
- if (!persisted) {
- persistEntities();
- refresh();
- for (ClusterEntity clusterEntity : hostEntity.getClusterEntities()) {
- try {
- clusters.getClusterById(clusterEntity.getClusterId()).refresh();
- } catch (AmbariException e) {
- LOG.error("Error while looking up the cluster", e);
- throw new RuntimeException("Cluster '" + clusterEntity.getClusterId() + "' was removed", e);
- }
- }
- persisted = true;
- } else {
- //refresh entities from active session
- getHostEntity();
- getHostStateEntity();
- saveIfPersisted();
- }
- } finally {
- writeLock.unlock();
- }
+ HostResponse r = new HostResponse(getHostName());
+
+ r.setAgentVersion(getAgentVersion());
+ r.setAvailableMemBytes(getAvailableMemBytes());
+ r.setPhCpuCount(getPhCpuCount());
+ r.setCpuCount(getCpuCount());
+ r.setDisksInfo(getDisksInfo());
+ r.setHealthStatus(getHealthStatus());
+ r.setHostAttributes(getHostAttributes());
+ r.setIpv4(getIPv4());
+ r.setIpv6(getIPv6());
+ r.setLastHeartbeatTime(getLastHeartbeatTime());
+ r.setLastAgentEnv(lastAgentEnv);
+ r.setLastRegistrationTime(getLastRegistrationTime());
+ r.setOsArch(getOsArch());
+ r.setOsInfo(getOsInfo());
+ r.setOsType(getOsType());
+ r.setRackInfo(getRackInfo());
+ r.setTotalMemBytes(getTotalMemBytes());
+ r.setPublicHostName(getPublicHostName());
+ r.setHostState(getState().toString());
+ r.setStatus(getStatus());
+ r.setRecoveryReport(getRecoveryReport());
+ r.setRecoverySummary(getRecoveryReport().getSummary());
+ return r;
}
@Transactional
- void persistEntities() {
+ private void persistEntities(HostEntity hostEntity) {
hostDAO.create(hostEntity);
- hostStateDAO.create(hostStateEntity);
if (!hostEntity.getClusterEntities().isEmpty()) {
for (ClusterEntity clusterEntity : hostEntity.getClusterEntities()) {
clusterEntity.getHostEntities().add(hostEntity);
@@ -1256,14 +972,6 @@ public class HostImpl implements Host {
}
}
- @Transactional
- void saveIfPersisted() {
- if (isPersisted()) {
- hostDAO.merge(hostEntity);
- hostStateDAO.merge(hostStateEntity);
- }
- }
-
@Override
@Transactional
public boolean addDesiredConfig(long clusterId, boolean selected, String user, Config config) {
@@ -1317,7 +1025,7 @@ public class HostImpl implements Host {
Map<String, DesiredConfig> map = new HashMap<String, DesiredConfig>();
for (HostConfigMapping e : hostConfigMappingDAO.findSelected(
- clusterId, hostEntity.getHostId())) {
+ clusterId, getHostId())) {
DesiredConfig dc = new DesiredConfig();
dc.setTag(e.getVersion());
@@ -1388,66 +1096,50 @@ public class HostImpl implements Host {
}
private HostConfigMapping getDesiredConfigEntity(long clusterId, String type) {
- return hostConfigMappingDAO.findSelectedByType(clusterId, hostEntity.getHostId(), type);
- }
-
- private void ensureMaintMap() {
- if (null == maintMap) {
- HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- String entity = hostStateEntity.getMaintenanceState();
- if (null == entity) {
- maintMap = new HashMap<Long, MaintenanceState>();
- } else {
- try {
- maintMap = gson.fromJson(entity, maintMapType);
- } catch (Exception e) {
- maintMap = new HashMap<Long, MaintenanceState>();
- }
- }
- }
- }
+ return hostConfigMappingDAO.findSelectedByType(clusterId, getHostId(), type);
}
- @Override
- public void setMaintenanceState(long clusterId, MaintenanceState state) {
+ private ConcurrentMap<Long, MaintenanceState> ensureMaintMap(HostStateEntity hostStateEntity) {
+ if (null == hostStateEntity || null == hostStateEntity.getMaintenanceState()) {
+ return new ConcurrentHashMap<>();
+ }
+
+ String entity = hostStateEntity.getMaintenanceState();
+ final ConcurrentMap<Long, MaintenanceState> map;
+
try {
- writeLock.lock();
+ Map<Long, MaintenanceState> gsonMap = gson.fromJson(entity, maintMapType);
+ map = new ConcurrentHashMap<>(gsonMap);
+ } catch (Exception e) {
+ return new ConcurrentHashMap<>();
+ }
- ensureMaintMap();
+ return map;
+ }
- maintMap.put(clusterId, state);
- String json = gson.toJson(maintMap, maintMapType);
+ @Override
+ public void setMaintenanceState(long clusterId, MaintenanceState state) {
+ maintMap.put(clusterId, state);
+ String json = gson.toJson(maintMap, maintMapType);
- HostStateEntity hostStateEntity = getHostStateEntity();
- if (hostStateEntity != null) {
- getHostStateEntity().setMaintenanceState(json);
- saveIfPersisted();
+ HostStateEntity hostStateEntity = getHostStateEntity();
+ if (hostStateEntity != null) {
+ hostStateEntity.setMaintenanceState(json);
+ hostStateDAO.merge(hostStateEntity);
- // broadcast the maintenance mode change
- MaintenanceModeEvent event = new MaintenanceModeEvent(state, this);
- eventPublisher.publish(event);
- }
- } finally {
- writeLock.unlock();
+ // broadcast the maintenance mode change
+ MaintenanceModeEvent event = new MaintenanceModeEvent(state, this);
+ eventPublisher.publish(event);
}
}
@Override
public MaintenanceState getMaintenanceState(long clusterId) {
- try {
- readLock.lock();
-
- ensureMaintMap();
-
- if (!maintMap.containsKey(clusterId)) {
- maintMap.put(clusterId, MaintenanceState.OFF);
- }
-
- return maintMap.get(clusterId);
- } finally {
- readLock.unlock();
+ if (!maintMap.containsKey(clusterId)) {
+ maintMap.put(clusterId, MaintenanceState.OFF);
}
+
+ return maintMap.get(clusterId);
}
/**
@@ -1462,20 +1154,13 @@ public class HostImpl implements Host {
// Get the cached host entity or load it fresh through the DAO.
public HostEntity getHostEntity() {
- if (isPersisted()) {
- hostEntity = hostDAO.findById(hostEntity.getHostId());
- }
- return hostEntity;
+ return hostDAO.findById(hostId);
}
// Get the cached host state entity or load it fresh through the DAO.
public HostStateEntity getHostStateEntity() {
- if (isPersisted()) {
- hostStateEntity = hostStateDAO.findByHostId(hostEntity.getHostId()) ;
- }
- return hostStateEntity;
+ return hostStateDAO.findByHostId(hostId);
}
-
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
index b3e3941..bba0325 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
@@ -742,7 +742,6 @@ public class TopologyManager {
if (null != rackInfoFromTemplate) {
host.setRackInfo(rackInfoFromTemplate);
- host.persist(); //todo this is required only if host is not persisted to database yet, is it really so?
try {
// todo: do we need this in case of blueprints?
ambariContext.getController().registerRackChange(ambariContext.getClusterName(topology.getClusterId()));
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
index b212e93..ffca51d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
@@ -103,7 +103,6 @@ public class ExecutionCommandWrapperTest {
clusters = injector.getInstance(Clusters.class);
clusters.addHost(HOST1);
- clusters.getHost(HOST1).persist();
clusters.addCluster(CLUSTER1, new StackId("HDP-0.1"));
Cluster cluster1 = clusters.getCluster(CLUSTER1);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
index bf9d0db..1ca777d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
@@ -112,10 +112,7 @@ public class TestActionDBAccessorImpl {
// Add this host's name since it is needed for server-side actions.
clusters.addHost(serverHostName);
- clusters.getHost(serverHostName).persist();
-
clusters.addHost(hostName);
- clusters.getHost(hostName).persist();
StackId stackId = new StackId("HDP-0.1");
clusters.addCluster(clusterName, stackId);
@@ -273,7 +270,6 @@ public class TestActionDBAccessorImpl {
for (int i = 0; i < 1000; i++) {
String hostName = "c64-" + i;
clusters.addHost(hostName);
- clusters.getHost(hostName).persist();
}
// create 1 request, 3 stages per host, each with 2 commands
@@ -460,7 +456,6 @@ public class TestActionDBAccessorImpl {
requestIds.add(requestId);
populateActionDB(db, hostName, requestId, stageId);
clusters.addHost("host2");
- clusters.getHost("host2").persist();
populateActionDB(db, hostName, requestId + 1, stageId);
List<Long> requestIdsResult =
db.getRequestsByStatus(null, BaseRequest.DEFAULT_PAGE_SIZE, false);
@@ -546,11 +541,8 @@ public class TestActionDBAccessorImpl {
s.setStageId(stageId);
clusters.addHost("host2");
- clusters.getHost("host2").persist();
clusters.addHost("host3");
- clusters.getHost("host3").persist();
clusters.addHost("host4");
- clusters.getHost("host4").persist();
s.addHostRoleExecutionCommand("host1", Role.HBASE_MASTER,
RoleCommand.START,
@@ -680,7 +672,6 @@ public class TestActionDBAccessorImpl {
String host = "host" + i;
clusters.addHost(host);
- clusters.getHost(host).persist();
s.addHostRoleExecutionCommand("host" + i, Role.HBASE_MASTER,
RoleCommand.START, null, "cluster1", "HBASE", false, false);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
index fa51f91..da54789 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
@@ -24,21 +24,19 @@ import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import junit.framework.Assert;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
import org.apache.ambari.server.agent.ActionQueue;
import org.apache.ambari.server.agent.CommandReport;
import org.apache.ambari.server.audit.AuditLogger;
-import org.apache.ambari.server.controller.HostsMap;
import org.apache.ambari.server.events.publishers.JPAEventPublisher;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -57,7 +55,8 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
import com.google.inject.persist.UnitOfWork;
-import static org.junit.Assert.assertNotNull;
+
+import junit.framework.Assert;
public class TestActionManager {
@@ -79,7 +78,6 @@ public class TestActionManager {
stageFactory = injector.getInstance(StageFactory.class);
clusters.addHost(hostname);
- clusters.getHost(hostname).persist();
StackId stackId = new StackId("HDP-0.1");
clusters.addCluster(clusterName, stackId);
unitOfWork = injector.getInstance(UnitOfWork.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
index 37a6ae0..674025c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
@@ -68,6 +68,7 @@ import org.apache.ambari.server.state.scheduler.RequestExecutionFactory;
import org.apache.ambari.server.state.scheduler.RequestExecutionImpl;
import org.apache.ambari.server.state.stack.OsFamily;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
+import org.apache.ambari.server.topology.PersistedState;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jettison.json.JSONException;
@@ -314,6 +315,7 @@ public class AgentResourceTest extends RandomPortJerseyTest {
bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class));
bind(HostDAO.class).toInstance(createNiceMock(HostDAO.class));
bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
+ bind(PersistedState.class).toInstance(createNiceMock(PersistedState.class));
}
private void installDependencies() {
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
index 6e3f2e0..dd93374 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
@@ -543,7 +543,6 @@ public class HeartbeatProcessorTest {
public void testCommandReport() throws AmbariException {
injector.injectMembers(this);
clusters.addHost(DummyHostname1);
- clusters.getHost(DummyHostname1).persist();
StackId dummyStackId = new StackId(DummyStackId);
clusters.addCluster(DummyCluster, dummyStackId);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
index e813e66..43503fa 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java
@@ -213,7 +213,6 @@ public class HeartbeatTestHelper {
clusters.addHost(hostName);
Host host = clusters.getHost(hostName);
host.setHostAttributes(hostAttributes);
- host.persist();
HostEntity hostEntity = hostDAO.findByName(hostName);
Assert.assertNotNull(hostEntity);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
index d121fcb..503c8e5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
@@ -146,10 +146,8 @@ public class TestHeartbeatMonitor {
Clusters clusters = injector.getInstance(Clusters.class);
clusters.addHost(hostname1);
setOsFamily(clusters.getHost(hostname1), "redhat", "6.3");
- clusters.getHost(hostname1).persist();
clusters.addHost(hostname2);
setOsFamily(clusters.getHost(hostname2), "redhat", "6.3");
- clusters.getHost(hostname2).persist();
clusters.addCluster(clusterName, stackId);
Cluster cluster = clusters.getCluster(clusterName);
helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
@@ -232,10 +230,8 @@ public class TestHeartbeatMonitor {
Clusters clusters = injector.getInstance(Clusters.class);
clusters.addHost(hostname1);
setOsFamily(clusters.getHost(hostname1), "redhat", "6.3");
- clusters.getHost(hostname1).persist();
clusters.addHost(hostname2);
setOsFamily(clusters.getHost(hostname2), "redhat", "6.3");
- clusters.getHost(hostname2).persist();
clusters.addCluster(clusterName, stackId);
Cluster cluster = clusters.getCluster(clusterName);
@@ -360,7 +356,6 @@ public class TestHeartbeatMonitor {
Clusters clusters = injector.getInstance(Clusters.class);
clusters.addHost(hostname1);
setOsFamily(clusters.getHost(hostname1), "redhat", "5.9");
- clusters.getHost(hostname1).persist();
clusters.addCluster(clusterName, stackId);
Cluster cluster = clusters.getCluster(clusterName);
@@ -443,7 +438,6 @@ public class TestHeartbeatMonitor {
Clusters clusters = injector.getInstance(Clusters.class);
clusters.addHost(hostname1);
setOsFamily(clusters.getHost(hostname1), "redhat", "6.3");
- clusters.getHost(hostname1).persist();
clusters.addCluster(clusterName, stackId);
Cluster cluster = clusters.getCluster(clusterName);
@@ -559,11 +553,9 @@ public class TestHeartbeatMonitor {
clusters.addHost(hostname1);
setOsFamily(clusters.getHost(hostname1), "redhat", "6.3");
- clusters.getHost(hostname1).persist();
clusters.addHost(hostname2);
setOsFamily(clusters.getHost(hostname2), "redhat", "6.3");
- clusters.getHost(hostname2).persist();
clusters.addCluster(clusterName, stackId);
Cluster cluster = clusters.getCluster(clusterName);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
index 080ca3a..c45c59d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
@@ -18,8 +18,8 @@
package org.apache.ambari.server.checks;
import java.util.ArrayList;
-import java.util.List;
import java.util.Collections;
+import java.util.List;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
@@ -44,8 +44,6 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -147,7 +145,6 @@ public class InstallPackagesCheckTest {
final List<HostVersionEntity> hostVersionEntities = new ArrayList<HostVersionEntity>();
for(String hostName : hostNames) {
Host host = Mockito.mock(Host.class);
- host.setHostName(hostName);
Mockito.when(host.getHostName()).thenReturn(hostName);
Mockito.when(host.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
hosts.add(host);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index e82900d..5556071 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@ -470,7 +470,6 @@ public class AmbariCustomCommandExecutionHelperTest {
clusters.addHost(hostname);
setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
clusters.getHost(hostname).setState(HostState.HEALTHY);
- clusters.getHost(hostname).persist();
if (null != clusterName) {
clusters.mapHostToCluster(hostname, clusterName);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 197b925..a3521fd 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -18,7 +18,6 @@
package org.apache.ambari.server.controller;
-import org.apache.ambari.server.controller.internal.DeleteStatusMetaData;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.createStrictMock;
@@ -79,10 +78,10 @@ import org.apache.ambari.server.actionmanager.TargetHostType;
import org.apache.ambari.server.agent.ExecutionCommand;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.audit.AuditLogger;
-import org.apache.ambari.server.audit.AuditLoggerModule;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProviderTest;
import org.apache.ambari.server.controller.internal.ComponentResourceProviderTest;
+import org.apache.ambari.server.controller.internal.DeleteStatusMetaData;
import org.apache.ambari.server.controller.internal.HostComponentResourceProviderTest;
import org.apache.ambari.server.controller.internal.HostResourceProviderTest;
import org.apache.ambari.server.controller.internal.RequestOperationLevel;
@@ -171,7 +170,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
-import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
@@ -313,7 +311,6 @@ public class AmbariManagementControllerTest {
clusters.addHost(hostname);
setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
clusters.getHost(hostname).setState(HostState.HEALTHY);
- clusters.getHost(hostname).persist();
}
if (null != clusterName) {
@@ -628,8 +625,6 @@ public class AmbariManagementControllerTest {
clusters.addHost(host2);
setOsFamily(clusters.getHost(host1), "redhat", "6.3");
setOsFamily(clusters.getHost(host2), "redhat", "6.3");
- clusters.getHost(host1).persist();
- clusters.getHost(host2).persist();
controller.createCluster(r);
Assert.assertNotNull(clusters.getCluster(cluster1));
@@ -1674,19 +1669,16 @@ public class AmbariManagementControllerTest {
h1.setIPv4("ipv41");
h1.setIPv6("ipv61");
setOsFamily(h1, "redhat", "6.3");
- h1.persist();
clusters.addHost(host2);
Host h2 = clusters.getHost(host2);
h2.setIPv4("ipv42");
h2.setIPv6("ipv62");
setOsFamily(h2, "redhat", "6.3");
- h2.persist();
clusters.addHost(host3);
Host h3 = clusters.getHost(host3);
h3.setIPv4("ipv43");
h3.setIPv6("ipv63");
setOsFamily(h3, "redhat", "6.3");
- h3.persist();
try {
set1.clear();
@@ -1808,8 +1800,6 @@ public class AmbariManagementControllerTest {
clusters.addHost(host2);
setOsFamily(clusters.getHost(host1), "redhat", "5.9");
setOsFamily(clusters.getHost(host2), "redhat", "5.9");
- clusters.getHost(host1).persist();
- clusters.getHost(host2).persist();
HostRequest request = new HostRequest(host2, "foo", new HashMap<String, String>());
requests.add(request);
@@ -1864,9 +1854,6 @@ public class AmbariManagementControllerTest {
setOsFamily(clusters.getHost(host1), "redhat", "5.9");
setOsFamily(clusters.getHost(host2), "redhat", "5.9");
setOsFamily(clusters.getHost(host3), "redhat", "5.9");
- clusters.getHost(host1).persist();
- clusters.getHost(host2).persist();
- clusters.getHost(host3).persist();
HostRequest r1 = new HostRequest(host1, cluster1, null);
HostRequest r2 = new HostRequest(host2, cluster1, null);
@@ -3136,7 +3123,6 @@ public class AmbariManagementControllerTest {
"centos5");
clusters.addHost(host4);
setOsFamily(clusters.getHost(host4), "redhat", "5.9");
- clusters.getHost(host4).persist();
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("a1", "b1");
@@ -8377,7 +8363,6 @@ public class AmbariManagementControllerTest {
RepositoryVersionState.INSTALLING);
clusters.addHost(hostName1);
setOsFamily(clusters.getHost(hostName1), "redhat", "5.9");
- clusters.getHost(hostName1).persist();
clusters.mapHostsToCluster(new HashSet<String>(){
{add(hostName1);}}, cluster1);
@@ -9353,13 +9338,10 @@ public class AmbariManagementControllerTest {
clusters.addHost("host3");
Host host = clusters.getHost("host1");
setOsFamily(host, "redhat", "6.3");
- host.persist();
host = clusters.getHost("host2");
setOsFamily(host, "redhat", "6.3");
- host.persist();
host = clusters.getHost("host3");
setOsFamily(host, "redhat", "6.3");
- host.persist();
ClusterRequest clusterRequest = new ClusterRequest(null, cluster1, "HDP-1.2.0", null);
amc.createCluster(clusterRequest);
@@ -9402,12 +9384,10 @@ public class AmbariManagementControllerTest {
clusters.addHost(HOST1);
Host host = clusters.getHost(HOST1);
setOsFamily(host, "redhat", "6.3");
- host.persist();
clusters.addHost(HOST2);
host = clusters.getHost(HOST2);
setOsFamily(host, "redhat", "6.3");
- host.persist();
AmbariManagementController amc = injector.getInstance(AmbariManagementController.class);
@@ -9497,13 +9477,10 @@ public class AmbariManagementControllerTest {
clusters.addHost(host3);
Host host = clusters.getHost("host1");
setOsFamily(host, "redhat", "5.9");
- host.persist();
host = clusters.getHost("host2");
setOsFamily(host, "redhat", "5.9");
- host.persist();
host = clusters.getHost("host3");
setOsFamily(host, "redhat", "5.9");
- host.persist();
ClusterRequest clusterRequest = new ClusterRequest(null, cluster1, "HDP-1.2.0", null);
amc.createCluster(clusterRequest);
@@ -9802,7 +9779,6 @@ public class AmbariManagementControllerTest {
clusters.addHost(HOST1);
Host host = clusters.getHost(HOST1);
setOsFamily(host, "redhat", "5.9");
- host.persist();
ClusterRequest clusterRequest = new ClusterRequest(null, CLUSTER_NAME, STACK_ID, null);
amc.createCluster(clusterRequest);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
index 73b5b75..58f597f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
@@ -178,7 +178,6 @@ public class BackgroundCustomCommandExecutionTest {
clusters.addHost(hostname);
setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
clusters.getHost(hostname).setState(HostState.HEALTHY);
- clusters.getHost(hostname).persist();
if (null != clusterName) {
clusters.mapHostToCluster(hostname, clusterName);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
index 2512bb3..a54fb98 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java
@@ -24,8 +24,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import junit.framework.Assert;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.internal.ComponentResourceProviderTest;
import org.apache.ambari.server.controller.internal.ServiceResourceProviderTest;
@@ -46,11 +44,13 @@ import org.apache.ambari.server.state.State;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.security.core.context.SecurityContextHolder;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
-import org.springframework.security.core.context.SecurityContextHolder;
+
+import junit.framework.Assert;
@SuppressWarnings("serial")
public class RefreshYarnCapacitySchedulerReleaseConfigTest {
@@ -177,7 +177,6 @@ public class RefreshYarnCapacitySchedulerReleaseConfigTest {
clusters.addHost(hostname);
setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
clusters.getHost(hostname).setState(HostState.HEALTHY);
- clusters.getHost(hostname).persist();
if (null != clusterName) {
clusters.mapHostToCluster(hostname, clusterName);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
index 9f610f9..c5eb76e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
@@ -170,14 +170,12 @@ public class JMXHostProviderTest {
hostAttributes.put("os_family", "redhat");
hostAttributes.put("os_release_version", "5.9");
clusters.getHost("h1").setHostAttributes(hostAttributes);
- clusters.getHost("h1").persist();
String host2 = "h2";
clusters.addHost(host2);
hostAttributes = new HashMap<String, String>();
hostAttributes.put("os_family", "redhat");
hostAttributes.put("os_release_version", "6.3");
clusters.getHost("h2").setHostAttributes(hostAttributes);
- clusters.getHost("h2").persist();
clusters.mapHostToCluster(host1, clusterName);
clusters.mapHostToCluster(host2, clusterName);
@@ -262,14 +260,12 @@ public class JMXHostProviderTest {
hostAttributes.put("os_family", "redhat");
hostAttributes.put("os_release_version", "5.9");
clusters.getHost("h1").setHostAttributes(hostAttributes);
- clusters.getHost("h1").persist();
String host2 = "h2";
clusters.addHost(host2);
hostAttributes = new HashMap<String, String>();
hostAttributes.put("os_family", "redhat");
hostAttributes.put("os_release_version", "6.3");
clusters.getHost("h2").setHostAttributes(hostAttributes);
- clusters.getHost("h2").persist();
clusters.mapHostToCluster(host1, clusterName);
clusters.mapHostToCluster(host2, clusterName);
@@ -365,14 +361,12 @@ public class JMXHostProviderTest {
hostAttributes.put("os_family", "redhat");
hostAttributes.put("os_release_version", "5.9");
clusters.getHost("h1").setHostAttributes(hostAttributes);
- clusters.getHost("h1").persist();
String host2 = "h2";
clusters.addHost(host2);
hostAttributes = new HashMap<String, String>();
hostAttributes.put("os_family", "redhat");
hostAttributes.put("os_release_version", "6.3");
clusters.getHost("h2").setHostAttributes(hostAttributes);
- clusters.getHost("h2").persist();
clusters.mapHostToCluster(host1, clusterName);
clusters.mapHostToCluster(host2, clusterName);
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
index 2721731..958957b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
@@ -146,7 +146,6 @@ public class StackDefinedPropertyProviderTest {
hostAttributes.put("os_family", "redhat");
hostAttributes.put("os_release_version", "6.3");
host.setHostAttributes(hostAttributes);
- host.persist();
clusters.mapHostToCluster("h1", "c2");
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
index 139702c..a0940ba 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
@@ -174,7 +174,6 @@ public class UpgradeResourceProviderHDP22Test {
hostAttributes.put("os_release_version", "6.3");
host.setHostAttributes(hostAttributes);
host.setState(HostState.HEALTHY);
- host.persist();
clusters.mapHostToCluster("h1", "c1");
http://git-wip-us.apache.org/repos/asf/ambari/blob/38700445/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index 63892cf..c2c8ced 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -232,7 +232,6 @@ public class UpgradeResourceProviderTest {
hostAttributes.put("os_release_version", "6.3");
host.setHostAttributes(hostAttributes);
host.setState(HostState.HEALTHY);
- host.persist();
clusters.mapHostToCluster("h1", "c1");
@@ -590,7 +589,6 @@ public class UpgradeResourceProviderTest {
hostAttributes.put("os_family", "redhat");
hostAttributes.put("os_release_version", "6.3");
host.setHostAttributes(hostAttributes);
- host.persist();
clusters.mapHostToCluster("h2", "c1");
Cluster cluster = clusters.getCluster("c1");