View Javadoc

1   /*
2    * Copyright (c) 1998-2002 The Jgroup Team.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser General Public License version 2 as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Lesser General Public License for more details.
12   *
13   * You should have received a copy of the GNU Lesser General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16   *
17   */
18   
19  package jgroup.upgrade;
20  
21  import java.rmi.NotBoundException;
22  import java.rmi.RemoteException;
23  
24  import jgroup.core.ConfigManager;
25  import jgroup.core.GroupManager;
26  import jgroup.core.IID;
27  import jgroup.core.JgroupException;
28  import jgroup.core.MembershipService;
29  import jgroup.core.arm.ExecException;
30  import jgroup.core.arm.UnknownGroupException;
31  import jgroup.core.protocols.Multicast;
32  import jgroup.core.registry.DependableRegistry;
33  import jgroup.core.registry.RegistryService;
34  import jgroup.relacs.config.AppConfig;
35  
36  import org.apache.log4j.Logger;
37  
38  
39  /**
40   *
41   *  @author Hein Meling
42   *  @since Jgroup 1.2
43   */
44  public class UpgradeManagerImpl
45    implements UpgradeManager
46  {
47  
48    ////////////////////////////////////////////////////////////////////////////////////////////
49    // Logger
50    ////////////////////////////////////////////////////////////////////////////////////////////
51  
52    /** Obtain logger for this class */
53    private static final Logger log = Logger.getLogger(UpgradeManagerImpl.class);
54  
55  
56    ////////////////////////////////////////////////////////////////////////////////////////////
57    // Constants
58    ////////////////////////////////////////////////////////////////////////////////////////////
59  
60    private static final String upgrSrvName = UpgradeService.UPGRADE_SERVICE + "-";
61  
62  
63    ////////////////////////////////////////////////////////////////////////////////////////////
64    // Private Fields
65    ////////////////////////////////////////////////////////////////////////////////////////////
66  
67    /** The application information for the upgrade manager application. */
68    private AppConfig thisApp;
69  
70    /** The dependable registry reference. */
71    private DependableRegistry dregistry;
72  
73  
74    ////////////////////////////////////////////////////////////////////////////////////////////
75    // Constructors
76    ////////////////////////////////////////////////////////////////////////////////////////////
77  
78    /**
79     *  Construct a local <code>UpgradeManagerImpl</code> instance.
80     *
81     *  @exception JgroupException
82     *    Raised if the upgrade manager could not be created for
83     *    numerous reasons.
84     *  @exception RemoteException
85     *    Raised if there was a problem with the dependable registry.
86     */
87    public UpgradeManagerImpl(DependableRegistry dregistry)
88      throws JgroupException, RemoteException
89    {
90      this.dregistry = dregistry;
91  
92      /* Initialize the application name for the upgrade mananger */
93      ConfigManager.init();
94      thisApp = AppConfig.getApplication(this);
95      /*
96       * Obtain a group manager for this application and the service proxy
97       * for the EGMI service.
98       */
99      GroupManager gm = GroupManager.getGroupManager(this);
100     MembershipService pgms = (MembershipService)  gm.getService(MembershipService.class);
101     RegistryService registryService = (RegistryService) gm.getService(RegistryService.class);
102 
103     pgms.join(thisApp.getGroupId());
104 
105     /* Bind the upgrade manager with the dependable registry */
106     IID iid = registryService.bind(thisApp.getRegistryName(), this);
107     if (log.isDebugEnabled())
108       log.debug("UpgradeManager started");
109   }
110 
111 
112   ////////////////////////////////////////////////////////////////////////////////////////////
113   // UpgradeManager interface methods
114   ////////////////////////////////////////////////////////////////////////////////////////////
115 
116   /**
117    *  Upgrade the group for the specified application, with the
118    *  applications required redundancy.
119    *
120    *  @param app
121    *    The application details required to upgrade the group.
122    *  @exception RemoteException
123    *    Raised if there was communication problems; only when invoked remotely.
124    *  @exception UnknownGroupException
125    *    Raised if the specified application has no group in the system.
126    */
127   @Multicast public void upgradeGroup(AppConfig app)
128     throws RemoteException, UnknownGroupException, ExecException
129   {
130     if (log.isDebugEnabled())
131       log.debug("Upgrading group: " + app);
132     String upgradeId = upgrSrvName + app.getGroupId();
133     if (log.isDebugEnabled())
134       log.debug("UpgradeId: "  + upgradeId);
135 
136     try {
137       UpgradeService upgrService = (UpgradeService) dregistry.lookup(upgradeId);
138       if (log.isDebugEnabled())
139         log.debug("Upgrade service proxy: " + upgrService);
140       upgrService.upgradeRequest(app);
141     } catch (NotBoundException e) {
142       throw new UnknownGroupException("Group not bound with the dependable registry", app.getGroupId());
143     }
144     
145     //joan-comment: this is the method that starts the upgrade algorithm.
146   }
147 
148 
149   /**
150    *  Downgrade the group for the given application.
151    *
152    *  @param app
153    *    The application group to remove.
154    *  @exception RemoteException
155    *    Raised if there was communication problems; only when invoked remotely.
156    *  @exception UnknownGroupException
157    *    Raised if the specified application has no group in the system.
158    */
159   @Multicast public void downgradeGroup(AppConfig app)
160     throws RemoteException, UnknownGroupException
161   {
162     throw new UnsupportedOperationException();
163   }
164 
165 } // END UpgradeManagerImpl