Author: [email protected]
Date: Wed May 30 14:53:35 2012
New Revision: 2415

Log:
Fixed some issues and added demo-core and demo-web distributions

Added:
   
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsUtil.java
Modified:
   trunk/amdatu-ams-populator/pom.xml
   
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsDistribution.java
   
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsFeature.java
   
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsPopulator.java

Modified: trunk/amdatu-ams-populator/pom.xml
==============================================================================
--- trunk/amdatu-ams-populator/pom.xml  (original)
+++ trunk/amdatu-ams-populator/pom.xml  Wed May 30 14:53:35 2012
@@ -28,7 +28,7 @@
   <name>Amdatu Development - AMS populator</name>
 
   <properties>
-    <org.amdatu.ace.version>1.0.0-RC1</org.amdatu.ace.version>
+    <org.amdatu.ace.version>1.0.0-RC3</org.amdatu.ace.version>
   </properties>
 
   <repositories>

Modified: 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsDistribution.java
==============================================================================
--- 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsDistribution.java
      (original)
+++ 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsDistribution.java
      Wed May 30 14:53:35 2012
@@ -1,3 +1,18 @@
+/*
+ * 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.ams.populator;
 
 import org.amdatu.ace.client.AceClientException;
@@ -12,13 +27,17 @@
 
 public class AmsDistribution {
     // Distributions are hard coded for now
-    private static final String[] DISTRIBUTIONS = new String[] {"demo-auth", 
"demo-opensocial", "demo-cassandra"};
+    private static final String[] DISTRIBUTIONS = new String[] { "demo-core", 
"demo-web", "demo-auth",
+        "demo-opensocial", "demo-cassandra" };
     private static final Map<String[], String> F2D = new HashMap<String[], 
String>();
 
     static {
-        F2D.put(new String[] {"core", "web", "auth"}, "demo-auth");
-        F2D.put(new String[] {"core", "web", "auth", "opensocial"}, 
"demo-opensocial");
-        F2D.put(new String[] {"core", "web", "auth-nostorage", 
"opensocial-nostorage", "cassandra"}, "demo-cassandra");
+        F2D.put(new String[] { "core" }, "demo-core");
+        F2D.put(new String[] { "core", "web" }, "demo-web");
+        F2D.put(new String[] { "core", "web", "auth" }, "demo-auth");
+        F2D.put(new String[] { "core", "web", "auth", "opensocial" }, 
"demo-opensocial");
+        F2D.put(new String[] { "core", "web", "auth-nostorage", 
"opensocial-nostorage", "cassandra" },
+            "demo-cassandra");
     }
 
     private AceClientWorkspace m_workspace;
@@ -45,16 +64,18 @@
     }
 
     private void createDistribution() throws AceClientException {
-        // Check if the distribution exists (see AMDATUMGMNT-13)
-        // Feature f = m_workspace.getResource(Distribution.class, name);
-
         // Create the distribution
         for (String distName : DISTRIBUTIONS) {
-            Distribution distribution = new DistributionBuilder()
-                .setName(distName)
-                .setDescription(distName)
-                .build();
-            m_workspace.createResource(distribution);
+            // Check if the distribution exists (see AMDATUMGMNT-13)
+            Distribution distribution =
+                AmsUtil.getResource(m_workspace, Distribution.class, 
Distribution.ATTR_NAME, distName);
+            if (distribution == null) {
+                distribution = new DistributionBuilder()
+                    .setName(distName)
+                    .setDescription(distName)
+                    .build();
+                m_workspace.createResource(distribution);
+            }
         }
     }
 

Modified: 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsFeature.java
==============================================================================
--- 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsFeature.java
   (original)
+++ 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsFeature.java
   Wed May 30 14:53:35 2012
@@ -49,8 +49,8 @@
     private String m_featureName;
     private AceClientWorkspace m_workspace;
 
-    private String m_tenantProcessorPid;
-    private String m_configProcessorPid;
+    private static final String TENANT_PROCESSOR_ID = 
"org.amdatu.tenant.conf.rp";
+    private static final String CONFIG_PROCESSOR_ID = 
"org.osgi.deployment.rp.autoconf";
 
     private List<String> m_symbolicNames = new ArrayList<String>();
     private List<String> m_configNames = new ArrayList<String>();
@@ -83,14 +83,15 @@
 
     private void createFeature() throws AceClientException {
         // Check if the feature exists (see AMDATUMGMNT-13)
-        // Feature f = m_workspace.getResource(Feature.class, name);
-
-        // Create the feature
-        Feature feature = new FeatureBuilder()
-            .setName(m_featureName)
-            .setDescription(m_featureName)
-            .build();
-        m_workspace.createResource(feature);
+        Feature feature = AmsUtil.getResource(m_workspace, Feature.class, 
Feature.ATTR_NAME, m_featureName);
+        if (feature == null) {
+            // Create the feature
+            feature = new FeatureBuilder()
+                .setName(m_featureName)
+                .setDescription(m_featureName)
+                .build();
+            m_workspace.createResource(feature);
+        }
     }
 
     private void uploadArtifacts() {
@@ -144,22 +145,26 @@
         try {
             jar = new JarInputStream(new FileInputStream(file));
             Attributes attr = jar.getManifest().getMainAttributes();
-            ArtifactBuilder builder = new ArtifactBuilder()
-                .isBundle()
-                .setUrl(file.toURI().toString())
-                .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);
+            String symbolicName = attr.getValue(Constants.BUNDLE_SYMBOLICNAME);
+
+            // Only upload the artifact if no artifact with this symbolic name 
already exists
+            if (!AmsUtil.resourceExists(m_workspace, Artifact.class, 
Constants.BUNDLE_SYMBOLICNAME, symbolicName)) {
+                ArtifactBuilder builder = new ArtifactBuilder()
+                    .isBundle()
+                    .setUrl(file.toURI().toString())
+                    .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);
+                }
+                
m_symbolicNames.add(attr.getValue(Constants.BUNDLE_SYMBOLICNAME));
+                Artifact artifact = builder.build();
+                m_workspace.createResource(artifact);
             }
-            m_symbolicNames.add(attr.getValue(Constants.BUNDLE_SYMBOLICNAME));
-            Artifact artifact = builder.build();
-            m_workspace.createResource(artifact);
         }
         finally {
             if (jar != null) {
@@ -168,52 +173,46 @@
         }
     }
 
-    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(File file) throws IOException, 
AceClientException {
         String fileName = 
file.getName().substring(file.getName().lastIndexOf('/') + 1);
         String name = "config " + fileName.substring(0, 
Math.min(fileName.lastIndexOf('.'), fileName.length()));
-        ArtifactBuilder builder =
-            new ArtifactBuilder()
-                .isConfig()
-                .setUrl(file.toURI().toString())
-                .setConfigFileName(file.getName())
-                .setName(name)
-                .setProcessorPid(m_configProcessorPid);
-        m_configNames.add(file.getName());
-        Artifact artifact = builder.build();
-        m_workspace.createResource(artifact);
+        String configFileName = file.getName();
+
+        // Only upload the config if no such config exists yet
+        if (!AmsUtil.resourceExists(m_workspace, Artifact.class, 
Artifact.ATTR_CONFIG_FILENAME, configFileName)) {
+            ArtifactBuilder builder =
+                new ArtifactBuilder()
+                    .isConfig()
+                    .setUrl(file.toURI().toString())
+                    .setConfigFileName(configFileName)
+                    .setName(name)
+                    .setProcessorPid(CONFIG_PROCESSOR_ID);
+            m_configNames.add(file.getName());
+            Artifact artifact = builder.build();
+            m_workspace.createResource(artifact);
+        }
     }
 
     private void installTenant(File file) throws IOException, 
AceClientException {
         String fileName = 
file.getName().substring(file.getName().lastIndexOf('/') + 1);
+        String configFileName = file.getName();
         String name = "tenant " + fileName.substring(0, 
Math.min(fileName.lastIndexOf('.'), fileName.length()));
-        ArtifactBuilder builder =
-            new ArtifactBuilder()
-                .isConfig()
-                .setUrl(file.toURI().toString())
-                .setConfigFileName(file.getName())
-                .setName(name)
-                .setProcessorPid(m_configProcessorPid);
-        builder.setProcessorPid(m_tenantProcessorPid);
-        builder.setAttribute("mimetype", "application/vnd.amdatu.tenantconf");
-        builder.setAttribute(TENANT_PID_KEY, getTenantPid(file));
-        m_configNames.add(file.getName());
-        Artifact artifact = builder.build();
-        m_workspace.createResource(artifact);
+
+        // Only upload the config if no such config exists yet
+        if (!AmsUtil.resourceExists(m_workspace, Artifact.class, 
Artifact.ATTR_CONFIG_FILENAME, configFileName)) {
+            ArtifactBuilder builder =
+                new ArtifactBuilder()
+                    .isConfig()
+                    .setUrl(file.toURI().toString())
+                    .setConfigFileName(configFileName)
+                    .setName(name)
+                    .setProcessorPid(TENANT_PROCESSOR_ID);
+            builder.setAttribute("mimetype", 
"application/vnd.amdatu.tenantconf");
+            builder.setAttribute(TENANT_PID_KEY, getTenantPid(file));
+            m_configNames.add(file.getName());
+            Artifact artifact = builder.build();
+            m_workspace.createResource(artifact);
+        }
     }
 
     private String getTenantPid(File file) throws IOException {

Modified: 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsPopulator.java
==============================================================================
--- 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsPopulator.java
 (original)
+++ 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsPopulator.java
 Wed May 30 14:53:35 2012
@@ -13,21 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * 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.ams.populator;
 
 import org.amdatu.ace.client.AceClient;

Added: 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsUtil.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-ams-populator/src/main/java/org/amdatu/ams/populator/AmsUtil.java  
    Wed May 30 14:53:35 2012
@@ -0,0 +1,43 @@
+/*
+ * 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.ams.populator;
+
+import org.amdatu.ace.client.AceClientException;
+import org.amdatu.ace.client.AceClientWorkspace;
+import org.amdatu.ace.client.model.AbstractResource;
+
+public final class AmsUtil {
+
+    private AmsUtil() {
+    }
+
+    public static <T extends AbstractResource> boolean 
resourceExists(AceClientWorkspace workspace, Class<T> clazz,
+        String key,
+        String value) throws AceClientException {
+        return getResource(workspace, clazz, key, value) != null;
+    }
+
+    public static <T extends AbstractResource> T 
getResource(AceClientWorkspace workspace, Class<T> clazz, String key,
+        String value) throws AceClientException {
+        T[] resources = workspace.getResources(clazz);
+        for (T resource : resources) {
+            if ((value == null && resource.getAttribute(key) == null) || 
value.equals(resource.getAttribute(key))) {
+                return resource;
+            }
+        }
+        return null;
+    }
+}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to