Skip to content

Commit

Permalink
Merge pull request #19 from beclab/feat/dependences
Browse files Browse the repository at this point in the history
feat: add dependencies preflight, admin preflight and fix install cus…
  • Loading branch information
icebergtsn authored Jun 20, 2024
2 parents cad151f + 2706438 commit b74a367
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 20 deletions.
3 changes: 1 addition & 2 deletions frontend/src/components/appcard/InstallButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ const hoverRef = ref(false);
const textColor = ref<string>();
const backgroundColor = ref<string>();
const border = ref<string>();
let hasCheck = false;
const { t } = useI18n();
let hasCheck = false;
const showDropMenu = computed(() => {
return (
Expand All @@ -177,7 +177,6 @@ const showDropMenu = computed(() => {
props.item.status === APP_STATUS.installed)
);
});
const { color: blueDefault } = useColor('blue-default');
const { color: grey } = useColor('background-3');
const { color: ink3 } = useColor('ink-3');
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/base/BtUploadChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { uploadDevFile } from 'src/api/private/operations';
import { useAppStore } from 'src/stores/app';
import { bus, BUS_EVENT } from 'src/utils/bus';
const uploadInput = ref();
const emit = defineEmits(['onSuccess']);
const appStore = useAppStore();
function openFileInput() {
//clear value before onclick
Expand All @@ -35,7 +33,6 @@ async function uploadFile(event: any) {
if (file) {
const { name, message } = await uploadDevFile(file);
if (name) {
appStore.addDevApplication(name);
emit('onSuccess');
} else {
bus.emit(BUS_EVENT.APP_BACKEND_ERROR, message);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface AppStoreInfo {
requiredCpu: string;
rating: number;
target: string;
namespace: string;
onlyAdmin: boolean;
permission: {
appData: boolean;
appCache: boolean;
Expand All @@ -50,6 +52,7 @@ export interface AppStoreInfo {
ZincSearch: MiddleWareCfg;
};
options: {
mobileSupported: boolean;
analytics: {
enable: boolean;
};
Expand Down Expand Up @@ -172,6 +175,7 @@ export interface UserResource {
}

export interface TerminusResource {
apps: Dependency[];
metrics: {
cpu: Resource;
memory: Resource;
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export default {
network_error: 'Network error, please try again later',
unknown_error: 'Unknown error',
failed_get_user_role: 'Failed to get user role',
only_be_installed_by_the_admin:
'This app can only be installed by the Admin.',
not_admin_role_install_middleware:
'This is a middleware, please contact your Terminus Admin to install.',
not_admin_role_install_cluster_app:
'This is a cluster app, please contact your Terminus Admin to install.',
failed_to_get_os_version: 'Failed to get Terminus Version',
Expand All @@ -171,6 +175,7 @@ export default {
user_not_enough_cpu: 'Not enough required CPU on your quota.',
user_not_enough_memory: 'Not enough required memory on your quota.',
failed_to_get_system_resource: 'Failed to get system resource',
need_to_install_dependent_app_first: 'Need to install dependent app first.',
terminus_not_enough_cpu: 'Not enough required CPU on Terminus cluster.',
terminus_not_enough_memory:
'Not enough required memory on Terminus cluster.',
Expand Down
13 changes: 1 addition & 12 deletions frontend/src/stores/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ export const useAppStore = defineStore('app', {
delete this.tempAppMap[name];
},

//temp function
async addDevApplication(name: string) {
const app = await getApp(name);
if (
app &&
app.source === SOURCE_TYPE.Development &&
app.cfgType === CFG_TYPE.WORK_FLOW
) {
this.installApps.unshift(app);
}
},

async installApp(app: AppStoreInfo, isDev: boolean) {
app.status = APP_STATUS.pending;
app.source = isDev ? SOURCE_TYPE.Development : SOURCE_TYPE.Market;
Expand Down Expand Up @@ -207,6 +195,7 @@ export const useAppStore = defineStore('app', {
break;
case CFG_TYPE.MIDDLEWARE:
this._handleMiddlewareStatus(app, operation, op_status);
break;
}
};

Expand Down
67 changes: 64 additions & 3 deletions frontend/src/stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
APP_STATUS,
AppStoreInfo,
DEPENDENCIES_TYPE,
Dependency,
ROLE_TYPE,
TerminusResource,
User,
Expand All @@ -18,6 +19,7 @@ import {
} from 'src/api/private/user';
import { i18n } from 'src/boot/i18n';
import { TerminusApp } from '@bytetrade/core';
import { CFG_TYPE } from 'src/constants/config';

export type UserState = {
userResource: UserResource | null;
Expand Down Expand Up @@ -73,7 +75,14 @@ export const useUserStore = defineStore('userStore', {
const terminus = this._terminusOSVersionPreflight(app);
const userResource = this._userResourcePreflight(app);
const systemResource = this._systemResourcePreflight(app);
if (role && terminus && userResource && systemResource) {
const appDependencies = this._appDependenciesPreflight(app);
if (
role &&
terminus &&
userResource &&
systemResource &&
appDependencies
) {
app.status = status;
} else {
app.status = APP_STATUS.preflightFailed;
Expand Down Expand Up @@ -102,6 +111,22 @@ export const useUserStore = defineStore('userStore', {
app.preflightError.push(i18n.global.t('error.failed_get_user_role'));
return false;
}

if (app.onlyAdmin && this.user.role !== ROLE_TYPE.Admin) {
app.preflightError.push(
i18n.global.t('error.only_be_installed_by_the_admin')
);
return false;
}
if (
app.cfgType === CFG_TYPE.MIDDLEWARE &&
this.user.role !== ROLE_TYPE.Admin
) {
app.preflightError.push(
i18n.global.t('error.not_admin_role_install_middleware')
);
return false;
}
if (
app.options &&
app.options.appScope &&
Expand All @@ -112,9 +137,8 @@ export const useUserStore = defineStore('userStore', {
i18n.global.t('error.not_admin_role_install_cluster_app')
);
return false;
} else {
return true;
}
return true;
},

_terminusOSVersionPreflight(app: AppStoreInfo): boolean {
Expand Down Expand Up @@ -211,6 +235,43 @@ export const useUserStore = defineStore('userStore', {
return isOK;
},

_appDependenciesPreflight(app: AppStoreInfo): boolean {
if (
app.options &&
app.options.dependencies &&
app.options.dependencies.length > 0
) {
const nameList = this.myApps.map((item) => item.name);
if (
this.systemResource &&
this.systemResource.apps &&
this.systemResource.apps.length > 0
) {
this.systemResource.apps.forEach((app: Dependency) => {
nameList.push(app.name);
});
}
console.log(nameList);

for (let i = 0; i < app.options.dependencies.length; i++) {
const appInfo = app.options.dependencies[i];
if (
appInfo.type === DEPENDENCIES_TYPE.application ||
appInfo.type === DEPENDENCIES_TYPE.middleware
) {
console.log(appInfo.name);
if (!nameList.includes(appInfo.name)) {
app.preflightError.push(
i18n.global.t('error.need_to_install_dependent_app_first')
);
return false;
}
}
}
}
return true;
},

_systemResourcePreflight(app: AppStoreInfo): boolean {
if (
!this.systemResource ||
Expand Down

0 comments on commit b74a367

Please sign in to comment.