cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DaanHoogland <...@git.apache.org>
Subject [GitHub] cloudstack pull request: CLOUDSTACK-9366: Capacity of one zone-wid...
Date Sat, 23 Apr 2016 10:14:35 GMT
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1516#discussion_r60826448
  
    --- Diff: engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java ---
    @@ -962,35 +962,58 @@ public boolean removeBy(Short capacityType, Long zoneId, Long podId,
Long cluste
         }
     
         @Override
    -    public void updateCapacityState(Long dcId, Long podId, Long clusterId, Long hostId,
String capacityState) {
    +    public void updateCapacityState(Long dcId, Long podId, Long clusterId, Long hostId,
String capacityState, short[] capacityType) {
             TransactionLegacy txn = TransactionLegacy.currentTxn();
             StringBuilder sql = new StringBuilder(UPDATE_CAPACITY_STATE);
             List<Long> resourceIdList = new ArrayList<Long>();
    +        StringBuilder where = new StringBuilder();
     
             if (dcId != null) {
    -            sql.append(" data_center_id = ?");
    +            where.append(" data_center_id = ? ");
                 resourceIdList.add(dcId);
             }
             if (podId != null) {
    -            sql.append(" pod_id = ?");
    +            where.append((where.length() > 0) ? " and pod_id = ? " : " pod_id = ?
");
                 resourceIdList.add(podId);
             }
             if (clusterId != null) {
    -            sql.append(" cluster_id = ?");
    +            where.append((where.length() > 0) ? " and cluster_id = ? " : " cluster_id
= ? ");
                 resourceIdList.add(clusterId);
             }
             if (hostId != null) {
    -            sql.append(" host_id = ?");
    +            where.append((where.length() > 0) ? " and host_id = ? " : " host_id =
? ");
                 resourceIdList.add(hostId);
             }
     
    +        if (capacityType != null) {
    +            where.append((where.length() > 0) ? " and capacity_type in " : " capacity_type
in ");
    +
    +            StringBuilder builder = new StringBuilder();
    +            for( int i = 0 ; i < capacityType.length; i++ ) {
    +                if(i==0){
    +                    builder.append(" (? ");
    +                }else{
    +                    builder.append(" ,? ");
    +                }
    +            }
    +            builder.append(" ) ");
    +
    +            where.append(builder);
    +        }
    +        sql.append(where);
    +
             PreparedStatement pstmt = null;
             try {
                 pstmt = txn.prepareAutoCloseStatement(sql.toString());
                 pstmt.setString(1, capacityState);
    -            for (int i = 0; i < resourceIdList.size(); i++) {
    +            int i = 0;
    +            for (; i < resourceIdList.size(); i++) {
                     pstmt.setLong(2 + i, resourceIdList.get(i));
                 }
    +            for(int j=0; j < capacityType.length; i++, j++ ) {
    +                pstmt.setShort(2 + i, capacityType[j]);
    --- End diff --
    
    from the code above you can not guarantee capacity types are starting at parameter no.3.
The 2 above should be a variable kept track off since the start of updateCapacityState()


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message