Skip to content

Comments

[Folderwatcher] Add Azure blob storage containers monitoring support#14926

Merged
lsiepel merged 4 commits intoopenhab:mainfrom
goopilot:azure
Apr 24, 2025
Merged

[Folderwatcher] Add Azure blob storage containers monitoring support#14926
lsiepel merged 4 commits intoopenhab:mainfrom
goopilot:azure

Conversation

@goopilot
Copy link
Contributor

@goopilot goopilot commented May 2, 2023

Signed-off-by: Alexandr Salamatov goopilot@gmail.com

Added support for monitoring of Azure blob storage containers

DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
// This returns extra character before <xml. Need to find out why
String sResponse = contentResponse.getContentAsString();
InputSource is = new InputSource(new StringReader(sResponse.substring(sResponse.indexOf("<"))));
Copy link
Contributor Author

@goopilot goopilot May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing this, but I don't like it.
The reason why I'm doing this that Azure in the HTTP response has some additional character before <?xml statement. So the DOM parser fails.

Wireshark also shows it:
2023-05-02 16 24 29

Did anybody experience that and if yes, what is the best solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wborn did you experience similar issue with Azure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, maybe it's a BOM?

https://en.m.wikipedia.org/wiki/Byte_order_mark

@lolodomo
Copy link
Contributor

I added the tag "work in progress" as "WIP" is still in the PR title.
Let us know when this is no more "work in progress".

@lolodomo lolodomo added work in progress A PR that is not yet ready to be merged enhancement An enhancement or new feature for an existing add-on labels May 25, 2024
@lsiepel
Copy link
Contributor

lsiepel commented Sep 29, 2024

Gentle ping @goopilot after 1.5 years without visible progress i wonder if you need any support and if we can bring this PR to the finish line.

@goopilot
Copy link
Contributor Author

Gentle ping @goopilot after 1.5 years without visible progress i wonder if you need any support and if we can bring this PR to the finish line.

Thanks for reminding me, I'll work on it this month

@lsiepel lsiepel added the awaiting feedback Awaiting feedback from the pull request author label Oct 26, 2024
@goopilot goopilot force-pushed the azure branch 2 times, most recently from d1615d5 to 0f5d9d5 Compare January 10, 2025 16:42
Signed-off-by: Alexandr Salamatov <goopilot@gmail.com>
@goopilot
Copy link
Contributor Author

@lsiepel could you have a look at it? I'm done with it.

@lsiepel lsiepel removed the awaiting feedback Awaiting feedback from the pull request author label Jan 10, 2025
@lsiepel
Copy link
Contributor

lsiepel commented Jan 10, 2025

@lsiepel could you have a look at it? I'm done with it.

Currently away, will try to look at it in the next week

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding Azure blob. Overall looks good, but do have some comments. Please also update the readme documentation.


public List<String> listBlob(String prefix, Map<String, String> headers, Map<String, String> params)
throws Exception {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

}

try {
previousBlobListing = WatcherCommon.initStorage(currentBlobListingFile,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method needs to return fast and it looks like this initStorage is blocking. If so it should run in a async thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsiepel The idea was that if storage (in this case it's a file) can't be created, then thing should fail initialization phase. But if I run it in the thread, then thing will be initiated before storage is created. Would you suggest to do storage init in a different function?

Copy link
Contributor

@lsiepel lsiepel Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both can still be achieved. A common procedure is like this:

  1. Validat the configuration
  2. set the thing state to unknown
  3. Start an scheduledtask that initilizes/authenticates etc the connection, form within that task:
  • Set the thing state accordingly
  • Schedule the refreshAzureBlobInformation task if all is ok.

this way the initialize method exits fast, sets the thing to unknonw and whenever the authentication finishes, the thing state is set to online/offline etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsiepel Thanks, I pushed changes, please have a look


if (refreshAzureBlobInformation()) {
if (config.pollIntervalAzure > 0) {
executionJob = scheduler.scheduleWithFixedDelay(this::refreshAzureBlobInformation,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the thing state to unknown just before you start the scheduled task.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be changed as part of the above comment (async init)

@lsiepel lsiepel removed the work in progress A PR that is not yet ready to be merged label Feb 19, 2025
@lsiepel lsiepel changed the title [Folderwatcher] [WIP] Azure blob storage containers monitoring support [Folderwatcher] Add Azure blob storage containers monitoring support Feb 19, 2025
@goopilot goopilot force-pushed the azure branch 2 times, most recently from 3f76708 to 92a2d32 Compare February 26, 2025 02:54
Signed-off-by: Alexandr Salamatov <goopilot@gmail.com>
@goopilot
Copy link
Contributor Author

@lsiepel could you have a look at it?

Comment on lines 73 to 88

if (config.azureAnonymous) {
azure = new AzureActions(httpClientFactory, config.azureAccountName, config.azureContainerName);
} else {
azure = new AzureActions(httpClientFactory, config.azureAccountName, config.azureContainerName,
config.azureAccessKey);
}
updateStatus(ThingStatus.UNKNOWN);
if (config.pollIntervalAzure > 0) {
executionJob = scheduler.scheduleWithFixedDelay(this::refreshAzureBlobInformation, 0,
config.pollIntervalAzure, TimeUnit.SECONDS);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Polling interval must be greater then 0 seconds");
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved implementation (might need spotless, as i wrote it here in github)

Suggested change
if (config.azureAnonymous) {
azure = new AzureActions(httpClientFactory, config.azureAccountName, config.azureContainerName);
} else {
azure = new AzureActions(httpClientFactory, config.azureAccountName, config.azureContainerName,
config.azureAccessKey);
}
updateStatus(ThingStatus.UNKNOWN);
if (config.pollIntervalAzure > 0) {
executionJob = scheduler.scheduleWithFixedDelay(this::refreshAzureBlobInformation, 0,
config.pollIntervalAzure, TimeUnit.SECONDS);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Polling interval must be greater then 0 seconds");
return;
}
if (config.azureAccountName.isBlank() || config.azureContainerName.isBlank()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Account name or container configuration is invalid");
return;
} else if (config.pollIntervalAzure == 0) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Polling interval must be greater then 0 seconds");
return;
}
if (config.azureAnonymous) {
azure = new AzureActions(httpClientFactory, config.azureAccountName, config.azureContainerName);
} else {
azure = new AzureActions(httpClientFactory, config.azureAccountName, config.azureContainerName,
config.azureAccessKey);
}
updateStatus(ThingStatus.UNKNOWN);
executionJob = scheduler.scheduleWithFixedDelay(this::refreshAzureBlobInformation, 0,
config.pollIntervalAzure, TimeUnit.SECONDS);

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor thing is left to fix. Rewrite the init method so that it better checks the configuration. Otherwise LGTM

Signed-off-by: Alexandr Salamatov <goopilot@gmail.com>
@goopilot
Copy link
Contributor Author

goopilot commented Apr 23, 2025

@lsiepel omg, for some reason I was sure I did it a long time ago. Can you have a look now?

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@lsiepel lsiepel merged commit c445d15 into openhab:main Apr 24, 2025
2 checks passed
@lsiepel lsiepel added this to the 5.0 milestone Apr 24, 2025
phenix1990 pushed a commit to phenix1990/openhab-addons that referenced this pull request Jul 31, 2025
…penhab#14926)

* Add Azure Thing

Signed-off-by: Alexandr Salamatov <goopilot@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature for an existing add-on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants