All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.btrplace.model.constraint.Split Maven / Gradle / Ivy

/*
 * Copyright (c) 2016 University Nice Sophia Antipolis
 *
 * This file is part of btrplace.
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 */

package org.btrplace.model.constraint;

import org.btrplace.model.VM;

import java.util.*;

/**
 * A constraint to force several sets of VMs to not share any node when they are
 * running.
 * 

* When the restriction is discrete, the constraint ensures there is no co-location on * only on a given model. *

* When the restriction is continuous, the constraint ensures a VM can not be set running * on a node that is hosting VMs from another group, even temporary. * * @author Fabien Hermenier */ @SideConstraint(args = {"part <<: vms"}, inv = "{ {host(v). v : p , vmState(v) = running}. p : part} <<: nodes") public class Split extends SimpleConstraint { private Collection> sets; /** * Make a new constraint having a discrete restriction. * * @param parts the disjoint sets of VMs that must be split */ public Split(Collection> parts) { this(parts, false); } /** * Make a new constraint. * * @param parts the disjoint sets of VMs that must be split * @param continuous {@code true} for a continuous restriction */ public Split(Collection> parts, boolean continuous) { super(continuous); Set all = new HashSet<>(); int cnt = 0; for (Collection s : parts) { cnt += s.size(); all.addAll(s); if (cnt != all.size()) { throw new IllegalArgumentException("The constraint expects disjoint sets of VMs"); } } this.sets = parts; } @Override public Set getInvolvedVMs() { Set s = new HashSet<>(); sets.forEach(s::addAll); return s; } /** * Get the groups of VMs identifier. * * @return the groups */ public Collection> getSets() { return this.sets; } /** * Get the group of VMs that contains the given VM. * * @param u the VM identifier * @return the group of VM if exists, an empty collection otherwise */ public Collection getAssociatedVGroup(VM u) { for (Collection vGrp : sets) { if (vGrp.contains(u)) { return vGrp; } } return Collections.emptySet(); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Split split = (Split) o; return isContinuous() == split.isContinuous() && Objects.equals(sets, split.sets); } @Override public int hashCode() { return Objects.hash(sets, isContinuous()); } @Override public String toString() { return "split(vms=" + sets + ", " + (isContinuous() ? "continuous" : "discrete") + ')'; } @Override public SplitChecker getChecker() { return new SplitChecker(this); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy