Skip to content

Commit

Permalink
Merge remote-tracking branch 'apache/main' into 4.19-vnf
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache committed Oct 17, 2023
2 parents 087bf14 + c9d2303 commit b52498f
Show file tree
Hide file tree
Showing 32 changed files with 426 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
@Parameter(name = ApiConstants.DISPLAY_NAME, type = CommandType.STRING, description = "an optional user generated name for the virtual machine")
private String displayName;

@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, description="The password of the virtual machine. If null, a random password will be generated for the VM.",
since="4.19.0.0")
protected String password;

//Owner information
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an optional account for the virtual machine. Must be used with domainId.")
private String accountName;
Expand Down Expand Up @@ -464,6 +468,10 @@ public Long getZoneId() {
return zoneId;
}

public String getPassword() {
return password;
}

public List<Long> getNetworkIds() {
if (MapUtils.isNotEmpty(vAppNetworks)) {
if (CollectionUtils.isNotEmpty(networkIds) || ipAddress != null || getIp6Address() != null || MapUtils.isNotEmpty(ipToNetworkList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.
package org.apache.cloudstack.api.command.user.vm;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import org.apache.cloudstack.acl.SecurityChecker.AccessType;
Expand Down Expand Up @@ -56,8 +57,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd implements UserCmd {
required=true, description="The ID of the virtual machine")
private Long id;

// unexposed parameter needed for serializing/deserializing the command
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, expose=false)
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, description="The new password of the virtual machine. If null, a random password will be generated for the VM.", since="4.19.0")
protected String password;


Expand Down Expand Up @@ -118,7 +118,14 @@ public Long getApiResourceId() {

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
password = _mgr.generateRandomPassword();
password = getPassword();
UserVm vm = _responseGenerator.findUserVmById(getId());
if (StringUtils.isBlank(password)) {
password = _mgr.generateRandomPassword();
s_logger.debug(String.format("Resetting VM [%s] password to a randomly generated password.", vm.getUuid()));
} else {
s_logger.debug(String.format("Resetting VM [%s] password to password defined by user.", vm.getUuid()));
}
CallContext.current().setEventDetails("Vm Id: " + getId());
UserVm result = _userVmService.resetVMPassword(this, password);
if (result != null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
@Param(description = "the domain name of the network owner")
private String domain;

@SerializedName(ApiConstants.DOMAIN_PATH)
@Param(description = "path of the Domain the network belongs to", since = "4.19.0.0")
private String domainPath;

@SerializedName("isdefault")
@Param(description = "true if network is default, false otherwise")
private Boolean isDefault;
Expand Down Expand Up @@ -420,6 +424,10 @@ public void setDomainName(String domain) {
this.domain = domain;
}

public void setDomainPath(String domainPath) {
this.domainPath = domainPath;
}

public void setNetworkOfferingAvailability(String networkOfferingAvailability) {
this.networkOfferingAvailability = networkOfferingAvailability;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,6 @@

package org.apache.cloudstack.direct.download;

import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.cloud.utils.storage.QCOW2Utils;
import org.apache.cloudstack.utils.security.SSLUtils;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.commons.collections.MapUtils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -60,6 +37,32 @@
import java.util.List;
import java.util.Map;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

import org.apache.cloudstack.utils.security.SSLUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.cloud.utils.Pair;
import com.cloud.utils.UriUtils;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.cloud.utils.storage.QCOW2Utils;

public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl {

protected CloseableHttpClient httpsClient;
Expand Down Expand Up @@ -183,8 +186,7 @@ public Long getRemoteFileSize(String url, String format) {
SSLContext context = getSSLContext();
urlConnection.setSSLSocketFactory(context.getSocketFactory());
urlConnection.connect();
boolean isCompressed = !url.endsWith("qcow2");
return QCOW2Utils.getVirtualSize(urlObj.openStream(), isCompressed);
return QCOW2Utils.getVirtualSize(urlObj.openStream(), UriUtils.isUrlForCompressedFile(url));
} catch (IOException e) {
throw new CloudRuntimeException(String.format("Cannot obtain qcow2 virtual size due to: %s", e.getMessage()), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,5 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<

void updateSystemVmTemplateId(long templateId, Hypervisor.HypervisorType hypervisorType);

List<VMInstanceVO> listByHostOrLastHostOrHostPod(long hostId, long podId);
List<VMInstanceVO> listByHostOrLastHostOrHostPod(List<Long> hostIds, long podId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -989,19 +989,19 @@ public void updateSystemVmTemplateId(long templateId, Hypervisor.HypervisorType
}

@Override
public List<VMInstanceVO> listByHostOrLastHostOrHostPod(long hostId, long podId) {
public List<VMInstanceVO> listByHostOrLastHostOrHostPod(List<Long> hostIds, long podId) {
SearchBuilder<VMInstanceVO> sb = createSearchBuilder();
sb.or().op("hostId", sb.entity().getHostId(), Op.EQ);
sb.or("lastHostId", sb.entity().getLastHostId(), Op.EQ);
sb.and().op("hostIdNull", sb.entity().getHostId(), SearchCriteria.Op.NULL);
sb.and().op("hostId", sb.entity().getHostId(), Op.IN);
sb.or("lastHostId", sb.entity().getLastHostId(), Op.IN);
sb.or().op("hostIdNull", sb.entity().getHostId(), SearchCriteria.Op.NULL);
sb.and("lastHostIdNull", sb.entity().getHostId(), SearchCriteria.Op.NULL);
sb.and("podId", sb.entity().getPodIdToDeployIn(), Op.EQ);
sb.cp();
sb.cp();
sb.done();
SearchCriteria<VMInstanceVO> sc = sb.create();
sc.setParameters("hostId", String.valueOf(hostId));
sc.setParameters("lastHostId", String.valueOf(hostId));
sc.setParameters("hostId", hostIds.toArray());
sc.setParameters("lastHostId", hostIds.toArray());
sc.setParameters("podId", String.valueOf(podId));
return listBy(sc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ protected Void deleteSnapshotCallback(AsyncCallbackDispatcher<SnapshotServiceImp
SnapshotResult res = null;
try {
if (result.isFailed()) {
s_logger.debug("delete snapshot failed" + result.getResult());
s_logger.debug(String.format("Failed to delete snapshot [%s] due to: [%s].", snapshot.getUuid(), result.getResult()));
snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
res = new SnapshotResult(context.snapshot, null);
res.setResult(result.getResult());
Expand All @@ -373,7 +373,8 @@ protected Void deleteSnapshotCallback(AsyncCallbackDispatcher<SnapshotServiceImp
res = new SnapshotResult(context.snapshot, null);
}
} catch (Exception e) {
s_logger.debug("Failed to in deleteSnapshotCallback", e);
s_logger.error(String.format("An exception occurred while processing an event in delete snapshot callback from snapshot [%s].", snapshot.getUuid()));
s_logger.debug(String.format("Exception while processing an event in delete snapshot callback from snapshot [%s].", snapshot.getUuid()), e);
res.setResult(e.toString());
}
future.complete(res);
Expand Down Expand Up @@ -418,15 +419,14 @@ public boolean deleteSnapshot(SnapshotInfo snapInfo) {
if (result.isFailed()) {
throw new CloudRuntimeException(result.getResult());
}
s_logger.debug(String.format("Successfully deleted snapshot [%s] with ID [%s].", snapInfo.getName(), snapInfo.getUuid()));
return true;
} catch (InterruptedException e) {
s_logger.debug("delete snapshot is failed: " + e.toString());
} catch (ExecutionException e) {
s_logger.debug("delete snapshot is failed: " + e.toString());
} catch (InterruptedException | ExecutionException e) {
s_logger.error(String.format("Failed to delete snapshot [%s] due to: [%s].", snapInfo.getUuid(), e.getMessage()));
s_logger.debug(String.format("Failed to delete snapshot [%s].", snapInfo.getUuid()), e);
}

return false;

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.Snapshot;
import com.cloud.storage.SnapshotVO;
import com.cloud.storage.Storage;
import com.cloud.storage.VolumeApiService;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.SnapshotDao;
Expand Down Expand Up @@ -360,10 +359,6 @@ public StrategyPriority canHandle(VMSnapshot vmSnapshot) {

@Override
public StrategyPriority canHandle(Long vmId, Long rootPoolId, boolean snapshotMemory) {
//This check could be removed when PR #5297 is merged
if (vmHasNFSOrLocalVolumes(vmId)) {
return StrategyPriority.CANT_HANDLE;
}
if (SnapshotManager.VmStorageSnapshotKvm.value() && !snapshotMemory) {
UserVmVO vm = userVmDao.findById(vmId);
if (vm.getState() == VirtualMachine.State.Running) {
Expand Down Expand Up @@ -465,17 +460,4 @@ protected CreateSnapshotPayload setPayload(VolumeInfo vol, SnapshotVO snapshotCr
payload.setQuiescevm(false);
return payload;
}

private boolean vmHasNFSOrLocalVolumes(long vmId) {
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(vmId);

for (VolumeObjectTO volumeTO : volumeTOs) {
Long poolId = volumeTO.getPoolId();
Storage.StoragePoolType poolType = vmSnapshotHelper.getStoragePoolType(poolId);
if (poolType == Storage.StoragePoolType.NetworkFilesystem || poolType == Storage.StoragePoolType.Filesystem) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ public interface ManagementServerHostDao extends GenericDao<ManagementServerHost
List<Long> listOrphanMsids();

ManagementServerHostVO findOneInUpState(Filter filter);

ManagementServerHostVO findOneByLongestRuntime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.TimeZone;


import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;

import com.cloud.cluster.ClusterInvalidSessionException;
Expand Down Expand Up @@ -204,6 +205,7 @@ protected ManagementServerHostDaoImpl() {

StateSearch = createSearchBuilder();
StateSearch.and("state", StateSearch.entity().getState(), SearchCriteria.Op.IN);
StateSearch.and("runid", StateSearch.entity().getRunid(), SearchCriteria.Op.GT);
StateSearch.done();
}

Expand Down Expand Up @@ -272,4 +274,14 @@ public ManagementServerHostVO findOneInUpState(Filter filter) {
return null;
}

@Override
public ManagementServerHostVO findOneByLongestRuntime() {
SearchCriteria<ManagementServerHostVO> sc = StateSearch.create();
sc.setParameters("state", ManagementServerHost.State.Up);
sc.setParameters("runid", 0);
Filter filter = new Filter(ManagementServerHostVO.class, "runid", true, 0L, 1L);
List<ManagementServerHostVO> msHosts = listBy(sc, filter);
return CollectionUtils.isNotEmpty(msHosts) ? msHosts.get(0) : null;
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<cs.opensaml.version>2.6.6</cs.opensaml.version>
<cs.rados-java.version>0.6.0</cs.rados-java.version>
<cs.java-linstor.version>0.3.0</cs.java-linstor.version>
<cs.reflections.version>0.9.12</cs.reflections.version>
<cs.reflections.version>0.10.2</cs.reflections.version>
<cs.servicemix.version>3.4.4_1</cs.servicemix.version>
<cs.servlet.version>4.0.1</cs.servlet.version>
<cs.tink.version>1.7.0</cs.tink.version>
Expand Down
4 changes: 4 additions & 0 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,10 @@ public NetworkResponse createNetworkResponse(ResponseView view, Network network)
Domain domain = ApiDBUtils.findDomainById(domainNetworkDetails.first());
if (domain != null) {
response.setDomainId(domain.getUuid());

StringBuilder domainPath = new StringBuilder("ROOT");
(domainPath.append(domain.getPath())).deleteCharAt(domainPath.length() - 1);
response.setDomainPath(domainPath.toString());
}
}
response.setSubdomainAccess(domainNetworkDetails.second());
Expand Down
12 changes: 11 additions & 1 deletion server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.host.Host;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.RouterHealthCheckResult;
Expand Down Expand Up @@ -1092,7 +1093,12 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
sb.and("stateNIN", sb.entity().getState(), SearchCriteria.Op.NIN);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
if (clusterId != null) {
sb.and().op("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
sb.or("clusterHostId", sb.entity().getHostId(), Op.IN);
sb.or("clusterLastHostId", sb.entity().getLastHostId(), Op.IN);
sb.cp();
}
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
sb.and("hostIdEQ", sb.entity().getHostId(), SearchCriteria.Op.EQ);
sb.and("templateId", sb.entity().getTemplateId(), SearchCriteria.Op.EQ);
Expand Down Expand Up @@ -1301,6 +1307,10 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm

if (clusterId != null) {
sc.setParameters("clusterId", clusterId);
List<HostJoinVO> hosts = _hostJoinDao.findByClusterId((Long)clusterId, Host.Type.Routing);
List<Long> hostIds = hosts.stream().map(HostJoinVO::getId).collect(Collectors.toList());
sc.setParameters("clusterHostId", hostIds.toArray());
sc.setParameters("clusterLastHostId", hostIds.toArray());
}

if (hostId != null) {
Expand Down
12 changes: 6 additions & 6 deletions server/src/main/java/com/cloud/deploy/FirstFitPlanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class FirstFitPlanner extends AdapterBase implements DeploymentClusterPla

protected String allocationAlgorithm = "random";
protected String globalDeploymentPlanner = "FirstFitPlanner";
protected String[] implicitHostTags;
protected String[] implicitHostTags = new String[0];

@Override
public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
Expand Down Expand Up @@ -214,11 +214,11 @@ private void reorderClustersBasedOnImplicitTags(List<Long> clusterList, int requ
Long uniqueTags;
for (Long clusterId : clusterList) {
uniqueTags = (long) 0;
List<Long> hostList = capacityDao.listHostsWithEnoughCapacity(requiredCpu, requiredRam, clusterId, Host.Type.Routing.toString());
if (!hostList.isEmpty() && implicitHostTags.length > 0) {
uniqueTags = new Long(hostTagsDao.getDistinctImplicitHostTags(hostList, implicitHostTags).size());
uniqueTags = uniqueTags + getHostsByCapability(hostList, Host.HOST_UEFI_ENABLE);
}
List<Long> hostList = capacityDao.listHostsWithEnoughCapacity(requiredCpu, requiredRam, clusterId, Host.Type.Routing.toString());
if (!hostList.isEmpty() && implicitHostTags.length > 0) {
uniqueTags = new Long(hostTagsDao.getDistinctImplicitHostTags(hostList, implicitHostTags).size());
uniqueTags = uniqueTags + getHostsByCapability(hostList, Host.HOST_UEFI_ENABLE);
}
UniqueTagsInClusterMap.put(clusterId, uniqueTags);
}
Collections.sort(clusterList, new Comparator<Long>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ private void checkAutoScaleVmGroupName(String groupName) {
private boolean startNewVM(long vmId) {
try {
CallContext.current().setEventDetails("Vm Id: " + vmId);
userVmMgr.startVirtualMachine(vmId, null, null, null);
userVmMgr.startVirtualMachine(vmId, null, new HashMap<>(), null);
} catch (final ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
Expand Down
Loading

0 comments on commit b52498f

Please sign in to comment.