use of org.ovirt.engine.core.common.migration.MigrationPolicy in project ovirt-engine by oVirt.
the class ConvergenceConfigProvider method initMigrationPolicies.
void initMigrationPolicies(String policiesStr, Version version) {
List<MigrationPolicy> policies = Collections.emptyList();
try {
policies = parse(policiesStr);
} catch (IOException e) {
log.error("The provided migration policies: '{}' are not valid, ignoring", policiesStr);
}
// init it to an empty map even the parsing failed
Map<Guid, MigrationPolicy> migrationPolicies = policies.stream().collect(toMap(MigrationPolicy::getId, identity()));
// the null object
migrationPolicies.put(NoMigrationPolicy.ID, new NoMigrationPolicy());
migrationPoliciesByVersion.put(version, migrationPolicies);
}
use of org.ovirt.engine.core.common.migration.MigrationPolicy in project ovirt-engine by oVirt.
the class ClusterModel method refreshMigrationPolicies.
public void refreshMigrationPolicies() {
Version version = getEffectiveVersion();
Guid selectedPolicyId = null;
if (getMigrationPolicies() != null && getMigrationPolicies().getSelectedItem() != null) {
selectedPolicyId = getMigrationPolicies().getSelectedItem().getId();
}
List<MigrationPolicy> policies = AsyncDataProvider.getInstance().getMigrationPolicies(version);
getMigrationPolicies().setItems(policies);
MigrationPolicy migrationPolicy;
if (selectedPolicyId == null) {
migrationPolicy = getIsEdit() ? findMigrationPolicyById(getEntity().getMigrationPolicyId(), policies) : findFirstNonEmptyMigrationPolicy(policies);
} else {
migrationPolicy = findMigrationPolicyById(selectedPolicyId, policies);
}
getMigrationPolicies().setSelectedItem(migrationPolicy != null ? migrationPolicy : findMigrationPolicyById(NoMigrationPolicy.ID, policies));
getMigrationPolicies().updateChangeability(ConfigValues.MigrationPoliciesSupported, version);
}
use of org.ovirt.engine.core.common.migration.MigrationPolicy in project ovirt-engine by oVirt.
the class ConvergenceConfigProviderTest method jsonInvalidJson.
@Test
public void jsonInvalidJson() throws IOException {
provider.initMigrationPolicies("this is not a valid json", VERSION);
MigrationPolicy policy = provider.getMigrationPolicy(Guid.newGuid(), VERSION);
assertTrue(policy instanceof NoMigrationPolicy);
}
use of org.ovirt.engine.core.common.migration.MigrationPolicy in project ovirt-engine by oVirt.
the class ConvergenceConfigProviderTest method jsonProperlyFilled.
@Test
public void jsonProperlyFilled() throws IOException {
Guid id = Guid.newGuid();
List<MigrationPolicy> policies = new ArrayList<>();
ConvergenceConfig config = new ConvergenceConfig();
config.setInitialItems(Collections.singletonList(new ConvergenceItem("setDowntime2", 1)));
config.setLastItems(Collections.singletonList(new ConvergenceItem("setDowntime3", 15)));
config.setConvergenceItems(Collections.singletonList(new ConvergenceItemWithStallingLimit(1, "someAction", 12)));
MigrationPolicy policy = new MigrationPolicy(id, "some name", "some long description", config);
policies.add(policy);
String json = JsonHelper.objectToJson(policies, false);
provider.initMigrationPolicies(json, VERSION);
// just basic sanity check
assertEquals(policy.getName(), provider.getMigrationPolicy(id, VERSION).getName());
assertEquals(policy.getDescription(), provider.getMigrationPolicy(id, VERSION).getDescription());
assertTrue(provider.getMigrationPolicy(id, new Version()) instanceof NoMigrationPolicy);
}
use of org.ovirt.engine.core.common.migration.MigrationPolicy in project ovirt-engine by oVirt.
the class MigrationPoliciesValueHelper method getExamplePolicy.
String getExamplePolicy() {
ConvergenceConfig config = new ConvergenceConfig();
config.setInitialItems(Arrays.asList(new ConvergenceItem("setDowntime", 100)));
config.setConvergenceItems(Arrays.asList(new ConvergenceItemWithStallingLimit(1, "setDowntime", 200)));
config.setLastItems(Arrays.asList(new ConvergenceItem("abort")));
List<MigrationPolicy> policies = Arrays.asList(new MigrationPolicy(Guid.Empty, "name of the policy", "description", config));
try {
return JsonHelper.objectToJson(policies, false);
} catch (IOException e) {
// if this fails, than we really want to fail it with an exception
throw new RuntimeException(e);
}
}
Aggregations