mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Prevent NPE on reboot stopped VM and startVM output with null displayname (#6397)
* Prevent NPE on reboot stopped VM * Use VM UUID instead of VM ID * Apply suggestion * Refactor and fix start VM output * Use format instead of concatenation
This commit is contained in:
parent
006473ca19
commit
b62b5c96e8
@ -28,6 +28,7 @@ import javax.persistence.Table;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user_vm")
|
||||
@ -141,4 +142,8 @@ public class UserVmVO extends VMInstanceVO implements UserVm {
|
||||
public String getName() {
|
||||
return instanceName;
|
||||
}
|
||||
|
||||
public String getDisplayNameOrHostName() {
|
||||
return StringUtils.isNotBlank(displayName) ? displayName : getHostName();
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
|
||||
userVmResponse.setName(userVm.getName());
|
||||
|
||||
if (userVm.getDisplayName() != null) {
|
||||
userVmResponse.setDisplayName(userVm.getDisplayName());
|
||||
userVmResponse.setDisplayName(userVm.getDisplayName());
|
||||
} else {
|
||||
userVmResponse.setDisplayName(userVm.getName());
|
||||
}
|
||||
|
||||
@ -3130,6 +3130,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
if (vmInstance.getState() != State.Running) {
|
||||
throw new InvalidParameterValueException(String.format("The VM %s (%s) is not running, unable to reboot it",
|
||||
vmInstance.getUuid(), vmInstance.getDisplayNameOrHostName()));
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, null, true, vmInstance);
|
||||
|
||||
checkIfHostOfVMIsInPrepareForMaintenanceState(vmInstance.getHostId(), vmId, "Reboot");
|
||||
@ -5119,8 +5124,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
if (vm.getState()== State.Running) {
|
||||
throw new InvalidParameterValueException("The virtual machine "+ vm.getUuid()+ " ("+ vm.getDisplayName()+ ") is already running");
|
||||
if (vm.getState() == State.Running) {
|
||||
throw new InvalidParameterValueException(String.format("The virtual machine %s (%s) is already running",
|
||||
vm.getUuid(), vm.getDisplayNameOrHostName()));
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(callerAccount, null, true, vm);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user