spark.vue 16.0 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.
 */
L
ligang 已提交
17 18 19
<template>
  <div class="spark-model">
    <m-list-box>
G
i18n  
gongzijian 已提交
20
      <div slot="text">{{$t('Program Type')}}</div>
L
ligang 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34
      <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>
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    <m-list-box>
      <div slot="text">{{$t('Spark Version')}}</div>
      <div slot="content">
        <x-select
                style="width: 130px;"
                v-model="sparkVersion"
                :disabled="isDetails">
          <x-option
                  v-for="city in sparkVersionList"
                  :key="city.code"
                  :value="city.code"
                  :label="city.code">
          </x-option>
        </x-select>
      </div>
    </m-list-box>
L
ligang 已提交
51
    <m-list-box v-if="programType !== 'PYTHON'">
G
i18n  
gongzijian 已提交
52
      <div slot="text">{{$t('Main class')}}</div>
L
ligang 已提交
53 54 55 56 57
      <div slot="content">
        <x-input
                :disabled="isDetails"
                type="input"
                v-model="mainClass"
G
i18n  
gongzijian 已提交
58
                :placeholder="$t('Please enter main class')"
L
ligang 已提交
59 60 61 62 63
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
64
      <div slot="text">{{$t('Main jar package')}}</div>
L
ligang 已提交
65
      <div slot="content">
B
break60 已提交
66 67 68
        <treeselect v-model="mainJar" :options="mainJarLists" :disable-branch-nodes="true" :normalizer="normalizer" :placeholder="$t('Please enter main jar package')">
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
L
ligang 已提交
69 70 71
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
72
      <div slot="text">{{$t('Deploy Mode')}}</div>
L
ligang 已提交
73 74 75 76 77 78 79 80 81 82
      <div slot="content">
        <x-radio-group v-model="deployMode">
          <x-radio :label="'cluster'" :disabled="isDetails"></x-radio>
          <x-radio :label="'client'" :disabled="isDetails"></x-radio>
          <x-radio :label="'local'" :disabled="isDetails"></x-radio>
        </x-radio-group>
      </div>
    </m-list-box>
    <div class="list-box-4p">
      <div class="clearfix list">
G
i18n  
gongzijian 已提交
83
        <span class="sp1">{{$t('Driver core number')}}</span>
L
ligang 已提交
84 85 86 87 88
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="driverCores"
G
i18n  
gongzijian 已提交
89
                  :placeholder="$t('Please enter driver core number')"
L
ligang 已提交
90 91 92 93
                  style="width: 200px;"
                  autocomplete="off">
        </x-input>
        </span>
G
i18n  
gongzijian 已提交
94
        <span class="sp1 sp3">{{$t('Driver memory use')}}</span>
L
ligang 已提交
95 96 97 98 99
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="driverMemory"
G
i18n  
gongzijian 已提交
100
                  :placeholder="$t('Please enter driver memory use')"
L
ligang 已提交
101 102 103 104 105 106
                  style="width: 186px;"
                  autocomplete="off">
        </x-input>
        </span>
      </div>
      <div class="clearfix list">
G
i18n  
gongzijian 已提交
107
        <span class="sp1">{{$t('Number of Executors')}}</span>
L
ligang 已提交
108 109 110 111 112
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="numExecutors"
G
i18n  
gongzijian 已提交
113
                  :placeholder="$t('Please enter the number of Executor')"
L
ligang 已提交
114 115 116 117
                  style="width: 200px;"
                  autocomplete="off">
        </x-input>
        </span>
G
i18n  
gongzijian 已提交
118
        <span class="sp1 sp3">{{$t('Executor memory')}}</span>
L
ligang 已提交
119 120 121 122 123
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="executorMemory"
G
i18n  
gongzijian 已提交
124
                  :placeholder="$t('Please enter the Executor memory')"
L
ligang 已提交
125 126 127 128 129 130
                  style="width: 186px;"
                  autocomplete="off">
        </x-input>
        </span>
      </div>
      <div class="clearfix list">
G
i18n  
gongzijian 已提交
131
        <span class="sp1">{{$t('Executor core number')}}</span>
L
ligang 已提交
132 133 134 135 136
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="executorCores"
G
i18n  
gongzijian 已提交
137
                  :placeholder="$t('Please enter Executor core number')"
L
ligang 已提交
138 139 140 141 142 143 144
                  style="width: 200px;"
                  autocomplete="off">
          </x-input>
        </span>
      </div>
    </div>
    <m-list-box>
G
i18n  
gongzijian 已提交
145
      <div slot="text">{{$t('Command-line parameters')}}</div>
L
ligang 已提交
146 147 148 149 150 151
      <div slot="content">
        <x-input
                :autosize="{minRows:2}"
                :disabled="isDetails"
                type="textarea"
                v-model="mainArgs"
G
i18n  
gongzijian 已提交
152
                :placeholder="$t('Please enter Command-line parameters')"
L
ligang 已提交
153 154 155 156 157
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
158
      <div slot="text">{{$t('Other parameters')}}</div>
L
ligang 已提交
159 160 161 162 163 164
      <div slot="content">
        <x-input
                :disabled="isDetails"
                :autosize="{minRows:2}"
                type="textarea"
                v-model="others"
G
i18n  
gongzijian 已提交
165
                :placeholder="$t('Please enter other parameters')">
L
ligang 已提交
166 167 168 169
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
B
break60 已提交
170 171
      <div slot="text">{{$t('Resources')}}</div>
      <div slot="content">
B
break60 已提交
172
        <treeselect v-model="resourceList" :multiple="true" :options="mainJarList" :normalizer="normalizer" :value-consists-of="valueConsistsOf" :placeholder="$t('Please select resources')">
B
break60 已提交
173 174 175 176 177
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
      </div>
    </m-list-box>
    <!-- <m-list-box>
G
i18n  
gongzijian 已提交
178
      <div slot="text">{{$t('Resources')}}</div>
L
ligang 已提交
179 180 181 182
      <div slot="content">
        <m-resources
                ref="refResources"
                @on-resourcesData="_onResourcesData"
183
                @on-cache-resourcesData="_onCacheResourcesData"
L
ligang 已提交
184 185 186
                :resource-list="resourceList">
        </m-resources>
      </div>
B
break60 已提交
187
    </m-list-box> -->
L
ligang 已提交
188
    <m-list-box>
G
i18n  
gongzijian 已提交
189
      <div slot="text">{{$t('Custom Parameters')}}</div>
L
ligang 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
      <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 已提交
207 208
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'
L
ligang 已提交
209 210 211 212 213 214
  import disabledState from '@/module/mixin/disabledState'

  export default {
    name: 'spark',
    data () {
      return {
B
break60 已提交
215
        valueConsistsOf: 'LEAF_PRIORITY',
L
ligang 已提交
216 217 218 219 220
        // Main function class
        mainClass: '',
        // Master jar package
        mainJar: null,
        // Master jar package(List)
B
break60 已提交
221
        mainJarLists: [],
L
ligang 已提交
222 223 224 225 226
        mainJarList: [],
        // Deployment method
        deployMode: 'cluster',
        // Resource(list)
        resourceList: [],
227 228
        // Cache ResourceList
        cacheResourceList: [],
L
ligang 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
        // Custom function
        localParams: [],
        // Driver Number of cores
        driverCores: 1,
        // Driver Number of memory
        driverMemory: '512M',
        // Executor Number
        numExecutors: 2,
        // Executor Number of memory
        executorMemory: '2G',
        // Executor Number of cores
        executorCores: 2,
        // Command line argument
        mainArgs: '',
        // Other parameters
        others: '',
        // Program type
        programType: 'SCALA',
        // Program type(List)
248 249 250 251
        programTypeList: [{ code: 'JAVA' }, { code: 'SCALA' }, { code: 'PYTHON' }],
        // Spark version
        sparkVersion: 'SPARK2',
        // Spark version(LIst)
B
break60 已提交
252 253 254 255 256 257
        sparkVersionList: [{ code: 'SPARK2' }, { code: 'SPARK1' }],
        normalizer(node) {
          return {
            label: node.name
          }
        }
L
ligang 已提交
258 259 260 261 262 263 264
      }
    },
    props: {
      backfillItem: Object
    },
    mixins: [disabledState],
    methods: {
265 266 267 268 269 270 271 272 273 274 275 276 277
      /**
       * 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 || '')
        })
      },
L
ligang 已提交
278 279 280 281 282 283 284 285 286 287 288 289
      /**
       * return localParams
       */
      _onLocalParams (a) {
        this.localParams = a
      },
      /**
       * return resourceList
       */
      _onResourcesData (a) {
        this.resourceList = a
      },
290 291 292 293 294 295
      /**
       * cache resourceList
       */
      _onCacheResourcesData (a) {
        this.cacheResourceList = a
      },
B
break60 已提交
296 297 298
      diGuiTree(item) {  // Recursive convenience tree structure
        item.forEach(item => {
          item.children === '' || item.children === undefined || item.children === null || item.children.length === 0?        
B
break60 已提交
299
            this.operationTree(item) : this.diGuiTree(item.children);
B
break60 已提交
300 301
        })
      },
B
break60 已提交
302 303 304 305 306 307
      operationTree(item) {
        if(item.dirctory) {
          item.isDisabled =true
        }
        delete item.children
      },
L
ligang 已提交
308 309 310 311 312
      /**
       * verification
       */
      _verification () {
        if (this.programType !== 'PYTHON' && !this.mainClass) {
G
i18n  
gongzijian 已提交
313
          this.$message.warning(`${i18n.$t('Please enter main class')}`)
L
ligang 已提交
314 315 316 317
          return false
        }

        if (!this.mainJar) {
G
i18n  
gongzijian 已提交
318
          this.$message.warning(`${i18n.$t('Please enter main jar package')}`)
L
ligang 已提交
319 320 321 322
          return false
        }

        if (!this.numExecutors) {
G
i18n  
gongzijian 已提交
323
          this.$message.warning(`${i18n.$t('Please enter the number of Executor')}`)
L
ligang 已提交
324 325 326 327
          return false
        }

        if (!Number.isInteger(parseInt(this.numExecutors))) {
G
i18n  
gongzijian 已提交
328
          this.$message.warning(`${i18n.$t('The number of Executors should be a positive integer')}`)
L
ligang 已提交
329 330 331 332
          return false
        }

        if (!this.executorMemory) {
G
i18n  
gongzijian 已提交
333
          this.$message.warning(`${i18n.$t('Please enter the Executor memory')}`)
L
ligang 已提交
334 335 336 337
          return false
        }

        if (!this.executorMemory) {
G
i18n  
gongzijian 已提交
338
          this.$message.warning(`${i18n.$t('Please enter the Executor memory')}`)
L
ligang 已提交
339 340 341 342
          return false
        }

        if (!_.isNumber(parseInt(this.executorMemory))) {
G
i18n  
gongzijian 已提交
343
          this.$message.warning(`${i18n.$t('Memory should be a positive integer')}`)
L
ligang 已提交
344 345 346 347
          return false
        }

        if (!this.executorCores) {
G
i18n  
gongzijian 已提交
348
          this.$message.warning(`${i18n.$t('Please enter ExecutorPlease enter Executor core number')}`)
L
ligang 已提交
349 350 351 352
          return false
        }

        if (!Number.isInteger(parseInt(this.executorCores))) {
G
i18n  
gongzijian 已提交
353
          this.$message.warning(`${i18n.$t('Core number should be positive integer')}`)
L
ligang 已提交
354 355 356 357 358 359
          return false
        }
        // localParams Subcomponent verification
        if (!this.$refs.refLocalParams._verifProp()) {
          return false
        }
B
break60 已提交
360 361 362 363 364 365
        // Process resourcelist
        let dataProcessing= _.map(this.resourceList, v => {
          return {
            id: v
          }
        })
L
ligang 已提交
366 367 368 369 370

        // storage
        this.$emit('on-params', {
          mainClass: this.mainClass,
          mainJar: {
B
break60 已提交
371
            id: this.mainJar
L
ligang 已提交
372 373
          },
          deployMode: this.deployMode,
B
break60 已提交
374
          resourceList: dataProcessing,
L
ligang 已提交
375 376 377 378 379 380 381 382
          localParams: this.localParams,
          driverCores: this.driverCores,
          driverMemory: this.driverMemory,
          numExecutors: this.numExecutors,
          executorMemory: this.executorMemory,
          executorCores: this.executorCores,
          mainArgs: this.mainArgs,
          others: this.others,
383 384
          programType: this.programType,
          sparkVersion: this.sparkVersion
L
ligang 已提交
385 386 387 388 389 390 391 392 393 394
        })
        return true
      }
    },
    watch: {
      // Listening type
      programType (type) {
        if (type === 'PYTHON') {
          this.mainClass = ''
        }
395 396 397 398 399 400 401 402 403 404 405
      },
      //Watch the cacheParams
      cacheParams (val) {
        this.$emit('on-cache-params', val)
      }
    },
    computed: {
      cacheParams () {
        return {
          mainClass: this.mainClass,
          mainJar: {
B
break60 已提交
406
            id: this.mainJar
407 408
          },
          deployMode: this.deployMode,
B
break60 已提交
409 410 411
          resourceList: _.map(this.resourceList, v => {
            return {id: v}
          }),
412 413 414 415 416 417 418 419 420 421 422
          localParams: this.localParams,
          driverCores: this.driverCores,
          driverMemory: this.driverMemory,
          numExecutors: this.numExecutors,
          executorMemory: this.executorMemory,
          executorCores: this.executorCores,
          mainArgs: this.mainArgs,
          others: this.others,
          programType: this.programType,
          sparkVersion: this.sparkVersion
        }
L
ligang 已提交
423 424 425
      }
    },
    created () {
B
break60 已提交
426 427 428 429 430 431
        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
L
ligang 已提交
432 433 434 435 436
        let o = this.backfillItem

        // Non-null objects represent backfill
        if (!_.isEmpty(o)) {
          this.mainClass = o.params.mainClass || ''
437 438 439 440 441 442 443
          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 || ''
          }
L
ligang 已提交
444 445 446 447 448 449 450 451 452
          this.deployMode = o.params.deployMode || ''
          this.driverCores = o.params.driverCores || 1
          this.driverMemory = o.params.driverMemory || '512M'
          this.numExecutors = o.params.numExecutors || 2
          this.executorMemory = o.params.executorMemory || '2G'
          this.executorCores = o.params.executorCores || 2
          this.mainArgs = o.params.mainArgs || ''
          this.others = o.params.others
          this.programType = o.params.programType || 'SCALA'
453
          this.sparkVersion = o.params.sparkVersion || 'SPARK2'
L
ligang 已提交
454 455 456 457

          // backfill resourceList
          let resourceList = o.params.resourceList || []
          if (resourceList.length) {
458 459 460 461 462 463 464 465 466 467 468 469 470 471
            _.map(resourceList, v => {
              if(v.res) {
                this.store.dispatch('dag/getResourceId',{
                  type: 'FILE',
                  fullName: '/'+v.res
                }).then(res => {
                  this.resourceList.push(res.id)
                }).catch(e => {
                  this.$message.error(e.msg || '')
                })
              } else {
                this.resourceList.push(v.id)
              }
            })
472
            this.cacheResourceList = resourceList
L
ligang 已提交
473 474 475 476 477 478 479 480 481 482 483 484
          }

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

    },
B
break60 已提交
485
    components: { mLocalParams, mListBox, mResources, Treeselect }
L
ligang 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
  }
</script>

<style lang="scss" rel="stylesheet/scss">
  .spark-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;
        }
      }
    }
  }
</style>