http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java index 664ba42..e6c50fb 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.ambari.annotations.Experimental; +import org.apache.ambari.annotations.ExperimentalFeature; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.ClusterNotFoundException; import org.apache.ambari.server.DuplicateResourceException; @@ -420,29 +422,14 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider for (ServiceRequest request : requests) { Cluster cluster = clusters.getCluster(request.getClusterName()); - String desiredStack = request.getDesiredStack(); - String desiredRepositoryVersion = request.getDesiredRepositoryVersion(); - RepositoryVersionEntity repositoryVersion = null; - if (StringUtils.isNotBlank(desiredStack) && StringUtils.isNotBlank(desiredRepositoryVersion)){ - repositoryVersion = repositoryVersionDAO.findByStackAndVersion(new StackId(desiredStack), - desiredRepositoryVersion); - } - - if (null == desiredStack) { - desiredStack = cluster.getDesiredStackVersion().toString(); - } - if (null == repositoryVersion) { - List<RepositoryVersionEntity> allVersions = repositoryVersionDAO.findByStack(new StackId(desiredStack)); - - if (CollectionUtils.isNotEmpty(allVersions)) { - repositoryVersion = allVersions.get(0); - } - } + RepositoryVersionEntity repositoryVersion = request.getResolvedRepository(); if (null == repositoryVersion) { throw new AmbariException(String.format("Could not find any repositories defined by %s", desiredStack)); + } else { + desiredStack = repositoryVersion.getStackId().toString(); } Service s = cluster.addService(request.getServiceName(), repositoryVersion); @@ -451,7 +438,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider * Get the credential_store_supported field only from the stack definition. * Not possible to update the value through a request. */ - StackId stackId = cluster.getDesiredStackVersion(); + StackId stackId = repositoryVersion.getStackId(); AmbariMetaInfo ambariMetaInfo = getManagementController().getAmbariMetaInfo(); ServiceInfo serviceInfo = ambariMetaInfo.getService(stackId.getStackName(), stackId.getStackVersion(), request.getServiceName()); @@ -621,6 +608,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider if (!serviceNames.containsKey(request.getClusterName())) { serviceNames.put(request.getClusterName(), new HashSet<String>()); } + if (serviceNames.get(request.getClusterName()) .contains(request.getServiceName())) { // TODO throw single exception @@ -746,6 +734,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider } } } + for (Service service : depServices) { updateServiceComponents(requestStages, changedComps, changedScHosts, ignoredScHosts, reqOpLvl, service, State.STARTED); @@ -767,6 +756,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider service.setCredentialStoreEnabled(credentialStoreEnabled); } + Cluster cluster = clusters.getCluster(clusterNames.iterator().next()); return controller.addStages(requestStages, cluster, requestProperties, @@ -877,7 +867,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider + ", hostname=" + sch.getHostName() + ", currentState=" + oldSchState + ", newDesiredState=" + newState; - StackId sid = cluster.getDesiredStackVersion(); + StackId sid = service.getDesiredStackId(); if ( ambariMetaInfo.getComponent( sid.getStackName(), sid.getStackVersion(), sc.getServiceName(), @@ -1050,6 +1040,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider AmbariMetaInfo ambariMetaInfo = getManagementController().getAmbariMetaInfo(); Map<String, Set<String>> serviceNames = new HashMap<>(); Set<String> duplicates = new HashSet<>(); + for (ServiceRequest request : requests) { final String clusterName = request.getClusterName(); final String serviceName = request.getServiceName(); @@ -1102,7 +1093,38 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider // Expected } - StackId stackId = cluster.getDesiredStackVersion(); + @Experimental(feature = ExperimentalFeature.MULTI_SERVICE, + comment = "the desired stack should not come from the cluster. this is a placeholder until the UI sends correct information") + String desiredStack = request.getDesiredStack(); + StackId stackId = new StackId(desiredStack); + + String desiredRepositoryVersion = request.getDesiredRepositoryVersion(); + RepositoryVersionEntity repositoryVersion = null; + if (StringUtils.isNotBlank(desiredRepositoryVersion)){ + repositoryVersion = repositoryVersionDAO.findByVersion(desiredRepositoryVersion); + } + + if (null == repositoryVersion) { + // !!! FIXME hack until the UI always sends the repository + if (null == desiredStack) { + desiredStack = cluster.getDesiredStackVersion().toString(); + } + + List<RepositoryVersionEntity> allVersions = repositoryVersionDAO.findByStack(new StackId(desiredStack)); + + if (CollectionUtils.isNotEmpty(allVersions)) { + repositoryVersion = allVersions.get(0); + } + } + + if (null == repositoryVersion) { + throw new AmbariException(String.format("Could not find any repositories defined by %s", desiredStack)); + } else { + stackId = repositoryVersion.getStackId(); + } + + request.setResolvedRepository(repositoryVersion); + if (!ambariMetaInfo.isValidService(stackId.getStackName(), stackId.getStackVersion(), request.getServiceName())) { throw new IllegalArgumentException("Unsupported or invalid service in stack, clusterName=" + clusterName
http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java index 8972ca2..e9682fb 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.apache.ambari.server.ServiceNotFoundException; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.configuration.ComponentSSLConfiguration; import org.apache.ambari.server.controller.jmx.JMXHostProvider; @@ -46,6 +47,7 @@ import org.apache.ambari.server.controller.utilities.StreamProvider; import org.apache.ambari.server.security.authorization.AuthorizationException; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.stack.Metric; import org.apache.ambari.server.state.stack.MetricDefinition; @@ -160,12 +162,19 @@ public class StackDefinedPropertyProvider implements PropertyProvider { String componentName = r.getPropertyValue(componentNamePropertyId).toString(); Cluster cluster = clusters.getCluster(clusterName); - StackId stack = cluster.getDesiredStackVersion(); - String svc = metaInfo.getComponentToService(stack.getStackName(), - stack.getStackVersion(), componentName); + Service service = null; + + try { + service = cluster.getServiceByComponentName(componentName); + } catch (ServiceNotFoundException e) { + LOG.debug("Could not load component {}", componentName); + continue; + } + + StackId stack = service.getDesiredStackId(); List<MetricDefinition> defs = metaInfo.getMetrics( - stack.getStackName(), stack.getStackVersion(), svc, componentName, type.name()); + stack.getStackName(), stack.getStackVersion(), service.getName(), componentName, type.name()); if (null == defs || 0 == defs.size()) { continue; @@ -227,6 +236,7 @@ public class StackDefinedPropertyProvider implements PropertyProvider { // Need to rethrow the catched 'AuthorizationException'. throw e; } catch (Exception e) { + e.printStackTrace(); LOG.error("Error loading deferred resources", e); throw new SystemException("Error loading deferred resources", e); } http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java index 6027ce7..115a043 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java @@ -1456,7 +1456,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider actionContext.setMaintenanceModeHostExcluded(true); ExecuteCommandJson jsons = s_commandExecutionHelper.get().getCommandJson(actionContext, - cluster, null); + cluster, context.getRepositoryVersion()); Stage stage = s_stageFactory.get().createNew(request.getId().longValue(), "/tmp/ambari", cluster.getClusterName(), cluster.getClusterId(), stageText, jsons.getClusterHostInfo(), http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java index c69d00b..3cf119c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java @@ -41,6 +41,7 @@ import org.apache.ambari.server.security.authorization.RoleAuthorization; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.ComponentInfo; import org.apache.ambari.server.state.LogDefinition; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -71,7 +72,7 @@ public class LoggingSearchPropertyProvider implements PropertyProvider { @Inject private LoggingRequestHelperFactory loggingRequestHelperFactory; - + @Override public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException { Map<String, Boolean> isLogSearchRunning = new HashMap<>(); @@ -186,12 +187,13 @@ public class LoggingSearchPropertyProvider implements PropertyProvider { private String getMappedComponentNameForSearch(String clusterName, String componentName, AmbariManagementController controller) { try { AmbariMetaInfo metaInfo = controller.getAmbariMetaInfo(); - StackId stackId = - controller.getClusters().getCluster(clusterName).getCurrentStackVersion(); + Cluster cluster = controller.getClusters().getCluster(clusterName); + String serviceName = controller.findServiceName(cluster, componentName); + Service service = cluster.getService(serviceName); + StackId stackId = service.getDesiredStackId(); + final String stackName = stackId.getStackName(); final String stackVersion = stackId.getStackVersion(); - final String serviceName = - metaInfo.getComponentToService(stackName, stackVersion, componentName); ComponentInfo componentInfo = metaInfo.getComponent(stackName, stackVersion, serviceName, componentName); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java index c4c2ddc..f77d47a 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java @@ -59,6 +59,8 @@ import org.apache.ambari.server.controller.spi.TemporalInfo; import org.apache.ambari.server.controller.utilities.PropertyHelper; import org.apache.ambari.server.events.MetricsCollectorHostDownEvent; import org.apache.ambari.server.events.publishers.AmbariEventPublisher; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric; @@ -308,12 +310,15 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider { StackId stackId; try { AmbariManagementController managementController = AmbariServer.getController(); - stackId = managementController.getClusters().getCluster(clusterName).getCurrentStackVersion(); + Cluster cluster = managementController.getClusters().getCluster(clusterName); + Service service = cluster.getServiceByComponentName(componentName); + stackId = service.getDesiredStackId(); + if (stackId != null) { String stackName = stackId.getStackName(); String version = stackId.getStackVersion(); AmbariMetaInfo ambariMetaInfo = managementController.getAmbariMetaInfo(); - String serviceName = ambariMetaInfo.getComponentToService(stackName, version, componentName); + String serviceName = service.getName(); String timeLineAppId = ambariMetaInfo.getComponent(stackName, version, serviceName, componentName).getTimelineAppid(); if (timeLineAppId != null){ timelineAppIdCache.put(componentName, timeLineAppId); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java index 264ba03..7cd2624 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java @@ -32,6 +32,7 @@ import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.ComponentInfo; import org.apache.ambari.server.state.MaintenanceState; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; import org.slf4j.Logger; @@ -78,12 +79,14 @@ public class DefaultServiceCalculatedState implements ServiceCalculatedState { return null; } + @Override public State getState(String clusterName, String serviceName) { try { Cluster cluster = getCluster(clusterName); if (cluster != null && managementControllerProvider != null) { + Service service = cluster.getService(serviceName); AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo(); - StackId stackId = cluster.getDesiredStackVersion(); + StackId stackId = service.getDesiredStackId(); ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, serviceName, null, null, null); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java index d44515c..d953156 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java @@ -29,6 +29,7 @@ import org.apache.ambari.server.controller.ServiceComponentHostRequest; import org.apache.ambari.server.controller.ServiceComponentHostResponse; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.ComponentInfo; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; @@ -45,7 +46,8 @@ public final class HBaseServiceCalculatedState extends DefaultServiceCalculatedS Cluster cluster = getCluster(clusterName); if (cluster != null && managementControllerProvider != null) { AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo(); - StackId stackId = cluster.getDesiredStackVersion(); + Service service = cluster.getService(serviceName); + StackId stackId = service.getDesiredStackId(); ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, serviceName, null, null, null); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java index 89d4004..20f5fc7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java @@ -29,6 +29,7 @@ import org.apache.ambari.server.controller.ServiceComponentHostRequest; import org.apache.ambari.server.controller.ServiceComponentHostResponse; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.ComponentInfo; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; @@ -45,7 +46,8 @@ public final class HDFSServiceCalculatedState extends DefaultServiceCalculatedSt Cluster cluster = getCluster(clusterName); if (cluster != null && managementControllerProvider != null) { AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo(); - StackId stackId = cluster.getDesiredStackVersion(); + Service service = cluster.getService(serviceName); + StackId stackId = service.getDesiredStackId(); ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, serviceName, null, null, null); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java index 0643c94..69ecddd 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java @@ -29,6 +29,7 @@ import org.apache.ambari.server.controller.ServiceComponentHostRequest; import org.apache.ambari.server.controller.ServiceComponentHostResponse; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.ComponentInfo; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; @@ -45,7 +46,9 @@ public final class HiveServiceCalculatedState extends DefaultServiceCalculatedSt Cluster cluster = getCluster(clusterName); if (cluster != null && managementControllerProvider != null) { AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo(); - StackId stackId = cluster.getDesiredStackVersion(); + Service service = cluster.getService(serviceName); + StackId stackId = service.getDesiredStackId(); + ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, serviceName, null, null, null); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java index 4d0cf92..76f047b 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java @@ -29,6 +29,7 @@ import org.apache.ambari.server.controller.ServiceComponentHostRequest; import org.apache.ambari.server.controller.ServiceComponentHostResponse; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.ComponentInfo; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; @@ -45,7 +46,9 @@ public final class OozieServiceCalculatedState extends DefaultServiceCalculatedS Cluster cluster = getCluster(clusterName); if (cluster != null && managementControllerProvider != null) { AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo(); - StackId stackId = cluster.getDesiredStackVersion(); + Service service = cluster.getService(serviceName); + StackId stackId = service.getDesiredStackId(); + ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, serviceName, null, null, null); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java index 24c4602..e73f6b4 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java @@ -29,6 +29,7 @@ import org.apache.ambari.server.controller.ServiceComponentHostRequest; import org.apache.ambari.server.controller.ServiceComponentHostResponse; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.ComponentInfo; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; @@ -45,7 +46,9 @@ public final class YARNServiceCalculatedState extends DefaultServiceCalculatedSt Cluster cluster = getCluster(clusterName); if (cluster != null && managementControllerProvider != null) { AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo(); - StackId stackId = cluster.getDesiredStackVersion(); + Service service = cluster.getService(serviceName); + StackId stackId = service.getDesiredStackId(); + ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, serviceName, null, null, null); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java index 40ec0a1..b217b45 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java @@ -133,25 +133,31 @@ public class RoleCommandOrder implements Cloneable { this.sectionKeys = sectionKeys; dependencies.clear(); - StackId stackId = cluster.getCurrentStackVersion(); - StackInfo stack = null; - try { - stack = ambariMetaInfo.getStack(stackId.getStackName(), - stackId.getStackVersion()); - } catch (AmbariException ignored) { - // initialize() will fail with NPE + Set<StackId> stackIds = new HashSet<>(); + for (Service service : cluster.getServices().values()) { + stackIds.add(service.getDesiredStackId()); } - Map<String,Object> userData = stack.getRoleCommandOrder().getContent(); - Map<String,Object> generalSection = - (Map<String, Object>) userData.get(GENERAL_DEPS_KEY); + for (StackId stackId : stackIds) { + StackInfo stack = null; + try { + stack = ambariMetaInfo.getStack(stackId.getStackName(), + stackId.getStackVersion()); + } catch (AmbariException ignored) { + // initialize() will fail with NPE + } + + Map<String,Object> userData = stack.getRoleCommandOrder().getContent(); + Map<String,Object> generalSection = + (Map<String, Object>) userData.get(GENERAL_DEPS_KEY); - addDependencies(generalSection); + addDependencies(generalSection); - for (String sectionKey : sectionKeys) { - Map<String, Object> section = (Map<String, Object>) userData.get(sectionKey); + for (String sectionKey : sectionKeys) { + Map<String, Object> section = (Map<String, Object>) userData.get(sectionKey); - addDependencies(section); + addDependencies(section); + } } extendTransitiveDependency(); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java index 3817570..f0a99e2 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java @@ -348,7 +348,7 @@ public class ClusterDAO { @Transactional public void remove(ClusterEntity clusterEntity) { - entityManagerProvider.get().remove(merge(clusterEntity)); + entityManagerProvider.get().remove(clusterEntity); } @Transactional http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java index a2472b6..f94e45d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java @@ -211,4 +211,18 @@ public class RepositoryVersionDAO extends CrudDAO<RepositoryVersionEntity, Long> "repositoryVersionsFromDefinition", RepositoryVersionEntity.class); return daoUtils.selectList(query); } + + + /** + * @param repositoryVersion + * @return + */ + @RequiresSession + public RepositoryVersionEntity findByVersion(String repositoryVersion) { + TypedQuery<RepositoryVersionEntity> query = entityManagerProvider.get().createNamedQuery("repositoryVersionByVersion", RepositoryVersionEntity.class); + + query.setParameter("version", repositoryVersion); + + return daoUtils.selectOne(query); + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java index 47abde4..513325f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java @@ -75,8 +75,10 @@ import com.google.inject.Provider; @NamedQueries({ @NamedQuery(name = "repositoryVersionByDisplayName", query = "SELECT repoversion FROM RepositoryVersionEntity repoversion WHERE repoversion.displayName=:displayname"), @NamedQuery(name = "repositoryVersionByStack", query = "SELECT repoversion FROM RepositoryVersionEntity repoversion WHERE repoversion.stack.stackName=:stackName AND repoversion.stack.stackVersion=:stackVersion"), + @NamedQuery(name = "repositoryVersionByVersion", query = "SELECT repoversion FROM RepositoryVersionEntity repoversion WHERE repoversion.version=:version"), @NamedQuery(name = "repositoryVersionByStackNameAndVersion", query = "SELECT repoversion FROM RepositoryVersionEntity repoversion WHERE repoversion.stack.stackName=:stackName AND repoversion.version=:version"), @NamedQuery(name = "repositoryVersionsFromDefinition", query = "SELECT repoversion FROM RepositoryVersionEntity repoversion WHERE repoversion.versionXsd IS NOT NULL") + }) @StaticallyInject public class RepositoryVersionEntity { http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryAction.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryAction.java index 7a99f09..743e5c8 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryAction.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryAction.java @@ -34,7 +34,6 @@ import org.apache.ambari.server.actionmanager.HostRoleCommand; import org.apache.ambari.server.actionmanager.HostRoleStatus; import org.apache.ambari.server.actionmanager.ServiceComponentHostEventWrapper; import org.apache.ambari.server.agent.CommandReport; -import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.metadata.ActionMetadata; import org.apache.ambari.server.orm.dao.HostRoleCommandDAO; import org.apache.ambari.server.orm.dao.UpgradeDAO; @@ -45,7 +44,6 @@ import org.apache.ambari.server.serveraction.AbstractServerAction; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.ServiceComponentHostEvent; -import org.apache.ambari.server.state.StackId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,9 +100,6 @@ public class AutoSkipFailedSummaryAction extends AbstractServerAction { private ActionMetadata actionMetadata; @Inject - private AmbariMetaInfo ambariMetaInfo; - - @Inject private Clusters clusters; /** @@ -125,7 +120,6 @@ public class AutoSkipFailedSummaryAction extends AbstractServerAction { String clusterName = hostRoleCommand.getExecutionCommandWrapper().getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); - StackId stackId = cluster.getDesiredStackVersion(); // use the host role command to get to the parent upgrade group UpgradeItemEntity upgradeItem = m_upgradeDAO.findUpgradeItemByRequestAndStage(requestId,stageId); @@ -197,8 +191,8 @@ public class AutoSkipFailedSummaryAction extends AbstractServerAction { Role role = skippedTask.getRole(); if (! publishedHostComponentsOnHost.contains(role)) { HashMap<String, String> details = new HashMap<>(); - String service = ambariMetaInfo.getComponentToService( - stackId.getStackName(), stackId.getStackVersion(), role.toString()); + + String service = cluster.getServiceByComponentName(role.toString()).getName(); details.put("service", service); details.put("component", role.toString()); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java index cf2844b..4d943f4 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java @@ -74,6 +74,14 @@ public interface Cluster { Service getService(String serviceName) throws AmbariException; /** + * Gets a service from the given component name. + * @param componentName + * @return + * @throws AmbariException + */ + Service getServiceByComponentName(String componentName) throws AmbariException; + + /** * Get all services * @return */ @@ -199,34 +207,6 @@ public interface Cluster { VersionDefinitionXml versionDefinitionXml, boolean forceInstalled) throws AmbariException; /** - - * Update state of a cluster stack version for cluster based on states of host versions and stackids. - * @param repositoryVersion the repository version entity whose version is a value like 2.2.1.0-100) - * @throws AmbariException - */ -// void recalculateClusterVersionState(RepositoryVersionEntity repositoryVersion) throws AmbariException; - - /** - * Update state of all cluster stack versions for cluster based on states of host versions. - * @throws AmbariException - */ -// void recalculateAllClusterVersionStates() throws AmbariException; - - /** - * Transition an existing cluster version from one state to another. - * - * @param stackId - * Stack ID - * @param version - * Stack version - * @param state - * Desired state - * @throws AmbariException - */ -// void transitionClusterVersion(StackId stackId, String version, -// RepositoryVersionState state) throws AmbariException; - - /** * Gets whether the cluster is still initializing or has finished with its * deployment requests. * http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java index aa53564..88e0cb8 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java @@ -209,15 +209,6 @@ public interface Clusters { throws AmbariException; /** - * Sets the current stack version for the cluster - * @param clusterName The name of the cluster - * @param stackId The identifier for the stack - * @throws AmbariException - */ - void setCurrentStackVersion(String clusterName, StackId stackId) - throws AmbariException; - - /** * Update the host set for clusters and the host attributes associated with the hosts * @param hostsClusters * @param hostAttributes http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java index d6cd997..78f10cd 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java @@ -19,6 +19,8 @@ package org.apache.ambari.server.state; import java.util.Map; +import org.apache.ambari.annotations.Experimental; +import org.apache.ambari.annotations.ExperimentalFeature; import org.apache.ambari.server.orm.entities.ClusterConfigEntity; import com.google.inject.assistedinject.Assisted; @@ -38,9 +40,25 @@ public interface ConfigFactory { * @param mapAttributes * @return */ + @Experimental(feature = ExperimentalFeature.MULTI_SERVICE, + comment = "This constructor is only used for test compatibility and should be removed") Config createNew(Cluster cluster, @Assisted("type") String type, @Assisted("tag") String tag, Map<String, String> map, Map<String, Map<String, String>> mapAttributes); + + /** + * Creates a new {@link Config} object using provided values. + * + * @param cluster + * @param type + * @param tag + * @param map + * @param mapAttributes + * @return + */ + Config createNew(StackId stackId, Cluster cluster, @Assisted("type") String type, @Assisted("tag") String tag, + Map<String, String> map, Map<String, Map<String, String>> mapAttributes); + /** * Creates a new {@link Config} object using provided entity * http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java index 05b50ab..96c2dd0 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java @@ -17,14 +17,12 @@ */ package org.apache.ambari.server.state; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -775,23 +773,31 @@ public class ConfigHelper { * @throws AmbariException */ public String getPropertyValueFromStackDefinitions(Cluster cluster, String configType, String propertyName) throws AmbariException { - StackId stackId = cluster.getCurrentStackVersion(); - StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), - stackId.getStackVersion()); - for (ServiceInfo serviceInfo : stack.getServices()) { - Set<PropertyInfo> serviceProperties = ambariMetaInfo.getServiceProperties(stack.getName(), stack.getVersion(), serviceInfo.getName()); - Set<PropertyInfo> stackProperties = ambariMetaInfo.getStackProperties(stack.getName(), stack.getVersion()); - serviceProperties.addAll(stackProperties); + Set<StackId> stackIds = new HashSet<>(); - for (PropertyInfo stackProperty : serviceProperties) { - String stackPropertyConfigType = fileNameToConfigType(stackProperty.getFilename()); + for (Service service : cluster.getServices().values()) { + stackIds.add(service.getDesiredStackId()); + } + + for (StackId stackId : stackIds) { - if (stackProperty.getName().equals(propertyName) && stackPropertyConfigType.equals(configType)) { - return stackProperty.getValue(); + StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), + stackId.getStackVersion()); + + for (ServiceInfo serviceInfo : stack.getServices()) { + Set<PropertyInfo> serviceProperties = ambariMetaInfo.getServiceProperties(stack.getName(), stack.getVersion(), serviceInfo.getName()); + Set<PropertyInfo> stackProperties = ambariMetaInfo.getStackProperties(stack.getName(), stack.getVersion()); + serviceProperties.addAll(stackProperties); + + for (PropertyInfo stackProperty : serviceProperties) { + String stackPropertyConfigType = fileNameToConfigType(stackProperty.getFilename()); + + if (stackProperty.getName().equals(propertyName) && stackPropertyConfigType.equals(configType)) { + return stackProperty.getValue(); + } } } - } return null; @@ -850,20 +856,22 @@ public class ConfigHelper { } public ServiceInfo getPropertyOwnerService(Cluster cluster, String configType, String propertyName) throws AmbariException { - StackId stackId = cluster.getCurrentStackVersion(); - StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()); - for (ServiceInfo serviceInfo : stack.getServices()) { - Set<PropertyInfo> serviceProperties = ambariMetaInfo.getServiceProperties(stack.getName(), stack.getVersion(), serviceInfo.getName()); + for (Service service : cluster.getServices().values()) { + StackId stackId = service.getDesiredStackId(); + StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()); - for (PropertyInfo stackProperty : serviceProperties) { - String stackPropertyConfigType = fileNameToConfigType(stackProperty.getFilename()); + for (ServiceInfo serviceInfo : stack.getServices()) { + Set<PropertyInfo> serviceProperties = ambariMetaInfo.getServiceProperties(stack.getName(), stack.getVersion(), serviceInfo.getName()); - if (stackProperty.getName().equals(propertyName) && stackPropertyConfigType.equals(configType)) { - return serviceInfo; + for (PropertyInfo stackProperty : serviceProperties) { + String stackPropertyConfigType = fileNameToConfigType(stackProperty.getFilename()); + + if (stackProperty.getName().equals(propertyName) && stackPropertyConfigType.equals(configType)) { + return serviceInfo; + } } } - } return null; @@ -873,7 +881,9 @@ public class ConfigHelper { // The original implementation of this method is to return all properties regardless of whether // they should be excluded or not. By setting removeExcluded to false in the method invocation // below, no attempt will be made to remove properties that exist in excluded types. - return getServiceProperties(cluster.getCurrentStackVersion(), serviceName, false); + Service service = cluster.getService(serviceName); + + return getServiceProperties(service.getDesiredStackId(), serviceName, false); } /** @@ -922,10 +932,20 @@ public class ConfigHelper { } public Set<PropertyInfo> getStackProperties(Cluster cluster) throws AmbariException { - StackId stackId = cluster.getCurrentStackVersion(); - StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()); - return ambariMetaInfo.getStackProperties(stack.getName(), stack.getVersion()); + Set<StackId> stackIds = new HashSet<>(); + for (Service service : cluster.getServices().values()) { + stackIds.add(service.getDesiredStackId()); + } + + Set<PropertyInfo> propertySets = new HashSet<>(); + + for (StackId stackId : stackIds) { + StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()); + propertySets.addAll(ambariMetaInfo.getStackProperties(stack.getName(), stack.getVersion())); + } + + return propertySets; } /** @@ -1138,7 +1158,7 @@ public class ConfigHelper { } } - return controller.createConfig(cluster, type, properties, tag, propertyAttributes); + return controller.createConfig(cluster.getDesiredStackVersion(), cluster, type, properties, tag, propertyAttributes); } /** @@ -1197,28 +1217,6 @@ public class ConfigHelper { return defaultPropertiesByType; } - /** - * Gets whether configurations are stale for a given service host component. - * - * @param sch - * the SCH to calcualte config staleness for (not {@code null}). - * @param desiredConfigs - * the desired configurations for the cluster. Obtaining these can be - * expensive and since this method operates on SCH's, it could be - * called 10,000's of times when generating cluster/host responses. - * Therefore, the caller should build these once and pass them in. If - * {@code null}, then this method will retrieve them at runtime, - * incurring a performance penality. - * @return - * @throws AmbariException - */ - private boolean calculateIsStaleConfigs(ServiceComponentHost sch, - Map<String, DesiredConfig> desiredConfigs) throws AmbariException { - - HostComponentDesiredStateEntity hostComponentDesiredStateEntity = sch.getDesiredStateEntity(); - return calculateIsStaleConfigs(sch, desiredConfigs, hostComponentDesiredStateEntity); - } - private boolean calculateIsStaleConfigs(ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs, HostComponentDesiredStateEntity hostComponentDesiredStateEntity) throws AmbariException { @@ -1252,7 +1250,7 @@ public class ConfigHelper { stale = false; - StackId stackId = cluster.getDesiredStackVersion(); + StackId stackId = sch.getServiceComponent().getDesiredStackId(); ServiceInfo serviceInfo = ambariMetaInfo.getService(stackId.getStackName(), stackId.getStackVersion(), sch.getServiceName()); @@ -1326,64 +1324,6 @@ public class ConfigHelper { } /** - * @return <code>true</code> if any service on the stack defines a property - * for the type. - */ - private boolean hasPropertyFor(StackId stack, String type, - Collection<String> keys) throws AmbariException { - - for (ServiceInfo svc : ambariMetaInfo.getServices(stack.getStackName(), - stack.getStackVersion()).values()) { - - if (svc.hasDependencyAndPropertyFor(type, keys)) { - return true; - } - - } - - return false; - } - - /** - * @return the keys that have changed values - */ - private Collection<String> findChangedKeys(Cluster cluster, String type, - Collection<String> desiredTags, Collection<String> actualTags) { - - Map<String, String> desiredValues = new HashMap<>(); - Map<String, String> actualValues = new HashMap<>(); - - for (String tag : desiredTags) { - Config config = cluster.getConfig(type, tag); - if (null != config) { - desiredValues.putAll(config.getProperties()); - } - } - - for (String tag : actualTags) { - Config config = cluster.getConfig(type, tag); - if (null != config) { - actualValues.putAll(config.getProperties()); - } - } - - List<String> keys = new ArrayList<>(); - - for (Entry<String, String> entry : desiredValues.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - - if (!actualValues.containsKey(key)) { - keys.add(key); - } else if (!actualValues.get(key).equals(value)) { - keys.add(key); - } - } - - return keys; - } - - /** * @return the map of tags for a desired config */ private Map<String, String> buildTags(HostConfig hc) { @@ -1419,23 +1359,6 @@ public class ConfigHelper { return !desiredSet.equals(actualSet); } - /** - * @return the list of combined config property names - */ - private Collection<String> mergeKeyNames(Cluster cluster, String type, Collection<String> tags) { - Set<String> names = new HashSet<>(); - - for (String tag : tags) { - Config config = cluster.getConfig(type, tag); - if (null != config) { - names.addAll(config.getProperties().keySet()); - } - } - - return names; - } - - public static String fileNameToConfigType(String filename) { int extIndex = filename.indexOf(AmbariMetaInfo.SERVICE_CONFIG_FILE_NAME_POSTFIX); return filename.substring(0, extIndex); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java index 0e40254..0adf1bd 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java @@ -101,6 +101,17 @@ public class ConfigImpl implements Config { @Assisted Map<String, String> properties, @Assisted @Nullable Map<String, Map<String, String>> propertiesAttributes, ClusterDAO clusterDAO, Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory) { + this(cluster.getDesiredStackVersion(), cluster, type, tag, properties, propertiesAttributes, + clusterDAO, gson, eventPublisher, lockFactory); + } + + + @AssistedInject + ConfigImpl(@Assisted @Nullable StackId stackId, @Assisted Cluster cluster, @Assisted("type") String type, + @Assisted("tag") @Nullable String tag, + @Assisted Map<String, String> properties, + @Assisted @Nullable Map<String, Map<String, String>> propertiesAttributes, ClusterDAO clusterDAO, + Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory) { propertyLock = lockFactory.newReadWriteLock(PROPERTY_LOCK_LABEL); @@ -139,7 +150,7 @@ public class ConfigImpl implements Config { // when creating a brand new config without a backing entity, use the // cluster's desired stack as the config's stack - stackId = cluster.getDesiredStackVersion(); + this.stackId = stackId; propertiesTypes = cluster.getConfigPropertiesTypes(type); persist(entity); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java index 9a35bcc..632298d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java @@ -254,4 +254,11 @@ public interface ServiceComponentHost { */ HostVersionEntity recalculateHostVersionState() throws AmbariException; + /** + * Convenience method to get the desired stack id from the service component + * + * @return the desired stack id + */ + StackId getDesiredStackId(); + } http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java index 3c8ef35..ca73f17 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java @@ -40,7 +40,6 @@ import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO; import org.apache.ambari.server.orm.dao.HostComponentStateDAO; import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO; -import org.apache.ambari.server.orm.dao.StackDAO; import org.apache.ambari.server.orm.entities.ClusterServiceEntity; import org.apache.ambari.server.orm.entities.ClusterServiceEntityPK; import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity; @@ -92,11 +91,6 @@ public class ServiceComponentImpl implements ServiceComponent { */ private final long desiredStateEntityId; - /** - * Data access object used for lookup up stacks. - */ - private final StackDAO stackDAO; - @Inject private RepositoryVersionDAO repoVersionDAO; @@ -108,7 +102,7 @@ public class ServiceComponentImpl implements ServiceComponent { AmbariMetaInfo ambariMetaInfo, ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO, ClusterServiceDAO clusterServiceDAO, ServiceComponentHostFactory serviceComponentHostFactory, - StackDAO stackDAO, AmbariEventPublisher eventPublisher) + AmbariEventPublisher eventPublisher) throws AmbariException { this.ambariMetaInfo = ambariMetaInfo; @@ -117,7 +111,6 @@ public class ServiceComponentImpl implements ServiceComponent { this.serviceComponentDesiredStateDAO = serviceComponentDesiredStateDAO; this.clusterServiceDAO = clusterServiceDAO; this.serviceComponentHostFactory = serviceComponentHostFactory; - this.stackDAO = stackDAO; this.eventPublisher = eventPublisher; ServiceComponentDesiredStateEntity desiredStateEntity = new ServiceComponentDesiredStateEntity(); @@ -161,14 +154,13 @@ public class ServiceComponentImpl implements ServiceComponent { ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO, ClusterServiceDAO clusterServiceDAO, HostComponentDesiredStateDAO hostComponentDesiredStateDAO, - ServiceComponentHostFactory serviceComponentHostFactory, StackDAO stackDAO, + ServiceComponentHostFactory serviceComponentHostFactory, AmbariEventPublisher eventPublisher) throws AmbariException { this.service = service; this.serviceComponentDesiredStateDAO = serviceComponentDesiredStateDAO; this.clusterServiceDAO = clusterServiceDAO; this.serviceComponentHostFactory = serviceComponentHostFactory; - this.stackDAO = stackDAO; this.eventPublisher = eventPublisher; this.ambariMetaInfo = ambariMetaInfo; @@ -191,7 +183,7 @@ public class ServiceComponentImpl implements ServiceComponent { serviceComponentHostFactory.createExisting(this, hostComponentStateEntity, hostComponentDesiredStateEntity)); } catch(ProvisionException ex) { - StackId currentStackId = service.getCluster().getCurrentStackVersion(); + StackId currentStackId = getDesiredStackId(); LOG.error(String.format("Can not get host component info: stackName=%s, stackVersion=%s, serviceName=%s, componentName=%s, hostname=%s", currentStackId.getStackName(), currentStackId.getStackVersion(), service.getName(),serviceComponentDesiredStateEntity.getComponentName(), hostComponentStateEntity.getHostName())); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java index 6bb0ffb..6c7c238 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java @@ -161,7 +161,7 @@ public class ServiceImpl implements Service { serviceComponentFactory.createExisting(this, serviceComponentDesiredStateEntity)); } catch(ProvisionException ex) { - StackId stackId = cluster.getCurrentStackVersion(); + StackId stackId = new StackId(serviceComponentDesiredStateEntity.getDesiredStack()); LOG.error(String.format("Can not get component info: stackName=%s, stackVersion=%s, serviceName=%s, componentName=%s", stackId.getStackName(), stackId.getStackVersion(), serviceEntity.getServiceName(),serviceComponentDesiredStateEntity.getComponentName())); @@ -186,8 +186,8 @@ public class ServiceImpl implements Service { @Override public void updateServiceInfo() throws AmbariException { try { - ServiceInfo serviceInfo = ambariMetaInfo.getService(cluster.getDesiredStackVersion().getStackName(), - cluster.getDesiredStackVersion().getStackVersion(), getName()); + ServiceInfo serviceInfo = ambariMetaInfo.getService(this); + isClientOnlyService = serviceInfo.isClientOnlyService(); isCredentialStoreSupported = serviceInfo.isCredentialStoreSupported(); isCredentialStoreRequired = serviceInfo.isCredentialStoreRequired(); @@ -197,7 +197,7 @@ public class ServiceImpl implements Service { + " not recognized in stack info" + ", clusterName=" + cluster.getClusterName() + ", serviceName=" + getName() - + ", stackInfo=" + cluster.getDesiredStackVersion().getStackName()); + + ", stackInfo=" + getDesiredStackId().getStackName()); } } @@ -308,8 +308,13 @@ public class ServiceImpl implements Service { @Override public StackId getDesiredStackId() { ServiceDesiredStateEntity serviceDesiredStateEntity = getServiceDesiredStateEntity(); - StackEntity desiredStackEntity = serviceDesiredStateEntity.getDesiredStack(); - return new StackId(desiredStackEntity); + + if (null == serviceDesiredStateEntity) { + return null; + } else { + StackEntity desiredStackEntity = serviceDesiredStateEntity.getDesiredStack(); + return new StackId(desiredStackEntity); + } } /** @@ -470,7 +475,7 @@ public class ServiceImpl implements Service { persistEntities(serviceEntity); // publish the service installed event - StackId stackId = cluster.getDesiredStackVersion(); + StackId stackId = getDesiredStackId(); cluster.addService(this); ServiceInstalledEvent event = new ServiceInstalledEvent(getClusterId(), stackId.getStackName(), @@ -595,10 +600,14 @@ public class ServiceImpl implements Service { deleteAllComponents(); deleteAllServiceConfigs(); + StackId stackId = getDesiredStackId(); + removeEntities(); // publish the service removed event - StackId stackId = cluster.getDesiredStackVersion(); + if (null == stackId) { + return; + } ServiceRemovedEvent event = new ServiceRemovedEvent(getClusterId(), stackId.getStackName(), stackId.getStackVersion(), getName()); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java index e4ac23e..23b6db1 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java @@ -34,7 +34,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import javax.annotation.Nullable; @@ -195,9 +194,6 @@ public class ClusterImpl implements Cluster { private final ReadWriteLock clusterGlobalLock; - // This is a lock for operations that do not need to be cluster global - private final Lock hostTransitionStateWriteLock; - /** * The unique ID of the {@link @ClusterEntity}. */ @@ -315,7 +311,6 @@ public class ClusterImpl implements Cluster { injector.injectMembers(this); clusterGlobalLock = lockFactory.newReadWriteLock("clusterGlobalLock"); - hostTransitionStateWriteLock = lockFactory.newLock("hostTransitionStateLock"); loadStackVersion(); loadServices(); @@ -876,6 +871,20 @@ public class ClusterImpl implements Cluster { } @Override + public Service getServiceByComponentName(String componentName) throws AmbariException { + for (Service service : services.values()) { + for (ServiceComponent component : service.getServiceComponents().values()) { + if (component.getName().equals(componentName)) { + return service; + } + } + } + + throw new ServiceNotFoundException(getClusterName(), "component: " + componentName); + } + + + @Override public StackId getDesiredStackVersion() { return desiredStackVersion; } http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/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 bdc4f90..3700c9f 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 @@ -37,7 +37,6 @@ import org.apache.ambari.server.ClusterNotFoundException; import org.apache.ambari.server.DuplicateResourceException; import org.apache.ambari.server.HostNotFoundException; import org.apache.ambari.server.agent.DiskInfo; -import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.events.HostRegisteredEvent; import org.apache.ambari.server.events.HostsAddedEvent; import org.apache.ambari.server.events.HostsRemovedEvent; @@ -78,7 +77,6 @@ import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.HostHealthStatus; import org.apache.ambari.server.state.HostHealthStatus.HealthStatus; import org.apache.ambari.server.state.HostState; -import org.apache.ambari.server.state.RepositoryInfo; import org.apache.ambari.server.state.SecurityType; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.configgroup.ConfigGroup; @@ -128,8 +126,6 @@ public class ClustersImpl implements Clusters { @Inject private HostFactory hostFactory; @Inject - private AmbariMetaInfo ambariMetaInfo; - @Inject private SecurityHelper securityHelper; @Inject private TopologyLogicalTaskDAO topologyLogicalTaskDAO; @@ -297,25 +293,6 @@ public class ClustersImpl implements Clusters { } @Override - public void setCurrentStackVersion(String clusterName, StackId stackId) - throws AmbariException{ - - if(stackId == null || clusterName == null || clusterName.isEmpty()){ - LOG.warn("Unable to set version for cluster " + clusterName); - throw new AmbariException("Unable to set" - + " version=" + stackId - + " for cluster " + clusterName); - } - - Cluster cluster = clusters.get(clusterName); - if (null == cluster) { - throw new ClusterNotFoundException(clusterName); - } - - cluster.setCurrentStackVersion(stackId); - } - - @Override public List<Host> getHosts() { return new ArrayList<>(hosts.values()); } @@ -428,13 +405,6 @@ public class ClustersImpl implements Clusters { eventPublisher.publish(event); } - private boolean isOsSupportedByClusterStack(Cluster c, Host h) throws AmbariException { - Map<String, List<RepositoryInfo>> repos = - ambariMetaInfo.getRepository(c.getDesiredStackVersion().getStackName(), - c.getDesiredStackVersion().getStackVersion()); - return !(repos == null || repos.isEmpty()) && repos.containsKey(h.getOsFamily()); - } - @Override public void updateHostWithClusterAndAttributes( Map<String, Set<String>> hostClusters, @@ -527,11 +497,9 @@ public class ClustersImpl implements Clusters { @Override public void mapHostToCluster(String hostname, String clusterName) throws AmbariException { - Host host = null; - Cluster cluster = null; - host = getHost(hostname); - cluster = getCluster(clusterName); + Host host = getHost(hostname); + Cluster cluster = getCluster(clusterName); // check to ensure there are no duplicates for (Cluster c : hostClusterMap.get(hostname)) { @@ -541,15 +509,6 @@ public class ClustersImpl implements Clusters { } } - if (!isOsSupportedByClusterStack(cluster, host)) { - String message = "Trying to map host to cluster where stack does not" - + " support host's os type" + ", clusterName=" + clusterName - + ", clusterStackId=" + cluster.getDesiredStackVersion().getStackId() - + ", hostname=" + hostname + ", hostOsFamily=" + host.getOsFamily(); - LOG.error(message); - throw new AmbariException(message); - } - long clusterId = cluster.getClusterId(); if (LOG.isDebugEnabled()) { LOG.debug("Mapping host {} to cluster {} (id={})", hostname, clusterName, http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java index a74e2a2..a04df3c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java @@ -409,7 +409,7 @@ public class ConfigGroupImpl implements ConfigGroup { (cluster.getClusterId(), config.getType(), config.getTag()); if (clusterConfigEntity == null) { - config = configFactory.createNew(cluster, config.getType(), config.getTag(), + config = configFactory.createNew(null, cluster, config.getType(), config.getTag(), config.getProperties(), config.getPropertiesAttributes()); entry.setValue(config); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServiceCheckGrouping.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServiceCheckGrouping.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServiceCheckGrouping.java index dbfce48..e07b822 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServiceCheckGrouping.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ServiceCheckGrouping.java @@ -180,7 +180,7 @@ public class ServiceCheckGrouping extends Grouping { Service svc = clusterServices.get(service); if (null != svc) { // Services that only have clients such as Pig can still have service check scripts. - StackId stackId = m_cluster.getDesiredStackVersion(); + StackId stackId = svc.getDesiredStackId(); try { ServiceInfo si = m_metaInfo.getService(stackId.getStackName(), stackId.getStackVersion(), service); CommandScriptDefinition script = si.getCommandScript(); @@ -201,6 +201,7 @@ public class ServiceCheckGrouping extends Grouping { * Attempts to merge all the service check groupings. This merges the excluded list and * the priorities. The priorities are merged in an order specific manner. */ + @Override public void merge(Iterator<Grouping> iterator) throws AmbariException { List<String> priorities = new ArrayList<>(); priorities.addAll(getPriorities()); http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java index e08b1f9..1b84f46 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java @@ -1567,4 +1567,13 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { public ServiceComponent getServiceComponent() { return serviceComponent; } + + /** + * {@inheritDoc} + */ + @Override + public StackId getDesiredStackId() { + return serviceComponent.getDesiredStackId(); + } + } http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java index cb12959..5939fca 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java @@ -42,6 +42,8 @@ import javax.persistence.EntityManager; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import org.apache.ambari.annotations.Experimental; +import org.apache.ambari.annotations.ExperimentalFeature; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.configuration.Configuration; @@ -67,6 +69,7 @@ import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigHelper; import org.apache.ambari.server.state.PropertyInfo; import org.apache.ambari.server.state.PropertyUpgradeBehavior; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.ServiceInfo; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.StackInfo; @@ -584,7 +587,7 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog { propertiesAttributes = Collections.emptyMap(); } - controller.createConfig(cluster, configType, mergedProperties, newTag, propertiesAttributes); + controller.createConfig(cluster.getDesiredStackVersion(), cluster, configType, mergedProperties, newTag, propertiesAttributes); Config baseConfig = cluster.getConfig(configType, newTag); if (baseConfig != null) { @@ -772,7 +775,13 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog { protected KerberosDescriptor getKerberosDescriptor(Cluster cluster) throws AmbariException { // Get the Stack-defined Kerberos Descriptor (aka default Kerberos Descriptor) AmbariMetaInfo ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class); - StackId stackId = cluster.getCurrentStackVersion(); + + + // !!! FIXME + @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES, + comment = "can only take the first stack we find until we can support multiple with Kerberos") + StackId stackId = getStackId(cluster); + KerberosDescriptor defaultDescriptor = ambariMetaInfo.getKerberosDescriptor(stackId.getStackName(), stackId.getStackVersion()); // Get the User-set Kerberos Descriptor @@ -1065,7 +1074,13 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog { for (final Cluster cluster : clusterMap.values()) { long clusterID = cluster.getClusterId(); - StackId stackId = cluster.getDesiredStackVersion(); + Service service = cluster.getServices().get(serviceName); + if (null == service) { + continue; + } + + StackId stackId = service.getDesiredStackId(); + Map<String, Object> widgetDescriptor = null; StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()); ServiceInfo serviceInfo = stackInfo.getService(serviceName); @@ -1133,4 +1148,10 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog { } } } + + @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES, + comment = "can only take the first stack we find until we can support multiple with Kerberos") + private StackId getStackId(Cluster cluster) throws AmbariException { + return cluster.getServices().values().iterator().next().getDesiredStackId(); + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java index 38ad5ba..9418489 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/FinalUpgradeCatalog.java @@ -20,8 +20,10 @@ package org.apache.ambari.server.upgrade; import java.sql.SQLException; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.api.services.AmbariMetaInfo; @@ -30,6 +32,7 @@ import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.ConfigHelper; import org.apache.ambari.server.state.PropertyInfo; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.StackInfo; import org.apache.ambari.server.utils.VersionUtils; @@ -91,17 +94,24 @@ public class FinalUpgradeCatalog extends AbstractUpgradeCatalog { Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { - Map<String, String> propertyMap = new HashMap<>(); - StackId stackId = cluster.getCurrentStackVersion(); - StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()); - List<PropertyInfo> properties = stackInfo.getProperties(); - for(PropertyInfo property : properties) { - if(property.getName().equals(ConfigHelper.CLUSTER_ENV_STACK_FEATURES_PROPERTY) || - property.getName().equals(ConfigHelper.CLUSTER_ENV_STACK_TOOLS_PROPERTY)) { - propertyMap.put(property.getName(), property.getValue()); + + Set<StackId> stackIds = new HashSet<>(); + for (Service service : cluster.getServices().values()) { + stackIds.add(service.getDesiredStackId()); + } + + for (StackId stackId : stackIds) { + Map<String, String> propertyMap = new HashMap<>(); + StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()); + List<PropertyInfo> properties = stackInfo.getProperties(); + for(PropertyInfo property : properties) { + if(property.getName().equals(ConfigHelper.CLUSTER_ENV_STACK_FEATURES_PROPERTY) || + property.getName().equals(ConfigHelper.CLUSTER_ENV_STACK_TOOLS_PROPERTY)) { + propertyMap.put(property.getName(), property.getValue()); + } } + updateConfigurationPropertiesForCluster(cluster, ConfigHelper.CLUSTER_ENV, propertyMap, true, true); } - updateConfigurationPropertiesForCluster(cluster, ConfigHelper.CLUSTER_ENV, propertyMap, true, true); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java index edf107a..b7a2e78 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java @@ -27,8 +27,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.ambari.annotations.Experimental; +import org.apache.ambari.annotations.ExperimentalFeature; import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.orm.DBAccessor; import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo; @@ -36,7 +37,6 @@ import org.apache.ambari.server.orm.dao.ClusterDAO; import org.apache.ambari.server.orm.dao.ClusterServiceDAO; import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO; import org.apache.ambari.server.orm.dao.HostComponentStateDAO; -import org.apache.ambari.server.orm.dao.MetainfoDAO; import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO; import org.apache.ambari.server.orm.dao.ServiceDesiredStateDAO; import org.apache.ambari.server.orm.entities.ClusterEntity; @@ -50,12 +50,10 @@ import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigHelper; -import org.apache.ambari.server.state.OperatingSystemInfo; import org.apache.ambari.server.state.PropertyInfo; import org.apache.ambari.server.state.RepositoryInfo; import org.apache.ambari.server.state.SecurityState; import org.apache.ambari.server.state.SecurityType; -import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.UpgradeState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -331,7 +329,10 @@ public class UpgradeCatalog200 extends AbstractUpgradeCatalog { updateClusterEnvConfiguration(); } + @Experimental(feature=ExperimentalFeature.PATCH_UPGRADES, + comment = "the metainfo table of storing the latest repo will be removed") protected void persistHDPRepo() throws AmbariException{ + /* AmbariManagementController amc = injector.getInstance( AmbariManagementController.class); AmbariMetaInfo ambariMetaInfo = amc.getAmbariMetaInfo(); @@ -369,7 +370,7 @@ public class UpgradeCatalog200 extends AbstractUpgradeCatalog { cluster.getClusterName()); System.out.println(repositoryTable(ambariMetaInfo.getStack(stackName, stackVersion).getRepositories())); } - + */ } /** http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java index 7b7681c..5c04b79 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java @@ -1072,18 +1072,23 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog { if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); for (final Cluster cluster : clusterMap.values()) { - StackId stackId = cluster.getCurrentStackVersion(); - if (stackId != null && stackId.getStackName().equals("HDP") && + + ServiceComponentDesiredStateDAO dao = injector.getInstance(ServiceComponentDesiredStateDAO.class); + ServiceComponentDesiredStateEntity entity = dao.findByName(cluster.getClusterId(), + "STORM", "STORM_REST_API"); + + if (null == entity) { + continue; + } + + StackId stackId = new StackId(entity.getDesiredStack()); + + if (stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.2") >= 0) { executeInTransaction(new Runnable() { @Override public void run() { - ServiceComponentDesiredStateDAO dao = injector.getInstance(ServiceComponentDesiredStateDAO.class); - ServiceComponentDesiredStateEntity entity = dao.findByName(cluster.getClusterId(), - "STORM", "STORM_REST_API"); - - if (entity != null) { EntityManager em = getEntityManagerProvider().get(); CriteriaBuilder cb = em.getCriteriaBuilder(); @@ -1114,7 +1119,6 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog { "delete from servicecomponentdesiredstate where component_name='STORM_REST_API';\n", e); } } - } }); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java index 90854dd..8eb2654 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java @@ -35,6 +35,7 @@ import org.apache.ambari.server.orm.dao.DaoUtils; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.utils.VersionUtils; import org.slf4j.Logger; @@ -305,9 +306,16 @@ public class UpgradeCatalog212 extends AbstractUpgradeCatalog { if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { + Service service = cluster.getServices().get("HIVE"); + + if (null == service) { + continue; + } + + StackId stackId = service.getDesiredStackId(); + String content = null; Boolean isHiveSitePresent = cluster.getDesiredConfigByType(HIVE_SITE) != null; - StackId stackId = cluster.getCurrentStackVersion(); Boolean isStackNotLess22 = (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.2") >= 0);