FCI tutorials

Introductory video tutorial

Federation Computing Interface (FCI), is an API for accessing resources of a resources federation via brokers.
This 6 minutes tutorial demonstrates how to use FCI. We take for example a ready scenario from FSToolkit and we make a Java code generation to prepare a FCI API skeleton code to manage our experimentation scenario and request resources with Java.
The video demonstrates how you can have complete control and how you can define complex scenarios and workflows within Java.
 

 

An example using the FCI within Java

Here is a simple example of creating and operating an experiment within Java by means of FCI:

		/*************************************************************************
		Copyright 2012 nam.ece.upatras.gr 
		
		Licensed under the Apache License, Version 2.0 (the "License"); 
		you may not use this file except in compliance with the License. 
		You may obtain a copy of the License at 
		
		http://www.apache.org/licenses/LICENSE-2.0 
		Unless required by applicable law or agreed to in writing, software 
		distributed under the License is distributed on an "AS IS" BASIS, 
		WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
		See the License for the specific language governing permissions and 
		limitations under the License. 
		*************************************************************************/
		
		
		package scenario;
		
		import java.util.ArrayList;
		import java.util.List;		
		import gr.upatras.ece.nam.fci.core.FCI;
		import gr.upatras.ece.nam.fci.core.ParameterValuePair;
		import gr.upatras.ece.nam.fci.core.ResourceContext;
		import gr.upatras.ece.nam.fci.core.ResourceGroup;
		import gr.upatras.ece.nam.fci.core.ResourceProvider;
		import gr.upatras.ece.nam.fci.core.ResourceProxy;
		import gr.upatras.ece.nam.fci.core.ServiceType;
		import brokermodel.fcielements.AuthorizationKey;
		import brokermodel.fcielements.FCICredentials;
		
		public class myScenario {
			

			FCI fci = FCI.getInstance();
			
			//for each imported office, we need a Resource Context	
			 //TODO: Please enter here identity for p2e
			String _username_p2e ="username";
			String _password_p2e ="pass";
			ResourceContext _context_p2e;
			
			public ResourceContext _return_context_p2e(){ 
				//credentials for amazon Broker
				FCICredentials cred = fci.createFCICredentials(_username_p2e, _password_p2e);
				AuthorizationKey authKey = fci.createAuthorizationKey(cred);
				ResourceContext _context_p2e = fci.createResourceContext("p2e", authKey);
				return _context_p2e;
			}
			
					
			//
			private ResourceProxy createResource_myecho(){
				//Create a service type by its name
				ServiceType service = _context_p2e.getServiceType("echo");
				
				//get a resource provider 
				ResourceProvider provider = _context_p2e.getResourceProviderByName("upatras");
				
				//create Parameters of a resource
				List params = new ArrayList();
				ParameterValuePair p;
				p = new ParameterValuePair("sleeptime_ms", "1000", "sleeptime_ms");
				params.add(p);
				p = new ParameterValuePair("output", "", "output");
				params.add(p);
				p = new ParameterValuePair("input", "HelloWorld", "input");
				params.add(p);
				ResourceProxy resource_myecho = _context_p2e.createResourceProxy(
					"myScenario", 
					"echo", 
					"myecho", 
					provider, service, params);
				return  resource_myecho;
			}
			/**
			 * @param args
			 */
			public static void main(String[] args) {
				new myScenario();
		
			}
			
			//for each imported office, we need credentials
		
			public myScenario() {
				CreateContexts();
				CreateScenario();
			}
			
			public void CreateContexts(){
				_context_p2e = _return_context_p2e();
				
			}
		
			private void CreateScenario() {
		    //    Group (for grouping resources)
				ResourceGroup myGroup = FCI.getInstance().createResourceGroup("myGroup");
				//all creates				
				ResourceProxy resource_myecho = createResource_myecho();
				System.out.println("myecho resource GUID: " + resource_myecho.getGUID());
				myGroup.addResourceProxy(resource_myecho);
								 
				
//				System.out.println("Echo input = "+ resource_myecho.getParameterValueOfResource("input", true));
//				//assignments
//				// Update assignments for resources of group

				
				//example reads
				System.out.println("myecho sleeptime_ms = "+ resource_myecho.getParameterValueOfResource("sleeptime_ms", true));
				System.out.println("myecho output = "+ resource_myecho.getParameterValueOfResource("output", true));
				System.out.println("myecho input = "+ resource_myecho.getParameterValueOfResource("input", true));
				
				// Terminate the group..terminate any contained resources and release scenario
				myGroup.TearDownResources();
				}
		
			
		
		
		}
		

Use the following to get an instance of FCI:

 FCI fci = FCI.getInstance(); 

Then get a resource context for a specific resource broker/provider:

String _username_p2e ="username";
			String _password_p2e ="pass";
			ResourceContext _context_p2e;
			

The next thing is to connect to the provider/broker. In this case we will use our p2e credentials to connect to p2e. The FCI command createResourceContext it is used to connect to "p2e" broker.

			public ResourceContext _return_context_p2e(){ 
				//credentials for amazon Broker
				FCICredentials cred = fci.createFCICredentials(_username_p2e, _password_p2e);
				AuthorizationKey authKey = fci.createAuthorizationKey(cred);
				ResourceContext _context_p2e = fci.createResourceContext("p2e", authKey);
				return _context_p2e;
			}

First is to create a group under which you can aggregate your resources by (createResourceGroup) and then go to create access for your required resource:

ResourceGroup myGroup = FCI.getInstance().createResourceGroup("myGroup");
				//all creates				
				ResourceProxy resource_myecho = createResource_myecho();
				System.out.println("myecho resource GUID: " + resource_myecho.getGUID());
				myGroup.addResourceProxy(resource_myecho);