Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #135 from andreisavu/api-step-1
Browse files Browse the repository at this point in the history
First step towards adding a REST API. Part of #119
  • Loading branch information
Andrei Savu committed Feb 1, 2013
2 parents b8064bc + e17e209 commit 9ae5f0f
Show file tree
Hide file tree
Showing 16 changed files with 703 additions and 92 deletions.
64 changes: 62 additions & 2 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<name>Axemblr Provisionr :: Console &amp; REST API</name>
<description>A basic web console and a REST API for Axemblr Provisionr</description>
<name>Axemblr Provisionr :: Web Console &amp; REST API</name>
<description>A basic web console and a REST API</description>

<artifactId>provisionr-console</artifactId>
<packaging>bundle</packaging>
Expand All @@ -43,11 +43,71 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/classes/features.xml</file>
<type>xml</type>
<classifier>features</classifier>
</artifact>
<artifact>
<file>${project.build.directory}/classes/com.axemblr.provisionr.console.cfg</file>
<type>cfg</type>
<classifier>defaults</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>features-maven-plugin</artifactId>
<version>${karaf.version}</version>
<executions>
<execution>
<id>add-features-to-repo</id>
<phase>package</phase>
<goals>
<!-- We are doing so to just to validate that all artifacts are reachable -->
<goal>add-features-to-repo</goal>
</goals>
<configuration>
<descriptors>
<descriptor>file:${project.build.directory}/classes/features.xml</descriptor>
</descriptors>
<features>
<feature>axemblr-provisionr-console</feature>
</features>
<repository>target/features-repo</repository>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@
package com.axemblr.provisionr.client;

import com.axemblr.provisionr.api.Provisionr;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.UUID;

public class ProvisionrClient {

private final List<Provisionr> services;

public ProvisionrClient(List<Provisionr> services) {
this.services = services;
}

public void init() {
System.out.println("**** Starting client. Got " + services.size() + " services.");
for (Provisionr service : services) {
service.startPoolManagementProcess(UUID.randomUUID().toString(), null);
}
this.services = checkNotNull(services, "services is null");
}

public List<Provisionr> getServices() {
Expand Down
22 changes: 18 additions & 4 deletions console/src/main/resources/OSGI-INF/blueprint/context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,26 @@
~ limitations under the License.
-->

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs">

<reference-list id="provisionrServices" interface="com.axemblr.provisionr.api.Provisionr"/>
<reference-list id="provisionrs" interface="com.axemblr.provisionr.api.Provisionr"/>

<bean id="poolClient" class="com.axemblr.provisionr.client.ProvisionrClient" init-method="init">
<argument ref="provisionrServices"/>
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>

<!--<jaxrs:server id="karafFeaturesService" address="/api">-->
<!--<jaxrs:serviceBeans>-->
<!--<ref component-id="karafFeaturesServiceBean"/>-->
<!--</jaxrs:serviceBeans>-->
<!--</jaxrs:server>-->

<bean id="poolClient" class="com.axemblr.provisionr.client.ProvisionrClient">
<argument ref="provisionrs"/>
</bean>

</blueprint>
5 changes: 5 additions & 0 deletions console/src/main/resources/com.axemblr.provisionr.console.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#
# REST API Configurations
#

40 changes: 40 additions & 0 deletions console/src/main/resources/features.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L
~
~ 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.
-->

<features name="axemblr-provisionr-console-features-${project.version}"
xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">

<repository>
mvn:com.axemblr.provisionr/provisionr-core/${project.version}/xml/features
</repository>
<repository>
mvn:org.apache.cxf.karaf/apache-cxf/${cxf.version}/xml/features
</repository>

<feature name="axemblr-provisionr-console" version="${project.version}">
<feature version="${cxf.version}">cxf</feature>
<feature version="${project.version}">axemblr-provisionr-core</feature>

<bundle start="true">mvn:com.axemblr.provisionr/provisionr-console/${project.version}</bundle>

<configfile finalname="/etc/com.axemblr.provisionr.console.cfg">
mvn:com.axemblr.provisionr/provisionr-console/${project.version}/cfg/defaults
</configfile>
</feature>

</features>
18 changes: 6 additions & 12 deletions karaf/tests/pom.xml → karaf/assembly-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
~ limitations under the License.
-->

<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">
<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">
<parent>
<artifactId>provisionr-parent</artifactId>
<groupId>com.axemblr.provisionr</groupId>
Expand All @@ -24,29 +25,22 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<name>Axemblr Provisionr :: Karaf Integration Tests</name>
<artifactId>karaf-tests</artifactId>
<name>Axemblr Provisionr :: Custom Karaf Distribution Tests</name>
<artifactId>provisionr-assembly-tests</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.axemblr.provisionr</groupId>
<artifactId>provisionr-features</artifactId>
<artifactId>provisionr-assembly</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.axemblr.provisionr</groupId>
<artifactId>provisionr-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.karaf</groupId>
<artifactId>jclouds-karaf</artifactId>
<version>${jclouds.karaf.version}</version>
<type>xml</type>
<classifier>features</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,35 @@
package com.axemblr.provisionr.karaf;

import com.axemblr.provisionr.api.Provisionr;
import static com.axemblr.provisionr.test.KarafTests.projectVersionAsSystemProperty;
import static com.axemblr.provisionr.test.KarafTests.useDefaultKarafAsInProjectWithJunitBundles;
import static com.axemblr.provisionr.test.KarafTests.getKarafVersionAsInProject;
import com.google.common.base.Stopwatch;
import com.google.common.io.CharStreams;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.FeaturesService;
import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.keepRuntimeFolder;
import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.logLevel;
import org.apache.karaf.tooling.exam.options.LogLevelOption;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.maven;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
Expand All @@ -50,13 +55,13 @@
import org.slf4j.LoggerFactory;

/**
* Test Axemblr Provisionr Feature installation in Apache Karaf.
* Run a set of tests on the custom Karaf distribution
*/
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class KarafDistributionTest {
public class CustomKarafDistributionTest {

private static final Logger LOG = LoggerFactory.getLogger(KarafDistributionTest.class);
private static final Logger LOG = LoggerFactory.getLogger(CustomKarafDistributionTest.class);

public static final String ACTIVITI_EXPLORER_URL = "http://localhost:8181/activiti-explorer/";

Expand All @@ -75,17 +80,23 @@ public class KarafDistributionTest {

@Configuration
public Option[] configuration() throws Exception {
MavenArtifactUrlReference distributionUrl = maven().groupId("com.axemblr.provisionr")
.artifactId("provisionr-assembly").versionAsInProject().type("tar.gz");

return new Option[]{
useDefaultKarafAsInProjectWithJunitBundles(),
projectVersionAsSystemProperty()
karafDistributionConfiguration()
.frameworkUrl(distributionUrl)
.karafVersion(getKarafVersionAsInProject())
.name("Axemblr Provisionr")
.unpackDirectory(new File("target/exam")),
keepRuntimeFolder(),
junitBundles(),
logLevel(LogLevelOption.LogLevel.INFO)
};
}

@Test
public void testAllFeaturesStartAsExpected() throws Exception {
features.addRepository(getProvisionrFeaturesUrl());

features.installFeature("axemblr-provisionr-all");
assertFeatureInstalled("axemblr-provisionr-all");

assertAllBundlesAreActive();
Expand Down Expand Up @@ -118,9 +129,8 @@ private void assertActivitiExplorerIsRunningInLessThan(int timeoutInMilliseconds
}
}

private <T> void assertProvisionrServicesAreStartedInLessThan(int timeoutInMilliseconds) throws InterruptedException {
final ServiceTracker<T, T> tracker = new ServiceTracker<T, T>(bundleContext,
Provisionr.class.getCanonicalName(), null);
private void assertProvisionrServicesAreStartedInLessThan(int timeoutInMilliseconds) throws InterruptedException {
final ServiceTracker tracker = new ServiceTracker(bundleContext, Provisionr.class.getCanonicalName(), null);
tracker.open(true);
try {
final Stopwatch stopwatch = new Stopwatch().start();
Expand Down Expand Up @@ -153,14 +163,6 @@ private <T> void assertProvisionrServicesAreStartedInLessThan(int timeoutInMilli
}
}

private URI getProvisionrFeaturesUrl() {
return URI.create(maven("com.axemblr.provisionr", "provisionr-features")
.version(System.getProperty("project.version"))
.classifier("features")
.type("xml")
.getURL());
}

private void assertAllBundlesAreActive() {
for (Bundle bundle : bundleContext.getBundles()) {
// skip fragments, they can't be started
Expand Down
19 changes: 4 additions & 15 deletions karaf/assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,26 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<name>Axemblr Provisionr :: Assembly</name>
<name>Axemblr Provisionr :: Custom Karaf Distribution</name>
<description>Install all the features as a custom Karaf distribution</description>
<artifactId>provisionr-assembly</artifactId>

<dependencies>
<dependency>
<groupId>com.axemblr.provisionr</groupId>
<artifactId>provisionr-branding</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.axemblr.provisionr</groupId>
<artifactId>provisionr-amazon</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.axemblr.provisionr</groupId>
<artifactId>provisionr-cloudstack</artifactId>
<version>${project.version}</version>
<artifactId>provisionr-features</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf</groupId>
<artifactId>apache-karaf</artifactId>
<version>${karaf.version}</version>
<type>tar.gz</type>
</dependency>
<dependency>
<groupId>org.activiti.karaf</groupId>
<artifactId>activiti-karaf-commands</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
3 changes: 2 additions & 1 deletion karaf/assembly/src/main/assembly/unix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<exclude>etc/org.apache.karaf.features.cfg</exclude>
<exclude>etc/custom.properties</exclude>
<exclude>etc/startup.properties</exclude>
<exclude>etc/org.apache.karaf.management.cfg</exclude>
<exclude>etc/jre.properties*</exclude>
<exclude>etc/org.apache.karaf.features.repos.cfg</exclude>
<exclude>readme.txt</exclude>
<exclude>LICENSE</exclude>
<exclude>NOTICE</exclude>
Expand Down
Loading

0 comments on commit 9ae5f0f

Please sign in to comment.