mr.vue 13.2 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
      <div slot="content">
22
        <x-select v-model="programType" :disabled="isDetails" style="width: 110px;">
L
ligang 已提交
23 24 25 26 27 28 29 30 31 32
          <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'">
G
i18n  
gongzijian 已提交
33
      <div slot="text">{{$t('Main class')}}</div>
L
ligang 已提交
34 35 36 37 38
      <div slot="content">
        <x-input
                :disabled="isDetails"
                type="input"
                v-model="mainClass"
G
i18n  
gongzijian 已提交
39
                :placeholder="$t('Please enter main class')"
L
ligang 已提交
40 41 42 43 44
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
45
      <div slot="text">{{$t('Main jar package')}}</div>
L
ligang 已提交
46
      <div slot="content">
47
        <treeselect v-model="mainJar" maxHeight="200" :options="mainJarLists" :disable-branch-nodes="true" :normalizer="normalizer" :value-consists-of="valueConsistsOf" :disabled="isDetails"  :placeholder="$t('Please enter main jar package')">
B
break60 已提交
48 49
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
L
ligang 已提交
50 51 52
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
53
      <div slot="text">{{$t('Command-line parameters')}}</div>
L
ligang 已提交
54 55 56 57 58 59
      <div slot="content">
        <x-input
                :autosize="{minRows:2}"
                :disabled="isDetails"
                type="textarea"
                v-model="mainArgs"
G
i18n  
gongzijian 已提交
60
                :placeholder="$t('Please enter Command-line parameters')"
L
ligang 已提交
61 62 63 64 65
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
66
      <div slot="text">{{$t('Other parameters')}}</div>
L
ligang 已提交
67 68 69 70 71 72
      <div slot="content">
        <x-input
                :disabled="isDetails"
                :autosize="{minRows:2}"
                type="textarea"
                v-model="others"
G
i18n  
gongzijian 已提交
73
                :placeholder="$t('Please enter other parameters')"
L
ligang 已提交
74 75 76 77 78
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
79
      <div slot="text">{{$t('Resources')}}</div>
L
ligang 已提交
80
      <div slot="content">
81
        <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 已提交
82 83
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
L
ligang 已提交
84 85 86
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
87
      <div slot="text">{{$t('Custom Parameters')}}</div>
L
ligang 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
      <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 mListBox from './_source/listBox'
  import mResources from './_source/resources'
  import mLocalParams from './_source/localParams'
B
break60 已提交
105 106
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'
L
ligang 已提交
107 108 109 110 111
  import disabledState from '@/module/mixin/disabledState'
  export default {
    name: 'mr',
    data () {
      return {
112
        valueConsistsOf: 'LEAF_PRIORITY',
L
ligang 已提交
113 114 115 116 117
        // Main function class
        mainClass: '',
        // Master jar package
        mainJar: null,
        // Main jar package (List)
B
break60 已提交
118
        mainJarLists: [],
L
ligang 已提交
119 120 121
        mainJarList: [],
        // Resource(list)
        resourceList: [],
Z
zhukai 已提交
122 123
        // Cache ResourceList
        cacheResourceList: [],
L
ligang 已提交
124 125 126 127 128 129 130 131 132
        // Custom parameter
        localParams: [],
        // Command line argument
        mainArgs: '',
        // Other parameters
        others: '',
        // Program type
        programType: 'JAVA',
        // Program type(List)
B
break60 已提交
133 134 135 136 137
        programTypeList: [{ code: 'JAVA' }, { code: 'PYTHON' }],
        normalizer(node) {
          return {
            label: node.name
          }
138 139 140
        },
        allNoResources: [],
        noRes: []
L
ligang 已提交
141 142 143 144 145 146 147
      }
    },
    props: {
      backfillItem: Object
    },
    mixins: [disabledState],
    methods: {
148 149 150 151 152 153 154 155 156 157 158 159 160
      /**
       * 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 已提交
161 162 163 164 165 166 167 168 169 170 171 172
      /**
       * return localParams
       */
      _onLocalParams (a) {
        this.localParams = a
      },
      /**
       * return resourceList
       */
      _onResourcesData (a) {
        this.resourceList = a
      },
Z
zhukai 已提交
173 174 175 176 177 178
      /**
       * cache resourceList
       */
      _onCacheResourcesData (a) {
        this.cacheResourceList = a
      },
B
break60 已提交
179 180 181
      diGuiTree(item) {  // Recursive convenience tree structure
        item.forEach(item => {
          item.children === '' || item.children === undefined || item.children === null || item.children.length === 0?        
182
            this.operationTree(item) : this.diGuiTree(item.children);
B
break60 已提交
183 184
        })
      },
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
      operationTree(item) {
        if(item.dirctory) {
          item.isDisabled =true
        }
        delete item.children
      },
      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 已提交
235 236
            name: $t('Unauthorized or deleted resources'),
            fullName: '/'+$t('Unauthorized or deleted resources'),
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
            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)
          }
        }
      },
L
ligang 已提交
252 253 254 255 256
      /**
       * verification
       */
      _verification () {
        if (this.programType !== 'PYTHON' && !this.mainClass) {
G
i18n  
gongzijian 已提交
257
          this.$message.warning(`${i18n.$t('Please enter main class')}`)
L
ligang 已提交
258 259 260 261
          return false
        }

        if (!this.mainJar) {
G
i18n  
gongzijian 已提交
262
          this.$message.warning(`${i18n.$t('Please enter main jar package')}`)
L
ligang 已提交
263 264 265
          return false
        }

266 267 268 269 270 271
        // noRes
        if (this.noRes.length>0) {
          this.$message.warning(`${i18n.$t('Please delete all non-existent resources')}`)
          return false
        }

L
ligang 已提交
272 273 274 275 276 277 278 279
        // localParams Subcomponent verification
        if (!this.$refs.refLocalParams._verifProp()) {
          return false
        }
        // storage
        this.$emit('on-params', {
          mainClass: this.mainClass,
          mainJar: {
B
break60 已提交
280
            id: this.mainJar
L
ligang 已提交
281
          },
B
break60 已提交
282 283 284
          resourceList: _.map(this.resourceList, v => {
            return {id: v}
          }),
L
ligang 已提交
285 286 287 288 289 290 291
          localParams: this.localParams,
          mainArgs: this.mainArgs,
          others: this.others,
          programType: this.programType
        })
        return true
      },
B
break60 已提交
292
    
L
ligang 已提交
293 294 295 296 297 298 299 300 301
    },
    watch: {
      /**
       * monitor
       */
      programType (type) {
        if (type === 'PYTHON') {
          this.mainClass = ''
        }
Z
zhukai 已提交
302 303 304 305 306 307 308 309
      },
      //Watch the cacheParams
      cacheParams (val) {
        this.$emit('on-cache-params', val);
      }
    },
    computed: {
      cacheParams () {
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
        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
Z
zhukai 已提交
334 335 336
        return {
          mainClass: this.mainClass,
          mainJar: {
B
break60 已提交
337
            id: this.mainJar
Z
zhukai 已提交
338
          },
339
          resourceList: resourceIdArr,
Z
zhukai 已提交
340 341 342 343 344
          localParams: this.localParams,
          mainArgs: this.mainArgs,
          others: this.others,
          programType: this.programType
        }
L
ligang 已提交
345 346 347
      }
    },
    created () {
B
break60 已提交
348 349 350 351 352 353
        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 已提交
354 355 356 357 358
        let o = this.backfillItem

        // Non-null objects represent backfill
        if (!_.isEmpty(o)) {
          this.mainClass = o.params.mainClass || ''
359 360 361 362 363 364 365
          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 已提交
366 367 368 369 370 371 372
          this.mainArgs = o.params.mainArgs || ''
          this.others = o.params.others
          this.programType = o.params.programType || 'JAVA'

          // backfill resourceList
          let resourceList = o.params.resourceList || []
          if (resourceList.length) {
373
            _.map(resourceList, v => {
374
              if(!v.id) {
375 376 377 378 379
                this.store.dispatch('dag/getResourceId',{
                  type: 'FILE',
                  fullName: '/'+v.res
                }).then(res => {
                  this.resourceList.push(res.id)
380
                  this.dataProcess(backResource)
381
                }).catch(e => {
382 383
                  this.resourceList.push(v.res)
                  this.dataProcess(backResource)
384 385 386
                })
              } else {
                this.resourceList.push(v.id)
387
                this.dataProcess(backResource)
388
              }
B
break60 已提交
389
            })
Z
zhukai 已提交
390
            this.cacheResourceList = resourceList
L
ligang 已提交
391 392 393
          }

          // backfill localParams
394
          let backResource = o.params.resourceList || []
L
ligang 已提交
395 396 397 398 399 400 401 402 403
          let localParams = o.params.localParams || []
          if (localParams.length) {
            this.localParams = localParams
          }
        }
    },
    mounted () {

    },
B
break60 已提交
404
    components: { mLocalParams, mListBox, mResources, Treeselect }
L
ligang 已提交
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
  }
</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;
        }
      }
    }
  }
430 431 432 433 434 435 436 437
  .vue-treeselect--disabled {
    .vue-treeselect__control {
      background-color: #ecf3f8;
      .vue-treeselect__single-value {
        color: #6d859e;
      }
    }
  }
L
ligang 已提交
438
</style>