Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gitseti committed Feb 18, 2021
1 parent 69ac477 commit 3ac8995
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ private HiveMQTestContainerExtension createHiveMQNode(final @NotNull String conn
.withExtension(extensionDir.toFile())
.withHiveMQConfig(new File("src/integrationTest/resources/config.xml"))
.withNetwork(network)
.withLogLevel(Level.DEBUG)
.waitingFor(Wait.forLogMessage(".*Started HiveMQ in.*\\n", 1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void init(
try {
azureStorageClient.createOrUpdate();
} catch (final IllegalStateException | IllegalArgumentException ex) {
log.warn("Initialization of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
log.warn("Initialization of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
return;
}

Expand All @@ -81,7 +81,7 @@ public void init(
saveOwnFile(clusterDiscoveryInput.getOwnClusterId(), clusterDiscoveryInput.getOwnAddress());
clusterDiscoveryOutput.provideCurrentNodes(getNodeAddresses());
} catch (final Exception ex) {
log.warn("Initialization of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
log.warn("Initialization of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
}

}
Expand All @@ -94,7 +94,7 @@ public void reload(
try {
azureStorageClient.createOrUpdate();
} catch (final IllegalStateException | IllegalArgumentException ex) {
log.warn("Reload of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
log.warn("Reload of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
return;
}

Expand All @@ -116,7 +116,7 @@ public void reload(

clusterDiscoveryOutput.provideCurrentNodes(getNodeAddresses());
} catch (final Exception ex) {
log.warn("Reload of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
log.warn("Reload of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
}
}

Expand All @@ -127,7 +127,7 @@ public void destroy(final @NotNull ClusterDiscoveryInput clusterDiscoveryInput)
deleteOwnFile(clusterDiscoveryInput.getOwnClusterId());
}
} catch (final RuntimeException ex) {
log.warn("Destroy of the Azure Cluster Discovery Callback failed. {}", ex.getMessage());
log.warn("Destroy of the Azure Cluster Discovery Callback failed. {}", getRootCause(ex).getMessage());
}

}
Expand Down Expand Up @@ -177,7 +177,7 @@ private void deleteOwnFile(final @NotNull String ownClusterId) throws RuntimeExc
try {
azureStorageClient.deleteBlob(blobKey);
} catch (final Exception ex) {
log.warn("Could not delete expired Azure Blob file '{}'. {}", blobKey, ex.getMessage());
log.warn("Could not delete expired Azure Blob file '{}'. {}", blobKey, getRootCause(ex));
}
} else {
nodeAddresses.add(nodeFile.getClusterNodeAddress());
Expand All @@ -203,7 +203,7 @@ private void deleteOwnFile(final @NotNull String ownClusterId) throws RuntimeExc
}
});
} catch (final Exception ex) {
log.warn("Could not get Azure Blobs. {}", ex.getMessage());
log.warn("Could not get Azure Blobs. {}", getRootCause(ex).getMessage());
}

return clusterNodeFiles;
Expand All @@ -215,7 +215,7 @@ private void deleteOwnFile(final @NotNull String ownClusterId) throws RuntimeExc
try {
fileContent = azureStorageClient.getBlobContent(blob.getName());
} catch (RuntimeException e) {
log.warn("An error occurred while downloading the Azure Blob. {}", e.getMessage());
log.warn("An error occurred while downloading the Azure Blob. {}", getRootCause(e).getMessage());
return null;
}

Expand All @@ -235,4 +235,14 @@ private void deleteOwnFile(final @NotNull String ownClusterId) throws RuntimeExc
void setAzureStorageClient(final @NotNull AzureStorageClient azureStorageClient) {
this.azureStorageClient = azureStorageClient;
}

private @NotNull Throwable getRootCause(final @NotNull Throwable e) {
Throwable cause;
Throwable result = e;

while(null != (cause = result.getCause()) && (result != cause) ) {
result = cause;
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean existsContainer() throws RuntimeException {
return containerClient.exists();
} catch (final BlobStorageException blobStorageException) {
throw new RuntimeException("Azure Storage Container existence check failed with status code " +
blobStorageException.getStatusCode() + " and error code " + blobStorageException.getErrorCode());
blobStorageException.getStatusCode() + " and error code " + blobStorageException.getErrorCode() + ".");
}
}

Expand All @@ -93,7 +93,7 @@ public void createContainer() throws RuntimeException {
} else {
throw new RuntimeException(
"Azure Storage Container creation failed with status code " + error.getStatusCode() +
" and error code " + error.getErrorCode());
" and error code " + error.getErrorCode() + ".");
}
}
}
Expand All @@ -107,7 +107,7 @@ public void saveBlob(final @NotNull String blobName, final @NotNull String conte
} catch (final BlobStorageException blobStorageException) {
throw new RuntimeException(
"Azure Storage Blob upload failed with status code " + blobStorageException.getStatusCode() +
" and error code " + blobStorageException.getErrorCode());
" and error code " + blobStorageException.getErrorCode() + ".");
}
}

Expand All @@ -116,10 +116,11 @@ public void deleteBlob(final @NotNull String blobName) throws RuntimeException {

try {
blob.delete();
} catch (final BlobStorageException blobStorageException) {
}
catch (final BlobStorageException blobStorageException) {
throw new RuntimeException(
"Azure Storage Blob delete failed with status code " + blobStorageException.getStatusCode() +
" and error code " + blobStorageException.getErrorCode());
" and error code " + blobStorageException.getErrorCode() + ".");
}
}

Expand All @@ -130,10 +131,11 @@ public String getBlobContent(final @NotNull String blobName) throws RuntimeExcep

try {
blobClient.download(outputStream);
} catch (final BlobStorageException blobStorageException) {
}
catch (final BlobStorageException blobStorageException) {
throw new RuntimeException(
"Azure Storage Blob download failed with status code " + blobStorageException.getStatusCode() +
" and error code " + blobStorageException.getErrorCode());
" and error code " + blobStorageException.getErrorCode() + ".");
}

return outputStream.toString();
Expand All @@ -147,7 +149,7 @@ public Iterator<BlobItem> getBlobs(final @NotNull String filePrefix) throws Runt
} catch (final BlobStorageException blobStorageException) {
throw new RuntimeException(
"Azure Storage Blobs retrieval failed with status code " + blobStorageException.getStatusCode() +
" and error code " + blobStorageException.getErrorCode());
" and error code " + blobStorageException.getErrorCode() + ".");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ private static boolean isValid(final @NotNull AzureDiscoveryConfig azureDiscover

final String connectionString = azureDiscoveryConfig.getConnectionString();
if (isNullOrBlank(connectionString)) {
logger.warn("The Connection String of the configuration file was empty.");
logger.warn("The Connection String in the configuration file was empty.");
return false;
}

final String containerName = azureDiscoveryConfig.getContainerName();
if (isNullOrBlank(containerName)) {
logger.warn("The Container Name of the configuration file was empty.");
logger.warn("The Container Name in the configuration file was empty.");
return false;
}

Expand All @@ -103,12 +103,12 @@ private static boolean isValid(final @NotNull AzureDiscoveryConfig azureDiscover
fileExpirationInSeconds = azureDiscoveryConfig.getFileExpirationInSeconds();
} catch (final UnsupportedOperationException e) {
logger.warn(
"The File Expiration Interval of the configuration file was empty.");
"The File Expiration Interval in the configuration file was not valid. {}.", e.getMessage());
return false;
}
if (fileExpirationInSeconds < 0) {
logger.warn(
"The File Expiration Interval of the configuration file was negative.");
"The File Expiration Interval in the configuration file was negative.");
return false;
}

Expand All @@ -117,12 +117,12 @@ private static boolean isValid(final @NotNull AzureDiscoveryConfig azureDiscover
fileUpdateIntervalInSeconds = azureDiscoveryConfig.getFileUpdateIntervalInSeconds();
} catch (final UnsupportedOperationException e) {
logger.warn(
"The File Update Interval of the configuration file was empty.");
"The File Update Interval in the configuration file was not valid. {}.", e.getMessage());
return false;
}
if (fileUpdateIntervalInSeconds < 0) {
logger.warn(
"The File Update Interval of the configuration file was negative.");
"The File Update Interval in the configuration file was negative.");
return false;
}

Expand Down

0 comments on commit 3ac8995

Please sign in to comment.