public PropertyGroup(Collection<Property> properties) { this.properties = new HashMap<String, Property>(); for (Property p: properties) { this.add(p); } }
public void setProperty(String key, String value){ if(this.properties.containsKey(key)){ if(value != null) this.properties.get(key).setValue(value); else this.properties.remove(key); } else{ Property p = new Property(key, value); this.properties.add(p); } }
@Override public String get(Object o) { return valueOf(o.toString()); }
public Boolean scaleOut(VMInstance vmi,Provider provider){ Scaler scaler = new Scaler(currentModel, coordinator, this); if(provider.getProperties().get("MaxVMs") != null) { int max = Integer.parseInt(provider.getProperties().valueOf("MaxVMs")); if (nbVMFromProvider(provider) + 1 < max) { scaler.scaleOut(vmi, provider); } else { if (coordinator != null) { coordinator.ack("MaxVMsReached", this.getClass().getName()); } return false; } }else { scaler.scaleOut(vmi,provider); } return true; }
public boolean isDefined(String propertyName) { return get(propertyName) != null; }
@Override public void validate(Report report) { final PropertyGroup demands = getRequiredEnd().getType().getDemands(); for (Property demand : demands) { final PropertyGroup offers = getProvidedEnd().getType().getOffers(); if (!offers.isDefined(demand.getName())) { final String error = String.format("Mismatch between demands and offers! Demanded: %s, but %s is not offered", demand, demand.getName()); report.addError(error); } else { if (!offers.contains(demand)) { final Property offer = offers.get(demand.getName()); final String error = String.format("Mismatch between demands and offers!! Demanded: %s, but offered %s", demand, offer); report.addError(error); } } } }
public boolean containsAll(PropertyGroup other) { for (final Property property: other) { if (!contains(property)) { return false; } } return true; }
public ProvidedExecutionPlatform(String name, Collection<Property> offers) { super(name); this.offers = new PropertyGroup(offers); }
public boolean match(RequiredExecutionPlatform platform) { return getOffers().containsAll(platform.getDemands()); }
public Boolean scaleOut(VMInstance vmi){ Scaler scaler = new Scaler(currentModel, coordinator, this); if(vmi.getType().getProvider().getProperties().get("MaxVMs") != null) { int max = Integer.parseInt(vmi.getType().getProvider().getProperties().valueOf("MaxVMs")); if (nbVMFromProvider(vmi.getType().getProvider()) +1 < max) { scaler.scaleOut(vmi); }else{ if (coordinator != null) { coordinator.ack("MaxVMsReached", this.getClass().getName()); } return false; } }else{ scaler.scaleOut(vmi); } return true; }
public boolean contains(String name, String value) { final Property p = get(name); if (p == null) { return false; } return p.hasValue(value); }
public boolean hasProperty(String key, String value) { return this.properties.contains(key, value); }
public RequiredExecutionPlatform(String name, Collection<Property> demands) { super(name); this.demands = new PropertyGroup(demands); }
public boolean canHost(InternalComponent component) { return offers.containsAll(component.getRequiredExecutionPlatform().getDemands()); }
@Override public String put(String k, String v) { this.add(new Property(k,v)); return k; }
public Boolean scaleOut(VMInstance vmi, int nb){ Scaler scaler = new Scaler(currentModel, coordinator, this); if(vmi.getType().getProvider().getProperties().get("MaxVMs") != null) { int max = Integer.parseInt(vmi.getType().getProvider().getProperties().valueOf("MaxVMs")); if (nbVMFromProvider(vmi.getType().getProvider()) + nb < max) { scaler.scaleOut(vmi,nb); }else{ if (coordinator != null) { coordinator.ack("MaxVMsReached", this.getClass().getName()); } return false; } }else { scaler.scaleOut(vmi, nb); } return true; }
public String valueOf(String name) { return get(name).getValue(); }
public static ConfigValet createValet(RelationshipInstance relation, Resource resource){ if(resource.hasProperty("valet")){ String type = resource.getProperties().valueOf("valet"); if("war-xml".equals(type)) return new WarXmlConfigValet(relation, resource); } return null; }
public boolean contains(Property property) { return contains(property.getName(), property.getValue()); }
public WithProperties(String name) { super(name); properties = new PropertyGroup(); }