Skip to content

Commit

Permalink
Feat: support to rollback the application (#657)
Browse files Browse the repository at this point in the history
Signed-off-by: barnettZQG <[email protected]>

Signed-off-by: barnettZQG <[email protected]>
  • Loading branch information
barnettZQG authored Jan 5, 2023
1 parent fec0f1d commit a968348
Show file tree
Hide file tree
Showing 23 changed files with 297 additions and 233 deletions.
212 changes: 62 additions & 150 deletions src/api/application.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { post, get, rdelete, put } from './request';
import {
application_mock,
getApplicationDetails_mock,
getApplicationComponents_mock,
createApplicationComponent_mock,
getComponentDetails_mock,
updateApplication_mock,
getPolicyList_mock,
createPolicy_mock,
getPolicyDetails_mock,
createApplicationTemplate_mock,
createApplicationEnv_mock,
getTraitDefinitionsDetails_mock,
getTraitDefinitions_mock,
getTrait_mock,
updateApplicationEnv_mock,
} from './devLink';
import { application, definition } from './productionLink';

import { application } from './productionLink';
import { getDomain } from '../utils/common';
import type {
ApplicationDeployRequest,
Expand Down Expand Up @@ -45,8 +29,7 @@ interface listRevisionsQuery {
}

const baseURLOject = getDomain();
const isMock = baseURLOject.MOCK;
const url = isMock ? application_mock : application;
const url = baseURLOject.APIBASE + application;

export function getApplicationList(params: ApplicationQuery) {
return get(url, { params: params }).then((res) => res);
Expand All @@ -58,204 +41,141 @@ export function createApplication(params: any) {
}

export function getApplicationDetails(params: any) {
const gurl = isMock ? `${getApplicationDetails_mock}` : `${application}/${params.name}`;
return get(gurl, params).then((res) => res);
return get(`${url}/${params.name}`, params).then((res) => res);
}

export function getApplicationStatus(params: { name: string; envName: string }) {
const gurl = isMock
? `${getApplicationDetails_mock}`
: `${application}/${params.name}/envs/${params.envName}/status`;
return get(gurl, params).then((res) => res);
return get(`${url}/${params.name}/envs/${params.envName}/status`, params).then((res) => res);
}

export function deleteApplicationPlan(params: { name: string }) {
export function deleteApplication(params: { name: string }) {
return rdelete(url + '/' + params.name, params);
}

export function getApplicationComponents(params: { appName: string }) {
const { appName } = params;
const gurl = isMock ? `${getApplicationComponents_mock}` : `${application}/${appName}/components`;
return get(gurl, {}).then((res) => res);
return get(`${url}/${appName}/components`, {}).then((res) => res);
}

export function createApplicationComponent(
params: ApplicationComponentConfig,
query: { appName: string },
) {
const gurl = isMock
? `${createApplicationComponent_mock}`
: `${application}/${query.appName}/components`;
return post(gurl, params).then((res) => res);
return post(`${url}/${query.appName}/components`, params).then((res) => res);
}

export function getComponentDetails(params: any) {
const gurl = isMock
? `${getComponentDetails_mock}`
: `${application}/${params.name}/components/${params.componentName}`;
return post(gurl, params).then((res) => res);
return post(`${url}/${params.name}/components/${params.componentName}`, params).then(
(res) => res,
);
}

export function deployApplication(params: ApplicationDeployRequest, customError?: boolean) {
const gurl = isMock ? `${updateApplication_mock}` : `${application}/${params.appName}/deploy`;
return post(gurl, params, customError);
return post(`${url}/${params.appName}/deploy`, params, customError);
}

export function getPolicyList(params: { appName: string }) {
const gurl = isMock ? `${getPolicyList_mock}` : `${application}/${params.appName}/policies`;
return get(gurl, params).then((res) => res);
return get(`${url}/${params.appName}/policies`, params).then((res) => res);
}

export function createPolicy(appName: string, params: CreatePolicyRequest) {
const gurl = isMock ? `${createPolicy_mock}` : `${application}/${appName}/policies`;
return post(gurl, params).then((res) => res);
return post(`${url}/${appName}/policies`, params).then((res) => res);
}

export function updatePolicy(appName: string, policyName: string, params: UpdatePolicyRequest) {
const gurl = `${application}/${appName}/policies/${policyName}`;
return put(gurl, params).then((res) => res);
return put(`${url}/${appName}/policies/${policyName}`, params).then((res) => res);
}

export function getPolicyDetail(params: { appName: string; policyName: string }) {
const gurl = isMock
? `${getPolicyDetails_mock}`
: `${application}/${params.appName}/policies/${params.policyName}`;
return get(gurl, params).then((res) => res);
return get(`${url}/${params.appName}/policies/${params.policyName}`, params).then((res) => res);
}

export function deletePolicy(params: { appName: string; policyName: string; force?: boolean }) {
const gurl = `${application}/${params.appName}/policies/${params.policyName}`;
const gURL = `${url}/${params.appName}/policies/${params.policyName}`;
if (params.force) {
return rdelete(gurl, { params: { force: true } }, true).then((res) => res);
return rdelete(gURL, { params: { force: true } }, true).then((res) => res);
}
return rdelete(gurl, {}, true).then((res) => res);
return rdelete(gURL, {}, true).then((res) => res);
}

export function createApplicationTemplate(params: any) {
const gurl = isMock
? `${createApplicationTemplate_mock}`
: `${application}/${params.name}/template`;
return post(gurl, params).then((res) => res);
}

export function getComponentDefinitions() {
const gurl = isMock ? `${getPolicyDetails_mock}` : `${definition}`;
return get(gurl, { params: { type: 'component' } }).then((res) => res);
}

export function detailComponentDefinition(params: { name: string }) {
const gurl = isMock ? `${getPolicyDetails_mock}` : `${definition}/${params.name}`;
return get(gurl, { params: { type: 'component' } }).then((res) => res);
}

export function getPolicyDefinitions() {
const gurl = isMock ? `${getPolicyDetails_mock}` : `${definition}`;
return get(gurl, { params: { type: 'policy' } }).then((res) => res);
}

export function detailPolicyDefinition(params: { name: string }) {
const gurl = isMock ? `${getPolicyDetails_mock}` : `${definition}/${params.name}`;
return get(gurl, { params: { type: 'policy' } }).then((res) => res);
return post(`${url}/${params.name}/template`, params).then((res) => res);
}

export function createApplicationEnv(params: { appName?: string }) {
const gurl = isMock ? `${createApplicationEnv_mock}` : `${application}/${params.appName}/envs`;
delete params.appName;
return post(gurl, params).then((res) => res);
return post(`${url}/${params.appName}/envs`, params).then((res) => res);
}

export function updateApplicationEnv(params: { appName?: string; name: string }) {
const gurl = isMock
? `${updateApplicationEnv_mock}`
: `${application}/${params.appName}/envs/${params.name}`;
return put(gurl, params).then((res) => res);
return put(`${url}/${params.appName}/envs/${params.name}`, params).then((res) => res);
}

export function getApplicationEnvbinding(params: { appName: string }) {
return get(`${application}/${params.appName}/envs`, params).then((res) => res);
return get(`${url}/${params.appName}/envs`, params).then((res) => res);
}

export function deleteApplicationEnvbinding(params: { appName: string; envName: string }) {
return rdelete(`${application}/${params.appName}/envs/${params.envName}`, {}).then((res) => res);
return rdelete(`${url}/${params.appName}/envs/${params.envName}`, {}).then((res) => res);
}

export function recycleApplicationEnvbinding(params: { appName: string; envName: string }) {
return post(`${application}/${params.appName}/envs/${params.envName}/recycle`, {}).then(
(res) => res,
);
}

export function getTraitDefinitions(params: { appliedWorkload: string }) {
const gurl = isMock ? `${getTraitDefinitions_mock}` : `${definition}`;
return get(gurl, { params: { type: 'trait', appliedWorkload: params.appliedWorkload } }).then(
(res) => res,
);
}

export function detailTraitDefinition(params: { name: string }) {
const gurl = isMock ? `${getTraitDefinitionsDetails_mock}` : `${definition}/${params.name}`;
return get(gurl, { params: { type: 'trait' } }).then((res) => res);
return post(`${url}/${params.appName}/envs/${params.envName}/recycle`, {}).then((res) => res);
}

export function getApplicationComponent(appName: string, componentName: string) {
const gurl = isMock
? `${getTrait_mock}`
: `${application}/${appName}/components/${componentName}`;
return get(gurl, {}).then((res) => res);
return get(`${url}/${appName}/components/${componentName}`, {}).then((res) => res);
}

export function createTrait(params: Trait, query: TraitQuery) {
const { appName, componentName } = query;
const gurl = isMock
? `${getTrait_mock}`
: `${application}/${appName}/components/${componentName}/traits`;
return post(gurl, params).then((res) => res);
return post(`${url}/${appName}/components/${componentName}/traits`, params).then((res) => res);
}

export function updateTrait(params: Trait, query: TraitQuery) {
const { appName, componentName, traitType } = query;
const gurl = isMock
? `${getTrait_mock}`
: `${application}/${appName}/components/${componentName}/traits/${traitType}`;
return put(gurl, params).then((res) => res);
return put(`${url}/${appName}/components/${componentName}/traits/${traitType}`, params).then(
(res) => res,
);
}

export function deleteTrait(query: TraitQuery) {
const { appName, componentName, traitType } = query;
const gurl = isMock
? `${getTrait_mock}`
: `${application}/${appName}/components/${componentName}/traits/${traitType}`;
return rdelete(gurl, {}).then((res) => res);
return rdelete(`${url}/${appName}/components/${componentName}/traits/${traitType}`, {}).then(
(res) => res,
);
}

export function listRevisions(query: listRevisionsQuery) {
const { appName } = query;
const gurl = isMock ? `${getTrait_mock}` : `${application}/${appName}/revisions`;
return get(gurl, { params: query }).then((res) => res);
return get(`${url}/${appName}/revisions`, { params: query }).then((res) => res);
}

export function detailRevision(query: { appName: string; revision: string }) {
const { appName, revision } = query;
const gurl = isMock ? `${getTrait_mock}` : `${application}/${appName}/revisions/${revision}`;
return get(gurl, {}).then((res) => res);
return get(`${url}/${appName}/revisions/${revision}`, {}).then((res) => res);
}

export function rollbackWithRevision(query: { appName: string; revision: string }) {
const { appName, revision } = query;
return post(`${url}/${appName}/revisions/${revision}/rollback`, {}).then((res) => res);
}

export function getApplicationStatistics(params: { appName: string }) {
return get(`${application}/${params.appName}/statistics`, params).then((res) => res);
return get(`${url}/${params.appName}/statistics`, params).then((res) => res);
}

export function getApplicationWorkflowRecord(params: { appName: string }) {
return get(`${application}/${params.appName}/records`, params).then((res) => res);
return get(`${url}/${params.appName}/records`, params).then((res) => res);
}

export function updateComponentProperties(
params: ApplicationComponentConfig,
query: { appName: string; componentName: string },
) {
const gurl = isMock
? `${getComponentDetails_mock}`
: `${application}/${query.appName}/components/${query.componentName}`;
return put(gurl, params).then((res) => res);
return put(`${url}/${query.appName}/components/${query.componentName}`, params).then(
(res) => res,
);
}

export function resumeApplicationWorkflowRecord(params: {
Expand All @@ -264,10 +184,9 @@ export function resumeApplicationWorkflowRecord(params: {
recordName: string;
}) {
const { appName, workflowName, recordName } = params;
return get(
`${application}/${appName}/workflows/${workflowName}/records/${recordName}/resume`,
{},
).then((res) => res);
return get(`${url}/${appName}/workflows/${workflowName}/records/${recordName}/resume`, {}).then(
(res) => res,
);
}

export function rollbackApplicationWorkflowRecord(params: {
Expand All @@ -276,10 +195,9 @@ export function rollbackApplicationWorkflowRecord(params: {
recordName: string;
}) {
const { appName, workflowName, recordName } = params;
return get(
`${application}/${appName}/workflows/${workflowName}/records/${recordName}/rollback`,
{},
).then((res) => res);
return get(`${url}/${appName}/workflows/${workflowName}/records/${recordName}/rollback`, {}).then(
(res) => res,
);
}

export function terminateApplicationWorkflowRecord(params: {
Expand All @@ -289,47 +207,41 @@ export function terminateApplicationWorkflowRecord(params: {
}) {
const { appName, workflowName, recordName } = params;
return get(
`${application}/${appName}/workflows/${workflowName}/records/${recordName}/terminate`,
`${url}/${appName}/workflows/${workflowName}/records/${recordName}/terminate`,
{},
).then((res) => res);
}

export function getApplicationTriggers(params: { appName: string }) {
const { appName } = params;
const gurl = isMock ? `${getTrait_mock}` : `${application}/${appName}/triggers`;
return get(gurl, {}).then((res) => res);
return get(`${url}/${appName}/triggers`, {}).then((res) => res);
}

export function updateApplication(params: any) {
const _url = isMock ? `${updateApplicationEnv_mock}` : `${application}/${params.name}`;
return put(_url, params).then((res) => res);
return put(`${url}/${params.name}`, params).then((res) => res);
}

export function createTriggers(params: Trigger, query: { appName: string }) {
const { appName } = query;
const gurl = isMock ? `${getTrait_mock}` : `${application}/${appName}/triggers`;
return post(gurl, params).then((res) => res);
return post(`${url}/${appName}/triggers`, params).then((res) => res);
}

export function deleteTriggers(params: { appName: string; token: string }) {
const { appName, token } = params;
const gurl = isMock ? `${getTrait_mock}` : `${application}/${appName}/triggers/${token}`;
return rdelete(gurl, {}).then((res) => res);
return rdelete(`${url}/${appName}/triggers/${token}`, {}).then((res) => res);
}

export function deleteComponent(query: { appName: string; componentName: string }) {
const gurl = isMock
? `${getTrait_mock}`
: `${application}/${query.appName}/components/${query.componentName}`;
return rdelete(gurl, {}).then((res) => res);
return rdelete(`${url}/${query.appName}/components/${query.componentName}`, {}).then(
(res) => res,
);
}

export function compareApplication(appName: string, params: ApplicationCompareRequest) {
const gurl = `${application}/${appName}/compare`;
return post(gurl, params).then((res) => res);
const _url = `${url}/${appName}/compare`;
return post(_url, params).then((res) => res);
}

export function dryRunApplication(appName: string, params: ApplicationDryRunRequest) {
const gurl = `${application}/${appName}/dry-run`;
return post(gurl, params, true).then((res) => res);
return post(`${url}/${appName}/dry-run`, params, true).then((res) => res);
}
Loading

0 comments on commit a968348

Please sign in to comment.