Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
import {array, fragment, fragmentArray} from 'ember-data-model-fragments/attributes';
export default Model.extend({
changeTracker: {trackHasMany: true, auto: true, enableIsDirty: true},
name: attr('string'),
style: attr('string'),
// object type
info: attr('object'),
blob: attr('json'),
// fragments
list: array('number'),
location: fragment('location'),
things: fragmentArray('things'),
// associations
company: belongsTo('company', { async: true, polymorphic: true }),
profile: belongsTo('profile', { async: false }),
projects: hasMany('project', { async: true }),
pets: hasMany('pet', { async: false, polymorphic: true })
});
// unique, non-empty values, alpha sort
return [...new Set(sources)].filter(Boolean).sort();
}
};
export default class ServiceInstance extends Model {
@attr('string') uid;
@attr('string') Datacenter;
// ProxyInstance is the ember-data model relationship
@belongsTo('Proxy') ProxyInstance;
// Proxy is the actual JSON api response
@attr() Proxy;
@attr() Node;
@attr() Service;
@fragmentArray('health-check') Checks;
@attr('number') SyncTime;
@attr() meta;
@attr({ defaultValue: () => [] }) Resources; // []
// The name is the Name of the Service (the grouping of instances)
@alias('Service.Service') Name;
// If the ID is blank fallback to the Service.Service (the Name)
@or('Service.{ID,Service}') ID;
@or('Service.Address', 'Node.Service') Address;
@attr('string') SocketPath;
@alias('Service.Tags') Tags;
@alias('Service.Meta') Meta;
@alias('Service.Namespace') Namespace;
migratingAllocations: computed('allocations.@each.{isMigrating,isRunning}', function() {
return this.allocations.filter(alloc => alloc.isRunning && alloc.isMigrating);
}),
lastMigrateTime: computed('allocations.@each.{isMigrating,isRunning,modifyTime}', function() {
const allocation = this.allocations
.filterBy('isRunning', false)
.filterBy('isMigrating')
.sortBy('modifyTime')
.reverse()[0];
if (allocation) {
return allocation.modifyTime;
}
}),
drivers: fragmentArray('node-driver'),
events: fragmentArray('node-event'),
hostVolumes: fragmentArray('host-volume'),
detectedDrivers: computed('drivers.@each.detected', function() {
return this.drivers.filterBy('detected');
}),
unhealthyDrivers: computed('detectedDrivers.@each.healthy', function() {
return this.detectedDrivers.filterBy('healthy', false);
}),
unhealthyDriverNames: computed('unhealthyDrivers.@each.name', function() {
return this.unhealthyDrivers.mapBy('name');
}),
// A status attribute that includes states not included in node status.
// Useful for coloring and sorting nodes
// polls description
description: attr('string', {
defaultValue: ''
}),
// ISO 8601 date + time string in UTC
expirationDate: attr('string', {
includePlainOnCreate: 'serverExpirationDate'
}),
// Must all options been answered?
forceAnswer: attr('boolean'),
// array of polls options
options: fragmentArray('option'),
// FindADate or MakeAPoll
pollType: attr('string'),
// timezone poll got created in (like "Europe/Berlin")
timezone: attr('string'),
// polls title
title: attr('string'),
// Croodle version poll got created with
version: attr('string', {
encrypted: false
}),
/*
// If any task group is not promoted yet requires promotion and the deployment
// is still running, the deployment needs promotion.
requiresPromotion: computed('taskGroupSummaries.@each.promoted', function() {
return this.status === 'running' &&
this.taskGroupSummaries
.toArray()
.some(summary => summary.get('requiresPromotion') && !summary.get('promoted'));
}),
status: attr('string'),
statusDescription: attr('string'),
isRunning: equal('status', 'running'),
taskGroupSummaries: fragmentArray('task-group-deployment-summary'),
allocations: hasMany('allocations'),
version: computed('versionNumber', 'job.versions.content.@each.number', function() {
return (this.get('job.versions') || []).findBy('number', this.versionNumber);
}),
// Dependent keys can only go one level past an @each so an alias is needed
versionSubmitTime: alias('version.submitTime'),
placedCanaries: sumAggregation('taskGroupSummaries', 'placedCanaries'),
desiredCanaries: sumAggregation('taskGroupSummaries', 'desiredCanaries'),
desiredTotal: sumAggregation('taskGroupSummaries', 'desiredTotal'),
placedAllocs: sumAggregation('taskGroupSummaries', 'placedAllocs'),
healthyAllocs: sumAggregation('taskGroupSummaries', 'healthyAllocs'),
unhealthyAllocs: sumAggregation('taskGroupSummaries', 'unhealthyAllocs'),
import { collect, sum } from '@ember/object/computed';
import Model from '@ember-data/model';
import { attr, belongsTo } from '@ember-data/model';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import sumAggregation from '../utils/properties/sum-aggregation';
import classic from 'ember-classic-decorator';
@classic
export default class JobSummary extends Model {
@belongsTo('job') job;
@fragmentArray('task-group-summary') taskGroupSummaries;
// Aggregate allocation counts across all summaries
@sumAggregation('taskGroupSummaries', 'queuedAllocs') queuedAllocs;
@sumAggregation('taskGroupSummaries', 'startingAllocs') startingAllocs;
@sumAggregation('taskGroupSummaries', 'runningAllocs') runningAllocs;
@sumAggregation('taskGroupSummaries', 'completeAllocs') completeAllocs;
@sumAggregation('taskGroupSummaries', 'failedAllocs') failedAllocs;
@sumAggregation('taskGroupSummaries', 'lostAllocs') lostAllocs;
@collect(
'queuedAllocs',
'startingAllocs',
'runningAllocs',
'completeAllocs',
'failedAllocs',
'lostAllocs'
const taskGroups = this.get('job.taskGroups');
return taskGroups && taskGroups.findBy('name', this.taskGroupName);
}),
unhealthyDrivers: computed('taskGroup.drivers.[]', 'node.unhealthyDriverNames.[]', function() {
const taskGroupUnhealthyDrivers = this.get('taskGroup.drivers');
const nodeUnhealthyDrivers = this.get('node.unhealthyDriverNames');
if (taskGroupUnhealthyDrivers && nodeUnhealthyDrivers) {
return intersection(taskGroupUnhealthyDrivers, nodeUnhealthyDrivers);
}
return [];
}),
states: fragmentArray('task-state'),
rescheduleEvents: fragmentArray('reschedule-event'),
hasRescheduleEvents: computed('rescheduleEvents.length', 'nextAllocation', function() {
return this.get('rescheduleEvents.length') > 0 || this.nextAllocation;
}),
hasStoppedRescheduling: computed(
'nextAllocation',
'clientStatus',
'followUpEvaluation.content',
function() {
return (
!this.get('nextAllocation.content') &&
!this.get('followUpEvaluation.content') &&
this.clientStatus === 'failed'
);
@fragment('task-group', { defaultValue: null }) allocationTaskGroup;
@computed('taskGroup.drivers.[]', 'node.unhealthyDriverNames.[]')
get unhealthyDrivers() {
const taskGroupUnhealthyDrivers = this.get('taskGroup.drivers');
const nodeUnhealthyDrivers = this.get('node.unhealthyDriverNames');
if (taskGroupUnhealthyDrivers && nodeUnhealthyDrivers) {
return intersection(taskGroupUnhealthyDrivers, nodeUnhealthyDrivers);
}
return [];
}
@fragmentArray('task-state') states;
@fragmentArray('reschedule-event') rescheduleEvents;
@computed('rescheduleEvents.length', 'nextAllocation')
get hasRescheduleEvents() {
return this.get('rescheduleEvents.length') > 0 || this.nextAllocation;
}
@computed('clientStatus', 'followUpEvaluation.content', 'nextAllocation.content')
get hasStoppedRescheduling() {
return (
!this.get('nextAllocation.content') &&
!this.get('followUpEvaluation.content') &&
this.clientStatus === 'failed'
);
}
stop() {
@fragment('task-group', { defaultValue: null }) allocationTaskGroup;
@computed('taskGroup.drivers.[]', 'node.unhealthyDriverNames.[]')
get unhealthyDrivers() {
const taskGroupUnhealthyDrivers = this.get('taskGroup.drivers');
const nodeUnhealthyDrivers = this.get('node.unhealthyDriverNames');
if (taskGroupUnhealthyDrivers && nodeUnhealthyDrivers) {
return intersection(taskGroupUnhealthyDrivers, nodeUnhealthyDrivers);
}
return [];
}
@fragmentArray('task-state') states;
@fragmentArray('reschedule-event') rescheduleEvents;
@computed('rescheduleEvents.length', 'nextAllocation')
get hasRescheduleEvents() {
return this.get('rescheduleEvents.length') > 0 || this.nextAllocation;
}
@computed('clientStatus', 'followUpEvaluation.content', 'nextAllocation.content')
get hasStoppedRescheduling() {
return (
!this.get('nextAllocation.content') &&
!this.get('followUpEvaluation.content') &&
this.clientStatus === 'failed'
);
}
import attr from "ember-data/attr";
import Fragment from "ember-data-model-fragments/fragment";
import { fragmentArray } from "ember-data-model-fragments/attributes";
import { fragment } from "utils/decorators";
export default class TwitchTicketProduct extends Fragment {
/** @type {TwitchTicketProductEmoticon[]} */
@fragmentArray( "twitch-ticket-product-emoticon" )
emoticons;
/** @type {TwitchTicketProductFeatures} */
@fragment( "twitch-ticket-product-features" )
features;
@attr( "number" )
interval_number;
@attr( "string" )
name;
@attr( "string" )
owner_name;
@attr( "string" )
period;
@attr( "string" )
price;
@attr( "boolean" )
recurring;