You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2016/06/23 02:08:39 UTC
[2/2] ambari git commit: AMBARI-17371 - Unable To Delete A Service
After Upgrade Due To Foreign Key Violation (jonathanhurley)
AMBARI-17371 - Unable To Delete A Service After Upgrade Due To Foreign Key Violation (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e22b3d41
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e22b3d41
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e22b3d41
Branch: refs/heads/trunk
Commit: e22b3d41f2be33057f5c1b06a9a23a65ba033bff
Parents: 91b39b0
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed Jun 22 11:30:28 2016 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Wed Jun 22 22:08:24 2016 -0400
----------------------------------------------------------------------
.../ServiceComponentDesiredStateEntity.java | 9 +--
.../entities/ServiceComponentHistoryEntity.java | 66 +++++---------------
.../upgrades/FinalizeUpgradeAction.java | 7 ++-
.../server/state/ServiceComponentTest.java | 23 +++++--
4 files changed, 40 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e22b3d41/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
index 7281c01..61c053d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
@@ -114,7 +114,7 @@ public class ServiceComponentDesiredStateEntity {
*/
@OneToMany(
mappedBy = "m_serviceComponentDesiredStateEntity",
- cascade = { CascadeType.MERGE, CascadeType.REFRESH, CascadeType.REMOVE })
+ cascade = { CascadeType.ALL })
private Collection<ServiceComponentHistoryEntity> serviceComponentHistory;
public Long getId() {
@@ -171,7 +171,7 @@ public class ServiceComponentDesiredStateEntity {
/**
* Adds a historical entry for the version of this service component. New
- * entries are automatically created when this entities is merged via a
+ * entries are automatically created when this entity is merged via a
* {@link CascadeType#MERGE}.
*
* @param historicalEntry
@@ -183,10 +183,7 @@ public class ServiceComponentDesiredStateEntity {
}
serviceComponentHistory.add(historicalEntry);
-
- if (!equals(historicalEntry.getServiceComponentDesiredState())) {
- historicalEntry.setServiceComponentDesiredState(this);
- }
+ historicalEntry.setServiceComponentDesiredState(this);
}
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/e22b3d41/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentHistoryEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentHistoryEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentHistoryEntity.java
index e7fef71..1521468 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentHistoryEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentHistoryEntity.java
@@ -30,7 +30,9 @@ import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
-import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+import com.google.common.base.Objects;
/**
* The {@link ServiceComponentHistoryEntity} class is used to represent an
@@ -86,10 +88,6 @@ public class ServiceComponentHistoryEntity {
*/
public void setServiceComponentDesiredState(ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity) {
m_serviceComponentDesiredStateEntity = serviceComponentDesiredStateEntity;
-
- if (!m_serviceComponentDesiredStateEntity.getHistory().contains(this)) {
- m_serviceComponentDesiredStateEntity.addHistory(this);
- }
}
/**
@@ -149,14 +147,12 @@ public class ServiceComponentHistoryEntity {
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ObjectUtils.hashCode(m_fromStack);
- result = prime * result + (int) (m_id ^ (m_id >>> 32));
- result = prime * result + ObjectUtils.hashCode(m_serviceComponentDesiredStateEntity);
- result = prime * result + ObjectUtils.hashCode(m_toStack);
- result = prime * result + ObjectUtils.hashCode(m_upgradeEntity);
- return result;
+ HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
+ hashCodeBuilder.append(m_fromStack);
+ hashCodeBuilder.append(m_toStack);
+ hashCodeBuilder.append(m_upgradeEntity);
+ hashCodeBuilder.append(m_serviceComponentDesiredStateEntity);
+ return hashCodeBuilder.toHashCode();
}
/**
@@ -176,44 +172,10 @@ public class ServiceComponentHistoryEntity {
return false;
}
- ServiceComponentHistoryEntity other = (ServiceComponentHistoryEntity) obj;
- if (m_fromStack == null) {
- if (other.m_fromStack != null) {
- return false;
- }
- } else if (!m_fromStack.equals(other.m_fromStack)) {
- return false;
- }
-
- if (m_id != other.m_id) {
- return false;
- }
-
- if (m_serviceComponentDesiredStateEntity == null) {
- if (other.m_serviceComponentDesiredStateEntity != null) {
- return false;
- }
- } else if (!m_serviceComponentDesiredStateEntity.equals(
- other.m_serviceComponentDesiredStateEntity)) {
- return false;
- }
-
- if (m_toStack == null) {
- if (other.m_toStack != null) {
- return false;
- }
- } else if (!m_toStack.equals(other.m_toStack)) {
- return false;
- }
-
- if (m_upgradeEntity == null) {
- if (other.m_upgradeEntity != null) {
- return false;
- }
- } else if (!m_upgradeEntity.equals(other.m_upgradeEntity)) {
- return false;
- }
-
- return true;
+ final ServiceComponentHistoryEntity other = (ServiceComponentHistoryEntity) obj;
+ return Objects.equal(m_fromStack, other.m_fromStack)
+ && Objects.equal(m_toStack, other.m_toStack)
+ && Objects.equal(m_upgradeEntity, other.m_upgradeEntity)
+ && Objects.equal(m_serviceComponentDesiredStateEntity, other.m_serviceComponentDesiredStateEntity);
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e22b3d41/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
index 9088c1c..a07d0e6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
@@ -513,17 +513,20 @@ public class FinalizeUpgradeAction extends AbstractServerAction {
for (Service service : cluster.getServices().values()) {
for (ServiceComponent serviceComponent : service.getServiceComponents().values()) {
if (serviceComponent.isVersionAdvertised()) {
+ // create the historical entry
ServiceComponentHistoryEntity historyEntity = new ServiceComponentHistoryEntity();
historyEntity.setUpgrade(upgradeEntity);
historyEntity.setFromStack(fromStack);
historyEntity.setToStack(toStack);
+ // get the service component
ServiceComponentDesiredStateEntity desiredStateEntity = serviceComponentDesiredStateDAO.findByName(
cluster.getClusterId(), serviceComponent.getServiceName(),
serviceComponent.getName());
- historyEntity.setServiceComponentDesiredState(desiredStateEntity);
- serviceComponentDesiredStateDAO.create(historyEntity);
+ // add the history to the component and save
+ desiredStateEntity.addHistory(historyEntity);
+ serviceComponentDesiredStateDAO.merge(desiredStateEntity);
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e22b3d41/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
index 6b00616..22cf302 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
@@ -397,13 +397,22 @@ public class ServiceComponentTest {
history.setFromStack(serviceComponentDesiredStateEntity.getDesiredStack());
history.setToStack(serviceComponentDesiredStateEntity.getDesiredStack());
history.setUpgrade(upgradeEntity);
- history.setServiceComponentDesiredState(serviceComponentDesiredStateEntity);
- history = serviceComponentDesiredStateDAO.merge(history);
+
+ serviceComponentDesiredStateEntity.addHistory(history);
+
+ serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.merge(
+ serviceComponentDesiredStateEntity);
serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(
cluster.getClusterId(), serviceName, componentName);
- Assert.assertEquals(history, serviceComponentDesiredStateEntity.getHistory().iterator().next());
+ assertEquals(1, serviceComponentDesiredStateEntity.getHistory().size());
+ ServiceComponentHistoryEntity persistedHistory = serviceComponentDesiredStateEntity.getHistory().iterator().next();
+
+ assertEquals(history.getFromStack(), persistedHistory.getFromStack());
+ assertEquals(history.getToStack(), persistedHistory.getFromStack());
+ assertEquals(history.getUpgrade(), persistedHistory.getUpgrade());
+ assertEquals(history.getServiceComponentDesiredState(), persistedHistory.getServiceComponentDesiredState());
}
@@ -508,12 +517,16 @@ public class ServiceComponentTest {
history.setToStack(serviceComponentDesiredStateEntity.getDesiredStack());
history.setUpgrade(upgradeEntity);
history.setServiceComponentDesiredState(serviceComponentDesiredStateEntity);
- history = serviceComponentDesiredStateDAO.merge(history);
+
+ serviceComponentDesiredStateEntity.addHistory(history);
+
+ serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.merge(
+ serviceComponentDesiredStateEntity);
serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(
cluster.getClusterId(), serviceName, componentName);
- Assert.assertEquals(history, serviceComponentDesiredStateEntity.getHistory().iterator().next());
+ assertEquals(1, serviceComponentDesiredStateEntity.getHistory().size());
// verify that we can retrieve the history directly
List<ServiceComponentHistoryEntity> componentHistoryList = serviceComponentDesiredStateDAO.findHistory(