Skip to content

Commit

Permalink
Make logging on upload/download quiet by default (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored May 2, 2021
1 parent c32740f commit 4da08e7
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class AzureStorageBuilder extends Builder implements SimpleBuildStep {

private final String downloadType;
private boolean deleteFromAzureAfterDownload;
private String storageCredentialId;
private final String storageCredentialId;
private String containerName = "";
private String fileShare;
private String includeFilesPattern = "";
Expand All @@ -83,6 +83,7 @@ public class AzureStorageBuilder extends Builder implements SimpleBuildStep {
private boolean includeArchiveZips;
private BuildSelector buildSelector;
private String projectName = "";
private boolean verbose;

private transient AzureStorageAccount.StorageAccountCredential storageCreds;

Expand Down Expand Up @@ -158,6 +159,15 @@ public BuildSelector getBuildSelector() {
return buildSelector;
}

public boolean isVerbose() {
return verbose;
}

@DataBoundSetter
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}

/**
* @deprecated use {@link #getStorageAccName(Item)}
*/
Expand Down Expand Up @@ -293,8 +303,9 @@ public void perform(
builderServiceData.setDownloadType(getDownloadType());
builderServiceData.setProjectName(Util.replaceMacro(projectName, envVars));
builderServiceData.setBuildSelector(buildSelector);
builderServiceData.setVerbose(isVerbose());

final StoragePluginService downloadService = getDownloadService(builderServiceData);
final StoragePluginService<DownloadServiceData> downloadService = getDownloadService(builderServiceData);
int filesDownloaded = downloadService.execute();

if (filesDownloaded == 0) {
Expand All @@ -309,7 +320,7 @@ public void perform(
}
}

private StoragePluginService getDownloadService(DownloadServiceData data) {
private StoragePluginService<DownloadServiceData> getDownloadService(DownloadServiceData data) {
switch (getDownloadType()) {
case DOWNLOAD_TYPE_FILE_SHARE:
return new DownloadFromFileService(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class WAStoragePublisher extends Recorder implements SimpleBuildStep {
private boolean doNotWaitForPreviousBuild;
private final String storageCredentialId;
private boolean onlyUploadModifiedArtifacts;
private boolean verbose;

private transient AzureStorageAccount.StorageAccountCredential storageCreds;

Expand Down Expand Up @@ -191,6 +192,15 @@ public void setMetadata(List<AzureBlobMetadataPair> metadata) {
this.metadata = metadata;
}

public boolean isVerbose() {
return verbose;
}

@DataBoundSetter
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}

/**
* Files path. Ant glob syntax.
*/
Expand Down Expand Up @@ -431,6 +441,7 @@ public void perform(
serviceData.setAzureBlobMetadata(metadata);
serviceData.setOnlyUploadModifiedArtifacts(onlyUploadModifiedArtifacts);
serviceData.setCredentialsId(getStorageCredentialId());
serviceData.setVerbose(isVerbose());
// Resolve virtual path
String expVP = Utils.replaceMacro(Util.fixNull(virtualPath), envVars);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ private int downloadArtifacts(Run<?, ?> source) {
private int scanBlobs(List<AzureBlob> azureBlobs) throws WAStorageException {
final DownloadServiceData serviceData = getServiceData();
int filesNeedDownload = 0;
println(Messages.AzureStorageBuilder_downloading());
if (serviceData.isVerbose()) {
println(Messages.AzureStorageBuilder_downloading());
}

for (final AzureBlob blob : azureBlobs) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public int execute() {
final DownloadServiceData serviceData = getServiceData();
int filesNeedDownload;
try {
println(Messages.AzureStorageBuilder_downloading());
if (serviceData.isVerbose()) {
println(Messages.AzureStorageBuilder_downloading());
}
final BlobContainerClient container = AzureUtils.getBlobContainerReference(
serviceData.getStorageAccountInfo(),
serviceData.getContainerName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public DownloadFromFileService(DownloadServiceData data) {
public int execute() {
int filesNeedDownload;
try {
println(Messages.AzureStorageBuilder_downloading());
if (getServiceData().isVerbose()) {
println(Messages.AzureStorageBuilder_downloading());
}
final ShareClient cloudFileShare = getCloudFileShare();
final ShareDirectoryClient cloudFileDirectory = cloudFileShare.getRootDirectoryClient();
filesNeedDownload = scanFileItems(cloudFileShare, cloudFileDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ protected void waitForDownloadEnd() throws WAStorageException {
protected void downloadSingleFile(ShareFileClient cloudFile) throws WAStorageException {
final DownloadServiceData serviceData = getServiceData();
try {
println("Downloading file:" + cloudFile.getFileUrl());
if (serviceData.isVerbose()) {
println("Downloading file:" + cloudFile.getFileUrl());
}
final FilePath destFile = destinationFilePath(cloudFile.getFilePath());

final long startTime = System.currentTimeMillis();
Expand All @@ -113,7 +115,9 @@ protected void downloadSingleFile(ShareFileClient cloudFile) throws WAStorageExc

protected void downloadBlob(BlobClient blob) throws WAStorageException {
try {
println("Downloading file:" + blob.getBlobUrl());
if (getServiceData().isVerbose()) {
println("Downloading file:" + blob.getBlobUrl());
}

final FilePath destFile = destinationFilePath(blob.getBlobName());
final long startTime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,23 @@ protected void updateAzureBlobs(List<UploadResult> results,
List<AzureBlob> azureBlobs) throws WAStorageException {
for (UploadResult result : results) {
if (result.getStatusCode() == HttpStatus.SC_CREATED) {
UploadServiceData serviceData = getServiceData();
AzureBlob azureBlob = new AzureBlob(
result.getName(),
result.getUrl(),
result.getFileHash(),
result.getByteSize(),
result.getStorageType(),
getServiceData().getCredentialsId());
serviceData.getCredentialsId());

filesUploaded.addAndGet(1);
azureBlobs.add(azureBlob);

long interval = result.getEndTime() - result.getStartTime();
println(Messages.UploadService_https_uploaded(result.getUrl(), getTime(interval)));

if (serviceData.isVerbose()) {
println(Messages.UploadService_https_uploaded(result.getUrl(), getTime(interval)));
}
}
}
}
Expand Down Expand Up @@ -456,16 +460,20 @@ public final int execute() throws WAStorageException {
return 0;
}

println(Messages.WAStoragePublisher_container_name(serviceData.getContainerName()));
println(Messages.WAStoragePublisher_share_name(serviceData.getFileShareName()));
println(Messages.WAStoragePublisher_filepath(serviceData.getFilePath()));
println(Messages.WAStoragePublisher_virtualpath(serviceData.getVirtualPath()));
println(Messages.WAStoragePublisher_excludepath(serviceData.getExcludedFilesPath()));
if (serviceData.isVerbose()) {
println(Messages.WAStoragePublisher_container_name(serviceData.getContainerName()));
println(Messages.WAStoragePublisher_share_name(serviceData.getFileShareName()));
println(Messages.WAStoragePublisher_filepath(serviceData.getFilePath()));
println(Messages.WAStoragePublisher_virtualpath(serviceData.getVirtualPath()));
println(Messages.WAStoragePublisher_excludepath(serviceData.getExcludedFilesPath()));
}
int filesNeedUpload = 0; // Counter to track no. of files that are need uploaded
int filesCount = 0;
try {
final FilePath workspacePath = serviceData.getRemoteWorkspace();
println(Messages.WAStoragePublisher_uploading());
if (serviceData.isVerbose()) {
println(Messages.WAStoragePublisher_uploading());
}

final StringBuilder archiveIncludes = new StringBuilder();

Expand Down Expand Up @@ -520,7 +528,9 @@ public final int execute() throws WAStorageException {
// archive file should not be included in downloaded file count
filesUploaded.decrementAndGet();
}
println(Messages.WAStoragePublisher_files_need_upload_count(filesNeedUpload));
if (serviceData.isVerbose()) {
println(Messages.WAStoragePublisher_files_need_upload_count(filesNeedUpload));
}
waitForUploadEnd();
} catch (IOException | InterruptedException e) {
throw new WAStorageException(e.getMessage(), e);
Expand Down Expand Up @@ -553,7 +563,9 @@ protected String uploadCloudFile(ShareFileClient fileClient, FilePath localPath)
null, null);

long endTime = System.currentTimeMillis();
println("Uploaded blob with uri " + fileClient.getFileUrl() + " in " + getTime(endTime - startTime));
if (getServiceData().isVerbose()) {
println("Uploaded file with uri " + fileClient.getFileUrl() + " in " + getTime(endTime - startTime));
}
return DatatypeConverter.printHexBinary(response.getValue().getContentMd5());
} catch (Exception e) {
throw new WAStorageException("Failed uploading file", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public abstract class ServiceData {
private final Launcher launcher;
private final TaskListener taskListener;
private final StorageAccountInfo storageAccountInfo;
private boolean verbose;

protected ServiceData(Run<?, ?> run,
FilePath workspace,
Expand All @@ -41,6 +42,14 @@ protected ServiceData(Run<?, ?> run,
this.storageAccountInfo = storageAccountInfo;
}

public boolean isVerbose() {
return verbose;
}

public void setVerbose(boolean verbose) {
this.verbose = verbose;
}

public StorageAccountInfo getStorageAccountInfo() {
return storageAccountInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class UploadServiceData extends ServiceData {
private String containerName;
private String fileShareName;
private AzureBlobProperties blobProperties;
private AzureBlobProperties blobProperties = new AzureBlobProperties();
private boolean pubAccessible;
private boolean cleanUpContainerOrShare;
private boolean cleanUpVirtualPath;
Expand All @@ -40,8 +40,8 @@ public class UploadServiceData extends ServiceData {
private String excludedFilesPath;
private UploadType uploadType;
private boolean onlyUploadModifiedArtifacts;
private List<AzureBlob> individualBlobs = Collections.synchronizedList(new ArrayList<AzureBlob>());
private List<AzureBlob> archiveBlobs = Collections.synchronizedList(new ArrayList<AzureBlob>());
private final List<AzureBlob> individualBlobs = Collections.synchronizedList(new ArrayList<>());
private final List<AzureBlob> archiveBlobs = Collections.synchronizedList(new ArrayList<>());
private List<AzureBlobMetadataPair> azureBlobMetadata;
private String credentialsId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,19 @@
</f:entry>

<f:entry field="flattenDirectories">
<div align="left">
<f:checkbox title="${%flattenDirectories_title}"/>
</div>
<f:checkbox title="${%flattenDirectories_title}"/>
</f:entry>

<f:entry field="deleteFromAzureAfterDownload">
<div align="left">
<f:checkbox title="${%deleteFromAzureAfterDownload_title}"/>
</div>
<f:checkbox title="${%deleteFromAzureAfterDownload_title}"/>
</f:entry>

<f:entry field="includeArchiveZips">
<div align="left">
<f:checkbox title="${%includeArchiveZips_title}"/>
</div>
<f:checkbox title="${%includeArchiveZips_title}"/>
</f:entry>

<f:entry field="verbose">
<f:checkbox title="${%Verbose logging}"/>
</f:entry>

</f:advanced>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Enabling this will provide more logging on downloading files.</p>
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,20 @@

<f:entry field="doNotUploadIndividualFiles"
help="/plugin/windows-azure-storage/help-doNotUploadIndividualFiles.html">
<div align="left">
<f:checkbox title="${%doNotUploadIndividualFiles_title}"/>
</div>
<f:checkbox title="${%doNotUploadIndividualFiles_title}"/>
</f:entry>

<f:entry field="doNotWaitForPreviousBuild"
help="/plugin/windows-azure-storage/help-doNotWaitForPreviousBuild.html">
<div align="left">
<f:checkbox title="${%doNotWaitForPreviousBuild_title}"/>
</div>
<f:checkbox title="${%doNotWaitForPreviousBuild_title}"/>
</f:entry>

<f:entry field="onlyUploadModifiedArtifacts"
help="/plugin/windows-azure-storage/help-onlyUploadModifiedArtifacts.html">
<div align="left">
<f:checkbox title="${%onlyUploadModifiedArtifacts_title}"/>
</div>
<f:checkbox title="${%onlyUploadModifiedArtifacts_title}"/>
</f:entry>
<f:entry field="verbose">
<f:checkbox title="${%Verbose logging}"/>
</f:entry>
</f:advanced>
</f:section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Enabling this will provide more logging on uploading files.</p>

0 comments on commit 4da08e7

Please sign in to comment.