github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/app/controllers/clients/client.js (about)

     1  import { alias } from '@ember/object/computed';
     2  import Controller from '@ember/controller';
     3  import { computed, observer } from '@ember/object';
     4  import { task } from 'ember-concurrency';
     5  import Sortable from 'nomad-ui/mixins/sortable';
     6  import Searchable from 'nomad-ui/mixins/searchable';
     7  import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
     8  
     9  export default Controller.extend(Sortable, Searchable, {
    10    queryParams: {
    11      currentPage: 'page',
    12      searchTerm: 'search',
    13      sortProperty: 'sort',
    14      sortDescending: 'desc',
    15      onlyPreemptions: 'preemptions',
    16    },
    17  
    18    // Set in the route
    19    flagAsDraining: false,
    20  
    21    currentPage: 1,
    22    pageSize: 8,
    23  
    24    sortProperty: 'modifyIndex',
    25    sortDescending: true,
    26  
    27    searchProps: computed(() => ['shortId', 'name']),
    28  
    29    onlyPreemptions: false,
    30  
    31    visibleAllocations: computed(
    32      'model.allocations.[]',
    33      'preemptions.[]',
    34      'onlyPreemptions',
    35      function() {
    36        return this.onlyPreemptions ? this.preemptions : this.model.allocations;
    37      }
    38    ),
    39  
    40    listToSort: alias('visibleAllocations'),
    41    listToSearch: alias('listSorted'),
    42    sortedAllocations: alias('listSearched'),
    43  
    44    eligibilityError: null,
    45    stopDrainError: null,
    46    drainError: null,
    47    showDrainNotification: false,
    48    showDrainUpdateNotification: false,
    49    showDrainStoppedNotification: false,
    50  
    51    preemptions: computed('model.allocations.@each.wasPreempted', function() {
    52      return this.model.allocations.filterBy('wasPreempted');
    53    }),
    54  
    55    sortedEvents: computed('model.events.@each.time', function() {
    56      return this.get('model.events')
    57        .sortBy('time')
    58        .reverse();
    59    }),
    60  
    61    sortedDrivers: computed('model.drivers.@each.name', function() {
    62      return this.get('model.drivers').sortBy('name');
    63    }),
    64  
    65    sortedHostVolumes: computed('model.hostVolumes.@each.name', function() {
    66      return this.model.hostVolumes.sortBy('name');
    67    }),
    68  
    69    setEligibility: task(function*(value) {
    70      try {
    71        yield value ? this.model.setEligible() : this.model.setIneligible();
    72      } catch (err) {
    73        const error = messageFromAdapterError(err) || 'Could not set eligibility';
    74        this.set('eligibilityError', error);
    75      }
    76    }).drop(),
    77  
    78    stopDrain: task(function*() {
    79      try {
    80        this.set('flagAsDraining', false);
    81        yield this.model.cancelDrain();
    82        this.set('showDrainStoppedNotification', true);
    83      } catch (err) {
    84        this.set('flagAsDraining', true);
    85        const error = messageFromAdapterError(err) || 'Could not stop drain';
    86        this.set('stopDrainError', error);
    87      }
    88    }).drop(),
    89  
    90    forceDrain: task(function*() {
    91      try {
    92        yield this.model.forceDrain({
    93          IgnoreSystemJobs: this.model.drainStrategy.ignoreSystemJobs,
    94        });
    95      } catch (err) {
    96        const error = messageFromAdapterError(err) || 'Could not force drain';
    97        this.set('drainError', error);
    98      }
    99    }).drop(),
   100  
   101    triggerDrainNotification: observer('model.isDraining', function() {
   102      if (!this.model.isDraining && this.flagAsDraining) {
   103        this.set('showDrainNotification', true);
   104      }
   105  
   106      this.set('flagAsDraining', this.model.isDraining);
   107    }),
   108  
   109    actions: {
   110      gotoAllocation(allocation) {
   111        this.transitionToRoute('allocations.allocation', allocation);
   112      },
   113  
   114      setPreemptionFilter(value) {
   115        this.set('onlyPreemptions', value);
   116      },
   117  
   118      drainNotify(isUpdating) {
   119        this.set('showDrainUpdateNotification', isUpdating);
   120      },
   121  
   122      drainError(err) {
   123        const error = messageFromAdapterError(err) || 'Could not run drain';
   124        this.set('drainError', error);
   125      },
   126    },
   127  });