Skip to content

Commit

Permalink
Merge pull request #507 from arenadata/develop
Browse files Browse the repository at this point in the history
Release 2020.08.10
  • Loading branch information
acmnu authored Aug 10, 2020
2 parents 70134fe + 0b1dec3 commit 699332e
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 31 deletions.
22 changes: 17 additions & 5 deletions python/cm/adcm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def get_prototype_config(proto, action=None):
return (spec, flat_spec, conf, attr)


def switch_config(obj, new_proto, old_proto): # pylint: disable=too-many-locals,too-many-branches
def switch_config(obj, new_proto, old_proto): # pylint: disable=too-many-locals,too-many-branches,too-many-statements
# process objects without config
if not obj.config:
spec, _, conf, attr = get_prototype_config(new_proto)
obj_conf = init_object_config(spec, conf, attr)
Expand All @@ -217,15 +218,19 @@ def is_new_default(key):
return True
return False

# set new default config values and gather information about activatable groups
new_conf = {}
active_groups = {}
inactive_groups = {}
for key in new_spec:
if new_spec[key].type == 'group':
limits = {}
if new_spec[key].limits:
limits = json.loads(new_spec[key].limits)
if 'activatable' in limits:
if 'active' in limits and not limits['active']:
if 'activatable' in limits and 'active' in limits:
if limits['active']:
active_groups[key.rstrip('/')] = True
else:
inactive_groups[key.rstrip('/')] = True
continue
if key in old_spec:
Expand All @@ -236,6 +241,7 @@ def is_new_default(key):
else:
new_conf[key] = get_default(new_spec[key], new_proto)

# go from flat config to 2-level dictionary
unflat_conf = {}
for key in new_conf:
k1, k2 = key.split('/')
Expand All @@ -246,12 +252,18 @@ def is_new_default(key):
unflat_conf[k1] = {}
unflat_conf[k1][k2] = new_conf[key]

# skip inactive groups in new prototype config
# skip inactive groups and set attributes for new config
attr = {}
if cl.attr:
attr = json.loads(cl.attr)
for key in unflat_conf:
if key in active_groups:
attr[key] = {'active': True}
if key in inactive_groups:
unflat_conf[key] = None
attr[key] = {'active': False}

save_obj_config(obj.config, unflat_conf, 'upgrade', cl.attr)
save_obj_config(obj.config, unflat_conf, 'upgrade', json.dumps(attr))
process_file_type(obj, new_unflat_spec, unflat_conf)


Expand Down
37 changes: 21 additions & 16 deletions python/cm/tests_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ def cook_upgrade(self, bundle):


def get_config(obj):
attr = {}
cl = ConfigLog.objects.get(obj_ref=obj.config, id=obj.config.current)
return json.loads(cl.config)
if cl.attr:
attr = json.loads(cl.attr)
return json.loads(cl.config), attr


class TestConfigUpgrade(TestCase):
Expand All @@ -168,7 +171,7 @@ def test_empty_first_config(self):
cluster = cm.api.add_cluster(proto1, 'Cluster1')
self.assertEqual(cluster.config, None)
cm.adcm_config.switch_config(cluster, proto2, proto1)
new_config = get_config(cluster)
new_config, _ = get_config(cluster)
self.assertEqual(new_config['port'], 42)

def test_adding_parameter(self):
Expand All @@ -177,44 +180,44 @@ def test_adding_parameter(self):
self.add_conf(prototype=proto2, name='host', type='string', default='arenadata.com')
self.add_conf(prototype=proto2, name='port', type='integer', default=42)
cluster = cm.api.add_cluster(proto1, 'Cluster1')
old_conf = get_config(cluster)
old_conf, _ = get_config(cluster)
self.assertEqual(old_conf, {'host': 'arenadata.com'})
cm.adcm_config.switch_config(cluster, proto2, proto1)
new_config = get_config(cluster)
new_config, _ = get_config(cluster)
self.assertEqual(new_config, {'host': 'arenadata.com', 'port': 42})

def test_deleting_parameter(self):
(proto1, proto2) = self.cook_proto()
self.add_conf(prototype=proto1, name='host', type='string', default='arenadata.com')
self.add_conf(prototype=proto2, name='port', type='integer', default=42)
cluster = cm.api.add_cluster(proto1, 'Cluster1')
old_conf = get_config(cluster)
old_conf, _ = get_config(cluster)
self.assertEqual(old_conf, {'host': 'arenadata.com'})
cm.adcm_config.switch_config(cluster, proto2, proto1)
new_config = get_config(cluster)
new_config, _ = get_config(cluster)
self.assertEqual(new_config, {'port': 42})

def test_default(self):
(proto1, proto2) = self.cook_proto()
self.add_conf(prototype=proto1, name='port', type='integer', default=42)
self.add_conf(prototype=proto2, name='port', type='integer', default=43)
cluster = cm.api.add_cluster(proto1, 'Cluster1')
old_conf = get_config(cluster)
old_conf, _ = get_config(cluster)
self.assertEqual(old_conf, {'port': 42})
cm.adcm_config.switch_config(cluster, proto2, proto1)
new_config = get_config(cluster)
new_config, _ = get_config(cluster)
self.assertEqual(new_config, {'port': 43})

def test_non_default(self):
(proto1, proto2) = self.cook_proto()
self.add_conf(prototype=proto1, name='port', type='integer', default=42)
self.add_conf(prototype=proto2, name='port', type='integer', default=43)
cluster = cm.api.add_cluster(proto1, 'Cluster1')
old_conf = get_config(cluster)
old_conf, _ = get_config(cluster)
old_conf['port'] = 100500
cm.adcm_config.save_obj_config(cluster.config, old_conf)
cm.adcm_config.switch_config(cluster, proto2, proto1)
new_config = get_config(cluster)
new_config, _ = get_config(cluster)
self.assertEqual(new_config, {'port': 100500})

def test_add_group(self):
Expand All @@ -224,10 +227,10 @@ def test_add_group(self):
self.add_conf(prototype=proto2, name='advance', type='group')
self.add_conf(prototype=proto2, name='advance', subname='port', type='integer', default=42)
cluster = cm.api.add_cluster(proto1, 'Cluster1')
old_conf = get_config(cluster)
old_conf, _ = get_config(cluster)
self.assertEqual(old_conf, {'host': 'arenadata.com'})
cm.adcm_config.switch_config(cluster, proto2, proto1)
new_config = get_config(cluster)
new_config, _ = get_config(cluster)
self.assertEqual(new_config, {'host': 'arenadata.com', 'advance': {'port': 42}})

def test_add_non_active_group(self):
Expand All @@ -238,11 +241,12 @@ def test_add_non_active_group(self):
self.add_conf(prototype=proto2, name='advance', type='group', limits=json.dumps(limits))
self.add_conf(prototype=proto2, name='advance', subname='port', type='integer', default=42)
cluster = cm.api.add_cluster(proto1, 'Cluster1')
old_conf = get_config(cluster)
old_conf, _ = get_config(cluster)
self.assertEqual(old_conf, {'host': 'arenadata.com'})
cm.adcm_config.switch_config(cluster, proto2, proto1)
new_config = get_config(cluster)
new_config, new_attr = get_config(cluster)
self.assertEqual(new_config, {'host': 'arenadata.com', 'advance': None})
self.assertEqual(new_attr, {'advance': {'active': False}})

def test_add_active_group(self):
(proto1, proto2) = self.cook_proto()
Expand All @@ -252,11 +256,12 @@ def test_add_active_group(self):
self.add_conf(prototype=proto2, name='advance', type='group', limits=json.dumps(limits))
self.add_conf(prototype=proto2, name='advance', subname='port', type='integer', default=42)
cluster = cm.api.add_cluster(proto1, 'Cluster1')
old_conf = get_config(cluster)
old_conf, _ = get_config(cluster)
self.assertEqual(old_conf, {'host': 'arenadata.com'})
cm.adcm_config.switch_config(cluster, proto2, proto1)
new_config = get_config(cluster)
new_config, new_attr = get_config(cluster)
self.assertEqual(new_config, {'host': 'arenadata.com', 'advance': {'port': 42}})
self.assertEqual(new_attr, {'advance': {'active': True}})


class TestUpgrade(TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicComponent, DynamicEvent } from '@app/shared/directives/dynamic.d
import { BaseDirective } from '../../../directives/base.directive';
import { ActionParameters } from '../actions.directive';
import { IValue, MasterService, whatShow } from './master.service';
import { ActionMasterConfigComponent } from './action-master-config.component';

@Component({
selector: 'app-master',
Expand All @@ -41,6 +42,7 @@ export class ActionMasterComponent extends BaseDirective implements DynamicCompo
show: whatShow;

@ViewChild('runBtn', { read: ElementRef }) runBtn: ElementRef;
@ViewChild(ActionMasterConfigComponent) master: ActionMasterConfigComponent;

constructor(private service: MasterService) {
super();
Expand All @@ -59,7 +61,8 @@ export class ActionMasterComponent extends BaseDirective implements DynamicCompo
return value && ((value.hostmap && value.hostmap.noValid) || (value.config && !value.config.form?.valid));
}

run(value: IValue) {
run(value: IValue = {}) {
value.attr = this.master?.fields?.attr;
const data = this.service.parseData(value);
this.service
.send(this.action.run, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { FieldService } from '@app/shared/configuration/field.service';
import { ConfigFieldsComponent } from '@app/shared/configuration/fields/fields.component';
import { ServiceHostComponent } from '@app/shared/host-components-map/services2hosts/service-host.component';
import { Post } from '@app/shared/host-components-map/types';
import { IConfigAttr } from '@app/shared/configuration/types';

export interface IValue {
attr?: IConfigAttr;
config?: ConfigFieldsComponent;
hostmap?: ServiceHostComponent;
}
Expand Down
4 changes: 4 additions & 0 deletions web/src/app/shared/configuration/fields/fields.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export class ConfigFieldsComponent {

constructor(private service: FieldService) {}

get attr() {
return this.dataOptions.filter((a) => a.type === 'group' && (a as PanelOptions).activatable).reduce((p, c: PanelOptions) => ({ ...p, [c.name]: { active: c.active } }), {});
}

isPanel(item: FieldOptions | PanelOptions) {
return 'options' in item && !item.hidden;
}
Expand Down
8 changes: 1 addition & 7 deletions web/src/app/shared/configuration/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,13 @@ export class ConfigComponent extends SocketListenerDirective implements OnInit {
);
}

getActivatableGroup() {
return this.fields.dataOptions
.filter((a) => a.type === 'group' && (a as PanelOptions).activatable)
.reduce((p, c: PanelOptions) => ({ ...p, [c.name]: { active: c.active } }), {});
}

save() {
const form = this.fields.form;
if (form.valid) {
this.saveFlag = true;
this.historyComponent.reset();
const config = this.service.parseValue(this.fields.form.value, this.rawConfig.config);
const send = { config, attr: this.getActivatableGroup(), description: this.tools.description.value };
const send = { config, attr: this.fields.attr, description: this.tools.description.value };
this.config$ = this.service.send(this.saveUrl, send).pipe(
tap((c) => {
this.saveFlag = false;
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/shared/details/detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DetailComponent extends SocketListenerDirective implements OnInit,
this.status = status;

const parent = w.current.typeName === 'cluster' ? null : w.cluster;
this.issue = parent?.issue || issue;
this.issue = issue;

this.current = {
parent,
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/shared/details/left/left.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class LeftComponent {
}

@Input() set issue(i: Issue) {
this.items = this.items.map((a) => ({ ...a, issue: this.navigation.findIssue(a.url, i || {}) ? 'issue' : '' }));
if (i) this.items = this.items.map((a) => ({ ...a, issue: this.navigation.findIssue(a.url, i) ? 'issue' : '' }));
}

@Input() set status(v: number) {
Expand Down

0 comments on commit 699332e

Please sign in to comment.