Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
33ca5b1
Early commit for review - largely untested
Spaceman1984 Jul 10, 2020
ba14254
committing for more testing
Spaceman1984 Jul 14, 2020
ee8bc8d
Removed unused import
Spaceman1984 Jul 14, 2020
9e4cf0a
Added json converter, more conversions and removed 'untested' comments
Spaceman1984 Jul 23, 2020
608732a
removed empty files
Spaceman1984 Jul 24, 2020
98552f0
added some more command conversions on vmware
Spaceman1984 Jul 24, 2020
9c7b36b
Fixed imports on certAuthority test
Spaceman1984 Jul 27, 2020
51e3152
Removed untested comments and improved performance on Json convertor,…
Spaceman1984 Jul 27, 2020
a6e2af4
Removed extra space
Spaceman1984 Jul 27, 2020
8208228
Added a few more conversions, fixed jsonParser output, and changed gl…
Spaceman1984 Jul 28, 2020
494da7a
Added missing license
Spaceman1984 Jul 28, 2020
dc66f04
Handling possible npe when using toReableSize, added locale tests
Spaceman1984 Jul 29, 2020
e9de068
Early commit for review - largely untested
Spaceman1984 Jul 10, 2020
3f8c118
committing for more testing
Spaceman1984 Jul 14, 2020
f0478e1
Added json converter, more conversions and removed 'untested' comments
Spaceman1984 Jul 23, 2020
294734d
removed empty files
Spaceman1984 Jul 24, 2020
769ad37
Removed extra space
Spaceman1984 Jul 27, 2020
40688aa
Added marvin tests, fixed json output, added more json tests
Spaceman1984 Aug 4, 2020
ed65896
Added more conversions in usage records
Spaceman1984 Aug 4, 2020
e24e105
More usage conversions
Spaceman1984 Aug 4, 2020
3e2d652
Fixed a few typos, and event descriptions
Spaceman1984 Aug 4, 2020
b2e6fb8
Removed null from Network usage record when network name is not set
Spaceman1984 Aug 5, 2020
4df8ff7
Added some conversions in list usage records API response
Spaceman1984 Aug 6, 2020
d643114
Added attributes to test
Spaceman1984 Aug 7, 2020
f8ae28d
Added some more conversions
Spaceman1984 Aug 7, 2020
fa34560
fixed some typos and added some more conversions
Spaceman1984 Aug 7, 2020
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: 3 additions & 0 deletions agent/src/main/java/com/cloud/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import javax.naming.ConfigurationException;

import com.cloud.utils.NumbersUtil;
import org.apache.cloudstack.agent.lb.SetupMSListAnswer;
import org.apache.cloudstack.agent.lb.SetupMSListCommand;
import org.apache.cloudstack.ca.PostCertificateRenewalCommand;
Expand Down Expand Up @@ -809,6 +810,8 @@ public void processResponse(final Response response, final Link link) {

public void processReadyCommand(final Command cmd) {
final ReadyCommand ready = (ReadyCommand)cmd;
// Set human readable sizes;
NumbersUtil.enableHumanReadableSizes = ready.getEnableHumanReadableSizes();

s_logger.info("Processing agent ready command, agent id = " + ready.getHostId());
if (ready.getHostId() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,23 @@ public String getEventType() {

@Override
public String getEventDescription() {
return "Volume Id: " + this._uuidMgr.getUuid(Volume.class, getEntityId()) + " to size " + getSize() + "G";
if (getSize() != null) {
return "Volume Id: " + this._uuidMgr.getUuid(Volume.class, getEntityId()) + " to size " + getSize() + " GB";
} else {
return "Volume Id: " + this._uuidMgr.getUuid(Volume.class, getEntityId());
}
}

@Override
public void execute() throws ResourceAllocationException {
Volume volume = null;
try {
CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getEntityId()) + " to size " + getSize() + "G");
if (size != null) {
CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getEntityId()) + " to size " + getSize() + " GB");
} else {
CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getEntityId()));
}

volume = _volumeService.resizeVolume(this);
} catch (InvalidParameterValueException ex) {
s_logger.info(ex.getMessage());
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/com/cloud/agent/api/ReadyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ public ReadyCommand() {
private List<String> msHostList;
private String lbAlgorithm;
private Long lbCheckInterval;
private Boolean enableHumanReadableSizes;

public ReadyCommand(Long dcId) {
super();
this.dcId = dcId;
}

public ReadyCommand(final Long dcId, final Long hostId) {
public ReadyCommand(final Long dcId, final Long hostId, boolean enableHumanReadableSizes) {
this(dcId);
this.hostId = hostId;
this.enableHumanReadableSizes = enableHumanReadableSizes;
}

public void setDetails(String details) {
Expand Down Expand Up @@ -88,4 +90,8 @@ public Long getLbCheckInterval() {
public void setLbCheckInterval(Long lbCheckInterval) {
this.lbCheckInterval = lbCheckInterval;
}

public Boolean getEnableHumanReadableSizes() {
return enableHumanReadableSizes;
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/com/cloud/agent/transport/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import com.cloud.utils.HumanReadableJson;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -417,6 +418,7 @@ protected String log(String msg, boolean logContent, Level level) {
assert false : "More gson errors on " + buff.toString();
return "";
}
content = new StringBuilder(HumanReadableJson.getHumanReadableBytesJson(content.toString()));
if (content.length() <= (1 + _cmds.length * 3)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import com.cloud.utils.UriUtils;
import com.cloud.utils.net.Proxy;

import static com.cloud.utils.NumbersUtil.toHumanReadableSize;

/**
* Download a template file using HTTP
*
Expand Down Expand Up @@ -205,7 +207,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) {
) {
out.seek(localFileSize);

s_logger.info("Starting download from " + downloadUrl + " to " + toFile + " remoteSize=" + remoteSize + " , max size=" + maxTemplateSizeInBytes);
s_logger.info("Starting download from " + downloadUrl + " to " + toFile + " remoteSize=" + toHumanReadableSize(remoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes));

if (copyBytes(file, in, out)) return 0;

Expand Down Expand Up @@ -268,14 +270,14 @@ private void checkDowloadCompletion() {
String downloaded = "(incomplete download)";
if (totalBytes >= remoteSize) {
status = Status.DOWNLOAD_FINISHED;
downloaded = "(download complete remote=" + remoteSize + "bytes)";
downloaded = "(download complete remote=" + toHumanReadableSize(remoteSize) + " bytes)";
}
errorString = "Downloaded " + totalBytes + " bytes " + downloaded;
errorString = "Downloaded " + toHumanReadableSize(totalBytes) + " bytes " + downloaded;
}

private boolean canHandleDownloadSize() {
if (remoteSize > maxTemplateSizeInBytes) {
s_logger.info("Remote size is too large: " + remoteSize + " , max=" + maxTemplateSizeInBytes);
s_logger.info("Remote size is too large: " + toHumanReadableSize(remoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes));
status = Status.UNRECOVERABLE_ERROR;
errorString = "Download file size is too large";
return false;
Expand Down Expand Up @@ -344,7 +346,7 @@ private long checkLocalFileSizeForResume(boolean resume, File file) {
long localFileSize = 0;
if (file.exists() && resume) {
localFileSize = file.length();
s_logger.info("Resuming download to file (current size)=" + localFileSize);
s_logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize));
}
return localFileSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.io.InputStream;
import java.util.Date;

import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
import static com.cloud.utils.StringUtils.join;
import static java.util.Arrays.asList;

Expand Down Expand Up @@ -168,7 +169,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) {
return 0;
}

LOGGER.info("Starting download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " and size " + remoteSize + " bytes");
LOGGER.info("Starting download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " and size " + toHumanReadableSize(remoteSize) + " bytes");

// Time the upload starts.
final Date start = new Date();
Expand Down Expand Up @@ -197,7 +198,7 @@ public void progressChanged(ProgressEvent progressEvent) {
// Record the amount of bytes transferred.
totalBytes += progressEvent.getBytesTransferred();

LOGGER.trace("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + totalBytes + " in " + ((new Date().getTime() - start.getTime()) / 1000) + " seconds");
LOGGER.trace("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + ((new Date().getTime() - start.getTime()) / 1000) + " seconds");

if (progressEvent.getEventType() == ProgressEventType.TRANSFER_STARTED_EVENT) {
status = Status.IN_PROGRESS;
Expand All @@ -222,9 +223,9 @@ public void progressChanged(ProgressEvent progressEvent) {
downloadTime = new Date().getTime() - start.getTime();

if (status == Status.DOWNLOAD_FINISHED) {
LOGGER.info("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + totalBytes + " in " + (downloadTime / 1000) + " seconds, completed successfully!");
LOGGER.info("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed successfully!");
} else {
LOGGER.warn("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + totalBytes + " in " + (downloadTime / 1000) + " seconds, completed with status " + status.toString());
LOGGER.warn("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed with status " + status.toString());
}

// Close input stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.cloud.storage.template.Processor.FormatInfo;
import com.cloud.utils.NumbersUtil;

import static com.cloud.utils.NumbersUtil.toHumanReadableSize;

public class TemplateLocation {
private static final Logger s_logger = Logger.getLogger(TemplateLocation.class);
public final static String Filename = "template.properties";
Expand Down Expand Up @@ -199,7 +201,7 @@ public boolean addFormat(FormatInfo newInfo) {

if (!checkFormatValidity(newInfo)) {
s_logger.warn("Format is invalid");
s_logger.debug("Format: " + newInfo.format + " size: " + newInfo.size + " virtualsize: " + newInfo.virtualSize + " filename: " + newInfo.filename);
s_logger.debug("Format: " + newInfo.format + " size: " + toHumanReadableSize(newInfo.size) + " virtualsize: " + toHumanReadableSize(newInfo.virtualSize) + " filename: " + newInfo.filename);
s_logger.debug("format, filename cannot be null and size, virtual size should be > 0 ");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.cloud.storage.StorageLayer;
import com.cloud.utils.component.AdapterBase;

import static com.cloud.utils.NumbersUtil.toHumanReadableSize;

public class VmdkProcessor extends AdapterBase implements Processor {
private static final Logger s_logger = Logger.getLogger(VmdkProcessor.class);

Expand Down Expand Up @@ -114,7 +116,7 @@ public long getTemplateVirtualSize(String templatePath, String templateName) thr
throw new InternalErrorException(msg);
}

s_logger.debug("vmdk file had size="+virtualSize);
s_logger.debug("vmdk file had size=" + toHumanReadableSize(virtualSize));
return virtualSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import com.cloud.utils.NumbersUtil;
import org.apache.cloudstack.agent.lb.IndirectAgentLB;
import org.apache.cloudstack.ca.CAManager;
import org.apache.cloudstack.framework.config.ConfigKey;
Expand Down Expand Up @@ -585,7 +586,7 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
}

final Long dcId = host.getDataCenterId();
final ReadyCommand ready = new ReadyCommand(dcId, host.getId());
final ReadyCommand ready = new ReadyCommand(dcId, host.getId(), NumbersUtil.enableHumanReadableSizes);
final Answer answer = easySend(hostId, ready);
if (answer == null || !answer.getResult()) {
// this is tricky part for secondary storage
Expand Down Expand Up @@ -1090,7 +1091,7 @@ private AgentAttache handleConnectedAgent(final Link link, final StartupCommand[

final HostVO host = _resourceMgr.createHostVOForConnectedAgent(startup);
if (host != null) {
ready = new ReadyCommand(host.getDataCenterId(), host.getId());
ready = new ReadyCommand(host.getDataCenterId(), host.getId(), NumbersUtil.enableHumanReadableSizes);

if (!indirectAgentLB.compareManagementServerList(host.getId(), host.getDataCenterId(), agentMSHostList)) {
final List<String> newMSList = indirectAgentLB.getManagementServerList(host.getId(), host.getDataCenterId(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
import com.cloud.vm.VmWorkTakeVolumeSnapshot;
import com.cloud.vm.dao.UserVmCloneSettingDao;
import com.cloud.vm.dao.UserVmDao;
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;

public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrationService, Configurable {

Expand Down Expand Up @@ -714,10 +715,10 @@ public DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering
if (rootDisksize != null) {
rootDisksize = rootDisksize * 1024 * 1024 * 1024;
if (rootDisksize > size) {
s_logger.debug("Using root disk size of " + rootDisksize + " Bytes for volume " + name);
s_logger.debug("Using root disk size of " + toHumanReadableSize(rootDisksize) + " Bytes for volume " + name);
size = rootDisksize;
} else {
s_logger.debug("Using root disk size of " + size + " Bytes for volume " + name + "since specified root disk size of " + rootDisksize + " Bytes is smaller than template");
s_logger.debug("Using root disk size of " + toHumanReadableSize(size) + " Bytes for volume " + name + "since specified root disk size of " + toHumanReadableSize(rootDisksize) + " Bytes is smaller than template");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
import com.cloud.vm.dao.VMInstanceDao;
import com.cloud.storage.dao.VolumeDao;

import static com.cloud.utils.HumanReadableJson.getHumanReadableBytesJson;

public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, ClusterManagerListener, Configurable {
// Advanced
public static final ConfigKey<Long> JobExpireMinutes = new ConfigKey<Long>("Advanced", Long.class, "job.expire.minutes", "1440",
Expand Down Expand Up @@ -257,6 +259,7 @@ public Long doInTransaction(TransactionStatus status) {
public void completeAsyncJob(final long jobId, final Status jobStatus, final int resultCode, final String resultObject) {
if (s_logger.isDebugEnabled()) {
String resultObj = obfuscatePassword(resultObject, HidePassword.value());
resultObj = convertHumanReadableJson(resultObj);
s_logger.debug("Complete async job-" + jobId + ", jobStatus: " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObj);
}

Expand Down Expand Up @@ -343,6 +346,15 @@ public List<Long> doInTransaction(final TransactionStatus status) {
_messageBus.publish(null, AsyncJob.Topics.JOB_STATE, PublishScope.GLOBAL, jobId);
}

private String convertHumanReadableJson(String resultObj) {

if (resultObj != null && resultObj.contains("/") && resultObj.contains("{")){
resultObj = resultObj.substring(0, resultObj.indexOf("{")) + getHumanReadableBytesJson(resultObj.substring(resultObj.indexOf("{")));
}

return resultObj;
}

@Override
@DB
public void updateAsyncJobStatus(final long jobId, final int processStatus, final String resultObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import com.cloud.utils.NumbersUtil;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -145,7 +146,7 @@ public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan pl
}
}

s_logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, ram_requested));
s_logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, NumbersUtil.toHumanReadableSize(ram_requested)));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;

import static com.cloud.utils.NumbersUtil.toHumanReadableSize;

@ResourceWrapper(handles = BackupSnapshotCommand.class)
public final class LibvirtBackupSnapshotCommandWrapper extends CommandWrapper<BackupSnapshotCommand, Answer, LibvirtComputingResource> {

Expand Down Expand Up @@ -121,7 +123,7 @@ public Answer execute(final BackupSnapshotCommand command, final LibvirtComputin
bos.write(buf, 0, bytes);
offset += bytes;
}
s_logger.debug("Completed backing up RBD snapshot " + snapshotName + " to " + snapshotDestPath + ". Bytes written: " + offset);
s_logger.debug("Completed backing up RBD snapshot " + snapshotName + " to " + snapshotDestPath + ". Bytes written: " + toHumanReadableSize(offset));
}catch(final IOException ex)
{
s_logger.error("BackupSnapshotAnswer:Exception:"+ ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;

import static com.cloud.utils.NumbersUtil.toHumanReadableSize;

/*
* Uses a local script now, eventually support for virStorageVolResize() will maybe work on qcow2 and lvm and we can do this in libvirt calls
*/
Expand All @@ -59,7 +61,7 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR

if ( currentSize == newSize) {
// nothing to do
s_logger.info("No need to resize volume: current size " + currentSize + " is same as new size " + newSize);
s_logger.info("No need to resize volume: current size " + toHumanReadableSize(currentSize) + " is same as new size " + toHumanReadableSize(newSize));
return new ResizeVolumeAnswer(command, true, "success", currentSize);
}

Expand All @@ -80,7 +82,7 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR
s_logger.debug("Volume " + path + " is on a RBD storage pool. No need to query for additional information.");
}

s_logger.debug("Resizing volume: " + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk);
s_logger.debug("Resizing volume: " + path + ", from: " + toHumanReadableSize(currentSize) + ", to: " + toHumanReadableSize(newSize) + ", type: " + type + ", name: " + vmInstanceName + ", shrinkOk: " + shrinkOk);

/* libvirt doesn't support resizing (C)LVM devices, and corrupts QCOW2 in some scenarios, so we have to do these via Bash script */
if (pool.getType() != StoragePoolType.CLVM && vol.getFormat() != PhysicalDiskFormat.QCOW2) {
Expand Down Expand Up @@ -127,7 +129,7 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR
pool = storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
pool.refresh();
final long finalSize = pool.getPhysicalDisk(volid).getVirtualSize();
s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize);
s_logger.debug("after resize, size reports as: " + toHumanReadableSize(finalSize) + ", requested: " + toHumanReadableSize(newSize));
return new ResizeVolumeAnswer(command, true, "success", finalSize);
} catch (final CloudRuntimeException e) {
final String error = "Failed to resize volume: " + e.getMessage();
Expand Down
Loading