Skip to content

Commit

Permalink
Finished the pos-merge code revision. Both API and examples are now
Browse files Browse the repository at this point in the history
functional along with its validation methods.
  • Loading branch information
dguedesb committed Apr 29, 2014
1 parent ff6b749 commit 3c0e544
Show file tree
Hide file tree
Showing 31 changed files with 1,698 additions and 1,746 deletions.
580 changes: 286 additions & 294 deletions SPIN_API/DebuggingFiles/CloudsigmaRS.ttl

Large diffs are not rendered by default.

788 changes: 390 additions & 398 deletions SPIN_API/DebuggingFiles/MAzureSmallPrePaid6m.ttl

Large diffs are not rendered by default.

435 changes: 213 additions & 222 deletions SPIN_API/DebuggingFiles/VMWareVPCloud.ttl

Large diffs are not rendered by default.

301 changes: 146 additions & 155 deletions SPIN_API/DebuggingFiles/amazonOD.ttl

Large diffs are not rendered by default.

392 changes: 199 additions & 193 deletions SPIN_API/DebuggingFiles/amazonRI.ttl

Large diffs are not rendered by default.

329 changes: 162 additions & 167 deletions SPIN_API/DebuggingFiles/amazonSI.ttl

Large diffs are not rendered by default.

285 changes: 140 additions & 145 deletions SPIN_API/DebuggingFiles/arsys.ttl

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions SPIN_API/src/priceModelValidation/AmazonODReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

package priceModelValidation;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

import com.hp.hpl.jena.rdf.model.Model;

import usdl.servicemodel.LinkedUSDLModel;
import usdl.servicemodel.LinkedUSDLModelFactory;
import usdl.servicemodel.Offering;
Expand All @@ -16,9 +20,6 @@
import usdl.servicemodel.PricePlan;
import usdl.servicemodel.QuantitativeValue;
import usdl.servicemodel.Usage;

import com.hp.hpl.jena.rdf.model.Model;

import exceptions.InvalidLinkedUSDLModelException;
import exceptions.ReadModelException;

Expand Down Expand Up @@ -76,14 +77,14 @@ public int compare(Usage s1, Usage s2) {
jmodel.setBaseURI("http://PricingAPIAmazonODInstance.com");
Model instance = jmodel.WriteToModel();//after we've done our changes in the jmodels, we transform them into a new Semantic model
//write model to file
/*File outputFile = new File("your_directory/amazonRIInstance.ttl");
File outputFile = new File("./amazonODInstance.ttl");
if (!outputFile.exists()) {
outputFile.createNewFile();
}

FileOutputStream out = new FileOutputStream(outputFile);
instance.write(out, "Turtle");
out.close();*/
out.close();

//after applying the changes to the jmodels and transforming them to a semantic web representation, we can calculate the prices of every offerings.
for(Offering off : myOfferings)
Expand Down
3 changes: 2 additions & 1 deletion SPIN_API/src/priceModelValidation/AmazonOnDemand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void main(String[] args) throws IOException, InvalidLinkedUSDLMode

AmazonOnDemandOffering(jmodel);

// jmodel.setBaseURI("http://PricingAPIAmazonOnDemandOfferings.com");
//
// for (Offering of : jmodel.getOfferings())
// {
Expand All @@ -54,6 +54,7 @@ public static void main(String[] args) throws IOException, InvalidLinkedUSDLMode
// }
// }
// }
// jmodel.setBaseURI("http://PricingAPIAmazonOnDemandOfferings.com");
Model instance = jmodel.WriteToModel();//transform the java models to a semantic representation

File outputFile = new File("./DebuggingFiles/amazonOD.ttl");
Expand Down
4 changes: 2 additions & 2 deletions SPIN_API/src/priceModelValidation/Arsys.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ private static void ArsysOffering(LinkedUSDLModel jmodel) throws IOException, In
//since there's another 4 possible OS system, means that the created server actually gives birth to 5 possible offerings instead of one:

//s1 includes CentOS
Service s2 = s1;//s2 includes Red Hat Enterprise Linux 6
Service s2 = new Service(s1);//s2 includes Red Hat Enterprise Linux 6
ArrayList<QuantitativeValue> s2QuantFeat = (ArrayList<QuantitativeValue>) s1QuantFeat.clone();//container for the Quantitative Features
ArrayList<QualitativeValue> s2QualFeat = (ArrayList<QualitativeValue>) s1QualFeat.clone();//container for the Qualitative Features
Service s3 = s1;//s3 includes Windows Server R2 2008 Web Ed.
Service s3 =new Service( s1);//s3 includes Windows Server R2 2008 Web Ed.
ArrayList<QuantitativeValue> s3QuantFeat = (ArrayList<QuantitativeValue>) s1QuantFeat.clone();//container for the Quantitative Features
ArrayList<QualitativeValue> s3QualFeat = (ArrayList<QualitativeValue>) s1QualFeat.clone();//container for the Qualitative Features
//every new service is the same as the s1 but with the difference that each possesses a different OS
Expand Down
2 changes: 1 addition & 1 deletion SPIN_API/src/priceModelValidation/CloudSigmaReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public int compare(Usage s1, Usage s2) {
}
else
{
var.setValue(definedVariables.get(var.getName().replaceAll("TIME\\d+.*", "")).getValue());
var.setValue( new QuantitativeValue((QuantitativeValue)definedVariables.get(var.getName().replaceAll("TIME\\d+.*", "")).getValue()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public int compare(Usage s1, Usage s2) {
}
else
{
var.setValue(definedVariables.get(var.getName().replaceAll("TIME\\d+.*", "")).getValue());
var.setValue( new QuantitativeValue((QuantitativeValue)definedVariables.get(var.getName().replaceAll("TIME\\d+.*", "")).getValue()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion SPIN_API/src/priceModelValidation/VMWareVPCloudReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public int compare(Usage s1, Usage s2) {
}
else
{
var.setValue(definedVariables.get(var.getName().replaceAll("TIME\\d+.*", "")).getValue());
var.setValue( new QuantitativeValue((QuantitativeValue)definedVariables.get(var.getName().replaceAll("TIME\\d+.*", "")).getValue()));
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions SPIN_API/src/usdl/constants/enums/ResourceNameEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

public enum ResourceNameEnum {

OFFERING("Service Offering"),
OFFERING("ServiceOffering"),
SERVICE("Service"),
PRICEPLAN("Price Plan"),
PRICECOMPONENT("Price Component"),
PRICEFUNCTION("Price Function"),
PRICESPEC("Price Specification"),
QUANTVALUE("Quantitative Value"),
QUALVALUE("Qualitative Value"),
CLOUDPROVIDER("Business Entity"),
USAGE("Usage Variable"),
PROVIDER("Provider Variable");
PRICEPLAN("PricePlan"),
PRICECOMPONENT("PriceComponent"),
PRICEFUNCTION("Function"),
PRICESPEC("PriceSpecification"),
QUANTVALUE("QuantitativeValue"),
QUALVALUE("QualitativeValue"),
CLOUDPROVIDER("BusinessEntity"),
USAGE("Usage"),
PROVIDER("Constant");

private String name;

Expand Down
2 changes: 2 additions & 0 deletions SPIN_API/src/usdl/constants/enums/USDLCoreEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ public Resource getResource(Model model) {
return null;
}
}


}
4 changes: 3 additions & 1 deletion SPIN_API/src/usdl/queries/QueryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public static String startQueryWithBasicPrefixes(){
" PREFIX "+Prefixes.RDFS.getName()+": <"+Prefixes.RDFS.getPrefix()+"> " +
" PREFIX "+Prefixes.GR.getName()+": <"+Prefixes.GR.getPrefix()+"> " +
" PREFIX "+Prefixes.XSD.getName()+": <"+Prefixes.XSD.getPrefix()+"> "+
" PREFIX "+Prefixes.CLOUD.getName()+": <"+ Prefixes.CLOUD.getPrefix()+">";
" PREFIX "+Prefixes.CLOUD.getName()+": <"+ Prefixes.CLOUD.getPrefix()+">" +
" PREFIX "+Prefixes.SPIN.getName()+": <"+ Prefixes.SPIN.getPrefix()+">";


return query;
}
Expand Down
13 changes: 4 additions & 9 deletions SPIN_API/src/usdl/queries/ReaderQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import usdl.constants.enums.RDFEnum;

import usdl.constants.enums.USDLCoreEnum;
import usdl.constants.enums.USDLPriceEnum;

public class ReaderQueries {

Expand All @@ -20,17 +19,13 @@ public static String readAllOfferings(String variableName){
return query;
}

public static String readAllUsageVariables(String variableName){
public static String findResource(String uri, String classType){
String query = QueryUtils.startQueryWithBasicPrefixes();
query = query +
" SELECT REDUCED ?pv" +
" SELECT REDUCED ?r" +
" WHERE { " +
" ?"+variableName+" "+RDFEnum.RDF_TYPE.getPropertyString()+" "+USDLCoreEnum.OFFERING.getPropertyString()+" . " +
" ?"+variableName+" "+USDLPriceEnum.HAS_PRICE_PLAN.getPropertyString()+" "+"?pp"+" . " +
" ?"+"pp"+" "+USDLPriceEnum.HAS_PRICE_COMPONENT.getPropertyString()+" "+"?pc"+" . " +
" ?"+"pc"+" "+USDLPriceEnum.HAS_PRICE_FUNCTION.getPropertyString()+" "+"?pf"+" . " +
" ?"+"pf"+" "+USDLPriceEnum.HAS_VARIABLE.getPropertyString()+" "+"?pv"+" . " +
" ?"+"pv"+" "+RDFEnum.RDF_TYPE.getPropertyString()+" "+USDLPriceEnum.USAGE.getPropertyString()+" . " +
" ?r"+" a"+" "+classType+" . " +
" FILTER(str(?r) = \""+uri+"\" ) . " +
" }";

return query;
Expand Down
19 changes: 10 additions & 9 deletions SPIN_API/src/usdl/servicemodel/CloudProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import usdl.constants.enums.FOAFEnum;
import usdl.constants.enums.GREnum;
import usdl.constants.enums.Prefixes;
import usdl.constants.enums.RDFEnum;
import usdl.constants.enums.RDFSEnum;
import usdl.constants.enums.ResourceNameEnum;
Expand All @@ -26,7 +27,6 @@ public class CloudProvider {
private List<Service> providedServices;
private String localName = null;
private String namespace = null;
@SuppressWarnings("unused")
private final String resourceType = ResourceNameEnum.OFFERING.getResourceType();


Expand All @@ -48,7 +48,7 @@ public CloudProvider(CloudProvider source) {//copy constructor
super();

if(source.getName() != null)
this.setName(source.getName());
this.setName(source.getName() + PricingAPIProperties.resourceCounter++);

if(source.getComment() != null)
this.setComment(source.getComment());
Expand Down Expand Up @@ -171,20 +171,21 @@ protected static CloudProvider readFromModel(Resource resource, Model model){
* @param model Model to where the object is to be written on.
* @throws InvalidLinkedUSDLModelException
*/
@SuppressWarnings("null")
protected void writeToModel(Resource owner,Model model,String baseURI) throws InvalidLinkedUSDLModelException{

Resource provider = null;

if(this.namespace == null){ //no namespace defined for this resource, we need to define one
if(baseURI != null || !baseURI.equalsIgnoreCase("")) // the baseURI argument is valid
this.namespace = baseURI;
else //use the default baseURI
this.namespace = PricingAPIProperties.defaultBaseURI;
}

if(baseURI != null || !baseURI.equalsIgnoreCase("")) // the baseURI argument is valid
this.namespace = baseURI;
else if(this.getNamespace() == null) //use the default baseURI
this.namespace = PricingAPIProperties.defaultBaseURI;


if(this.localName != null){
LinkedUSDLValidator validator = new LinkedUSDLValidator();
validator.checkDuplicateURI(model, ResourceFactory.createResource(this.namespace + this.localName));
validator.checkDuplicateURI(model, ResourceFactory.createResource(this.namespace + this.localName),Prefixes.GR.getName()+":"+this.resourceType);
provider = model.createResource(this.namespace + this.localName);
if(this.name != null){
provider.addProperty(FOAFEnum.NAME.getProperty(model),model.createLiteral(this.name));
Expand Down
11 changes: 4 additions & 7 deletions SPIN_API/src/usdl/servicemodel/LinkedUSDLModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ public String getBaseURI() {

public void setBaseURI(String baseURI) {
this.baseURI = baseURI + "#";
if(prefixes.get("") != null)
prefixes.put(this.baseURI, "");
else
prefixes.put(this.baseURI, "");
prefixes.put(this.baseURI, "");
}

protected Map<String, String> getPrefixes() {
Expand Down Expand Up @@ -146,6 +143,7 @@ private List<Offering> readAllOfferings(Model model) throws InvalidLinkedUSDLMod
return offeringsList;
}

@SuppressWarnings("unused")
private List<Service> readAllServices(Model model){
List<Service> servicesList = new ArrayList<>();

Expand Down Expand Up @@ -173,15 +171,14 @@ public Model WriteToModel() throws InvalidLinkedUSDLModelException
private Model setModelPrefixes(Model model){


if(this.prefixes.get("") == null)
this.prefixes.put(this.baseURI, "");
this.prefixes.put(this.baseURI, "");

Iterator<Entry<String, String>> it = this.prefixes.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pairs = (Map.Entry<String, String>)it.next();
String key = (String)pairs.getKey(); //URI
String value = (String)pairs.getValue(); //preffix name
System.out.println(key + " -> " +value);
// System.out.println(key + " -> " +value);
model.setNsPrefix(value, key);
}
return model;
Expand Down
8 changes: 4 additions & 4 deletions SPIN_API/src/usdl/servicemodel/LinkedUSDLModelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,15 @@ public static LinkedUSDLModel createFromModel(String path, String baseURI, boole


Model model = new LinkedUSDLModelFactory().importModel(path);

//checks of the imported model already has a baseURI to use.
String uri = model.getNsPrefixURI("");
if(uri != null){
System.out.println("HAS BASE URI " + baseURI);
baseURI = uri+"#";
System.out.println("HAS BASE URI " + uri);
baseURI = uri;
}

LinkedUSDLModel linkedUSDL = new LinkedUSDLModel(baseURI);
System.out.println("BASE URI: " + baseURI);
// System.out.println("BASE URI: " + baseURI);


//TESTS
Expand Down Expand Up @@ -245,6 +244,7 @@ private Map<String, String> processPrefixes(Model model, Map<String, String> pre
String key = (String)pairs.getKey();
if(key.equalsIgnoreCase(""))
key = name;


result.put((String)pairs.getValue(), key);

Expand Down
17 changes: 8 additions & 9 deletions SPIN_API/src/usdl/servicemodel/Offering.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;

import usdl.constants.enums.Prefixes;
import usdl.constants.enums.RDFEnum;
import usdl.constants.enums.RDFSEnum;
import usdl.constants.enums.ResourceNameEnum;
Expand All @@ -25,7 +26,6 @@ public class Offering {
private String comment = null;
private String localName = null;
private String namespace = null;
@SuppressWarnings("unused")
private final String resourceType = ResourceNameEnum.OFFERING.getResourceType();

public Offering(){
Expand All @@ -46,7 +46,7 @@ public Offering(Offering source) {//copy constructor
super();

if(source.getName() != null)
this.setName(source.getName());
this.setName(source.getName() + PricingAPIProperties.resourceCounter++);

if(source.getComment() != null)
this.setComment(source.getComment());
Expand Down Expand Up @@ -167,20 +167,19 @@ public static Offering readFromModel(Resource resource, Model model){
* @param model Model to where the object is to be written on.
* @throws InvalidLinkedUSDLModelException
*/
@SuppressWarnings("null")
public void writeToModel(Model model, String baseURI) throws InvalidLinkedUSDLModelException
{
Resource offering = null;

if(this.namespace == null){ //no namespace defined for this resource, we need to define one
if(baseURI != null || !baseURI.equalsIgnoreCase("")) // the baseURI argument is valid
this.namespace = baseURI;
else //use the default baseURI
this.namespace = PricingAPIProperties.defaultBaseURI;
}
if (baseURI != null || !baseURI.equalsIgnoreCase("")) // the baseURIargument is valid
this.namespace = baseURI;
else if(this.getNamespace() == null) // use the default baseURI
this.namespace = PricingAPIProperties.defaultBaseURI;

if(this.localName != null){
LinkedUSDLValidator validator = new LinkedUSDLValidator();
validator.checkDuplicateURI(model, ResourceFactory.createResource(this.namespace + this.localName));
validator.checkDuplicateURI(model, ResourceFactory.createResource(this.namespace + this.localName),Prefixes.USDL_CORE.getName()+":"+this.resourceType);
offering = model.createResource(this.namespace + this.localName);

offering.addProperty(RDFEnum.RDF_TYPE.getProperty(model), USDLCoreEnum.OFFERING.getResource(model));//rdf type
Expand Down
Loading

0 comments on commit 3c0e544

Please sign in to comment.