Skip to content

Commit

Permalink
Provide upgrade via webserver for adapters (#2326)
Browse files Browse the repository at this point in the history
* started working on adapterUpgradeManager

* more work for adapter upgrade manager

* start the logic on message

* do not process exit

* refactor getRepository, so we can use Upgrade/Install outside of setup too

* use upgrade to perform all checks os deps install etc on webserver upgrade process

* logger should stream to webserver too

* documentation and feature flag

* add WIP placeholder

* fix nodejs info in changelog
  • Loading branch information
foxriver76 authored Jul 5, 2023
1 parent f56b587 commit 9c02108
Show file tree
Hide file tree
Showing 14 changed files with 587 additions and 176 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Placeholder for the next version (at the beginning of the line):
## __WORK IN PROGRESS__
-->
## 5.0.6 (2023-07-02) - Jana
## ## __WORK IN PROGRESS__ - Jana
**BREAKING CHANGES**
* Support for Node.js 12 is dropped! Supported are Node.js 14.18.0+, 16.4.0+ and 18.x
* Support for Node.js 12 and 14 is dropped! Supported are Node.js 16.4.0+ and 18.x
* Backups created with the new js-controller version cannot be restored on hosts with lower js-controller version!
* Update recommended npm version to 8
* Deprecate binary states, Adapters will change to use Files instead!
Expand Down
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,49 @@ If port 8081 is occupied, you can install a second Admin UI on an alternate port

The command line interface is described at https://www.iobroker.net/#de/documentation/config/cli.md

### Adapter Upgrade with Webserver
**Feature status:** New in 5.0.0

**Feature Flag for detection:** `ADAPTER_WEBSERVER_UPGRADE`

An adapter can be upgraded via `sendToHost`. The adapter sends parameters to the `js-controller` which contain the
information of the adapter to upgrade as well as information to start a webserver. The webserver can be polled by a UI,
even if the adapter itself is stopped during upgrade or does not know of the upgrade.

Example:

```typescript
sendToHostAsync('system.host.test', 'upgradeAdapterWithWebserver', {
version: '1.0.5',
adapterName: 'hm-rpc',
useHttps: true,
port: 8081,
certPrivateName: 'defaultPrivate',
certPublicName: 'defaultPublic'
});
```

In this example the controller will upgrade the adapter `hm-rpc` to version `1.0.5`. During the upgrade,
the log and status information is provided by a webserver running on port `8081`, and using `https` with
the given certificates.

During the update, you can perform a `GET` request against the webserver to get the current status of the upgrade.

The webserver response is defined as following:

```typescript
interface ServerResponse {
/** If the update is still running */
running: boolean;
/** Stderr log during the upgrade */
stderr: string[];
/** Stdout log during the upgrade */
stdout: string[];
/** If installation process succeeded */
success?: boolean;
}
```

### Controller UI Upgrade
**Feature status:** New in 5.0.0

Expand All @@ -97,6 +140,21 @@ In this example, the controller will be upgraded to version `5.0.5` and the web
take the configuration (http/s, port, certificates) of `system.adapter.admin.0`.
During the update, you can perform a `GET` request against the webserver to get the current status of the upgrade.

The webserver response is defined as following:

```typescript
interface ServerResponse {
/** If the update is still running */
running: boolean;
/** Stderr log during the upgrade */
stderr: string[];
/** Stdout log during the upgrade */
stdout: string[];
/** If installation process succeeded */
success?: boolean;
}
```

### Hostname
**Feature status:** stable

Expand Down
7 changes: 0 additions & 7 deletions packages/adapter/src/lib/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9417,13 +9417,6 @@ export class AdapterClass extends EventEmitter {
}

if (sourceObj?.common) {
// TODO: this is just a test, remove it after short test period (version 5.0)
if (sourceObj._id !== sourceId) {
this._logger.error(
`${this.namespaceLog} Alias ids do not match sourceId=${sourceId}, sourceObjId=${sourceObj._id}, report this at https://github.com/ioBroker/ioBroker.js-controller/issues`
);
}

if (!this.aliases.has(sourceObj._id)) {
// TODO what means this, we ensured alias existed, did some async stuff now it's gone -> alias has been deleted?
this._logger.error(
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter/src/lib/adapter/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const SUPPORTED_FEATURES_INTERNAL = [
'BINARY_STATE_EVENT', // stateChange event could be received for binary states too. Deprecated in js-controller 5.0
'CUSTOM_FULL_VIEW', // `getObjectView('system', 'custom-full', ...)` will return full objects and not only `common.custom` part. Since `js-controller` 5.0
'ADAPTER_GET_OBJECTS_BY_ARRAY', // getForeignObjects supports array of ids too. Since js-controller 5.0
'CONTROLLER_UI_UPGRADE' // Controller can be updated via sendToHost('upgradeController', ...)
'CONTROLLER_UI_UPGRADE', // Controller can be updated via sendToHost('upgradeController', ...)
'ADAPTER_WEBSERVER_UPGRADE' // Controller supports upgrading adapter and providing a webserver (triggered via sendToHost). Since `js-controller` 5.0
] as const;

export const SUPPORTED_FEATURES = [...SUPPORTED_FEATURES_INTERNAL];
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export { Vendor } from './lib/setup/setupVendor';
export { Upload } from './lib/setup/setupUpload';
// required by testConsole
export { BackupRestore } from './lib/setup/setupBackup';
// used by adapter upgrade manager
export { Upgrade } from './lib/setup/setupUpgrade';
4 changes: 0 additions & 4 deletions packages/cli/src/lib/_Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import type { Client as StatesRedisClient } from '@iobroker/db-states-redis';
import type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';

export type ProcessExitCallback = (exitCode: number) => void;
export type GetRepositoryHandler = (
repoName: string | undefined,
params: Record<string, any>
) => Promise<Record<string, any>>;
export type CleanDatabaseHandler = (isDeleteDb: boolean) => any;
export type DbConnectCallback = (params: DbConnectAsyncReturn) => void;

Expand Down
Loading

0 comments on commit 9c02108

Please sign in to comment.