-
Notifications
You must be signed in to change notification settings - Fork 1
Simple Example
Now that you've successfully configured the environment, we can start using the LinkedUSDL Pricing API!
Suppose we're trying to describe a Cloud Service provided by a business entity. The service has some characteristics and, the customer is able to rent/use it in exchange for a fee. For this particular example, suppose the customer is charged a single fee for each month he used/rented the service.
To create a semantic description of the Service, you only need to follow these three steps:
- Step 1 - Create an instance of the Service class and populate it with some features/attributes.
- Step 2 - Create an instance of the Offering class, link the created Service and define its Price Plan.
- Step 3 - Call the WriteToModel() function to create the Sematic (RDF/Turtle) representation of the Service.
First, we need to create an object to represent Service and its features. This is done by creating an instance of the Service class:
//Offerings container
LinkedUSDLModel jmodel;
jmodel = LinkedUSDLModelFactory.createEmptyModel();
Service serv1 = new Service();// create an empty service
serv1.setName("Service1");
serv1.setComment("This is an imaginary service.");
Now that we have a container for the Service features, we can create and link them to the Service instance. The API considers two different types of features:
- Qualitative Features - Their value can't be quantified, it's a specific word or phrase to describe a thing or express a concept therefore, their value is a String (e.g: Windows Server, SSD, MySQL, ...).
- Quantitative Features - Their value can be quantified ( e.g: MemorySize or CPU Speed ) thus, their value is a double.
Each feature needs a type to give some kind of meaning to its value. To achieve this, the API includes the CLOUDEnum which helps us pick the appropriate type for the feature at hand. For this example, let's consider the following features for the service:
-
Qualitative Features:
- Location: Europe
- Windows: Windows Server 2012 R2
- Performance: High
-
Quantitative Features:
- Availability: 99%
- DiskSize: 400 Gb
- MemorySize: 6 Gb
- Qualitative Features Description
QualitativeValue qualfeat1 = new QualitativeValue();
QualitativeValue qualfeat2 = new QualitativeValue();
QualitativeValue qualfeat3 = new QualitativeValue();
qualfeat1.addType(CLOUDEnum.PERFORMANCE.getConceptURI());//feature type, CloudTaxonomy-> Performance
qualfeat1.setComment("Feature that specifies the performance of the service");//feature comment
qualfeat1.setHasLabel("High");//feature value
serv1.addQualFeature(qualfeat1);//add the feature to the service
qualfeat2.addType(CLOUDEnum.LOCATION.getConceptURI());
qualfeat2.setComment("Feature that specifies the location of the service");
qualfeat2.setHasLabel("Europe");
serv1.addQualFeature(qualfeat2);
qualfeat3.addType(CLOUDEnum.WINDOWS.getConceptURI());
qualfeat3.setComment("Feature that specifies the OS of the service");
qualfeat3.setHasLabel("Windows Server 2012 R2");
serv1.addQualFeature(qualfeat3);
//////////////////////////////////////////////////////////
- Quantitative Features Description
QuantitativeValue quantfeat1 = new QuantitativeValue();
QuantitativeValue quantfeat2 = new QuantitativeValue();
QuantitativeValue quantfeat3 = new QuantitativeValue();
quantfeat1.addType(CLOUDEnum.AVAILABILITY.getConceptURI());//feature type
quantfeat1.setValue(99);//quantitative value
quantfeat1.setUnitOfMeasurement("P1");//unit of measurement - P1
quantfeat1.setComment("Feature that specifies the availability of the service");//feature comment
serv1.addQuantFeature(quantfeat1);//link the feature to the service
quantfeat2.addType(CLOUDEnum.DISKSIZE.getConceptURI());
quantfeat2.setValue(400);
quantfeat1.setUnitOfMeasurement("E34");//unit of measurement - E34
quantfeat2.setComment("Feature that specifies the disk size of the service");
serv1.addQuantFeature(quantfeat2);
quantfeat3.addType(CLOUDEnum.MEMORYSIZE.getConceptURI());
quantfeat3.setValue(6);
quantfeat1.setUnitOfMeasurement("E34");//unit of measurement - E34
quantfeat3.setComment("Feature that specifies the RAM size of the service");
serv1.addQuantFeature(quantfeat3);
////////////////////////////////////////////////////////////////////////////////
With this, our Service description is complete! Now, we can proceed to step 2, creating the Service's PricePlan.
### Step 2: Create an instance of the Offering class, link the created _Service_ and define its Price PlanNow that we've created and populated our Service object, let's link it to an appropriate description of it's pricing model. As specified at the beggining of the page, the customer needs to pay a fee per each month he used/is going to use the service. The total cost of the service is easily reproduced by the following mathematical expression: NMonths * ServiceCostPMonth.
Looking at the mathematical expression, we identify two different types of variables:
- Variables whose value we know à priori - Provider Variables
- Variables whose value is only known by the customer - Usage Variables
In our case, NMonths is the Usage Variable since the number of months that the service will be rented depends solely on the consumer. ServiceCostPMonth, on the other hand, is the Provider Variable since its the provider that decides cost of the service per month. Let's assume that the cost of the rental (per month) of the service we just modeled is 160 euros.
Once we know this information, we're ready to start describing the Service's Price Plan:
First, we need to create an instance of the Offering class and add our service instance to it:
////////////////////////////////////////////////////////////////////////////////
Offering off1 = new Offering();
off1.setComment("Offering that includes the serv1 and its Price Plan");
off1.addService(serv1);//link serv1 to the offering
off1.setName("Offering1");
Let's create an instance of the PricePlan class and link it to the created Offering instance. This class is the container for every object necessary to describe and calculate the cost of the service.
PricePlan pp1 = new PricePlan();//Price plan of the Offering1
pp1.setComment("PricePlan of the offering1");
pp1.setName("PricePlan1");
off1.setPricePlan(pp1);//link the price plan to the offering
Each PricePlan instance needs to contain at least one instance of the PriceComponent class. As the name implies, each of these PriceComponents is a component that influences the final cost of the service. For example, we could have a PriceComponent to model the mathematical expression that is responsible for calculating the cost of a certain attribute of the Service (e.g: a certain fee for including an Oracle database), and use another PriceComponent to model the mathematical expression that calculates the cost of the service after a certain period of usage. The final cost would be the sum of the values returned by the two PriceComponents. We can also imagine another case where we could use a third Price Component to model a mathematical expression that is responsible for calculating a certain deduction that is to be applied on the total cost of the service. While it's possible to model these scenarios using the API, they fall out of the scope of this simple example and shall be introduced on the following examples.
For this example, we only need a single PriceComponent to model the mathematical expression described above:
PriceComponent pc1 = new PriceComponent();//PriceComponent of the PricePlan1
pc1.setComment("PriceComponent of the PricePlan1");
pc1.setName("PriceComponent1");
pp1.addPriceComponent(pc1);//link the price component to the price plan
Now, we need to model the mathematical expression and link it to the PriceComponent. To achieve this, we need to create an instance of the PriceFunction class:
PriceFunction pf1 = new PriceFunction();
pf1.setComment("Price Function to calculate the price of the PriceComponent1");
pf1.setName("PriceFunction1");
pc1.setPriceFunction(pf1);//link it to the PriceComponent
There are two steps to correctly model the mathematical expression:
- Step 1 - Describe the mathematical expression variables using the Usage and Provider classes.
- Step 2 - Create a String representation of the mathematical expression.
As explained earlier, there are two types of variables: Usage and Provider. In this example, we identified one Usage variable ( NMonths ) and one Provider variable ( ServiceCostPMonth ):
Provider provvar1 = new Provider();//constant variable of the function
provvar1.setComment("Constant variable of the function1. Specifies the monthly cost of the VM instance.");
provvar1.setName("serv1mcost");
QuantitativeValue monthly_cost = new QuantitativeValue();//variable's value
monthly_cost.setValue(160);//160euros per month for the instance specified above
monthly_cost.setUnitOfMeasurement("EUR");
provvar1.setValue(monthly_cost);
pf1.addProviderVariable(provvar1);//link the variable to the function1
Usage usagevar1 = new Usage();//dynamic variable of the function - User dependent
usagevar1.setComment("Usage variable of the function1. Represents the number of months the user will be renting this service");
usagevar1.setName("serv1nmonths");
pf1.addUsageVariable(usagevar1);//link the usage variable to the function1
Now that we've modeled the variables, we just need to create the String representation of the mathematical expression.
##### Step 2: Create a String representation of the mathematical expressionOnce everything's been modeled, we just need to create the String representation of the mathematical expression using the traditional mathematical syntax:
String form = provvar1.getName()+" * "+ usagevar1.getName();
pf1.setStringFunction(form);//set the string mathematical expression
NOTE: It's important to note that the String needs to use the same name as the one defined when creating the variable instance.
### Step 3: Call the _WriteToModel()_ function to create the Sematic (RDF/Turtle) representation of the ServiceNow that everything has been correctly modeled, we just need to add our Offering instance to the LinkedUSDLModel instance, set a base URI (it can be anything you want as long as it's a String) and call the WriteToModel() function.
ArrayList<Offering> offerings = new ArrayList<Offering>();
offerings.add(off1);
jmodel.setOfferings(offerings);//add the created offering to the LinkedUSDLModel instance.
jmodel.setBaseURI("http://PricingAPISimpleExample.com");
Model instance = jmodel.WriteToModel();//transform the java models to a semantic representation
File outputFile = new File("./simple_example.ttl");
if (!outputFile.exists()) {
outputFile.createNewFile();
}
FileOutputStream out = new FileOutputStream(outputFile);
instance.write(out, "Turtle");
out.close();
Compile it and, if everything went as expected, you'll see a new .ttl file with a semantic description of the service on the directory of your project!
Source code of the example can be found here.
#####[Next: Modeling an Amazon EC2 Cloud Service](Amazon EC2)