|
57 | 57 | import javax.persistence.LockModeType; |
58 | 58 | import javax.persistence.Tuple; |
59 | 59 | import javax.persistence.TypedQuery; |
| 60 | +import javax.persistence.metamodel.SingularAttribute; |
| 61 | + |
60 | 62 | import java.util.*; |
61 | 63 | import java.util.concurrent.Callable; |
62 | 64 |
|
@@ -947,20 +949,36 @@ private void handle(APIGetLocalStorageHostDiskCapacityMsg msg) { |
947 | 949 | q.add(LocalStorageHostRefVO_.primaryStorageUuid, Op.EQ, msg.getPrimaryStorageUuid()); |
948 | 950 | q.add(LocalStorageHostRefVO_.hostUuid, Op.EQ, msg.getHostUuid()); |
949 | 951 | LocalStorageHostRefVO ref = q.find(); |
| 952 | + |
| 953 | + long total = 0; |
| 954 | + long available = 0; |
| 955 | + long availablePhy = 0; |
| 956 | + long totalPhy = 0; |
| 957 | + |
950 | 958 | if (ref == null) { |
951 | | - reply.setError(errf.instantiateErrorCode(SysErrors.RESOURCE_NOT_FOUND, |
952 | | - String.format("local primary storage[uuid:%s] doesn't have the host[uuid:%s]", |
953 | | - self.getUuid(), msg.getHostUuid()))); |
954 | | - bus.reply(msg, reply); |
955 | | - return; |
| 959 | + HostStatus status = Q.New(HostVO.class).select(HostVO_.status) |
| 960 | + .eq(HostVO_.uuid, msg.getHostUuid()).findValue(); |
| 961 | + if (status == HostStatus.Connected) { |
| 962 | + reply.setError(errf.instantiateErrorCode(SysErrors.RESOURCE_NOT_FOUND, |
| 963 | + String.format( |
| 964 | + "local primary storage[uuid:%s] doesn't have the host[uuid:%s]", |
| 965 | + self.getUuid(), msg.getHostUuid()))); |
| 966 | + bus.reply(msg, reply); |
| 967 | + return; |
| 968 | + } |
| 969 | + } else { |
| 970 | + total = ref.getTotalCapacity(); |
| 971 | + available = ref.getAvailableCapacity(); |
| 972 | + availablePhy = ref.getAvailablePhysicalCapacity(); |
| 973 | + totalPhy = ref.getTotalPhysicalCapacity(); |
956 | 974 | } |
957 | 975 |
|
958 | 976 | HostDiskCapacity c = new HostDiskCapacity(); |
959 | 977 | c.setHostUuid(msg.getHostUuid()); |
960 | | - c.setTotalCapacity(ref.getTotalCapacity()); |
961 | | - c.setAvailableCapacity(ref.getAvailableCapacity()); |
962 | | - c.setAvailablePhysicalCapacity(ref.getAvailablePhysicalCapacity()); |
963 | | - c.setTotalPhysicalCapacity(ref.getTotalPhysicalCapacity()); |
| 978 | + c.setTotalCapacity(total); |
| 979 | + c.setAvailableCapacity(available); |
| 980 | + c.setAvailablePhysicalCapacity(availablePhy); |
| 981 | + c.setTotalPhysicalCapacity(totalPhy); |
964 | 982 | reply.setInventories(list(c)); |
965 | 983 | } else { |
966 | 984 | SimpleQuery<LocalStorageHostRefVO> q = dbf.createQuery(LocalStorageHostRefVO.class); |
|
0 commit comments