Source Code Cross Referenced for JESWS7Impl.java in  » Portal » Open-Portal » com » sun » portal » fabric » tasks » 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.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: JESWS7Impl.java,v 1.35.2.3 2007/05/04 21:27:10 nh119428 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.tasks;
014:
015:        import java.io.File;
016:        import java.io.FileWriter;
017:        import java.io.IOException;
018:        import java.io.BufferedReader;
019:        import java.io.FileReader;
020:        import java.net.*;
021:        import java.io.*;
022:
023:        import java.util.Map;
024:        import java.util.StringTokenizer;
025:        import java.util.logging.Level;
026:        import java.util.logging.Logger;
027:        import java.util.logging.LogRecord;
028:
029:        import org.jdom.Element;
030:
031:        import com.sun.portal.admin.common.context.PSConfigContext;
032:        import com.sun.portal.fabric.util.FileUtil;
033:        import com.sun.portal.fabric.util.os.OSTasks;
034:        import com.sun.portal.fabric.util.os.OSTasksFactory;
035:        import com.sun.portal.log.common.PortalLogger;
036:        import com.sun.portal.util.Platform;
037:
038:        public class JESWS7Impl extends WebContainerBase {
039:
040:            // WS 7 Instance related variables
041:            private String wcHomeDir = null;
042:            private String wcInstance = null;
043:            private String wcScheme = null;
044:
045:            // WS 7 Config Name is the attribute wcConfigName
046:            private String wcConfigName = null;
047:
048:            // WS 7 Admin Server related variables
049:            private String wcAdminSecure = null;
050:            private String wcAdminHost = null;
051:            private String wcAdminPort = null;
052:            private String wcAdminUser = null;
053:            private String wcAdminPassword = null;
054:            private String wcPlatform = null;
055:            private String wcDocRoot = null;
056:            private String passFilePath = null;
057:            private String wadm = null;
058:            private static Logger logger = PortalLogger
059:                    .getLogger(JESWS7Impl.class);
060:
061:            private static boolean isWinOS() {
062:                return Platform.name.equals("windows");
063:            }
064:
065:            /**
066:             * Constructor
067:             *
068:             * @param wcAttributes WebContainer Information as a Map
069:             * @param logger Logger
070:             */
071:            public JESWS7Impl(final Map wcAttributes) {
072:
073:                super (wcAttributes);
074:                execUtil.storeOutput(true);
075:                execUtil.storeError(true);
076:
077:                // Fetch the attributes form the input map and initialize the vars
078:                wcHomeDir = (String) wcAttributes
079:                        .get(WEB_CONTAINER_INSTALL_DIR);
080:                wcInstance = (String) wcAttributes.get(WEB_CONTAINER_INSTANCE);
081:                wcDocRoot = (String) wcAttributes.get(WEB_CONTAINER_DOC_ROOT);
082:                wcScheme = (String) wcAttributes.get(SCHEME);
083:
084:                wcConfigName = (String) wcAttributes.get(WEB_CONTAINER_DOMAIN);
085:
086:                wcAdminSecure = (String) wcAttributes
087:                        .get(WEB_CONTAINER_ADMIN_SCHEME);
088:                wcAdminHost = (String) wcAttributes
089:                        .get(WEB_CONTAINER_ADMIN_HOST);
090:                wcAdminPort = (String) wcAttributes
091:                        .get(WEB_CONTAINER_ADMIN_PORT);
092:                wcAdminUser = (String) wcAttributes
093:                        .get(WEB_CONTAINER_ADMIN_UID);
094:                wcAdminPassword = (String) wcAttributes
095:                        .get(WEB_CONTAINER_ADMIN_PASSWORD);
096:
097:                if (wcAdminSecure.equalsIgnoreCase("https")) {
098:                    wcAdminSecure = "true";
099:                } else {
100:                    wcAdminSecure = "false";
101:                }
102:
103:                // Set the path to the wadm command
104:                wadm = wcHomeDir + fs + "bin" + fs
105:                        + Platform.getCommand("wadm");
106:                // create password file
107:                createPasswordFile();
108:
109:            }
110:
111:            // args should never be a null
112:            private void runwadm(String[] args) throws ConfigurationException {
113:
114:                // Execute wadm CLI with the args
115:                int iRetCode = execUtil.exec(wadm, args);
116:                // The command failed
117:                if (iRetCode != 0) {
118:                    // Get the error from the Runtime
119:                    String sError = execUtil.getError();
120:                    if ((sError == null) || sError.trim().equals("")) {
121:                        StringBuffer err = new StringBuffer("Command Failed: ");
122:                        err.append(wadm);
123:
124:                        // Assuming args is never null get the wadm command thats being
125:                        // executed to put into the Exception message
126:                        for (int i = 0; i < args.length; i++) {
127:                            err.append(" ").append(args[i]);
128:                        }
129:
130:                        sError = err.toString();
131:                    } else if (sError.indexOf("ADMIN3306") != -1) {
132:                        logger
133:                                .log(Level.SEVERE, "PSFB_CSPFT0012",
134:                                        new String[] { getCommand(wadm, args),
135:                                                sError });
136:                        return;
137:                    }
138:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
139:                            getCommand(wadm, args), sError });
140:                    // Throw configuration Exception
141:                    throw new ConfigurationException(sError);
142:                }
143:            }
144:
145:            private void createPasswordFile() {
146:
147:                try {
148:                    File passwdFile = File.createTempFile(FileUtil
149:                            .getRandomDirName(), "");
150:                    // Initialize the value of the variable to be used in other methods
151:                    passFilePath = passwdFile.getAbsolutePath();
152:                    FileWriter fwriter = new FileWriter(passFilePath);
153:                    String content = "wadm_password=" + wcAdminPassword + nl;
154:                    fwriter.write(content);
155:                    fwriter.close();
156:                    execUtil
157:                            .exec("chmod", new String[] { "600", passFilePath });
158:                } catch (IOException ioe) {
159:                    if (logger.isLoggable(Level.SEVERE)) {
160:                        LogRecord record = new LogRecord(Level.SEVERE,
161:                                "PSFB_CSPFT0025");
162:                        record.setThrown(ioe);
163:                        record.setLoggerName(logger.getName());
164:                        logger.log(record);
165:                    }
166:                }
167:            }
168:
169:            private String getClasspathSuffix() {
170:                String[] args = { "get-jvm-prop", "--user=" + wcAdminUser,
171:                        "--password-file=" + passFilePath,
172:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
173:                        "--ssl=" + wcAdminSecure, "--config=" + wcConfigName,
174:                        "class-path-suffix" };
175:                execUtil.storeOutput(true);
176:                execUtil.exec(wadm, args);
177:                String cp = execUtil.getOutput();
178:                if (cp != null) {
179:                    cp.trim();
180:                    cp = cp.replaceAll("\n", "");
181:                }
182:                return cp;
183:            }
184:
185:            private String getNativeLibPath() {
186:                String[] args = { "get-jvm-prop", "--user=" + wcAdminUser,
187:                        "--password-file=" + passFilePath,
188:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
189:                        "--ssl=" + wcAdminSecure, "--config=" + wcConfigName,
190:                        "native-library-path-prefix" };
191:                execUtil.storeOutput(true);
192:                execUtil.exec(wadm, args);
193:                String np = execUtil.getOutput();
194:                if (np != null) {
195:                    np.trim();
196:                    np = np.replaceAll("\n", "");
197:                }
198:                return np;
199:            }
200:
201:            public void postDeploy() throws ConfigurationException {
202:
203:                // Just deploy the modified config onto the instance using the 
204:                // wadm deploy-config command.
205:                String[] args = { "deploy-config", "--user=" + wcAdminUser,
206:                        "--password-file=" + passFilePath,
207:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
208:                        "--ssl=" + wcAdminSecure, wcConfigName };
209:                int iRetCode = execUtil.exec(wadm, args);
210:                // The command failed. Check if command failed because of manual config chamges.
211:                if (iRetCode != 0) {
212:                    // Get the error from the Runtime
213:                    String sError = execUtil.getError();
214:                    if ((sError != null) && sError.indexOf("ADMIN3658") != -1) {
215:                        logger
216:                                .log(Level.SEVERE, "PSFB_CSPFT0012",
217:                                        new String[] { getCommand(wadm, args),
218:                                                sError });
219:                        // Throw configuration Exception
220:                        throw new ConfigurationException(sError);
221:                    }
222:                }
223:                return;
224:            }
225:
226:            public void start() throws ConfigurationException {
227:
228:                logger.log(Level.INFO, "PSFB_CSPFT0103");
229:
230:                // Set force=true to ensure that manual edits to the config on the 
231:                // instance do not cause a failure for the deploy-config operation
232:                String[] deployConfigArgs = { "deploy-config",
233:                        "--user=" + wcAdminUser,
234:                        "--password-file=" + passFilePath,
235:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
236:                        "--ssl=" + wcAdminSecure, "--force=true", wcConfigName };
237:                execUtil.exec(wadm, deployConfigArgs);
238:
239:                // Invoke the start operation on the server instance
240:                String[] args = { "start-instance", "--user=" + wcAdminUser,
241:                        "--password-file=" + passFilePath,
242:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
243:                        "--ssl=" + wcAdminSecure, "--config=" + wcConfigName };
244:                //runwadm(args);
245:                execUtil.exec(wadm, args);
246:                return;
247:            }
248:
249:            public void stop() throws ConfigurationException {
250:
251:                logger.log(Level.INFO, "PSFB_CSPFT0102");
252:                String[] args = { "stop-instance", "--user=" + wcAdminUser,
253:                        "--password-file=" + passFilePath,
254:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
255:                        "--ssl=" + wcAdminSecure, "--config=" + wcConfigName };
256:                runwadm(args);
257:            }
258:
259:            /**
260:             * Deploys the WAR file on to the webcontainer instance
261:             *
262:             * @param warFile WAR file including full path
263:             * @param uri Deployment URI
264:             */
265:            public void deploy(String warFile, String uri)
266:                    throws ConfigurationException {
267:
268:                justDeploy(warFile, uri);
269:                // Apply config changes to ws instance
270:                postDeploy();
271:            }
272:
273:            public void justDeploy(String warFile, String uri)
274:                    throws ConfigurationException {
275:
276:                String[] args = { "add-webapp", "--user=" + wcAdminUser,
277:                        "--password-file=" + passFilePath,
278:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
279:                        "--ssl=" + wcAdminSecure, "--config=" + wcConfigName,
280:                        "--vs=" + wcInstance, "--uri=" + uri, warFile };
281:
282:                runwadm(args);
283:            }
284:
285:            /**
286:             * Undeploys the WAR file from the webcontainer instance
287:             *
288:             * @param uri Deployment URI
289:             */
290:            public void undeploy(String uri) throws ConfigurationException {
291:
292:                String[] args = { "remove-webapp", "--user=" + wcAdminUser,
293:                        "--password-file=" + passFilePath,
294:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
295:                        "--ssl=" + wcAdminSecure, "--config=" + wcConfigName,
296:                        "--vs=" + wcInstance, "--uri=" + uri };
297:                runwadm(args);
298:                // Apply config changes to ws instance
299:                postDeploy();
300:            }
301:
302:            public boolean appendClasspath(String classpath) {
303:
304:                String cp = getClasspathSuffix();
305:                if (classpath != null) {
306:                    // Append the classpath entries given in the params to the server
307:                    // classpath suffix            
308:                    if (cp == null || cp.equals("")) {
309:                        // If emtpy or null set what is passed
310:                        cp = classpath;
311:                    } else {
312:                        // Else append
313:                        cp = getMergedClassPath(classpath, cp);
314:                    }
315:
316:                    String[] args = { "set-jvm-prop", "--user=" + wcAdminUser,
317:                            "--password-file=" + passFilePath,
318:                            "--host=" + wcAdminHost, "--port=" + wcAdminPort,
319:                            "--config=" + wcConfigName,
320:                            "--ssl=" + wcAdminSecure, "class-path-suffix=" + cp };
321:                    args[args.length - 1] = "class-path-suffix=" + cp;
322:                    File wsClspthFile = null;
323:                    try {
324:                        File tmpFile = new File("tmp.cls");
325:                        String s1;
326:                        StringBuffer tsb = new StringBuffer();
327:                        FileWriter tfw = new FileWriter(tmpFile);
328:                        tfw.write(args[args.length - 1]);
329:                        tfw.close();
330:                        BufferedReader tbr = new BufferedReader(new FileReader(
331:                                tmpFile));
332:                        while ((s1 = tbr.readLine()) != null) {
333:                            tsb.append(s1);
334:                        }
335:                        tbr.close();
336:                        tmpFile.delete();
337:                        args[args.length - 1] = tsb.toString().trim()
338:                                .replaceAll(";", "\\\\;");
339:                        wsClspthFile = File.createTempFile("wsclasspath",
340:                                ".cls");
341:                        String wsClspthName = wsClspthFile.getAbsolutePath();
342:                        FileWriter fwriter = new FileWriter(wsClspthFile);
343:                        System.out.println(wsClspthName);
344:                        for (int i = 0; i < args.length; i++) {
345:                            fwriter.write(args[i] + " ");
346:                        }
347:                        fwriter.close();
348:
349:                        String[] args1 = { "--user=" + wcAdminUser,
350:                                "--password-file=" + passFilePath,
351:                                "--host=" + wcAdminHost,
352:                                "--port=" + wcAdminPort,
353:                                "--commands-file=" + wsClspthFile };
354:                        if (execUtil.exec(wadm, args1) == 0) {
355:                            wsClspthFile.delete();
356:                            return true;
357:                        } else {
358:                            return false;
359:                        }
360:                    } catch (IOException e) {
361:                        return false;
362:                    }
363:                }
364:
365:                return false;
366:
367:            }
368:
369:            public void DeployConfigforUpgrade() {
370:                //For upgrade we need to use --force and --restart also.
371:                // Just deploy the modified config onto the instance using the 
372:                // wadm deploy-config command.
373:                String[] args = { "deploy-config", "--user=" + wcAdminUser,
374:                        "--password-file=" + passFilePath,
375:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
376:                        "--ssl=" + wcAdminSecure, "--force", "--restart",
377:                        wcConfigName };
378:                execUtil.exec(wadm, args);
379:                return;
380:            }
381:
382:            public void deployConfigRestart() {
383:                //For upgrade we need to use --force and --restart also.
384:                // Just deploy the modified config onto the instance using the
385:                // wadm deploy-config command.
386:                String[] args = { "deploy-config", "--user=" + wcAdminUser,
387:                        "--password-file=" + passFilePath,
388:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
389:                        "--ssl=" + wcAdminSecure, "--restart", wcConfigName };
390:
391:                execUtil.exec(wadm, args);
392:                return;
393:            }
394:
395:            public boolean removeClasspath(String classpath) {
396:
397:                boolean bRet = false;
398:                String cp = getClasspathSuffix();
399:                if (cp != null && !cp.equals("")) {
400:                    // Remove the classpath entries given in the params from the 
401:                    // Server classpath suffix if they exist
402:                    int startIndex1 = cp.indexOf(classpath);
403:                    if (startIndex1 >= 0) {
404:                        cp = cp.replaceAll(classpath, "");
405:                        bRet = true;
406:                    } else if (isPortalConfigured()) {
407:                        String[] sPaths = classpath.split(File.pathSeparator);
408:                        for (int i = 0; i < sPaths.length; i++) {
409:                            cp = cp.replaceAll(File.pathSeparator + sPaths[i]
410:                                    + File.pathSeparator, File.pathSeparator);
411:                        }
412:                        bRet = true;
413:                    }
414:                    if (bRet) {
415:                        String sCpsPattern = File.pathSeparator + "["
416:                                + File.pathSeparator + "]*";
417:                        cp = cp.replaceAll(sCpsPattern, File.pathSeparator);
418:
419:                        String[] args = { "set-jvm-prop",
420:                                "--user=" + wcAdminUser,
421:                                "--password-file=" + passFilePath,
422:                                "--host=" + wcAdminHost,
423:                                "--port=" + wcAdminPort,
424:                                "--config=" + wcConfigName,
425:                                "--ssl=" + wcAdminSecure,
426:                                "class-path-suffix=" + cp };
427:                        if (execUtil.exec(wadm, args) == 0) {
428:                            return true;
429:                        }
430:                    }
431:                }
432:                return false;
433:            }
434:
435:            public boolean addJVMOption(String option, String value) {
436:                if (option != null) {
437:                    StringBuffer optArg = new StringBuffer();
438:                    if (!option.startsWith("-")) {
439:                        optArg.append("-D" + option);
440:                    } else {
441:                        optArg.append(option);
442:                    }
443:                    // If the value param is not null that means the JVM option is of
444:                    // type -Dabc=xyz or -Xabc=xyz
445:                    if (value != null && !value.equals("")) {
446:                        optArg.append("=").append(value);
447:                    }
448:                    String[] args = { "create-jvm-options",
449:                            "--user=" + wcAdminUser,
450:                            "--password-file=" + passFilePath,
451:                            "--host=" + wcAdminHost, "--port=" + wcAdminPort,
452:                            "--ssl=" + wcAdminSecure,
453:                            "--config=" + wcConfigName, "--", optArg.toString() };
454:                    if (execUtil.exec(wadm, args) != 0) {
455:                        return false;
456:                    }
457:                }
458:                return true;
459:            }
460:
461:            public boolean removeJVMOption(String option, String value) {
462:
463:                if (option != null) {
464:                    StringBuffer optArg = new StringBuffer();
465:                    if (!option.startsWith("-")) {
466:                        optArg.append("-D" + option);
467:                    } else {
468:                        optArg.append(option);
469:                    }
470:                    // If the value param is not null that means the JVM option is of
471:                    // type -Dabc=xyz or -Xabc=xyz
472:                    if (value != null && !value.equals("")) {
473:                        optArg.append("=").append(value);
474:                    }
475:                    String[] args = { "delete-jvm-options",
476:                            "--user=" + wcAdminUser,
477:                            "--password-file=" + passFilePath,
478:                            "--host=" + wcAdminHost, "--port=" + wcAdminPort,
479:                            "--ssl=" + wcAdminSecure,
480:                            "--config=" + wcConfigName, optArg.toString() };
481:                    if (execUtil.exec(wadm, args) != 0) {
482:                        return false;
483:                    }
484:                }
485:                return true;
486:            }
487:
488:            public boolean doesJVMOptionExist(String option) {
489:                // Init return code
490:                boolean exists = false;
491:                String[] args = { "list-jvm-options", "--user=" + wcAdminUser,
492:                        "--password-file=" + passFilePath,
493:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
494:                        "--ssl=" + wcAdminSecure, "--config=" + wcConfigName, };
495:                // Set exec util to store the output
496:                execUtil.storeOutput(true);
497:                execUtil.exec(wadm, args);
498:                String output = execUtil.getOutput();
499:                // If output string contains the param then return true
500:                if (output != null && output.indexOf(option) > 0) {
501:                    exists = true;
502:                }
503:
504:                return exists;
505:            }
506:
507:            public void configResource(Element root, String derbyHost,
508:                    String derbyPort, String databaseName, String poolName) {
509:
510:                String[] args = {
511:                        "create-jdbc-resource",
512:                        "--user=" + wcAdminUser,
513:                        "--password-file=" + passFilePath,
514:                        "--host=" + wcAdminHost,
515:                        "--port=" + wcAdminPort,
516:                        "--config=" + wcConfigName,
517:                        "--datasource-class=org.apache.derby.jdbc.ClientConnectionPoolDataSource",
518:                        "--min-connections=8", "--max-connections=32",
519:                        "--idle-timeout=300", "--wait-timeout=10",
520:                        "--ssl=" + wcAdminSecure,
521:                        root.getAttributeValue("name") };
522:                execUtil.exec(wadm, args);
523:
524:                String[] args1 = { "create-jdbc-resource-userprop",
525:                        "--user=" + wcAdminUser,
526:                        "--password-file=" + passFilePath,
527:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
528:                        "--config=" + wcConfigName, "--jndi-name",
529:                        root.getAttributeValue("name"),
530:                        "--ssl=" + wcAdminSecure, "serverName=" + derbyHost,
531:                        "portNumber=" + derbyPort,
532:                        "User=" + root.getAttributeValue("username"),
533:                        "Password=" + root.getAttributeValue("password"),
534:                        "databaseName=" + databaseName };
535:                execUtil.exec(wadm, args1);
536:
537:            }
538:
539:            public void unConfigResource(String jndiName, String poolName) {
540:
541:                String[] args = { "delete-jdbc-resource",
542:                        "--user=" + wcAdminUser,
543:                        "--password-file=" + passFilePath,
544:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
545:                        "--config=" + wcConfigName, "--ssl=" + wcAdminSecure,
546:                        jndiName };
547:                execUtil.exec(wadm, args);
548:            }
549:
550:            /* This method returns the platform config property from WS7.
551:               This property is used to determine if WS7 instance is running in 64 bit mode or
552:               32 bit mode.
553:             */
554:            public String getPlatform() {
555:
556:                String[] args = { "get-config-prop", "--user=" + wcAdminUser,
557:                        "--password-file=" + passFilePath,
558:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
559:                        "--config=" + wcConfigName, "--ssl=" + wcAdminSecure,
560:                        "platform" };
561:                execUtil.storeOutput(true);
562:                execUtil.exec(wadm, args);
563:                return execUtil.getOutput();
564:            }
565:
566:            public boolean setNativeLibraryPath(String path) {
567:
568:                String np = getNativeLibPath();
569:                if (path != null) {
570:
571:                    //Check if WS instance is 64 bit
572:                    if (wcPlatform == null) {
573:                        wcPlatform = getPlatform();
574:                    }
575:                    if (wcPlatform != null && wcPlatform.indexOf("64") != -1) {
576:                        if (FileUtil.directoryExists(path + "/sparcv9")) {
577:                            path = path + "/sparcv9";
578:                        } else if (FileUtil.directoryExists(path + "/amd64")) {
579:                            path = path + "/amd64";
580:                        }
581:                    }
582:                    if (np == null || np.equals("")) {
583:                        // If emtpy or null set what is passed
584:                        np = path;
585:                    } else {
586:                        // Else append
587:                        np = np + File.pathSeparator + path;
588:                    }
589:                    String[] args = { "set-jvm-prop", "--user=" + wcAdminUser,
590:                            "--password-file=" + passFilePath,
591:                            "--host=" + wcAdminHost, "--port=" + wcAdminPort,
592:                            "--ssl=" + wcAdminSecure,
593:                            "--config=" + wcConfigName,
594:                            "native-library-path-prefix=" + np };
595:                    if (execUtil.exec(wadm, args) != 0) {
596:                        return false;
597:                    }
598:                }
599:
600:                return true;
601:            }
602:
603:            public boolean removeNativeLibraryPath(String path) {
604:                String curLibPath = getNativeLibPath();
605:                if (curLibPath != null) {
606:                    curLibPath = curLibPath.replaceAll(path, "");
607:                    String[] args = { "set-jvm-prop", "--user=" + wcAdminUser,
608:                            "--password-file=" + passFilePath,
609:                            "--host=" + wcAdminHost, "--port=" + wcAdminPort,
610:                            "--ssl=" + wcAdminSecure,
611:                            "--config=" + wcConfigName,
612:                            "native-library-path-prefix=" + curLibPath };
613:                    if (execUtil.exec(wadm, args) == 0) {
614:                        return true;
615:                    }
616:                }
617:                return false;
618:            }
619:
620:            /**
621:             * Configures the WebContainer with the classpath
622:             * settings, JVM options and other settings needed
623:             * for Identity Server SDK
624:             */
625:            public void doIdentitySDKConfig(final PSConfigContext configContext)
626:                    throws ConfigurationException {
627:
628:                String cp = getClasspathSuffix();
629:                // Check if the classpath suffix contains the am_sdk.jar to verify
630:                // if the AM Server/SDK is already configured on this webserver
631:                // instance
632:                if (cp.indexOf("am_sdk.jar") > 0) {
633:                    logger.log(Level.INFO, "PSFB_CSPFT0319");
634:                    return;
635:                }
636:
637:                logger.log(Level.INFO, "PSFB_CSPFT0320");
638:
639:                String host = (String) wcAttributes.get(HOST);
640:                String port = (String) wcAttributes.get(PORT);
641:                String amProductLoc = configContext.getISBaseDir();
642:                String amConfigDir = configContext.getISConfigDir();
643:                String psDataDir = configContext.getPSDataDir();
644:
645:                int index = amProductLoc.lastIndexOf(fs);
646:                String amProductDir = amProductLoc.substring(index + 1);
647:                String amBaseDir = amProductLoc.substring(0, index);
648:
649:                // Get WS data dir using wadm command
650:                String wcDataHome = getWSInstanceRoot();
651:
652:                StringBuffer fileData = new StringBuffer();
653:                fileData
654:                        .append("BASEDIR=" + amBaseDir + nl)
655:                        .append("PRODUCT_DIR=" + amProductDir + nl)
656:                        .append("CONFIG_DIR=" + amConfigDir + nl)
657:                        .append("WS_INSTANCE=https-" + wcConfigName + nl)
658:                        .append("WS_HOME=" + wcDataHome + nl)
659:                        .append("WS_PROTOCOL=" + wcScheme + nl)
660:                        .append("WS_HOST=" + host + nl)
661:                        .append("WS_PORT=" + port + nl)
662:                        .append("WS_ADMINPORT=" + wcAdminPort + nl)
663:                        .append("WS_ADMIN=" + wcAdminUser + nl)
664:                        .append("WS_ADMINPASSWD=" + wcAdminPassword + nl)
665:                        .append("DEPLOY_LEVEL=7" + nl)
666:                        .append("JAVA_HOME=" + configContext.getJavaHome() + nl)
667:                        .append("WEB_CONTAINER=WS" + nl);
668:
669:                String amSilentName = psDataDir + fs + "tmp" + fs
670:                        + "amsilent_ps." + FileUtil.getRandomDirName();
671:                File amSilentFile = new File(amSilentName);
672:                try {
673:                    FileWriter fwriter = new FileWriter(amSilentFile);
674:                    fwriter.write(fileData.toString());
675:                    fwriter.close();
676:                } catch (IOException e) {
677:                    logger.log(Level.SEVERE, "PSFB_CSPFT0016");
678:                    amSilentFile.delete();
679:                    return;
680:                }
681:
682:                logger.log(Level.FINEST, "PSFB_CSPFT0018", new String[] {});
683:                String amconfig = amProductLoc + fs + "bin" + fs + "amconfig";
684:                String args[] = { "-s", amSilentName };
685:                if (execUtil.exec(amconfig, args) != 0) {
686:                    logger.log(Level.SEVERE, "PSFB_CSPFT0019", new String[] {
687:                            wcType, wcConfigName });
688:                } else {
689:                    logger.log(Level.INFO, "PSFB_CSPFT0020", new String[] {
690:                            wcType, wcConfigName });
691:                }
692:
693:                // Delete the sample temp file to ensure that no passwords are leftout
694:                amSilentFile.delete();
695:            }
696:
697:            /**
698:             * Validate web container data
699:             */
700:            public void validate() throws ValidationException {
701:
702:                if (!checkDirExists(WEB_CONTAINER_INSTALL_DIR, wcHomeDir)) {
703:                    throw new ValidationException(
704:                            "Invalid Install Directory = " + wcHomeDir);
705:                }
706:
707:                if (!wadmExists(wcHomeDir)) {
708:                    throw new ValidationException(
709:                            "wadm not found in "
710:                                    + wcHomeDir
711:                                    + fs
712:                                    + "bin directory. Please check the value of WebContainerInstallDir");
713:                }
714:
715:                // This will not be needed after WS 7 fixes the add-webapp command
716:                if (!checkNotNullOrEmpty(WEB_CONTAINER_INSTANCE, wcInstance)) {
717:                    throw new ValidationException("Invalid Instance Name");
718:                }
719:
720:                if (!checkNotNullOrEmpty(WEB_CONTAINER_DOMAIN, wcConfigName)) {
721:
722:                    throw new ValidationException("Invalid Domain Name");
723:                }
724:
725:                if (!checkNotNull(WEB_CONTAINER_ADMIN_UID, wcAdminUser)) {
726:
727:                    throw new ValidationException("Invalid Admin User");
728:                }
729:
730:                if (!checkNotNull(WEB_CONTAINER_ADMIN_PASSWORD,
731:                        wcAdminPassword, true)) {
732:                    throw new ValidationException("Invalid Admin Password");
733:                }
734:
735:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_SCHEME,
736:                        wcAdminSecure)) {
737:                    throw new ValidationException("Invalid Admin Scheme");
738:                }
739:
740:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_HOST, wcAdminHost)) {
741:                    throw new ValidationException("Invalid Admin Host");
742:                }
743:
744:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_PORT, wcAdminPort)) {
745:                    throw new ValidationException("Invalid Admin Port");
746:                }
747:
748:                // Validate instance name
749:                if (!validateInstanceName(wcInstance)) {
750:                    throw new ValidationException("Invalid Instance Name");
751:                }
752:
753:                // Validate Instant host & port of admin server
754:                if (!validateInstanceHostNamePort(wcAdminHost, wcAdminPort)) {
755:                    throw new ValidationException(
756:                            "Invalid Instance Admin Server Host/Port");
757:                }
758:
759:                // Validate Instant host & port
760:                String host = (String) wcAttributes.get(HOST);
761:                String port = (String) wcAttributes.get(PORT);
762:                if (!validateInstanceHostNamePort(host, port)) {
763:                    throw new ValidationException("Invalid Instance Host/Port");
764:                }
765:
766:                // Validate if the wadm cli exists in the path given as input
767:                File cliFile = new File(wadm);
768:                if (!cliFile.exists()) {
769:                    throw new ValidationException("wadm Command not found at :"
770:                            + wadm);
771:                }
772:
773:                /* Validating if WS ports, passwords and if WS is running by getting a value that
774:                 is sure to be set. In this case server classpath
775:                 */
776:                if (wcPlatform == null) {
777:                    wcPlatform = getPlatform();
778:                }
779:                String sFieldName = "Platform";
780:                if (!checkNotNullOrEmpty(sFieldName, wcPlatform)) {
781:
782:                    throw new ValidationException(
783:                            "Could not fetch the value of "
784:                                    + sFieldName
785:                                    + ". Please check wadm username and password");
786:                }
787:                if ((wcPlatform.indexOf("64") == -1)
788:                        && (wcPlatform.indexOf("32") == -1)) {
789:                    throw new ValidationException(
790:                            "Could not fetch the value of "
791:                                    + sFieldName
792:                                    + ". Please check wadm username and password");
793:                }
794:            }
795:
796:            public void postValidationInit() throws ConfigurationException {
797:                // Nothing to init. If any variables need to be initialized after the
798:                // validation the code goes in here
799:            }
800:
801:            public boolean isPortalConfigured() {
802:                String cp = getClasspathSuffix();
803:                // Check if classpath contains the portal jar file
804:                if (cp != null && cp.indexOf(PORTAL_TEST_JAR) > -1) {
805:                    logger.log(Level.INFO, "PSFB_CSPFT0041");
806:                    return true;
807:                } else {
808:                    return false;
809:                }
810:            }
811:
812:            public void createSymbolicLinks(final PSConfigContext configContext) {
813:
814:                //Creating links for help, voice to webcontainer docs
815:                try {
816:                    String docsDir = wcDocRoot;
817:                    String helpDir = docsDir + fs + "online_help" + fs
818:                            + "docs_en_US";
819:                    String psHelpDir = configContext.getPSBaseDir() + fs
820:                            + "docs" + fs + "public_html" + fs + "online_help"
821:                            + fs + "docs_en_US";
822:                    String voiceDir = configContext.getPSBaseDir() + fs
823:                            + "export" + fs + "voice";
824:
825:                    OSTasks osTasks = OSTasksFactory.getOSTasks(configContext);
826:                    osTasks.createSymbolicLink(voiceDir, docsDir);
827:                    osTasks.createSymbolicLink(psHelpDir + fs + "ps", helpDir);
828:                    osTasks.createSymbolicLink(psHelpDir + fs + "ma", helpDir);
829:                } catch (Exception e) {
830:                    logger.log(Level.SEVERE, "PSFB_CSPFT0040", e);
831:                }
832:            }
833:
834:            public void deleteSymbolicLinks(final PSConfigContext configContext) {
835:
836:                try {
837:                    String docsDir = wcDocRoot;
838:                    String helpDir = docsDir + fs + "online_help" + fs
839:                            + "docs_en_US";
840:                    OSTasks osTasks = OSTasksFactory.getOSTasks(configContext);
841:                    osTasks.removeSymbolicLink(docsDir + fs + "voice");
842:                    osTasks.removeSymbolicLink(helpDir + fs + "ps");
843:                    osTasks.removeSymbolicLink(helpDir + fs + "ma");
844:                } catch (Exception e) {
845:                    logger.log(Level.SEVERE, "PSFB_CSPFT0038", e);
846:                }
847:            }
848:
849:            public void doMiscTasks(PSConfigContext configContext) {
850:                // Set the JVM turning options
851:                doJVMMemorySettings();
852:                logger.log(Level.INFO, "PSFB_CSPFT0103");
853:            }
854:
855:            public void undoMiscTasks(PSConfigContext configContext) {
856:                // Undo JVM tuning options
857:                removeJVMOption("-Xms512M -Xmx768M -Xss128k", null);
858:                removeJVMOption(
859:                        "-XX:NewSize=168M -XX:MaxNewSize=168M -XX:PermSize=192M -XX:MaxPermSize=192M -XX:SoftRefLRUPolicyMSPerMB=0",
860:                        null);
861:                removeJVMOption("-XX:+DisableExplicitGC", null);
862:                //removeJVMOption("-XX:+DisableExplicitGC -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintClassHistogram", null);
863:                //doing the deploy config
864:                try {
865:                    deployConfigRestart();
866:                } catch (Exception e) {
867:                    logger.log(Level.SEVERE, "PSFB_CSPFT0038", e);
868:                }
869:            }
870:
871:            private boolean doWinJVMMemorySettings() {
872:                removeJVMOption("-Xms128m -Xmx256m", null);
873:                addJVMOption("-Xms128M -Xmx256M -Xss128k", null);
874:                addJVMOption(
875:                        "-XX:NewSize=100M -XX:MaxNewSize=100M -XX:PermSize=120M -XX:MaxPermSize=120M -XX:SoftRefLRUPolicyMSPerMB=0",
876:                        null);
877:                addJVMOption("-XX:+DisableExplicitGC", null);
878:                return true;
879:            }
880:
881:            /**
882:             *  Do required container memory settings if the appserver vm setting are the default
883:             *  i.e. if -Xmx256m setting is found
884:             *  Note: A webserver restart  is required before these settings come into play.
885:             *  The calling class should decide whether to do the restart
886:             */
887:            public boolean doJVMMemorySettings() {
888:                if (isWinOS()) {
889:                    doWinJVMMemorySettings();
890:                } else {
891:                    removeJVMOption("-Xms128m -Xmx256m", null);
892:                    if (wcPlatform == null) {
893:                        wcPlatform = getPlatform();
894:                    }
895:                    if ((wcPlatform != null)
896:                            && (wcPlatform.indexOf("64") == -1)) {
897:                        addJVMOption("-Xms512M -Xmx768M -Xss128k", null);
898:                    } else {
899:                        addJVMOption("-Xms512M -Xmx768M", null);
900:                    }
901:                    addJVMOption(
902:                            "-XX:NewSize=168M -XX:MaxNewSize=168M -XX:PermSize=192M -XX:MaxPermSize=192M -XX:SoftRefLRUPolicyMSPerMB=0",
903:                            null);
904:                    addJVMOption("-XX:+DisableExplicitGC", null);
905:                }
906:                return true;
907:            }
908:
909:            public String getWSInstanceRoot() {
910:                String[] args = { "get-admin-prop", "--user=" + wcAdminUser,
911:                        "--password-file=" + passFilePath,
912:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
913:                        "--ssl=" + wcAdminSecure, "instance-root" };
914:                execUtil.storeOutput(true);
915:                execUtil.exec(wadm, args);
916:                return execUtil.getOutput();
917:            }
918:
919:            protected void finalize() throws Throwable {
920:
921:                super .finalize();
922:
923:                if ((passFilePath != null) && !passFilePath.trim().equals("")) {
924:
925:                    File fAdminPasswordFile = new File(passFilePath);
926:                    if (fAdminPasswordFile.isFile()) {
927:
928:                        fAdminPasswordFile.delete();
929:                    }
930:                }
931:            }
932:
933:            private boolean wadmExists(String wcInstallDir) {
934:                String wadm = null;
935:                wadm = wcInstallDir + fs + "bin" + fs
936:                        + Platform.getCommand("wadm");
937:                if (FileUtil.fileExists(wadm)) {
938:                    return true;
939:                } else {
940:                    return false;
941:                }
942:            }
943:
944:            private boolean validateInstanceName(final String wsInstanceName) {
945:                String[] args = { "list-configs", "--user=" + wcAdminUser,
946:                        "--password-file=" + passFilePath,
947:                        "--host=" + wcAdminHost, "--port=" + wcAdminPort,
948:                        "--ssl=" + wcAdminSecure, };
949:                execUtil.storeOutput(true);
950:                execUtil.exec(wadm, args);
951:                String configNames = execUtil.getOutput();
952:                StringTokenizer tokenizer = new StringTokenizer(configNames, nl);
953:                boolean validInstance = false;
954:
955:                while (tokenizer.hasMoreTokens()) {
956:                    String token = tokenizer.nextToken();
957:                    if (token.equalsIgnoreCase(wsInstanceName)) {
958:                        logger.log(Level.SEVERE, "PSFB_CSPFT0345",
959:                                new String[] { wsInstanceName });
960:                        validInstance = true;
961:                    }
962:                }
963:                if (!validInstance) {
964:                    logger.log(Level.SEVERE, "PSFB_CSPFT0346",
965:                            new String[] { wsInstanceName });
966:                }
967:                return validInstance;
968:            }
969:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.