Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added service agreements operational db migration #2780

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
298 changes: 51 additions & 247 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@ import { createRequire } from 'module';
import { execSync } from 'child_process';
import DependencyInjection from './src/service/dependency-injection.js';
import Logger from './src/logger/logger.js';
import { MIN_NODE_VERSION, NODE_ENVIRONMENTS } from './src/constants/constants.js';
import { MIN_NODE_VERSION } from './src/constants/constants.js';
import FileService from './src/service/file-service.js';
import OtnodeUpdateCommand from './src/commands/common/otnode-update-command.js';
import OtAutoUpdater from './src/modules/auto-updater/implementation/ot-auto-updater.js';
import PullBlockchainShardingTableMigration from './src/migration/pull-sharding-table-migration.js';
import TripleStoreUserConfigurationMigration from './src/migration/triple-store-user-configuration-migration.js';
import TelemetryModuleUserConfigurationMigration from './src/migration/telemetry-module-user-configuration-migration.js';
import PrivateAssetsMetadataMigration from './src/migration/private-assets-metadata-migration.js';
import ServiceAgreementsMetadataMigration from './src/migration/service-agreements-metadata-migration.js';
import RemoveAgreementStartEndTimeMigration from './src/migration/remove-agreement-start-end-time-migration.js';
import MarkOldBlockchainEventsAsProcessedMigration from './src/migration/mark-old-blockchain-events-as-processed-migration.js';
import TripleStoreMetadataMigration from './src/migration/triple-store-metadata-migration.js';
import RemoveOldEpochCommandsMigration from './src/migration/remove-old-epoch-commands-migration.js';
import PendingStorageMigration from './src/migration/pending-storage-migration.js';
import MigrationExecutor from './src/migration/migration-executor.js';

const require = createRequire(import.meta.url);
const pjson = require('./package.json');
Expand All @@ -36,8 +27,14 @@ class OTNode {
async start() {
await this.checkForUpdate();
await this.removeUpdateFile();
await this.executeTripleStoreUserConfigurationMigration();
await this.executeTelemetryModuleUserConfigurationMigration();
await MigrationExecutor.executeTripleStoreUserConfigurationMigration(
this.logger,
this.config,
);
await MigrationExecutor.executeTelemetryModuleUserConfigurationMigration(
this.logger,
this.config,
);
this.logger.info(' ██████╗ ████████╗███╗ ██╗ ██████╗ ██████╗ ███████╗');
this.logger.info('██╔═══██╗╚══██╔══╝████╗ ██║██╔═══██╗██╔══██╗██╔════╝');
this.logger.info('██║ ██║ ██║ ██╔██╗ ██║██║ ██║██║ ██║█████╗');
Expand All @@ -54,15 +51,47 @@ class OTNode {
this.initializeEventEmitter();

await this.initializeModules();
await this.executePullShardingTableMigration();
await this.executePrivateAssetsMetadataMigration();
await this.executeRemoveAgreementStartEndTimeMigration();
await this.executeMarkOldBlockchainEventsAsProcessedMigration();
await this.executeTripleStoreMetadataMigration();
await this.executeServiceAgreementsMetadataMigration();
await this.executeRemoveOldEpochCommandsMigration();
await this.executePendingStorageMigration();

await MigrationExecutor.executePullShardingTableMigration(
this.container,
this.logger,
this.config,
);
await MigrationExecutor.executePrivateAssetsMetadataMigration(
this.container,
this.logger,
this.config,
);
await MigrationExecutor.executeRemoveAgreementStartEndTimeMigration(
this.container,
this.logger,
this.config,
);
await MigrationExecutor.executeMarkOldBlockchainEventsAsProcessedMigration(
this.container,
this.logger,
this.config,
);
await MigrationExecutor.executeTripleStoreMetadataMigration(
this.container,
this.logger,
this.config,
);
await MigrationExecutor.executeServiceAgreementsMetadataMigration(
this.container,
this.logger,
this.config,
);
await MigrationExecutor.executeRemoveOldEpochCommandsMigration(
this.container,
this.logger,
this.config,
);
await MigrationExecutor.executePendingStorageMigration(this.logger, this.config);
await MigrationExecutor.executeServiceAgreementsOpDatabaseMigration(
this.container,
this.logger,
this.config,
);
await this.createProfiles();

await this.initializeCommandExecutor();
Expand Down Expand Up @@ -292,211 +321,6 @@ class OTNode {
});
}

async executePrivateAssetsMetadataMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;
const blockchainModuleManager = this.container.resolve('blockchainModuleManager');
const tripleStoreService = this.container.resolve('tripleStoreService');
const serviceAgreementService = this.container.resolve('serviceAgreementService');
const ualService = this.container.resolve('ualService');
const dataService = this.container.resolve('dataService');

const migration = new PrivateAssetsMetadataMigration(
'privateAssetsMetadataMigration',
this.logger,
this.config,
tripleStoreService,
blockchainModuleManager,
serviceAgreementService,
ualService,
dataService,
);

if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
this.logger.info('Node will now restart!');
this.stop(1);
}
}

async executeTelemetryModuleUserConfigurationMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const migration = new TelemetryModuleUserConfigurationMigration(
'telemetryModuleUserConfigurationMigration',
this.logger,
this.config,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
this.logger.info('Node will now restart!');
this.stop(1);
}
}

async executeTripleStoreUserConfigurationMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const migration = new TripleStoreUserConfigurationMigration(
'tripleStoreUserConfigurationMigration',
this.logger,
this.config,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
this.logger.info('Node will now restart!');
this.stop(1);
}
}

async executePullShardingTableMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const blockchainModuleManager = this.container.resolve('blockchainModuleManager');
const repositoryModuleManager = this.container.resolve('repositoryModuleManager');
const validationModuleManager = this.container.resolve('validationModuleManager');

const migration = new PullBlockchainShardingTableMigration(
'pullShardingTableMigrationV612',
this.logger,
this.config,
repositoryModuleManager,
blockchainModuleManager,
validationModuleManager,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
}
}

async executeServiceAgreementsMetadataMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const blockchainModuleManager = this.container.resolve('blockchainModuleManager');
const repositoryModuleManager = this.container.resolve('repositoryModuleManager');
const tripleStoreService = this.container.resolve('tripleStoreService');
const serviceAgreementService = this.container.resolve('serviceAgreementService');
const ualService = this.container.resolve('ualService');

const migration = new ServiceAgreementsMetadataMigration(
'serviceAgreementsMetadataMigration',
this.logger,
this.config,
tripleStoreService,
blockchainModuleManager,
repositoryModuleManager,
serviceAgreementService,
ualService,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
}
}

async executeRemoveAgreementStartEndTimeMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const tripleStoreService = this.container.resolve('tripleStoreService');

const migration = new RemoveAgreementStartEndTimeMigration(
'removeAgreementStartEndTimeMigration',
this.logger,
this.config,
tripleStoreService,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
}
}

async executeTripleStoreMetadataMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;
const blockchainModuleManager = this.container.resolve('blockchainModuleManager');
const tripleStoreService = this.container.resolve('tripleStoreService');
const serviceAgreementService = this.container.resolve('serviceAgreementService');
const ualService = this.container.resolve('ualService');
const dataService = this.container.resolve('dataService');

const migration = new TripleStoreMetadataMigration(
'tripleStoreMetadataMigration',
this.logger,
this.config,
tripleStoreService,
blockchainModuleManager,
serviceAgreementService,
ualService,
dataService,
);

if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
}
}

async executeRemoveOldEpochCommandsMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const repositoryModuleManager = this.container.resolve('repositoryModuleManager');

const migration = new RemoveOldEpochCommandsMigration(
'removeOldEpochCommandsMigration',
this.logger,
this.config,
repositoryModuleManager,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
}
}

async executePendingStorageMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const migration = new PendingStorageMigration(
'pendingStorageMigration',
this.logger,
this.config,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
}
}

async initializeShardingTableService() {
try {
const shardingTableService = this.container.resolve('shardingTableService');
Expand Down Expand Up @@ -533,26 +357,6 @@ class OTNode {
this.logger.info('Stopping node...');
process.exit(code);
}

async executeMarkOldBlockchainEventsAsProcessedMigration() {
if (
process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT ||
process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST
)
return;

const repositoryModuleManager = this.container.resolve('repositoryModuleManager');

const migration = new MarkOldBlockchainEventsAsProcessedMigration(
'markOldBlockchainEventsAsProcessedMigration',
this.logger,
this.config,
repositoryModuleManager,
);
if (!(await migration.migrationAlreadyExecuted())) {
await migration.migrate();
}
}
}

export default OTNode;
24 changes: 24 additions & 0 deletions src/migration/base-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ class BaseMigration {
);
}

async getMigrationInfo() {
const migrationFolderPath = this.fileService.getMigrationFolderPath();
const migrationInfoFileName = `${this.migrationName}_info`;
const migrationInfoPath = path.join(migrationFolderPath, migrationInfoFileName);
let migrationInfo = null;
if (await this.fileService.pathExists(migrationInfoPath)) {
migrationInfo = await this.fileService
.readFile(migrationInfoPath, true)
.catch(() => {});
}
return migrationInfo;
}

async saveMigrationInfo(migrationInfo) {
const migrationFolderPath = this.fileService.getMigrationFolderPath();
const migrationInfoFileName = `${this.migrationName}_info`;
await this.fileService.writeContentsToFile(
migrationFolderPath,
migrationInfoFileName,
JSON.stringify(migrationInfo),
false,
);
}

async executeMigration() {
throw Error('Execute migration method not implemented');
}
Expand Down
Loading
Loading