Skip to content

Commit 6a14ffb

Browse files
committed
Merge branch 'master' into ovfprops-full
2 parents b4dcef3 + c732865 commit 6a14ffb

File tree

18 files changed

+285
-53
lines changed

18 files changed

+285
-53
lines changed

api/src/main/java/com/cloud/vm/NicProfile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ public String toString() {
435435
.append(iPv4Address)
436436
.append("-")
437437
.append(broadcastUri)
438+
.append("]")
438439
.toString();
439440
}
440-
}
441+
}

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,14 @@ public void execute() {
138138
e.printStackTrace();
139139
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
140140
} catch (Exception e) {
141-
e.printStackTrace();
142-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm " + e.getMessage());
141+
s_logger.error("Failed to move vm due to: " + e.getStackTrace());
142+
if (e.getMessage() != null) {
143+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage());
144+
} else if (e.getCause() != null) {
145+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getCause());
146+
} else {
147+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
148+
}
143149
}
144150

145151
}

api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.apache.cloudstack.api.response.NetworkOfferingResponse;
2223
import org.apache.log4j.Logger;
2324

2425
import org.apache.cloudstack.acl.RoleType;
@@ -88,6 +89,9 @@ public class ListNetworksCmd extends BaseListTaggedResourcesCmd implements UserC
8889
@Parameter(name = ApiConstants.DISPLAY_NETWORK, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin})
8990
private Boolean display;
9091

92+
@Parameter(name = ApiConstants.NETWORK_OFFERING_ID, type = CommandType.UUID, entityType = NetworkOfferingResponse.class, description = "list networks by network offering ID")
93+
private Long networkOfferingId;
94+
9195
/////////////////////////////////////////////////////
9296
/////////////////// Accessors ///////////////////////
9397
/////////////////////////////////////////////////////
@@ -144,6 +148,10 @@ public Boolean getForVpc() {
144148
return forVpc;
145149
}
146150

151+
public Long getNetworkOfferingId() {
152+
return networkOfferingId;
153+
}
154+
147155
@Override
148156
public Boolean getDisplay() {
149157
if (display != null) {

client/src/main/java/org/apache/cloudstack/ServerDaemon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private void createHttpsConnector(final HttpConfiguration httpConfig) {
219219
// Configure SSL
220220
if (httpsEnable && !Strings.isNullOrEmpty(keystoreFile) && new File(keystoreFile).exists()) {
221221
// SSL Context
222-
final SslContextFactory sslContextFactory = new SslContextFactory();
222+
final SslContextFactory sslContextFactory = new SslContextFactory.Server();
223223

224224
// Define keystore path and passwords
225225
sslContextFactory.setKeyStorePath(keystoreFile);

engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile request
187187
*/
188188
boolean removeNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException;
189189

190+
Boolean updateDefaultNicForVM(VirtualMachine vm, Nic nic, Nic defaultNic);
191+
190192
/**
191193
* @param vm
192194
* @param network

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,9 @@ protected boolean sendStop(final VirtualMachineGuru guru, final VirtualMachinePr
16641664
}
16651665

16661666
guru.finalizeStop(profile, answer);
1667+
final UserVmVO userVm = _userVmDao.findById(vm.getId());
1668+
userVm.setPowerState(PowerState.PowerOff);
1669+
_userVmDao.update(userVm.getId(), userVm);
16671670
} else {
16681671
s_logger.error("Invalid answer received in response to a StopCommand for " + vm.getInstanceName());
16691672
return false;
@@ -5747,4 +5750,116 @@ private Pair<JobInfo.Status, String> orchestrateRestoreVirtualMachine(final VmWo
57475750
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, _jobMgr.marshallResultObject(passwordMap));
57485751
}
57495752

5753+
@Override
5754+
public Boolean updateDefaultNicForVM(final VirtualMachine vm, final Nic nic, final Nic defaultNic) {
5755+
5756+
final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
5757+
if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
5758+
VmWorkJobVO placeHolder = null;
5759+
placeHolder = createPlaceHolderWork(vm.getId());
5760+
try {
5761+
return orchestrateUpdateDefaultNicForVM(vm, nic, defaultNic);
5762+
} finally {
5763+
if (placeHolder != null) {
5764+
_workJobDao.expunge(placeHolder.getId());
5765+
}
5766+
}
5767+
} else {
5768+
final Outcome<VirtualMachine> outcome = updateDefaultNicForVMThroughJobQueue(vm, nic, defaultNic);
5769+
5770+
try {
5771+
outcome.get();
5772+
} catch (final InterruptedException e) {
5773+
throw new RuntimeException("Operation is interrupted", e);
5774+
} catch (final java.util.concurrent.ExecutionException e) {
5775+
throw new RuntimeException("Execution exception", e);
5776+
}
5777+
5778+
final Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
5779+
if (jobResult != null) {
5780+
if (jobResult instanceof Boolean) {
5781+
return (Boolean)jobResult;
5782+
}
5783+
}
5784+
5785+
throw new RuntimeException("Unexpected job execution result");
5786+
}
5787+
}
5788+
5789+
private Boolean orchestrateUpdateDefaultNicForVM(final VirtualMachine vm, final Nic nic, final Nic defaultNic) {
5790+
5791+
s_logger.debug("Updating default nic of vm " + vm + " from nic " + defaultNic.getUuid() + " to nic " + nic.getUuid());
5792+
Integer chosenID = nic.getDeviceId();
5793+
Integer existingID = defaultNic.getDeviceId();
5794+
NicVO nicVO = _nicsDao.findById(nic.getId());
5795+
NicVO defaultNicVO = _nicsDao.findById(defaultNic.getId());
5796+
5797+
nicVO.setDefaultNic(true);
5798+
nicVO.setDeviceId(existingID);
5799+
defaultNicVO.setDefaultNic(false);
5800+
defaultNicVO.setDeviceId(chosenID);
5801+
5802+
_nicsDao.persist(nicVO);
5803+
_nicsDao.persist(defaultNicVO);
5804+
return true;
5805+
}
5806+
5807+
public Outcome<VirtualMachine> updateDefaultNicForVMThroughJobQueue(final VirtualMachine vm, final Nic nic, final Nic defaultNic) {
5808+
5809+
final CallContext context = CallContext.current();
5810+
final User user = context.getCallingUser();
5811+
final Account account = context.getCallingAccount();
5812+
5813+
final List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
5814+
VirtualMachine.Type.Instance, vm.getId(),
5815+
VmWorkUpdateDefaultNic.class.getName());
5816+
5817+
VmWorkJobVO workJob = null;
5818+
if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
5819+
assert pendingWorkJobs.size() == 1;
5820+
workJob = pendingWorkJobs.get(0);
5821+
} else {
5822+
5823+
workJob = new VmWorkJobVO(context.getContextId());
5824+
5825+
workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
5826+
workJob.setCmd(VmWorkUpdateDefaultNic.class.getName());
5827+
5828+
workJob.setAccountId(account.getId());
5829+
workJob.setUserId(user.getId());
5830+
workJob.setVmType(VirtualMachine.Type.Instance);
5831+
workJob.setVmInstanceId(vm.getId());
5832+
workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
5833+
5834+
final VmWorkUpdateDefaultNic workInfo = new VmWorkUpdateDefaultNic(user.getId(), account.getId(), vm.getId(),
5835+
VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, nic.getId(), defaultNic.getId());
5836+
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
5837+
5838+
_jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
5839+
}
5840+
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
5841+
5842+
return new VmJobVirtualMachineOutcome(workJob, vm.getId());
5843+
}
5844+
5845+
@ReflectionUse
5846+
private Pair<JobInfo.Status, String> orchestrateUpdateDefaultNic(final VmWorkUpdateDefaultNic work) throws Exception {
5847+
final VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, work.getVmId());
5848+
if (vm == null) {
5849+
s_logger.info("Unable to find vm " + work.getVmId());
5850+
}
5851+
assert vm != null;
5852+
final NicVO nic = _entityMgr.findById(NicVO.class, work.getNicId());
5853+
if (nic == null) {
5854+
throw new CloudRuntimeException("Unable to find nic " + work.getNicId());
5855+
}
5856+
final NicVO defaultNic = _entityMgr.findById(NicVO.class, work.getDefaultNicId());
5857+
if (defaultNic == null) {
5858+
throw new CloudRuntimeException("Unable to find default nic " + work.getDefaultNicId());
5859+
}
5860+
final boolean result = orchestrateUpdateDefaultNicForVM(vm, nic, defaultNic);
5861+
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED,
5862+
_jobMgr.marshallResultObject(result));
5863+
}
5864+
57505865
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.vm;
18+
19+
public class VmWorkUpdateDefaultNic extends VmWork {
20+
private static final long serialVersionUID = -4265657031064437934L;
21+
22+
Long nicId;
23+
Long defaultNicId;
24+
25+
public VmWorkUpdateDefaultNic(long userId, long accountId, long vmId, String handlerName, Long nicId, Long defaultNicId) {
26+
super(userId, accountId, vmId, handlerName);
27+
28+
this.nicId = nicId;
29+
this.defaultNicId = defaultNicId;
30+
}
31+
32+
public Long getNicId() {
33+
return nicId;
34+
}
35+
36+
public Long getDefaultNicId() {
37+
return defaultNicId;
38+
}
39+
}

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
<cs.guava.version>28.2-jre</cs.guava.version>
135135
<cs.httpclient.version>4.5.11</cs.httpclient.version>
136136
<cs.httpcore.version>4.4.13</cs.httpcore.version>
137-
<cs.influxdb-java.version>2.17</cs.influxdb-java.version>
137+
<cs.influxdb-java.version>2.20</cs.influxdb-java.version>
138138
<cs.jackson.version>2.10.3</cs.jackson.version>
139139
<cs.jasypt.version>1.9.3</cs.jasypt.version>
140140
<cs.java-ipv6.version>0.17</cs.java-ipv6.version>
@@ -144,8 +144,8 @@
144144
<cs.jaxb.version>2.3.0</cs.jaxb.version>
145145
<cs.jaxws.version>2.3.2-1</cs.jaxws.version>
146146
<cs.jersey-bundle.version>1.19.4</cs.jersey-bundle.version>
147-
<cs.jetty.version>9.4.26.v20200117</cs.jetty.version>
148-
<cs.jetty-maven-plugin.version>9.4.26.v20200117</cs.jetty-maven-plugin.version>
147+
<cs.jetty.version>9.4.27.v20200227</cs.jetty.version>
148+
<cs.jetty-maven-plugin.version>9.4.27.v20200227</cs.jetty-maven-plugin.version>
149149
<cs.jna.version>5.5.0</cs.jna.version>
150150
<cs.joda-time.version>2.10.5</cs.joda-time.version>
151151
<cs.jpa.version>2.2.1</cs.jpa.version>
@@ -159,7 +159,7 @@
159159
<cs.neethi.version>2.0.4</cs.neethi.version>
160160
<cs.nitro.version>10.1</cs.nitro.version>
161161
<cs.opensaml.version>2.6.4</cs.opensaml.version>
162-
<cs.rados-java.version>0.5.0</cs.rados-java.version>
162+
<cs.rados-java.version>0.6.0</cs.rados-java.version>
163163
<cs.reflections.version>0.9.12</cs.reflections.version>
164164
<cs.servicemix.version>3.3.3_1</cs.servicemix.version>
165165
<cs.servlet.version>4.0.1</cs.servlet.version>

server/src/main/java/com/cloud/acl/DomainChecker.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public boolean checkAccess(Account caller, Domain domain) throws PermissionDenie
106106
if (caller.getState() != Account.State.enabled) {
107107
throw new PermissionDeniedException(caller + " is disabled.");
108108
}
109+
110+
if (domain == null) {
111+
throw new PermissionDeniedException(String.format("Provided domain is NULL, cannot check access for account [uuid=%s, name=%s]", caller.getUuid(), caller.getAccountName()));
112+
}
113+
109114
long domainId = domain.getId();
110115

111116
if (_accountService.isNormalUser(caller.getId())) {

server/src/main/java/com/cloud/network/NetworkServiceImpl.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,7 @@ public Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd
15511551
Map<String, String> tags = cmd.getTags();
15521552
Boolean forVpc = cmd.getForVpc();
15531553
Boolean display = cmd.getDisplay();
1554+
Long networkOfferingId = cmd.getNetworkOfferingId();
15541555

15551556
// 1) default is system to false if not specified
15561557
// 2) reset parameter to false if it's specified by the regular user
@@ -1679,29 +1680,29 @@ public Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd
16791680
if (isSystem == null || !isSystem) {
16801681
if (!permittedAccounts.isEmpty()) {
16811682
//get account level networks
1682-
networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType,
1683-
skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, permittedAccounts));
1683+
networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
1684+
aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, permittedAccounts));
16841685
//get domain level networks
16851686
if (domainId != null) {
1686-
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, true,
1687-
restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, domainId, false));
1687+
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
1688+
aclType, true, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, domainId, false));
16881689
}
16891690
} else {
16901691
//add account specific networks
1691-
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType,
1692-
skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, path, isRecursive));
1692+
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
1693+
aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, path, isRecursive));
16931694
//add domain specific networks of domain + parent domains
1694-
networksToReturn.addAll(listDomainSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType,
1695-
skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, path, isRecursive));
1695+
networksToReturn.addAll(listDomainSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
1696+
aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, path, isRecursive));
16961697
//add networks of subdomains
16971698
if (domainId == null) {
1698-
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, true,
1699-
restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, caller.getDomainId(), true));
1699+
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
1700+
aclType, true, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, caller.getDomainId(), true));
17001701
}
17011702
}
17021703
} else {
1703-
networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks,
1704-
restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter);
1704+
networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
1705+
null, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter);
17051706
}
17061707

17071708
if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !networksToReturn.isEmpty()) {
@@ -1748,8 +1749,10 @@ public Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd
17481749
return new Pair<List<? extends Network>, Integer>(networksToReturn, networksToReturn.size());
17491750
}
17501751

1751-
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType,
1752-
Long physicalNetworkId, String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId, Map<String, String> tags, Boolean display) {
1752+
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id,
1753+
Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId,
1754+
Long networkOfferingId, String aclType, boolean skipProjectNetworks, Boolean restartRequired,
1755+
Boolean specifyIpRanges, Long vpcId, Map<String, String> tags, Boolean display) {
17531756

17541757
SearchCriteria<NetworkVO> sc = sb.create();
17551758

@@ -1819,6 +1822,10 @@ private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<Netwo
18191822
}
18201823
}
18211824

1825+
if (networkOfferingId != null) {
1826+
sc.addAnd("networkOfferingId", SearchCriteria.Op.EQ, networkOfferingId);
1827+
}
1828+
18221829
return sc;
18231830
}
18241831

@@ -2438,6 +2445,9 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
24382445
// log assign usage events for new offering
24392446
List<NicVO> nics = _nicDao.listByNetworkId(networkId);
24402447
for (NicVO nic : nics) {
2448+
if (nic.getReservationStrategy() == Nic.ReservationStrategy.PlaceHolder) {
2449+
continue;
2450+
}
24412451
long vmId = nic.getInstanceId();
24422452
VMInstanceVO vm = _vmDao.findById(vmId);
24432453
if (vm == null) {

0 commit comments

Comments
 (0)