KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > install > InstallerImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.enterprise.jbi.serviceengine.install;
26
27 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException;
28 import com.sun.enterprise.server.ApplicationServer;
29 import com.sun.logging.LogDomains;
30 import java.io.File JavaDoc;
31 import java.io.FileInputStream JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.net.URI JavaDoc;
34 import java.util.Properties JavaDoc;
35 import java.util.logging.Level JavaDoc;
36 import java.util.logging.Logger JavaDoc;
37 import javax.management.ObjectName JavaDoc;
38
39
40
41 /**
42  * Installs Java EE Service Engine on a CAS installation. In openESB world, an
43  * instance could either be a CAS or a non CAS ESB member. Java EE Servijece Engine
44  * is installed on a instance only if the instance is CAS. All components
45  * installed on CAS are installed on a non CAS ESB member by the CAS.
46  * @author Manishaa Umbar
47  */

48 public class InstallerImpl implements Installer {
49     
50         
51     /**
52      * addComponent operation of ESB installation MBean adds the component
53      * to ESB's registry and repository. By adding a component, component becomes
54      * installable.
55      */

56     private static final String JavaDoc ADD_COMPONENT_OPERATION="addComponent";
57     
58     /**
59      * Install a already added component in ESB environment
60      */

61     private static final String JavaDoc INSTALL_COMPONENT_OPERATION="installComponent";
62     
63     /**
64      * removeComponent operation of ESB installation MBean removes the component
65      * from ESB's registry and repository.
66      */

67     private static final String JavaDoc REMOVE_COMPONENT_OPERATION="removeComponent";
68     
69     /**
70      * UnInstalls already added component in ESB environment. By uninstalling a component,
71      * component becomes removable from the registry and repository of CAS.
72      */

73     private static final String JavaDoc UNINSTALL_COMPONENT_OPERATION="uninstallComponent";
74     
75     /**
76      * Starts the component
77      */

78     private static final String JavaDoc START_COMPONENT_OPERATION="startComponent";
79     
80     /**
81      * Stops the component
82      */

83     private static final String JavaDoc STOP_COMPONENT_OPERATION="stopComponent";
84     
85     
86     private String JavaDoc componentName = null;
87     private String JavaDoc SE_BUNDLE = "lib/addons/jbi/appserv-jbise.jar";
88     
89     private String JavaDoc JBI_FOLDER = "jbi";
90     
91     private MBeanHelper mbeanHelper;
92     
93     private String JavaDoc jbiInstanceName;
94     
95     private boolean jbiInstalled = false;
96     
97     /**
98      * Internal handle to the logger instance
99      */

100     private static Logger JavaDoc logger =
101             LogDomains.getLogger(LogDomains.SERVER_LOGGER);
102     
103     /** Creates a new instance of CASInstallerImpl */
104     public InstallerImpl(MBeanHelper mbeanHelper) {
105         this.mbeanHelper = mbeanHelper;
106         String JavaDoc installationRoot =
107                 ApplicationServer.getServerContext().getInstallRoot();
108         String JavaDoc jbiInstallationDir = installationRoot + File.separator + JBI_FOLDER;
109         boolean mbeanRegistered = false;
110         try {
111             mbeanRegistered = mbeanHelper.isMBeanRegistered(MBeanHelper.ESB_INSTALLATION_SERVICE);
112         } catch(ServiceEngineException ex) {
113             logger.log(Level.SEVERE, ex.getMessage(), ex);
114         }
115         jbiInstalled = new File JavaDoc(jbiInstallationDir).exists() && mbeanRegistered;
116     }
117     
118     public boolean isJBIInstalled() {
119         return jbiInstalled;
120     }
121     
122     public void setComponentName(String JavaDoc componentName) {
123         this.componentName = componentName;
124     }
125     
126     
127     /**
128      * Installs the service engine and starts it
129      * @param zipFilePath packaged 208 compliant service engine bundle
130      *
131      */

132     public String JavaDoc install(String JavaDoc zipFilePath) throws ServiceEngineException {
133         //Use InstallationServiceMBean to install new component
134
String JavaDoc result = null;
135         if(zipFilePath == null) {
136             zipFilePath = getServiceEngineBundle();
137                 log(Level.FINE, "Java EE Service Engine Bundle :" , zipFilePath);
138                 try {
139                     
140                     ObjectName JavaDoc objName = mbeanHelper.getObjectName(
141                             MBeanHelper.ESB_INSTALLATION_SERVICE);
142                     
143                     log(Level.FINEST, "installation_service_log_name" , objName.toString());
144                     
145                     result = (String JavaDoc)mbeanHelper.invokeMBeanOperation(objName,
146                             ADD_COMPONENT_OPERATION, new Object JavaDoc[]{zipFilePath},
147                             new String JavaDoc[] {"java.lang.String"});
148                             
149                     log(Level.FINEST, " Status of addComponent ", result );
150                             
151                     result = (String JavaDoc)mbeanHelper.invokeMBeanOperation(objName,
152                                     INSTALL_COMPONENT_OPERATION,
153                                     new Object JavaDoc[]{componentName},
154                                     new String JavaDoc[] {"java.lang.String"});
155                                     
156                     log(Level.FINEST, " Status of installComponent ", result );
157                 } catch(Exception JavaDoc e) {
158                     log(Level.SEVERE,
159                             "Error occurred during installation of Java EE Service Engine",
160                             e.getMessage());
161                 }
162         }
163         return result;
164         
165     }
166     
167     /**
168      * Starts the component with provided name
169      */

170     public void start() throws ServiceEngineException {
171             try {
172                 ObjectName JavaDoc objName = mbeanHelper.getObjectName(
173                         MBeanHelper.ESB_LIFECYCLE_SERVICE);
174                 
175                 log(Level.FINEST, "lifecycle_service_obj_name" , objName.toString());
176                 
177                 String JavaDoc result = (String JavaDoc)mbeanHelper.invokeMBeanOperation(objName,
178                         START_COMPONENT_OPERATION, new Object JavaDoc[]{componentName},
179                         new String JavaDoc[] {"java.lang.String"});
180                         log(Level.FINEST, "Start Component Status", result);
181             } catch(Exception JavaDoc e) {
182                 log(Level.SEVERE,
183                         "Error occurred during startup of Java EE Service Engine",
184                         e.getMessage());
185             }
186     }
187     
188     
189     /**
190      * Checks if the compoenent specified by componentName is installed or
191      * not
192      */

193     public boolean isComponentInstalled() {
194             try {
195                 String JavaDoc domainDir = ApplicationServer.getServerContext().getInstanceEnvironment().getInstancesRoot();
196                 String JavaDoc fs = File.separator;
197                 String JavaDoc javaeeSEDir = domainDir + fs + "jbi" + fs + "engines" + fs + "JavaEEServiceEngine";
198                 if(!(new File JavaDoc(javaeeSEDir).exists())) {
199                     return false;
200                 }
201             } catch(Exception JavaDoc e) {
202                 log(Level.WARNING, "Exception occurred while getting component by name", e.getMessage());
203                 return false;
204             }
205         
206         return true;
207     }
208     
209     /**
210      * Stops the component with provided name
211      */

212     public void stop() throws ServiceEngineException {
213             try {
214                 
215                 ObjectName JavaDoc objName = mbeanHelper.getObjectName(
216                         MBeanHelper.ESB_LIFECYCLE_SERVICE);
217                 
218                 log(Level.FINEST, "lifecycle_service_obj_name" , objName.toString());
219                 
220                 String JavaDoc result = (String JavaDoc)mbeanHelper.invokeMBeanOperation(objName,
221                         STOP_COMPONENT_OPERATION, new Object JavaDoc[]{componentName},
222                         new String JavaDoc[] {"java.lang.String"});
223                         log(Level.FINEST, "Start Component Status", result);
224             } catch(Exception JavaDoc e) {
225                 log(Level.SEVERE,
226                         "Error occurred during stopping of Java EE Service Engine",
227                         e.getMessage());
228             }
229         
230     }
231     
232     /**
233      * Uninstalls the component with provided name
234      */

235     public void uninstall() throws ServiceEngineException {
236             try {
237                 
238                 ObjectName JavaDoc objName = mbeanHelper.getObjectName(
239                         MBeanHelper.ESB_INSTALLATION_SERVICE);
240                 
241                 log(Level.FINEST, "installation_service_log_name" , objName.toString());
242                 
243                 String JavaDoc result = (String JavaDoc)mbeanHelper.invokeMBeanOperation(objName,
244                         UNINSTALL_COMPONENT_OPERATION, new Object JavaDoc[]{componentName},
245                         new String JavaDoc[] {"java.lang.String"});
246                         
247                         log(Level.FINEST, " Status of uninstallComponent ", result );
248                         
249                         result = (String JavaDoc)mbeanHelper.invokeMBeanOperation(objName,
250                                 REMOVE_COMPONENT_OPERATION,
251                                 new Object JavaDoc[]{componentName},
252                                 new String JavaDoc[] {"java.lang.String"});
253                                 
254                                 log(Level.FINEST, " Status of removeComponent ", result );
255             } catch(Exception JavaDoc e) {
256                 log(Level.SEVERE,
257                         "Error occurred during uninstallation of Java EE Service Engine",
258                         e.getMessage());
259             }
260     }
261     
262     private String JavaDoc getServiceEngineBundle() {
263         
264         String JavaDoc seBundle = System.getProperty("com.sun.aas.installRoot") +
265                     File.separator + SE_BUNDLE;
266         return seBundle;
267     }
268     
269     
270     private void log(Level JavaDoc level, String JavaDoc property, String JavaDoc logString) {
271         logger.log(level,property,logString);
272     }
273     
274 }
275
Popular Tags