Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion engine/schema/src/main/java/com/cloud/host/HostVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.GenericDao;
import java.util.Arrays;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.lang3.StringUtils;

@Entity
Expand Down Expand Up @@ -680,7 +681,7 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return String.format("Host {\"id\": \"%s\", \"name\": \"%s\", \"uuid\": \"%s\", \"type\"=\"%s\"}", id, name, uuid, type);
return String.format("Host %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "name", "uuid", "type"));
}

public void setHypervisorType(HypervisorType hypervisorType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.cloud.offering.ServiceOffering;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;

@Entity
@Table(name = "service_offering")
Expand Down Expand Up @@ -424,7 +425,7 @@ public String getUuid() {

@Override
public String toString() {
return String.format("Service offering {\"id\": %s, \"name\": \"%s\", \"uuid\": \"%s\"}", getId(), getName(), getUuid());
return String.format("Service offering %s.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "name", "uuid"));
}

public boolean isDynamicScalingEnabled() {
Expand Down
3 changes: 2 additions & 1 deletion engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import javax.persistence.Transient;

import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -501,7 +502,7 @@ public void setRemoved(Date removed) {

@Override
public String toString() {
return String.format("VM instance {id: \"%s\", name: \"%s\", uuid: \"%s\", type=\"%s\"}", id, getInstanceName(), uuid, type);
return String.format("VM instance %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "instanceName", "uuid", "type"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,9 @@ public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
}
final List<String> hostTags = cmd.getHostTags();
if (hostTags != null) {
List<VMInstanceVO> activeVMs = _vmDao.listByHostId(hostId);
s_logger.warn(String.format("The following active VMs [%s] are using the host [%s]. Updating the host tags will not affect them.", activeVMs, host));

if (s_logger.isDebugEnabled()) {
s_logger.debug("Updating Host Tags to :" + hostTags);
}
Expand Down
29 changes: 20 additions & 9 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1845,20 +1845,31 @@ public HashMap<Long, List<VmDiskStatsEntry>> getVmDiskStatistics(long hostId, St
public boolean upgradeVirtualMachine(Long vmId, Long newServiceOfferingId, Map<String, String> customParameters) throws ResourceUnavailableException,
ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {

// Verify input parameters
VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
Account caller = CallContext.current().getCallingAccount();
_accountMgr.checkAccess(caller, null, true, vmInstance);
if (vmInstance != null) {
if (vmInstance.getState().equals(State.Stopped)) {
upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, customParameters);
return true;
}
if (vmInstance.getState().equals(State.Running)) {
return upgradeRunningVirtualMachine(vmId, newServiceOfferingId, customParameters);
if (vmInstance == null) {
s_logger.error(String.format("VM instance with id [%s] is null, it is not possible to upgrade a null VM.", vmId));
return false;
}

if (State.Stopped.equals(vmInstance.getState())) {
upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, customParameters);
return true;
}

if (State.Running.equals(vmInstance.getState())) {
ServiceOfferingVO newServiceOfferingVO = _serviceOfferingDao.findById(newServiceOfferingId);
HostVO instanceHost = _hostDao.findById(vmInstance.getHostId());
_hostDao.loadHostTags(instanceHost);

if (!instanceHost.checkHostServiceOfferingTags(newServiceOfferingVO)) {
s_logger.error(String.format("Cannot upgrade VM [%s] as the new service offering [%s] does not have the required host tags %s.", vmInstance, newServiceOfferingVO,
instanceHost.getHostTags()));
return false;
}
}
return false;
return upgradeRunningVirtualMachine(vmId, newServiceOfferingId, customParameters);
}

private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingId, Map<String, String> customParameters) throws ResourceUnavailableException,
Expand Down