KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > installer > NodeDestinationDeployer


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Briclet Frédéric.
23 Contributor(s): Philippe Merle, Christophe Contreras.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer;
28
29 import java.io.IOException JavaDoc;
30 import java.io.InputStream JavaDoc;
31 import java.util.Hashtable JavaDoc;
32 import org.ist.coach.DCI.NodeManager;
33 import org.ist.coach.DCI.NodeManagerHelper;
34 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.FatalDeploymentException;
35 import org.objectweb.openccm.descriptor.softpkg.ccm.CodeInstallationFailureException;
36 import org.objectweb.openccm.descriptor.softpkg.ccm.DependencyResolutionFailureException;
37 import org.omg.Components.CCMHome;
38 import org.omg.Components.ConfigValue;
39 import org.omg.Components.Deployment.ComponentInstallation;
40 import org.omg.Components.Deployment.ComponentServer;
41 import org.omg.Components.Deployment.Container;
42 import org.omg.Components.Deployment.InstallationFailure;
43 import org.omg.Components.Deployment.InvalidLocation;
44
45 /**
46  * The NodeDestinationDeployer is the DestinationDeployer able to install
47  * a home on a DCI node.
48  *
49  * @author <a HREF="mailto:briclet@lifl.fr">Briclet Frédéric</a>
50  *
51  * @version 0.1
52  */

53 public class NodeDestinationDeployer
54        extends DestinationDeployerBase
55 {
56     // ==================================================================
57
//
58
// Internal state.
59
//
60
// ==================================================================
61

62     private NodeManager node;
63
64     private ComponentServer cs;
65
66     private Hashtable JavaDoc containerTable;
67
68     private java.util.List JavaDoc config_values;
69
70     private NodeDependencyVisitorDeployer depVisitor;
71
72     // ==================================================================
73
//
74
// Constructor.
75
//
76
// ==================================================================
77

78     public
79     NodeDestinationDeployer()
80     {
81         containerTable = new Hashtable JavaDoc();
82         config_values = new java.util.LinkedList JavaDoc();
83         depVisitor = new NodeDependencyVisitorDeployer();
84     }
85
86     // ==================================================================
87
//
88
// Internals methods.
89
//
90
// ==================================================================
91

92     /**
93      * Internal method to install a home
94      */

95     private CCMHome
96     installCCMHome(
97         ConfigValue[] csConfig,
98         ConfigValue[] contConfig,
99         ConfigValue[] homeConfig,
100         String JavaDoc implID,
101         String JavaDoc entryPoint)
102     throws FatalDeploymentException
103     {
104         CCMHome home = null;
105         try {
106             if (cs == null)
107                 cs =
108                     getNode()
109                         .provide_server_activator()
110                         .create_component_server(
111                         csConfig);
112             Container cont = cs.create_container(contConfig);
113             home = cont.install_home(implID, entryPoint, homeConfig);
114             containerTable.put(home, cont);
115         } catch (Exception JavaDoc e) {
116             e.printStackTrace();
117             throw new FatalDeploymentException(this,e,"Cannot deploy the CCMHome on the required destination");
118         }
119         return home;
120     }
121
122     /**
123      * Internal method to retrieve a nodeManager
124      * @return
125      * @throws Exception
126      */

127     private NodeManager
128     getNode()
129     throws Exception JavaDoc
130     {
131         if (node == null)
132         {
133             node = getNodeDeployer().getNodeManager();
134         }
135         return node;
136     }
137
138     /**
139      * Internal method to start a HTTP server for component archive uploading
140      * @param input the input on the file to upload
141      * @param name the file name to upload
142      * @return The URL to use to download file
143      * @throws java.io.IOException if I/O problem occured
144      */

145     private String JavaDoc
146     startHttpServer(InputStream JavaDoc input, String JavaDoc name)
147     throws java.io.IOException JavaDoc
148     {
149         (new Thread JavaDoc(new org
150
            .objectweb
151             .openccm
152             .deploytool
153             .MicroServerHttp(
154                 getRootDeployerContext().getServerSocket(),
155                 input,
156                 name)))
157             .start();
158         return "http://"
159             + java.net.InetAddress.getLocalHost().getHostAddress()
160             + ':'
161             + getRootDeployerContext().getServerSocket().getLocalPort()
162             + '/'
163             + name;
164     }
165
166     // ==================================================================
167
//
168
// Public methods.
169
//
170
// ==================================================================
171

172     /**
173      * Make the target destination deployer process all the dependencies
174      * of the implementation.
175      *
176      * @throws FatalDeploymentException if a problem occured
177      * during processing of dependencies
178      */

179     public void
180     resolveDependency()
181     throws FatalDeploymentException
182     {
183         try {
184             /*config_values.addAll(Arrays.asList(getSoftpkgDeployer()
185                                                 .processDependencies
186                                                     (getComponentInstallation())));*/

187             getSoftpkgDeployer().visitDependencyDeployers(depVisitor);
188             /* List l=Arrays.asList(getImplementationDeployer()
189                                   .install(getComponentInstallation()));
190                
191               config_values.addAll(l); */

192             getImplementationDeployer().visitDependencyDeployers(depVisitor);
193             getImplementationDeployer().visitCodeDeployers(depVisitor);
194
195             try {
196                 String JavaDoc url =
197                     startHttpServer(
198                         getSoftpkgDeployer().getComponentArchiveStream(),
199                         getSoftpkgDeployer().getSoftpkg().getName() + ".car");
200                 getComponentInstallation().install(
201                     getSoftpkgDeployer().getSoftpkg().getName(),
202                     url);
203
204             } catch (IOException JavaDoc e) {
205                 // TODO Auto-generated catch block
206
e.printStackTrace();
207                 throw new FatalDeploymentException(
208                     e,
209                     "Cannot install implementation in target node");
210             } catch (InvalidLocation e) {
211                 // TODO Auto-generated catch block
212
e.printStackTrace();
213                 throw new FatalDeploymentException(
214                     e,
215                     "Cannot install implementation in target node");
216             } catch (InstallationFailure e) {
217                 // TODO Auto-generated catch block
218
e.printStackTrace();
219                 throw new FatalDeploymentException(
220                     e,
221                     "Cannot install implementation in target node");
222             }
223
224         } catch (DependencyResolutionFailureException e) {
225             getErrorManager().submitException(e);
226         } catch (CodeInstallationFailureException e) {
227             e.printStackTrace();
228             getErrorManager().submitException(e);
229         }
230     }
231
232     /**
233      * InstallHome install the home on the precised destination according
234      * to the host requirements, such as dependencies and event factory.
235      *
236      * @return The home installed
237      * @throws FatalDeploymentException
238      */

239     public CCMHome
240     installHome()
241     throws FatalDeploymentException
242     {
243
244         ConfigValue[] config_home =
245         /*(ConfigValue[])
246                                          config_values.toArray(new ConfigValue[config_values.size()]);*/

247         depVisitor.getConfigValue();
248
249         return installCCMHome(
250             new ConfigValue[0],
251             new ConfigValue[0],
252             config_home,
253             getImplementationDeployer().getImplementation().getId(),
254             depVisitor.getEntryPoint());
255     }
256
257     /**
258      * Return the component installation of the target host used
259      * to install the home.
260      *
261      * @return The component installation of the target host
262      * @throws FatalDeploymentException if a fatal problem occured during installation
263      */

264     public ComponentInstallation
265     getComponentInstallation()
266     throws FatalDeploymentException
267     {
268         try {
269
270             return getNode().provide_component_installation();
271         } catch (Exception JavaDoc e) {
272             getLogger().log("Exception occured during retrieving of Node");
273         throw new FatalDeploymentException(this,e,"Cannot access to the componentinstallation on the required destination");
274         }
275     }
276
277     /**
278      * Remove a previously installed CCMHome
279      *
280      * @param home the home to remove
281      * @throws FatalDeploymentException if a fatal problem occured during uninstallation
282      */

283     public void
284     removeHome(CCMHome home)
285     throws FatalDeploymentException
286     {
287         try {
288             Container cont = (Container) containerTable.remove(home);
289             if(cont==null)
290                 return ;
291             cont.remove_home(home);
292             
293             if(cont.get_homes().length==0){
294                 if(cont.get_component_server().get_containers().length==1)
295                     cont.get_component_server().remove();
296                 else
297                     cont.remove();
298             }
299           
300         } catch (Exception JavaDoc e) {
301             e.printStackTrace();
302             throw new FatalDeploymentException(e);
303         }
304     }
305
306 }
307
Popular Tags