2020-10-05 17:07:35 +00:00
|
|
|
import Route from '@ember/routing/route';
|
2020-12-08 15:47:55 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2021-01-19 15:40:39 +00:00
|
|
|
import { set, get, action } from '@ember/object';
|
2020-10-05 17:07:35 +00:00
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class TopologyRoute extends Route {
|
2020-12-08 15:47:55 +00:00
|
|
|
@service('ui-config') config;
|
2020-12-16 09:18:29 +00:00
|
|
|
@service('data-source/service') data;
|
|
|
|
@service('repository/intention') repo;
|
2021-01-19 15:40:39 +00:00
|
|
|
@service('feedback') feedback;
|
2020-12-08 15:47:55 +00:00
|
|
|
|
2020-12-16 09:18:29 +00:00
|
|
|
@action
|
|
|
|
async createIntention(source, destination) {
|
2021-01-19 15:40:39 +00:00
|
|
|
// begin with a create action as it makes more sense if the we can't even
|
|
|
|
// get a list of intentions
|
|
|
|
let notification = this.feedback.notification('create');
|
|
|
|
try {
|
|
|
|
// intentions will be a proxy object
|
|
|
|
let intentions = await this.intentions;
|
|
|
|
let intention = intentions.find(item => {
|
|
|
|
return (
|
|
|
|
item.Datacenter === source.Datacenter &&
|
|
|
|
item.SourceName === source.Name &&
|
|
|
|
item.SourceNS === source.Namespace &&
|
|
|
|
item.DestinationName === destination.Name &&
|
|
|
|
item.DestinationNS === destination.Namespace
|
|
|
|
);
|
|
|
|
});
|
|
|
|
if (typeof intention === 'undefined') {
|
|
|
|
intention = this.repo.create({
|
|
|
|
Datacenter: source.Datacenter,
|
|
|
|
SourceName: source.Name,
|
|
|
|
SourceNS: source.Namespace || 'default',
|
|
|
|
DestinationName: destination.Name,
|
|
|
|
DestinationNS: destination.Namespace || 'default',
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// we found an intention in the find higher up, so we are updating
|
|
|
|
notification = this.feedback.notification('update');
|
|
|
|
}
|
|
|
|
set(intention, 'Action', 'allow');
|
|
|
|
await this.repo.persist(intention);
|
|
|
|
notification.success(intention);
|
|
|
|
} catch (e) {
|
|
|
|
notification.error(e);
|
|
|
|
}
|
2020-12-16 09:18:29 +00:00
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
2021-01-19 15:40:39 +00:00
|
|
|
afterModel(model, transition) {
|
|
|
|
this.intentions = this.data.source(
|
|
|
|
uri => uri`/${model.nspace}/${model.dc.Name}/intentions/for-service/${model.slug}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async deactivate(transition) {
|
|
|
|
const intentions = await this.intentions;
|
|
|
|
intentions.destroy();
|
|
|
|
}
|
|
|
|
|
2020-12-16 09:18:29 +00:00
|
|
|
async model() {
|
2020-10-05 17:07:35 +00:00
|
|
|
const parent = this.routeName
|
|
|
|
.split('.')
|
|
|
|
.slice(0, -1)
|
|
|
|
.join('.');
|
2020-12-16 09:18:29 +00:00
|
|
|
const model = this.modelFor(parent);
|
|
|
|
const dc = get(model, 'dc');
|
|
|
|
const nspace = get(model, 'nspace');
|
2020-12-08 15:47:55 +00:00
|
|
|
|
2020-12-16 09:18:29 +00:00
|
|
|
const item = get(model, 'items.firstObject');
|
2020-12-17 16:35:01 +00:00
|
|
|
let kind = get(item, 'Service.Kind');
|
|
|
|
if (typeof kind === 'undefined') {
|
|
|
|
kind = '';
|
2020-12-16 09:18:29 +00:00
|
|
|
}
|
2020-12-17 16:35:01 +00:00
|
|
|
const topology = await this.data.source(
|
|
|
|
uri => uri`/${nspace}/${dc.Name}/topology/${model.slug}/${kind}`
|
|
|
|
);
|
|
|
|
let hasMetricsProvider = await this.config.findByPath('metrics_provider');
|
|
|
|
hasMetricsProvider = !!hasMetricsProvider;
|
|
|
|
|
2020-12-08 15:47:55 +00:00
|
|
|
return {
|
2020-12-16 09:18:29 +00:00
|
|
|
...model,
|
2020-12-17 16:35:01 +00:00
|
|
|
topology,
|
|
|
|
hasMetricsProvider,
|
2020-12-08 15:47:55 +00:00
|
|
|
};
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
|
|
|
super.setupController(...arguments);
|
2020-10-05 17:07:35 +00:00
|
|
|
controller.setProperties(model);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|