Author: [email protected]
Date: Wed May 23 11:34:10 2012
New Revision: 2384

Log:
Added assembly for AMS population

Added:
   trunk/amdatu-release-demo/src/main/assembly/ams-components.xml
   trunk/amdatu-release-demo/src/main/assembly/ams-populator.xml
   trunk/amdatu-release-demo/src/main/java/
   trunk/amdatu-release-demo/src/main/java/org/
   trunk/amdatu-release-demo/src/main/java/org/amdatu/
   trunk/amdatu-release-demo/src/main/java/org/amdatu/dev/
   trunk/amdatu-release-demo/src/main/java/org/amdatu/dev/distributions/
   
trunk/amdatu-release-demo/src/main/java/org/amdatu/dev/distributions/DistributionInstaller.java
   trunk/amdatu-release-demo/src/main/resources/bin/populate.bat
   trunk/amdatu-release-demo/src/main/resources/config/core/
   
trunk/amdatu-release-demo/src/main/resources/config/core/amdatu-core-config.xml
   
trunk/amdatu-release-demo/src/main/resources/config/core/tenant-PLATFORM.tenant
   
trunk/amdatu-release-demo/src/main/resources/config/core/tenant-tenant1.tenant
   trunk/amdatu-release-demo/src/main/resources/config/web/
   trunk/amdatu-release-demo/src/main/resources/config/web/amdatu-web-config.xml
   
trunk/amdatu-release-demo/src/main/resources/config/web/org.amdatu.web.rest.wink.xml
Modified:
   trunk/amdatu-release-demo/pom.xml
   trunk/amdatu-release-demo/src/main/assembly/auth-components.xml
   trunk/amdatu-release-demo/src/main/assembly/cassandra-components.xml
   trunk/amdatu-release-demo/src/main/assembly/opensocial-components.xml
   trunk/amdatu-release-demo/src/main/resources/config/amdatu-core-config.xml
   trunk/amdatu-release-demo/src/main/resources/config/amdatu-web-config.xml
   
trunk/amdatu-release-demo/src/main/resources/config/org.amdatu.web.rest.wink.xml
   trunk/amdatu-release-demo/src/main/resources/config/tenant-PLATFORM.tenant
   trunk/amdatu-release-demo/src/main/resources/config/tenant-tenant1.tenant

Modified: trunk/amdatu-release-demo/pom.xml
==============================================================================
--- trunk/amdatu-release-demo/pom.xml   (original)
+++ trunk/amdatu-release-demo/pom.xml   Wed May 23 11:34:10 2012
@@ -24,7 +24,7 @@
     <relativePath>../amdatu-parent/pom.xml</relativePath>
   </parent>
   <artifactId>org.amdatu.release.demo</artifactId>
-  <version>1.0.0-SNAPSHOT</version>
+  <version>0.3.0-SNAPSHOT</version>
   <packaging>pom</packaging>
   <name>Amdatu - Demo release</name>
 
@@ -36,6 +36,7 @@
     <amdatu.tenant.id>tenant1</amdatu.tenant.id>
     <amdatu.tenant.name>Tenant 1</amdatu.tenant.name>
 
+    <org.amdatu.populator.version>0.3.0-SNAPSHOT</org.amdatu.populator.version>
     <org.amdatu.auth.version>0.3.0-SNAPSHOT</org.amdatu.auth.version>
     <org.amdatu.cassandra.version>0.3.0-SNAPSHOT</org.amdatu.cassandra.version>
     
<org.amdatu.opensocial.version>0.3.0-SNAPSHOT</org.amdatu.opensocial.version>
@@ -562,6 +563,13 @@
       <version>${org.amdatu.cassandra.version}</version>
       <scope>compile</scope>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu</groupId>
+      <artifactId>org.amdatu.ams.populator</artifactId>
+      <version>${org.amdatu.populator.version}</version>
+      <scope>compile</scope>
+    </dependency>
+
   </dependencies>
   <build>
     <defaultGoal>package</defaultGoal>
@@ -577,6 +585,20 @@
         </plugin>
       </plugins>
     </pluginManagement>
+
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            
<Main-Class>org.amdatu.dev.distributions.DistributionInstaller</Main-Class>
+            <Embed-Dependency>*;scope=compile;inline=true</Embed-Dependency>
+            <Embed-Transitive>true</Embed-Transitive>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
   </build>
   <profiles>
     <!--
@@ -639,8 +661,9 @@
                   <appendAssemblyId>true</appendAssemblyId>
                   <descriptors>
                     <descriptor>src/main/assembly/auth.xml</descriptor>
-                    <descriptor>src/main/assembly/opensocial.xml</descriptor>
-                    <descriptor>src/main/assembly/cassandra.xml</descriptor>
+                    
<!--<descriptor>src/main/assembly/opensocial.xml</descriptor>
+                    <descriptor>src/main/assembly/cassandra.xml</descriptor>-->
+                    
<descriptor>src/main/assembly/ams-populator.xml</descriptor>
                   </descriptors>
                 </configuration>
               </execution>

Added: trunk/amdatu-release-demo/src/main/assembly/ams-components.xml
==============================================================================
--- (empty file)
+++ trunk/amdatu-release-demo/src/main/assembly/ams-components.xml      Wed May 
23 11:34:10 2012
@@ -0,0 +1,255 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<component 
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/component/1.1.2"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/component/1.1.2
 http://maven.apache.org/xsd/component-1.1.2.xsd";>
+  <dependencySets>
+    <!-- AMS populator -->
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <outputDirectory></outputDirectory>
+      <includes>
+        <include>org.amdatu:org.amdatu.ams.populator</include>
+      </includes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <directoryMode>0755</directoryMode>
+      <fileMode>0644</fileMode>
+    </dependencySet>
+
+    <!-- Core feature -->
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <outputDirectory>features/core</outputDirectory>
+      <includes>
+        <include>org.osgi:org.osgi.compendium</include>
+        <include>org.apache.felix:org.apache.felix.dependencymanager</include>
+        
<include>org.apache.felix:org.apache.felix.dependencymanager.shell</include>
+        <include>org.apache.felix:org.apache.felix.metatype</include>
+        <include>org.apache.felix:org.apache.felix.log</include>
+        <include>org.apache.felix:org.apache.felix.shell</include>
+        <include>org.apache.felix:org.apache.felix.shell.tui</include>
+        <include>org.apache.ace:org.apache.ace.managementagent</include>
+        <include>org.amdatu.tenant:org.amdatu.tenant.api</include>
+        <include>org.amdatu.tenant:org.amdatu.tenant.adapter</include>
+        <include>org.amdatu.tenant:org.amdatu.tenant.conf.rp</include>
+        <include>org.amdatu.tenant:org.amdatu.tenant.factory</include>
+        
<include>org.amdatu.fileinstall:org.amdatu.fileinstall.autoconf</include>
+        
<include>org.amdatu.fileinstall:org.amdatu.fileinstall.tenantconf</include>
+        <include>org.amdatu.deployment:org.amdatu.deployment.autoconf</include>
+        
<include>org.amdatu.configadmin:org.amdatu.multitenant.org.apache.felix.configadmin</include>
+        
<include>org.amdatu.eventadmin:org.amdatu.multitenant.org.apache.felix.eventadmin</include>
+        
<include>org.amdatu.preferences:org.amdatu.multitenant.org.apache.felix.prefs</include>
+        
<include>org.amdatu.useradmin:org.amdatu.multitenant.org.ops4j.pax.useradmin.pax-useradmin-service</include>
+        
<include>org.amdatu.useradmin:org.amdatu.multitenant.org.amdatu.useradmin.pax.fsstorage</include>
+        <include>org.amdatu.template:org.amdatu.template.processor</include>
+      </includes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <directoryMode>0755</directoryMode>
+      <fileMode>0644</fileMode>
+    </dependencySet>
+
+    <!-- Web feature -->
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <outputDirectory>features/web</outputDirectory>
+      <includes>
+        <include>org.amdatu.web:org.amdatu.web.dispatcher</include>
+        <include>org.amdatu.web:org.amdatu.web.httpcontext</include>
+        
<include>org.amdatu.httpservice:org.amdatu.multitenant.org.apache.felix.http.jetty</include>
+        <include>org.amdatu.web:org.amdatu.web.jaxrs</include>
+        
<include>org.amdatu.web:org.amdatu.web.tenantresolver.hostname</include>
+        
<include>org.amdatu.web:org.amdatu.web.tenantresolver.parameter</include>
+        <include>org.amdatu.web:org.amdatu.web.wink</include>
+        <include>org.amdatu.web:org.amdatu.web.jsp</include>
+        <include>org.amdatu.web:org.amdatu.web.resource</include>
+      </includes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <directoryMode>0755</directoryMode>
+      <fileMode>0644</fileMode>
+    </dependencySet>
+
+    <!-- Auth feature -->
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <outputDirectory>features/auth</outputDirectory>
+      <includes>
+        <include>org.amdatu.auth:*</include>
+      </includes>
+      <excludes>
+        
<exclude>org.amdatu.auth:org.amdatu.auth.example.oauth.consumer</exclude>
+        
<exclude>org.amdatu.auth:org.amdatu.auth.example.oauth.provider</exclude>
+        <exclude>org.amdatu.auth:org.amdatu.auth.config</exclude>
+      </excludes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <directoryMode>0755</directoryMode>
+      <fileMode>0644</fileMode>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>features/auth</outputDirectory>
+      <includes>
+        <include>org.amdatu.auth:org.amdatu.auth.config</include>
+      </includes>
+      <unpack>true</unpack>
+      <unpackOptions>
+        <excludes>
+          <exclude>META-INF/**</exclude>
+        </excludes>
+        <filtered>true</filtered>
+      </unpackOptions>
+      <outputFileNameMapping></outputFileNameMapping> <!-- MASSEMBLY-533 -->
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+
+    <!-- Auth no storage feature -->
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <outputDirectory>features/auth-nostorage</outputDirectory>
+      <includes>
+        <include>org.amdatu.auth:*</include>
+      </includes>
+      <excludes>
+        
<exclude>org.amdatu.auth:org.amdatu.auth.example.oauth.consumer</exclude>
+        
<exclude>org.amdatu.auth:org.amdatu.auth.example.oauth.provider</exclude>
+        <exclude>org.amdatu.auth:org.amdatu.auth.config</exclude>
+        <exclude>org.amdatu.auth:org.amdatu.auth.oauth.store.*</exclude>
+        <exclude>org.amdatu.auth.tokenstore.mem</exclude>
+      </excludes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <directoryMode>0755</directoryMode>
+      <fileMode>0644</fileMode>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>features/auth-nostorage</outputDirectory>
+      <includes>
+        <include>org.amdatu.auth:org.amdatu.auth.config</include>
+      </includes>
+      <unpack>true</unpack>
+      <unpackOptions>
+        <excludes>
+          <exclude>META-INF/**</exclude>
+        </excludes>
+        <filtered>true</filtered>
+      </unpackOptions>
+      <outputFileNameMapping></outputFileNameMapping> <!-- MASSEMBLY-533 -->
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+
+    <!-- OpenSocial feature -->
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <outputDirectory>features/opensocial</outputDirectory>
+      <includes>
+        <include>org.amdatu.opensocial:*</include>
+      </includes>
+      <excludes>
+        <exclude>org.amdatu.opensocial:org.amdatu.opensocial.config</exclude>
+      </excludes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <directoryMode>0755</directoryMode>
+      <fileMode>0644</fileMode>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>features/opensocial</outputDirectory>
+      <includes>
+        <include>org.amdatu.opensocial:org.amdatu.opensocial.config</include>
+      </includes>
+      <unpack>true</unpack>
+      <unpackOptions>
+        <excludes>
+          <exclude>META-INF/**</exclude>
+        </excludes>
+        <filtered>true</filtered>
+      </unpackOptions>
+      <outputFileNameMapping></outputFileNameMapping> <!-- MASSEMBLY-533 -->
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+
+    <!-- OpenSocial no storage feature -->
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <outputDirectory>features/opensocial-nostorage</outputDirectory>
+      <includes>
+        <include>org.amdatu.opensocial:*</include>
+      </includes>
+      <excludes>
+        <exclude>org.amdatu.opensocial:org.amdatu.opensocial.config</exclude>
+        <exclude>org.amdatu.opensocial:org.amdatu.opensocial.store.*</exclude>
+      </excludes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <directoryMode>0755</directoryMode>
+      <fileMode>0644</fileMode>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>features/opensocial-nostorage</outputDirectory>
+      <includes>
+        <include>org.amdatu.opensocial:org.amdatu.opensocial.config</include>
+      </includes>
+      <unpack>true</unpack>
+      <unpackOptions>
+        <excludes>
+          <exclude>META-INF/**</exclude>
+        </excludes>
+        <filtered>true</filtered>
+      </unpackOptions>
+      <outputFileNameMapping></outputFileNameMapping> <!-- MASSEMBLY-533 -->
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+
+    <!-- Cassandra feature -->
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <outputDirectory>features/cassandra</outputDirectory>
+      <includes>
+        <include>org.amdatu.cassandra:*</include>
+      </includes>
+      <excludes>
+        <exclude>org.amdatu.cassandra:org.amdatu.cassandra.config</exclude>
+      </excludes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <directoryMode>0755</directoryMode>
+      <fileMode>0644</fileMode>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>features/cassandra</outputDirectory>
+      <includes>
+        <include>org.amdatu.cassandra:org.amdatu.cassandra.config</include>
+      </includes>
+      <unpack>true</unpack>
+      <unpackOptions>
+        <excludes>
+          <exclude>META-INF/**</exclude>
+        </excludes>
+        <filtered>true</filtered>
+      </unpackOptions>
+      <outputFileNameMapping></outputFileNameMapping> <!-- MASSEMBLY-533 -->
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+  </dependencySets>
+
+  <fileSets>
+    <fileSet>
+      <directory>src/main/resources/bin</directory>
+      <includes>
+        <include>populate.bat</include>
+      </includes>
+      <outputDirectory></outputDirectory>
+      <filtered>true</filtered>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/config/core</directory>
+      <outputDirectory>features/core</outputDirectory>
+      <filtered>true</filtered>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/config/web</directory>
+      <outputDirectory>features/web</outputDirectory>
+      <filtered>true</filtered>
+    </fileSet>
+  </fileSets>
+</component>
\ No newline at end of file

Added: trunk/amdatu-release-demo/src/main/assembly/ams-populator.xml
==============================================================================
--- (empty file)
+++ trunk/amdatu-release-demo/src/main/assembly/ams-populator.xml       Wed May 
23 11:34:10 2012
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright (c) 2010, 2011 The Amdatu Foundation
+
+  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.verning permissions and limitations
+  under the License.
+-->
+<assembly 
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
 http://maven.apache.org/xsd/assembly-1.1.2.xsd";>
+  <id>ams-${project.version}</id>
+  <formats>
+    <format>dir</format>
+    <format>zip</format>
+  </formats>
+  <includeBaseDirectory>false</includeBaseDirectory>
+  <componentDescriptors>
+    
<componentDescriptor>src/main/assembly/ams-components.xml</componentDescriptor>
+  </componentDescriptors>
+</assembly>
\ No newline at end of file

Modified: trunk/amdatu-release-demo/src/main/assembly/auth-components.xml
==============================================================================
--- trunk/amdatu-release-demo/src/main/assembly/auth-components.xml     
(original)
+++ trunk/amdatu-release-demo/src/main/assembly/auth-components.xml     Wed May 
23 11:34:10 2012
@@ -116,7 +116,12 @@
       <filtered>true</filtered>
     </fileSet>
     <fileSet>
-      <directory>src/main/resources/config</directory>
+      <directory>src/main/resources/config/core</directory>
+      <outputDirectory>multitenantweb</outputDirectory>
+      <filtered>true</filtered>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/config/web</directory>
       <outputDirectory>multitenantweb</outputDirectory>
       <filtered>true</filtered>
     </fileSet>

Modified: trunk/amdatu-release-demo/src/main/assembly/cassandra-components.xml
==============================================================================
--- trunk/amdatu-release-demo/src/main/assembly/cassandra-components.xml        
(original)
+++ trunk/amdatu-release-demo/src/main/assembly/cassandra-components.xml        
Wed May 23 11:34:10 2012
@@ -119,7 +119,12 @@
       <filtered>true</filtered>
     </fileSet>
     <fileSet>
-      <directory>src/main/resources/config</directory>
+      <directory>src/main/resources/config/core</directory>
+      <outputDirectory>multitenantweb</outputDirectory>
+      <filtered>true</filtered>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/config/web</directory>
       <outputDirectory>multitenantweb</outputDirectory>
       <filtered>true</filtered>
     </fileSet>

Modified: trunk/amdatu-release-demo/src/main/assembly/opensocial-components.xml
==============================================================================
--- trunk/amdatu-release-demo/src/main/assembly/opensocial-components.xml       
(original)
+++ trunk/amdatu-release-demo/src/main/assembly/opensocial-components.xml       
Wed May 23 11:34:10 2012
@@ -117,7 +117,12 @@
       <filtered>true</filtered>
     </fileSet>
     <fileSet>
-      <directory>src/main/resources/config</directory>
+      <directory>src/main/resources/config/core</directory>
+      <outputDirectory>multitenantweb</outputDirectory>
+      <filtered>true</filtered>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/config/web</directory>
       <outputDirectory>multitenantweb</outputDirectory>
       <filtered>true</filtered>
     </fileSet>

Added: 
trunk/amdatu-release-demo/src/main/java/org/amdatu/dev/distributions/DistributionInstaller.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-release-demo/src/main/java/org/amdatu/dev/distributions/DistributionInstaller.java
     Wed May 23 11:34:10 2012
@@ -0,0 +1,390 @@
+/*
+ * Copyright (c) 2010-2012 The Amdatu Foundation
+ *
+ * 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 org.amdatu.dev.distributions;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import org.amdatu.ace.client.AceClient;
+import org.amdatu.ace.client.AceClientException;
+import org.amdatu.ace.client.AceClientWorkspace;
+import org.amdatu.ace.client.model.AbstractResource;
+import org.amdatu.ace.client.model.Artifact;
+import org.amdatu.ace.client.model.Artifact2Feature;
+import org.amdatu.ace.client.model.Artifact2FeatureBuilder;
+import org.amdatu.ace.client.model.ArtifactBuilder;
+import org.amdatu.ace.client.model.Distribution;
+import org.amdatu.ace.client.model.DistributionBuilder;
+import org.amdatu.ace.client.model.Feature;
+import org.amdatu.ace.client.model.Feature2Distribution;
+import org.amdatu.ace.client.model.Feature2DistributionBuilder;
+import org.amdatu.ace.client.model.FeatureBuilder;
+import org.osgi.framework.Constants;
+
+// @checkstyle:off
+public class DistributionInstaller {
+// @checkstyle:on
+
+    private static final String DEPLOYMENT_PROVIDES_RESOURCE_PROCESSOR = 
"Deployment-ProvidesResourceProcessor";
+
+    private static final String OBR_END_POINT = "http://localhost:8080/obr";;
+    private static final String PATH = "http://localhost:8080/client/work";;
+    private static final String TENANT_PID_KEY = "org.amdatu.tenant.pid";
+
+    private AceClient m_client;
+    private AceClientWorkspace m_workspace;
+
+    private String m_tenantProcessorPid;
+    private String m_configProcessorPid;
+
+    private final boolean m_uploadToObr = true;
+    private final URL m_obrURL;
+    private final URL[] m_bundles;
+    private final URL[] m_config;
+
+    private static final Map<String, String> FEATURES = new HashMap<String, 
String>();
+    private static final Map<String, String> DEMOS = new HashMap<String, 
String>();
+
+    // By Symbolic-Name
+    private static final String[] BUNDLES_BASIC = {"org.apache.felix.*", 
"osgi.*", "org.amdatu.deployment.autoconf"};
+    private static final String[] BUNDLES_TENANT = {"org.amdatu.tenant.*", 
"org.amdatu.multitenant.*"};
+    private static final String[] BUNDLES_WEB = {"org.amdatu.web.*"};
+    private static final String[] BUNDLES_DEMO_TENANT_GLOBAL = 
{"org.amdatu.kitchensink.demo.tenant.global"};
+    private static final String[] BUNDLES_DEMO_TENANT_LOCAL = 
{"org.amdatu.kitchensink.demo.tenant.local"};
+    private static final String[] BUNDLES_DEMO_TENANT_WEB = 
{"org.amdatu.kitchensink.demo.tenant.web"};
+
+    // By Name
+    private static final String[] CONFIG_BASIC = {"amdatu-core-config.xml"};
+    private static final String[] CONFIG_TENANT = {"tenant-PLATFORM.tenant"};
+    private static final String[] CONFIG_WEB = {"amdatu-web-config.xml"};
+    private static final String[] CONFIG_DEMO_TENANT_GLOBAL = 
{"demo-global.xml"};
+    private static final String[] CONFIG_DEMO_TENANT_LOCAL = {"*.tenant", 
"*-demo-local.xml"};
+    private static final String[] CONFIG_DEMO_TENANT_WEB = {"*.tenant", 
"*-demo-web.xml"};
+
+    // By Name
+    private static final String[] FEATURES_DEMO_TENANT_GLOBAL = {"Basic", 
"Tenant Demo - Global"};
+    private static final String[] FEATURES_DEMO_TENANT_LOCAL = {"Basic", 
"Tenant", "Tenant Demo - Local"};
+    private static final String[] FEATURES_DEMO_TENANT_WEB = {"Basic", 
"Tenant", "Web", "Tenant Demo - Web"};
+
+    static {
+        FEATURES.put("Basic", "Provides the basic functionality");
+        FEATURES.put("Tenant", "Provides the tenant functionality");
+        FEATURES.put("Web", "Provides the web functionality");
+        FEATURES.put("Tenant Demo - Global", "Provides the global tenant demo 
bundles");
+        FEATURES.put("Tenant Demo - Local", "Provides the local tenant demo 
bundles");
+        FEATURES.put("Tenant Demo - Web", "Provides the web tenant demo 
bundles");
+        DEMOS.put("Tenant Demo - Global", "The global tenant demo");
+        DEMOS.put("Tenant Demo - Local", "The local tenant demo");
+        DEMOS.put("Tenant Demo - Web", "The web tenant demo");
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (args.length == 0) {
+            throw new RuntimeException("Please use the provided run script to 
run the installer");
+        }
+        new DistributionInstaller(new File(args[0] + 
"/bundles").getAbsoluteFile(),
+            new File(args[0] + "/config").getAbsoluteFile());
+    }
+
+    public DistributionInstaller(File bundleDir, File configDir) throws 
Exception {
+        m_obrURL = new URL(OBR_END_POINT);
+
+        m_bundles = uploadBundles(bundleDir);
+        m_config = uploadConfig(configDir);
+
+        installDemos();
+    }
+
+    private URL[] uploadBundles(File bundleDir) throws IOException {
+        List<URL> bundles = new ArrayList<URL>();
+        for (File f : bundleDir.listFiles()) {
+            if (!f.getName().endsWith(".jar")) {
+                continue;
+            }
+            bundles.add(m_uploadToObr ? uploadToObr(f) : f.toURI().toURL());
+        }
+        return bundles.toArray(new URL[bundles.size()]);
+    }
+
+    private URL[] uploadConfig(File configDir) throws IOException {
+        List<URL> config = new ArrayList<URL>();
+        for (File f : configDir.listFiles()) {
+            if (!f.getName().endsWith(".tenant") && 
!f.getName().endsWith(".xml")) {
+                continue;
+            }
+            config.add(m_uploadToObr ? uploadToObr(f) : f.toURI().toURL());
+        }
+        return config.toArray(new URL[config.size()]);
+    }
+
+    private URL uploadToObr(File file) throws IOException {
+        URL artifactObrUrl = null;
+        OutputStream out = null;
+        InputStream in = null;
+        try {
+            artifactObrUrl = new URL(m_obrURL.toExternalForm() + "/" + 
file.getName());
+            System.out.println("Uploading: " + artifactObrUrl);
+            URLConnection connection = artifactObrUrl.openConnection();
+            connection.setDoOutput(true);
+            connection.setDoInput(true);
+
+            URL artifactFileUrl = file.toURI().toURL();
+            in = artifactFileUrl.openStream();
+            out = connection.getOutputStream();
+            byte[] buf = new byte[8 * 1024];
+            for (int i = in.read(buf); i != -1; i = in.read(buf)) {
+                out.write(buf, 0, i);
+            }
+            out.flush();
+            out.close();
+
+            HttpURLConnection conn = (HttpURLConnection) connection;
+            int status = conn.getResponseCode();
+            if (status != 200) {
+                if (status == 409) { // Already uploaded
+                    System.out.println("Artifact already uploaded: " + 
artifactObrUrl);
+                    return artifactObrUrl;
+                }
+                throw new IOException("Failed to upload file to the OBR at "
+                    + artifactObrUrl.toExternalForm() + " (responsecode: " + 
status + ").");
+            }
+        }
+        finally {
+            if (in != null) {
+                in.close();
+            }
+            if (out != null) {
+                out.close();
+            }
+        }
+        return artifactObrUrl;
+    }
+
+    private void installDemos() throws Exception {
+        m_client = new AceClient(PATH);
+        m_workspace = m_client.createNewWorkspace();
+
+        installBundles();
+        installConfig();
+
+        createFeatures();
+        createDistributions();
+        createAssociations();
+
+        m_workspace.commit();
+        m_workspace.remove();
+
+        System.out.println("Installation bundles and demos completed!");
+    }
+
+    private void installBundles() throws Exception {
+        for (URL bundle : m_bundles) {
+            JarInputStream jar = new JarInputStream(bundle.openStream());
+            installBundle(bundle, jar.getManifest());
+        }
+    }
+
+    private void installBundle(URL bundle, Manifest manifest) throws Exception 
{
+        System.out.println("Installing " + bundle);
+        Attributes attr = manifest.getMainAttributes();
+        ArtifactBuilder builder = new ArtifactBuilder()
+            .isBundle()
+            .setUrl(bundle.toExternalForm())
+            .setName(attr.getValue(Constants.BUNDLE_NAME))
+            .setDescription(attr.getValue(Constants.BUNDLE_DESCRIPTION))
+            .setBundleName(attr.getValue(Constants.BUNDLE_NAME))
+            
.setBundleSymbolicName(attr.getValue(Constants.BUNDLE_SYMBOLICNAME))
+            .setBundleVersion(attr.getValue(Constants.BUNDLE_VERSION));
+        String conf = attr.getValue(DEPLOYMENT_PROVIDES_RESOURCE_PROCESSOR);
+        if (conf != null) {
+            builder.setAttribute(DEPLOYMENT_PROVIDES_RESOURCE_PROCESSOR, conf);
+            setResourceProcessor(conf);
+        }
+        Artifact a = builder.build();
+        createResource(a, bundle.toString());
+    }
+
+    private void setResourceProcessor(String conf) {
+        if (conf.contains("tenant")) {
+            if (m_tenantProcessorPid != null) {
+                throw new IllegalStateException("Only one resource processor 
per type allowed");
+            }
+            m_tenantProcessorPid = conf;
+        }
+        else {
+            if (m_configProcessorPid != null) {
+                throw new IllegalStateException("Only one resource processor 
per type allowed");
+            }
+            m_configProcessorPid = conf;
+        }
+    }
+
+    private void installConfig() throws Exception {
+        for (URL config : m_config) {
+            installConfig(config);
+        }
+    }
+
+    private void installConfig(URL config) throws Exception {
+        System.out.println("Installing " + config);
+        String url = config.toExternalForm();
+        String fileName = url.substring(url.lastIndexOf('/') + 1);
+        String name = fileName.substring(0, Math.min(url.lastIndexOf('.'), 
fileName.length()));
+        ArtifactBuilder ab =
+            new ArtifactBuilder()
+                .isConfig()
+                .setUrl(url)
+                .setConfigFileName(fileName)
+                .setName(name)
+                .setProcessorPid(m_configProcessorPid);
+        if (name.endsWith(".tenant")) {
+            ab.setProcessorPid(m_tenantProcessorPid);
+            ab.setAttribute("mimetype", "application/vnd.amdatu.tenantconf");
+            ab.setAttribute(TENANT_PID_KEY, getTenantPid(config));
+        }
+        Artifact a = ab.build();
+        createResource(a, config.toString());
+    }
+
+    private String getTenantPid(URL config) {
+        try {
+            BufferedReader br = new BufferedReader(new 
InputStreamReader(config.openStream()));
+            String line;
+            while ((line = br.readLine()) != null) {
+                line = line.replace(" ", "");
+                if (line.startsWith(TENANT_PID_KEY)) {
+                    return line.substring(line.indexOf('=') + 1);
+                }
+            }
+        }
+        catch (Exception e) {
+            System.err.println("Could not retrieve tenant pid for config: " + 
config);
+        }
+        return null;
+    }
+
+    private void createResource(AbstractResource a, String name) {
+        try {
+            m_workspace.createResource(a);
+        }
+        catch (AceClientException ace) {
+            System.err.println("Failed to create resource (" + name + "): " + 
ace.getMessage());
+        }
+    }
+
+    private void createFeatures() throws Exception {
+        for (Entry<String, String> feature : FEATURES.entrySet()) {
+            Feature f = new FeatureBuilder()
+                .setName(feature.getKey())
+                .setDescription(feature.getValue())
+                .build();
+            createResource(f, "Feature " + feature.getKey());
+        }
+    }
+
+    private void createDistributions() throws Exception {
+        for (Entry<String, String> demo : DEMOS.entrySet()) {
+            Distribution d = new DistributionBuilder()
+                .setName(demo.getKey())
+                .setDescription(demo.getValue())
+                .build();
+            createResource(d, "Demo " + demo.getKey());
+        }
+    }
+
+    private void createAssociations() throws Exception {
+        System.out.println("Creating associations");
+        createBundleAssociations();
+        createConfigAssociations();
+        createFeatureAssociations();
+    }
+
+    private void createBundleAssociations() throws Exception {
+        createBundleAssociations(BUNDLES_BASIC, "Basic");
+        createBundleAssociations(BUNDLES_TENANT, "Tenant");
+        createBundleAssociations(BUNDLES_WEB, "Web");
+        createBundleAssociations(BUNDLES_DEMO_TENANT_GLOBAL, "Tenant Demo - 
Global");
+        createBundleAssociations(BUNDLES_DEMO_TENANT_LOCAL, "Tenant Demo - 
Local");
+        createBundleAssociations(BUNDLES_DEMO_TENANT_WEB, "Tenant Demo - Web");
+    }
+
+    private void createBundleAssociations(String[] bundles, String 
rightEndPoint) throws Exception {
+        for (String symName : bundles) {
+            Artifact2Feature a =
+                new Artifact2FeatureBuilder()
+                    .setLeftCardinality("2147483647")
+                    .setLeftEndpoint("(Bundle-SymbolicName=" + symName + ")")
+                    .setRightEndpoint("(Name=" + rightEndPoint + ")")
+                    .build();
+            createResource(a, "Association '" + symName + "'-'" + 
rightEndPoint + "'");
+        }
+    }
+
+    private void createConfigAssociations() throws Exception {
+        createConfigAssociations(CONFIG_BASIC, "Basic");
+        createConfigAssociations(CONFIG_TENANT, "Tenant");
+        createConfigAssociations(CONFIG_WEB, "Web");
+        createConfigAssociations(CONFIG_DEMO_TENANT_GLOBAL, "Tenant Demo - 
Global");
+        createConfigAssociations(CONFIG_DEMO_TENANT_LOCAL, "Tenant Demo - 
Local");
+        createConfigAssociations(CONFIG_DEMO_TENANT_WEB, "Tenant Demo - Web");
+    }
+
+    private void createConfigAssociations(String[] config, String 
rightEndPoint) throws Exception {
+        for (String name : config) {
+            Artifact2Feature a =
+                new Artifact2FeatureBuilder()
+                    .setLeftCardinality("2147483647")
+                    .setLeftEndpoint("(filename=" + name + ")")
+                    .setRightEndpoint("(Name=" + rightEndPoint + ")")
+                    .build();
+            createResource(a, "Association '" + name + "'-'" + rightEndPoint + 
"'");
+        }
+    }
+
+    private void createFeatureAssociations() throws Exception {
+        createFeatureAssociations(FEATURES_DEMO_TENANT_GLOBAL, "Tenant Demo - 
Global");
+        createFeatureAssociations(FEATURES_DEMO_TENANT_LOCAL, "Tenant Demo - 
Local");
+        createFeatureAssociations(FEATURES_DEMO_TENANT_WEB, "Tenant Demo - 
Web");
+    }
+
+    private void createFeatureAssociations(String[] features, String 
rightEndPoint) throws Exception {
+        for (String name : features) {
+            Feature2Distribution a =
+                new Feature2DistributionBuilder()
+                    .setLeftCardinality("2147483647")
+                    .setLeftEndpoint("(Name=" + name + ")")
+                    .setRightEndpoint("(Name=" + rightEndPoint + ")")
+                    .build();
+            createResource(a, "Association '" + name + "'-'" + rightEndPoint + 
"'");
+        }
+    }
+
+}

Added: trunk/amdatu-release-demo/src/main/resources/bin/populate.bat
==============================================================================
--- (empty file)
+++ trunk/amdatu-release-demo/src/main/resources/bin/populate.bat       Wed May 
23 11:34:10 2012
@@ -0,0 +1 @@
+java -jar org.amdatu.ams.populator-${org.amdatu.populator.version}.jar
\ No newline at end of file

Added: 
trunk/amdatu-release-demo/src/main/resources/config/core/amdatu-core-config.xml
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-release-demo/src/main/resources/config/core/amdatu-core-config.xml 
    Wed May 23 11:34:10 2012
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<MetaData xmlns="http://www.osgi.org/xmlns/metatype/v1.1.0"; 
filter="(|(!(org.amdatu.tenant.pid=*))(org.amdatu.tenant.pid=org.amdatu.tenant.PLATFORM))">
+</MetaData>

Added: 
trunk/amdatu-release-demo/src/main/resources/config/core/tenant-PLATFORM.tenant
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-release-demo/src/main/resources/config/core/tenant-PLATFORM.tenant 
    Wed May 23 11:34:10 2012
@@ -0,0 +1,2 @@
+org.amdatu.tenant.pid=org.amdatu.tenant.PLATFORM
+org.amdatu.tenant.name=Platform tenant

Added: 
trunk/amdatu-release-demo/src/main/resources/config/core/tenant-tenant1.tenant
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-release-demo/src/main/resources/config/core/tenant-tenant1.tenant  
    Wed May 23 11:34:10 2012
@@ -0,0 +1,3 @@
+org.amdatu.tenant.pid=${amdatu.tenant.id}
+org.amdatu.tenant.name=${amdatu.tenant.name}
+org.amdatu.web.hostnames=${amdatu.http.hostname}

Added: 
trunk/amdatu-release-demo/src/main/resources/config/web/amdatu-web-config.xml
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-release-demo/src/main/resources/config/web/amdatu-web-config.xml   
    Wed May 23 11:34:10 2012
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<MetaData xmlns="http://www.osgi.org/xmlns/metatype/v1.1.0"; 
filter="(|(!(org.amdatu.tenant.pid=*))(org.amdatu.tenant.pid=org.amdatu.tenant.PLATFORM))">
+  <OCD name="Apache Felix Http Config" id="org.osgi.service.http">
+    <AD id="org.osgi.service.http.port" type="STRING" cardinality="0" />
+  </OCD>
+  <Designate pid="org.apache.felix.http" bundle="*">
+    <Object ocdref="org.osgi.service.http">
+      <Attribute adref="org.osgi.service.http.port">
+        <Value>${amdatu.http.port}</Value>
+      </Attribute>
+    </Object>
+  </Designate>
+</MetaData>

Added: 
trunk/amdatu-release-demo/src/main/resources/config/web/org.amdatu.web.rest.wink.xml
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-release-demo/src/main/resources/config/web/org.amdatu.web.rest.wink.xml
        Wed May 23 11:34:10 2012
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<MetaData xmlns="http://www.osgi.org/xmlns/metatype/v1.0.0"; 
filter="(|(!(org.amdatu.tenant.pid=*))(org.amdatu.tenant.pid=org.amdatu.tenant.PLATFORM))">
+  <OCD name="Amdatu Web REST Wink Configuration" id="org.amdatu.web.rest">
+    <AD id="wink.rest.path" type="STRING" cardinality="0" />
+  </OCD>
+  <Designate pid="org.amdatu.web.rest.wink" bundle="*">
+    <Object ocdref="org.amdatu.web.rest">
+     <Attribute adref="wink.rest.path">
+        <Value>/rest</Value>
+      </Attribute>
+      </Object>
+  </Designate>
+</MetaData>
\ No newline at end of file
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to