spark.vue 11.8 KB
Newer Older
L
ligang 已提交
1 2 3
<template>
  <div class="spark-model">
    <m-list-box>
G
i18n  
gongzijian 已提交
4
      <div slot="text">{{$t('Program Type')}}</div>
L
ligang 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
      <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'">
G
i18n  
gongzijian 已提交
20
      <div slot="text">{{$t('Main class')}}</div>
L
ligang 已提交
21 22 23 24 25
      <div slot="content">
        <x-input
                :disabled="isDetails"
                type="input"
                v-model="mainClass"
G
i18n  
gongzijian 已提交
26
                :placeholder="$t('Please enter main class')"
L
ligang 已提交
27 28 29 30 31
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
32
      <div slot="text">{{$t('Main jar package')}}</div>
L
ligang 已提交
33 34 35
      <div slot="content">
        <x-select
                style="width: 100%;"
G
i18n  
gongzijian 已提交
36
                :placeholder="$t('Please enter main jar package')"
L
ligang 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49
                v-model="mainJar"
                filterable
                :disabled="isDetails">
          <x-option
                  v-for="city in mainJarList"
                  :key="city.code"
                  :value="city.code"
                  :label="city.code">
          </x-option>
        </x-select>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
50
      <div slot="text">{{$t('Deploy Mode')}}</div>
L
ligang 已提交
51 52 53 54 55 56 57 58 59 60
      <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 已提交
61
        <span class="sp1">{{$t('Driver core number')}}</span>
L
ligang 已提交
62 63 64 65 66
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="driverCores"
G
i18n  
gongzijian 已提交
67
                  :placeholder="$t('Please enter driver core number')"
L
ligang 已提交
68 69 70 71
                  style="width: 200px;"
                  autocomplete="off">
        </x-input>
        </span>
G
i18n  
gongzijian 已提交
72
        <span class="sp1 sp3">{{$t('Driver memory use')}}</span>
L
ligang 已提交
73 74 75 76 77
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="driverMemory"
G
i18n  
gongzijian 已提交
78
                  :placeholder="$t('Please enter driver memory use')"
L
ligang 已提交
79 80 81 82 83 84
                  style="width: 186px;"
                  autocomplete="off">
        </x-input>
        </span>
      </div>
      <div class="clearfix list">
G
i18n  
gongzijian 已提交
85
        <span class="sp1">{{$t('Number of Executors')}}</span>
L
ligang 已提交
86 87 88 89 90
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="numExecutors"
G
i18n  
gongzijian 已提交
91
                  :placeholder="$t('Please enter the number of Executor')"
L
ligang 已提交
92 93 94 95
                  style="width: 200px;"
                  autocomplete="off">
        </x-input>
        </span>
G
i18n  
gongzijian 已提交
96
        <span class="sp1 sp3">{{$t('Executor memory')}}</span>
L
ligang 已提交
97 98 99 100 101
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="executorMemory"
G
i18n  
gongzijian 已提交
102
                  :placeholder="$t('Please enter the Executor memory')"
L
ligang 已提交
103 104 105 106 107 108
                  style="width: 186px;"
                  autocomplete="off">
        </x-input>
        </span>
      </div>
      <div class="clearfix list">
G
i18n  
gongzijian 已提交
109
        <span class="sp1">{{$t('Executor core number')}}</span>
L
ligang 已提交
110 111 112 113 114
        <span class="sp2">
          <x-input
                  :disabled="isDetails"
                  type="input"
                  v-model="executorCores"
G
i18n  
gongzijian 已提交
115
                  :placeholder="$t('Please enter Executor core number')"
L
ligang 已提交
116 117 118 119 120 121 122
                  style="width: 200px;"
                  autocomplete="off">
          </x-input>
        </span>
      </div>
    </div>
    <m-list-box>
G
i18n  
gongzijian 已提交
123
      <div slot="text">{{$t('Command-line parameters')}}</div>
L
ligang 已提交
124 125 126 127 128 129
      <div slot="content">
        <x-input
                :autosize="{minRows:2}"
                :disabled="isDetails"
                type="textarea"
                v-model="mainArgs"
G
i18n  
gongzijian 已提交
130
                :placeholder="$t('Please enter Command-line parameters')"
L
ligang 已提交
131 132 133 134 135
                autocomplete="off">
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
136
      <div slot="text">{{$t('Other parameters')}}</div>
L
ligang 已提交
137 138 139 140 141 142
      <div slot="content">
        <x-input
                :disabled="isDetails"
                :autosize="{minRows:2}"
                type="textarea"
                v-model="others"
G
i18n  
gongzijian 已提交
143
                :placeholder="$t('Please enter other parameters')">
L
ligang 已提交
144 145 146 147
        </x-input>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
148
      <div slot="text">{{$t('Resources')}}</div>
L
ligang 已提交
149 150 151 152 153 154 155 156 157
      <div slot="content">
        <m-resources
                ref="refResources"
                @on-resourcesData="_onResourcesData"
                :resource-list="resourceList">
        </m-resources>
      </div>
    </m-list-box>
    <m-list-box>
G
i18n  
gongzijian 已提交
158
      <div slot="text">{{$t('Custom Parameters')}}</div>
L
ligang 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 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 235
      <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'
  import disabledState from '@/module/mixin/disabledState'

  export default {
    name: 'spark',
    data () {
      return {
        // Main function class
        mainClass: '',
        // Master jar package
        mainJar: null,
        // Master jar package(List)
        mainJarList: [],
        // Deployment method
        deployMode: 'cluster',
        // Resource(list)
        resourceList: [],
        // 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)
        programTypeList: [{ code: 'JAVA' }, { code: 'SCALA' }, { code: 'PYTHON' }]
      }
    },
    props: {
      backfillItem: Object
    },
    mixins: [disabledState],
    methods: {
      /**
       * return localParams
       */
      _onLocalParams (a) {
        this.localParams = a
      },
      /**
       * return resourceList
       */
      _onResourcesData (a) {
        this.resourceList = a
      },
      /**
       * verification
       */
      _verification () {
        if (this.programType !== 'PYTHON' && !this.mainClass) {
G
i18n  
gongzijian 已提交
236
          this.$message.warning(`${i18n.$t('Please enter main class')}`)
L
ligang 已提交
237 238 239 240
          return false
        }

        if (!this.mainJar) {
G
i18n  
gongzijian 已提交
241
          this.$message.warning(`${i18n.$t('Please enter main jar package')}`)
L
ligang 已提交
242 243 244 245
          return false
        }

        if (!this.numExecutors) {
G
i18n  
gongzijian 已提交
246
          this.$message.warning(`${i18n.$t('Please enter the number of Executor')}`)
L
ligang 已提交
247 248 249 250
          return false
        }

        if (!Number.isInteger(parseInt(this.numExecutors))) {
G
i18n  
gongzijian 已提交
251
          this.$message.warning(`${i18n.$t('The number of Executors should be a positive integer')}`)
L
ligang 已提交
252 253 254 255
          return false
        }

        if (!this.executorMemory) {
G
i18n  
gongzijian 已提交
256
          this.$message.warning(`${i18n.$t('Please enter the Executor memory')}`)
L
ligang 已提交
257 258 259 260
          return false
        }

        if (!this.executorMemory) {
G
i18n  
gongzijian 已提交
261
          this.$message.warning(`${i18n.$t('Please enter the Executor memory')}`)
L
ligang 已提交
262 263 264 265
          return false
        }

        if (!_.isNumber(parseInt(this.executorMemory))) {
G
i18n  
gongzijian 已提交
266
          this.$message.warning(`${i18n.$t('Memory should be a positive integer')}`)
L
ligang 已提交
267 268 269 270
          return false
        }

        if (!this.executorCores) {
G
i18n  
gongzijian 已提交
271
          this.$message.warning(`${i18n.$t('Please enter ExecutorPlease enter Executor core number')}`)
L
ligang 已提交
272 273 274 275
          return false
        }

        if (!Number.isInteger(parseInt(this.executorCores))) {
G
i18n  
gongzijian 已提交
276
          this.$message.warning(`${i18n.$t('Core number should be positive integer')}`)
L
ligang 已提交
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 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 399 400
          return false
        }

        if (!this.$refs.refResources._verifResources()) {
          return false
        }

        // localParams Subcomponent verification
        if (!this.$refs.refLocalParams._verifProp()) {
          return false
        }

        // storage
        this.$emit('on-params', {
          mainClass: this.mainClass,
          mainJar: {
            res: this.mainJar
          },
          deployMode: this.deployMode,
          resourceList: this.resourceList,
          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
        })
        return true
      },
      /**
       * get resources list
       */
      _getResourcesList () {
        return new Promise((resolve, reject) => {
          let isJar = (alias) => {
            return alias.substring(alias.lastIndexOf('.') + 1, alias.length) !== 'jar'
          }
          this.mainJarList = _.map(_.cloneDeep(this.store.state.dag.resourcesListS), v => {
            return {
              id: v.id,
              code: v.alias,
              disabled: isJar(v.alias)
            }
          })
          resolve()
        })
      }
    },
    watch: {
      // Listening type
      programType (type) {
        if (type === 'PYTHON') {
          this.mainClass = ''
        }
      }
    },
    created () {
      this._getResourcesList().then(() => {
        let o = this.backfillItem

        // Non-null objects represent backfill
        if (!_.isEmpty(o)) {
          this.mainClass = o.params.mainClass || ''
          this.mainJar = o.params.mainJar.res || ''
          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'

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

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

    },
    components: { mLocalParams, mListBox, mResources }
  }
</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>