Source Code Cross Referenced for UnConfigurePortal.java in  » Portal » Open-Portal » com » sun » portal » fabric » config » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.fabric.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: UnConfigurePortal.java,v 1.36.2.3 2007/04/17 08:08:22 ns208321 Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.config;
014:
015:        import java.net.InetAddress;
016:        import java.util.ArrayList;
017:        import java.util.Collections;
018:        import java.util.HashMap;
019:        import java.util.HashSet;
020:        import java.util.List;
021:        import java.util.Map;
022:        import java.util.logging.Level;
023:        import java.util.logging.Logger;
024:        import java.io.PrintWriter;
025:        import java.io.StringWriter;
026:        import java.io.File;
027:
028:        import javax.management.MBeanServerConnection;
029:
030:        import com.sun.portal.admin.common.DomainAttributes;
031:        import com.sun.portal.admin.common.context.PSConfigContext;
032:        import com.sun.portal.admin.common.context.PSConfigContextImpl;
033:        import com.sun.portal.admin.common.context.PortalDomainContext;
034:        import com.sun.portal.admin.common.util.AdminClientUtil;
035:        import com.sun.portal.fabric.tasks.Cacao;
036:        import com.sun.portal.fabric.tasks.ConfigurationException;
037:        import com.sun.portal.fabric.util.FileUtil;
038:        import com.sun.portal.fabric.util.os.OSTasks;
039:        import com.sun.portal.fabric.util.os.OSTasksFactory;
040:        import com.sun.portal.util.Platform;
041:        import com.sun.portal.log.common.PortalLogManager;
042:        import com.sun.portal.log.common.PortalLogger;
043:        import com.sun.portal.fabric.config.ValidatePortalInputData;
044:
045:        public class UnConfigurePortal {
046:
047:            private static PortalConfigData pci = null;
048:            private static PortalConfigurator pc = new PortalConfigurator();
049:            private static List components = null;
050:            private static Map portalServerToDelete = null;
051:            private static List searchServerToDelete = null;
052:            private static Map instances = null;
053:            private static Logger configLogger = null;
054:            private static PSConfigContext pcc = null;
055:            private static boolean unconfigureAll = false;
056:            private static final String FS = Platform.fs;
057:            private static OSTasks osTasks = null;
058:            private static ValidatePortalInputData validateinput = null;
059:
060:            public static void main(String[] args) {
061:                try {
062:                    // Initialize error code to success
063:                    int exitCode = 1;
064:                    //Initialise Portal Log Manager
065:                    new PortalLogManager().init("debug.com.sun.portal.fabric");
066:                    configLogger = PortalLogger
067:                            .getLogger(UnConfigurePortal.class);
068:
069:                    if (args == null || args.length < 1) {
070:                        System.err
071:                                .println("UnConfiguration Failed : Missing arguments. Please provide the config XML file location.");
072:                        // Exit current VM with error
073:                        System.exit(exitCode);
074:                    }
075:
076:                    try {
077:                        pci = new PortalConfigData(args[0]);
078:                    } catch (Exception e) {
079:                        configLogger.log(Level.SEVERE, "PSFB_CSPFC0074", e);
080:                        System.err
081:                                .println("Errors in processing input XML file");
082:                        // Exit current VM with error
083:                        System.exit(exitCode);
084:                    }
085:
086:                    String psconfigMode = pci.getPSConfigMode();
087:                    if (psconfigMode != null
088:                            && psconfigMode.equals("Unconfigure")) {
089:
090:                        unconfigureAll = pci.getIsUnconfigureAll().equals(
091:                                "true");
092:                        if (unconfigureAll) {
093:                            configLogger.log(Level.INFO, "PSFB_CSPFC0096");
094:                            // Ignore user inputs and unconfigure all Portal components
095:                            // administered by the PAS if UnconfigureAll flag is set to true
096:                            components = new ArrayList();
097:                            components.add("netletproxy");
098:                            components.add("rewriterproxy");
099:                            components.add("gateway");
100:                            components.add("portalserver");
101:                        } else {
102:
103:                            components = pci.getPSComponentsToUnConfigure();
104:                        }
105:
106:                        boolean bUnConfigureCacao = false;
107:                        try {
108:                            // call the preunconfig task
109:                            OSTasksFactory osTasksFactory = OSTasksFactory
110:                                    .getInstance();
111:                            osTasks = osTasksFactory.getOSTasks(pc
112:                                    .getPSConfigContext());
113:                            osTasks.preunconfig();
114:
115:                            // Get the PSConfigContext
116:                            pcc = new PSConfigContextImpl(
117:                                    AdminClientUtil.DEFAULT_DOMAIN);
118:                            System.out.println("Logs redirected to "
119:                                    + pcc.getPSDataDir()
120:                                    + "/logs/config/portal.fabric.0.0.log");
121:                            validateinput = new ValidatePortalInputData(pcc,
122:                                    pci);
123:                            configLogger.log(Level.INFO, "PSFB_CSPFC0004");
124:
125:                            String sAMAdminUID = pci.getAMAdmin();
126:                            String sAMAdminPassword = pci.getAMAdminPassword();
127:                            String sConfigHostName = pci.getConfigHostName();
128:
129:                            // Get the MBean Server connection
130:                            MBeanServerConnection msc = pc
131:                                    .getMbeanServerConnection(sAMAdminUID,
132:                                            sAMAdminPassword, sConfigHostName);
133:
134:                            // Unconfigure Netlet Proxy Component
135:                            if (components.contains("netletproxy")) {
136:
137:                                try {
138:
139:                                    //Get the Netlet Proxy instances to delete from the configuration file
140:                                    instances = pci
141:                                            .getSRAComponentInstancesToDelete(
142:                                                    "netletproxy",
143:                                                    sConfigHostName);
144:
145:                                    if (instances.isEmpty()) {
146:                                        if (unconfigureAll) {
147:                                            //Get the List of Netlet Proxy Instances to remove on all hosts
148:                                            instances = pc
149:                                                    .getListofSRAComponents(
150:                                                            msc, "nlproxy",
151:                                                            null);
152:                                        } else {
153:                                            //Get the List of Netlet Proxy Instances to remove on configuration host only
154:                                            instances = pc
155:                                                    .getListofSRAComponents(
156:                                                            msc, "nlproxy",
157:                                                            sConfigHostName);
158:                                        }
159:                                    }
160:
161:                                    if (!instances.isEmpty()) {
162:                                        configLogger.log(Level.INFO,
163:                                                "PSFB_CSPFC0098");
164:                                        pc.unconfigureSRAComponents(msc,
165:                                                "nlproxy", instances,
166:                                                sAMAdminUID, sAMAdminPassword);
167:                                        configLogger.log(Level.INFO,
168:                                                "PSFB_CSPFC0099");
169:                                    }
170:                                } catch (Exception e) {
171:                                    configLogger.log(Level.SEVERE,
172:                                            "PSFB_CSPFC0100", e);
173:                                    if (!instances.isEmpty()) {
174:                                        throw e;
175:                                    }
176:                                }
177:                            }
178:
179:                            // Unconfigure Rewriter Proxy Component
180:                            if (components.contains("rewriterproxy")) {
181:
182:                                try {
183:
184:                                    //Get the Rewriter Proxy instances to delete from the configuration file
185:                                    instances = pci
186:                                            .getSRAComponentInstancesToDelete(
187:                                                    "rewriterproxy",
188:                                                    sConfigHostName);
189:
190:                                    if (instances.isEmpty()) {
191:                                        if (unconfigureAll) {
192:                                            //Get the List of Rewriter Proxy Instances to remove on all hosts
193:                                            instances = pc
194:                                                    .getListofSRAComponents(
195:                                                            msc, "rwproxy",
196:                                                            null);
197:                                        } else {
198:                                            //Get the List of Rewriter Proxy Instances to remove on configuration host only
199:                                            instances = pc
200:                                                    .getListofSRAComponents(
201:                                                            msc, "rwproxy",
202:                                                            sConfigHostName);
203:                                        }
204:                                    }
205:
206:                                    if (!instances.isEmpty()) {
207:                                        configLogger.log(Level.INFO,
208:                                                "PSFB_CSPFC0101");
209:                                        pc.unconfigureSRAComponents(msc,
210:                                                "rwproxy", instances,
211:                                                sAMAdminUID, sAMAdminPassword);
212:                                        configLogger.log(Level.INFO,
213:                                                "PSFB_CSPFC0102");
214:                                    }
215:                                } catch (Exception e) {
216:                                    configLogger.log(Level.SEVERE,
217:                                            "PSFB_CSPFC0103", e);
218:                                    if (!instances.isEmpty()) {
219:                                        throw e;
220:                                    }
221:                                }
222:                            }
223:
224:                            // Unconfigure Gateway Component
225:                            if (components.contains("gateway")) {
226:
227:                                try {
228:                                    //Get the List of Gateway Instances to delete from the configuration file
229:                                    instances = pci
230:                                            .getSRAComponentInstancesToDelete(
231:                                                    "gateway", sConfigHostName);
232:                                    if (instances.isEmpty()) {
233:                                        if (unconfigureAll) {
234:                                            //Get the List of Gateway Instances to remove on all hosts
235:                                            instances = pc
236:                                                    .getListofSRAComponents(
237:                                                            msc, "gateway",
238:                                                            null);
239:                                        } else {
240:                                            //Get the List of Gateway Instances to remove on configuration host only
241:                                            instances = pc
242:                                                    .getListofSRAComponents(
243:                                                            msc, "gateway",
244:                                                            sConfigHostName);
245:                                        }
246:                                    }
247:
248:                                    if (!instances.isEmpty()) {
249:                                        configLogger.log(Level.INFO,
250:                                                "PSFB_CSPFC0104");
251:                                        pc.unconfigureSRAComponents(msc,
252:                                                "gateway", instances,
253:                                                sAMAdminUID, sAMAdminPassword);
254:                                        configLogger.log(Level.INFO,
255:                                                "PSFB_CSPFC0105");
256:                                    }
257:                                } catch (Exception e) {
258:                                    configLogger.log(Level.SEVERE,
259:                                            "PSFB_CSPFC0105", e);
260:                                    if (!instances.isEmpty()) {
261:                                        throw e;
262:                                    }
263:                                }
264:                            }
265:
266:                            // Unconfigure Portal Server component
267:                            if (components.contains("portalserver")) {
268:
269:                                configLogger.log(Level.INFO, "PSFB_CSPFC0249");
270:
271:                                if (unconfigureAll) {
272:
273:                                    // Unconfigure SRA only when UnconfigureAll flag is set to true.
274:                                    configLogger.log(Level.INFO,
275:                                            "PSFB_CSPFC0107");
276:
277:                                    //Remove the SRA services and SRA Rewriter Rulesets
278:                                    pc.removeSRAServicesFromAM(msc, pcc,
279:                                            sAMAdminPassword, pcc
280:                                                    .getDefaultOrganization());
281:                                    configLogger.log(Level.INFO,
282:                                            "PSFB_CSPFC0108");
283:
284:                                    //Delete Search Servers on all hosts
285:                                    searchServerToDelete = new ArrayList();
286:                                    pc.deleteSearchServer(msc,
287:                                            searchServerToDelete, null);
288:
289:                                    //Unconfigure Portal Software on all hosts
290:                                    portalServerToDelete = new HashMap();
291:                                    pc.unconfigurePortal(msc,
292:                                            portalServerToDelete,
293:                                            sConfigHostName, sAMAdminUID,
294:                                            sAMAdminPassword);
295:
296:                                    //Unconfigure Sample Portal
297:                                    SamplePortals samplePortals = new SamplePortals(
298:                                            pcc);
299:                                    samplePortals.unconfigure(sAMAdminPassword,
300:                                            pci.getLDAPUserPassword());
301:
302:                                    //Remove the Portal Data from AM
303:                                    configLogger.log(Level.INFO,
304:                                            "Closing MBean Server Connection");
305:                                    pc.closeMbeanServerConnection();
306:                                    configLogger.log(Level.INFO,
307:                                            "Getting MBean Server Connetion");
308:                                    msc = pc.getMbeanServerConnection(
309:                                            sAMAdminUID, sAMAdminPassword,
310:                                            sConfigHostName);
311:                                    pc.removePortalDomainServicesFromAM(msc,
312:                                            pcc, sAMAdminPassword, pcc
313:                                                    .getDefaultOrganization());
314:                                } else {
315:
316:                                    //Get the List of Search Servers to Delete
317:                                    configLogger.log(Level.INFO,
318:                                            "PSFB_CSPFC0109");
319:                                    searchServerToDelete = pci
320:                                            .getSearchSeversToDelete();
321:
322:                                    //Get the List of Portals Servers to Delete
323:                                    configLogger.log(Level.INFO,
324:                                            "PSFB_CSPFC0110");
325:                                    portalServerToDelete = pci
326:                                            .getPortalInstances();
327:
328:                                    //Delete Search Servers on local host
329:                                    pc.deleteSearchServer(msc,
330:                                            searchServerToDelete,
331:                                            sConfigHostName);
332:
333:                                    //Unconfigure Portal Software on local host
334:                                    pc.unconfigurePortal(msc,
335:                                            portalServerToDelete,
336:                                            sConfigHostName, sAMAdminUID,
337:                                            sAMAdminPassword);
338:                                }
339:
340:                                configLogger.log(Level.INFO, "PSFB_CSPFC0247");
341:                                pc.unconfigDerby(pcc, sConfigHostName);
342:                                configLogger.log(Level.INFO, "PSFB_CSPFC0248");
343:
344:                                configLogger.log(Level.INFO, "PSFB_CSPFC0250");
345:                            }
346:
347:                            // If all the Portal Servers components has been unconfigured
348:                            // on the local machine then unconfigure Cacao Server.
349:                            bUnConfigureCacao = !pc
350:                                    .isPortalComponentsConfigured(msc,
351:                                            sConfigHostName);
352:                            if (bUnConfigureCacao) {
353:                                // Remove the local host from the installedHosts
354:                                // list in the portal domain context.
355:                                PortalDomainContext pdc = AdminClientUtil
356:                                        .getPortalDomainContext();
357:                                List domainMBeanPath = Collections
358:                                        .singletonList(pdc.getID());
359:
360:                                HashSet installedHosts = new HashSet(
361:                                        pdc
362:                                                .getAttributeValues(
363:                                                        AdminClientUtil.PORTAL_DOMAIN_MBEAN_TYPE,
364:                                                        domainMBeanPath,
365:                                                        DomainAttributes.INSTALLED_HOSTS));
366:
367:                                installedHosts.remove(InetAddress
368:                                        .getLocalHost().getHostName());
369:
370:                                pdc
371:                                        .setAttributeValues(
372:                                                AdminClientUtil.PORTAL_DOMAIN_MBEAN_TYPE,
373:                                                domainMBeanPath,
374:                                                DomainAttributes.INSTALLED_HOSTS,
375:                                                installedHosts);
376:
377:                                configLogger.log(Level.INFO, "PSFB_CSPFC0251");
378:                                Cacao cc = new Cacao(pc.getPSConfigContext());
379:                                cc.unconfigureDomain();
380:                                configLogger.log(Level.INFO, "PSFB_CSPFC0252");
381:
382:                                // JES:MF related unconfiguration
383:                                String sJESMFBinDir = pcc.getJESMFBinDir();
384:                                if (sJESMFBinDir != null) {
385:
386:                                    List list = cc
387:                                            .get_data_com_sun_cmm_ps_module(true);
388:                                    String sTokenReplacedFile = cc
389:                                            .getTokenReplacedModuleFile(list);
390:                                    String[] sArgs = new String[] { "-u",
391:                                            sTokenReplacedFile };
392:                                    String sScriptPath = null;
393:                                    Platform.psConfDir = pcc.getPSConfigDir();
394:                                    sScriptPath = Platform
395:                                            .getCommand("mfwksetup");
396:                                    File fScript = new File(sScriptPath);
397:                                    sScriptPath = fScript.getCanonicalPath();
398:                                    String result1 = cc.execCommand(
399:                                            sScriptPath, sArgs, true);
400:                                    configLogger.log(Level.INFO, result1);
401:                                }
402:                                //The resetJavaFlags is commented out as a result of CR 6494953.
403:                                // Appserver is getting killed during stop cacao which is done
404:                                // while reseting of java-flags.
405:                                //cc.resetJavaFlags();
406:
407:                                pdc
408:                                        .removeResource(
409:                                                AdminClientUtil.PORTAL_DOMAIN_MBEAN_TYPE,
410:                                                Collections.singletonList(pdc
411:                                                        .getID()));
412:                            }
413:
414:                            exitCode = 0;
415:                        } catch (Exception e) {
416:                            //System.err.println("UnConfiguration Failed : " + e.getMessage());
417:                            System.err
418:                                    .println("UnConfiguration Failed : "
419:                                            + e.getMessage()
420:                                            + " Please check the fabric log file "
421:                                            + pcc.getPSDataDir()
422:                                            + "/logs/config/portal.fabric.0.0.log for more details.");
423:                            configLogger.log(Level.SEVERE, "PSFB_CSPFC0158", e);
424:                        } finally {
425:                            if (bUnConfigureCacao && (exitCode == 0)) {
426:                                FileUtil.deleteDir(pcc.getPSDataDir() + FS
427:                                        + "derby");
428:                                FileUtil.deleteDir(pcc.getPSDataDir() + FS
429:                                        + "portals");
430:                                FileUtil.deleteDir(pcc.getPSDataDir() + FS
431:                                        + "searchservers");
432:                                FileUtil.deleteDir(pcc.getPSDataDir() + FS
433:                                        + "tmp");
434:                                FileUtil.deleteDir(pcc.getPSConfigDir());
435:                            }
436:
437:                            if (exitCode == 0) {
438:                                try {
439:                                    configLogger.log(Level.INFO,
440:                                            "PSFB_CSPFC0227");
441:                                    pc.closeMbeanServerConnection();
442:                                    configLogger.log(Level.INFO,
443:                                            "PSFB_CSPFC0015");
444:                                } catch (Exception e) {
445:                                    configLogger.log(Level.INFO,
446:                                            "PSFB_CSPFC0261");
447:                                }
448:
449:                                System.err
450:                                        .println("UnConfiguration Successful");
451:                                osTasks.postunconfig();
452:                            }
453:                        }
454:                    } else if (psconfigMode != null) {
455:                        System.err
456:                                .println("UnConfiguration Failed : Invalid input file. XML has a \'"
457:                                        + pci.getPSConfigMode() + "\' Element.");
458:                    } else {
459:                        System.err
460:                                .println("UnConfiguration Failed : Invalid input file");
461:                    }
462:
463:                    // Exit the VM with the correct exit value
464:                    System.exit(exitCode);
465:                } catch (Exception e) {
466:                    System.err.println("Unconfiguration failed");
467:                    StringWriter sw = new StringWriter();
468:                    PrintWriter pw = new PrintWriter(sw);
469:                    e.printStackTrace(pw);
470:                    if (configLogger != null) {
471:                        configLogger.log(Level.SEVERE, sw.toString());
472:                    } else {
473:                        String msg = (e.getMessage() == null) ? "A serious Exception has occured."
474:                                : e.getMessage();
475:                        System.out.println("Unconfiguration Failed: " + msg);
476:
477:                    }
478:                    System.exit(1);
479:                }
480:            }
481:
482:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.