Author: mahadev
Date: Thu Jan 24 01:41:02 2013
New Revision: 1437832
URL: http://svn.apache.org/viewvc?rev=1437832&view=rev
Log:
AMBARI-1194. API support for cascade delete of a specified cluster (Tom
Beerbower via mahadev)
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/State.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Jan 24 01:41:02 2013
@@ -15,6 +15,9 @@ Trunk (unreleased changes):
AMBARI-1163. During agent registration and heartbeat, send information about
various hadoop artifacts back to Ambari. (Nate Cole via mahadev)
+ AMBARI-1194. API support for cascade delete of a specified cluster
+ (Tom Beerbower via mahadev)
+
IMPROVEMENTS
AMBARI-1236. Display a progress bar during deploy prep. (yusaku)
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
Thu Jan 24 01:41:02 2013
@@ -159,7 +159,7 @@ public class ClusterEntity {
private Collection<StageEntity> stages;
- @OneToMany(mappedBy = "cluster")
+ @OneToMany(mappedBy = "cluster", cascade = CascadeType.REMOVE)
public Collection<StageEntity> getStages() {
return stages;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
Thu Jan 24 01:41:02 2013
@@ -245,7 +245,7 @@ public class HostRoleCommandEntity {
private ExecutionCommandEntity executionCommand;
- @OneToOne(mappedBy = "hostRoleCommand")
+ @OneToOne(mappedBy = "hostRoleCommand", cascade = CascadeType.REMOVE)
public ExecutionCommandEntity getExecutionCommand() {
return executionCommand;
}
@@ -277,4 +277,4 @@ public class HostRoleCommandEntity {
public void setHost(HostEntity host) {
this.host = host;
}
-}
\ No newline at end of file
+}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
Thu Jan 24 01:41:02 2013
@@ -111,7 +111,7 @@ public class StageEntity {
private Collection<HostRoleCommandEntity> hostRoleCommands;
- @OneToMany(mappedBy = "stage")
+ @OneToMany(mappedBy = "stage", cascade = CascadeType.REMOVE)
public Collection<HostRoleCommandEntity> getHostRoleCommands() {
return hostRoleCommands;
}
@@ -122,7 +122,7 @@ public class StageEntity {
private Collection<RoleSuccessCriteriaEntity> roleSuccessCriterias;
- @OneToMany(mappedBy = "stage")
+ @OneToMany(mappedBy = "stage", cascade = CascadeType.REMOVE)
public Collection<RoleSuccessCriteriaEntity> getRoleSuccessCriterias() {
return roleSuccessCriterias;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
Thu Jan 24 01:41:02 2013
@@ -487,26 +487,22 @@ public class ServiceComponentImpl implem
@Override
public synchronized boolean canBeRemoved() {
- State state = getDesiredState();
- if (state != State.INIT
- && state != State.UNINSTALLED) {
+ if (!getDesiredState().isRemovableState()) {
return false;
}
- boolean safeToRemove = true;
for (ServiceComponentHost sch : hostComponents.values()) {
if (!sch.canBeRemoved()) {
- safeToRemove = false;
LOG.warn("Found non removable hostcomponent when trying to"
+ " delete service component"
+ ", clusterName=" + getClusterName()
+ ", serviceName=" + getServiceName()
+ ", componentName=" + getName()
+ ", hostname=" + sch.getHostName());
- break;
+ return false;
}
}
- return safeToRemove;
+ return true;
}
@Override
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
Thu Jan 24 01:41:02 2013
@@ -444,24 +444,20 @@ public class ServiceImpl implements Serv
@Override
public synchronized boolean canBeRemoved() {
- State state = getDesiredState();
- if (state != State.INIT
- && state != State.UNINSTALLED) {
+ if (!getDesiredState().isRemovableState()) {
return false;
}
- boolean safeToRemove = true;
for (ServiceComponent sc : components.values()) {
if (!sc.canBeRemoved()) {
- safeToRemove = false;
LOG.warn("Found non removable component when trying to delete service"
+ ", clusterName=" + cluster.getClusterName()
+ ", serviceName=" + getName()
+ ", componentName=" + sc.getName());
- break;
+ return false;
}
}
- return safeToRemove;
+ return true;
}
@Override
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/State.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/State.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/State.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/State.java
Thu Jan 24 01:41:02 2013
@@ -121,4 +121,22 @@ public enum State {
}
}
+ /**
+ * Indicates whether or not the resource with this state
+ * can be removed.
+ *
+ * @return true if this is a removable state
+ */
+ public boolean isRemovableState() {
+ switch (State.values()[this.state]) {
+ case INIT:
+ case INSTALLING:
+ case INSTALLED:
+ case INSTALL_FAILED:
+ case UNINSTALLED:
+ return true;
+ default:
+ return false;
+ }
+ }
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
Thu Jan 24 01:41:02 2013
@@ -1212,16 +1212,13 @@ public class ServiceComponentHostImpl im
public synchronized boolean canBeRemoved() {
try {
readLock.lock();
- State desiredState = getDesiredState();
- State liveState = getState();
- if ((desiredState == State.INIT || desiredState == State.UNINSTALLED)
- && (liveState == State.INIT || liveState == State.UNINSTALLED)) {
- return true;
- }
+
+ return (getDesiredState().isRemovableState() &&
+ getState().isRemovableState());
+
} finally {
readLock.unlock();
}
- return false;
}
@Override
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
Thu Jan 24 01:41:02 2013
@@ -34,6 +34,7 @@ import org.apache.ambari.server.agent.Co
import org.apache.ambari.server.controller.HostsMap;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import
org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
import org.apache.ambari.server.utils.StageUtils;
@@ -157,4 +158,22 @@ public class TestActionManager {
stages.add(s);
db.persistActions(stages);
}
+
+ @Test
+ public void testCascadeDeleteStages() throws Exception {
+ ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class);
+ ActionManager am = injector.getInstance(ActionManager.class);
+ populateActionDB(db, hostname);
+ assertEquals(1, clusters.getClusters().size());
+
+ Cluster cluster = clusters.getCluster(clusterName);
+
+ assertEquals(1, am.getRequests().size());
+
+ clusters.deleteCluster(clusterName);
+
+ assertEquals(0, clusters.getClusters().size());
+ assertEquals(0, am.getRequests().size());
+
+ }
}
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
Thu Jan 24 01:41:02 2013
@@ -39,6 +39,7 @@ import org.apache.ambari.server.orm.enti
import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK;
import
org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
import
org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntityPK;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -308,4 +309,21 @@ public class ServiceComponentTest {
Assert.assertFalse(sb.toString().isEmpty());
}
+ @Test
+ public void testCanBeRemoved() throws Exception{
+ String componentName = "NAMENODE";
+ ServiceComponent component = serviceComponentFactory.createNew(service,
+ componentName);
+
+ for (State state : State.values()) {
+ component.setDesiredState(state);
+
+ if (state.isRemovableState()) {
+ org.junit.Assert.assertTrue(component.canBeRemoved());
+ }
+ else {
+ org.junit.Assert.assertFalse(component.canBeRemoved());
+ }
+ }
+ }
}
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
Thu Jan 24 01:41:02 2013
@@ -252,4 +252,31 @@ public class ServiceTest {
assertEquals(0, mapReduce.getServiceComponents().size());
}
+
+ @Test
+ public void testCanBeRemoved() throws Exception{
+ Service service = cluster.addService("HDFS");
+
+ for (State state : State.values()) {
+ service.setDesiredState(state);
+
+ if (state.isRemovableState()) {
+ org.junit.Assert.assertTrue(service.canBeRemoved());
+ }
+ else {
+ org.junit.Assert.assertFalse(service.canBeRemoved());
+ }
+ }
+
+ ServiceComponent component = service.addServiceComponent("NAMENODE");
+ // can't remove a STARTED component
+ component.setDesiredState(State.STARTED);
+
+ for (State state : State.values()) {
+ service.setDesiredState(state);
+ // should always be false if the sub component can not be removed
+ org.junit.Assert.assertFalse(service.canBeRemoved());
+ }
+ }
+
}
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java?rev=1437832&r1=1437831&r2=1437832&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
Thu Jan 24 01:41:02 2013
@@ -22,7 +22,9 @@ import static org.junit.Assert.fail;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import com.google.inject.Provider;
import org.apache.ambari.server.AmbariException;
@@ -655,4 +657,20 @@ public class ServiceComponentHostTest {
}
}
+ @Test
+ public void testCanBeRemoved() throws Exception{
+ ServiceComponentHostImpl impl = (ServiceComponentHostImpl)
+ createNewServiceComponentHost("HDFS", "HDFS_CLIENT", "h1", true);
+
+ for (State state : State.values()) {
+ impl.setState(state);
+
+ if (state.isRemovableState()) {
+ Assert.assertTrue(impl.canBeRemoved());
+ }
+ else {
+ Assert.assertFalse(impl.canBeRemoved());
+ }
+ }
+ }
}