http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 f1e93ac..a0d7352 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 @@ -681,7 +681,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { LOG.debug("Updating live stack version during INSTALL event" + ", new stack version=" + e.getStackId()); } - impl.setStackVersion(new StackId(e.getStackId())); } } } @@ -782,7 +781,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { stateEntity.setHostEntity(hostEntity); stateEntity.setCurrentState(stateMachine.getCurrentState()); stateEntity.setUpgradeState(UpgradeState.NONE); - stateEntity.setCurrentStack(stackEntity); HostComponentDesiredStateEntity desiredStateEntity = new HostComponentDesiredStateEntity(); desiredStateEntity.setClusterId(serviceComponent.getClusterId()); @@ -790,7 +788,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { desiredStateEntity.setServiceName(serviceComponent.getServiceName()); desiredStateEntity.setHostEntity(hostEntity); desiredStateEntity.setDesiredState(State.INIT); - desiredStateEntity.setDesiredStack(stackEntity); if(!serviceComponent.isMasterComponent() && !serviceComponent.isClientComponent()) { desiredStateEntity.setAdminState(HostComponentAdminState.INSERVICE); @@ -1120,36 +1117,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { } @Override - public StackId getStackVersion() { - HostComponentStateEntity schStateEntity = getStateEntity(); - return getStackVersionFromSCHStateEntity(schStateEntity); - } - - private StackId getStackVersionFromSCHStateEntity(HostComponentStateEntity schStateEntity) { - if (schStateEntity == null) { - return new StackId(); - } - - StackEntity currentStackEntity = schStateEntity.getCurrentStack(); - return new StackId(currentStackEntity.getStackName(), currentStackEntity.getStackVersion()); - } - - @Override - public void setStackVersion(StackId stackId) { - StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion()); - - HostComponentStateEntity stateEntity = getStateEntity(); - if (stateEntity != null) { - stateEntity.setCurrentStack(stackEntity); - stateEntity = hostComponentStateDAO.merge(stateEntity); - } else { - LOG.warn("Setting a member on an entity object that may have been " - + "previously deleted, serviceName = " + getServiceName() + ", " + "componentName = " - + getServiceComponentName() + ", " + "hostName = " + getHostName()); - } - } - - @Override public State getDesiredState() { HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity(); if (desiredStateEntity != null) { @@ -1180,38 +1147,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { } @Override - public StackId getDesiredStackVersion() { - HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity(); - return getDesiredStackVersionFromHostComponentDesiredStateEntity(desiredStateEntity); - } - - private StackId getDesiredStackVersionFromHostComponentDesiredStateEntity(HostComponentDesiredStateEntity desiredStateEntity) { - if (desiredStateEntity != null) { - StackEntity desiredStackEntity = desiredStateEntity.getDesiredStack(); - return new StackId(desiredStackEntity.getStackName(), desiredStackEntity.getStackVersion()); - } else { - LOG.warn("Trying to fetch a member from an entity object that may " - + "have been previously deleted, serviceName = " + getServiceName() + ", " - + "componentName = " + getServiceComponentName() + ", " + "hostName = " + getHostName()); - } - return null; - } - - @Override - public void setDesiredStackVersion(StackId stackId) { - LOG.debug("Set DesiredStackVersion on serviceName = {} componentName = {} hostName = {} to {}", - getServiceName(), getServiceComponentName(), getHostName(), stackId); - - HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity(); - if (desiredStateEntity != null) { - StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion()); - - desiredStateEntity.setDesiredStack(stackEntity); - hostComponentDesiredStateDAO.merge(desiredStateEntity); - } - } - - @Override public HostComponentAdminState getComponentAdminState() { HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity(); return getComponentAdminStateFromDesiredStateEntity(desiredStateEntity); @@ -1250,14 +1185,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { public ServiceComponentHostResponse convertToResponse(Map<String, DesiredConfig> desiredConfigs) { HostComponentStateEntity hostComponentStateEntity = getStateEntity(); HostEntity hostEntity = hostComponentStateEntity.getHostEntity(); - if (null == hostComponentStateEntity) { - LOG.warn( - "Could not convert ServiceComponentHostResponse to a response. It's possible that Host {} was deleted.", - getHostName()); - return null; - } - StackId stackVersion = getStackVersionFromSCHStateEntity(hostComponentStateEntity); HostComponentDesiredStateEntity hostComponentDesiredStateEntity = getDesiredStateEntity(); String clusterName = serviceComponent.getClusterName(); @@ -1266,14 +1194,14 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { String hostName = getHostName(); String publicHostName = hostEntity.getPublicHostName(); String state = getState().toString(); - String stackId = stackVersion.getStackId(); String desiredState = (hostComponentDesiredStateEntity == null) ? null : hostComponentDesiredStateEntity.getDesiredState().toString(); - String desiredStackId = getDesiredStackVersionFromHostComponentDesiredStateEntity(hostComponentDesiredStateEntity).getStackId(); + String desiredStackId = serviceComponent.getDesiredStackVersion().getStackId(); HostComponentAdminState componentAdminState = getComponentAdminStateFromDesiredStateEntity(hostComponentDesiredStateEntity); UpgradeState upgradeState = hostComponentStateEntity.getUpgradeState(); String displayName = null; try { + StackId stackVersion = serviceComponent.getDesiredStackVersion(); ComponentInfo compInfo = ambariMetaInfo.getComponent(stackVersion.getStackName(), stackVersion.getStackVersion(), serviceName, serviceComponentName); displayName = compInfo.getDisplayName(); @@ -1281,9 +1209,15 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { displayName = serviceComponentName; } + String desiredRepositoryVersion = null; + RepositoryVersionEntity repositoryVersion = serviceComponent.getDesiredRepositoryVersion(); + if (null != repositoryVersion) { + desiredRepositoryVersion = repositoryVersion.getVersion(); + } + ServiceComponentHostResponse r = new ServiceComponentHostResponse(clusterName, serviceName, - serviceComponentName, displayName, hostName, publicHostName, state, stackId, - desiredState, desiredStackId, componentAdminState); + serviceComponentName, displayName, hostName, publicHostName, state, getVersion(), + desiredState, desiredStackId, desiredRepositoryVersion, componentAdminState); r.setActualConfigs(actualConfigs); r.setUpgradeState(upgradeState); @@ -1312,11 +1246,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { .append(", serviceName=") .append(serviceComponent.getServiceName()) .append(", desiredStackVersion=") - .append(getDesiredStackVersion()) + .append(serviceComponent.getDesiredStackVersion()) .append(", desiredState=") .append(getDesiredState()) - .append(", stackVersion=") - .append(getStackVersion()) + .append(", version=") + .append(getVersion()) .append(", state=") .append(getState()) .append(", securityState=") @@ -1377,7 +1311,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { // completed, but only if it was persisted if (fireRemovalEvent) { long clusterId = getClusterId(); - StackId stackId = getStackVersion(); + StackId stackId = serviceComponent.getDesiredStackVersion(); String stackVersion = stackId.getStackVersion(); String stackName = stackId.getStackName(); String serviceName = getServiceName(); @@ -1614,4 +1548,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost { return hostComponentStateDAO.findById(hostComponentStateId); } + /** + * {@inheritDoc} + */ + @Override + public ServiceComponent getServiceComponent() { + return serviceComponent; + } }
http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java index 5e0d707..4a1e61f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java @@ -72,6 +72,7 @@ import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.SecurityType; +import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.configgroup.ConfigGroup; import org.apache.ambari.server.utils.RetryHelper; import org.slf4j.Logger; @@ -167,9 +168,10 @@ public class AmbariContext { public void createAmbariResources(ClusterTopology topology, String clusterName, SecurityType securityType, String repoVersion) { Stack stack = topology.getBlueprint().getStack(); + StackId stackId = new StackId(stack.getName(), stack.getVersion()); createAmbariClusterResource(clusterName, stack.getName(), stack.getVersion(), securityType, repoVersion); - createAmbariServiceAndComponentResources(topology, clusterName); + createAmbariServiceAndComponentResources(topology, clusterName, stackId, repoVersion); } public void createAmbariClusterResource(String clusterName, String stackName, String stackVersion, SecurityType securityType, String repoVersion) { @@ -196,7 +198,8 @@ public class AmbariContext { } } - public void createAmbariServiceAndComponentResources(ClusterTopology topology, String clusterName) { + public void createAmbariServiceAndComponentResources(ClusterTopology topology, String clusterName, + StackId stackId, String repositoryVersion) { Collection<String> services = topology.getBlueprint().getServices(); try { @@ -209,7 +212,9 @@ public class AmbariContext { Set<ServiceComponentRequest> componentRequests = new HashSet<>(); for (String service : services) { String credentialStoreEnabled = topology.getBlueprint().getCredentialStoreEnabled(service); - serviceRequests.add(new ServiceRequest(clusterName, service, null, credentialStoreEnabled)); + serviceRequests.add(new ServiceRequest(clusterName, service, null, stackId.getStackId(), + repositoryVersion, credentialStoreEnabled)); + for (String component : topology.getBlueprint().getComponents(service)) { String recoveryEnabled = topology.getBlueprint().getRecoveryEnabled(service, component); componentRequests.add(new ServiceComponentRequest(clusterName, service, component, null, recoveryEnabled)); http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 6c59784..cb12959 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 @@ -102,8 +102,6 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog { protected DBAccessor dbAccessor; @Inject protected Configuration configuration; - @Inject - protected StackUpgradeUtil stackUpgradeUtil; protected Injector injector; http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeHelper.java deleted file mode 100644 index 0aab0b5..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeHelper.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ambari.server.upgrade; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.InputMismatchException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.ambari.server.controller.ControllerModule; -import org.apache.ambari.server.orm.DBAccessor; -import org.apache.ambari.server.orm.dao.MetainfoDAO; -import org.apache.ambari.server.orm.entities.MetainfoEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.Gson; -import com.google.inject.Guice; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.persist.PersistService; -import com.google.inject.persist.Transactional; - -public class StackUpgradeHelper { - private static final Logger LOG = LoggerFactory.getLogger - (StackUpgradeHelper.class); - - private static final String STACK_ID_UPDATE_ACTION = "updateStackId"; - private static final String METAINFO_UPDATE_ACTION = "updateMetaInfo"; - private static final String STACK_ID_STACK_NAME_KEY = "stackName"; - - @Inject - private DBAccessor dbAccessor; - @Inject - private PersistService persistService; - @Inject - private MetainfoDAO metainfoDAO; - @Inject - private StackUpgradeUtil stackUpgradeUtil; - - private void startPersistenceService() { - persistService.start(); - } - - private void stopPersistenceService() { - persistService.stop(); - } - - /** - * Add key value to the metainfo table. - * @param data - * @throws SQLException - */ - @Transactional - void updateMetaInfo(Map<String, String> data) throws SQLException { - if (data != null && !data.isEmpty()) { - for (Map.Entry<String, String> entry : data.entrySet()) { - MetainfoEntity metainfoEntity = metainfoDAO.findByKey(entry.getKey()); - if (metainfoEntity != null) { - metainfoEntity.setMetainfoName(entry.getKey()); - metainfoEntity.setMetainfoValue(entry.getValue()); - metainfoDAO.merge(metainfoEntity); - } else { - metainfoEntity = new MetainfoEntity(); - metainfoEntity.setMetainfoName(entry.getKey()); - metainfoEntity.setMetainfoValue(entry.getValue()); - metainfoDAO.create(metainfoEntity); - } - } - } - } - - /** - * Change the stack id in the Ambari DB. - * @param stackInfo - * @throws SQLException - */ - public void updateStackVersion(Map<String, String> stackInfo) throws Exception { - if (stackInfo == null || stackInfo.isEmpty()) { - throw new IllegalArgumentException("Empty stack id. " + stackInfo); - } - - String repoUrl = stackInfo.remove("repo_url"); - String repoUrlOs = stackInfo.remove("repo_url_os"); - String mirrorList = stackInfo.remove("mirrors_list"); - - Iterator<Map.Entry<String, String>> stackIdEntry = stackInfo.entrySet().iterator(); - Map.Entry<String, String> stackEntry = stackIdEntry.next(); - - String stackName = stackEntry.getKey(); - String stackVersion = stackEntry.getValue(); - - LOG.info("Updating stack id, stackName = " + stackName + ", " + - "stackVersion = "+ stackVersion); - - stackUpgradeUtil.updateStackDetails(stackName, stackVersion); - - if (null != repoUrl) { - stackUpgradeUtil.updateLocalRepo(stackName, stackVersion, repoUrl, repoUrlOs, mirrorList); - } - - dbAccessor.updateTable("hostcomponentstate", "current_state", "INSTALLED", "where current_state = 'UPGRADING'"); - } - - private List<String> getValidActions() { - return new ArrayList<String>() {{ - add(STACK_ID_UPDATE_ACTION); - add(METAINFO_UPDATE_ACTION); - }}; - } - - /** - * Support changes need to support upgrade of Stack - * @param args Simple key value json map - */ - public static void main(String[] args) { - try { - if (args.length < 2) { - throw new InputMismatchException("Need to provide action, " + - "stack name and stack version."); - } - - String action = args[0]; - String valueMap = args[1]; - - Injector injector = Guice.createInjector(new ControllerModule()); - StackUpgradeHelper stackUpgradeHelper = injector.getInstance(StackUpgradeHelper.class); - Gson gson = injector.getInstance(Gson.class); - - if (!stackUpgradeHelper.getValidActions().contains(action)) { - throw new IllegalArgumentException("Unsupported action. Allowed " + - "actions: " + stackUpgradeHelper.getValidActions()); - } - - - stackUpgradeHelper.startPersistenceService(); - Map<String, String> values = gson.<Map<String, String>>fromJson(valueMap, Map.class); - - if (action.equals(STACK_ID_UPDATE_ACTION)) { - stackUpgradeHelper.updateStackVersion(values); - - } else if (action.equals(METAINFO_UPDATE_ACTION)) { - - stackUpgradeHelper.updateMetaInfo(values); - } - - stackUpgradeHelper.stopPersistenceService(); - - } catch (Throwable t) { - LOG.error("Caught exception on upgrade. Exiting...", t); - System.exit(1); - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java deleted file mode 100644 index b258aa8..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ambari.server.upgrade; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.ambari.server.api.services.AmbariMetaInfo; -import org.apache.ambari.server.orm.dao.ClusterDAO; -import org.apache.ambari.server.orm.dao.ClusterStateDAO; -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.dao.StackDAO; -import org.apache.ambari.server.orm.entities.ClusterEntity; -import org.apache.ambari.server.orm.entities.ClusterStateEntity; -import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity; -import org.apache.ambari.server.orm.entities.HostComponentStateEntity; -import org.apache.ambari.server.orm.entities.MetainfoEntity; -import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity; -import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity; -import org.apache.ambari.server.orm.entities.StackEntity; -import org.apache.ambari.server.state.OperatingSystemInfo; -import org.apache.ambari.server.state.stack.OsFamily; - -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.persist.Transactional; - -public class StackUpgradeUtil { - @Inject - private Injector injector; - - @Transactional - public void updateStackDetails(String stackName, String stackVersion) { - ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class); - StackDAO stackDAO = injector.getInstance(StackDAO.class); - List<Long> clusterIds = new ArrayList<>(); - - StackEntity stackEntity = stackDAO.find(stackName, stackVersion); - - List<ClusterEntity> clusterEntities = clusterDAO.findAll(); - if (clusterEntities != null && !clusterEntities.isEmpty()) { - for (ClusterEntity entity : clusterEntities) { - clusterIds.add(entity.getClusterId()); - entity.setDesiredStack(stackEntity); - clusterDAO.merge(entity); - } - } - - ClusterStateDAO clusterStateDAO = injector.getInstance(ClusterStateDAO.class); - - for (Long clusterId : clusterIds) { - ClusterStateEntity clusterStateEntity = clusterStateDAO.findByPK(clusterId); - clusterStateEntity.setCurrentStack(stackEntity); - clusterStateDAO.merge(clusterStateEntity); - } - - HostComponentStateDAO hostComponentStateDAO = injector.getInstance - (HostComponentStateDAO.class); - List<HostComponentStateEntity> hcEntities = hostComponentStateDAO.findAll(); - - if (hcEntities != null) { - for (HostComponentStateEntity hc : hcEntities) { - hc.setCurrentStack(stackEntity); - hostComponentStateDAO.merge(hc); - } - } - - HostComponentDesiredStateDAO hostComponentDesiredStateDAO = - injector.getInstance(HostComponentDesiredStateDAO.class); - - List<HostComponentDesiredStateEntity> hcdEntities = hostComponentDesiredStateDAO.findAll(); - - if (hcdEntities != null) { - for (HostComponentDesiredStateEntity hcd : hcdEntities) { - hcd.setDesiredStack(stackEntity); - hostComponentDesiredStateDAO.merge(hcd); - } - } - - ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = - injector.getInstance(ServiceComponentDesiredStateDAO.class); - - List<ServiceComponentDesiredStateEntity> scdEntities = - serviceComponentDesiredStateDAO.findAll(); - - if (scdEntities != null) { - for (ServiceComponentDesiredStateEntity scd : scdEntities) { - scd.setDesiredStack(stackEntity); - serviceComponentDesiredStateDAO.merge(scd); - } - } - - ServiceDesiredStateDAO serviceDesiredStateDAO = injector.getInstance(ServiceDesiredStateDAO.class); - - List<ServiceDesiredStateEntity> sdEntities = serviceDesiredStateDAO.findAll(); - - if (sdEntities != null) { - for (ServiceDesiredStateEntity sd : sdEntities) { - sd.setDesiredStack(stackEntity); - serviceDesiredStateDAO.merge(sd); - } - } - } - - /** - * @param stackName - * @param stackVersion - * @param repoUrl - * @param repoUrlOs - * @param mirrorList - * @throws Exception - */ - public void updateLocalRepo(String stackName, String stackVersion, - String repoUrl, String repoUrlOs, String mirrorList) throws Exception { - - if (null == repoUrl || - repoUrl.isEmpty() || - !repoUrl.startsWith("http")) { - return; - } - - String[] oses = new String[0]; - - if (null != repoUrlOs) { - oses = repoUrlOs.split(","); - } - - AmbariMetaInfo ami = injector.getInstance(AmbariMetaInfo.class); - MetainfoDAO metaDao = injector.getInstance(MetainfoDAO.class); - OsFamily os_family = injector.getInstance(OsFamily.class); - - String stackRepoId = stackName + "-" + stackVersion; - - if (0 == oses.length) { - // do them all - for (OperatingSystemInfo osi : ami.getOperatingSystems(stackName, stackVersion)) { - ami.updateRepo(stackName, stackVersion, osi.getOsType(), - stackRepoId, repoUrl, mirrorList); - } - - } else { - for (String os : oses) { - - String family = os_family.find(os); - if (null != family) { - String key = ami.generateRepoMetaKey(stackName, stackVersion, os, - stackRepoId, AmbariMetaInfo.REPOSITORY_XML_PROPERTY_BASEURL); - - String familyKey = ami.generateRepoMetaKey(stackName, stackVersion, family, - stackRepoId, AmbariMetaInfo.REPOSITORY_XML_PROPERTY_BASEURL); - - // need to use (for example) redhat6 if the os is centos6 - MetainfoEntity entity = metaDao.findByKey(key); - if (null == entity) { - entity = new MetainfoEntity(); - entity.setMetainfoName(key); - entity.setMetainfoValue(repoUrl); - metaDao.merge(entity); - } else { - entity.setMetainfoValue(repoUrl); - metaDao.merge(entity); - } - - entity = metaDao.findByKey(familyKey); - if (null == entity) { - entity = new MetainfoEntity(); - entity.setMetainfoName(familyKey); - entity.setMetainfoValue(repoUrl); - metaDao.merge(entity); - } else { - entity.setMetainfoValue(repoUrl); - metaDao.merge(entity); - } - } - } - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/python/ambari-server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py index 737be6a..deb4993 100755 --- a/ambari-server/src/main/python/ambari-server.py +++ b/ambari-server/src/main/python/ambari-server.py @@ -37,7 +37,7 @@ from ambari_server.dbConfiguration import DATABASE_NAMES, LINUX_DBMS_KEYS_LIST from ambari_server.serverConfiguration import configDefaults, get_ambari_properties, PID_NAME from ambari_server.serverUtils import is_server_runing, refresh_stack_hash, wait_for_server_to_stop from ambari_server.serverSetup import reset, setup, setup_jce_policy -from ambari_server.serverUpgrade import upgrade, upgrade_stack, set_current +from ambari_server.serverUpgrade import upgrade, set_current from ambari_server.setupHttps import setup_https, setup_truststore from ambari_server.setupMpacks import install_mpack, uninstall_mpack, upgrade_mpack, STACK_DEFINITIONS_RESOURCE_NAME, \ SERVICE_DEFINITIONS_RESOURCE_NAME, MPACKS_RESOURCE_NAME @@ -50,8 +50,8 @@ from ambari_server.enableStack import enable_stack_version from ambari_server.setupActions import BACKUP_ACTION, LDAP_SETUP_ACTION, LDAP_SYNC_ACTION, PSTART_ACTION, \ REFRESH_STACK_HASH_ACTION, RESET_ACTION, RESTORE_ACTION, UPDATE_HOST_NAMES_ACTION, CHECK_DATABASE_ACTION, \ SETUP_ACTION, SETUP_SECURITY_ACTION,START_ACTION, STATUS_ACTION, STOP_ACTION, RESTART_ACTION, UPGRADE_ACTION, \ - UPGRADE_STACK_ACTION, SETUP_JCE_ACTION, SET_CURRENT_ACTION, START_ACTION, STATUS_ACTION, STOP_ACTION, UPGRADE_ACTION, \ - UPGRADE_STACK_ACTION, SETUP_JCE_ACTION, SET_CURRENT_ACTION, ENABLE_STACK_ACTION, SETUP_SSO_ACTION, \ + SETUP_JCE_ACTION, SET_CURRENT_ACTION, START_ACTION, STATUS_ACTION, STOP_ACTION, UPGRADE_ACTION, \ + SETUP_JCE_ACTION, SET_CURRENT_ACTION, ENABLE_STACK_ACTION, SETUP_SSO_ACTION, \ DB_CLEANUP_ACTION, INSTALL_MPACK_ACTION, UNINSTALL_MPACK_ACTION, UPGRADE_MPACK_ACTION, PAM_SETUP_ACTION, KERBEROS_SETUP_ACTION from ambari_server.setupSecurity import setup_ldap, sync_ldap, setup_master_key, setup_ambari_krb5_jaas, setup_pam from ambari_server.userInput import get_validated_string_input @@ -753,7 +753,6 @@ def create_user_action_map(args, options): RESET_ACTION: UserAction(reset, options), STATUS_ACTION: UserAction(status, options), UPGRADE_ACTION: UserAction(upgrade, options), - UPGRADE_STACK_ACTION: UserActionPossibleArgs(upgrade_stack, [2, 4], args), LDAP_SETUP_ACTION: UserAction(setup_ldap, options), LDAP_SYNC_ACTION: UserAction(sync_ldap, options), SET_CURRENT_ACTION: UserAction(set_current, options), http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/python/ambari_server/serverUpgrade.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari_server/serverUpgrade.py b/ambari-server/src/main/python/ambari_server/serverUpgrade.py index 6f17900..1bc7682 100644 --- a/ambari-server/src/main/python/ambari_server/serverUpgrade.py +++ b/ambari-server/src/main/python/ambari_server/serverUpgrade.py @@ -60,10 +60,6 @@ SCHEMA_UPGRADE_HELPER_CMD = "{0} -cp {1} " + \ "org.apache.ambari.server.upgrade.SchemaUpgradeHelper" + \ " > " + configDefaults.SERVER_OUT_FILE + " 2>&1" -STACK_UPGRADE_HELPER_CMD = "{0} -cp {1} " + \ - "org.apache.ambari.server.upgrade.StackUpgradeHelper" + \ - " {2} {3} > " + configDefaults.SERVER_OUT_FILE + " 2>&1" - SCHEMA_UPGRADE_HELPER_CMD_DEBUG = "{0} " \ "-server -XX:NewRatio=2 " \ "-XX:+UseConcMarkSweepGC " + \ @@ -77,52 +73,6 @@ SCHEMA_UPGRADE_DEBUG = False SUSPEND_START_MODE = False -# -# Stack upgrade -# - -def upgrade_stack(args): - logger.info("Upgrade stack.") - if not is_root(): - err = 'Ambari-server upgradestack should be run with ' \ - 'root-level privileges' - raise FatalException(4, err) - - check_database_name_property() - - try: - stack_id = args[1] - except IndexError: - #stack_id is mandatory - raise FatalException("Invalid number of stack upgrade arguments") - - try: - repo_url = args[2] - except IndexError: - repo_url = None - - try: - repo_url_os = args[3] - except IndexError: - repo_url_os = None - - parser = optparse.OptionParser() - parser.add_option("-d", type="int", dest="database_index") - - db = get_ambari_properties()[JDBC_DATABASE_PROPERTY] - - idx = LINUX_DBMS_KEYS_LIST.index(db) - - (options, opt_args) = parser.parse_args(["-d {0}".format(idx)]) - - stack_name, stack_version = stack_id.split(STACK_NAME_VER_SEP) - retcode = run_stack_upgrade(options, stack_name, stack_version, repo_url, repo_url_os) - - if not retcode == 0: - raise FatalException(retcode, 'Stack upgrade failed.') - - return retcode - def load_stack_values(version, filename): import xml.etree.ElementTree as ET values = {} @@ -143,52 +93,6 @@ def load_stack_values(version, filename): return values - -def run_stack_upgrade(args, stackName, stackVersion, repo_url, repo_url_os): - jdk_path = get_java_exe_path() - if jdk_path is None: - print_error_msg("No JDK found, please run the \"setup\" " - "command to install a JDK automatically or install any " - "JDK manually to " + configDefaults.JDK_INSTALL_DIR) - return 1 - stackId = {} - stackId[stackName] = stackVersion - if repo_url is not None: - stackId['repo_url'] = repo_url - if repo_url_os is not None: - stackId['repo_url_os'] = repo_url_os - - serverClassPath = ServerClassPath(get_ambari_properties(), args) - command = STACK_UPGRADE_HELPER_CMD.format(jdk_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), - "updateStackId", - "'" + json.dumps(stackId) + "'") - (retcode, stdout, stderr) = run_os_command(command) - print_info_msg("Return code from stack upgrade command, retcode = {0}".format(str(retcode))) - if retcode > 0: - print_error_msg("Error executing stack upgrade, please check the server logs.") - return retcode - -def run_metainfo_upgrade(args, keyValueMap=None): - jdk_path = get_java_exe_path() - if jdk_path is None: - print_error_msg("No JDK found, please run the \"setup\" " - "command to install a JDK automatically or install any " - "JDK manually to " + configDefaults.JDK_INSTALL_DIR) - - retcode = 1 - if keyValueMap: - serverClassPath = ServerClassPath(get_ambari_properties(), args) - command = STACK_UPGRADE_HELPER_CMD.format(jdk_path, serverClassPath.get_full_ambari_classpath_escaped_for_shell(), - 'updateMetaInfo', - "'" + json.dumps(keyValueMap) + "'") - (retcode, stdout, stderr) = run_os_command(command) - print_info_msg("Return code from stack upgrade command, retcode = {0}".format(str(retcode))) - if retcode > 0: - print_error_msg("Error executing metainfo upgrade, please check the server logs.") - - return retcode - - # # Repo upgrade # @@ -203,47 +107,6 @@ def change_objects_owner(args): dbms.change_db_files_owner() -def upgrade_local_repo(args): - properties = get_ambari_properties() - if properties == -1: - print_error_msg("Error getting ambari properties") - return -1 - - stack_location = get_stack_location(properties) - stack_root_local = os.path.join(stack_location, "HDPLocal") - if not os.path.exists(stack_root_local): - print_info_msg("HDPLocal stack directory does not exist, skipping") - return - - stack_root = os.path.join(stack_location, "HDP") - if not os.path.exists(stack_root): - print_info_msg("HDP stack directory does not exist, skipping") - return - - for stack_version_local in os.listdir(stack_root_local): - repo_file_local = os.path.join(stack_root_local, stack_version_local, "repos", "repoinfo.xml.rpmsave") - if not os.path.exists(repo_file_local): - repo_file_local = os.path.join(stack_root_local, stack_version_local, "repos", "repoinfo.xml") - - repo_file = os.path.join(stack_root, stack_version_local, "repos", "repoinfo.xml") - - print_info_msg("Local repo file: {0}".format(repo_file_local)) - print_info_msg("Repo file: {0}".format(repo_file_local)) - - metainfo_update_items = {} - - if os.path.exists(repo_file_local) and os.path.exists(repo_file): - local_values = load_stack_values(stack_version_local, repo_file_local) - repo_values = load_stack_values(stack_version_local, repo_file) - for k, v in local_values.iteritems(): - if repo_values.has_key(k): - local_url = local_values[k] - repo_url = repo_values[k] - if repo_url != local_url: - metainfo_update_items[k] = local_url - - run_metainfo_upgrade(args, metainfo_update_items) - # # Schema upgrade # @@ -384,9 +247,6 @@ def upgrade(args): else: adjust_directory_permissions(user) - # local repo - upgrade_local_repo(args) - # create jdbc symlinks if jdbc drivers are available in resources check_jdbc_drivers(args) http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/python/ambari_server/setupActions.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/python/ambari_server/setupActions.py b/ambari-server/src/main/python/ambari_server/setupActions.py index 358bfc9..758e42f 100644 --- a/ambari-server/src/main/python/ambari_server/setupActions.py +++ b/ambari-server/src/main/python/ambari_server/setupActions.py @@ -26,7 +26,6 @@ STOP_ACTION = "stop" RESTART_ACTION = "restart" RESET_ACTION = "reset" UPGRADE_ACTION = "upgrade" -UPGRADE_STACK_ACTION = "upgradestack" REFRESH_STACK_HASH_ACTION = "refresh-stack-hash" STATUS_ACTION = "status" SETUP_HTTPS_ACTION = "setup-https" http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql index b241dc2..e25cfa3 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql @@ -178,22 +178,20 @@ CREATE TABLE servicecomponentdesiredstate ( id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, - desired_stack_id BIGINT NOT NULL, + desired_repo_version_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, - desired_version VARCHAR(255) NOT NULL DEFAULT 'UNKNOWN', service_name VARCHAR(255) NOT NULL, recovery_enabled SMALLINT NOT NULL DEFAULT 0, repo_state VARCHAR(255) NOT NULL DEFAULT 'INIT', CONSTRAINT pk_sc_desiredstate PRIMARY KEY (id), CONSTRAINT UQ_scdesiredstate_name UNIQUE(component_name, service_name, cluster_id), - CONSTRAINT FK_scds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_scds_desired_repo_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE hostcomponentdesiredstate ( id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, - desired_stack_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, @@ -204,7 +202,6 @@ CREATE TABLE hostcomponentdesiredstate ( CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY (id), CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_name, host_id, cluster_id), CONSTRAINT FK_hcdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), - CONSTRAINT FK_hcds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); @@ -213,14 +210,12 @@ CREATE TABLE hostcomponentstate ( cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', - current_stack_id BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id), - CONSTRAINT FK_hcs_current_stack_id FOREIGN KEY (current_stack_id) REFERENCES stack(stack_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); @@ -250,14 +245,14 @@ CREATE TABLE host_version ( CREATE TABLE servicedesiredstate ( cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, - desired_stack_id BIGINT NOT NULL, + desired_repo_version_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, maintenance_state VARCHAR(32) NOT NULL, security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', credential_store_enabled SMALLINT NOT NULL DEFAULT 0, CONSTRAINT PK_servicedesiredstate PRIMARY KEY (cluster_id, service_name), - CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_repo_version_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE adminprincipaltype ( http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql index 670bf17..8e1f51f 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql @@ -198,22 +198,20 @@ CREATE TABLE servicecomponentdesiredstate ( id BIGINT NOT NULL, component_name VARCHAR(100) NOT NULL, cluster_id BIGINT NOT NULL, - desired_stack_id BIGINT NOT NULL, - desired_version VARCHAR(255) NOT NULL DEFAULT 'UNKNOWN', + desired_repo_version_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(100) NOT NULL, recovery_enabled SMALLINT NOT NULL DEFAULT 0, repo_state VARCHAR(255) NOT NULL DEFAULT 'INIT', CONSTRAINT pk_sc_desiredstate PRIMARY KEY (id), CONSTRAINT UQ_scdesiredstate_name UNIQUE(component_name, service_name, cluster_id), - CONSTRAINT FK_scds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_scds_desired_repo_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE hostcomponentdesiredstate ( id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(100) NOT NULL, - desired_stack_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_name VARCHAR(100) NOT NULL, @@ -224,7 +222,6 @@ CREATE TABLE hostcomponentdesiredstate ( CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY (id), CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_name, host_id, cluster_id), CONSTRAINT FK_hcdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), - CONSTRAINT FK_hcds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); @@ -233,14 +230,12 @@ CREATE TABLE hostcomponentstate ( cluster_id BIGINT NOT NULL, component_name VARCHAR(100) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', - current_stack_id BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_name VARCHAR(100) NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id), - CONSTRAINT FK_hcs_current_stack_id FOREIGN KEY (current_stack_id) REFERENCES stack(stack_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); @@ -270,14 +265,14 @@ CREATE TABLE host_version ( CREATE TABLE servicedesiredstate ( cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, - desired_stack_id BIGINT NOT NULL, + desired_repo_version_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, maintenance_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', credential_store_enabled SMALLINT NOT NULL DEFAULT 0, CONSTRAINT PK_servicedesiredstate PRIMARY KEY (cluster_id, service_name), - CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_repo_version_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE adminprincipaltype ( http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql index 00b3248..5ae144a 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql @@ -179,22 +179,20 @@ CREATE TABLE servicecomponentdesiredstate ( id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, - desired_stack_id NUMBER(19) NOT NULL, + desired_repo_version_id NUMBER(19) NOT NULL, desired_state VARCHAR2(255) NOT NULL, - desired_version VARCHAR(255) DEFAULT 'UNKNOWN' NOT NULL, service_name VARCHAR2(255) NOT NULL, recovery_enabled SMALLINT DEFAULT 0 NOT NULL, repo_state VARCHAR2(255) DEFAULT 'INIT' NOT NULL, CONSTRAINT pk_sc_desiredstate PRIMARY KEY (id), CONSTRAINT UQ_scdesiredstate_name UNIQUE(component_name, service_name, cluster_id), - CONSTRAINT FK_scds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_scds_desired_repo_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE hostcomponentdesiredstate ( id NUMBER(19) NOT NULL, cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, - desired_stack_id NUMBER(19) NULL, desired_state VARCHAR2(255) NOT NULL, host_id NUMBER(19) NOT NULL, service_name VARCHAR2(255) NOT NULL, @@ -205,7 +203,6 @@ CREATE TABLE hostcomponentdesiredstate ( CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY (id), CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_name, host_id, cluster_id), CONSTRAINT FK_hcdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), - CONSTRAINT FK_hcds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); CREATE TABLE hostcomponentstate ( @@ -213,14 +210,12 @@ CREATE TABLE hostcomponentstate ( cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, version VARCHAR2(32) DEFAULT 'UNKNOWN' NOT NULL, - current_stack_id NUMBER(19) NOT NULL, current_state VARCHAR2(255) NOT NULL, host_id NUMBER(19) NOT NULL, service_name VARCHAR2(255) NOT NULL, upgrade_state VARCHAR2(32) DEFAULT 'NONE' NOT NULL, security_state VARCHAR2(32) DEFAULT 'UNSECURED' NOT NULL, CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id), - CONSTRAINT FK_hcs_current_stack_id FOREIGN KEY (current_stack_id) REFERENCES stack(stack_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); @@ -250,14 +245,14 @@ CREATE TABLE host_version ( CREATE TABLE servicedesiredstate ( cluster_id NUMBER(19) NOT NULL, desired_host_role_mapping NUMBER(10) NOT NULL, - desired_stack_id NUMBER(19) NOT NULL, + desired_repo_version_id NUMBER(19) NOT NULL, desired_state VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, maintenance_state VARCHAR2(32) NOT NULL, security_state VARCHAR2(32) DEFAULT 'UNSECURED' NOT NULL, credential_store_enabled SMALLINT DEFAULT 0 NOT NULL, CONSTRAINT PK_servicedesiredstate PRIMARY KEY (cluster_id, service_name), - CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_repo_version_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE adminprincipaltype ( http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql index f6af968..a4b296d 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -178,22 +178,20 @@ CREATE TABLE servicecomponentdesiredstate ( id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, - desired_stack_id BIGINT NOT NULL, - desired_version VARCHAR(255) NOT NULL DEFAULT 'UNKNOWN', + desired_repo_version_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, recovery_enabled SMALLINT NOT NULL DEFAULT 0, repo_state VARCHAR(255) NOT NULL DEFAULT 'INIT', CONSTRAINT pk_sc_desiredstate PRIMARY KEY (id), CONSTRAINT UQ_scdesiredstate_name UNIQUE(component_name, service_name, cluster_id), - CONSTRAINT FK_scds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_scds_desired_repo_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE hostcomponentdesiredstate ( id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, - desired_stack_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, @@ -204,7 +202,6 @@ CREATE TABLE hostcomponentdesiredstate ( CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY (id), CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_name, host_id, cluster_id), CONSTRAINT FK_hcdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), - CONSTRAINT FK_hcds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); CREATE TABLE hostcomponentstate ( @@ -212,14 +209,12 @@ CREATE TABLE hostcomponentstate ( cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', - current_stack_id BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id), - CONSTRAINT FK_hcs_current_stack_id FOREIGN KEY (current_stack_id) REFERENCES stack(stack_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); @@ -249,16 +244,17 @@ CREATE TABLE host_version ( CREATE TABLE servicedesiredstate ( cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, - desired_stack_id BIGINT NOT NULL, + desired_repo_version_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, maintenance_state VARCHAR(32) NOT NULL, security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', credential_store_enabled SMALLINT NOT NULL DEFAULT 0, CONSTRAINT PK_servicedesiredstate PRIMARY KEY (cluster_id, service_name), - CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_repo_version_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); + CREATE TABLE adminprincipaltype ( principal_type_id INTEGER NOT NULL, principal_type_name VARCHAR(255) NOT NULL, http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql index 64a0137..2f346d2 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql @@ -177,22 +177,20 @@ CREATE TABLE servicecomponentdesiredstate ( id NUMERIC(19) NOT NULL, component_name VARCHAR(255) NOT NULL, cluster_id NUMERIC(19) NOT NULL, - desired_stack_id NUMERIC(19) NOT NULL, - desired_version VARCHAR(255) NOT NULL DEFAULT 'UNKNOWN', + desired_repo_version_id NUMERIC(19) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, recovery_enabled SMALLINT NOT NULL DEFAULT 0, repo_state VARCHAR(255) NOT NULL DEFAULT 'INIT', CONSTRAINT pk_sc_desiredstate PRIMARY KEY (id), CONSTRAINT UQ_scdesiredstate_name UNIQUE(component_name, service_name, cluster_id), - CONSTRAINT FK_scds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_scds_desired_repo_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE hostcomponentdesiredstate ( id NUMERIC(19) NOT NULL, cluster_id NUMERIC(19) NOT NULL, component_name VARCHAR(255) NOT NULL, - desired_stack_id NUMERIC(19) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id NUMERIC(19) NOT NULL, service_name VARCHAR(255) NOT NULL, @@ -203,7 +201,6 @@ CREATE TABLE hostcomponentdesiredstate ( CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY (id), CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_name, host_id, cluster_id), CONSTRAINT FK_hcdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), - CONSTRAINT FK_hcds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); CREATE TABLE hostcomponentstate ( @@ -211,14 +208,12 @@ CREATE TABLE hostcomponentstate ( cluster_id NUMERIC(19) NOT NULL, component_name VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', - current_stack_id NUMERIC(19) NOT NULL, current_state VARCHAR(255) NOT NULL, host_id NUMERIC(19) NOT NULL, service_name VARCHAR(255) NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', CONSTRAINT PK_hostcomponentstate PRIMARY KEY (id), - CONSTRAINT FK_hcs_current_stack_id FOREIGN KEY (current_stack_id) REFERENCES stack(stack_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); @@ -248,14 +243,14 @@ CREATE TABLE host_version ( CREATE TABLE servicedesiredstate ( cluster_id NUMERIC(19) NOT NULL, desired_host_role_mapping INTEGER NOT NULL, - desired_stack_id NUMERIC(19) NOT NULL, + desired_repo_version_id NUMERIC(19) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, maintenance_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', credential_store_enabled SMALLINT NOT NULL DEFAULT 0, CONSTRAINT PK_servicedesiredstate PRIMARY KEY (cluster_id, service_name), - CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_repo_version_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE adminprincipaltype ( http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql index 22b2c3d..e57fec9 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -191,22 +191,20 @@ CREATE TABLE servicecomponentdesiredstate ( id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, - desired_stack_id BIGINT NOT NULL, - desired_version VARCHAR(255) NOT NULL DEFAULT 'UNKNOWN', + desired_repo_version_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, recovery_enabled SMALLINT NOT NULL DEFAULT 0, repo_state VARCHAR(255) NOT NULL DEFAULT 'INIT', CONSTRAINT pk_sc_desiredstate PRIMARY KEY (id), CONSTRAINT UQ_scdesiredstate_name UNIQUE(component_name, service_name, cluster_id), - CONSTRAINT FK_scds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_scds_desired_repo_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE hostcomponentdesiredstate ( id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, - desired_stack_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, @@ -216,7 +214,6 @@ CREATE TABLE hostcomponentdesiredstate ( restart_required BIT NOT NULL DEFAULT 0, CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY CLUSTERED (id), CONSTRAINT UQ_hcdesiredstate_name UNIQUE NONCLUSTERED (component_name, service_name, host_id, cluster_id), - CONSTRAINT FK_hcds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id), CONSTRAINT hstcmponentdesiredstatehstid FOREIGN KEY (host_id) REFERENCES hosts (host_id)); @@ -226,14 +223,12 @@ CREATE TABLE hostcomponentstate ( cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', - current_stack_id BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', CONSTRAINT PK_hostcomponentstate PRIMARY KEY CLUSTERED (id), - CONSTRAINT FK_hcs_current_stack_id FOREIGN KEY (current_stack_id) REFERENCES stack(stack_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); @@ -253,14 +248,14 @@ CREATE TABLE hoststate ( CREATE TABLE servicedesiredstate ( cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, - desired_stack_id BIGINT NOT NULL, + desired_repo_version_id BIGINT NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, maintenance_state VARCHAR(32) NOT NULL, security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', credential_store_enabled SMALLINT NOT NULL DEFAULT 0, CONSTRAINT PK_servicedesiredstate PRIMARY KEY CLUSTERED (cluster_id,service_name), - CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES stack(stack_id), + CONSTRAINT FK_repo_version_id FOREIGN KEY (desired_repo_version_id) REFERENCES repo_version (repo_version_id), CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id)); CREATE TABLE adminprincipaltype ( http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/main/resources/properties.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/properties.json b/ambari-server/src/main/resources/properties.json index 9b2bbf8..a6bf367 100644 --- a/ambari-server/src/main/resources/properties.json +++ b/ambari-server/src/main/resources/properties.json @@ -15,6 +15,8 @@ "Service":[ "ServiceInfo/service_name", "ServiceInfo/cluster_name", + "ServiceInfo/desired_stack", + "ServiceInfo/desired_repository_version", "ServiceInfo/state", "ServiceInfo/maintenance_state", "ServiceInfo/credential_store_supported", @@ -83,14 +85,14 @@ "HostRoles/display_name", "HostRoles/state", "HostRoles/desired_state", - "HostRoles/stack_id", + "HostRoles/version", "HostRoles/desired_stack_id", + "HostRoles/desired_repository_version", "HostRoles/actual_configs", "params/run_smoke_test", "HostRoles/stale_configs", "HostRoles/desired_admin_state", "HostRoles/maintenance_state", - "HostRoles/hdp_version", "HostRoles/service_name", "HostRoles/upgrade_state", "_" http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/test/java/org/apache/ambari/server/agent/DummyHeartbeatConstants.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/DummyHeartbeatConstants.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/DummyHeartbeatConstants.java index a7c53d5..69980dc 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/DummyHeartbeatConstants.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/DummyHeartbeatConstants.java @@ -36,6 +36,7 @@ public interface DummyHeartbeatConstants { String DummyHostStatus = "I am ok"; String DummyStackId = "HDP-0.1"; + String DummyRepositoryVersion = "0.1-1234"; String HDFS = "HDFS"; String HBASE = "HBASE"; http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 2dd91c0..5afeb77 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 @@ -64,6 +64,7 @@ import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.orm.dao.HostDAO; import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; +import org.apache.ambari.server.orm.entities.ClusterVersionEntity; import org.apache.ambari.server.orm.entities.HostEntity; import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; import org.apache.ambari.server.state.Alert; @@ -94,7 +95,6 @@ import com.google.gson.JsonObject; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; -import com.google.inject.persist.UnitOfWork; import junit.framework.Assert; @@ -109,9 +109,6 @@ public class HeartbeatProcessorTest { private Clusters clusters; @Inject - private UnitOfWork unitOfWork; - - @Inject Configuration config; @Inject @@ -159,7 +156,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testHeartbeatWithConfigs() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.addServiceComponent(NAMENODE); @@ -228,7 +225,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testRestartRequiredAfterInstallClient() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(HDFS_CLIENT); hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1); @@ -293,7 +290,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testHeartbeatCustomCommandWithConfigs() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.addServiceComponent(NAMENODE); @@ -377,7 +374,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testHeartbeatCustomStartStop() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.addServiceComponent(NAMENODE); @@ -461,7 +458,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testStatusHeartbeat() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.addServiceComponent(NAMENODE); @@ -587,7 +584,7 @@ public class HeartbeatProcessorTest { public void testCommandReportOnHeartbeatUpdatedState() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); @@ -706,7 +703,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testUpgradeSpecificHandling() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); @@ -800,7 +797,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testCommandStatusProcesses() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED); @@ -877,93 +874,9 @@ public class HeartbeatProcessorTest { @Test @SuppressWarnings("unchecked") - public void testComponentUpgradeCompleteReport() throws Exception { - Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); - hdfs.addServiceComponent(DATANODE); - hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); - hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(HDFS_CLIENT); - hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1); - - ServiceComponentHost serviceComponentHost1 = clusters.getCluster(DummyCluster).getService(HDFS). - getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1); - ServiceComponentHost serviceComponentHost2 = clusters.getCluster(DummyCluster).getService(HDFS). - getServiceComponent(NAMENODE).getServiceComponentHost(DummyHostname1); - - StackId stack130 = new StackId("HDP-1.3.0"); - StackId stack120 = new StackId("HDP-1.2.0"); - - serviceComponentHost1.setState(State.UPGRADING); - serviceComponentHost2.setState(State.INSTALLING); - - serviceComponentHost1.setStackVersion(stack120); - serviceComponentHost1.setDesiredStackVersion(stack130); - serviceComponentHost2.setStackVersion(stack120); - - HeartBeat hb = new HeartBeat(); - hb.setTimestamp(System.currentTimeMillis()); - hb.setResponseId(0); - hb.setHostname(DummyHostname1); - hb.setNodeStatus(new HostStatus(HostStatus.Status.HEALTHY, DummyHostStatus)); - CommandReport cr1 = new CommandReport(); - cr1.setActionId(StageUtils.getActionId(requestId, stageId)); - cr1.setTaskId(1); - cr1.setClusterName(DummyCluster); - cr1.setServiceName(HDFS); - cr1.setRole(DATANODE); - cr1.setStatus(HostRoleStatus.COMPLETED.toString()); - cr1.setStdErr("none"); - cr1.setStdOut("dummy output"); - cr1.setExitCode(0); - cr1.setRoleCommand(RoleCommand.UPGRADE.toString()); - - CommandReport cr2 = new CommandReport(); - cr2.setActionId(StageUtils.getActionId(requestId, stageId)); - cr2.setTaskId(2); - cr2.setClusterName(DummyCluster); - cr2.setServiceName(HDFS); - cr2.setRole(NAMENODE); - cr2.setStatus(HostRoleStatus.COMPLETED.toString()); - cr2.setStdErr("none"); - cr2.setStdOut("dummy output"); - cr2.setExitCode(0); - cr2.setRoleCommand(RoleCommand.UPGRADE.toString()); - ArrayList<CommandReport> reports = new ArrayList<>(); - reports.add(cr1); - reports.add(cr2); - hb.setReports(reports); - - ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, - Role.DATANODE, null, null); - - ActionManager am = actionManagerTestHelper.getMockActionManager(); - expect(am.getTasks(EasyMock.<List<Long>>anyObject())).andReturn( - new ArrayList<HostRoleCommand>() {{ - add(command); - add(command); - }}); - replay(am); - - HeartBeatHandler handler = heartbeatTestHelper.getHeartBeatHandler(am, aq); - HeartbeatProcessor heartbeatProcessor = handler.getHeartbeatProcessor(); - heartbeatProcessor.processHeartbeat(hb); - - assertEquals("Stack version for SCH should be updated to " + - serviceComponentHost1.getDesiredStackVersion(), - stack130, serviceComponentHost1.getStackVersion()); - assertEquals("Stack version for SCH should not change ", - stack120, serviceComponentHost2.getStackVersion()); - } - - - @Test - @SuppressWarnings("unchecked") public void testComponentUpgradeFailReport() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.addServiceComponent(NAMENODE); @@ -982,10 +895,6 @@ public class HeartbeatProcessorTest { serviceComponentHost1.setState(State.UPGRADING); serviceComponentHost2.setState(State.INSTALLING); - serviceComponentHost1.setStackVersion(stack120); - serviceComponentHost1.setDesiredStackVersion(stack130); - serviceComponentHost2.setStackVersion(stack120); - Stage s = stageFactory.createNew(requestId, "/a/b", "cluster1", 1L, "action manager test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); @@ -1071,10 +980,6 @@ public class HeartbeatProcessorTest { assertEquals("State of SCH should change after fail report", State.INSTALL_FAILED, serviceComponentHost2.getState()); assertEquals("Stack version of SCH should not change after fail report", - stack120, serviceComponentHost1.getStackVersion()); - assertEquals("Stack version of SCH should not change after fail report", - stack130, serviceComponentHost1.getDesiredStackVersion()); - assertEquals("Stack version of SCH should not change after fail report", State.INSTALL_FAILED, serviceComponentHost2.getState()); } @@ -1083,7 +988,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testComponentUpgradeInProgressReport() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.addServiceComponent(NAMENODE); @@ -1102,10 +1007,6 @@ public class HeartbeatProcessorTest { serviceComponentHost1.setState(State.UPGRADING); serviceComponentHost2.setState(State.INSTALLING); - serviceComponentHost1.setStackVersion(stack120); - serviceComponentHost1.setDesiredStackVersion(stack130); - serviceComponentHost2.setStackVersion(stack120); - HeartBeat hb = new HeartBeat(); hb.setTimestamp(System.currentTimeMillis()); hb.setResponseId(0); @@ -1155,8 +1056,6 @@ public class HeartbeatProcessorTest { handler.handleHeartBeat(hb); assertEquals("State of SCH not change while operation is in progress", State.UPGRADING, serviceComponentHost1.getState()); - assertEquals("Stack version of SCH should not change after in progress report", - stack130, serviceComponentHost1.getDesiredStackVersion()); assertEquals("State of SCH not change while operation is in progress", State.INSTALLING, serviceComponentHost2.getState()); } @@ -1240,6 +1139,7 @@ public class HeartbeatProcessorTest { replay(am); Cluster cluster = heartbeatTestHelper.getDummyCluster(); + HeartBeatHandler handler = heartbeatTestHelper.getHeartBeatHandler(am, new ActionQueue()); HeartbeatProcessor heartbeatProcessor = handler.getHeartbeatProcessor(); HeartBeat hb = new HeartBeat(); @@ -1247,7 +1147,7 @@ public class HeartbeatProcessorTest { JsonObject json = new JsonObject(); json.addProperty("actual_version", "2.2.1.0-2222"); json.addProperty("package_installation_result", "SUCCESS"); - json.addProperty("installed_repository_version", "0.1"); + json.addProperty("installed_repository_version", "0.1-1234"); json.addProperty("stack_id", cluster.getDesiredStackVersion().getStackId()); @@ -1273,12 +1173,12 @@ public class HeartbeatProcessorTest { StackId stackId = new StackId("HDP", "0.1"); RepositoryVersionDAO dao = injector.getInstance(RepositoryVersionDAO.class); - RepositoryVersionEntity entity = dao.findByStackAndVersion(stackId, "0.1"); + RepositoryVersionEntity entity = dao.findByStackAndVersion(stackId, "0.1-1234"); Assert.assertNotNull(entity); heartbeatProcessor.processHeartbeat(hb); - entity = dao.findByStackAndVersion(stackId, "0.1"); + entity = dao.findByStackAndVersion(stackId, "0.1-1234"); Assert.assertNull(entity); entity = dao.findByStackAndVersion(stackId, "2.2.1.0-2222"); @@ -1289,7 +1189,7 @@ public class HeartbeatProcessorTest { @SuppressWarnings("unchecked") public void testComponentInProgressStatusSafeAfterStatusReport() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); - Service hdfs = cluster.addService(HDFS); + Service hdfs = addService(cluster, HDFS); hdfs.addServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE). addServiceComponentHost(DummyHostname1); @@ -1358,5 +1258,20 @@ public class HeartbeatProcessorTest { } - + /** + * Adds the service to the cluster using the current cluster version as the + * repository version for the service. + * + * @param cluster + * the cluster. + * @param serviceName + * the service name. + * @return the newly added service. + * @throws AmbariException + */ + private Service addService(Cluster cluster, String serviceName) throws AmbariException { + ClusterVersionEntity clusterVersion = cluster.getCurrentClusterVersion(); + RepositoryVersionEntity repositoryVersion = clusterVersion.getRepositoryVersion(); + return cluster.addService(serviceName, repositoryVersion); + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 2e65e8d..6e1ebdd 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 @@ -21,6 +21,7 @@ import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyCluste import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyHostname1; import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyOSRelease; import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyOs; +import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyRepositoryVersion; import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyStackId; import static org.apache.ambari.server.agent.DummyHeartbeatConstants.HBASE; @@ -151,13 +152,14 @@ public class HeartbeatTestHelper { add(DummyHostname1); }}; - return getDummyCluster(DummyCluster, DummyStackId, configProperties, hostNames); + return getDummyCluster(DummyCluster, new StackId(DummyStackId), DummyRepositoryVersion, + configProperties, hostNames); } - public Cluster getDummyCluster(String clusterName, String desiredStackId, - Map<String, String> configProperties, Set<String> hostNames) + public Cluster getDummyCluster(String clusterName, StackId stackId, String repositoryVersion, + Map<String, String> configProperties, Set<String> hostNames) throws Exception { - StackEntity stackEntity = stackDAO.find(HDP_22_STACK.getStackName(), HDP_22_STACK.getStackVersion()); + StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion()); org.junit.Assert.assertNotNull(stackEntity); // Create the cluster @@ -177,8 +179,6 @@ public class HeartbeatTestHelper { clusterDAO.create(clusterEntity); - StackId stackId = new StackId(desiredStackId); - // because this test method goes around the Clusters business object, we // forcefully will refresh the internal state so that any tests which // incorrect use Clusters after calling this won't be affected @@ -196,8 +196,8 @@ public class HeartbeatTestHelper { Config config = cf.createNew(cluster, "cluster-env", "version1", configProperties, new HashMap<String, Map<String, String>>()); cluster.addDesiredConfig("user", Collections.singleton(config)); - helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); - cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin", + helper.getOrCreateRepositoryVersion(stackId, repositoryVersion); + cluster.createClusterVersion(stackId, repositoryVersion, "admin", RepositoryVersionState.INSTALLING); Map<String, String> hostAttributes = new HashMap<>();
