Skip to content

Commit

Permalink
[CE-146] Add host management page
Browse files Browse the repository at this point in the history
Change build-js, npm-install support for react, vue

Change-Id: I31d6bace040491de4fc03bb4d8d149c840117f67
Signed-off-by: Haitao Yue <[email protected]>
  • Loading branch information
hightall committed Sep 26, 2017
1 parent ea7e212 commit 41a7a30
Show file tree
Hide file tree
Showing 15 changed files with 623 additions and 33 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ else
SED = sed -i
endif

ifeq (${THEME}, react)
ifneq ($(wildcard ./src/themes/react/static/node_modules),)
ifneq (${THEME}, basic)
ifneq ($(wildcard ./src/${STATIC_FOLDER}/node_modules),)
INSTALL_NPM=
else
INSTALL_NPM=npm-install
endif
ifneq ($(wildcard ./src/themes/react/static/js/dist),)
ifneq ($(wildcard ./src/${STATIC_FOLDER}/js/dist),)
BUILD_JS=
else
BUILD_JS=build-js
Expand Down Expand Up @@ -107,8 +107,8 @@ setup-master: ##@Environment Setup dependency for master node
setup-worker: ##@Environment Setup dependency for worker node
cd scripts/worker_node && bash setup.sh

build-js: ##@Nodejs Build js files for vue
bash scripts/master_node/build_vuejs.sh
build-js: ##@Nodejs Build js files
bash scripts/master_node/build_js.sh

watch-mode: ##@Nodejs Run watch mode with js files for react
bash scripts/master_node/watch_mode.sh
Expand Down
5 changes: 2 additions & 3 deletions docker-compose-build-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ services:
# cello dashboard service
build-js:
image: node
container_name: build-js
volumes: # This should be removed in product env
- ./src/themes/vue/static:/app
- ./src/themes/vue/templates:/app/templates
- ./src/$STATIC_FOLDER:/app
- ./src/$TEMPLATE_FOLDER:/app/templates
command: bash -c "cd /app && npm run build"
3 changes: 1 addition & 2 deletions docker-compose-npm-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ services:
# cello dashboard service
npm-install:
image: node
container_name: npm-install
volumes: # This should be removed in product env
- ./src/themes/vue/static:/app
- ./src/$STATIC_FOLDER:/app
environment:
- NPM_REGISTRY=$NPM_REGISTRY
command: bash -c "cd /app && npm install --loglevel http --registry https://$NPM_REGISTRY"
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ else
fi


echo_b "Start build react js files..."
docker-compose -f docker-compose-build-js.yml up --no-recreate
echo_b "Start build js files..."
docker-compose -f docker-compose-build-js.yml up --force-recreate

#echo "Restarting mongo_express"
#[[ "$(docker ps -q --filter='name=mongo_express')" != "" ]] && docker restart mongo_express
2 changes: 1 addition & 1 deletion scripts/master_node/npm_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fi


echo_b "Start install npm packages..."
docker-compose -f docker-compose-npm-install.yml up --no-recreate
docker-compose -f docker-compose-npm-install.yml up --force-recreate

#echo "Restarting mongo_express"
#[[ "$(docker ps -q --filter='name=mongo_express')" != "" ]] && docker restart mongo_express
1 change: 1 addition & 0 deletions src/themes/vue/static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"axios": "^0.16.2",
"vue-echarts": "*",
"moment": "^2.18.1",
"qs": "^6.5.1",
"vuex-router-sync": "^4.1.2"
},
"devDependencies": {
Expand Down
36 changes: 36 additions & 0 deletions src/themes/vue/static/src/api/host.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

/* Copyright IBM Corp, All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
import axios from 'axios'
import Urls from '@/config/Urls'
import qs from 'qs'

export default {
getHosts (params, cb) {
axios.get(Urls.host.list, {params: params}).then(res => {
cb(res.data)
})
},
deleteHost (params, cb) {
axios.delete(Urls.host.delete, {data: params}).then(res => {
cb(res.data)
})
},
operateHost (params, cb) {
axios.post(Urls.host.operation, qs.stringify(params)).then(res => {
cb(res.data)
})
},
updateHost (params, cb) {
axios.put(Urls.host.update, qs.stringify(params)).then(res => {
cb(res.data)
})
},
createHost (params, cb) {
axios.post(Urls.host.create, qs.stringify(params)).then(res => {
cb(res.data)
})
}
}
25 changes: 25 additions & 0 deletions src/themes/vue/static/src/config/Urls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

/* Copyright IBM Corp, All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

const apiBase = '/api'
export default {
overview: {
stat: apiBase + '/stat'
},
host: {
list: apiBase + '/hosts',
create: apiBase + '/host',
delete: apiBase + '/host',
update: apiBase + '/host',
operation: apiBase + '/host_op'
},
cluster: {
list: apiBase + '/clusters',
create: apiBase + '/cluster',
delete: apiBase + '/cluster',
operation: apiBase + '/cluster_op'
}
}
169 changes: 169 additions & 0 deletions src/themes/vue/static/src/pages/Host/HostModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@

<!-- Copyright IBM Corp, All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
-->
<template>
<Modal
v-model="visible"
:title="title"
ok-text="OK"
cancel-text="Cancel">
<Form ref="hostForm" :model="formItem" :rules="ruleValidate" :label-width="80">
<FormItem label="Host Name" prop="name" :label-width="100">
<Input type="text" :readonly="type === 'update'" v-model="formItem.name" placeholder="Input host name" />
</FormItem>
<FormItem prop="worker_api" :label-width="100">
<label slot="label">
URL
<Tooltip placement="top-end">
<Icon type="help-circled" />
<div slot="content">
<p>Input the node ip and port</p>
<p>example: 192.168.1.1:6527</p>
</div>
</Tooltip>
</label>
<Input :readonly="type === 'update'" v-model="formItem.worker_api">
<span slot="prepend">tcp://</span>
</Input>
</FormItem>
<FormItem label="Capacity" :label-width="100">
<InputNumber :min="1" v-model="formItem.capacity"></InputNumber>
</FormItem>
<FormItem label="Log Level" prop="log_level" :label-width="100">
<Select v-model="formItem.log_level" placeholder="Select log level">
<Option value="DEBUG">DEBUG</Option>
<Option value="INFO">INFO</Option>
<Option value="NOTICE">NOTICE</Option>
<Option value="WARNING">WARNING</Option>
<Option value="ERROR">ERROR</Option>
<Option value="CRITICAL">CRITICAL</Option>
</Select>
</FormItem>
<FormItem label="Log Type" prop="log_type" :label-width="100">
<Select v-model="formItem.log_type" placeholder="Select log type">
<Option value="local">LOCAL</Option>
<Option value="syslog">SYSLOG</Option>
</Select>
</FormItem>
<FormItem v-if="formItem.log_type === 'syslog'" label="Log Server" :label-width="100">
<Input v-model="formItem.log_server" />
</FormItem>
<FormItem :label-width="100">
<label slot="label">
Schedulable
<Tooltip placement="top-end">
<Icon type="help-circled" />
<div slot="content">
Schedulable for cluster request
</div>
</Tooltip>
</label>
<i-switch v-model="formItem.schedulable" size="large">
<span v-for="item in switchChoices" :slot="item.value">{{ item.label }}</span>
</i-switch>
</FormItem>
<FormItem :label-width="100">
<label slot="label">
Keep filed
<Tooltip placement="top-end">
<Icon type="help-circled" />
<div slot="content">
Keep filled with cluster
</div>
</Tooltip>
</label>
<i-switch v-model="formItem.autofill" size="large">
<span v-for="item in switchChoices" :slot="item.value">{{ item.label }}</span>
</i-switch>
</FormItem>
</Form>
<div slot="footer">
<Button type="text" @click="hideModal">Cancel</Button>
<Button type="primary" :loading="submitting" @click="submitForm">Ok</Button>
</div>
</Modal>
</template>

<script>
import { mapActions } from 'vuex'
export default {
props: ['type', 'visible', 'onCancel', 'formItem', 'onOk', 'host'],
data () {
const validateName = (rule, value, callback) => {
callback()
}
return {
ruleValidate: {
name: [
{ required: true, message: 'Please input Host name', trigger: 'blur' },
{ validator: validateName, trigger: 'blur' }
],
worker_api: [
{ required: true, message: 'Please input URL', trigger: 'blur' }
],
log_level: [
{ required: true, message: 'Please Select a log level', trigger: 'blur' }
],
log_type: [
{ required: true, message: 'Please Select a log type', trigger: 'blur' }
]
},
switchChoices: [
{
value: true,
label: 'Yes'
},
{
value: false,
label: 'No'
}
]
}
},
computed: {
title () {
if (this.type === 'create') {
return 'Create Host'
} else {
return 'Edit Host'
}
}
},
methods: {
...mapActions([
'updateHost',
'createHost'
]),
hideModal () {
this.$refs['hostForm'].resetFields()
this.onCancel()
},
submitForm () {
this.$refs['hostForm'].validate((valid) => {
this.submitting = true
if (valid) {
this.formItem.schedulable = this.formItem.schedulable ? 'true' : 'false'
this.formItem.autofill = this.formItem.autofill ? 'true' : 'false'
if (this.type === 'create') {
this.createHost(this.formItem)
this.submitting = false
this.onCancel()
} else if (this.type === 'update') {
this.formItem.id = this.host.id
this.updateHost(this.formItem)
this.submitting = false
this.onCancel()
}
} else {
this.submitting = false
}
})
}
}
}
</script>

<style>
</style>
Loading

0 comments on commit 41a7a30

Please sign in to comment.