mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactor few process of VirtualMachineManagerImpl and improve logs (#4966)
* Improve logs * Remove unnecessary comments * Use diamond inference * Fix some logs * Remove unnecessary unboxing * Create method to handle job result * Remove unused vars and fix some logics * Extract code to method and few adjusts * Use CollectionUtils * Extract pending work job validation to method * Create new constructors * Extract work job and info creation to a method * Extract submit async job to a method * Extract find vm by id to a method * Change log level from trace to debug * Remove unnused methods and add logs * Undo code remotion * Remove asserts and fix conditionals * Address @GabrielBrascher reviews * Remove double quotes from keys in manual json * Undo code remotion * Add object to log * Remove statement from try/catch * Implement toString with ReflectionToStringBuilderUtils * Fix errors related to merge main Co-authored-by: Daniel Augusto Veronezi Salvador <daniel@scclouds.com.br>
This commit is contained in:
parent
d8004871e5
commit
ddd2fcaf2d
@ -20,6 +20,7 @@ import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
@ -430,16 +431,6 @@ public class NicProfile implements InternalIdentity, Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("NicProfile[").append(id)
|
||||
.append("-")
|
||||
.append(vmId)
|
||||
.append("-")
|
||||
.append(reservationId)
|
||||
.append("-")
|
||||
.append(iPv4Address)
|
||||
.append("-")
|
||||
.append(broadcastUri)
|
||||
.append("]")
|
||||
.toString();
|
||||
return String.format("NicProfile %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "vmId", "reservationId", "iPv4Address", "broadcastUri"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,13 @@ public class VmWork implements Serializable {
|
||||
this.handlerName = handlerName;
|
||||
}
|
||||
|
||||
public VmWork(VmWork vmWork) {
|
||||
this.userId = vmWork.getUserId();
|
||||
this.accountId = vmWork.getAccountId();
|
||||
this.vmId = vmWork.getVmId();
|
||||
this.handlerName = vmWork.getHandlerName();
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,12 @@ public class VmWorkAddVmToNetwork extends VmWork {
|
||||
requstedNicProfile = requested;
|
||||
}
|
||||
|
||||
public VmWorkAddVmToNetwork(VmWork vmWork, long networkId, NicProfile requested) {
|
||||
super(vmWork);
|
||||
this.networkId = networkId;
|
||||
this.requstedNicProfile = requested;
|
||||
}
|
||||
|
||||
public Long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
||||
@ -41,18 +41,27 @@ public class VmWorkMigrate extends VmWork {
|
||||
public VmWorkMigrate(long userId, long accountId, long vmId, String handlerName,
|
||||
long srcHostId, DeployDestination dst) {
|
||||
super(userId, accountId, vmId, handlerName);
|
||||
setConstructorParams(srcHostId, dst);
|
||||
}
|
||||
|
||||
public VmWorkMigrate(VmWork vmWork, long srcHostId, DeployDestination dest) {
|
||||
super(vmWork);
|
||||
setConstructorParams(srcHostId, dest);
|
||||
}
|
||||
|
||||
private void setConstructorParams(long srcHostId, DeployDestination dest) {
|
||||
this.srcHostId = srcHostId;
|
||||
zoneId = dst.getDataCenter() != null ? dst.getDataCenter().getId() : null;
|
||||
podId = dst.getPod() != null ? dst.getPod().getId() : null;
|
||||
clusterId = dst.getCluster() != null ? dst.getCluster().getId() : null;
|
||||
hostId = dst.getHost() != null ? dst.getHost().getId() : null;
|
||||
if (dst.getStorageForDisks() != null) {
|
||||
storage = new HashMap<String, String>(dst.getStorageForDisks().size());
|
||||
for (Map.Entry<Volume, StoragePool> entry : dst.getStorageForDisks().entrySet()) {
|
||||
storage.put(entry.getKey().getUuid(), entry.getValue().getUuid());
|
||||
this.zoneId = dest.getDataCenter() != null ? dest.getDataCenter().getId() : null;
|
||||
this.podId = dest.getPod() != null ? dest.getPod().getId() : null;
|
||||
this.clusterId = dest.getCluster() != null ? dest.getCluster().getId() : null;
|
||||
this.hostId = dest.getHost() != null ? dest.getHost().getId() : null;
|
||||
if (dest.getStorageForDisks() != null) {
|
||||
this.storage = new HashMap<>(dest.getStorageForDisks().size());
|
||||
for (Map.Entry<Volume, StoragePool> entry : dest.getStorageForDisks().entrySet()) {
|
||||
this.storage.put(entry.getKey().getUuid(), entry.getValue().getUuid());
|
||||
}
|
||||
} else {
|
||||
storage = null;
|
||||
this.storage = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,11 @@ public class VmWorkMigrateAway extends VmWork {
|
||||
this.srcHostId = srcHostId;
|
||||
}
|
||||
|
||||
public VmWorkMigrateAway(VmWork vmWork, long srcHostId) {
|
||||
super(vmWork);
|
||||
this.srcHostId = srcHostId;
|
||||
}
|
||||
|
||||
public long getSrcHostId() {
|
||||
return srcHostId;
|
||||
}
|
||||
|
||||
@ -30,6 +30,11 @@ public class VmWorkMigrateForScale extends VmWorkMigrate {
|
||||
this.newSvcOfferingId = newSvcOfferingId;
|
||||
}
|
||||
|
||||
public VmWorkMigrateForScale(VmWork vmWork, long srcHostId, DeployDestination dest, Long newSvcOfferingId) {
|
||||
super(vmWork, srcHostId, dest);
|
||||
this.newSvcOfferingId = newSvcOfferingId;
|
||||
}
|
||||
|
||||
public Long getNewServiceOfferringId() {
|
||||
return newSvcOfferingId;
|
||||
}
|
||||
|
||||
@ -35,6 +35,13 @@ public class VmWorkMigrateWithStorage extends VmWork {
|
||||
this.volumeToPool = volumeToPool;
|
||||
}
|
||||
|
||||
public VmWorkMigrateWithStorage(VmWork vmWork, long srcHostId, long destHostId, Map<Long, Long> volumeToPool) {
|
||||
super(vmWork);
|
||||
this.srcHostId = srcHostId;
|
||||
this.destHostId = destHostId;
|
||||
this.volumeToPool = volumeToPool;
|
||||
}
|
||||
|
||||
public long getSrcHostId() {
|
||||
return srcHostId;
|
||||
}
|
||||
|
||||
@ -34,6 +34,11 @@ public class VmWorkReboot extends VmWork {
|
||||
setParams(params);
|
||||
}
|
||||
|
||||
public VmWorkReboot(VmWork vmWork, Map<VirtualMachineProfile.Param, Object> params) {
|
||||
super(vmWork);
|
||||
setParams(params);
|
||||
}
|
||||
|
||||
public Map<VirtualMachineProfile.Param, Object> getParams() {
|
||||
Map<VirtualMachineProfile.Param, Object> map = new HashMap<VirtualMachineProfile.Param, Object>();
|
||||
|
||||
|
||||
@ -39,6 +39,14 @@ public class VmWorkReconfigure extends VmWork {
|
||||
this.sameHost = sameHost;
|
||||
}
|
||||
|
||||
public VmWorkReconfigure(VmWork vmWork, long oldServiceOfferingId, long newServiceOfferingId, Map<String, String> customParameters, boolean sameHost) {
|
||||
super(vmWork);
|
||||
this.oldServiceOfferingId = oldServiceOfferingId;
|
||||
this.newServiceOfferingId = newServiceOfferingId;
|
||||
this.customParameters = customParameters;
|
||||
this.sameHost = sameHost;
|
||||
}
|
||||
|
||||
public Long getOldServiceOfferingId() {
|
||||
return oldServiceOfferingId;
|
||||
}
|
||||
|
||||
@ -27,6 +27,11 @@ public class VmWorkRemoveNicFromVm extends VmWork {
|
||||
this.nicId = nicId;
|
||||
}
|
||||
|
||||
public VmWorkRemoveNicFromVm(VmWork vmWork, long nicId) {
|
||||
super(vmWork);
|
||||
this.nicId = nicId;
|
||||
}
|
||||
|
||||
public Long getNicId() {
|
||||
return nicId;
|
||||
}
|
||||
|
||||
@ -33,6 +33,12 @@ public class VmWorkRemoveVmFromNetwork extends VmWork {
|
||||
this.broadcastUri = broadcastUri;
|
||||
}
|
||||
|
||||
public VmWorkRemoveVmFromNetwork(VmWork vmWork, Network network, URI broadcastUri) {
|
||||
super(vmWork);
|
||||
this.network = network;
|
||||
this.broadcastUri = broadcastUri;
|
||||
}
|
||||
|
||||
public Network getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
@ -27,6 +27,11 @@ public class VmWorkRestore extends VmWork {
|
||||
this.templateId = templateId;
|
||||
}
|
||||
|
||||
public VmWorkRestore(VmWork vmWork, Long templateId) {
|
||||
super(vmWork);
|
||||
this.templateId = templateId;
|
||||
}
|
||||
|
||||
public Long getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@ -54,6 +54,10 @@ public class VmWorkStart extends VmWork {
|
||||
super(userId, accountId, vmId, handlerName);
|
||||
}
|
||||
|
||||
public VmWorkStart(VmWork vmWork){
|
||||
super(vmWork);
|
||||
}
|
||||
|
||||
public DeploymentPlan getPlan() {
|
||||
|
||||
if (podId != null || clusterId != null || hostId != null || poolId != null || physicalNetworkId != null || avoids !=null) {
|
||||
|
||||
@ -26,6 +26,11 @@ public class VmWorkStop extends VmWork {
|
||||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
public VmWorkStop(VmWork vmWork, boolean cleanup) {
|
||||
super(vmWork);
|
||||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
public boolean isCleanup() {
|
||||
return cleanup;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ public class VmWorkStorageMigration extends VmWork {
|
||||
|
||||
Map<Long, Long> volumeToPool;
|
||||
|
||||
public VmWorkStorageMigration(long userId, long accountId, long vmId, String handlerName, Map <Long, Long> volumeToPool) {
|
||||
public VmWorkStorageMigration(long userId, long accountId, long vmId, String handlerName, Map<Long, Long> volumeToPool) {
|
||||
super(userId, accountId, vmId, handlerName);
|
||||
|
||||
this.volumeToPool = volumeToPool;
|
||||
@ -32,4 +32,9 @@ public class VmWorkStorageMigration extends VmWork {
|
||||
public Map<Long, Long> getVolumeToPool() {
|
||||
return volumeToPool;
|
||||
}
|
||||
|
||||
public VmWorkStorageMigration(VmWork vmWork, Map<Long, Long> volumeToPool) {
|
||||
super(vmWork);
|
||||
this.volumeToPool = volumeToPool;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,12 @@ public class VmWorkUpdateDefaultNic extends VmWork {
|
||||
this.defaultNicId = defaultNicId;
|
||||
}
|
||||
|
||||
public VmWorkUpdateDefaultNic(VmWork vmWork, long nicId, long defaultNicId) {
|
||||
super(vmWork);
|
||||
this.nicId = nicId;
|
||||
this.defaultNicId = defaultNicId;
|
||||
}
|
||||
|
||||
public Long getNicId() {
|
||||
return nicId;
|
||||
}
|
||||
|
||||
@ -31,6 +31,8 @@ import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
@ -551,15 +553,9 @@ public class VMTemplateVO implements VirtualMachineTemplate {
|
||||
return uniqueName.hashCode();
|
||||
}
|
||||
|
||||
@Transient
|
||||
String toString;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (toString == null) {
|
||||
toString = new StringBuilder("Tmpl[").append(id).append("-").append(format).append("-").append(uniqueName).toString();
|
||||
}
|
||||
return toString;
|
||||
return String.format("Template %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "uniqueName", "format"));
|
||||
}
|
||||
|
||||
public void setRemoved(Date removed) {
|
||||
|
||||
@ -24,6 +24,7 @@ import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.Command.OnError;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Commands implements Iterable<Command> {
|
||||
OnError _handler;
|
||||
@ -150,4 +151,10 @@ public class Commands implements Iterable<Command> {
|
||||
public Iterator<Command> iterator() {
|
||||
return _cmds.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return _cmds.stream().map(cmd -> cmd.toString()).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user