You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/01/15 03:04:55 UTC
[14/44] Revert "Merge remote-tracking branch 'origin/javelin' into
javelin"
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
index e55bef6..baaf391 100755
--- a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
+++ b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
@@ -35,10 +35,7 @@ import com.cloud.capacity.CapacityVO;
import com.cloud.storage.Storage;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.dao.StoragePoolDao;
-import com.cloud.storage.dao.StoragePoolDaoImpl;
import com.cloud.utils.Pair;
-import com.cloud.utils.StringUtils;
-import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@@ -60,116 +57,116 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART1 = "SELECT DISTINCT capacity.cluster_id FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster on (cluster.id = capacity.cluster_id AND cluster.removed is NULL) WHERE ";
private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2 = " AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " +
- "AND cluster_id IN (SELECT distinct cluster_id FROM `cloud`.`op_host_capacity` WHERE ";
+ "AND cluster_id IN (SELECT distinct cluster_id FROM `cloud`.`op_host_capacity` WHERE ";
private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3 = " AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) ";
-
+
private final SearchBuilder<CapacityVO> _hostIdTypeSearch;
- private final SearchBuilder<CapacityVO> _hostOrPoolIdSearch;
+ private final SearchBuilder<CapacityVO> _hostOrPoolIdSearch;
protected GenericSearchBuilder<CapacityVO, SummedCapacity> SummedCapacitySearch;
- private SearchBuilder<CapacityVO> _allFieldsSearch;
+ private final SearchBuilder<CapacityVO> _allFieldsSearch;
@Inject protected StoragePoolDao _storagePoolDao;
-
+
private static final String LIST_HOSTS_IN_CLUSTER_WITH_ENOUGH_CAPACITY = "SELECT a.host_id FROM (host JOIN op_host_capacity a ON host.id = a.host_id AND host.cluster_id = ? AND host.type = ? " +
- "AND (a.total_capacity * ? - a.used_capacity) >= ? and a.capacity_type = 1) " +
- "JOIN op_host_capacity b ON a.host_id = b.host_id AND b.total_capacity - b.used_capacity >= ? AND b.capacity_type = 0";
-
+ "AND (a.total_capacity * ? - a.used_capacity) >= ? and a.capacity_type = 1) " +
+ "JOIN op_host_capacity b ON a.host_id = b.host_id AND b.total_capacity - b.used_capacity >= ? AND b.capacity_type = 0";
+
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART1 = "SELECT cluster_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) FROM `cloud`.`op_host_capacity` WHERE " ;
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART2 = " AND capacity_type = ? GROUP BY cluster_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) ASC";
-
+
private static final String LIST_PODSINZONE_BY_HOST_CAPACITIES = "SELECT DISTINCT capacity.pod_id FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod " +
- " ON (pod.id = capacity.pod_id AND pod.removed is NULL) WHERE " +
- " capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " +
- " AND pod_id IN (SELECT distinct pod_id FROM `cloud`.`op_host_capacity` WHERE " +
- " capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) ";
+ " ON (pod.id = capacity.pod_id AND pod.removed is NULL) WHERE " +
+ " capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " +
+ " AND pod_id IN (SELECT distinct pod_id FROM `cloud`.`op_host_capacity` WHERE " +
+ " capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) ";
private static final String ORDER_PODS_BY_AGGREGATE_CAPACITY = "SELECT pod_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) FROM `cloud`.`op_host_capacity` WHERE data_center_id = ? " +
- " AND capacity_type = ? GROUP BY pod_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) ASC";
-
+ " AND capacity_type = ? GROUP BY pod_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) ASC";
+
private static final String LIST_CAPACITY_BY_RESOURCE_STATE = "SELECT capacity.data_center_id, sum(capacity.used_capacity), sum(capacity.reserved_quantity), sum(capacity.total_capacity), capacity_capacity_type "+
- "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`data_center` dc ON (dc.id = capacity.data_center_id AND dc.removed is NULL)"+
- "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod ON (pod.id = capacity.pod_id AND pod.removed is NULL)"+
- "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster ON (cluster.id = capacity.cluster_id AND cluster.removed is NULL)"+
- "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host` host ON (host.id = capacity.host_id AND host.removed is NULL)"+
- "WHERE dc.allocation_state = ? AND pod.allocation_state = ? AND cluster.allocation_state = ? AND host.resource_state = ? AND capacity_type not in (3,4) ";
-
+ "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`data_center` dc ON (dc.id = capacity.data_center_id AND dc.removed is NULL)"+
+ "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod ON (pod.id = capacity.pod_id AND pod.removed is NULL)"+
+ "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster ON (cluster.id = capacity.cluster_id AND cluster.removed is NULL)"+
+ "FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host` host ON (host.id = capacity.host_id AND host.removed is NULL)"+
+ "WHERE dc.allocation_state = ? AND pod.allocation_state = ? AND cluster.allocation_state = ? AND host.resource_state = ? AND capacity_type not in (3,4) ";
+
private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
- "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
- " capacity.capacity_type, capacity.data_center_id "+
- "FROM `cloud`.`op_host_capacity` capacity "+
- "WHERE total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled'";
+ "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
+ " capacity.capacity_type, capacity.data_center_id "+
+ "FROM `cloud`.`op_host_capacity` capacity "+
+ "WHERE total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled'";
private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2 = " GROUP BY data_center_id, capacity_type order by percent desc limit ";
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
- "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
- " capacity.capacity_type, capacity.data_center_id, pod_id "+
- "FROM `cloud`.`op_host_capacity` capacity "+
- "WHERE total_capacity > 0 AND pod_id is not null AND capacity_state='Enabled'";
+ "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
+ " capacity.capacity_type, capacity.data_center_id, pod_id "+
+ "FROM `cloud`.`op_host_capacity` capacity "+
+ "WHERE total_capacity > 0 AND pod_id is not null AND capacity_state='Enabled'";
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2 = " GROUP BY pod_id, capacity_type order by percent desc limit ";
-
+
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
- "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
- "capacity.capacity_type, capacity.data_center_id, pod_id, cluster_id "+
- "FROM `cloud`.`op_host_capacity` capacity "+
- "WHERE total_capacity > 0 AND cluster_id is not null AND capacity_state='Enabled'";
+ "((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
+ "capacity.capacity_type, capacity.data_center_id, pod_id, cluster_id "+
+ "FROM `cloud`.`op_host_capacity` capacity "+
+ "WHERE total_capacity > 0 AND cluster_id is not null AND capacity_state='Enabled'";
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2 = " GROUP BY cluster_id, capacity_type order by percent desc limit ";
private static final String UPDATE_CAPACITY_STATE = "UPDATE `cloud`.`op_host_capacity` SET capacity_state = ? WHERE ";
private static final String LIST_CLUSTERS_CROSSING_THRESHOLD = "SELECT cluster_id " +
- "FROM (SELECT cluster_id, ( (sum(capacity.used_capacity) + sum(capacity.reserved_capacity) + ?)/sum(total_capacity) ) ratio "+
- "FROM `cloud`.`op_host_capacity` capacity "+
- "WHERE capacity.data_center_id = ? AND capacity.capacity_type = ? AND capacity.total_capacity > 0 "+
- "GROUP BY cluster_id) tmp " +
- "WHERE tmp.ratio > ? ";
-
-
+ "FROM (SELECT cluster_id, ( (sum(capacity.used_capacity) + sum(capacity.reserved_capacity) + ?)/sum(total_capacity) ) ratio "+
+ "FROM `cloud`.`op_host_capacity` capacity "+
+ "WHERE capacity.data_center_id = ? AND capacity.capacity_type = ? AND capacity.total_capacity > 0 "+
+ "GROUP BY cluster_id) tmp " +
+ "WHERE tmp.ratio > ? ";
+
+
public CapacityDaoImpl() {
- _hostIdTypeSearch = createSearchBuilder();
- _hostIdTypeSearch.and("hostId", _hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
- _hostIdTypeSearch.and("type", _hostIdTypeSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
- _hostIdTypeSearch.done();
-
- _hostOrPoolIdSearch = createSearchBuilder();
- _hostOrPoolIdSearch.and("hostId", _hostOrPoolIdSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
- _hostOrPoolIdSearch.done();
-
- _allFieldsSearch = createSearchBuilder();
- _allFieldsSearch.and("id", _allFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
- _allFieldsSearch.and("hostId", _allFieldsSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
- _allFieldsSearch.and("zoneId", _allFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
- _allFieldsSearch.and("podId", _allFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ);
- _allFieldsSearch.and("clusterId", _allFieldsSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
- _allFieldsSearch.and("capacityType", _allFieldsSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
- _allFieldsSearch.and("capacityState", _allFieldsSearch.entity().getCapacityState(), SearchCriteria.Op.EQ);
-
- _allFieldsSearch.done();
+ _hostIdTypeSearch = createSearchBuilder();
+ _hostIdTypeSearch.and("hostId", _hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
+ _hostIdTypeSearch.and("type", _hostIdTypeSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
+ _hostIdTypeSearch.done();
+
+ _hostOrPoolIdSearch = createSearchBuilder();
+ _hostOrPoolIdSearch.and("hostId", _hostOrPoolIdSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
+ _hostOrPoolIdSearch.done();
+
+ _allFieldsSearch = createSearchBuilder();
+ _allFieldsSearch.and("id", _allFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
+ _allFieldsSearch.and("hostId", _allFieldsSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
+ _allFieldsSearch.and("zoneId", _allFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+ _allFieldsSearch.and("podId", _allFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ);
+ _allFieldsSearch.and("clusterId", _allFieldsSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
+ _allFieldsSearch.and("capacityType", _allFieldsSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
+ _allFieldsSearch.and("capacityState", _allFieldsSearch.entity().getCapacityState(), SearchCriteria.Op.EQ);
+
+ _allFieldsSearch.done();
}
-
+
@Override
public List<Long> listClustersCrossingThreshold(short capacityType, Long zoneId, Float disableThreshold, long compute_requested, Float overProvFactor){
-
- Transaction txn = Transaction.currentTxn();
- PreparedStatement pstmt = null;
- List<Long> result = new ArrayList<Long>();
- StringBuilder sql = new StringBuilder(LIST_CLUSTERS_CROSSING_THRESHOLD);
-
-
- try {
- pstmt = txn.prepareAutoCloseStatement(sql.toString());
- pstmt.setLong(1, compute_requested);
- pstmt.setLong(2, zoneId);
- pstmt.setShort(3, capacityType);
- pstmt.setFloat(4, disableThreshold*overProvFactor);
-
- ResultSet rs = pstmt.executeQuery();
- while (rs.next()) {
- result.add(rs.getLong(1));
- }
- return result;
- } catch (SQLException e) {
- throw new CloudRuntimeException("DB Exception on: " + sql, e);
- } catch (Throwable e) {
- throw new CloudRuntimeException("Caught: " + sql, e);
- }
- }
+
+ Transaction txn = Transaction.currentTxn();
+ PreparedStatement pstmt = null;
+ List<Long> result = new ArrayList<Long>();
+ StringBuilder sql = new StringBuilder(LIST_CLUSTERS_CROSSING_THRESHOLD);
+
+
+ try {
+ pstmt = txn.prepareAutoCloseStatement(sql.toString());
+ pstmt.setLong(1, compute_requested);
+ pstmt.setLong(2, zoneId);
+ pstmt.setShort(3, capacityType);
+ pstmt.setFloat(4, disableThreshold*overProvFactor);
+
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ result.add(rs.getLong(1));
+ }
+ return result;
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("DB Exception on: " + sql, e);
+ } catch (Throwable e) {
+ throw new CloudRuntimeException("Caught: " + sql, e);
+ }
+ }
/*public static String preparePlaceHolders(int length) {
StringBuilder builder = new StringBuilder();
@@ -188,17 +185,17 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
}
}*/
-
+
@Override
public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, String resource_state){
-
+
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
List<SummedCapacity> result = new ArrayList<SummedCapacity>();
StringBuilder sql = new StringBuilder(LIST_CAPACITY_BY_RESOURCE_STATE);
List<Long> resourceIdList = new ArrayList<Long>();
-
+
if (zoneId != null){
sql.append(" AND capacity.data_center_id = ?");
resourceIdList.add(zoneId);
@@ -237,29 +234,29 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
-
+
@Override
public List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit){
-
+
StringBuilder finalQuery = new StringBuilder();
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
List<SummedCapacity> result = new ArrayList<SummedCapacity>();
-
+
switch(level){
- case 1: // List all the capacities grouped by zone, capacity Type
- finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1);
- break;
-
- case 2: // List all the capacities grouped by pod, capacity Type
- finalQuery.append(LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1);
- break;
-
- case 3: // List all the capacities grouped by cluster, capacity Type
- finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1);
- break;
- }
-
+ case 1: // List all the capacities grouped by zone, capacity Type
+ finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1);
+ break;
+
+ case 2: // List all the capacities grouped by pod, capacity Type
+ finalQuery.append(LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1);
+ break;
+
+ case 3: // List all the capacities grouped by cluster, capacity Type
+ finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1);
+ break;
+ }
+
if (zoneId != null){
finalQuery.append(" AND data_center_id="+zoneId);
}
@@ -272,32 +269,32 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
if (capacityType != null){
finalQuery.append(" AND capacity_type="+capacityType);
}
-
+
switch(level){
case 1: // List all the capacities grouped by zone, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2);
break;
-
+
case 2: // List all the capacities grouped by pod, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2);
break;
-
+
case 3: // List all the capacities grouped by cluster, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2);
break;
}
-
+
finalQuery.append(limit.toString());
-
+
try {
pstmt = txn.prepareAutoCloseStatement(finalQuery.toString());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
SummedCapacity summedCapacity = new SummedCapacity( rs.getLong(1), rs.getLong(2), rs.getFloat(3),
- (short)rs.getLong(4), rs.getLong(5),
- level != 1 ? rs.getLong(6): null,
- level == 3 ? rs.getLong(7): null);
-
+ (short)rs.getLong(4), rs.getLong(5),
+ level != 1 ? rs.getLong(6): null,
+ level == 3 ? rs.getLong(7): null);
+
result.add(summedCapacity);
}
return result;
@@ -306,61 +303,61 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
} catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + finalQuery, e);
}
-
+
}
-
+
@Override
public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId){
-
- SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
- SummedCapacitySearch.select("dcId", Func.NATIVE, SummedCapacitySearch.entity().getDataCenterId());
+
+ SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
+ SummedCapacitySearch.select("dcId", Func.NATIVE, SummedCapacitySearch.entity().getDataCenterId());
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
SummedCapacitySearch.select("sumReserved", Func.SUM, SummedCapacitySearch.entity().getReservedCapacity());
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
SummedCapacitySearch.select("capacityType", Func.NATIVE, SummedCapacitySearch.entity().getCapacityType());
-
+
if (zoneId==null && podId==null && clusterId==null){ // List all the capacities grouped by zone, capacity Type
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getDataCenterId(), SummedCapacitySearch.entity().getCapacityType());
}else {
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getCapacityType());
}
-
+
if (zoneId != null){
- SummedCapacitySearch.and("dcId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
+ SummedCapacitySearch.and("dcId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
}
if (podId != null){
- SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
+ SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
}
if (clusterId != null){
- SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
+ SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
}
if (capacityType != null){
- SummedCapacitySearch.and("capacityType", SummedCapacitySearch.entity().getCapacityType(), Op.EQ);
+ SummedCapacitySearch.and("capacityType", SummedCapacitySearch.entity().getCapacityType(), Op.EQ);
}
SummedCapacitySearch.done();
-
-
+
+
SearchCriteria<SummedCapacity> sc = SummedCapacitySearch.create();
if (zoneId != null){
- sc.setParameters("dcId", zoneId);
+ sc.setParameters("dcId", zoneId);
}
if (podId != null){
- sc.setParameters("podId", podId);
+ sc.setParameters("podId", podId);
}
if (clusterId != null){
- sc.setParameters("clusterId", clusterId);
+ sc.setParameters("clusterId", clusterId);
}
if (capacityType != null){
- sc.setParameters("capacityType", capacityType);
+ sc.setParameters("capacityType", capacityType);
}
-
+
Filter filter = new Filter(CapacityVO.class, null, true, null, null);
List<SummedCapacity> results = customSearchIncludingRemoved(sc, filter);
return results;
-
+
}
-
+
public void updateAllocated(Long hostId, long allocatedAmount, short capacityType, boolean add) {
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
@@ -384,48 +381,48 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
}
}
-
+
@Override
public CapacityVO findByHostIdType(Long hostId, short capacityType) {
- SearchCriteria<CapacityVO> sc = _hostIdTypeSearch.create();
- sc.setParameters("hostId", hostId);
- sc.setParameters("type", capacityType);
- return findOneBy(sc);
+ SearchCriteria<CapacityVO> sc = _hostIdTypeSearch.create();
+ sc.setParameters("hostId", hostId);
+ sc.setParameters("type", capacityType);
+ return findOneBy(sc);
}
-
+
@Override
public List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor){
- Transaction txn = Transaction.currentTxn();
+ Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
StringBuilder sql = new StringBuilder(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART1);
-
+
if(isZone){
- sql.append("capacity.data_center_id = ?");
+ sql.append("capacity.data_center_id = ?");
}else{
- sql.append("capacity.pod_id = ?");
+ sql.append("capacity.pod_id = ?");
}
sql.append(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2);
if(isZone){
- sql.append("capacity.data_center_id = ?");
+ sql.append("capacity.data_center_id = ?");
}else{
- sql.append("capacity.pod_id = ?");
+ sql.append("capacity.pod_id = ?");
}
sql.append(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, id);
- pstmt.setShort(2, CapacityVO.CAPACITY_TYPE_CPU);
- pstmt.setFloat(3, cpuOverprovisioningFactor);
- pstmt.setLong(4, requiredCpu);
- pstmt.setLong(5, id);
- pstmt.setShort(6, CapacityVO.CAPACITY_TYPE_MEMORY);
- pstmt.setFloat(7, 1);
- pstmt.setLong(8, requiredRam);
-
- ResultSet rs = pstmt.executeQuery();
+ pstmt.setShort(2, CapacityVO.CAPACITY_TYPE_CPU);
+ pstmt.setFloat(3, cpuOverprovisioningFactor);
+ pstmt.setLong(4, requiredCpu);
+ pstmt.setLong(5, id);
+ pstmt.setShort(6, CapacityVO.CAPACITY_TYPE_MEMORY);
+ pstmt.setFloat(7, 1);
+ pstmt.setLong(8, requiredRam);
+
+ ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(rs.getLong(1));
}
@@ -436,11 +433,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
-
-
+
+
@Override
public List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor){
- Transaction txn = Transaction.currentTxn();
+ Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
@@ -448,11 +445,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, clusterId);
- pstmt.setString(2, hostType);
- pstmt.setFloat(3, cpuOverprovisioningFactor);
- pstmt.setLong(4, requiredCpu);
- pstmt.setLong(5, requiredRam);
-
+ pstmt.setString(2, hostType);
+ pstmt.setFloat(3, cpuOverprovisioningFactor);
+ pstmt.setLong(4, requiredCpu);
+ pstmt.setLong(5, requiredRam);
+
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(rs.getLong(1));
@@ -464,61 +461,61 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
-
- public static class SummedCapacity {
- public long sumUsed;
- public long sumReserved;
- public long sumTotal;
- public Float percentUsed;
- public short capacityType;
- public Long clusterId;
- public Long podId;
- public Long dcId;
- public SummedCapacity() {
- }
- public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
- short capacityType, Long clusterId, Long podId) {
- super();
- this.sumUsed = sumUsed;
- this.sumReserved = sumReserved;
- this.sumTotal = sumTotal;
- this.capacityType = capacityType;
- this.clusterId = clusterId;
- this.podId = podId;
- }
- public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
+
+ public static class SummedCapacity {
+ public long sumUsed;
+ public long sumReserved;
+ public long sumTotal;
+ public Float percentUsed;
+ public short capacityType;
+ public Long clusterId;
+ public Long podId;
+ public Long dcId;
+ public SummedCapacity() {
+ }
+ public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
+ short capacityType, Long clusterId, Long podId) {
+ super();
+ this.sumUsed = sumUsed;
+ this.sumReserved = sumReserved;
+ this.sumTotal = sumTotal;
+ this.capacityType = capacityType;
+ this.clusterId = clusterId;
+ this.podId = podId;
+ }
+ public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
short capacityType, Long clusterId, Long podId, Long zoneId) {
- this(sumUsed, sumReserved, sumTotal, capacityType, clusterId, podId);
- this.dcId = zoneId;
- }
-
- public SummedCapacity(long sumUsed, long sumTotal, float percentUsed, short capacityType, Long zoneId, Long podId, Long clusterId) {
- super();
- this.sumUsed = sumUsed;
- this.sumTotal = sumTotal;
- this.percentUsed = percentUsed;
- this.capacityType = capacityType;
+ this(sumUsed, sumReserved, sumTotal, capacityType, clusterId, podId);
+ this.dcId = zoneId;
+ }
+
+ public SummedCapacity(long sumUsed, long sumTotal, float percentUsed, short capacityType, Long zoneId, Long podId, Long clusterId) {
+ super();
+ this.sumUsed = sumUsed;
+ this.sumTotal = sumTotal;
+ this.percentUsed = percentUsed;
+ this.capacityType = capacityType;
this.clusterId = clusterId;
this.podId = podId;
this.dcId = zoneId;
}
-
- public Short getCapacityType() {
- return capacityType;
- }
- public Long getUsedCapacity() {
- return sumUsed;
- }
- public long getReservedCapacity() {
- return sumReserved;
- }
- public Long getTotalCapacity() {
- return sumTotal;
- }
- public Long getDataCenterId() {
+
+ public Short getCapacityType() {
+ return capacityType;
+ }
+ public Long getUsedCapacity() {
+ return sumUsed;
+ }
+ public long getReservedCapacity() {
+ return sumReserved;
+ }
+ public Long getTotalCapacity() {
+ return sumTotal;
+ }
+ public Long getDataCenterId() {
return dcId;
}
- public Long getClusterId() {
+ public Long getClusterId() {
return clusterId;
}
public Long getPodId() {
@@ -527,110 +524,111 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
public Float getPercentUsed() {
return percentUsed;
}
- }
- public List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId){
+ }
+ @Override
+ public List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId){
- SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
+ SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
SummedCapacitySearch.select("capacityType", Func.NATIVE, SummedCapacitySearch.entity().getCapacityType());
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getCapacityType());
-
+
if(zoneId != null){
- SummedCapacitySearch.and("zoneId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
+ SummedCapacitySearch.and("zoneId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
}
if (podId != null){
- SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
+ SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
}
if (clusterId != null){
- SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
+ SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
}
SummedCapacitySearch.done();
-
-
+
+
SearchCriteria<SummedCapacity> sc = SummedCapacitySearch.create();
if (zoneId != null){
- sc.setParameters("zoneId", zoneId);
+ sc.setParameters("zoneId", zoneId);
}
if (podId != null){
- sc.setParameters("podId", podId);
+ sc.setParameters("podId", podId);
}
if (clusterId != null){
- sc.setParameters("clusterId", clusterId);
+ sc.setParameters("clusterId", clusterId);
}
-
+
return customSearchIncludingRemoved(sc, null);
- }
-
- @Override
- public List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId, Long podId, Long clusterId){
+ }
+
+ @Override
+ public List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId, Long podId, Long clusterId){
- SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
+ SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
SummedCapacitySearch.select("capacityType", Func.NATIVE, SummedCapacitySearch.entity().getCapacityType());
SummedCapacitySearch.and("capacityType", SummedCapacitySearch.entity().getCapacityType(), Op.EQ);
-
- SearchBuilder<StoragePoolVO> nonSharedStorage = _storagePoolDao.createSearchBuilder();
- nonSharedStorage.and("poolTypes", nonSharedStorage.entity().getPoolType(), SearchCriteria.Op.IN);
- SummedCapacitySearch.join("nonSharedStorage", nonSharedStorage, nonSharedStorage.entity().getId(), SummedCapacitySearch.entity().getHostOrPoolId(), JoinType.INNER);
- nonSharedStorage.done();
-
+
+ SearchBuilder<StoragePoolVO> nonSharedStorage = _storagePoolDao.createSearchBuilder();
+ nonSharedStorage.and("poolTypes", nonSharedStorage.entity().getPoolType(), SearchCriteria.Op.IN);
+ SummedCapacitySearch.join("nonSharedStorage", nonSharedStorage, nonSharedStorage.entity().getId(), SummedCapacitySearch.entity().getHostOrPoolId(), JoinType.INNER);
+ nonSharedStorage.done();
+
if(zoneId != null){
- SummedCapacitySearch.and("zoneId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
+ SummedCapacitySearch.and("zoneId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
}
if (podId != null){
- SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
+ SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
}
if (clusterId != null){
- SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
+ SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
}
SummedCapacitySearch.done();
-
-
+
+
SearchCriteria<SummedCapacity> sc = SummedCapacitySearch.create();
sc.setJoinParameters("nonSharedStorage", "poolTypes", Storage.getNonSharedStoragePoolTypes().toArray());
sc.setParameters("capacityType", Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED);
if (zoneId != null){
- sc.setParameters("zoneId", zoneId);
+ sc.setParameters("zoneId", zoneId);
}
if (podId != null){
- sc.setParameters("podId", podId);
+ sc.setParameters("podId", podId);
}
if (clusterId != null){
- sc.setParameters("clusterId", clusterId);
+ sc.setParameters("clusterId", clusterId);
}
-
+
return customSearchIncludingRemoved(sc, null);
- }
-
+ }
+
@Override
public boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId, Long hostId) {
SearchCriteria<CapacityVO> sc = _allFieldsSearch.create();
-
+
if (capacityType != null) {
sc.setParameters("capacityType", capacityType);
}
-
+
if (zoneId != null) {
sc.setParameters("zoneId", zoneId);
}
-
+
if (podId != null) {
sc.setParameters("podId", podId);
}
-
+
if (clusterId != null) {
sc.setParameters("clusterId", clusterId);
}
-
+
if (hostId != null) {
sc.setParameters("hostId", hostId);
}
-
+
return remove(sc) > 0;
}
-
+
@Override
public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor){
Transaction txn = Transaction.currentTxn();
@@ -639,7 +637,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
Map<Long, Double> clusterCapacityMap = new HashMap<Long, Double>();
StringBuilder sql = new StringBuilder(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART1);
-
+
if(isZone){
sql.append("data_center_id = ?");
}else{
@@ -708,13 +706,13 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
Map<Long, Double> podCapacityMap = new HashMap<Long, Double>();
-
+
StringBuilder sql = new StringBuilder(ORDER_PODS_BY_AGGREGATE_CAPACITY);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(2, zoneId);
pstmt.setShort(3, capacityTypeForOrdering);
-
+
if(capacityTypeForOrdering == CapacityVO.CAPACITY_TYPE_CPU){
pstmt.setFloat(1, cpuOverprovisioningFactor);
pstmt.setFloat(4, cpuOverprovisioningFactor);
@@ -722,7 +720,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
pstmt.setFloat(1, 1);
pstmt.setFloat(4, 1);
}
-
+
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Long podId = rs.getLong(1);
@@ -736,13 +734,13 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
-
+
@Override
public void updateCapacityState(Long dcId, Long podId, Long clusterId, Long hostId, String capacityState) {
Transaction txn = Transaction.currentTxn();
StringBuilder sql = new StringBuilder(UPDATE_CAPACITY_STATE);
List<Long> resourceIdList = new ArrayList<Long>();
-
+
if (dcId != null){
sql.append(" data_center_id = ?");
resourceIdList.add(dcId);
@@ -759,7 +757,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
sql.append(" host_id = ?");
resourceIdList.add(hostId);
}
-
+
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/server/src/com/cloud/cluster/CheckPointManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/CheckPointManager.java b/server/src/com/cloud/cluster/CheckPointManager.java
deleted file mode 100644
index b6333e6..0000000
--- a/server/src/com/cloud/cluster/CheckPointManager.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-
-/**
- * TaskManager helps business logic deal with clustering failover.
- * Say you're writing code that introduces an inconsistent state over
- * of your operation? Who will come back to cleanup this state? TaskManager
- * with different content during your process. If the server dies, TaskManager
- * running elsewhere. If there are no clustered servers, then TaskManager will
- * cleanup when the dead server resumes.
- *
- */
-public interface CheckPointManager {
- /**
- * responsible for cleaning up.
- *
- * @param context context information to be stored.
- * @return Check point id.
- */
- long pushCheckPoint(CleanupMaid context);
-
- /**
- * update the task with new context
- * @param taskId
- * @param updatedContext new updated context.
- */
- void updateCheckPointState(long taskId, CleanupMaid updatedContext);
-
-
- /**
- * removes the task as it is completed.
- *
- * @param taskId
- */
- void popCheckPoint(long taskId);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/server/src/com/cloud/cluster/CheckPointManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/CheckPointManagerImpl.java b/server/src/com/cloud/cluster/CheckPointManagerImpl.java
deleted file mode 100644
index e02a2f0..0000000
--- a/server/src/com/cloud/cluster/CheckPointManagerImpl.java
+++ /dev/null
@@ -1,247 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.cluster.dao.StackMaidDao;
-import com.cloud.configuration.Config;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.serializer.SerializerHelper;
-import com.cloud.utils.DateUtil;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.Manager;
-import com.cloud.utils.concurrency.NamedThreadFactory;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.db.GlobalLock;
-
-@Component
-@Local(value=CheckPointManager.class)
-public class CheckPointManagerImpl implements CheckPointManager, Manager, ClusterManagerListener {
- private static final Logger s_logger = Logger.getLogger(CheckPointManagerImpl.class);
-
- private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds
- private int _cleanupRetryInterval;
-
- private String _name;
-
- @Inject
- private StackMaidDao _maidDao;
-
- @Inject
- private ClusterManager _clusterMgr;
-
- @Inject ConfigurationDao _configDao;
-
- long _msId;
-
- private final ScheduledExecutorService _cleanupScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Task-Cleanup"));
-
- protected CheckPointManagerImpl() {
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> xmlParams) throws ConfigurationException {
- _name = name;
-
- if (s_logger.isInfoEnabled()) {
- s_logger.info("Start configuring StackMaidManager : " + name);
- }
-
- StackMaid.init(ManagementServerNode.getManagementServerId());
- _msId = ManagementServerNode.getManagementServerId();
-
- _clusterMgr.registerListener(this);
-
- Map<String, String> params = _configDao.getConfiguration(xmlParams);
-
- _cleanupRetryInterval = NumbersUtil.parseInt(params.get(Config.TaskCleanupRetryInterval.key()), 600);
- _maidDao.takeover(_msId, _msId);
- return true;
- }
-
- private void cleanupLeftovers(List<CheckPointVO> l) {
- for (CheckPointVO maid : l) {
- if (StackMaid.doCleanup(maid)) {
- _maidDao.expunge(maid.getId());
- }
- }
- }
-
- @Override
- public void onManagementNodeIsolated() {
- }
-
- @DB
- private Runnable getGCTask() {
- return new Runnable() {
- @Override
- public void run() {
- GlobalLock scanLock = GlobalLock.getInternLock("StackMaidManagerGC");
- try {
- if (scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
- try {
- reallyRun();
- } finally {
- scanLock.unlock();
- }
- }
- } finally {
- scanLock.releaseRef();
- }
- }
-
- public void reallyRun() {
- try {
- Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - 7200000);
- List<CheckPointVO> l = _maidDao.listLeftoversByCutTime(cutTime);
- cleanupLeftovers(l);
- } catch (Throwable e) {
- s_logger.error("Unexpected exception when trying to execute queue item, ", e);
- }
- }
- };
- }
-
- @Override
- public boolean start() {
- _cleanupScheduler.schedule(new CleanupTask(), _cleanupRetryInterval > 0 ? _cleanupRetryInterval : 600, TimeUnit.SECONDS);
- return true;
- }
-
- @Override
- public boolean stop() {
- return true;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- @Override
- public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
- // Nothing to do
- }
-
- @Override
- public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
- for (ManagementServerHostVO node : nodeList) {
- if (_maidDao.takeover(node.getMsid(), selfNodeId)) {
- s_logger.info("Taking over from " + node.getMsid());
- _cleanupScheduler.execute(new CleanupTask());
- }
- }
- }
-
- @Override
- @DB
- public long pushCheckPoint(CleanupMaid context) {
- long seq = _maidDao.pushCleanupDelegate(_msId, 0, context.getClass().getName(), context);
- return seq;
- }
-
- @Override
- @DB
- public void updateCheckPointState(long taskId, CleanupMaid updatedContext) {
- CheckPointVO task = _maidDao.createForUpdate();
- task.setDelegate(updatedContext.getClass().getName());
- task.setContext(SerializerHelper.toSerializedStringOld(updatedContext));
- _maidDao.update(taskId, task);
- }
-
- @Override
- @DB
- public void popCheckPoint(long taskId) {
- _maidDao.remove(taskId);
- }
-
- protected boolean cleanup(CheckPointVO task) {
- s_logger.info("Cleaning up " + task);
- CleanupMaid delegate = (CleanupMaid)SerializerHelper.fromSerializedString(task.getContext());
- assert delegate.getClass().getName().equals(task.getDelegate()) : "Deserializer says " + delegate.getClass().getName() + " but it's suppose to be " + task.getDelegate();
-
- int result = delegate.cleanup(this);
- if (result <= 0) {
- if (result == 0) {
- s_logger.info("Successfully cleaned up " + task.getId());
- } else {
- s_logger.warn("Unsuccessful in cleaning up " + task + ". Procedure to cleanup manaully: " + delegate.getCleanupProcedure());
- }
- popCheckPoint(task.getId());
- return true;
- } else {
- s_logger.error("Unable to cleanup " + task.getId());
- return false;
- }
- }
-
- class CleanupTask implements Runnable {
- private Date _curDate;
- public CleanupTask() {
- _curDate = new Date();
- }
-
- @Override
- public void run() {
- try {
- List<CheckPointVO> tasks = _maidDao.listLeftoversByCutTime(_curDate, _msId);
- tasks.addAll(_maidDao.listCleanupTasks(_msId));
-
- List<CheckPointVO> retries = new ArrayList<CheckPointVO>();
-
- for (CheckPointVO task : tasks) {
- try {
- if (!cleanup(task)) {
- retries.add(task);
- }
- } catch (Exception e) {
- s_logger.warn("Unable to clean up " + task, e);
-
- }
- }
-
- if (retries.size() > 0) {
- if (_cleanupRetryInterval > 0) {
- _cleanupScheduler.schedule(this, _cleanupRetryInterval, TimeUnit.SECONDS);
- } else {
- for (CheckPointVO task : retries) {
- s_logger.warn("Cleanup procedure for " + task + ": " + ((CleanupMaid)SerializerHelper.fromSerializedString(task.getContext())).getCleanupProcedure());
- }
- }
- }
-
- } catch (Exception e) {
- s_logger.error("Unable to cleanup all of the tasks for " + _msId, e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/server/src/com/cloud/cluster/CleanupMaid.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/CleanupMaid.java b/server/src/com/cloud/cluster/CleanupMaid.java
deleted file mode 100644
index 1ff83f1..0000000
--- a/server/src/com/cloud/cluster/CleanupMaid.java
+++ /dev/null
@@ -1,41 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.cluster;
-
-/**
- *
- * task. The state is serialized and stored. When cleanup is required
- * CleanupMaid is instantiated from the stored data and cleanup() is called.
- *
- */
-public interface CleanupMaid {
- /**
- * cleanup according the state that was stored.
- *
- * @return 0 indicates cleanup was successful. Negative number
- * indicates the cleanup was unsuccessful but don't retry. Positive number
- * indicates the cleanup was unsuccessful and retry in this many seconds.
- */
- int cleanup(CheckPointManager checkPointMgr);
-
-
- /**
- * returned here is recorded.
- * @return
- */
- String getCleanupProcedure();
-}