Author: [email protected]
Date: Mon Nov 28 09:18:24 2011
New Revision: 1795

Log:


Added:
   sandbox/ivol/amdatu-gadget-container/mail-service/src/main/resources/
   
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/resources/OSGI-INF/
   
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/resources/OSGI-INF/metatype/
   
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/resources/OSGI-INF/metatype/metatype.xml
Modified:
   
sandbox/ivol/amdatu-gadget-container/configfiles_AWS/org.amdatu.gadgetcontainer.mail.service.cfg
   sandbox/ivol/amdatu-gadget-container/mail-service/pom.xml
   
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/service/EMailServiceImpl.java
   sandbox/ivol/amdatu-gadget-container/pom.xml
   
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java
   
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantListenerImpl.java
   
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
   
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/tenant.js
   
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/util.js
   sandbox/ivol/amdatu-gadget-container/tenant-management-service/pom.xml
   
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/osgi/Activator.java
   
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/service/TenantManagementServiceImpl.java

Modified: 
sandbox/ivol/amdatu-gadget-container/configfiles_AWS/org.amdatu.gadgetcontainer.mail.service.cfg
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/configfiles_AWS/org.amdatu.gadgetcontainer.mail.service.cfg
    (original)
+++ 
sandbox/ivol/amdatu-gadget-container/configfiles_AWS/org.amdatu.gadgetcontainer.mail.service.cfg
    Mon Nov 28 09:18:24 2011
@@ -1,5 +1,13 @@
+# The email address on who's behalf the mail is send
[email protected]
+
+# Protocol or API to transport the email with. Valid options are
+# SMTP and AMAZON_AWS. Default is SMTP
+mail.transport = AMAZON_AWS
+
+# SMTP transport settings
 # The SMTP server
-mail.smtp.host=none
+mail.smtp.host=
 
 # The SMTP server port (optional)
 mail.smtp.port=
@@ -13,5 +21,10 @@
 # Password of that user (optional)
 mail.smtp.password=
 
-# The email address on who's behalf the mail is send
[email protected]
\ No newline at end of file
+# Amazon SES transport settings
+# The Amazon AWS Access Key Id
+mail.amazon.aws.access.key.id = AKIAI5Y5GXJXAV3CDB2A
+
+# The Amazon AWS Secret Access Key
+mail.amazon.aws.access.key.secret = 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
+

Modified: sandbox/ivol/amdatu-gadget-container/mail-service/pom.xml
==============================================================================
--- sandbox/ivol/amdatu-gadget-container/mail-service/pom.xml   (original)
+++ sandbox/ivol/amdatu-gadget-container/mail-service/pom.xml   Mon Nov 28 
09:18:24 2011
@@ -29,9 +29,57 @@
 
   <dependencies>
     <dependency>
+      <groupId>com.amazon</groupId>
+      <artifactId>aws-java-sdk</artifactId>
+      <version>1.2.12</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.4</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.1.1</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.1.1</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpcore</artifactId>
+      <version>4.1</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-core-asl</artifactId>
+      <version>1.4.3</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
       <groupId>javax.mail</groupId>
       <artifactId>mail</artifactId>
-      <version>1.4.4</version>
+      <version>1.4.3</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>stax</groupId>
+      <artifactId>stax-api</artifactId>
+      <version>1.0.1</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>stax</groupId>
+      <artifactId>stax</artifactId>
+      <version>1.2.0</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>
@@ -45,22 +93,17 @@
           <instructions>
             
<Bundle-Activator>org.amdatu.gadgetcontainer.email.osgi.Activator</Bundle-Activator>
             <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
-            
<Embed-Dependency>*;scope=compile;artifactId=json|mail|org.amdatu.libraries.utilities</Embed-Dependency>
+            
<Embed-Dependency>*;scope=compile;artifactId=json|mail|commons-codec|org.amdatu.libraries.utilities|aws-java-sdk|commons-logging|httpclient|httpcore|jackson-core-asl</Embed-Dependency>
             <Embed-Transitive>false</Embed-Transitive>
             <Export-Package>org.amdatu.gadgetcontainer.email</Export-Package>
-            <Import-Package>*;resolution:=optional</Import-Package>
-
-              <!--
+            <Import-Package>
+              !org.apache.avalon.framework.logger,
+              !org.apache.log,
+              !org.apache.log4j,
+              !jcifs.ntlmssp,
               !sun.security.util,
-              !javax.microedition.io,
-              !org.apache.coyote.*,
-              !org.apache.tomcat.*,
-              !org.apache.tools.ant.*,
-              !org.apache.xalan.*,
-              !org.apache.xml.utils,
-              !org.apache.xpath.*,
               *
-              -->
+            </Import-Package>
           </instructions>
         </configuration>
       </plugin>

Modified: 
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/service/EMailServiceImpl.java
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/service/EMailServiceImpl.java
      (original)
+++ 
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/java/org/amdatu/gadgetcontainer/email/service/EMailServiceImpl.java
      Mon Nov 28 09:18:24 2011
@@ -24,6 +24,7 @@
 import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.mail.Transport;
+import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 
@@ -32,47 +33,90 @@
 import org.osgi.service.cm.ManagedService;
 import org.osgi.service.log.LogService;
 
+import com.amazonaws.services.simpleemail.AWSJavaMailTransport;
+
 public class EMailServiceImpl implements EMailService, ManagedService {
     // Regular expression that a valid email address must match
     private final static Pattern VALID_EMAIL_ADDRESS = 
Pattern.compile(".+@.+\\.[a-z]+");
-    
-    // Java mail Properties
+
+    // Generic mail properties
+    private final static String TRANSPORT = "mail.transport";
+    private final static String TRANSPORT_AWS = "AMAZON_AWS";
+    private final static String FROM = "mail.from.address";
+
+    // Mail transport properties
+    // SMTP
     private final static String HOST = "mail.smtp.host";
     private final static String PORT = "mail.smtp.port";
     private final static String AUTH = "mail.smtp.auth";
     private final static String USERNAME = "mail.smtp.username";
     private final static String PASSWORD = "mail.smtp.password";
-    private final static String FROM = "from.address";
-    
+
+    // Amazon AWS
+    private final static String AWS_ACCESS_KEY = 
"mail.amazon.aws.access.key.id";
+    private final static String AWS_ACCESS_SECRET = 
"mail.amazon.aws.access.key.secret";
+
     // Injected service dependencies
     private volatile LogService m_logService;
 
     // Configuration settings, managed by Config Admin
-    private Properties m_properties;
-    private String m_username;
-    private String m_password;
-
-    private String m_fromAddress = "[email protected]";
-
+    private Properties m_javaMailProperties;
+    private boolean m_aws = false;
+    private String m_fromAddress;
+    private String m_smtpUsername;
+    private String m_smtpPassword;
+    private String m_awsAccessKey;
+    private String m_awsAccessSecret;
+    
     @SuppressWarnings("rawtypes")
     public void updated(Dictionary properties) throws ConfigurationException {
         if (properties != null) {
-            m_properties = new Properties();
-            m_properties.setProperty(HOST, properties.get(HOST).toString());
-            if (!properties.get(PORT).toString().isEmpty()) {
-                m_properties.setProperty(PORT, 
properties.get(PORT).toString());
-            } else {
-                m_properties.remove(PORT);
-            }
-            m_properties.setProperty(AUTH, properties.get(AUTH).toString());
-          
-            m_username = properties.get(USERNAME).toString();
-            m_password = properties.get(PASSWORD).toString();
-            
-            m_fromAddress = properties.get(FROM).toString();
+            if (properties.get(TRANSPORT) != null)
+                if 
(TRANSPORT_AWS.equalsIgnoreCase(properties.get(TRANSPORT).toString())) {
+                    initAWS(properties);
+                }
+                else {
+                    initSMTP(properties);
+                }
         }
     }
 
+    @SuppressWarnings("rawtypes")
+    private void initSMTP(Dictionary properties) {
+        m_aws = false;
+        m_javaMailProperties = new Properties();
+        m_javaMailProperties.setProperty(HOST, 
properties.get(HOST).toString());
+        if (!properties.get(PORT).toString().isEmpty()) {
+            m_javaMailProperties.setProperty(PORT, 
properties.get(PORT).toString());
+        }
+        else {
+            m_javaMailProperties.remove(PORT);
+        }
+        m_javaMailProperties.setProperty(AUTH, 
properties.get(AUTH).toString());
+
+        m_smtpUsername = properties.get(USERNAME).toString();
+        m_smtpPassword = properties.get(PASSWORD).toString();
+
+        m_fromAddress = properties.get(FROM).toString();
+    }
+
+    @SuppressWarnings("rawtypes")
+    private void initAWS(Dictionary properties) {
+        m_aws = true;
+
+        m_awsAccessKey = properties.get(AWS_ACCESS_KEY) != null ? 
properties.get(AWS_ACCESS_KEY).toString() : "";
+        m_awsAccessSecret =
+            properties.get(AWS_ACCESS_SECRET) != null ? 
properties.get(AWS_ACCESS_SECRET).toString() : "";
+
+        m_javaMailProperties = new Properties();
+
+        m_javaMailProperties.setProperty("mail.transport.protocol", "aws");
+        m_javaMailProperties.setProperty("mail.aws.user", m_awsAccessKey);
+        m_javaMailProperties.setProperty("mail.aws.password", 
m_awsAccessSecret);
+
+        m_fromAddress = properties.get(FROM).toString();
+    }
+
     public boolean validateEmailAddress(String email) {
         if (email == null || email.isEmpty()) {
             return true;
@@ -82,20 +126,35 @@
     }
 
     public void send(String[] to, String subject, String HtmlMessage) {
+        m_logService.log(LogService.LOG_INFO, "Preparing to send email to '" + 
to + "'");
         Transport transport = null;
+
         try {
-            Session mailSession = Session.getDefaultInstance(m_properties);
-            transport = mailSession.getTransport("smtp");
+            Session mailSession = Session.getInstance(m_javaMailProperties);
             MimeMessage message = prepareMessage(mailSession, "ISO-8859-2", 
m_fromAddress, subject, HtmlMessage, to);
+
+            if (m_aws) {
+                transport = new AWSJavaMailTransport(mailSession, null);
+            }
+            else {
+                transport = mailSession.getTransport("smtp");
+            }
+
             transport.connect();
-            Transport.send(message);
+            transport.sendMessage(message, null);
+        }
+        catch (AddressException e) {
+            m_logService.log(LogService.LOG_ERROR, "Failed to send mail to " + 
to, e);
         }
         catch (MessagingException e) {
             m_logService.log(LogService.LOG_ERROR, "Failed to send mail to " + 
to, e);
         }
         finally {
             try {
-                transport.close();
+                if (transport != null) {
+                    transport.close();
+                    m_logService.log(LogService.LOG_INFO, "Email send 
successfully");
+                }
             }
             catch (MessagingException e) {
                 m_logService.log(LogService.LOG_ERROR, "Failed to send mail to 
" + to, e);
@@ -106,7 +165,7 @@
     private MimeMessage prepareMessage(Session mailSession, String charset,
         String from, String subject,
         String HtmlMessage, String[] recipient) {
-        // Multipurpose Internet Mail Extensions
+        // Multi purpose Internet Mail Extensions
         MimeMessage message = null;
         try {
             message = new MimeMessage(mailSession);

Added: 
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/resources/OSGI-INF/metatype/metatype.xml
==============================================================================
--- (empty file)
+++ 
sandbox/ivol/amdatu-gadget-container/mail-service/src/main/resources/OSGI-INF/metatype/metatype.xml
 Mon Nov 28 09:18:24 2011
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0";>
+    <OCD id="org.amdatu.gadgetcontainer.mail.service" name="Amdatu email 
service">
+      <AD id="mail.from.address" name="mail.from.address" type="String" 
description="The email address on who's behalf the mail is send." />
+      <AD id="mail.transport" name="mail.transport" type="String" 
description="Protocol or API to transport the email with. Valid options are 
SMTP and AMAZON_AWS. Default is SMTP" />
+
+      <AD id="mail.smtp.host" name="mail.smtp.host" type="String" 
description="The SMTP server." />
+      <AD id="mail.smtp.port" name="mail.smtp.port" type="String" 
description="The SMTP server port (optional)." />
+      <AD id="mail.smtp.auth" name="mail.smtp.auth" type="String" 
description="Authorization mechanism of the SMTP server (optional)." />
+      <AD id="mail.smtp.username" name="mail.smtp.username" type="String" 
description="Username required to send emails (optional)." />
+      <AD id="mail.smtp.password" name="mail.smtp.password" type="String" 
description="Password of that user (optional)." />
+
+      <AD id="mail.amazon.aws.access.key.id" 
name="mail.amazon.aws.access.key.id" type="String" description="The Amazon AWS 
Access Key Id." />
+      <AD id="mail.amazon.aws.access.key.secret" 
name="mail.amazon.aws.access.key.secret" type="String" description="The Amazon 
AWS Secret Access Key." />
+    </OCD>
+    <Designate pid="org.amdatu.gadgetcontainer.mail.service">
+      <Object ocdref="org.amdatu.gadgetcontainer.mail.service" />
+    </Designate>
+</metatype:MetaData>
\ No newline at end of file

Modified: sandbox/ivol/amdatu-gadget-container/pom.xml
==============================================================================
--- sandbox/ivol/amdatu-gadget-container/pom.xml        (original)
+++ sandbox/ivol/amdatu-gadget-container/pom.xml        Mon Nov 28 09:18:24 2011
@@ -40,8 +40,8 @@
     <org.amdatu.lib.version>0.2.1</org.amdatu.lib.version>
     <amdatu.libraries.version>0.2.1</amdatu.libraries.version>
 
-    <org.amdatu.cassandra.version>0.2.1-RC3</org.amdatu.cassandra.version>
-    <org.amdatu.auth.version>0.2.1-RC1</org.amdatu.auth.version>
+    <org.amdatu.cassandra.version>0.2.1</org.amdatu.cassandra.version>
+    <org.amdatu.auth.version>0.2.1</org.amdatu.auth.version>
     <org.amdatu.opensocial.version>0.2.0</org.amdatu.opensocial.version>
 
     <org.apache.felix.main.version>3.0.2</org.apache.felix.main.version>

Modified: 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java
 (original)
+++ 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/osgi/Activator.java
 Mon Nov 28 09:18:24 2011
@@ -102,6 +102,8 @@
                 .setInterface(new String[] { TenantListener.class.getName() }, 
null)
                 .setImplementation(TenantListenerImpl.class)
                 
.add(createServiceDependency().setService(EMailService.class).setRequired(true))
+                
.add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
+                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
                 .add(
                     
createServiceDependency().setService(UserAdmin.class).setCallbacks("userAdminAdded",
                         "userAdminRemoved")));

Modified: 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantListenerImpl.java
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantListenerImpl.java
     (original)
+++ 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantListenerImpl.java
     Mon Nov 28 09:18:24 2011
@@ -15,9 +15,11 @@
  */
 package org.amdatu.opensocial.tenant.gadget.service;
 
+import static 
org.amdatu.auth.login.service.LoginService.CHANGE_PASSWORD_UPON_FIRST_LOGIN;
 import static 
org.amdatu.auth.login.service.LoginService.PASSWORD_CREDENTIAL_KEY;
 import static org.amdatu.auth.login.service.LoginService.TENANT_CREDENTIAL_KEY;
-import static 
org.amdatu.auth.login.service.LoginService.CHANGE_PASSWORD_UPON_FIRST_LOGIN;
+
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -26,6 +28,9 @@
 import org.amdatu.opensocial.tenant.gadget.TenantListener;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogService;
 import org.osgi.service.useradmin.Group;
 import org.osgi.service.useradmin.Role;
 import org.osgi.service.useradmin.User;
@@ -36,8 +41,9 @@
  * immediately available but it may take some time. In our case we need to do 
some stuff
  * (like creating admin account) on the new tenant after it has come 
available. This stuff
  * is handled by this class.
+ * 
  * @author ivol
- *
+ * 
  */
 public class TenantListenerImpl implements TenantListener {
     // End of line separator
@@ -45,6 +51,8 @@
 
     // Injected service dependencies
     private volatile EMailService m_mailService;
+    private volatile ConfigurationAdmin m_configAdmin;
+    private volatile LogService m_logService;
 
     // Tenants in the queue to handle
     private List<TenantQueueItem> m_tenantQueue = new 
ArrayList<TenantQueueItem>();
@@ -59,19 +67,24 @@
     }
 
     /**
-     * Note that instead of listening to new tenant coming available we listen 
to UserAdmin 
+     * Note that instead of listening to new tenant coming available we listen 
to UserAdmin
      * (which is tenant aware). We need UserAdmin to create the new admin 
account for, availability
      * of the Tenant service is not enough.
+     * 
      * @param userAdmin
      */
     @SuppressWarnings("unchecked")
     public void userAdminAdded(ServiceReference serviceReference, Object 
userAdminObj) {
+        m_logService.log(LogService.LOG_INFO, "New UserAdmin service has come 
available");
+        
         // Verify that the tenant associated with this UserAdmin service is in 
our 'to be handled' queue
         Object tenantId = 
serviceReference.getProperty(Tenant.TENANT_ID_SERVICEPROPERTY);
         if (tenantId != null) {
             for (TenantQueueItem tenant : m_tenantQueue) {
                 if (tenant.getId().equals(tenantId.toString())) {
-                    // This tenant is in our queue. We now create a new 
account for it 
+                    m_logService.log(LogService.LOG_INFO, "New UserAdmin 
service is contained by tenant queue, preparing new user");
+                    
+                    // This tenant is in our queue. We now create a new 
account for it
                     // in the UserAdmin of this tenant
                     if (userAdminObj instanceof UserAdmin) {
                         UserAdmin userAdmin = (UserAdmin) userAdminObj;
@@ -80,23 +93,25 @@
                         String password = generatePassword();
                         User adminUser = (User) 
userAdmin.createRole(DEFAULT_USERNAME, Role.USER);
                         if (adminUser == null) {
-                            // This should never happen, an admin user exists 
already for a newly created tenant.
-                            // But if this happens then we send an email about 
the new tenant and the notice
-                            // that an admin account is already available for 
it
-                            sendMail(tenant);
-                        } else {
-                            
adminUser.getCredentials().put(PASSWORD_CREDENTIAL_KEY, password);
-                            
adminUser.getCredentials().put(TENANT_CREDENTIAL_KEY, tenant.getId());
-                            
adminUser.getProperties().put(CHANGE_PASSWORD_UPON_FIRST_LOGIN, "true");
-    
-                            // Add the user to a new Administrators group
-                            Group adminGroup = (Group) 
userAdmin.createRole(DEFAULT_ADMIN_GROUP, Role.GROUP);
-                            adminGroup.addMember(adminUser);
-                            
-                            // Now send an email to the specified email 
address with the username and generated password
-                            sendMail(tenant, password);
+                            // This can happen if this tenant was deleted 
before, but the Cassandra
+                            // keyspace was not dropped. So we reset the 
password and send the mail
+                            adminUser = (User) 
userAdmin.getRole(DEFAULT_USERNAME);
+                            m_logService.log(LogService.LOG_INFO, "Updating 
password credential of existing user");
                         }
-                        
+                        
adminUser.getCredentials().put(PASSWORD_CREDENTIAL_KEY, password);
+                        adminUser.getCredentials().put(TENANT_CREDENTIAL_KEY, 
tenant.getId());
+                        
adminUser.getProperties().put(CHANGE_PASSWORD_UPON_FIRST_LOGIN, "true");
+
+                        // Add the user to a new Administrators group
+                        Group adminGroup = (Group) 
userAdmin.createRole(DEFAULT_ADMIN_GROUP, Role.GROUP);
+                        if (adminGroup == null) {
+                            adminGroup = (Group) 
userAdmin.getRole(DEFAULT_ADMIN_GROUP);
+                        }
+                        adminGroup.addMember(adminUser);
+
+                        // Now send an email to the specified email address 
with the username and generated password
+                        sendMail(tenant, password);
+                        m_logService.log(LogService.LOG_INFO, "Email send to 
'" + tenant.getEmail() + "'");
                     }
                 }
             }
@@ -110,7 +125,7 @@
     private String generatePassword() {
         return DigestUtils.md5Hex(new Long(System.nanoTime()).toString());
     }
-    
+
     private void sendMail(TenantQueueItem tenant) {
         String subject = "Amdatu tenant created";
         String content = "A new tenant has been created for you with the 
following properties:" + EOL;
@@ -121,7 +136,7 @@
         content += "The dashboard to this new application can be reached on 
this URL: " + EOL;
         content += "http://"; + tenant.getHost() + 
":2204/dashboard/jsp/dashboard.jsp";
 
-        m_mailService.send(new String[]{tenant.getEmail()}, subject, content);
+        m_mailService.send(new String[] { tenant.getEmail() }, subject, 
content);
     }
 
     private void sendMail(TenantQueueItem tenant, String password) {
@@ -134,10 +149,26 @@
         content += "  Username: " + DEFAULT_USERNAME + EOL;
         content += "  Password: " + password + EOL + EOL;
         content += "The dashboard to this new application can be reached on 
this URL: " + EOL;
-        content += "http://"; + tenant.getHost() + 
":2204/dashboard/jsp/dashboard.jsp" + EOL + EOL;
+        content += "http://"; + tenant.getHost();
+        if (!"80".equals(getPortNr())) {
+            content += ":" + getPortNr();
+        }
+        content += "/dashboard/jsp/dashboard.jsp" + EOL + EOL;
         content += "You will be asked to change your password the first time 
you login.";
 
-        m_mailService.send(new String[]{tenant.getEmail()}, subject, content);
+        m_mailService.send(new String[] { tenant.getEmail() }, subject, 
content);
+    }
+
+    private String getPortNr() {
+        try {
+            Configuration config = 
m_configAdmin.getConfiguration("org.apache.felix.http", null);
+            return 
config.getProperties().get("org.osgi.service.http.port").toString();
+        }
+        catch (IOException e) {
+            m_logService.log(LogService.LOG_ERROR, "Could not retrieve portnr 
from Felix HTTP service configuration. " +
+                "Using port 80 instead.", e);
+        }
+        return "80";
     }
 }
 

Modified: 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
  (original)
+++ 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
  Mon Nov 28 09:18:24 2011
@@ -80,7 +80,7 @@
     private volatile UserAdmin m_userAdmin;
     private volatile TokenProvider m_tokenProvider;
     private volatile DependencyManager m_dependencyManager;
-
+    
     /**
      * The init() method is invoked by the Felix dependency manager.
      * 
@@ -236,7 +236,7 @@
         if (isAuthorized(request)) {
         TenantBean tenant = null;
         try {
-            if (m_tenantDAO.deleteTenant(id)) {
+            if (m_tenantDAO.deleteTenant(id)) {               
                 return Response.ok(tenant, 
MediaType.APPLICATION_JSON_TYPE).cacheControl(NO_CACHE_CONTROL)
                     .build();
             }

Modified: 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/tenant.js
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/tenant.js
        (original)
+++ 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/tenant.js
        Mon Nov 28 09:18:24 2011
@@ -175,5 +175,6 @@
   show('tenant_details');
   show('tenant_email_row');
   show('tenant_save');
+  show('cancel');
   gadgets.window.adjustHeight();
 }
\ No newline at end of file

Modified: 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/util.js
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/util.js
  (original)
+++ 
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/util.js
  Mon Nov 28 09:18:24 2011
@@ -61,7 +61,7 @@
 function getBaseUrl() {
   var baseUrl = window.location.protocol +"//" + window.location.hostname;
   if (window.location.port != "") {
-    baseurl += ":" + window.location.port;
+    baseUrl += ":" + window.location.port;
   }
   return baseUrl;
 }

Modified: sandbox/ivol/amdatu-gadget-container/tenant-management-service/pom.xml
==============================================================================
--- sandbox/ivol/amdatu-gadget-container/tenant-management-service/pom.xml      
(original)
+++ sandbox/ivol/amdatu-gadget-container/tenant-management-service/pom.xml      
Mon Nov 28 09:18:24 2011
@@ -33,6 +33,11 @@
       <artifactId>org.amdatu.libraries.utilities</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>org.amdatu.cassandra.application</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: 
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/osgi/Activator.java
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/osgi/Activator.java
     (original)
+++ 
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/osgi/Activator.java
     Mon Nov 28 09:18:24 2011
@@ -15,6 +15,7 @@
  */
 package org.amdatu.core.tenant.osgi;
 
+import org.amdatu.cassandra.application.CassandraDaemonService;
 import org.amdatu.core.tenant.TenantManagementService;
 import org.amdatu.core.tenant.TenantStorageProvider;
 import org.amdatu.core.tenant.service.TenantConfigServiceImpl;
@@ -42,6 +43,9 @@
                     .setService(TenantStorageProvider.class)
                     .setRequired(true))
                 .add(createServiceDependency()
+                    .setService(CassandraDaemonService.class)
+                    .setRequired(true))
+                .add(createServiceDependency()
                     .setService(LogService.class)
                     .setRequired(false))
             );

Modified: 
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/service/TenantManagementServiceImpl.java
==============================================================================
--- 
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/service/TenantManagementServiceImpl.java
        (original)
+++ 
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/service/TenantManagementServiceImpl.java
        Mon Nov 28 09:18:24 2011
@@ -15,23 +15,24 @@
  */
 package org.amdatu.core.tenant.service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
-
-import org.amdatu.core.tenant.Tenant;
-import org.amdatu.core.tenant.TenantEntity;
-import org.amdatu.core.tenant.TenantException;
-import org.amdatu.core.tenant.TenantManagementService;
-import org.amdatu.core.tenant.TenantStorageProvider;
-import org.apache.felix.dm.Component;
-import org.apache.felix.dm.DependencyManager;
-import org.osgi.service.log.LogService;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
+
+import org.amdatu.cassandra.application.CassandraDaemonService;
+import org.amdatu.core.tenant.Tenant;
+import org.amdatu.core.tenant.TenantEntity;
+import org.amdatu.core.tenant.TenantException;
+import org.amdatu.core.tenant.TenantManagementService;
+import org.amdatu.core.tenant.TenantStorageProvider;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.service.log.LogService;
 
 /**
  * This class implements the Tenant management service. It provides CRUD 
operations on tenants and ensures
@@ -50,7 +51,8 @@
     private volatile LogService m_logService;
     private volatile DependencyManager m_manager;
     private volatile TenantStorageProvider m_tenantStorageProvider;
-
+    private volatile CassandraDaemonService m_cassandraDaemon;
+    
     private Map<Tenant, Component> m_tenantComponents = new HashMap<Tenant, 
Component>();
 
     // We currently use all-exclusive access.
@@ -168,7 +170,14 @@
             try {
                 readLock.lock();
                 writeLock.unlock();
-                removeTenantService(tenant);
+                removeTenantService(tenant);
+                
+                // This is a dirty hack to support deleting tenants. When a 
tenant is deleted, 
+                // the keyspace in Cassandra still exists. As a consequence 
all services that
+                // depend on the keyspace instead of the tenant directly keep 
running, like UserAdmin.
+                if (m_cassandraDaemon != null) {
+                    m_cassandraDaemon.dropKeyspace(tenant.getId());
+                }
             } finally {
                 readLock.unlock();
             }
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to