flink.vue 17.6 KB
Newer Older
K
khadgarmage 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
<template>
  <div class="flink-model">
    <m-list-box>
      <div slot="text">{{$t('Program Type')}}</div>
      <div slot="content">
        <x-select
                style="width: 130px;"
                v-model="programType"
                :disabled="isDetails">
          <x-option
                  v-for="city in programTypeList"
                  :key="city.code"
                  :value="city.code"
                  :label="city.code">
          </x-option>
        </x-select>
      </div>
    </m-list-box>

    <m-list-box v-if="programType !== 'PYTHON'">
      <div slot="text">{{$t('Main class')}}</div>
      <div slot="content">
        <x-input
                :disabled="isDetails"
                type="input"
                v-model="mainClass"
                :placeholder="$t('Please enter main class')"
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
      <div slot="text">{{$t('Main jar package')}}</div>
      <div slot="content">
51
        <treeselect v-model="mainJar" maxHeight="200" :options="mainJarLists" :disable-branch-nodes="true" :normalizer="normalizer" :disabled="isDetails" :placeholder="$t('Please enter main jar package')">
B
break60 已提交
52 53
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
54 55 56 57 58 59 60
      </div>
    </m-list-box>
    <m-list-box>
      <div slot="text">{{$t('Deploy Mode')}}</div>
      <div slot="content">
        <x-radio-group v-model="deployMode">
          <x-radio :label="'cluster'" :disabled="isDetails"></x-radio>
B
break60 已提交
61
          <x-radio :label="'local'" :disabled="isDetails"></x-radio>
62 63 64
        </x-radio-group>
      </div>
    </m-list-box>
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    <m-list-box>
      <div slot="text">{{$t('Flink Version')}}</div>
      <div slot="content">
        <x-select
          style="width: 100px;"
          v-model="flinkVersion"
          :disabled="isDetails">
          <x-option
            v-for="version in flinkVersionList"
            :key="version.code"
            :value="version.code"
            :label="version.code">
          </x-option>
        </x-select>
      </div>
    </m-list-box>
81 82
    <div class="list-box-4p">
      <div class="clearfix list">
83
        <span class="sp1" style="word-break:break-all">{{$t('jobManagerMemory')}}</span>
84 85
        <span class="sp2">
          <x-input
86 87 88
            :disabled="isDetails"
            type="input"
            v-model="jobManagerMemory"
B
BoYiZhang 已提交
89
            :placeholder="$t('Please enter jobManager memory')"
90 91
            style="width: 200px;"
            autocomplete="off">
92 93
        </x-input>
        </span>
94
        <span class="sp1 sp3">{{$t('taskManagerMemory')}}</span>
95 96
        <span class="sp2">
          <x-input
97 98 99
            :disabled="isDetails"
            type="input"
            v-model="taskManagerMemory"
B
BoYiZhang 已提交
100
            :placeholder="$t('Please enter the taskManager memory')"
101 102
            style="width: 186px;"
            autocomplete="off">
103 104 105 106
        </x-input>
        </span>
      </div>
      <div class="clearfix list">
107
        <span class="sp1">{{$t('slot')}}</span>
108 109 110 111
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
112
                  v-model="slot"
B
BoYiZhang 已提交
113
                  :placeholder="$t('Please enter solt number')"
114 115 116 117
                  style="width: 200px;"
                  autocomplete="off">
        </x-input>
        </span>
118 119
        <div v-if="flinkVersion !== '>=1.10'">
        <span class="sp1 sp3">{{$t('taskManager')}}</span>
120 121 122 123
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
124
                  v-model="taskManager"
B
BoYiZhang 已提交
125
                  :placeholder="$t('Please enter taskManager number')"
126 127 128 129
                  style="width: 186px;"
                  autocomplete="off">
        </x-input>
        </span>
130
        </div>
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
      </div>
    </div>
    <m-list-box>
      <div slot="text">{{$t('Command-line parameters')}}</div>
      <div slot="content">
        <x-input
                :autosize="{minRows:2}"
                :disabled="isDetails"
                type="textarea"
                v-model="mainArgs"
                :placeholder="$t('Please enter Command-line parameters')"
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
      <div slot="text">{{$t('Other parameters')}}</div>
      <div slot="content">
        <x-input
                :disabled="isDetails"
                :autosize="{minRows:2}"
                type="textarea"
                v-model="others"
                :placeholder="$t('Please enter other parameters')">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
      <div slot="text">{{$t('Resources')}}</div>
      <div slot="content">
161
        <treeselect v-model="resourceList" :multiple="true" maxHeight="200" :options="mainJarList" :normalizer="normalizer" :disabled="isDetails" :value-consists-of="valueConsistsOf" :placeholder="$t('Please select resources')">
B
break60 已提交
162 163
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
      </div>
    </m-list-box>
    <m-list-box>
      <div slot="text">{{$t('Custom Parameters')}}</div>
      <div slot="content">
        <m-local-params
                ref="refLocalParams"
                @on-local-params="_onLocalParams"
                :udp-list="localParams"
                :hide="false">
        </m-local-params>
      </div>
    </m-list-box>
  </div>
</template>
<script>
  import _ from 'lodash'
  import i18n from '@/module/i18n'
  import mLocalParams from './_source/localParams'
  import mListBox from './_source/listBox'
  import mResources from './_source/resources'
B
break60 已提交
185 186
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'
187 188 189 190 191 192
  import disabledState from '@/module/mixin/disabledState'

  export default {
    name: 'flink',
    data () {
      return {
B
break60 已提交
193
        valueConsistsOf: 'LEAF_PRIORITY',
194 195 196 197 198
        // Main function class
        mainClass: '',
        // Master jar package
        mainJar: null,
        // Master jar package(List)
B
break60 已提交
199
        mainJarLists: [],
200 201 202 203 204
        mainJarList: [],
        // Deployment method
        deployMode: 'cluster',
        // Resource(list)
        resourceList: [],
205 206
        // Cache ResourceList
        cacheResourceList: [],
207 208 209 210 211 212
        // Custom function
        localParams: [],
        // Driver Number of cores
        slot: 1,
        // Driver Number of memory
        taskManager: '2',
B
BoYiZhang 已提交
213
        // jobManager Memory
214
        jobManagerMemory: '1G',
B
BoYiZhang 已提交
215
        // taskManager Memory
216 217 218 219 220 221 222 223
        taskManagerMemory: '2G',
        // Command line argument
        mainArgs: '',
        // Other parameters
        others: '',
        // Program type
        programType: 'SCALA',
        // Program type(List)
B
break60 已提交
224
        programTypeList: [{ code: 'JAVA' }, { code: 'SCALA' }, { code: 'PYTHON' }],
225 226 227 228 229

        flinkVersion:'<1.10',
        // Flink Versions(List)
        flinkVersionList: [{ code: '<1.10' }, { code: '>=1.10' }],

B
break60 已提交
230 231 232 233
        normalizer(node) {
          return {
            label: node.name
          }
234 235 236
        },
        allNoResources: [],
        noRes: [],
237 238 239 240 241 242 243
      }
    },
    props: {
      backfillItem: Object
    },
    mixins: [disabledState],
    methods: {
244 245 246 247 248 249 250 251 252 253 254 255 256
      /**
       * getResourceId
       */
      marjarId(name) {
        this.store.dispatch('dag/getResourceId',{
          type: 'FILE',
          fullName: '/'+name
        }).then(res => {
          this.mainJar = res.id
        }).catch(e => {
          this.$message.error(e.msg || '')
        })
      },
257 258 259 260 261 262 263 264 265 266 267 268
      /**
       * return localParams
       */
      _onLocalParams (a) {
        this.localParams = a
      },
      /**
       * return resourceList
       */
      _onResourcesData (a) {
        this.resourceList = a
      },
269 270 271 272 273 274
      /**
       * cache resourceList
       */
      _onCacheResourcesData (a) {
        this.cacheResourceList = a
      },
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
      /**
       * verification
       */
      _verification () {
        if (this.programType !== 'PYTHON' && !this.mainClass) {
          this.$message.warning(`${i18n.$t('Please enter main class')}`)
          return false
        }


        if (!this.mainJar) {
          this.$message.warning(`${i18n.$t('Please enter main jar package')}`)
          return false
        }

        if (!this.jobManagerMemory) {
B
BoYiZhang 已提交
291
          this.$message.warning(`${i18n.$t('Please enter jobManager memory')}`)
292 293 294 295
          return false
        }

        if (!Number.isInteger(parseInt(this.jobManagerMemory))) {
B
BoYiZhang 已提交
296
          this.$message.warning(`${i18n.$t('Memory should be a positive integer')}`)
297 298 299 300
          return false
        }

        if (!this.taskManagerMemory) {
B
BoYiZhang 已提交
301
          this.$message.warning(`${i18n.$t('Please enter the taskManager memory')}`)
302 303 304 305 306 307 308 309
          return false
        }

        if (!_.isNumber(parseInt(this.taskManagerMemory))) {
          this.$message.warning(`${i18n.$t('Memory should be a positive integer')}`)
          return false
        }

310 311 312 313 314 315
        // noRes
        if (this.noRes.length>0) {
          this.$message.warning(`${i18n.$t('Please delete all non-existent resources')}`)
          return false
        }

316 317 318 319 320 321 322 323 324
        // localParams Subcomponent verification
        if (!this.$refs.refLocalParams._verifProp()) {
          return false
        }

        // storage
        this.$emit('on-params', {
          mainClass: this.mainClass,
          mainJar: {
B
break60 已提交
325
            id: this.mainJar
326 327
          },
          deployMode: this.deployMode,
B
break60 已提交
328 329 330
          resourceList: _.map(this.resourceList, v => {
            return {id: v}
          }),
331
          localParams: this.localParams,
332
          flinkVersion: this.flinkVersion,
333 334 335 336 337 338 339 340 341 342
          slot: this.slot,
          taskManager: this.taskManager,
          jobManagerMemory: this.jobManagerMemory,
          taskManagerMemory: this.taskManagerMemory,
          mainArgs: this.mainArgs,
          others: this.others,
          programType: this.programType
        })
        return true
      },
B
break60 已提交
343 344 345
      diGuiTree(item) {  // Recursive convenience tree structure
        item.forEach(item => {
          item.children === '' || item.children === undefined || item.children === null || item.children.length === 0?        
B
break60 已提交
346
            this.operationTree(item) : this.diGuiTree(item.children);
347
        })
B
break60 已提交
348
      },
B
break60 已提交
349 350 351 352 353 354
      operationTree(item) {
        if(item.dirctory) {
          item.isDisabled =true
        }
        delete item.children
      },
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
      searchTree(element, id) {
        // 根据id查找节点
        if (element.id == id) {
          return element;
        } else if (element.children != null) {
          var i;
          var result = null;
          for (i = 0; result == null && i < element.children.length; i++) {
            result = this.searchTree(element.children[i], id);
          }
          return result;
        }
        return null;
      },
      dataProcess(backResource) {
        let isResourceId = []
        let resourceIdArr = []
        if(this.resourceList.length>0) {
          this.resourceList.forEach(v=>{
            this.mainJarList.forEach(v1=>{
              if(this.searchTree(v1,v)) {
                isResourceId.push(this.searchTree(v1,v))
              }
            })
          })
          resourceIdArr = isResourceId.map(item=>{
            return item.id
          })
          Array.prototype.diff = function(a) {
            return this.filter(function(i) {return a.indexOf(i) < 0;});
          };
          let diffSet = this.resourceList.diff(resourceIdArr);
          let optionsCmp = []
          if(diffSet.length>0) {
            diffSet.forEach(item=>{
              backResource.forEach(item1=>{
                if(item==item1.id || item==item1.res) {
                  optionsCmp.push(item1)
                }
              })
            })
          }
          let noResources = [{
            id: -1,
B
break60 已提交
399 400
            name: $t('Unauthorized or deleted resources'),
            fullName: '/'+$t('Unauthorized or deleted resources'),
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
            children: []
          }]
          if(optionsCmp.length>0) {
            this.allNoResources = optionsCmp
            optionsCmp = optionsCmp.map(item=>{
              return {id: item.id,name: item.name,fullName: item.res}
            })
            optionsCmp.forEach(item=>{
              item.isNew = true
            })
            noResources[0].children = optionsCmp
            this.mainJarList = this.mainJarList.concat(noResources)
          }
        }
      },
416 417 418 419 420 421 422
    },
    watch: {
      // Listening type
      programType (type) {
        if (type === 'PYTHON') {
          this.mainClass = ''
        }
423 424 425 426 427 428 429 430
      },
      //Watch the cacheParams
      cacheParams (val) {
        this.$emit('on-cache-params', val);
      }
    },
    computed: {
      cacheParams () {
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
        let isResourceId = []
        let resourceIdArr = []
        if(this.resourceList.length>0) {
          this.resourceList.forEach(v=>{
            this.mainJarList.forEach(v1=>{
              if(this.searchTree(v1,v)) {
                isResourceId.push(this.searchTree(v1,v))
              }
            })
          })
          resourceIdArr = isResourceId.map(item=>{
            return {id: item.id,name: item.name,res: item.fullName}
          })
        }
        let result = []
        resourceIdArr.forEach(item=>{
          this.allNoResources.forEach(item1=>{
            if(item.id==item1.id) {
              // resultBool = true
             result.push(item1)
            }
          })
        })
        this.noRes = result
455 456 457
        return {
          mainClass: this.mainClass,
          mainJar: {
B
break60 已提交
458
            id: this.mainJar
459 460
          },
          deployMode: this.deployMode,
461
          resourceList: resourceIdArr,
462 463 464 465 466 467 468 469 470
          localParams: this.localParams,
          slot: this.slot,
          taskManager: this.taskManager,
          jobManagerMemory: this.jobManagerMemory,
          taskManagerMemory: this.taskManagerMemory,
          mainArgs: this.mainArgs,
          others: this.others,
          programType: this.programType
        }
471 472 473
      }
    },
    created () {
B
break60 已提交
474 475 476 477 478 479
        let item = this.store.state.dag.resourcesListS
        let items = this.store.state.dag.resourcesListJar
        this.diGuiTree(item)
        this.diGuiTree(items)
        this.mainJarList = item
        this.mainJarLists = items
480 481 482 483
        let o = this.backfillItem
        // Non-null objects represent backfill
        if (!_.isEmpty(o)) {
          this.mainClass = o.params.mainClass || ''
484 485 486 487 488 489 490
          if(o.params.mainJar.res) {
            this.marjarId(o.params.mainJar.res)
          } else if(o.params.mainJar.res=='') {
            this.mainJar = ''
          } else {
            this.mainJar = o.params.mainJar.id || ''
          }
491
          this.deployMode = o.params.deployMode || ''
492
          this.flinkVersion = o.params.flinkVersion || '<1.10'
493 494 495 496 497
          this.slot = o.params.slot || 1
          this.taskManager = o.params.taskManager || '2'
          this.jobManagerMemory = o.params.jobManagerMemory || '1G'
          this.taskManagerMemory = o.params.taskManagerMemory || '2G'

498

499 500 501 502 503
          this.mainArgs = o.params.mainArgs || ''
          this.others = o.params.others
          this.programType = o.params.programType || 'SCALA'

          // backfill resourceList
504
          let backResource = o.params.resourceList || []
505 506
          let resourceList = o.params.resourceList || []
          if (resourceList.length) {
507
            _.map(resourceList, v => {
508
              if(!v.id) {
509 510 511 512 513
                this.store.dispatch('dag/getResourceId',{
                  type: 'FILE',
                  fullName: '/'+v.res
                }).then(res => {
                  this.resourceList.push(res.id)
514
                  this.dataProcess(backResource)
515
                }).catch(e => {
516 517
                  this.resourceList.push(v.res)
                  this.dataProcess(backResource)
518 519 520
                })
              } else {
                this.resourceList.push(v.id)
521
                this.dataProcess(backResource)
522
              }
B
break60 已提交
523
            })
524
            this.cacheResourceList = resourceList
525 526 527 528 529 530 531 532 533 534 535 536
          }

          // backfill localParams
          let localParams = o.params.localParams || []
          if (localParams.length) {
            this.localParams = localParams
          }
        }
    },
    mounted () {

    },
B
break60 已提交
537
    components: { mLocalParams, mListBox, mResources, Treeselect }
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
  }
</script>

<style lang="scss" rel="stylesheet/scss">
  .flink-model {
    .list-box-4p {
      .list {
        margin-bottom: 14px;
        .sp1 {
          float: left;
          width: 112px;
          text-align: right;
          margin-right: 10px;
          font-size: 14px;
          color: #777;
          display: inline-block;
          padding-top: 6px;
        }
        .sp2 {
          float: left;
          margin-right: 4px;
        }
        .sp3 {
          width: 176px;
        }
      }
    }
  }
566 567 568 569 570 571 572 573
  .vue-treeselect--disabled {
    .vue-treeselect__control {
      background-color: #ecf3f8;
      .vue-treeselect__single-value {
        color: #6d859e;
      }
    }
  }
574
</style>