@Override public Capacity buildConstraint(VJobElementBuilder eBuilder, List<PBVJob.vjob.Param> args) throws ConstraintBuilderException { PBPlacementConstraintBuilders.ensureArity(this, args, 2); ManagedElementSet<Node> ns = PBPlacementConstraintBuilders.makeNodes(eBuilder, args.get(0)); if (ns.isEmpty()) { throw new ConstraintBuilderException(args.get(0) + " is an empty set"); } int v = PBPlacementConstraintBuilders.makeInt(args.get(1)); if (v < 0) { throw new ConstraintBuilderException("capacity can not be negative (" + v + ")"); } return new Capacity(ns, v); }
@Override public Root buildConstraint(List<VJobElement> args) throws ConstraintBuilderException { if (args.size() != 1) { throw new ConstraintBuilderException(this); } try { ManagedElementSet<VirtualMachine> vms = (ManagedElementSet<VirtualMachine>) args.get(0); if (vms.isEmpty()) { throw new ConstraintBuilderException("Empty set not allowed"); } return new Root(vms); } catch (ClassCastException e) { throw new ConstraintBuilderException(getSignature(), e); } }
private void make(Configuration cfg) { VJob v = new BasicPlasmaVJob("vappHA"); ManagedElementSet<VirtualMachine> t1 = new SimpleManagedElementSet<VirtualMachine>(); t1.add(cfg.getAllVirtualMachines().get("vappHA.VM1")); t1.add(cfg.getAllVirtualMachines().get("vappHA.VM2")); t1.add(cfg.getAllVirtualMachines().get("vappHA.VM3")); v.addConstraint(new ContinuousSpread(t1)); v.addVirtualMachine(cfg.getAllVirtualMachines().get("vappHA.VM10")); v.addVirtualMachine(cfg.getAllVirtualMachines().get("vappHA.top")); v.addVirtualMachine(cfg.getAllVirtualMachines().get("vappHA.middle")); ManagedElementSet<Node> ns = new SimpleManagedElementSet<Node>(); ns.add(cfg.getOnlines().get("node-1")); ns.add(cfg.getOnlines().get("node-2")); v.addConstraint(new Capacity(ns, 15)); ManagedElementSet<Node> ns2 = new SimpleManagedElementSet<Node>(); ns2.add(cfg.getOnlines().get("node-3")); ns2.add(cfg.getOnlines().get("node-4")); Set<ManagedElementSet<Node>> x = new HashSet<ManagedElementSet<Node>>(); x.add(ns); x.add(ns2); v.addConstraint(new Among(t1, x)); v.addConstraint(new Ban(t1, ns2)); try { ProtobufVJobSerializer.getInstance().write(v, RESOURCE); } catch (Exception e) { Assert.fail(e.getMessage(), e); } }
// select the node state variable in order @Override public IntDomainVar selectVar() { // ManagedElementSet<VirtualMachine> allVMS = // pb.getSourceConfiguration().getAllVirtualMachines(); // IntDomainVar[] hosters = new IntDomainVar[allVMS.size()]; // for(int i = 0; i < allVMS.size(); i++) { // VirtualMachine vm = pb.getVirtualMachine(i); // hosters[i] = pb.getAssociatedAction(vm).getDemandingSlice().hoster(); // if(hosters[i].isInstantiated()) { // log.debug("hoster " + i + " instancied " + hosters[i].getVal()); // } else { // log.debug("hoster " + i + " not instancied "); // } // } for (int i = 0; i < nodes.size(); i++) { Node n = nodes.get(i); // future online and future offline should have their state set already if (!pb.getFutureOnlines().contains(n) && !pb.getFutureOfflines().contains(n)) { ManageableNodeActionModel action = (ManageableNodeActionModel) pb.getAssociatedAction(n); log.debug("Node " + n.getName()); log.debug("state instancied " + action.getState().isInstantiated()); // Select the empty nodes first if (!action.getState().isInstantiated() && pb.getUsedMem(n).isInstantiatedTo(0)) { log.debug("select node " + n.getName() + " for switch off"); return action.getState(); } if (pb.getUsedMem(n).isInstantiatedTo(0) && !action.start().isInstantiated()) { log.debug("select node " + n.getName() + " for start"); return action.start(); } } } return null; }