|
|
@@ -5,6 +5,9 @@ import {graphqlUrl} from "../../../config";
|
|
|
import {SHOW_CLOUD} from "../../../gql";
|
|
|
import {request} from 'graphql-request'
|
|
|
import axios from 'axios';
|
|
|
+import {deployAll} from "../../../config";
|
|
|
+import {ADD_APIGWPATH, ADD_APIGROUP, ADD_DEPLOY, ADD_PROJECT} from "../../../gql";
|
|
|
+import {idGen, pushPostfix, removeSpace, shiftPrefix} from "../../../func";
|
|
|
|
|
|
const {Content} = Layout;
|
|
|
axios.defaults.withCredentials = true;
|
|
|
@@ -14,7 +17,8 @@ class DeployCloudChoose extends Component {
|
|
|
super();
|
|
|
this.state = {
|
|
|
userID: 'demo',
|
|
|
- secretId: '',
|
|
|
+ cloudID: 'tencent_CloudID',
|
|
|
+ secretID: '',
|
|
|
secretKey: '',
|
|
|
appId: '',
|
|
|
disabled: false
|
|
|
@@ -34,7 +38,8 @@ class DeployCloudChoose extends Component {
|
|
|
switch (cloud.cloudName) {
|
|
|
case 'tencent':
|
|
|
this.setState({
|
|
|
- secretId: cloud.secretId,
|
|
|
+ cloudID: cloud.id,
|
|
|
+ secretID: cloud.secretId,
|
|
|
secretKey: cloud.secretKey,
|
|
|
appId: cloud.appId
|
|
|
});
|
|
|
@@ -59,10 +64,10 @@ class DeployCloudChoose extends Component {
|
|
|
if (this.props.location && this.props.location.state) {
|
|
|
switch (this.props.location.state.schemaID) {
|
|
|
case 'order_schemaID':
|
|
|
- bucketName = 'order';
|
|
|
+ bucketName = 'appointment';
|
|
|
break;
|
|
|
case 'ecommerce_schemaID':
|
|
|
- bucketName = 'ec';
|
|
|
+ bucketName = 'e-commerce';
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -71,36 +76,145 @@ class DeployCloudChoose extends Component {
|
|
|
if (bucketName === '') {
|
|
|
console.log('state, 没有传值');
|
|
|
} else {
|
|
|
+ let _this = this;
|
|
|
+
|
|
|
// 开始调用
|
|
|
console.log('开始调用');
|
|
|
this.setState({
|
|
|
disabled: true
|
|
|
});
|
|
|
- let _this = this;
|
|
|
- axios.post('http://deploy.ioobot.cn/api/deploy-all',
|
|
|
+
|
|
|
+ let now = new Date().getTime(),
|
|
|
+ functionName = this.state.userID + '_' + bucketName.substr(0, 2) + '_' + now,
|
|
|
+ serviceName = this.state.userID + '_' + bucketName.substr(0, 2) + '_' + now,
|
|
|
+ resources = [`${bucketName}/schema.edn`, `${bucketName}/resolve-map.edn`, `${bucketName}/mongodb/mongo-config.edn`, `${bucketName}/mongodb/deploy-conf.edn`];
|
|
|
+
|
|
|
+ console.log(now, functionName, serviceName, resources);
|
|
|
+ axios.post(deployAll,
|
|
|
{
|
|
|
- 'fc-name': this.state.userID + new Date().getTime(),
|
|
|
+ 'fc-name': functionName,
|
|
|
'bucket': 'native-fc',
|
|
|
'object-file': 'fc-only.zip',
|
|
|
'res-bucket': 'case',
|
|
|
- 'resources': '["appointment/schema.edn" "appointment/resolve-map.edn" "appointment/mongodb/mongo-config.edn" "appointment/mongodb/deploy-conf.edn"]',
|
|
|
- 'service-name': this.state.userID + new Date().getTime(),
|
|
|
+ 'resources': resources,
|
|
|
+ 'service-name': serviceName,
|
|
|
'path': "/*"
|
|
|
})
|
|
|
.then(function (response) {
|
|
|
- _this.setState({
|
|
|
- disabled: false
|
|
|
- });
|
|
|
- _this.props.changeTabBar('my-deploy');
|
|
|
- _this.props.history.push({
|
|
|
- pathname: `/common/deploy`,
|
|
|
- state: {}
|
|
|
- });
|
|
|
+ console.log(response);
|
|
|
+ // 处理数据
|
|
|
+ let result = response['data']['apigw-result'];
|
|
|
+ let apiData = result['api-info'];
|
|
|
+ let serviceData = result['service-info'];
|
|
|
+
|
|
|
+ // 存数据
|
|
|
+ let pathID = idGen('path'),
|
|
|
+ groupID = idGen('group'),
|
|
|
+ deployID = idGen('deploy'),
|
|
|
+ projectID = idGen('project');
|
|
|
+
|
|
|
+ let {apiId, path, method} = apiData;
|
|
|
+ let {serviceName, serviceId, subDomain} = serviceData;
|
|
|
+
|
|
|
+ let {userID, cloudID} = _this.state;
|
|
|
+
|
|
|
+ let pathVarObj = {
|
|
|
+ id: idGen('path'),
|
|
|
+ user_id: userID,
|
|
|
+ apiGWGroup_id: pathID,
|
|
|
+ deploy_id: deployID,
|
|
|
+ apiGWName: functionName,
|
|
|
+ requestMethod: method,
|
|
|
+ apiGWPath: path,
|
|
|
+ apiId: apiId,
|
|
|
+ apiGWDesc: '',
|
|
|
+ serviceType: 'SCF',
|
|
|
+ timeout: 300,
|
|
|
+ createdAt: now,
|
|
|
+ updatedAt: ''
|
|
|
+ };
|
|
|
+
|
|
|
+ let projectVarObj = {
|
|
|
+ id: projectID,
|
|
|
+ projectType: 'case',
|
|
|
+ cloud_id: cloudID,
|
|
|
+ user_id: userID,
|
|
|
+ projectName: functionName,
|
|
|
+ database_id: '',
|
|
|
+ apiGWGroup_id: '',
|
|
|
+ deploy_id: '',
|
|
|
+ case_id: '',
|
|
|
+ wxConfig_id: '',
|
|
|
+ schema_id: '',
|
|
|
+ createdAt: now,
|
|
|
+ updatedAt: '',
|
|
|
+ projectStatus: 'deployed'
|
|
|
+ };
|
|
|
+
|
|
|
+ let groupVarObj = {
|
|
|
+ id: groupID,
|
|
|
+ cloud_id: cloudID,
|
|
|
+ user_id: userID,
|
|
|
+ userStatus: '',
|
|
|
+ userDomain: '',
|
|
|
+ groupName: serviceName,
|
|
|
+ frontType: '',
|
|
|
+ region: '',
|
|
|
+ environmentName: '',
|
|
|
+ defaultDomain: subDomain,
|
|
|
+ status: '',
|
|
|
+ serviceId: serviceId,
|
|
|
+ createdAt: now,
|
|
|
+ updatedAt: ''
|
|
|
+ };
|
|
|
+
|
|
|
+ let deployVarObj = {
|
|
|
+ id: deployID,
|
|
|
+ cloud_id: cloudID,
|
|
|
+ functionName,
|
|
|
+ cosObjectName: '',
|
|
|
+ region: '',
|
|
|
+ cosBucketRegion: '',
|
|
|
+ description: '',
|
|
|
+ cosBucketName: '',
|
|
|
+ vpcId: '',
|
|
|
+ subnetId: '',
|
|
|
+ memorySize: 512,
|
|
|
+ timeout: 300,
|
|
|
+ handler: '',
|
|
|
+ serviceName: "",
|
|
|
+ fc_id: '',
|
|
|
+ createdAt: now,
|
|
|
+ updatedAt: ''
|
|
|
+ };
|
|
|
+
|
|
|
+ let add_apigwpath = request(graphqlUrl, ADD_APIGWPATH, pathVarObj),
|
|
|
+ add_project = request(graphqlUrl, ADD_PROJECT, projectVarObj),
|
|
|
+ add_apigroup = request(graphqlUrl, ADD_APIGROUP, groupVarObj),
|
|
|
+ add_deploy = request(graphqlUrl, ADD_DEPLOY, deployVarObj);
|
|
|
+
|
|
|
+ Promise.all([add_apigwpath, add_project, add_apigroup, add_deploy])
|
|
|
+ .then(value => {
|
|
|
+ console.log(value);
|
|
|
|
|
|
+ // 展示数据
|
|
|
+ _this.setState({
|
|
|
+ disabled: false
|
|
|
+ });
|
|
|
+ _this.props.changeTabBar('my-deploy');
|
|
|
+ _this.props.history.push({
|
|
|
+ pathname: `/common/deploy`,
|
|
|
+ state: {
|
|
|
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
})
|
|
|
.catch(function (error) {
|
|
|
- console.log(error);
|
|
|
+ console.log('axios error', error);
|
|
|
});
|
|
|
}
|
|
|
}
|