[jboss-cvs] JBossAS SVN: r83381 - trunk/cluster/src/main/org/jboss/ha/singleton.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 23 15:29:20 EST 2009


Author: bstansberry at jboss.com
Date: 2009-01-23 15:29:19 -0500 (Fri, 23 Jan 2009)
New Revision: 83381

Added:
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivator.java
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivatorMBean.java
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManager.java
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManagerMBean.java
Log:
[JBAS-5563] Prototype hasingleton deployer that uses ProfileService.activate/releaseProfile()

Added: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivator.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivator.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivator.java	2009-01-23 20:29:19 UTC (rev 83381)
@@ -0,0 +1,252 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+import org.jboss.logging.Logger;
+import org.jboss.profileservice.spi.NoSuchProfileException;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+
+/**
+ * Bean that activates a configurable Profile when notified by a singleton
+ * controller, and releases it when notified.
+ * 
+ * TODO rename and move to another package, as there is nothing 
+ * HASingleton-specific about what this bean does; it just exposes an
+ * operation an HASingletonController can use.
+ * 
+ * @author Brian Stansberry
+ * @version $Revision: 82920 $
+ */
+public class HASingletonProfileActivator implements HASingletonProfileActivatorMBean
+{
+   /** Default value for {@link #getProfileName()} */
+   public static final String DEFAULT_PROFILE_NAME = "deploy-hasingleton";
+   
+   protected final Logger log = Logger.getLogger(getClass());
+   
+   /** Whether this node has activated its profile */
+   private boolean activated;
+   
+   /** The profile service key domain */
+   private String profileDomain;
+   
+   /** The profile service key name */
+   private String profileServer;
+   
+   /** The profile service key name */
+   private String profileName;
+   
+   /** The profile service key */
+   private ProfileKey profileKey;
+   
+   /** The profile service */
+   private ProfileService profileService;
+
+   // ----------------------------------------------------------- Constructors
+
+   /**
+    * Create a new HASingletonProfileActivator.
+    */
+   public HASingletonProfileActivator()
+   {
+      super();
+   }
+
+   // ------------------------------------------------------------- Properties
+   
+   /**
+    * Gets the ProfileService.
+    * 
+    * @return the profileService.
+    */
+   public ProfileService getProfileService()
+   {
+      return profileService;
+   }
+
+   /**
+    * Sets the ProfileService reference.
+    * 
+    * @param profileService the profileService. Cannot be <code>null</code>
+    * 
+    * @throws IllegalArgumentException if <code>profileService</code> is <code>null</code>
+    */
+   public void setProfileService(ProfileService profileService)
+   {
+      if (profileService == null)
+      {
+         throw new IllegalArgumentException("profileService is null");
+      }
+      
+      this.profileService = profileService;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getProfileDomain()
+   {
+      return profileDomain;
+   }
+
+   /**
+    * Sets the value that should be used for the 
+    * {@link ProfileKey#getDomain() domain} portion of
+    * the singleton @{link Profile}'s {@link #getProfileKey() ProfileKey}.
+    * 
+    * @param profileDomain the domain, or <code>null</code>
+    */
+   public void setProfileDomain(String profileDomain)
+   {
+      this.profileDomain = profileDomain;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getProfileServer()
+   {
+      return profileServer;
+   }
+
+   /**
+    * Sets the value that should be used for the 
+    * {@link ProfileKey#getServer() server} portion of
+    * the singleton @{link Profile}'s {@link #getProfileKey() ProfileKey}.
+    * 
+    * @param profileServer the server, or <code>null</code>
+    */
+   public void setProfileServer(String profileServer)
+   {
+      this.profileServer = profileServer;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getProfileName()
+   {
+      return profileName == null ? DEFAULT_PROFILE_NAME : profileName;
+   }
+
+   /**
+    * Sets the value that should be used for the 
+    * {@link ProfileKey#getName() name} portion of
+    * the singleton @{link Profile}'s {@link #getProfileKey() ProfileKey}.
+    * 
+    * @param profileName the name, or <code>null</code>
+    */
+   public void setProfileName(String profileName)
+   {
+      this.profileName = profileName;
+   }
+   
+   /**
+    * {@inheritDoc}
+    */
+   public boolean isActivated()
+   {
+      return activated;
+   }
+   
+   // -------------------------------------------------------------- Public
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void activateProfile() throws Exception
+   {
+      if (this.profileService == null)
+      {
+         throw new IllegalStateException("Must configure the ProfileService");
+      }
+      
+      if (!this.activated)
+      {         
+         try
+         {
+            this.profileService.activateProfile(getProfileKey());
+            
+            this.activated = true;
+         }
+         catch (NoSuchProfileException e)
+         {
+            handleNoSuchProfileException(e);
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public synchronized void releaseProfile() throws Exception
+   {
+      if (this.activated)
+      {         
+         try
+         {
+            this.profileService.releaseProfile(getProfileKey());
+         }
+         catch (NoSuchProfileException e)
+         {
+            log.warn("No Profile is registered under key " + getProfileKey());
+         }
+         
+         this.activated = false;
+      }
+   }
+   
+   /**
+    * Gets the key for the {@link Profile} that we activate and release.
+    * 
+    * @return the key. Will not return <code>null</code>
+    * 
+    * @see HASingletonProfileActivator#getProfileDomain() 
+    * @see HASingletonProfileActivator#getProfileServer() 
+    * @see HASingletonProfileActivator#getProfileName()
+    */
+   public ProfileKey getProfileKey()
+   {
+      if (this.profileKey == null)
+      {
+         this.profileKey = new ProfileKey(getProfileDomain(), getProfileServer(), getProfileName());
+      }
+      return this.profileKey;
+   }
+   
+   // -------------------------------------------------------------- Protected
+   
+
+   /**
+    * Handle a NoSuchProfileException thrown in {@link #activateProfile()}.
+    * This base implementation just logs a WARN.
+    */
+   protected void handleNoSuchProfileException(NoSuchProfileException e)
+   {
+      log.warn("No Profile has been registered under key " + getProfileKey() +
+            " -- perhaps you have a deployed deploy-hasingleton-jboss-beans.xml " +
+            " without any corresponding profile configured?");      
+   }
+
+}
\ No newline at end of file


Property changes on: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivator.java
___________________________________________________________________
Name: svn:keywords
   + 

Added: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivatorMBean.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivatorMBean.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivatorMBean.java	2009-01-23 20:29:19 UTC (rev 83381)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+
+/**
+ * StandardMBean interface for {@link HASingletonProfileActivator}.
+ * 
+ * @author Brian Stansberry
+ * @version $Revision: 82920 $
+ */
+public interface HASingletonProfileActivatorMBean
+{
+
+   /**
+    * Gets the value that should be used for the 
+    * {@link ProfileKey#getDomain() domain} portion of
+    * the singleton @{link Profile}'s {@link #getProfileKey() ProfileKey}.
+    * 
+    * @return the domain, or <code>null</code> if not set
+    */
+   String getProfileDomain();
+
+   /**
+    * Gets the value that should be used for the 
+    * {@link ProfileKey#getServer() server} portion of
+    * the singleton @{link Profile}'s {@link #getProfileKey() ProfileKey}.
+    * 
+    * @return the server, or <code>null</code> if not set
+    */
+   String getProfileServer();
+
+   /**
+    * Gets the value that should be used for the 
+    * {@link ProfileKey#getName() name} portion of
+    * the singleton @{link Profile}'s {@link #getProfileKey() ProfileKey}.
+    * 
+    * @return the name, or {@link #DEFAULT_PROFILE_NAME} if not set
+    */
+   String getProfileName();
+
+   /**
+    * Gets whether this object has activated its profile.
+    * 
+    * @return <code>true</code> if {@link #activateProfile()} has successfully
+    *         completed and {@link #releaseProfile()} has not been called;
+    *         <code>false</code> otherwise.
+    */
+   boolean isActivated();
+
+   /**
+    * Tells the ProfileService to {@link ProfileService#activateProfile(ProfileKey) activate the profile}. 
+    * Called by the HASingletonController when we become the singleton master.
+    */
+   void activateProfile() throws Exception;
+
+   /**
+    * Tells the ProfileService to {@link ProfileService#releaseProfile(ProfileKey) release the profile}. 
+    * Called by the HASingletonController when we are no longer the singleton master.
+    */
+   void releaseProfile() throws Exception;
+
+}
\ No newline at end of file


Property changes on: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileActivatorMBean.java
___________________________________________________________________
Name: svn:keywords
   + 

Added: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManager.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManager.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManager.java	2009-01-23 20:29:19 UTC (rev 83381)
@@ -0,0 +1,227 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.profileservice.spi.NoSuchProfileException;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.profileservice.spi.metadata.ProfileMetaData;
+import org.jboss.profileservice.spi.metadata.ProfileSourceMetaData;
+import org.jboss.profileservice.spi.metadata.SubProfileMetaData;
+import org.jboss.system.server.profileservice.repository.AbstractProfileFactory;
+import org.jboss.system.server.profileservice.repository.DefaultDeploymentRepositoryFactory;
+
+/**
+ * Extends {@link HASingletonProfileActivator} by actually creating and
+ * registering a {@link Profile} from a configurable set of URIs during
+ * the {@link #start()} phase, deregistering it in the {@link #stop()} phase.
+ * 
+ * @author Brian Stansberry
+ * @version $Revision: 82920 $
+ */
+public class HASingletonProfileManager extends HASingletonProfileActivator implements HASingletonProfileManagerMBean
+{   
+   private AbstractProfileFactory profileFactory;
+   
+   /** The list of URIs to scan */
+   private List<URI> uriList = new CopyOnWriteArrayList<URI>();
+   
+   /**
+    * Create a new HASingletonProfileManager.
+    *
+    */
+   public HASingletonProfileManager()
+   {
+      super();
+   }
+   
+   // ----------------------------------------------------------  Properties
+   
+   public AbstractProfileFactory getProfileFactory()
+   {
+      return profileFactory;
+   }
+
+   public void setProfileFactory(AbstractProfileFactory profileFactory)
+   {
+      this.profileFactory = profileFactory;
+   }
+
+   /**
+    * Set the uri list
+    * 
+    * @param list the list
+    * @throws IOException
+    */
+   public void setURIList(final List<URI> list) throws IOException
+   {
+      if (list == null)
+      {
+         throw new NullPointerException("list argument cannot be null");
+      }
+   
+      // start out with a fresh list
+      uriList.clear();
+   
+      for(int n = 0; n < list.size(); n ++)
+      {
+         URI uri = list.get(n);
+         if (uri == null)
+         {
+            throw new IllegalArgumentException("list element["+n+"] is null");
+         }
+
+         if( uriList.add(uri) == true )
+         {
+            log.debug("Added URI: " + uri);
+         }  
+      }
+      log.debug("URI list: " + uriList);
+   }
+
+   /**
+    * Get the uri list
+    * 
+    * @return the list
+    */
+   public List<URI> getURIList()
+   {
+      return new ArrayList<URI>(uriList);
+   }
+
+   
+
+   // -----------------------------------------------------------------  Public
+
+   /**
+    * Builds a profile from the {@link #getURIList() URI list} and registers
+    * it under the configured {@link #getProfileKey()}.
+    */
+   public void start() throws Exception
+   {    
+      if (this.profileFactory == null)
+      {
+         throw new IllegalStateException("Must configure profileFactory");
+      } 
+      
+      if (getProfileService() == null)
+      {
+         throw new IllegalStateException("Must configure profileService");
+      }
+      
+      URI[] rootURIs = uriList.toArray(new URI[uriList.size()]);
+      // TODO add dependencies on bootstrap profiles
+      String[] rootSubProfiles = new String[0];
+      ProfileMetaData metadata = createProfileMetaData(DefaultDeploymentRepositoryFactory.MUTABLE_TYPE, rootURIs, rootSubProfiles);
+      
+      Profile profile = profileFactory.createProfile(getProfileKey(), metadata);
+      getProfileService().registerProfile(profile);      
+   }
+   
+   /**
+    * Unregisters the profile registered in {@link #start()}.
+    */
+   public void stop() throws Exception
+   {      
+      ProfileService profSvc = getProfileService();
+      ProfileKey profKey = getProfileKey();
+      if (profSvc != null &&  profKey != null)
+      {
+         try
+         {
+            // Inactivate first if needed
+            if (profSvc.getActiveProfileKeys().contains(profKey))
+            {
+               releaseProfile();
+            }
+            
+            Profile profile = profSvc.getProfile(profKey);
+            profSvc.unregisterProfile(profile);
+         }
+         catch (NoSuchProfileException e)
+         {
+            log.warn("Could not unregister unknown profile " + profKey);
+         }
+      }
+   }
+   
+   // ----------------------------------------------------------------  Private
+
+   
+   /**
+    * Create a profile meta data.
+    * 
+    * @param name the profile name.
+    * @param repositoryType the repository type.
+    * @param uris the repository uris.
+    * @param subProfiles a list of profile dependencies.
+    * @return the profile meta data.
+    */
+   private ProfileMetaData createProfileMetaData(String repositoryType, URI[] uris, String[] subProfiles)
+   {
+      // Create profile
+      ProfileMetaData metaData = new ProfileMetaData();
+      metaData.setDomain(getProfileDomain());
+      metaData.setServer(getProfileServer());
+      metaData.setName(getProfileName());
+      
+      // Create profile sources
+      List<ProfileSourceMetaData> sources = new ArrayList<ProfileSourceMetaData>();
+      for(URI uri : uris)
+         sources.add(createSource(repositoryType, uri));
+      metaData.setSources(sources);
+      
+      List<SubProfileMetaData> profileList = new ArrayList<SubProfileMetaData>();
+      for(String subProfile : subProfiles)
+      {
+         SubProfileMetaData md = new SubProfileMetaData();
+         md.setName(subProfile);
+         profileList.add(md);
+      }
+      metaData.setSubprofiles(profileList);
+      
+      return metaData;
+   }
+   
+   /**
+    * Create a profile repository source meta data.
+    * 
+    * @param type the repository type.
+    * @param uri the uri
+    * @return the profile source meta data.
+    */
+   private ProfileSourceMetaData createSource(String type, URI uri)
+   {
+      ProfileSourceMetaData source = new ProfileSourceMetaData();
+      source.setType(type);
+      source.setSource(uri.toString());
+      return source;
+   }
+   
+}


Property changes on: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManager.java
___________________________________________________________________
Name: svn:keywords
   + 

Added: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManagerMBean.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManagerMBean.java	                        (rev 0)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManagerMBean.java	2009-01-23 20:29:19 UTC (rev 83381)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.singleton;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+
+/**
+ * StandardMBean interface for {@link HASingletonProfileManager}.
+ * 
+ * @author Brian Stansberry
+ * @version $Revision: 82920 $
+ */
+public interface HASingletonProfileManagerMBean
+{
+
+   /**
+    * Set the uri list
+    * 
+    * @param list the list
+    * @throws IOException
+    */
+   public abstract void setURIList(final List<URI> list) throws IOException;
+
+   /**
+    * Get the uri list
+    * 
+    * @return the list
+    */
+   public abstract List<URI> getURIList();
+
+}
\ No newline at end of file


Property changes on: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonProfileManagerMBean.java
___________________________________________________________________
Name: svn:keywords
   + 




More information about the jboss-cvs-commits mailing list