Author: mahadev
Date: Wed Jan 23 21:10:41 2013
New Revision: 1437735
URL: http://svn.apache.org/viewvc?rev=1437735&view=rev
Log:
AMBARI-1250. Upgrade the posgres connector to 9.1. (mahadev)
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/pom.xml
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
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/ClusterServiceEntity.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.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/cluster/ClusterImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.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/state/ServiceTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Jan 23 21:10:41 2013
@@ -173,6 +173,9 @@ Trunk (unreleased changes):
directories that we get from the server (only for hadoop and its eco system)
and not all. (mahadev)
+ AMBARI-1250. Upgrade the posgres connector to 9.1.
+ (mahadev)
+
AMBARI-1.2.0 branch:
INCOMPATIBLE CHANGES
Modified: incubator/ambari/trunk/ambari-server/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/pom.xml?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/pom.xml (original)
+++ incubator/ambari/trunk/ambari-server/pom.xml Wed Jan 23 21:10:41 2013
@@ -531,7 +531,7 @@
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
- <version>8.3-603.jdbc4</version>
+ <version>9.1-901.jdbc4</version>
</dependency>
</dependencies>
<!--<reporting>
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
Wed Jan 23 21:10:41 2013
@@ -57,6 +57,7 @@ import org.apache.ambari.server.state.sv
import
org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
import
org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -2689,9 +2690,7 @@ public class AmbariManagementControllerI
@Override
public synchronized void deleteCluster(ClusterRequest request)
throws AmbariException {
- throw new AmbariException("Delete cluster not supported");
- /*
if (request.getClusterName() == null
|| request.getClusterName().isEmpty()) {
// FIXME throw correct error
@@ -2705,13 +2704,22 @@ public class AmbariManagementControllerI
// deleting whole cluster
clusters.deleteCluster(request.getClusterName());
}
- */
}
@Override
public RequestStatusResponse deleteServices(Set<ServiceRequest> request)
throws AmbariException {
- throw new AmbariException("Delete services not supported");
+
+ for (ServiceRequest serviceRequest : request) {
+ if (StringUtils.isEmpty(serviceRequest.getClusterName()) ||
StringUtils.isEmpty(serviceRequest.getServiceName())) {
+ // FIXME throw correct error
+ throw new AmbariException("invalid arguments");
+ } else {
+
clusters.getCluster(serviceRequest.getClusterName()).deleteService(serviceRequest.getServiceName());
+ }
+ }
+ return null;
+
}
@Override
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
Wed Jan 23 21:10:41 2013
@@ -108,4 +108,9 @@ public class ClusterDAO {
remove(findByName(clusterName));
}
+ @Transactional
+ public void removeByPK(long id) {
+ remove(findById(id));
+ }
+
}
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=1437735&r1=1437734&r2=1437735&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
Wed Jan 23 21:10:41 2013
@@ -169,7 +169,7 @@ public class ClusterEntity {
}
private Collection<ClusterConfigEntity> configEntities;
- @OneToMany(mappedBy = "clusterEntity")
+ @OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
public Collection<ClusterConfigEntity> getClusterConfigEntities() {
return configEntities;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
Wed Jan 23 21:10:41 2013
@@ -105,7 +105,7 @@ public class ClusterServiceEntity {
private ServiceDesiredStateEntity serviceDesiredStateEntity;
- @OneToOne(mappedBy = "clusterServiceEntity")
+ @OneToOne(mappedBy = "clusterServiceEntity", cascade = CascadeType.ALL)
public ServiceDesiredStateEntity getServiceDesiredStateEntity() {
return serviceDesiredStateEntity;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
Wed Jan 23 21:10:41 2013
@@ -158,7 +158,7 @@ public class HostComponentStateEntity {
private Collection<HostComponentConfigMappingEntity> configMappingEntities;
@OneToMany(mappedBy = "hostComponentStateEntity", cascade = CascadeType.ALL)
- public Collection<HostComponentConfigMappingEntity>
getHostComponentConfigMappingEntities() {
+ public Collection<HostComponentConfigMappingEntity>
getHostComponentConfigMappingEntities() {
return configMappingEntities;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
Wed Jan 23 21:10:41 2013
@@ -115,7 +115,11 @@ public class ServiceDesiredStateEntity {
private ClusterServiceEntity clusterServiceEntity;
@OneToOne
- @javax.persistence.JoinColumns({@javax.persistence.JoinColumn(name =
"cluster_id", referencedColumnName = "cluster_id", nullable = false),
@javax.persistence.JoinColumn(name = "service_name", referencedColumnName =
"service_name", nullable = false)})
+ @javax.persistence.JoinColumns(
+ {
+ @JoinColumn(name = "cluster_id", referencedColumnName =
"cluster_id", nullable = false),
+ @JoinColumn(name = "service_name", referencedColumnName =
"service_name", nullable = false)
+ })
public ClusterServiceEntity getClusterServiceEntity() {
return clusterServiceEntity;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
Wed Jan 23 21:10:41 2013
@@ -101,4 +101,6 @@ public interface Cluster {
public void deleteService(String serviceName) throws AmbariException;
public boolean canBeRemoved();
+
+ public void delete() throws AmbariException;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
Wed Jan 23 21:10:41 2013
@@ -42,7 +42,7 @@ public class ConfigImpl implements Confi
private String versionTag;
private Map<String, String> properties;
private ClusterConfigEntity entity;
-
+
@Inject
private ClusterDAO clusterDAO;
@Inject
@@ -111,7 +111,7 @@ public class ConfigImpl implements Confi
@Transactional
@Override
- public void persist() {
+ public synchronized void persist() {
ClusterEntity clusterEntity = clusterDAO.findById(cluster.getClusterId());
@@ -128,7 +128,7 @@ public class ConfigImpl implements Confi
clusterEntity.getClusterConfigEntities().add(entity);
clusterDAO.merge(clusterEntity);
cluster.refresh();
-
+
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
Wed Jan 23 21:10:41 2013
@@ -76,11 +76,12 @@ public interface Service {
*/
public boolean canBeRemoved();
- public void removeAllComponents() throws AmbariException;
+ public void deleteAllComponents() throws AmbariException;
public void deleteServiceComponent(String componentName)
throws AmbariException;
public boolean isClientOnlyService();
+ public void delete() throws AmbariException;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
Wed Jan 23 21:10:41 2013
@@ -75,11 +75,13 @@ public interface ServiceComponent {
public boolean canBeRemoved();
- public void removeAllServiceComponentHosts() throws AmbariException;
+ public void deleteAllServiceComponentHosts() throws AmbariException;
- public void removeServiceComponentHosts(String hostname)
+ public void deleteServiceComponentHosts(String hostname)
throws AmbariException;
ServiceComponentHost addServiceComponentHost(
String hostName) throws AmbariException;
+
+ public void delete() throws AmbariException;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
Wed Jan 23 21:10:41 2013
@@ -104,4 +104,6 @@ public interface ServiceComponentHost {
public void debugDump(StringBuilder sb);
public boolean canBeRemoved();
+
+ public void delete() throws AmbariException;
}
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=1437735&r1=1437734&r2=1437735&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
Wed Jan 23 21:10:41 2013
@@ -510,7 +510,8 @@ public class ServiceComponentImpl implem
}
@Override
- public synchronized void removeAllServiceComponentHosts()
+ @Transactional
+ public synchronized void deleteAllServiceComponentHosts()
throws AmbariException {
LOG.info("Deleting all servicecomponenthosts for component"
+ ", clusterName=" + getClusterName()
@@ -527,12 +528,16 @@ public class ServiceComponentImpl implem
+ ", hostname=" + sch.getHostName());
}
}
+
+ for (ServiceComponentHost serviceComponentHost : hostComponents.values()) {
+ serviceComponentHost.delete();
+ }
+
hostComponents.clear();
- // FIXME update DB
}
@Override
- public synchronized void removeServiceComponentHosts(String hostname)
+ public synchronized void deleteServiceComponentHosts(String hostname)
throws AmbariException {
ServiceComponentHost sch = getServiceComponentHost(hostname);
LOG.info("Deleting servicecomponenthost for cluster"
@@ -547,16 +552,39 @@ public class ServiceComponentImpl implem
+ ", componentName=" + getName()
+ ", hostname=" + sch.getHostName());
}
+ sch.delete();
hostComponents.remove(hostname);
- // FIXME update DB
}
@Override
public synchronized void deleteDesiredConfigs(Set<String> configTypes) {
+ componentConfigMappingDAO.removeByType(configTypes);
for (String configType : configTypes) {
desiredConfigs.remove(configType);
}
- componentConfigMappingDAO.removeByType(configTypes);
+ }
+
+ @Override
+ @Transactional
+ public synchronized void delete() throws AmbariException {
+ deleteAllServiceComponentHosts();
+
+ if (persisted) {
+ removeEntities();
+ persisted = false;
+ }
+
+ desiredConfigs.clear();
+ }
+
+ @Transactional
+ protected void removeEntities() throws AmbariException {
+ ServiceComponentDesiredStateEntityPK pk = new
ServiceComponentDesiredStateEntityPK();
+ pk.setClusterId(getClusterId());
+ pk.setComponentName(getName());
+ pk.setServiceName(getServiceName());
+
+ serviceComponentDesiredStateDAO.removeByPK(pk);
}
}
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=1437735&r1=1437734&r2=1437735&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
Wed Jan 23 21:10:41 2013
@@ -414,8 +414,10 @@ public class ServiceImpl implements Serv
serviceDesiredStateDAO.create(serviceDesiredStateEntity);
clusterEntity.getClusterServiceEntities().add(serviceEntity);
clusterDAO.merge(clusterEntity);
- serviceEntity = clusterServiceDAO.merge(serviceEntity);
- serviceDesiredStateEntity =
serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
+// serviceEntity =
+ clusterServiceDAO.merge(serviceEntity);
+// serviceDesiredStateEntity =
+ serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
}
@Transactional
@@ -463,7 +465,8 @@ public class ServiceImpl implements Serv
}
@Override
- public synchronized void removeAllComponents() throws AmbariException {
+ @Transactional
+ public synchronized void deleteAllComponents() throws AmbariException {
LOG.info("Deleting all components for service"
+ ", clusterName=" + cluster.getClusterName()
+ ", serviceName=" + getName());
@@ -477,11 +480,12 @@ public class ServiceImpl implements Serv
+ ", componentName=" + component.getName());
}
}
- for (ServiceComponent component : components.values()) {
- component.removeAllServiceComponentHosts();
+
+ for (ServiceComponent serviceComponent : components.values()) {
+ serviceComponent.delete();
}
+
components.clear();
- // FIXME update DB
}
@Override
@@ -499,9 +503,9 @@ public class ServiceImpl implements Serv
+ ", serviceName=" + getName()
+ ", componentName=" + componentName);
}
- component.removeAllServiceComponentHosts();
+
+ component.delete();
components.remove(componentName);
- // FIXME update DB
}
@Override
@@ -509,4 +513,26 @@ public class ServiceImpl implements Serv
return isClientOnlyService;
}
+ @Override
+ @Transactional
+ public synchronized void delete() throws AmbariException {
+ deleteAllComponents();
+
+ if (persisted) {
+ removeEntities();
+ persisted = false;
+ }
+
+ desiredConfigs.clear();
+ }
+
+ @Transactional
+ protected void removeEntities() throws AmbariException {
+ ClusterServiceEntityPK pk = new ClusterServiceEntityPK();
+ pk.setClusterId(getClusterId());
+ pk.setServiceName(getName());
+
+ clusterServiceDAO.removeByPK(pk);
+ }
+
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
Wed Jan 23 21:10:41 2013
@@ -434,6 +434,7 @@ public class ClusterImpl implements Clus
}
@Override
+ @Transactional
public synchronized void deleteAllServices() throws AmbariException {
loadServices();
LOG.info("Deleting all services for cluster"
@@ -446,11 +447,12 @@ public class ClusterImpl implements Clus
+ ", serviceName=" + service.getName());
}
}
+
for (Service service : services.values()) {
- service.removeAllComponents();
+ service.delete();
}
+
services.clear();
- // FIXME update DB
}
@Override
@@ -467,9 +469,8 @@ public class ClusterImpl implements Clus
+ ", clusterName=" + getClusterName()
+ ", serviceName=" + service.getName());
}
- service.removeAllComponents();
+ service.delete();
services.remove(serviceName);
- // FIXME update DB
}
@Override
@@ -486,4 +487,17 @@ public class ClusterImpl implements Clus
}
return safeToRemove;
}
+
+ @Override
+ @Transactional
+ public void delete() throws AmbariException {
+ deleteAllServices();
+ removeEntities();
+ configs.clear();
+ }
+
+ @Transactional
+ protected void removeEntities() throws AmbariException {
+ clusterDAO.removeByPK(getClusterId());
+ }
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
Wed Jan 23 21:10:41 2013
@@ -360,7 +360,6 @@ public class ClustersImpl implements Clu
}
@Override
- @Transactional
public synchronized void deleteCluster(String clusterName)
throws AmbariException {
Cluster cluster = getCluster(clusterName);
@@ -368,9 +367,15 @@ public class ClustersImpl implements Clu
throw new AmbariException("Could not delete cluster"
+ ", clusterName=" + clusterName);
}
- cluster.deleteAllServices();
+ LOG.info("Deleting cluster "+ cluster.getClusterName());
+ cluster.delete();
+
+ //clear maps
+ for (Set<Cluster> clusterSet : hostClusterMap.values()) {
+ clusterSet.remove(cluster);
+ }
+ clusterHostMap.remove(cluster.getClusterName());
clusters.remove(clusterName);
- // FIXME update DB
}
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
Wed Jan 23 21:10:41 2013
@@ -213,7 +213,7 @@ public class HostImpl implements Host {
}
-// //TODO remove
+// //TODO delete
// public HostImpl(String hostname) {
// this.stateMachine = stateMachineFactory.make(this);
// ReadWriteLock rwLock = new ReentrantReadWriteLock();
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=1437735&r1=1437734&r2=1437735&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
Wed Jan 23 21:10:41 2013
@@ -1228,13 +1228,47 @@ public class ServiceComponentHostImpl im
public void deleteDesiredConfigs(Set<String> configTypes) {
try {
writeLock.lock();
+ hostComponentDesiredConfigMappingDAO.removeByType(configTypes);
for (String configType : configTypes) {
desiredConfigs.remove(configType);
}
- hostComponentDesiredConfigMappingDAO.removeByType(configTypes);
} finally {
writeLock.unlock();
}
}
+ @Override
+ public void delete() throws AmbariException {
+ try {
+ writeLock.lock();
+ if (persisted) {
+ removeEntities();
+ persisted = false;
+ }
+ desiredConfigs.clear();
+ } finally {
+ writeLock.unlock();
+ }
+
+ }
+
+ @Transactional
+ protected void removeEntities() {
+ HostComponentStateEntityPK pk = new HostComponentStateEntityPK();
+ pk.setClusterId(stateEntity.getClusterId());
+ pk.setComponentName(stateEntity.getComponentName());
+ pk.setServiceName(stateEntity.getServiceName());
+ pk.setHostName(stateEntity.getHostName());
+
+ hostComponentStateDAO.removeByPK(pk);
+
+ HostComponentDesiredStateEntityPK desiredPK = new
HostComponentDesiredStateEntityPK();
+ desiredPK.setClusterId(desiredStateEntity.getClusterId());
+ desiredPK.setComponentName(desiredStateEntity.getComponentName());
+ desiredPK.setServiceName(desiredStateEntity.getServiceName());
+ desiredPK.setHostName(desiredStateEntity.getHostName());
+
+ hostComponentDesiredStateDAO.removeByPK(desiredPK);
+ }
+
}
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=1437735&r1=1437734&r2=1437735&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
Wed Jan 23 21:10:41 2013
@@ -18,8 +18,6 @@
package org.apache.ambari.server.state;
-import static org.junit.Assert.fail;
-
import java.util.HashMap;
import java.util.Map;
@@ -38,6 +36,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.*;
+
public class ServiceTest {
private Clusters clusters;
@@ -224,4 +224,32 @@ public class ServiceTest {
}
+ @Test
+ public void testDeleteServiceComponent() throws Exception {
+ Service hdfs = cluster.addService("HDFS");
+ Service mapReduce = cluster.addService("MAPREDUCE");
+
+ hdfs.persist();
+
+ ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
+ nameNode.persist();
+ ServiceComponent jobTracker = mapReduce.addServiceComponent("JOBTRACKER");
+
+ assertEquals(2, cluster.getServices().size());
+ assertEquals(1, hdfs.getServiceComponents().size());
+ assertEquals(1, mapReduce.getServiceComponents().size());
+ assertTrue(hdfs.isPersisted());
+ assertFalse(mapReduce.isPersisted());
+
+ hdfs.deleteServiceComponent("NAMENODE");
+
+ assertEquals(0, hdfs.getServiceComponents().size());
+ assertEquals(1, mapReduce.getServiceComponents().size());
+
+ mapReduce.deleteServiceComponent("JOBTRACKER");
+
+ assertEquals(0, hdfs.getServiceComponents().size());
+ assertEquals(0, mapReduce.getServiceComponents().size());
+
+ }
}
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
Wed Jan 23 21:10:41 2013
@@ -18,6 +18,8 @@
package org.apache.ambari.server.state.cluster;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@@ -36,6 +38,7 @@ import org.apache.ambari.server.api.serv
import org.apache.ambari.server.controller.ClusterResponse;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
import org.apache.ambari.server.state.AgentVersion;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
@@ -59,6 +62,8 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
+import javax.persistence.EntityManager;
+
public class ClusterTest {
private Clusters clusters;
@@ -290,4 +295,24 @@ public class ClusterTest {
c1.debugDump(sb);
}
+ @Test
+ public void testDeleteService() throws Exception {
+ c1.addService("MAPREDUCE").persist();
+
+ Service hdfs = c1.addService("HDFS");
+ hdfs.persist();
+ ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
+ nameNode.persist();
+
+
+ assertEquals(2, c1.getServices().size());
+ assertEquals(2, injector.getProvider(EntityManager.class).get().
+ createQuery("SELECT service FROM ClusterServiceEntity
service").getResultList().size());
+
+ c1.deleteService("HDFS");
+
+ assertEquals(1, c1.getServices().size());
+ assertEquals(1, injector.getProvider(EntityManager.class).get().
+ createQuery("SELECT service FROM ClusterServiceEntity
service").getResultList().size());
+ }
}
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java?rev=1437735&r1=1437734&r2=1437735&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
Wed Jan 23 21:10:41 2013
@@ -18,12 +18,7 @@
package org.apache.ambari.server.state.cluster;
-import static org.junit.Assert.fail;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import com.google.inject.Guice;
import com.google.inject.Inject;
@@ -38,14 +33,18 @@ import org.apache.ambari.server.HostNotF
import org.apache.ambari.server.api.services.AmbariMetaInfo;
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.Host;
-import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.orm.dao.*;
+import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK;
+import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK;
+import org.apache.ambari.server.state.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import javax.persistence.EntityManager;
+
+import static org.junit.Assert.*;
+
public class ClustersTest {
private Clusters clusters;
@@ -270,4 +269,80 @@ public class ClustersTest {
// TODO verify dump output?
}
+ @Test
+ public void testDeleteCluster() throws Exception {
+ String c1 = "c1";
+ final String h1 = "h1";
+ final String h2 = "h2";
+
+ clusters.addCluster(c1);
+
+ Cluster cluster = clusters.getCluster(c1);
+ cluster.setDesiredStackVersion(new StackId("HDP-0.1"));
+
+ Config config =
injector.getInstance(ConfigFactory.class).createNew(cluster, "t1", new
HashMap<String, String>() {{
+ put("prop1", "val1");
+ }});
+ config.setVersionTag("1");
+ config.persist();
+
+ clusters.addHost(h1);
+ clusters.addHost(h2);
+
+ Host host1 = clusters.getHost(h1);
+ host1.setOsType("centos5");
+ Host host2 = clusters.getHost(h2);
+ host2.setOsType("centos5");
+ host1.persist();
+ host2.persist();
+
+ clusters.mapHostsToCluster(new HashSet<String>() {
+ {
+ addAll(Arrays.asList(h1, h2));
+ }
+ }, c1);
+
+
+ Service hdfs = cluster.addService("HDFS");
+ hdfs.persist();
+
+
assertNotNull(injector.getInstance(ClusterServiceDAO.class).findByClusterAndServiceNames(c1,
"HDFS"));
+
+ ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
+ nameNode.persist();
+ ServiceComponent dataNode = hdfs.addServiceComponent("DATANODE");
+ dataNode.persist();
+
+ ServiceComponentHost nameNodeHost = nameNode.addServiceComponentHost(h1);
+ nameNodeHost.persist();
+
+ ServiceComponentHost dataNodeHost = dataNode.addServiceComponentHost(h2);
+ dataNodeHost.persist();
+
+ HostComponentStateEntityPK hkspk = new HostComponentStateEntityPK();
+ HostComponentDesiredStateEntityPK hkdspk = new
HostComponentDesiredStateEntityPK();
+
+ hkspk.setClusterId(nameNodeHost.getClusterId());
+ hkspk.setHostName(nameNodeHost.getHostName());
+ hkspk.setServiceName(nameNodeHost.getServiceName());
+ hkspk.setComponentName(nameNodeHost.getServiceComponentName());
+
+ hkdspk.setClusterId(nameNodeHost.getClusterId());
+ hkdspk.setHostName(nameNodeHost.getHostName());
+ hkdspk.setServiceName(nameNodeHost.getServiceName());
+ hkdspk.setComponentName(nameNodeHost.getServiceComponentName());
+
+
assertNotNull(injector.getInstance(HostComponentStateDAO.class).findByPK(hkspk));
+
assertNotNull(injector.getInstance(HostComponentDesiredStateDAO.class).findByPK(hkdspk));
+ assertEquals(1,
injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM
ClusterConfigEntity config").getResultList().size());
+
+ clusters.deleteCluster(c1);
+
+ assertEquals(2, injector.getInstance(HostDAO.class).findAll().size());
+
assertNull(injector.getInstance(HostComponentStateDAO.class).findByPK(hkspk));
+
assertNull(injector.getInstance(HostComponentDesiredStateDAO.class).findByPK(hkdspk));
+ //configs are removed implicitly by cascade operation
+ assertEquals(0,
injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM
ClusterConfigEntity config").getResultList().size());
+
+ }
}