You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/04/02 19:37:02 UTC
[2/2] ambari git commit: AMBARI-10168. Full Delete of Host : Switch
host-related tables to use host_id instead of host_name column for hoststate,
hostcomponentstate, hostcomponentdesiredstate (alejandro)
AMBARI-10168. Full Delete of Host : Switch host-related tables to use host_id instead of host_name column for hoststate, hostcomponentstate, hostcomponentdesiredstate (alejandro)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1487ad37
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1487ad37
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1487ad37
Branch: refs/heads/trunk
Commit: 1487ad371827d80197d185428ef1a380baf10e6f
Parents: 97347b7
Author: Alejandro Fernandez <af...@hortonworks.com>
Authored: Wed Mar 25 14:44:07 2015 -0700
Committer: Alejandro Fernandez <af...@hortonworks.com>
Committed: Thu Apr 2 10:36:52 2015 -0700
----------------------------------------------------------------------
.../orm/dao/HostComponentDesiredStateDAO.java | 2 +-
.../apache/ambari/server/orm/dao/HostDAO.java | 6 +-
.../HostComponentDesiredStateEntity.java | 18 +-
.../HostComponentDesiredStateEntityPK.java | 16 +-
.../orm/entities/HostComponentStateEntity.java | 18 +-
.../entities/HostComponentStateEntityPK.java | 16 +-
.../ambari/server/orm/entities/HostEntity.java | 20 +-
.../server/orm/entities/HostStateEntity.java | 18 +-
.../server/state/ServiceComponentImpl.java | 2 +-
.../svccomphost/ServiceComponentHostImpl.java | 32 ++-
.../server/upgrade/AbstractUpgradeCatalog.java | 5 +
.../server/upgrade/SchemaUpgradeHelper.java | 34 ++-
.../ambari/server/upgrade/UpgradeCatalog.java | 6 +
.../server/upgrade/UpgradeCatalog150.java | 32 ++-
.../server/upgrade/UpgradeCatalog151.java | 17 +-
.../server/upgrade/UpgradeCatalog160.java | 18 +-
.../server/upgrade/UpgradeCatalog161.java | 19 +-
.../server/upgrade/UpgradeCatalog170.java | 18 +-
.../server/upgrade/UpgradeCatalog200.java | 8 +
.../server/upgrade/UpgradeCatalog210.java | 156 +++++++----
.../main/resources/Ambari-DDL-MySQL-CREATE.sql | 43 ++--
.../main/resources/Ambari-DDL-Oracle-CREATE.sql | 43 ++--
.../resources/Ambari-DDL-Postgres-CREATE.sql | 45 ++--
.../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql | 41 ++-
.../resources/Ambari-DDL-SQLServer-CREATE.sql | 48 ++--
.../dao/HostComponentDesiredStateDAOTest.java | 9 +-
.../server/state/ServiceComponentTest.java | 12 +-
.../server/state/cluster/ClustersTest.java | 11 +-
.../svccomphost/ServiceComponentHostTest.java | 16 +-
.../ambari/server/upgrade/SectionDDL.java | 44 ++++
.../server/upgrade/UpgradeCatalog150Test.java | 1 -
.../server/upgrade/UpgradeCatalog170Test.java | 14 +-
.../server/upgrade/UpgradeCatalog200Test.java | 16 +-
.../server/upgrade/UpgradeCatalog210Test.java | 257 ++++++++++++++-----
.../server/upgrade/UpgradeCatalogHelper.java | 2 -
.../server/upgrade/UpgradeCatalogTest.java | 53 +++-
36 files changed, 741 insertions(+), 375 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
index 8e92877..2d699b7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
@@ -73,7 +73,7 @@ public class HostComponentDesiredStateDAO {
@Transactional
public void remove(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) {
- HostEntity hostEntity = hostDAO.findByName(hostComponentDesiredStateEntity.getHostName());
+ HostEntity hostEntity = hostComponentDesiredStateEntity.getHostEntity();
entityManagerProvider.get().remove(merge(hostComponentDesiredStateEntity));
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
index 0fb9c59..6442bf5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
@@ -40,12 +40,12 @@ public class HostDAO {
/**
* Looks for Host by ID
- * @param id ID of Host
+ * @param hostId ID of Host
* @return Found entity or NULL
*/
@RequiresSession
- public HostEntity findById(long id) {
- return entityManagerProvider.get().find(HostEntity.class, id);
+ public HostEntity findById(long hostId) {
+ return entityManagerProvider.get().find(HostEntity.class, hostId);
}
@RequiresSession
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
index e0f1e9e..7f0b19d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
@@ -49,8 +49,8 @@ public class HostComponentDesiredStateEntity {
private String serviceName;
@Id
- @Column(name = "host_name", insertable = false, updatable = false)
- private String hostName = "";
+ @Column(name = "host_id", nullable = false, insertable = false, updatable = false)
+ private Long hostId;
@Id
@Column(name = "component_name", insertable = false, updatable = false)
@@ -82,7 +82,7 @@ public class HostComponentDesiredStateEntity {
private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity;
@ManyToOne
- @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
+ @JoinColumn(name = "host_id", referencedColumnName = "host_id", nullable = false)
private HostEntity hostEntity;
@Enumerated(value = EnumType.STRING)
@@ -109,12 +109,8 @@ public class HostComponentDesiredStateEntity {
this.serviceName = serviceName;
}
- public String getHostName() {
- return defaultString(hostName);
- }
-
- public void setHostName(String hostName) {
- this.hostName = hostName;
+ public Long getHostId() {
+ return hostEntity != null ? hostEntity.getHostId() : null;
}
public String getComponentName() {
@@ -178,7 +174,7 @@ public class HostComponentDesiredStateEntity {
if (desiredStackVersion != null ? !desiredStackVersion.equals(that.desiredStackVersion) : that.desiredStackVersion != null)
return false;
if (desiredState != null ? !desiredState.equals(that.desiredState) : that.desiredState != null) return false;
- if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+ if (hostEntity != null ? !hostEntity.equals(that.hostEntity) : that.hostEntity != null) return false;
if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
return true;
@@ -187,7 +183,7 @@ public class HostComponentDesiredStateEntity {
@Override
public int hashCode() {
int result = clusterId != null ? clusterId.intValue() : 0;
- result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+ result = 31 * result + (hostEntity != null ? hostEntity.hashCode() : 0);
result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
result = 31 * result + (desiredState != null ? desiredState.hashCode() : 0);
result = 31 * result + (desiredStackVersion != null ? desiredStackVersion.hashCode() : 0);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntityPK.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntityPK.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntityPK.java
index fc92858..1fd899d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntityPK.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntityPK.java
@@ -47,16 +47,16 @@ public class HostComponentDesiredStateEntityPK implements Serializable {
this.serviceName = serviceName;
}
- private String hostName;
+ private Long hostId;
@Id
- @Column(name = "host_name", nullable = false, insertable = true, updatable = true)
- public String getHostName() {
- return hostName;
+ @Column(name = "host_id", nullable = false, insertable = true, updatable = true)
+ public Long getHostId() {
+ return hostId;
}
- public void setHostName(String hostName) {
- this.hostName = hostName;
+ public void setHostId(Long hostId) {
+ this.hostId = hostId;
}
private String componentName;
@@ -80,7 +80,7 @@ public class HostComponentDesiredStateEntityPK implements Serializable {
if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false;
if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
- if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+ if (hostId != null ? !hostId.equals(that.hostId) : that.hostId != null) return false;
return true;
}
@@ -88,7 +88,7 @@ public class HostComponentDesiredStateEntityPK implements Serializable {
@Override
public int hashCode() {
int result = clusterId !=null ? clusterId.intValue() : 0;
- result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+ result = 31 * result + (hostId != null ? hostId.hashCode() : 0);
result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
return result;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
index 0a31b90..4463366 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
@@ -32,7 +32,7 @@ import static org.apache.commons.lang.StringUtils.defaultString;
@NamedQueries({
@NamedQuery(name = "HostComponentStateEntity.findAll", query = "SELECT hcs from HostComponentStateEntity hcs"),
@NamedQuery(name = "HostComponentStateEntity.findByHost", query =
- "SELECT hcs from HostComponentStateEntity hcs WHERE hcs.hostName=:hostName"),
+ "SELECT hcs from HostComponentStateEntity hcs WHERE hcs.hostEntity.hostName=:hostName"),
})
public class HostComponentStateEntity {
@@ -45,8 +45,8 @@ public class HostComponentStateEntity {
private String serviceName;
@Id
- @Column(name = "host_name", insertable = false, updatable = false)
- private String hostName = "";
+ @Column(name = "host_id", nullable=false, insertable = false, updatable = false)
+ private Long hostId;
@Id
@Column(name = "component_name", nullable = false, insertable = false, updatable = false)
@@ -79,7 +79,7 @@ public class HostComponentStateEntity {
private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity;
@ManyToOne
- @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
+ @JoinColumn(name = "host_id", referencedColumnName = "host_id", nullable = false)
private HostEntity hostEntity;
public Long getClusterId() {
@@ -99,11 +99,11 @@ public class HostComponentStateEntity {
}
public String getHostName() {
- return defaultString(hostName);
+ return this.hostEntity.getHostName();
}
- public void setHostName(String hostName) {
- this.hostName = hostName;
+ public Long getHostId() {
+ return hostEntity != null ? hostEntity.getHostId() : null;
}
public String getComponentName() {
@@ -167,7 +167,7 @@ public class HostComponentStateEntity {
return false;
if (currentState != null ? !currentState.equals(that.currentState) : that.currentState != null) return false;
if (upgradeState != null ? !upgradeState.equals(that.upgradeState) : that.upgradeState != null) return false;
- if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+ if (hostEntity != null ? !hostEntity.equals(that.hostEntity) : that.hostEntity != null) return false;
if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
if (version != null ? !version.equals(that.version) : that.version != null) return false;
@@ -177,7 +177,7 @@ public class HostComponentStateEntity {
@Override
public int hashCode() {
int result = clusterId != null ? clusterId.intValue() : 0;
- result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+ result = 31 * result + (hostEntity != null ? hostEntity.hashCode() : 0);
result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
result = 31 * result + (upgradeState != null ? upgradeState.hashCode() : 0);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntityPK.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntityPK.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntityPK.java
index bc103a1..86e0dee 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntityPK.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntityPK.java
@@ -48,16 +48,16 @@ public class HostComponentStateEntityPK implements Serializable {
this.serviceName = serviceName;
}
- private String hostName;
+ private Long hostId;
@Id
- @Column(name = "host_name", nullable = false, insertable = true, updatable = true)
- public String getHostName() {
- return hostName;
+ @Column(name = "host_id", nullable = false, insertable = true, updatable = true)
+ public Long getHostId() {
+ return hostId;
}
- public void setHostName(String hostName) {
- this.hostName = hostName;
+ public void setHostId(Long hostId) {
+ this.hostId = hostId;
}
private String componentName;
@@ -81,7 +81,7 @@ public class HostComponentStateEntityPK implements Serializable {
if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false;
if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
- if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+ if (hostId != null ? !hostId.equals(that.hostId) : that.hostId != null) return false;
return true;
}
@@ -89,7 +89,7 @@ public class HostComponentStateEntityPK implements Serializable {
@Override
public int hashCode() {
int result = clusterId !=null ? clusterId.intValue() : 0;
- result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+ result = 31 * result + (hostId != null ? hostId.hashCode() : 0);
result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
return result;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
index 4df5f39..a811c16 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
@@ -54,9 +54,9 @@ import static org.apache.commons.lang.StringUtils.defaultString;
public class HostEntity implements Comparable<HostEntity> {
@Id
- @Column(name = "id", nullable = false, insertable = true, updatable = false)
+ @Column(name = "host_id", nullable = false, insertable = true, updatable = false)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "host_id_generator")
- private Long id;
+ private Long hostId;
@Column(name = "host_name", nullable = false, insertable = true, updatable = true, unique = true)
@Basic
@@ -133,7 +133,7 @@ public class HostEntity implements Comparable<HostEntity> {
@ManyToMany
@JoinTable(name = "ClusterHostMapping",
- joinColumns = {@JoinColumn(name = "host_id", referencedColumnName = "id")},
+ joinColumns = {@JoinColumn(name = "host_id", referencedColumnName = "host_id")},
inverseJoinColumns = {@JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id")}
)
private Collection<ClusterEntity> clusterEntities;
@@ -144,12 +144,12 @@ public class HostEntity implements Comparable<HostEntity> {
@OneToMany(mappedBy = "host", cascade = CascadeType.REMOVE)
private Collection<HostRoleCommandEntity> hostRoleCommandEntities;
- public Long getId() {
- return id;
+ public Long getHostId() {
+ return hostId;
}
- public void setId(Long id) {
- this.id = id;
+ public void setHostId(Long hostId) {
+ this.hostId = hostId;
}
public String getHostName() {
@@ -279,14 +279,12 @@ public class HostEntity implements Comparable<HostEntity> {
HostEntity that = (HostEntity) o;
- if (!hostName.equals(that.hostName)) return false;
-
- return true;
+ return this.hostId == that.hostId && this.hostName.equals(that.hostName);
}
@Override
public int hashCode() {
- return hostName.hashCode();
+ return hostId.hashCode();
}
@Override
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
index 5d5a1e8..52ae322 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
@@ -35,9 +35,9 @@ import org.apache.ambari.server.state.HostState;
@Entity
public class HostStateEntity {
- @javax.persistence.Column(name = "host_name", nullable = false, insertable = false, updatable = false)
+ @javax.persistence.Column(name = "host_id", nullable = false, insertable = false, updatable = false)
@Id
- private String hostName;
+ private Long hostId;
@Column(name = "available_mem", nullable = false, insertable = true, updatable = true)
@Basic
@@ -64,17 +64,9 @@ public class HostStateEntity {
@OneToOne
- @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
+ @JoinColumn(name = "host_id", referencedColumnName = "host_id", nullable = false)
private HostEntity hostEntity;
- public String getHostName() {
- return hostName;
- }
-
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
-
public Long getAvailableMem() {
return availableMem;
}
@@ -130,18 +122,18 @@ public class HostStateEntity {
HostStateEntity that = (HostStateEntity) o;
+ if (hostId != null ? hostId != that.hostId : that.hostId != null) return false;
if (availableMem != null ? !availableMem.equals(that.availableMem) : that.availableMem != null) return false;
if (timeInState != null ? !timeInState.equals(that.timeInState) : that.timeInState!= null) return false;
if (agentVersion != null ? !agentVersion.equals(that.agentVersion) : that.agentVersion != null) return false;
if (currentState != null ? !currentState.equals(that.currentState) : that.currentState != null) return false;
- if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
return true;
}
@Override
public int hashCode() {
- int result = hostName != null ? hostName.hashCode() : 0;
+ int result = hostId != null ? hostId.intValue() : 0;
result = 31 * result + (availableMem != null ? availableMem.intValue() : 0);
result = 31 * result + (timeInState != null ? timeInState.intValue() : 0);
result = 31 * result + (agentVersion != null ? agentVersion.hashCode() : 0);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 1bd2814..23246b4 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
@@ -120,7 +120,7 @@ public class ServiceComponentImpl implements ServiceComponent {
pk.setClusterId(hostComponentStateEntity.getClusterId());
pk.setServiceName(hostComponentStateEntity.getServiceName());
pk.setComponentName(hostComponentStateEntity.getComponentName());
- pk.setHostName(hostComponentStateEntity.getHostName());
+ pk.setHostId(hostComponentStateEntity.getHostId());
HostComponentDesiredStateEntity hostComponentDesiredStateEntity = hostComponentDesiredStateDAO.findByPK(pk);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 7975f4e..370cd48 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
@@ -690,12 +690,24 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
this.serviceComponent = serviceComponent;
clusterGlobalLock = serviceComponent.getClusterGlobalLock();
+ HostEntity hostEntity = null;
+ try {
+ host = clusters.getHost(hostName);
+ hostEntity = hostDAO.findByName(hostName);
+ if (hostEntity == null) {
+ throw new AmbariException("Could not find host " + hostName);
+ }
+ } catch (AmbariException e) {
+ LOG.error("Host '{}' was not found" + hostName);
+ throw new RuntimeException(e);
+ }
+
stateEntity = new HostComponentStateEntity();
stateEntity.setClusterId(serviceComponent.getClusterId());
stateEntity.setComponentName(serviceComponent.getName());
stateEntity.setServiceName(serviceComponent.getServiceName());
stateEntity.setVersion(State.UNKNOWN.toString());
- stateEntity.setHostName(hostName);
+ stateEntity.setHostEntity(hostEntity);
stateEntity.setCurrentState(stateMachine.getCurrentState());
stateEntity.setUpgradeState(UpgradeState.NONE);
stateEntity.setCurrentStackVersion(gson.toJson(new StackId()));
@@ -706,7 +718,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
desiredStateEntity.setClusterId(serviceComponent.getClusterId());
desiredStateEntity.setComponentName(serviceComponent.getName());
desiredStateEntity.setServiceName(serviceComponent.getServiceName());
- desiredStateEntity.setHostName(hostName);
+ desiredStateEntity.setHostEntity(hostEntity);
desiredStateEntity.setDesiredState(State.INIT);
desiredStateEntity.setDesiredStackVersion(
gson.toJson(serviceComponent.getDesiredStackVersion()));
@@ -718,14 +730,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
desiredStateEntityPK = getHostComponentDesiredStateEntityPK(desiredStateEntity);
- try {
- host = clusters.getHost(hostName);
- } catch (AmbariException e) {
- //TODO exception?
- LOG.error("Host '{}' was not found" + hostName);
- throw new RuntimeException(e);
- }
-
resetLastOpInfo();
}
@@ -1321,7 +1325,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
pk.setClusterId(stateEntity.getClusterId());
pk.setComponentName(stateEntity.getComponentName());
pk.setServiceName(stateEntity.getServiceName());
- pk.setHostName(stateEntity.getHostName());
+ pk.setHostId(stateEntity.getHostId());
hostComponentStateDAO.removeByPK(pk);
@@ -1329,7 +1333,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
desiredPK.setClusterId(desiredStateEntity.getClusterId());
desiredPK.setComponentName(desiredStateEntity.getComponentName());
desiredPK.setServiceName(desiredStateEntity.getServiceName());
- desiredPK.setHostName(desiredStateEntity.getHostName());
+ desiredPK.setHostId(desiredStateEntity.getHostId());
hostComponentDesiredStateDAO.removeByPK(desiredPK);
@@ -1542,7 +1546,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
dpk.setClusterId(desiredStateEntity.getClusterId());
dpk.setComponentName(desiredStateEntity.getComponentName());
dpk.setServiceName(desiredStateEntity.getServiceName());
- dpk.setHostName(desiredStateEntity.getHostName());
+ dpk.setHostId(desiredStateEntity.getHostId());
return dpk;
}
@@ -1552,7 +1556,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
pk.setClusterId(stateEntity.getClusterId());
pk.setComponentName(stateEntity.getComponentName());
pk.setServiceName(stateEntity.getServiceName());
- pk.setHostName(stateEntity.getHostName());
+ pk.setHostId(stateEntity.getHostId());
return pk;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 1f3c09a..863b5da 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
@@ -91,6 +91,11 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
return null;
}
+ @Override
+ public String[] getCompatibleVersions() {
+ return null;
+ }
+
protected static UpgradeCatalog getUpgradeCatalog(String version) {
return upgradeCatalogMap.get(version);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
index 3691af2..61482c9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
@@ -26,6 +26,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.configuration.Configuration;
@@ -126,7 +128,6 @@ public class SchemaUpgradeHelper {
*/
protected List<UpgradeCatalog> getUpgradePath(String sourceVersion,
String targetVersion) throws AmbariException {
-
List<UpgradeCatalog> upgradeCatalogs = new ArrayList<UpgradeCatalog>();
List<UpgradeCatalog> candidateCatalogs = new ArrayList<UpgradeCatalog>(allUpgradeCatalogs);
@@ -150,6 +151,33 @@ public class SchemaUpgradeHelper {
}
/**
+ * Determine if the class definitions in the target version allow running the Upgrade Catalogs in the path.
+ * @param upgradeCatalogs Ordered list of upgrade catalogs
+ * @param targetVersion Destination version
+ * @throws AmbariException If invalid path, will throw an exception.
+ */
+ public void validateUpgradePath(List<UpgradeCatalog> upgradeCatalogs, String targetVersion) throws AmbariException {
+ for(UpgradeCatalog upgradeCatalog : upgradeCatalogs) {
+ if (upgradeCatalog.getCompatibleVersions() != null) {
+ boolean validPath = false;
+ for (String version : upgradeCatalog.getCompatibleVersions()) {
+ // Treat dots as dots instead of match-any-char, and * as wildcard
+ String regexVersion = version.replace(".", "\\.").replace("*", ".*");
+ Matcher m = Pattern.compile(regexVersion).matcher(targetVersion);
+ if (m.matches()) {
+ validPath = true;
+ break;
+ }
+ }
+ if (!validPath) {
+ throw new AmbariException("Cannot upgrade because UpgradeCatalog " +
+ upgradeCatalog.getTargetVersion() + " is not supported in Ambari version " + targetVersion + ".");
+ }
+ }
+ }
+ }
+
+ /**
* Extension of main controller module
*/
public static class UpgradeHelperModule extends ControllerModule {
@@ -243,6 +271,8 @@ public class SchemaUpgradeHelper {
List<UpgradeCatalog> upgradeCatalogs =
schemaUpgradeHelper.getUpgradePath(sourceVersion, targetVersion);
+ schemaUpgradeHelper.validateUpgradePath(upgradeCatalogs, targetVersion);
+
schemaUpgradeHelper.executeUpgrade(upgradeCatalogs);
schemaUpgradeHelper.startPersistenceService();
@@ -256,7 +286,7 @@ public class SchemaUpgradeHelper {
schemaUpgradeHelper.stopPersistenceService();
} catch (Throwable e) {
if (e instanceof AmbariException) {
- LOG.error("Exception occured during upgrade, failed", e);
+ LOG.error("Exception occurred during upgrade, failed", e);
throw (AmbariException)e;
}else{
LOG.error("Unexpected error, upgrade failed", e);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog.java
index fcf4f51..a10b21c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog.java
@@ -52,4 +52,10 @@ public interface UpgradeCatalog {
* @return null : default
*/
public String getSourceVersion();
+
+ /**
+ * Returns a list of versions using simplified regex of the Ambari versions that allow running this UpgradeCatalog.
+ * @return null : default
+ */
+ public String[] getCompatibleVersions();
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
index dd8e33e..d80909b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
@@ -88,6 +88,19 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
}
@Override
+ public String getTargetVersion() {
+ return "1.5.0";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String[] getCompatibleVersions() {
+ return new String[] {"1.5.*", "1.6.*", "1.7.*", "2.0.*"};
+ }
+
+ @Override
public void executeDDLUpdates() throws AmbariException, SQLException {
LOG.debug("Upgrading schema...");
DatabaseType databaseType = configuration.getDatabaseType();
@@ -577,6 +590,7 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
+ HostDAO hostDao = injector.getInstance(HostDAO.class);
List<ClusterEntity> clusterEntities = clusterDAO.findAll();
for (final ClusterEntity clusterEntity : clusterEntities) {
@@ -626,8 +640,13 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
serviceComponentDesiredStateEntity.setClusterServiceEntity(clusterServiceEntity);
serviceComponentDesiredStateEntity.setHostComponentDesiredStateEntities(new ArrayList<HostComponentDesiredStateEntity>());
+ final HostEntity host = hostDao.findByName(jtHostname);
+ if (host == null) {
+ continue;
+ }
+
final HostComponentStateEntity stateEntity = new HostComponentStateEntity();
- stateEntity.setHostName(jtHostname);
+ stateEntity.setHostEntity(host);
stateEntity.setCurrentState(jtCurrState);
stateEntity.setCurrentStackVersion(clusterEntity.getDesiredStackVersion());
@@ -645,7 +664,7 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class);
HostDAO hostDAO = injector.getInstance(HostDAO.class);
- HostEntity hostEntity = hostDAO.findByName(stateEntity.getHostName());
+ HostEntity hostEntity = stateEntity.getHostEntity();
hostEntity.addHostComponentStateEntity(stateEntity);
hostEntity.addHostComponentDesiredStateEntity(desiredStateEntity);
@@ -754,6 +773,7 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
protected void processDecommissionedDatanodes() {
KeyValueDAO keyValueDAO = injector.getInstance(KeyValueDAO.class);
ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
+ HostDAO hostDAO = injector.getInstance(HostDAO.class);
Gson gson = injector.getInstance(Gson.class);
HostComponentDesiredStateDAO desiredStateDAO = injector.getInstance
(HostComponentDesiredStateDAO.class);
@@ -777,12 +797,13 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
String[] nodes = decommissionedNodes.split(",");
if (nodes.length > 0) {
for (String node : nodes) {
+ HostEntity hostEntity = hostDAO.findByName(node.trim());
HostComponentDesiredStateEntityPK entityPK =
new HostComponentDesiredStateEntityPK();
entityPK.setClusterId(clusterId);
entityPK.setServiceName("HDFS");
entityPK.setComponentName("DATANODE");
- entityPK.setHostName(node.trim());
+ entityPK.setHostId(hostEntity.getHostId());
HostComponentDesiredStateEntity desiredStateEntity =
desiredStateDAO.findByPK(entityPK);
desiredStateEntity.setAdminState(HostComponentAdminState.DECOMMISSIONED);
@@ -875,9 +896,4 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
}
}
-
- @Override
- public String getTargetVersion() {
- return "1.5.0";
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog151.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog151.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog151.java
index afe27b5..cd3945a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog151.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog151.java
@@ -39,6 +39,18 @@ public class UpgradeCatalog151 extends AbstractUpgradeCatalog {
return "1.5.0";
}
+ @Override
+ public String getTargetVersion() {
+ return "1.5.1";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String[] getCompatibleVersions() {
+ return new String[] {"1.5.*", "1.6.*", "1.7.*", "2.0.*"};
+ }
// ----- Constructors ------------------------------------------------------
@@ -138,9 +150,4 @@ public class UpgradeCatalog151 extends AbstractUpgradeCatalog {
@Override
public void executeDMLUpdates() throws AmbariException, SQLException {
}
-
- @Override
- public String getTargetVersion() {
- return "1.5.1";
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java
index a1f11d8..ac32081 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog160.java
@@ -41,6 +41,19 @@ public class UpgradeCatalog160 extends AbstractUpgradeCatalog {
return "1.5.1";
}
+ @Override
+ public String getTargetVersion() {
+ return "1.6.0";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String[] getCompatibleVersions() {
+ return new String[] {"1.6.*", "1.7.*", "2.0.*"};
+ }
+
// ----- Constructors ------------------------------------------------------
@Inject
@@ -190,9 +203,4 @@ public class UpgradeCatalog160 extends AbstractUpgradeCatalog {
// Add missing property for YARN
updateConfigurationProperties("global", Collections.singletonMap("jobhistory_heapsize", "900"), false, false);
}
-
- @Override
- public String getTargetVersion() {
- return "1.6.0";
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
index 4ab0cb6..ac8bb52 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
@@ -51,6 +51,20 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
return "1.6.0";
}
+
+ @Override
+ public String getTargetVersion() {
+ return "1.6.1";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String[] getCompatibleVersions() {
+ return new String[] {"1.6.*", "1.7.*", "2.0.*"};
+ }
+
/**
* Logger.
*/
@@ -316,9 +330,4 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
"threshold=100\npig.optimistic.files.concatenation=false;\n\npig.disable.counter=false\n\n" +
"hcat.bin=/usr/bin/hcat"), true, false);
}
-
- @Override
- public String getTargetVersion() {
- return "1.6.1";
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
index 98ac89f..db0506b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
@@ -51,6 +51,7 @@ import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
import org.apache.ambari.server.orm.dao.ConfigGroupConfigMappingDAO;
import org.apache.ambari.server.orm.dao.DaoUtils;
+import org.apache.ambari.server.orm.dao.HostDAO;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.dao.KeyValueDAO;
import org.apache.ambari.server.orm.dao.PermissionDAO;
@@ -72,6 +73,7 @@ import org.apache.ambari.server.orm.entities.ClusterServiceEntityPK;
import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntity;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
+import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity_;
import org.apache.ambari.server.orm.entities.KeyValueEntity;
@@ -145,6 +147,14 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public String[] getCompatibleVersions() {
+ return new String[] {"1.7.*", "2.0.*"};
+ }
+
+ /**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger
@@ -714,6 +724,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
ServiceDesiredStateDAO serviceDesiredStateDAO = injector.getInstance(ServiceDesiredStateDAO.class);
ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
+ HostDAO hostDAO = injector.getInstance(HostDAO.class);
List<ClusterEntity> clusterEntities = clusterDAO.findAll();
for (final ClusterEntity clusterEntity : clusterEntities) {
@@ -762,7 +773,6 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
hostComponentDesiredStateEntity.setComponentName(hcDesiredStateEntityToBeDeleted.getComponentName());
hostComponentDesiredStateEntity.setDesiredStackVersion(hcDesiredStateEntityToBeDeleted.getDesiredStackVersion());
hostComponentDesiredStateEntity.setDesiredState(hcDesiredStateEntityToBeDeleted.getDesiredState());
- hostComponentDesiredStateEntity.setHostName(hcDesiredStateEntityToBeDeleted.getHostName());
hostComponentDesiredStateEntity.setHostEntity(hcDesiredStateEntityToBeDeleted.getHostEntity());
hostComponentDesiredStateEntity.setAdminState(hcDesiredStateEntityToBeDeleted.getAdminState());
hostComponentDesiredStateEntity.setMaintenanceState(hcDesiredStateEntityToBeDeleted.getMaintenanceState());
@@ -775,12 +785,16 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
while (hostComponentStateIterator.hasNext()) {
HostComponentStateEntity hcStateToBeDeleted = hostComponentStateIterator.next();
+ HostEntity hostToBeDeleted = hostDAO.findByName(hcStateToBeDeleted.getHostName());
+ if (hostToBeDeleted == null) {
+ continue;
+ }
+
HostComponentStateEntity hostComponentStateEntity = new HostComponentStateEntity();
hostComponentStateEntity.setClusterId(clusterEntity.getClusterId());
hostComponentStateEntity.setComponentName(hcStateToBeDeleted.getComponentName());
hostComponentStateEntity.setCurrentStackVersion(hcStateToBeDeleted.getCurrentStackVersion());
hostComponentStateEntity.setCurrentState(hcStateToBeDeleted.getCurrentState());
- hostComponentStateEntity.setHostName(hcStateToBeDeleted.getHostName());
hostComponentStateEntity.setHostEntity(hcStateToBeDeleted.getHostEntity());
hostComponentStateEntity.setServiceName(serviceName);
hostComponentStateEntity.setServiceComponentDesiredStateEntity(serviceComponentDesiredStateEntity);
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 d3b062a..e577aa4 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
@@ -96,6 +96,14 @@ public class UpgradeCatalog200 extends AbstractUpgradeCatalog {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public String[] getCompatibleVersions() {
+ return new String[] {"2.0.*"};
+ }
+
+ /**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 23ed67d..d1a0bbe 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
@@ -26,8 +26,7 @@ import java.util.List;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
-import org.apache.ambari.server.orm.dao.HostDAO;
-import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,9 +40,6 @@ import com.google.inject.persist.Transactional;
*/
public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
- @Inject
- HostDAO hostDAO;
-
private static final String CLUSTERS_TABLE = "clusters";
private static final String HOSTS_TABLE = "hosts";
private static final String HOST_COMPONENT_DESIRED_STATE_TABLE = "hostcomponentdesiredstate";
@@ -62,6 +58,8 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
private static final String VIEW_PARAMETER_TABLE = "viewparameter";
private static final String STACK_TABLE_DEFINITION = "stack";
+ private static final String HOST_ID_COL = "host_id";
+
/**
* {@inheritDoc}
*/
@@ -79,6 +77,13 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
}
/**
+ * {@inheritDoc}
+ */
+ public String[] getCompatibleVersions() {
+ return new String[] {"*"};
+ }
+
+ /**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger
@@ -117,12 +122,14 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
private void executeHostsDDLUpdates() throws AmbariException, SQLException {
Configuration.DatabaseType databaseType = configuration.getDatabaseType();
- dbAccessor.addColumn(HOSTS_TABLE, new DBColumnInfo("id", Long.class, null, null, true));
+ dbAccessor.addColumn(HOSTS_TABLE, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true));
+ // Sequence value for the hosts table primary key. First record will be 1, so ambari_sequence value must be 0.
Long hostId = 0L;
ResultSet resultSet = null;
try {
- resultSet = dbAccessor.executeSelect("SELECT host_name FROM hosts");
+ // Notice that hosts are ordered by host_id ASC, so any null values are last.
+ resultSet = dbAccessor.executeSelect("SELECT host_name, host_id FROM hosts ORDER BY host_id ASC, host_name ASC");
hostId = populateHostsId(resultSet);
} finally {
if (resultSet != null) {
@@ -132,39 +139,39 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
// Insert host id number into ambari_sequences
dbAccessor.executeQuery("INSERT INTO ambari_sequences (sequence_name, sequence_value) VALUES ('host_id_seq', " + hostId + ")");
- //dbAccessor.insertRow("ambari_sequences", new String[]{"sequence_name", "sequence_value"}, new String[]{"host_id_seq", hostId.toString()}, false);
// Make the hosts id non-null after all the values are populated
if (databaseType == Configuration.DatabaseType.DERBY) {
// This is a workaround for UpgradeTest.java unit test
- dbAccessor.executeQuery("ALTER TABLE hosts ALTER column id NOT NULL");
+ dbAccessor.executeQuery("ALTER TABLE " + HOSTS_TABLE + " ALTER column " + HOST_ID_COL + " NOT NULL");
} else {
- dbAccessor.alterColumn("hosts", new DBColumnInfo("id", Long.class, null, null, false));
- //dbAccessor.executeQuery("ALTER TABLE hosts ALTER column id SET NOT NULL");
+ dbAccessor.alterColumn(HOSTS_TABLE, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, false));
}
// Drop the 8 FK constraints in the host-related tables. They will be recreated later after the PK is changed.
// The only host-related table not being included is alert_history.
if (databaseType == Configuration.DatabaseType.DERBY) {
- dbAccessor.executeQuery("ALTER TABLE hostcomponentdesiredstate DROP CONSTRAINT hstcmponentdesiredstatehstname");
- dbAccessor.executeQuery("ALTER TABLE hostcomponentstate DROP CONSTRAINT hostcomponentstate_host_name");
- dbAccessor.executeQuery("ALTER TABLE hoststate DROP CONSTRAINT FK_hoststate_host_name");
- dbAccessor.executeQuery("ALTER TABLE host_version DROP CONSTRAINT FK_host_version_host_name");
- dbAccessor.executeQuery("ALTER TABLE host_role_command DROP CONSTRAINT FK_host_role_command_host_name");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_COMPONENT_STATE_TABLE + " DROP CONSTRAINT hostcomponentstate_host_name");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_COMPONENT_DESIRED_STATE_TABLE + " DROP CONSTRAINT hstcmponentdesiredstatehstname");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_ROLE_COMMAND_TABLE + " DROP CONSTRAINT FK_host_role_command_host_name");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_STATE_TABLE + " DROP CONSTRAINT FK_hoststate_host_name");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_VERSION_TABLE + " DROP CONSTRAINT FK_host_version_host_name");
+ dbAccessor.executeQuery("ALTER TABLE " + CONFIG_GROUP_HOST_MAPPING_TABLE + " DROP CONSTRAINT FK_cghm_hname");
+ dbAccessor.executeQuery("ALTER TABLE " + KERBEROS_PRINCIPAL_HOST_TABLE + " DROP CONSTRAINT FK_krb_pr_host_hostname");
+
// This FK name is actually different on Derby.
- dbAccessor.executeQuery("ALTER TABLE hostconfigmapping DROP CONSTRAINT FK_hostconfigmapping_host_name");
- dbAccessor.executeQuery("ALTER TABLE configgrouphostmapping DROP CONSTRAINT FK_cghm_hname");
- dbAccessor.executeQuery("ALTER TABLE kerberos_principal_host DROP CONSTRAINT FK_krb_pr_host_hostname");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_CONFIG_MAPPING_TABLE + " DROP CONSTRAINT FK_hostconfigmapping_host_name");
} else {
- dbAccessor.dropConstraint(HOST_COMPONENT_DESIRED_STATE_TABLE, "hstcmponentdesiredstatehstname");
dbAccessor.dropConstraint(HOST_COMPONENT_STATE_TABLE, "hostcomponentstate_host_name");
+ dbAccessor.dropConstraint(HOST_COMPONENT_DESIRED_STATE_TABLE, "hstcmponentdesiredstatehstname");
+ dbAccessor.dropConstraint(HOST_ROLE_COMMAND_TABLE, "FK_host_role_command_host_name");
dbAccessor.dropConstraint(HOST_STATE_TABLE, "FK_hoststate_host_name");
dbAccessor.dropConstraint(HOST_VERSION_TABLE, "FK_host_version_host_name");
- dbAccessor.dropConstraint(HOST_ROLE_COMMAND_TABLE, "FK_host_role_command_host_name");
- dbAccessor.dropConstraint(HOST_CONFIG_MAPPING_TABLE, "FK_hostconfmapping_host_name");
dbAccessor.dropConstraint(CONFIG_GROUP_HOST_MAPPING_TABLE, "FK_cghm_hname");
dbAccessor.dropConstraint(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_krb_pr_host_hostname");
+
+ dbAccessor.dropConstraint(HOST_CONFIG_MAPPING_TABLE, "FK_hostconfmapping_host_name");
}
// In Ambari 2.0.0, there were discrepancies with the FK in the ClusterHostMapping table in the Postgres databases.
@@ -182,31 +189,25 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
"It is possible it did not exist or the deletion failed. " + e.getMessage());
}
- // Readd the FK to the cluster_id; will add the host_id at the end.
+ // Re-add the FK to the cluster_id; will add the host_id at the end.
dbAccessor.addFKConstraint(CLUSTER_HOST_MAPPING_TABLE, "FK_clusterhostmapping_cluster_id",
"cluster_id", CLUSTERS_TABLE, "cluster_id", false);
- // Drop the PK, and recreate it on the id instead
+ // Drop the PK, and recreate it on the host_id instead
if (databaseType == Configuration.DatabaseType.DERBY) {
String constraintName = getDerbyTableConstraintName("p", HOSTS_TABLE);
if (null != constraintName) {
- dbAccessor.executeQuery("ALTER TABLE hosts DROP CONSTRAINT " + constraintName);
+ dbAccessor.executeQuery("ALTER TABLE " + HOSTS_TABLE + " DROP CONSTRAINT " + constraintName);
}
} else {
dbAccessor.dropConstraint(HOSTS_TABLE, "hosts_pkey");
}
- dbAccessor.executeQuery("ALTER TABLE hosts ADD CONSTRAINT PK_hosts_id PRIMARY KEY (id)");
+ dbAccessor.executeQuery("ALTER TABLE " + HOSTS_TABLE + " ADD CONSTRAINT PK_hosts_id PRIMARY KEY (host_id)");
+ dbAccessor.executeQuery("ALTER TABLE " + HOSTS_TABLE + " ADD CONSTRAINT UQ_hosts_host_name UNIQUE (host_name)");
- dbAccessor.executeQuery("ALTER TABLE hosts ADD CONSTRAINT UQ_hosts_host_name UNIQUE (host_name)");
// TODO, for now, these still point to the host_name and will be fixed one table at a time to point to the host id.
// Re-add the FKs
- dbAccessor.addFKConstraint(HOST_COMPONENT_DESIRED_STATE_TABLE, "hstcmponentdesiredstatehstname",
- "host_name", HOSTS_TABLE, "host_name", false);
- dbAccessor.addFKConstraint(HOST_COMPONENT_STATE_TABLE, "hostcomponentstate_host_name",
- "host_name", HOSTS_TABLE, "host_name", false);
- dbAccessor.addFKConstraint(HOST_STATE_TABLE, "FK_hoststate_host_name",
- "host_name", HOSTS_TABLE, "host_name", false);
dbAccessor.addFKConstraint(HOST_VERSION_TABLE, "FK_host_version_host_name",
"host_name", HOSTS_TABLE, "host_name", false);
dbAccessor.addFKConstraint(HOST_ROLE_COMMAND_TABLE, "FK_host_role_command_host_name",
@@ -220,22 +221,79 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
// Add host_id to the host-related tables, and populate the host_id, one table at a time.
- dbAccessor.addColumn(CLUSTER_HOST_MAPPING_TABLE, new DBColumnInfo("host_id", Long.class, null, null, true));
- dbAccessor.executeQuery("UPDATE clusterhostmapping chm SET host_id = (SELECT id FROM hosts h WHERE h.host_name = chm.host_name) WHERE chm.host_id IS NULL AND chm.host_name IS NOT NULL");
-
- if (databaseType == Configuration.DatabaseType.DERBY) {
- // This is a workaround for UpgradeTest.java unit test
- dbAccessor.executeQuery("ALTER TABLE clusterhostmapping ALTER column host_id NOT NULL");
- } else {
- dbAccessor.executeQuery("ALTER TABLE clusterhostmapping ALTER column host_id SET NOT NULL");
+ // TODO, include other tables.
+ String[] tablesToAddHostID = new String[] {
+ CLUSTER_HOST_MAPPING_TABLE,
+ HOST_COMPONENT_STATE_TABLE,
+ HOST_COMPONENT_DESIRED_STATE_TABLE,
+ HOST_STATE_TABLE
+ };
+ for (String tableName : tablesToAddHostID) {
+ dbAccessor.addColumn(tableName, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true));
+ dbAccessor.executeQuery("UPDATE " + tableName + " t SET host_id = (SELECT host_id FROM hosts h WHERE h.host_name = t.host_name) WHERE t.host_id IS NULL AND t.host_name IS NOT NULL");
+
+ if (databaseType == Configuration.DatabaseType.DERBY) {
+ // This is a workaround for UpgradeTest.java unit test
+ dbAccessor.executeQuery("ALTER TABLE " + tableName + " ALTER column " + HOST_ID_COL + " NOT NULL");
+ } else {
+ dbAccessor.executeQuery("ALTER TABLE " + tableName + " ALTER column " + HOST_ID_COL + " SET NOT NULL");
+ }
}
// These are the FKs that have already been corrected.
+ // TODO, include other tables.
dbAccessor.addFKConstraint(CLUSTER_HOST_MAPPING_TABLE, "FK_clusterhostmapping_host_id",
- "host_id", HOSTS_TABLE, "id", false);
+ "host_id", HOSTS_TABLE, "host_id", false);
+ dbAccessor.addFKConstraint(HOST_COMPONENT_STATE_TABLE, "FK_hostcomponentstate_host_id",
+ "host_id", HOSTS_TABLE, "host_id", false);
+ dbAccessor.addFKConstraint(HOST_COMPONENT_DESIRED_STATE_TABLE, "FK_hostcomponentdesiredstate_host_id",
+ "host_id", HOSTS_TABLE, "host_id", false);
+ dbAccessor.addFKConstraint(HOST_STATE_TABLE, "FK_hoststate_host_id",
+ "host_id", HOSTS_TABLE, "host_id", false);
- dbAccessor.dropColumn(CLUSTER_HOST_MAPPING_TABLE, "host_name");
+
+ // For any tables where the host_name was part of the PK, need to drop the PK, and recreate it with the host_id
+ // TODO, include other tables.
+ String[] tablesWithHostNameInPK = new String[] {
+ CLUSTER_HOST_MAPPING_TABLE,
+ HOST_COMPONENT_STATE_TABLE,
+ HOST_COMPONENT_DESIRED_STATE_TABLE,
+ HOST_STATE_TABLE
+ };
+
+ if (databaseType == Configuration.DatabaseType.DERBY) {
+ for (String tableName : tablesWithHostNameInPK) {
+ String constraintName = getDerbyTableConstraintName("p", tableName);
+ if (null != constraintName) {
+ dbAccessor.executeQuery("ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName);
+ }
+ }
+ } else {
+
+ dbAccessor.dropConstraint(CLUSTER_HOST_MAPPING_TABLE, "clusterhostmapping_pkey");
+ dbAccessor.dropConstraint(HOST_COMPONENT_STATE_TABLE, "hostcomponentstate_pkey");
+ dbAccessor.dropConstraint(HOST_COMPONENT_DESIRED_STATE_TABLE, "hostcomponentdesiredstate_pkey");
+ dbAccessor.dropConstraint(HOST_STATE_TABLE, "hoststate_pkey");
+ // TODO, include other tables.
+ }
+ dbAccessor.executeQuery("ALTER TABLE " + CLUSTER_HOST_MAPPING_TABLE +
+ " ADD CONSTRAINT clusterhostmapping_pkey PRIMARY KEY (cluster_id, host_id)");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_COMPONENT_STATE_TABLE +
+ " ADD CONSTRAINT hostcomponentstate_pkey PRIMARY KEY (cluster_id, component_name, host_id, service_name)");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_COMPONENT_DESIRED_STATE_TABLE +
+ " ADD CONSTRAINT hostcomponentdesiredstate_pkey PRIMARY KEY (cluster_id, component_name, host_id, service_name)");
+ dbAccessor.executeQuery("ALTER TABLE " + HOST_STATE_TABLE +
+ " ADD CONSTRAINT hoststate_pkey PRIMARY KEY (host_id)");
+ // TODO, include other tables.
+
+ // Finish by deleting the unnecessary host_name columns.
+ dbAccessor.dropColumn(CLUSTER_HOST_MAPPING_TABLE, "host_name");
+ dbAccessor.dropColumn(HOST_COMPONENT_STATE_TABLE, "host_name");
+ dbAccessor.dropColumn(HOST_COMPONENT_DESIRED_STATE_TABLE, "host_name");
+ dbAccessor.dropColumn(HOST_STATE_TABLE, "host_name");
+ // TODO, include other tables.
+
// view columns for cluster association
dbAccessor.addColumn(VIEW_INSTANCE_TABLE, new DBColumnInfo("cluster_handle", String.class, 255, null, true));
dbAccessor.addColumn(VIEW_PARAMETER_TABLE, new DBColumnInfo("cluster_config", String.class, 255, null, true));
@@ -300,7 +358,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
/**
* Populate the id of the hosts table with an auto-increment int.
- * @param resultSet Rows from the hosts table
+ * @param resultSet Rows from the hosts table, sorted first by host_id
* @return Returns an integer with the id for the next host record to be inserted.
* @throws SQLException
*/
@@ -310,10 +368,14 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
if (resultSet != null) {
try {
while (resultSet.next()) {
+ hostId++;
final String hostName = resultSet.getString(1);
- HostEntity host = hostDAO.findByName(hostName);
- host.setId(++hostId);
- hostDAO.merge(host);
+ Long currHostID = resultSet.getLong(2); // in case of a retry, may not be null
+
+ if (currHostID == null && StringUtils.isNotBlank(hostName)) {
+ dbAccessor.executeQuery("UPDATE " + HOSTS_TABLE + " SET host_id = " + hostId +
+ " WHERE host_name = '" + hostName + "'");
+ }
}
} catch (Exception e) {
LOG.error("Unable to populate the id of the hosts. " + e.getMessage());
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 7593e07..3bfe959 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -102,15 +102,13 @@ CREATE TABLE hostcomponentdesiredstate (
component_name VARCHAR(255) NOT NULL,
desired_stack_version VARCHAR(255) NOT NULL,
desired_state VARCHAR(255) NOT NULL,
- host_name VARCHAR(255) NOT NULL,
- -- host_id BIGINT NOT NULL,
+ host_id BIGINT NOT NULL,
service_name VARCHAR(255) NOT NULL,
admin_state VARCHAR(32),
maintenance_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE',
security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED',
restart_required TINYINT(1) NOT NULL DEFAULT 0,
- PRIMARY KEY (cluster_id, component_name, host_name, service_name));
- -- PRIMARY KEY (cluster_id, component_name, host_id, service_name));
+ PRIMARY KEY (cluster_id, component_name, host_id, service_name));
CREATE TABLE hostcomponentstate (
cluster_id BIGINT NOT NULL,
@@ -118,16 +116,14 @@ CREATE TABLE hostcomponentstate (
version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN',
current_stack_version VARCHAR(255) NOT NULL,
current_state VARCHAR(255) NOT NULL,
- host_name VARCHAR(255) NOT NULL,
- -- host_id BIGINT 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',
- PRIMARY KEY (cluster_id, component_name, host_name, service_name));
- -- PRIMARY KEY (cluster_id, component_name, host_id, service_name));
+ PRIMARY KEY (cluster_id, component_name, host_id, service_name));
CREATE TABLE hosts (
- id BIGINT NOT NULL,
+ host_id BIGINT NOT NULL,
host_name VARCHAR(255) NOT NULL,
cpu_count INTEGER NOT NULL,
cpu_info VARCHAR(255) NOT NULL,
@@ -143,19 +139,17 @@ CREATE TABLE hosts (
public_host_name VARCHAR(255),
rack_info VARCHAR(255) NOT NULL,
total_mem BIGINT NOT NULL,
- PRIMARY KEY (id));
+ PRIMARY KEY (host_id));
CREATE TABLE hoststate (
agent_version VARCHAR(255) NOT NULL,
available_mem BIGINT NOT NULL,
current_state VARCHAR(255) NOT NULL,
health_status VARCHAR(255),
- host_name VARCHAR(255) NOT NULL,
- -- host_id BIGINT NOT NULL,
+ host_id BIGINT NOT NULL,
time_in_state BIGINT NOT NULL,
maintenance_state VARCHAR(512),
- PRIMARY KEY (host_name));
- -- PRIMARY KEY (host_id));
+ PRIMARY KEY (host_id));
CREATE TABLE host_version (
id BIGINT NOT NULL,
@@ -601,31 +595,28 @@ ALTER TABLE clusterconfigmapping ADD CONSTRAINT clusterconfigmappingcluster_id F
ALTER TABLE clusterstate ADD CONSTRAINT FK_clusterstate_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
ALTER TABLE cluster_version ADD CONSTRAINT FK_cluster_version_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
ALTER TABLE cluster_version ADD CONSTRAINT FK_cluster_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES repo_version (repo_version_id);
-ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstname FOREIGN KEY (host_name) REFERENCES hosts (host_name);
--- ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstid FOREIGN KEY (host_id) REFERENCES hosts (id);
+ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT FK_hostcomponentdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
ALTER TABLE hostcomponentstate ADD CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
-ALTER TABLE hostcomponentstate ADD CONSTRAINT hostcomponentstate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
--- ALTER TABLE hostcomponentstate ADD CONSTRAINT hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
-ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
--- ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+ALTER TABLE hostcomponentstate ADD CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
+ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
--- ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+-- ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE host_version ADD CONSTRAINT FK_host_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES repo_version (repo_version_id);
ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
ALTER TABLE servicedesiredstate ADD CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
ALTER TABLE execution_command ADD CONSTRAINT FK_execution_command_task_id FOREIGN KEY (task_id) REFERENCES host_role_command (task_id);
ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id);
ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
--- ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+-- ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE role_success_criteria ADD CONSTRAINT role_success_criteria_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id);
ALTER TABLE stage ADD CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id);
ALTER TABLE request ADD CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id);
ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
-ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
--- ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+-- ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE serviceconfigmapping ADD CONSTRAINT FK_scvm_scv FOREIGN KEY (service_config_id) REFERENCES serviceconfig(service_config_id);
ALTER TABLE serviceconfigmapping ADD CONSTRAINT FK_scvm_config FOREIGN KEY (config_id) REFERENCES clusterconfig(config_id);
ALTER TABLE serviceconfighosts ADD CONSTRAINT FK_scvhosts_scv FOREIGN KEY (service_config_id) REFERENCES serviceconfig(service_config_id);
@@ -634,7 +625,7 @@ ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_confg FOREIGN KEY (c
ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_cgccm_gid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id);
ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_cgid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id);
ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_hname FOREIGN KEY (host_name) REFERENCES hosts (host_name);
--- ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+-- ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE requestschedulebatchrequest ADD CONSTRAINT FK_rsbatchrequest_schedule_id FOREIGN KEY (schedule_id) REFERENCES requestschedule (schedule_id);
ALTER TABLE hostgroup ADD CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name);
ALTER TABLE hostgroup_component ADD CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup(blueprint_name, name);
@@ -679,7 +670,7 @@ CREATE TABLE kerberos_principal_host (
);
ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_hostname FOREIGN KEY (host_name) REFERENCES hosts (host_name) ON DELETE CASCADE;
--- ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (id) ON DELETE CASCADE;
+-- ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id) ON DELETE CASCADE;
ALTER TABLE kerberos_principal_host
ADD CONSTRAINT FK_krb_pr_host_principalname
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 0562bc6..807306f 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -91,15 +91,13 @@ CREATE TABLE hostcomponentdesiredstate (
component_name VARCHAR2(255) NOT NULL,
desired_stack_version VARCHAR2(255) NULL,
desired_state VARCHAR2(255) NOT NULL,
- host_name VARCHAR2(255) NOT NULL,
- --host_id NUMBER(19) NOT NULL,
+ host_id NUMBER(19) NOT NULL,
service_name VARCHAR2(255) NOT NULL,
admin_state VARCHAR2(32) NULL,
maintenance_state VARCHAR2(32) NOT NULL,
security_state VARCHAR2(32) DEFAULT 'UNSECURED' NOT NULL,
restart_required NUMBER(1) DEFAULT 0 NOT NULL,
- PRIMARY KEY (cluster_id, component_name, host_name, service_name));
- --PRIMARY KEY (cluster_id, component_name, host_id, service_name));
+ PRIMARY KEY (cluster_id, component_name, host_id, service_name));
CREATE TABLE hostcomponentstate (
cluster_id NUMBER(19) NOT NULL,
@@ -107,16 +105,14 @@ CREATE TABLE hostcomponentstate (
version VARCHAR2(32) DEFAULT 'UNKNOWN' NOT NULL,
current_stack_version VARCHAR2(255) NOT NULL,
current_state VARCHAR2(255) NOT NULL,
- host_name VARCHAR2(255) NOT NULL,
- --host_id NUMBER(19) 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,
- PRIMARY KEY (cluster_id, component_name, host_name, service_name));
- --PRIMARY KEY (cluster_id, component_name, host_id, service_name));
+ PRIMARY KEY (cluster_id, component_name, host_id, service_name));
CREATE TABLE hosts (
- id NUMBER(19) NOT NULL,
+ host_id NUMBER(19) NOT NULL,
host_name VARCHAR2(255) NOT NULL,
cpu_count INTEGER NOT NULL,
cpu_info VARCHAR2(255) NULL,
@@ -132,19 +128,17 @@ CREATE TABLE hosts (
public_host_name VARCHAR2(255) NULL,
rack_info VARCHAR2(255) NOT NULL,
total_mem INTEGER NOT NULL,
- PRIMARY KEY (id));
+ PRIMARY KEY (host_id));
CREATE TABLE hoststate (
agent_version VARCHAR2(255) NULL,
available_mem NUMBER(19) NOT NULL,
current_state VARCHAR2(255) NOT NULL,
health_status VARCHAR2(255) NULL,
- host_name VARCHAR2(255) NOT NULL,
- --host_id NUMBER(19) NOT NULL,
+ host_id NUMBER(19) NOT NULL,
time_in_state NUMBER(19) NOT NULL,
maintenance_state VARCHAR2(512),
- PRIMARY KEY (host_name));
- --PRIMARY KEY (host_id));
+ PRIMARY KEY (host_id));
CREATE TABLE host_version (
id NUMBER(19) NOT NULL,
@@ -590,31 +584,28 @@ ALTER TABLE clusterconfigmapping ADD CONSTRAINT clusterconfigmappingcluster_id F
ALTER TABLE clusterstate ADD CONSTRAINT FK_clusterstate_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
ALTER TABLE cluster_version ADD CONSTRAINT FK_cluster_version_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
ALTER TABLE cluster_version ADD CONSTRAINT FK_cluster_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES repo_version (repo_version_id);
-ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstname FOREIGN KEY (host_name) REFERENCES hosts (host_name);
---ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstid FOREIGN KEY (host_id) REFERENCES hosts (id);
+ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT FK_hostcomponentdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
ALTER TABLE hostcomponentstate ADD CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
-ALTER TABLE hostcomponentstate ADD CONSTRAINT hostcomponentstate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
---ALTER TABLE hostcomponentstate ADD CONSTRAINT hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
-ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
---ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+ALTER TABLE hostcomponentstate ADD CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
+ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
---ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+--ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE host_version ADD CONSTRAINT FK_host_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES repo_version (repo_version_id);
ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
ALTER TABLE servicedesiredstate ADD CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
ALTER TABLE execution_command ADD CONSTRAINT FK_execution_command_task_id FOREIGN KEY (task_id) REFERENCES host_role_command (task_id);
ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id);
ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
---ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+--ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE role_success_criteria ADD CONSTRAINT role_success_criteria_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id);
ALTER TABLE stage ADD CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id);
ALTER TABLE request ADD CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id);
ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
-ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
---ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+--ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE serviceconfigmapping ADD CONSTRAINT FK_scvm_scv FOREIGN KEY (service_config_id) REFERENCES serviceconfig(service_config_id);
ALTER TABLE serviceconfigmapping ADD CONSTRAINT FK_scvm_config FOREIGN KEY (config_id) REFERENCES clusterconfig(config_id);
ALTER TABLE configgroup ADD CONSTRAINT FK_configgroup_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
@@ -622,7 +613,7 @@ ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_confg FOREIGN KEY (v
ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_cgccm_gid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id);
ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_cgid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id);
ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_hname FOREIGN KEY (host_name) REFERENCES hosts (host_name);
---ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES hosts (id);
+--ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
ALTER TABLE requestschedulebatchrequest ADD CONSTRAINT FK_rsbatchrequest_schedule_id FOREIGN KEY (schedule_id) REFERENCES requestschedule (schedule_id);
ALTER TABLE hostgroup ADD CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name);
ALTER TABLE hostgroup_component ADD CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup(blueprint_name, name);
@@ -669,7 +660,7 @@ CREATE TABLE kerberos_principal_host (
ALTER TABLE kerberos_principal_host
ADD CONSTRAINT FK_krb_pr_host_hostname
FOREIGN KEY (host_name) REFERENCES hosts (host_name) ON DELETE CASCADE;
---ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (id) ON DELETE CASCADE;
+--ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id) ON DELETE CASCADE;
ALTER TABLE kerberos_principal_host
ADD CONSTRAINT FK_krb_pr_host_principalname