Skip to content

Commit d4635e3

Browse files
committed
Merge remote-tracking branch 'origin/4.15'
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 61977fa + 2cdde87 commit d4635e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1579
-340
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ env:
164164

165165
- TESTS="component/test_project_usage
166166
component/test_protocol_number_security_group
167+
component/test_public_ip
167168
component/test_resource_limits"
168169

169170
- TESTS="component/test_regions_accounts

api/src/main/java/com/cloud/network/VirtualNetworkApplianceService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.network.router.VirtualRouter;
2828
import com.cloud.user.Account;
2929
import com.cloud.utils.Pair;
30+
import com.cloud.vm.Nic;
3031

3132
public interface VirtualNetworkApplianceService {
3233
/**
@@ -75,4 +76,6 @@ public interface VirtualNetworkApplianceService {
7576
* @return
7677
*/
7778
Pair<Boolean, String> performRouterHealthChecks(long routerId);
79+
80+
<T extends VirtualRouter> void collectNetworkStatistics(T router, Nic nic);
7881
}

api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import java.util.Date;
2020

21-
import com.google.gson.annotations.SerializedName;
22-
2321
import org.apache.cloudstack.api.ApiConstants;
2422
import org.apache.cloudstack.api.BaseResponse;
2523
import org.apache.cloudstack.api.EntityReference;
@@ -28,6 +26,7 @@
2826
import com.cloud.host.Status;
2927
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3028
import com.cloud.serializer.Param;
29+
import com.google.gson.annotations.SerializedName;
3130

3231
@EntityReference(value = Host.class)
3332
public class HostForMigrationResponse extends BaseResponse {
@@ -452,6 +451,10 @@ public void setHypervisorVersion(String hypervisorVersion) {
452451
this.hypervisorVersion = hypervisorVersion;
453452
}
454453

454+
public Boolean getHaHost() {
455+
return haHost;
456+
}
457+
455458
public void setHaHost(Boolean haHost) {
456459
this.haHost = haHost;
457460
}

api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
209209
private Long memoryKBs;
210210

211211
@SerializedName("memoryintfreekbs")
212-
@Param(description = "the internal memory thats free in vm")
212+
@Param(description = "the internal memory that's free in vm or zero if it can not be calculated")
213213
private Long memoryIntFreeKBs;
214214

215215
@SerializedName("memorytargetkbs")

engine/components-api/src/main/java/com/cloud/network/IpAddressManager.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,22 @@ void allocateNicValues(NicProfile nic, DataCenter dc, VirtualMachineProfile vm,
208208
void releasePodIp(Long id) throws CloudRuntimeException;
209209

210210
boolean isUsageHidden(IPAddressVO address);
211+
212+
List<IPAddressVO> listAvailablePublicIps(final long dcId,
213+
final Long podId,
214+
final List<Long> vlanDbIds,
215+
final Account owner,
216+
final VlanType vlanUse,
217+
final Long guestNetworkId,
218+
final boolean sourceNat,
219+
final boolean assign,
220+
final boolean allocate,
221+
final String requestedIp,
222+
final boolean isSystem,
223+
final Long vpcId,
224+
final Boolean displayIp,
225+
final boolean forSystemVms,
226+
final boolean lockOneRow)
227+
throws InsufficientAddressCapacityException;
211228
}
212229

engine/schema/src/main/java/com/cloud/vm/dao/DomainRouterDaoImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,14 @@ public void addRouterToGuestNetwork(final VirtualRouter router, final Network gu
383383
final RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType());
384384
_routerNetworkDao.persist(routerNtwkMap);
385385
//2) create user stats entry for the network
386-
UserStatisticsVO stats =
387-
_userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), guestNetwork.getId(), null, router.getId(), router.getType().toString());
388-
if (stats == null) {
389-
stats =
390-
new UserStatisticsVO(router.getAccountId(), router.getDataCenterId(), null, router.getId(), router.getType().toString(), guestNetwork.getId());
391-
_userStatsDao.persist(stats);
386+
if (router.getVpcId() == null) {
387+
UserStatisticsVO stats =
388+
_userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), guestNetwork.getId(), null, router.getId(), router.getType().toString());
389+
if (stats == null) {
390+
stats =
391+
new UserStatisticsVO(router.getAccountId(), router.getDataCenterId(), null, router.getId(), router.getType().toString(), guestNetwork.getId());
392+
_userStatsDao.persist(stats);
393+
}
392394
}
393395
txn.commit();
394396
}

server/src/main/java/com/cloud/api/ApiDBUtils.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import javax.annotation.PostConstruct;
2828
import javax.inject.Inject;
2929

30+
import com.cloud.vm.NicVO;
31+
import com.cloud.vm.dao.NicDao;
3032
import org.apache.cloudstack.acl.Role;
3133
import org.apache.cloudstack.acl.RoleService;
3234
import org.apache.cloudstack.affinity.AffinityGroup;
@@ -459,6 +461,7 @@ public class ApiDBUtils {
459461
static BackupDao s_backupDao;
460462
static BackupScheduleDao s_backupScheduleDao;
461463
static BackupOfferingDao s_backupOfferingDao;
464+
static NicDao s_nicDao;
462465

463466
@Inject
464467
private ManagementServer ms;
@@ -703,6 +706,8 @@ public class ApiDBUtils {
703706
private BackupOfferingDao backupOfferingDao;
704707
@Inject
705708
private BackupScheduleDao backupScheduleDao;
709+
@Inject
710+
private NicDao nicDao;
706711

707712
@PostConstruct
708713
void init() {
@@ -812,6 +817,7 @@ void init() {
812817
s_hostDetailsDao = hostDetailsDao;
813818
s_clusterDetailsDao = clusterDetailsDao;
814819
s_vmSnapshotDao = vmSnapshotDao;
820+
s_nicDao = nicDao;
815821
s_nicSecondaryIpDao = nicSecondaryIpDao;
816822
s_vpcProvSvc = vpcProvSvc;
817823
s_affinityGroupDao = affinityGroupDao;
@@ -2090,4 +2096,12 @@ public static BackupScheduleResponse newBackupScheduleResponse(BackupSchedule sc
20902096
public static BackupOfferingResponse newBackupOfferingResponse(BackupOffering policy) {
20912097
return s_backupOfferingDao.newBackupOfferingResponse(policy);
20922098
}
2099+
2100+
public static NicVO findByIp4AddressAndNetworkId(String ip4Address, long networkId) {
2101+
return s_nicDao.findByIp4AddressAndNetworkId(ip4Address, networkId);
2102+
}
2103+
2104+
public static NicSecondaryIpVO findSecondaryIpByIp4AddressAndNetworkId(String ip4Address, long networkId) {
2105+
return s_nicSecondaryIpDao.findByIp4AddressAndNetworkId(ip4Address, networkId);
2106+
}
20932107
}

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,9 @@ public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ip
921921
}
922922
}
923923

924+
// show vm info for shared networks
925+
showVmInfoForSharedNetworks(forVirtualNetworks, ipAddr, ipResponse);
926+
924927
// show this info to full view only
925928
if (view == ResponseView.Full) {
926929
VlanVO vl = ApiDBUtils.findVlanById(ipAddr.getVlanId());
@@ -955,6 +958,42 @@ public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ip
955958
return ipResponse;
956959
}
957960

961+
private void showVmInfoForSharedNetworks(boolean forVirtualNetworks, IpAddress ipAddr, IPAddressResponse ipResponse) {
962+
if (!forVirtualNetworks) {
963+
NicVO nic = ApiDBUtils.findByIp4AddressAndNetworkId(ipAddr.getAddress().toString(), ipAddr.getNetworkId());
964+
965+
if (nic == null) { // find in nic_secondary_ips, user vm only
966+
NicSecondaryIpVO secondaryIp =
967+
ApiDBUtils.findSecondaryIpByIp4AddressAndNetworkId(ipAddr.getAddress().toString(), ipAddr.getNetworkId());
968+
if (secondaryIp != null) {
969+
UserVm vm = ApiDBUtils.findUserVmById(secondaryIp.getVmId());
970+
if (vm != null) {
971+
ipResponse.setVirtualMachineId(vm.getUuid());
972+
ipResponse.setVirtualMachineName(vm.getHostName());
973+
if (vm.getDisplayName() != null) {
974+
ipResponse.setVirtualMachineDisplayName(vm.getDisplayName());
975+
} else {
976+
ipResponse.setVirtualMachineDisplayName(vm.getHostName());
977+
}
978+
}
979+
}
980+
} else if (nic.getVmType() == VirtualMachine.Type.User) {
981+
UserVm vm = ApiDBUtils.findUserVmById(nic.getInstanceId());
982+
if (vm != null) {
983+
ipResponse.setVirtualMachineId(vm.getUuid());
984+
ipResponse.setVirtualMachineName(vm.getHostName());
985+
if (vm.getDisplayName() != null) {
986+
ipResponse.setVirtualMachineDisplayName(vm.getDisplayName());
987+
} else {
988+
ipResponse.setVirtualMachineDisplayName(vm.getHostName());
989+
}
990+
}
991+
} else if (nic.getVmType() == VirtualMachine.Type.DomainRouter) {
992+
ipResponse.setIsSystem(true);
993+
}
994+
}
995+
}
996+
958997
@Override
959998
public LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer) {
960999
LoadBalancerResponse lbResponse = new LoadBalancerResponse();

server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
2626

2727
import javax.inject.Inject;
2828

29-
import org.apache.log4j.Logger;
30-
import org.springframework.stereotype.Component;
31-
3229
import org.apache.cloudstack.api.ApiConstants.HostDetails;
3330
import org.apache.cloudstack.api.response.GpuResponse;
3431
import org.apache.cloudstack.api.response.HostForMigrationResponse;
3532
import org.apache.cloudstack.api.response.HostResponse;
3633
import org.apache.cloudstack.api.response.VgpuResponse;
3734
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
35+
import org.apache.cloudstack.ha.HAResource;
36+
import org.apache.cloudstack.ha.dao.HAConfigDao;
3837
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
38+
import org.apache.commons.lang.StringUtils;
39+
import org.apache.log4j.Logger;
40+
import org.springframework.stereotype.Component;
3941

4042
import com.cloud.api.ApiDBUtils;
4143
import com.cloud.api.query.vo.HostJoinVO;
@@ -52,9 +54,6 @@
5254
import com.cloud.utils.db.SearchBuilder;
5355
import com.cloud.utils.db.SearchCriteria;
5456

55-
import org.apache.cloudstack.ha.HAResource;
56-
import org.apache.cloudstack.ha.dao.HAConfigDao;
57-
5857
@Component
5958
public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements HostJoinDao {
6059
public static final Logger s_logger = Logger.getLogger(HostJoinDaoImpl.class);
@@ -178,17 +177,13 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail
178177
hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage);
179178

180179
String hostTags = host.getTag();
181-
hostResponse.setHostTags(host.getTag());
180+
hostResponse.setHostTags(hostTags);
182181

182+
hostResponse.setHaHost(false);
183183
String haTag = ApiDBUtils.getHaTag();
184-
if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) {
185-
if (haTag.equalsIgnoreCase(hostTags)) {
186-
hostResponse.setHaHost(true);
187-
} else {
188-
hostResponse.setHaHost(false);
189-
}
190-
} else {
191-
hostResponse.setHaHost(false);
184+
if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(hostTags) &&
185+
haTag.equalsIgnoreCase(hostTags)) {
186+
hostResponse.setHaHost(true);
192187
}
193188

194189
hostResponse.setHypervisorVersion(host.getHypervisorVersion());
@@ -274,12 +269,19 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail
274269
@Override
275270
public HostResponse setHostResponse(HostResponse response, HostJoinVO host) {
276271
String tag = host.getTag();
277-
if (tag != null) {
278-
if (response.getHostTags() != null && response.getHostTags().length() > 0) {
272+
if (StringUtils.isNotEmpty(tag)) {
273+
if (StringUtils.isNotEmpty(response.getHostTags())) {
279274
response.setHostTags(response.getHostTags() + "," + tag);
280275
} else {
281276
response.setHostTags(tag);
282277
}
278+
279+
if (Boolean.FALSE.equals(response.getHaHost())) {
280+
String haTag = ApiDBUtils.getHaTag();
281+
if (StringUtils.isNotEmpty(haTag) && haTag.equalsIgnoreCase(tag)) {
282+
response.setHaHost(true);
283+
}
284+
}
283285
}
284286
return response;
285287
}
@@ -334,17 +336,13 @@ public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, Enu
334336
hostResponse.setMemoryAllocatedBytes(mem);
335337

336338
String hostTags = host.getTag();
337-
hostResponse.setHostTags(host.getTag());
339+
hostResponse.setHostTags(hostTags);
338340

341+
hostResponse.setHaHost(false);
339342
String haTag = ApiDBUtils.getHaTag();
340-
if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) {
341-
if (haTag.equalsIgnoreCase(hostTags)) {
342-
hostResponse.setHaHost(true);
343-
} else {
344-
hostResponse.setHaHost(false);
345-
}
346-
} else {
347-
hostResponse.setHaHost(false);
343+
if (StringUtils.isNotEmpty(haTag) && StringUtils.isNotEmpty(hostTags) &&
344+
haTag.equalsIgnoreCase(hostTags)) {
345+
hostResponse.setHaHost(true);
348346
}
349347

350348
hostResponse.setHypervisorVersion(host.getHypervisorVersion());
@@ -419,6 +417,13 @@ public HostForMigrationResponse setHostForMigrationResponse(HostForMigrationResp
419417
} else {
420418
response.setHostTags(tag);
421419
}
420+
421+
if (Boolean.FALSE.equals(response.getHaHost())) {
422+
String haTag = ApiDBUtils.getHaTag();
423+
if (StringUtils.isNotEmpty(haTag) && haTag.equalsIgnoreCase(tag)) {
424+
response.setHaHost(true);
425+
}
426+
}
422427
}
423428
return response;
424429
}

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,11 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
222222
userVmResponse.setDiskKbsWrite((long)vmStats.getDiskWriteKBs());
223223
userVmResponse.setDiskIORead((long)vmStats.getDiskReadIOs());
224224
userVmResponse.setDiskIOWrite((long)vmStats.getDiskWriteIOs());
225-
userVmResponse.setMemoryKBs((long)vmStats.getMemoryKBs());
226-
userVmResponse.setMemoryIntFreeKBs((long)vmStats.getIntFreeMemoryKBs());
225+
long totalMemory = (long)vmStats.getMemoryKBs();
226+
long freeMemory = (long)vmStats.getIntFreeMemoryKBs();
227+
long correctedFreeMemory = freeMemory >= totalMemory ? 0 : freeMemory;
228+
userVmResponse.setMemoryKBs(totalMemory);
229+
userVmResponse.setMemoryIntFreeKBs(correctedFreeMemory);
227230
userVmResponse.setMemoryTargetKBs((long)vmStats.getTargetMemoryKBs());
228231

229232
}

0 commit comments

Comments
 (0)