Skip to content

Commit

Permalink
[ACS-5845] remove Alfresco Compatibility usage (#8822)
Browse files Browse the repository at this point in the history
* upgrade to latest js-api

* upgrade to latest js-api

* upgrade to latest js-api

* upgrade to latest js-api

* upgrade to latest js-api

* upgrade to latest js-api

* fix security concerns for execSync

* security fix

* fixes as per code reviews

* code fixes for attach file widget dialog

* code fixes

* code fixes

* disable ACS storage check

* add the jira to the commented out block

* remove useless logger call

* code fixes

* code fixes

* code fixes

* code and typing fixes

* fix lint

* disable the code

* try other fixes, add missing headers

* dump error to console

* replace test file with in-memory stream

* code fixes

* simplify checks

* disable upload

* remove useless test and ng-mocks dependency
  • Loading branch information
DenysVuika authored Aug 21, 2023
1 parent d0c35c2 commit 29ec2fc
Show file tree
Hide file tree
Showing 23 changed files with 683 additions and 677 deletions.
71 changes: 37 additions & 34 deletions e2e/protractor/save-remote.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('fs');
const rimraf = require('rimraf');
const path = require('path');
const { spawnSync } = require('node:child_process');
const fs = require('node:fs');
const path = require('node:path');
const TestConfig = require('../test.config');
const AlfrescoApi = require('@alfresco/js-api').AlfrescoApiCompatibility;
const { AlfrescoApi, NodesApi, UploadApi } = require('@alfresco/js-api');

function buildNumber() {
let buildNumber = process.env.GH_BUILD_NUMBER;
Expand All @@ -16,54 +16,57 @@ function buildNumber() {
async function uploadScreenshot(retryCount, suffixFileName) {
console.log(`Start uploading report ${retryCount}`);

let alfrescoJsApi = new AlfrescoApi({
const alfrescoJsApi = new AlfrescoApi({
provider: 'ECM',
hostEcm: TestConfig.screenshot.url
});

const nodesApi = new NodesApi(alfrescoJsApi);
const uploadApi = new UploadApi(alfrescoJsApi);

await alfrescoJsApi.login(TestConfig.users.screenshot.username, TestConfig.users.screenshot.password);

let folderNode;

try {
folderNode = await alfrescoJsApi.nodes.addNode('-my-', {
'name': `retry-${retryCount}`,
'relativePath': `Builds/${buildNumber()}/`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
folderNode = await nodesApi.createNode(
'-my-',
{
name: `retry-${retryCount}`,
relativePath: `Builds/${buildNumber()}/`,
nodeType: 'cm:folder'
},
{},
{
overwrite: true
}
);
} catch (error) {
folderNode = await alfrescoJsApi.nodes.getNode('-my-', {
'relativePath': `Builds/${buildNumber()}/retry-${retryCount}`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
folderNode = await nodesApi.getNode('-my-', {
relativePath: `Builds/${buildNumber()}/retry-${retryCount}`
});
}

suffixFileName = suffixFileName.replace(/\//g, '-');

fs.renameSync(path.resolve(__dirname, '../../e2e-output/'), path.resolve(__dirname, `../../e2e-output-${retryCount}-${process.env.GH_ACTION_RETRY_COUNT}/`))
fs.renameSync(
path.resolve(__dirname, '../../e2e-output/'),
path.resolve(__dirname, `../../e2e-output-${retryCount}-${process.env.GH_ACTION_RETRY_COUNT}/`)
);

const child_process = require("child_process");
child_process.execSync(` tar -czvf ../e2e-result-${suffixFileName}-${retryCount}.tar .`, {
cwd: path.resolve(__dirname, `../../e2e-output-${retryCount}-${process.env.GH_ACTION_RETRY_COUNT}/`)
spawnSync(` tar -czvf ../e2e-result-${suffixFileName}-${retryCount}.tar .`, {
cwd: path.resolve(__dirname, `../../e2e-output-${retryCount}-${process.env.GH_ACTION_RETRY_COUNT}/`),
shell: false
});

let pathFile = path.join(__dirname, `../../e2e-result-${suffixFileName}-${retryCount}.tar`);
let file = fs.createReadStream(pathFile);
await alfrescoJsApi.upload.uploadFile(
file,
'',
folderNode.entry.id,
null,
{
'name': `e2e-result-${suffixFileName}-${retryCount}.tar`,
'nodeType': 'cm:content',
'autoRename': true
}
);
const pathFile = path.join(__dirname, `../../e2e-result-${suffixFileName}-${retryCount}.tar`);
const file = fs.createReadStream(pathFile);

await uploadApi.uploadFile(file, '', folderNode.entry.id, null, {
name: `e2e-result-${suffixFileName}-${retryCount}.tar`,
nodeType: 'cm:content',
autoRename: true
});
}

module.exports = {
Expand Down
108 changes: 47 additions & 61 deletions lib/cli/scripts/check-cs-env.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
/* eslint-disable */
const alfrescoApi = require('@alfresco/js-api');
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { AlfrescoApi, NodesApi, UploadApi } from '@alfresco/js-api';
import { argv, exit } from 'node:process';
import { Buffer } from 'node:buffer';
const program = require('commander');
const path = require('path');
const fs = require('fs');
/* eslint-enable */
import { logger } from './logger';
const MAX_RETRY = 3;
const TIMEOUT = 20000;
let counter = 0;
let alfrescoJsApi: AlfrescoApi;

export default async function main(_args: string[]) {

program
.version('0.1.0')
.description('Check Content service is up ')
Expand All @@ -20,88 +35,60 @@ export default async function main(_args: string[]) {
.option('-u, --username [type]', 'username ')
.option('-t, --time [type]', 'time ')
.option('-r, --retry [type]', 'retry ')
.parse(process.argv);
.parse(argv);

await checkEnv();
await checkDiskSpaceFullEnv();
// TODO: https://alfresco.atlassian.net/browse/ACS-5873
// await checkDiskSpaceFullEnv();
}

async function checkEnv() {
try {
const alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
alfrescoJsApi = new AlfrescoApi({
provider: 'ECM',
hostEcm: program.host
hostEcm: program.host,
contextRoot: 'alfresco'
});

await alfrescoJsApi.login(program.username, program.password);
} catch (error) {
if (error?.error?.code === 'ETIMEDOUT') {
logger.error('The env is not reachable. Terminating');
process.exit(1);
exit(1);
}
logger.error('Login error environment down or inaccessible');
counter++;
const retry = program.retry || MAX_RETRY;
const time = program.time || TIMEOUT;
if (retry === counter) {
logger.error('Give up');
process.exit(1);
exit(1);
} else {
logger.error(`Retry in 1 minute attempt N ${counter}`, error);
sleep(time);
checkEnv();
await checkEnv();
}
}
}

// @ts-ignore
async function checkDiskSpaceFullEnv() {
logger.info(`Start Check disk full space`);

try {
const nodesApi = new NodesApi(alfrescoJsApi);
const uploadApi = new UploadApi(alfrescoJsApi);

const alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
provider: 'ECM',
hostEcm: program.host
});

await alfrescoJsApi.login(program.username, program.password);

let folder;

try {
folder = await alfrescoJsApi.nodes.addNode('-my-', {
name: `try-env`,
relativePath: `Builds`,
nodeType: 'cm:folder'
}, {}, {
overwrite: true
});
const fileContent = 'x'.repeat(1024 * 1024);
const file = Buffer.from(fileContent, 'utf8');

} catch (error) {
folder = await alfrescoJsApi.nodes.getNode('-my-', {
relativePath: `Builds/try-env`,
nodeType: 'cm:folder'
}, {}, {
overwrite: true
});
}
const pathFile = path.join(__dirname, '../', 'README.md');

const file = fs.createReadStream(pathFile);

const uploadedFile = await alfrescoJsApi.upload.uploadFile(
file,
'',
folder.entry.id,
null,
{
name: 'README.md',
nodeType: 'cm:content',
autoRename: true
}
);
const uploadedFile = await uploadApi.uploadFile(file, '', '-my-', null, {
name: 'README.md',
nodeType: 'cm:content',
autoRename: true
});

alfrescoJsApi.node.deleteNode(uploadedFile.entry.id, {permanent: true});
await nodesApi.deleteNode(uploadedFile.entry.id, { permanent: true });
} catch (error) {
counter++;

Expand All @@ -112,18 +99,17 @@ async function checkDiskSpaceFullEnv() {
logger.info('================ Not able to upload a file ==================');
logger.info('================ Possible cause CS is full ==================');
logger.info('=============================================================');
process.exit(1);
exit(1);
} else {
logger.error(`Retry N ${counter} ${error?.error?.status}`);
logger.error(`Retry N ${counter}`);
logger.error(JSON.stringify(error));
sleep(time);
checkDiskSpaceFullEnv();
await checkDiskSpaceFullEnv();
}

}

}

function sleep(delay) {
function sleep(delay: number) {
const start = new Date().getTime();
while (new Date().getTime() < start + delay) { }
while (new Date().getTime() < start + delay) {}
}
40 changes: 28 additions & 12 deletions lib/cli/scripts/check-ps-env.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,69 @@
/* eslint-disable */
const alfrescoApi = require('@alfresco/js-api');
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { AlfrescoApi } from '@alfresco/js-api';
import { exit, argv } from 'node:process';
const program = require('commander');
/* eslint-enable */
import { logger } from './logger';
const MAX_RETRY = 10;
const TIMEOUT = 60000;
let counter = 0;

export default async function main(_args: string[]) {

program
.version('0.1.0')
.description('Check Process service is up ')
.usage('check-ps-env [options]')
.option('--host [type]', 'Remote environment host adf.lab.com ')
.option('-p, --password [type]', 'password ')
.option('-u, --username [type]', 'username ')
.parse(process.argv);
.parse(argv);

await checkEnv();
}

async function checkEnv() {
try {
const alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
const alfrescoJsApi = new AlfrescoApi({
provider: 'BPM',
hostBpm: program.host
hostBpm: program.host,
contextRoot: 'alfresco'
});

await alfrescoJsApi.login(program.username, program.password);
} catch (e) {
if (e.error.code === 'ETIMEDOUT') {
logger.error('The env is not reachable. Terminating');
process.exit(1);
exit(1);
}
logger.error('Login error environment down or inaccessible');
counter++;
if (MAX_RETRY === counter) {
logger.error('Give up');
process.exit(1);
exit(1);
} else {
logger.error(`Retry in 1 minute attempt N ${counter}`);
sleep(TIMEOUT);
checkEnv();
await checkEnv();
}
}
}

function sleep(delay) {
function sleep(delay: number) {
const start = new Date().getTime();
while (new Date().getTime() < start + delay) { }
while (new Date().getTime() < start + delay) {}
}
Loading

0 comments on commit 29ec2fc

Please sign in to comment.