diff options
author | pikusa <pikusa@man.poznan.pl> | 2013-04-03 13:18:17 (GMT) |
---|---|---|
committer | pikusa <pikusa@man.poznan.pl> | 2013-04-03 13:18:17 (GMT) |
commit | 2f2a3a129c91de540e66c3bfbe30b0df1942cd4b (patch) | |
tree | 2d313cdf0068af368d4de6067d676be16f6a6464 /request-handler | |
parent | ff8aa232b071a9b54dff833714a870fd0aec0b30 (diff) | |
download | novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.zip novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.gz novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.bz2 |
project commit and dir tree change
Diffstat (limited to 'request-handler')
5 files changed, 282 insertions, 0 deletions
diff --git a/request-handler/pom.xml b/request-handler/pom.xml new file mode 100644 index 0000000..ae3a6d9 --- /dev/null +++ b/request-handler/pom.xml @@ -0,0 +1,91 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>eu.novi</groupId> + <artifactId>parent</artifactId> + <version>0.1.0-SNAPSHOT</version> + <relativePath>../parent/</relativePath> + </parent> + <artifactId>request-handler</artifactId> + <packaging>bundle</packaging> + <name>Federated slice</name> + + <developers> + <developer> + <id>blazej.pietrzak</id> + <name>Blazej Pietrzak</name> + <email>blazej.pietrzak@man.poznan.pl</email> + <organization>PSNC</organization> + <organizationUrl>http://www.man.poznan.pl/</organizationUrl> + <roles> + <role>architect</role> + <role>developer</role> + </roles> + <timezone>+1</timezone> + </developer> + </developers> + + <dependencies> + <dependency> + <groupId>eu.novi</groupId> + <artifactId>framework</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.servicemix.bundles</groupId> + <artifactId>org.apache.servicemix.bundles.bcprov-jdk16</artifactId> + <version>1.46_1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.servicemix.bundles</groupId> + <artifactId>org.apache.servicemix.bundles.jzlib</artifactId> + <scope>compile</scope> + <version>1.0.7_1</version> + </dependency> + + <dependency> + <groupId>net.schmizz</groupId> + <artifactId>sshj</artifactId> + <version>0.6.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>eu.novi</groupId> + <artifactId>resources</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>eu.novi</groupId> + <artifactId>resources-federica</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>eu.novi</groupId> + <artifactId>resources-planetlab</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Export-Package>eu.novi.federation.*</Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/request-handler/src/main/java/eu/novi/federation/FederatedTestbed.java b/request-handler/src/main/java/eu/novi/federation/FederatedTestbed.java new file mode 100644 index 0000000..0d07411 --- /dev/null +++ b/request-handler/src/main/java/eu/novi/federation/FederatedTestbed.java @@ -0,0 +1,14 @@ +package eu.novi.federation; + +/** + * Represents the combined testbed. + * + * Federation strategies must implement it e.g. SFA. + * + * @author <a href="mailto:blazej.pietrzak@man.poznan.pl">Blazej Pietrzak</a> + * + */ +public interface FederatedTestbed { + + void configure(Slice slice); +} diff --git a/request-handler/src/main/java/eu/novi/federation/Slice.java b/request-handler/src/main/java/eu/novi/federation/Slice.java new file mode 100644 index 0000000..2adf08c --- /dev/null +++ b/request-handler/src/main/java/eu/novi/federation/Slice.java @@ -0,0 +1,58 @@ +package eu.novi.federation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import eu.novi.resources.Resource; + +/** + * Represents a federated slice. + * + * @author <a href="mailto:blazej.pietrzak@man.poznan.pl">Blazej Pietrzak</a> + * @author <a href="mailto:pikusa@man.poznan.pl">Piotr Pikusa</a> + * + */ +public class Slice { + private Collection<Resource> resources = new ArrayList<Resource>(); + + private boolean configured = false; + + private boolean update = false; + + public void addResource(Resource resource) { + resources.add(resource); + update = configured; + } + + public boolean isUpdated() { + return update; + } + + public boolean isConfigured(){ + return configured; + } + + /** + * Create or update a slice. + * + * @param testbed federation strategy + */ + public void configure(FederatedTestbed testbed) { + testbed.configure(this); + + for (Resource resource : resources) + resource.configure(); + + configured = true; + } + + /** + * Release the resources included in the slice + */ + public void releaseResources(){ + for (Resource resource : resources) + resource.release(); //TODO change it to the the release method!! + + } +} diff --git a/request-handler/src/test/java/eu/novi/federation/FederatedResourcesIT.java b/request-handler/src/test/java/eu/novi/federation/FederatedResourcesIT.java new file mode 100644 index 0000000..55af453 --- /dev/null +++ b/request-handler/src/test/java/eu/novi/federation/FederatedResourcesIT.java @@ -0,0 +1,61 @@ +package eu.novi.federation; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.Configuration; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.osgi.framework.BundleContext; + +import eu.novi.framework.IntegrationTesting; + +/** + * Integration tests for federated resources in PlanetLab and FEDERICA. + * + * @author <a href="mailto:blazej.pietrzak@man.poznan.pl">Blazej Pietrzak</a> + * + */ +@RunWith(JUnit4TestRunner.class) +public class FederatedResourcesIT { + private static final String TESTBED_FEDERICA = "(testbed=FEDERICA)"; + private static final String TESTBED_PLANETLAB = "(testbed=PlanetLab)"; + private static final String TESTBED_ALL = null; + + private static final String RESOURCE_SERVICE = "eu.novi.resources.Resource"; + private static final String ROUTER_SERVICE = "eu.novi.resources.Router"; + private static final String NODE_SERVICE = "eu.novi.resources.Node"; + + @Configuration + public static Option[] configuration() throws Exception { + return IntegrationTesting.createConfigurationWithBundles( + "resources-federica", "resources-planetlab"); + } + + /*IT tests temporary commented + @Test + public void findAllResources(BundleContext ctx) throws Exception { + ctx.getServiceReferences(null, null); + assertEquals(3, ctx.getServiceReferences(RESOURCE_SERVICE, TESTBED_ALL).length); + } + + @Test + public void findPlanetLabSliver(BundleContext ctx) throws Exception { + ctx.getServiceReferences(null, null); + assertEquals(1, ctx.getServiceReferences(NODE_SERVICE, TESTBED_PLANETLAB).length); + } + + @Test + public void findFEDERICAVM(BundleContext ctx) throws Exception { + ctx.getServiceReferences(null, null); + assertEquals(1, ctx.getServiceReferences(NODE_SERVICE, TESTBED_FEDERICA).length); + } + + @Test + public void findFEDERICARouter(BundleContext ctx) throws Exception { + ctx.getServiceReferences(null, null); + assertEquals(1, ctx.getServiceReferences(ROUTER_SERVICE, TESTBED_FEDERICA).length); + } + */ +} diff --git a/request-handler/src/test/java/eu/novi/federation/SliceConfigurationTest.java b/request-handler/src/test/java/eu/novi/federation/SliceConfigurationTest.java new file mode 100644 index 0000000..0133d65 --- /dev/null +++ b/request-handler/src/test/java/eu/novi/federation/SliceConfigurationTest.java @@ -0,0 +1,58 @@ +package eu.novi.federation; + +/** + * Unit test case for slice configuration. + * + * @author <a href="mailto:blazej.pietrzak@man.poznan.pl">Blazej Pietrzak</a> + * + */ +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import eu.novi.resources.Resource; + +public class SliceConfigurationTest { + + protected Slice slice; + protected Resource resource1, resource2; + protected FederatedTestbed federatedTestbed; + + @Before + public void givenSliceWithResources() throws Exception { + slice = new Slice(); + resource1 = mock(Resource.class); + resource2 = mock(Resource.class); + slice.addResource(resource1); + slice.addResource(resource2); + + federatedTestbed = mock(FederatedTestbed.class); + slice.configure(federatedTestbed); + } + + @After + public void tearDown() throws Exception { + slice = null; + resource1 = null; + resource2 = null; + federatedTestbed = null; + } + + @Test + public void checkFederatedTestbedConfigured() { + verify(federatedTestbed).configure(slice); + } + + @Test + public void checkResource1Configured() { + verify(resource1).configure(); + } + + @Test + public void checkResource2Configured() { + verify(resource2).configure(); + } +} |