|
@@ -145,12 +145,14 @@ public class ClusterImpl implements Cluster {
|
|
|
|
|
|
private StackId desiredStackVersion;
|
|
|
|
|
|
+ private volatile boolean desiredStackVersionSet = true;
|
|
|
+
|
|
|
private volatile Map<String, Service> services = null;
|
|
|
|
|
|
/**
|
|
|
* [ Config Type -> [ Config Version Tag -> Config ] ]
|
|
|
*/
|
|
|
- private Map<String, Map<String, Config>> allConfigs;
|
|
|
+ private volatile Map<String, Map<String, Config>> allConfigs;
|
|
|
|
|
|
/**
|
|
|
* [ ServiceName -> [ ServiceComponentName -> [ HostName -> [ ... ] ] ] ]
|
|
@@ -918,6 +920,7 @@ public class ClusterImpl implements Cluster {
|
|
|
|
|
|
@Override
|
|
|
public StackId getDesiredStackVersion() {
|
|
|
+ loadStackVersion();
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
try {
|
|
|
return desiredStackVersion;
|
|
@@ -1756,6 +1759,7 @@ public class ClusterImpl implements Cluster {
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Config> getConfigsByType(String configType) {
|
|
|
+ loadConfigurations();
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
try {
|
|
|
if (!allConfigs.containsKey(configType)) {
|
|
@@ -1770,6 +1774,7 @@ public class ClusterImpl implements Cluster {
|
|
|
|
|
|
@Override
|
|
|
public Config getConfig(String configType, String versionTag) {
|
|
|
+ loadConfigurations();
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
try {
|
|
|
if (!allConfigs.containsKey(configType)
|
|
@@ -1801,6 +1806,7 @@ public class ClusterImpl implements Cluster {
|
|
|
|
|
|
@Override
|
|
|
public void addConfig(Config config) {
|
|
|
+ loadConfigurations();
|
|
|
clusterGlobalLock.writeLock().lock();
|
|
|
try {
|
|
|
if (config.getType() == null || config.getType().isEmpty()) {
|
|
@@ -1818,6 +1824,7 @@ public class ClusterImpl implements Cluster {
|
|
|
|
|
|
@Override
|
|
|
public Collection<Config> getAllConfigs() {
|
|
|
+ loadConfigurations();
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
try {
|
|
|
List<Config> list = new ArrayList<Config>();
|
|
@@ -1835,6 +1842,7 @@ public class ClusterImpl implements Cluster {
|
|
|
@Override
|
|
|
public ClusterResponse convertToResponse()
|
|
|
throws AmbariException {
|
|
|
+ loadStackVersion();
|
|
|
String clusterName = getClusterName();
|
|
|
Map<String, Host> hosts = clusters.getHostsForCluster(clusterName);
|
|
|
clusterGlobalLock.readLock().lock();
|
|
@@ -1851,6 +1859,7 @@ public class ClusterImpl implements Cluster {
|
|
|
@Override
|
|
|
public void debugDump(StringBuilder sb) {
|
|
|
loadServices();
|
|
|
+ loadStackVersion();
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
try {
|
|
|
sb.append("Cluster={ clusterName=").append(getClusterName()).append(
|
|
@@ -2022,6 +2031,7 @@ public class ClusterImpl implements Cluster {
|
|
|
|
|
|
@Override
|
|
|
public Map<String, DesiredConfig> getDesiredConfigs() {
|
|
|
+ loadConfigurations();
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
try {
|
|
|
Map<String, DesiredConfig> map = new HashMap<String, DesiredConfig>();
|
|
@@ -2205,8 +2215,8 @@ public class ClusterImpl implements Cluster {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @RequiresSession
|
|
|
public List<ServiceConfigVersionResponse> getServiceConfigVersions() {
|
|
|
+ loadConfigurations();
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
try {
|
|
|
List<ServiceConfigVersionResponse> serviceConfigVersionResponses = new ArrayList<ServiceConfigVersionResponse>();
|
|
@@ -2468,6 +2478,7 @@ public class ClusterImpl implements Cluster {
|
|
|
|
|
|
@Override
|
|
|
public Config getDesiredConfigByType(String configType) {
|
|
|
+ loadConfigurations();
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
try {
|
|
|
for (ClusterConfigMappingEntity e : clusterEntity.getConfigMappingEntities()) {
|
|
@@ -2873,7 +2884,6 @@ public class ClusterImpl implements Cluster {
|
|
|
* {@inheritDoc}
|
|
|
*/
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
public void applyLatestConfigurations(StackId stackId) {
|
|
|
clusterGlobalLock.writeLock().lock();
|
|
|
try {
|
|
@@ -3036,4 +3046,80 @@ public class ClusterImpl implements Cluster {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void loadConfigurations() {
|
|
|
+ if (allConfigs != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ clusterGlobalLock.writeLock().lock();
|
|
|
+ try {
|
|
|
+ if (allConfigs != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cacheConfigurations();
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ clusterGlobalLock.writeLock().unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadStackVersion() {
|
|
|
+ if (desiredStackVersionSet) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ clusterGlobalLock.writeLock().lock();
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (desiredStackVersionSet) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ desiredStackVersion = new StackId(clusterEntity.getDesiredStack());
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(desiredStackVersion.getStackName()) && !
|
|
|
+ StringUtils.isEmpty(desiredStackVersion.getStackVersion())) {
|
|
|
+ try {
|
|
|
+ loadServiceConfigTypes();
|
|
|
+ } catch (AmbariException e) {
|
|
|
+ //TODO recheck wrapping exception here, required for lazy loading after invalidation
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ desiredStackVersionSet = true;
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ clusterGlobalLock.writeLock().unlock();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Purpose of this method is to clear all cached data to re-read it from database.
|
|
|
+ * To be used in case of desync.
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void invalidateData() {
|
|
|
+ clusterGlobalLock.writeLock().lock();
|
|
|
+ try {
|
|
|
+ allConfigs = null;
|
|
|
+ services = null;
|
|
|
+ desiredStackVersionSet = false;
|
|
|
+
|
|
|
+ serviceComponentHosts.clear();
|
|
|
+ serviceComponentHostsByHost.clear();
|
|
|
+ svcHostsLoaded = false;
|
|
|
+
|
|
|
+ clusterConfigGroups = null;
|
|
|
+
|
|
|
+ //TODO investigate reset request executions, it has separate api which is not too heavy
|
|
|
+
|
|
|
+ refresh();
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ clusterGlobalLock.writeLock().unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|