001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)JbiVerifyApplicationEnv.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.ant;
030:
031: import org.apache.tools.ant.BuildException;
032: import java.io.File;
033: import java.io.IOException;
034: import java.io.StringWriter;
035: import java.io.PrintWriter;
036: import java.util.Iterator;
037: import java.util.Set;
038: import javax.management.openmbean.CompositeData;
039: import javax.management.openmbean.CompositeType;
040: import javax.management.openmbean.OpenType;
041: import javax.management.openmbean.TabularType;
042: import javax.management.openmbean.TabularData;
043:
044: /** This class is an ant task for stopping the service engine or binding component.
045: *
046: * @author Sun Microsystems, Inc.
047: */
048: public class JbiVerifyApplicationEnvTask extends JbiTargetTask {
049: /**
050: * success msg key
051: */
052: private static final String SUCCESS_STATUS_KEY = "jbi.ui.ant.verify.app.env.successful";
053: /**
054: * failure msg key
055: */
056: private static final String FAILED_STATUS_KEY = "jbi.ui.ant.verify.app.env.failed";
057:
058: /** Holds value of property application zip file. */
059: private File mAppFile;
060:
061: /** Holds value of property generating deploy command flag. */
062: private boolean mIncludeDeployFlag;
063:
064: /** Holds value of property templates dir. */
065: private String mTemplateDir;
066:
067: /** Getter for property application zip file.
068: * @return Path of property application zip file.
069: *
070: */
071:
072: public File getFile() {
073: return this .mAppFile;
074: }
075:
076: /**
077: * Setter for property application zip file.
078: * @param file the file path to the appliction zip file.
079: */
080: public void setFile(File file) {
081: this .mAppFile = file;
082: }
083:
084: /** Getter for property deploy.
085: * @return Value of property deploy flag.
086: *
087: */
088: public boolean getIncludeDeploy() {
089: return this .mIncludeDeployFlag;
090: }
091:
092: /**
093: * Setter for property deploy flag.
094: * @param deployFlag the deploy flag.
095: */
096: public void setIncludeDeploy(boolean includeDeploy) {
097: this .mIncludeDeployFlag = includeDeploy;
098: }
099:
100: /** Getter for property templatesdir.
101: * @return Value of property templatedir.
102: *
103: */
104: public String getTemplateDir() {
105: return this .mTemplateDir;
106: }
107:
108: /**
109: * Setter for property templatedir.
110: * @param templateDir the dir indicating where the templates will be genearted.
111: */
112: public void setTemplateDir(String templateDir) {
113: this .mTemplateDir = templateDir;
114: }
115:
116: /** executes the stop componentnt task. Ant Task framework calls this method to
117: * excute the task.
118: * @throws BuildException if error or exception occurs.
119: */
120: public void executeTask() throws BuildException {
121:
122: String target = getValidTarget();
123:
124: try {
125: String templateFlagStr = !((mTemplateDir == null) || (mTemplateDir
126: .compareTo("") == 0)) ? "True" : "False";
127: String deployFlagStr = mIncludeDeployFlag == true ? "True"
128: : "False";
129: this .logDebug("app path: " + mAppFile.getPath()
130: + " The target: " + target
131: + " The gen templates flag: " + templateFlagStr
132: + " The templates dir: " + mTemplateDir
133: + " The deploy flag: " + deployFlagStr);
134:
135: CompositeData result = this .getJBIAdminCommands()
136: .verifyApplication(
137: mAppFile.getPath(),
138: target,
139: !((mTemplateDir == null) || (mTemplateDir
140: .compareTo("") == 0)),
141: mTemplateDir, mIncludeDeployFlag);
142:
143: printResultCompositeData(result);
144: } catch (Exception ex) {
145: processTaskException(ex);
146: }
147:
148: }
149:
150: protected void printResultCompositeData(CompositeData compData)
151: throws IOException {
152: String[] attributeNames = { "ServiceAssemblyName",
153: "ServiceAssemblyDescription", "NumServiceUnits",
154: "AllComponentsInstalled", "MissingComponentsList",
155: "EndpointInfo", "TemplateZIPID",
156: "JavaEEVerificationReport" };
157:
158: String[] endpointNames = { "EndpointName", "ServiceUnitName",
159: "ComponentName", "Status",
160: "MissingApplicationVariables",
161: "MissingApplicationConfigurations" };
162:
163: String saName = (String) compData.get(attributeNames[0]);
164: String saDesc = (String) compData.get(attributeNames[1]);
165: int numSUs = ((Integer) compData.get(attributeNames[2]))
166: .intValue();
167: boolean allComponentsInstalled = ((Boolean) compData
168: .get(attributeNames[3])).booleanValue();
169: String[] missingComponents = (String[]) compData
170: .get(attributeNames[4]);
171: CompositeData[] endpointInfo = (CompositeData[]) compData
172: .get(attributeNames[5]);
173: String templateZipID = (String) compData.get(attributeNames[6]);
174:
175: logWarning(getI18NBundle()
176: .getMessage(
177: "jbi.ui.ant.print.jbi.verify.app.env.info.header.separator"));
178: logWarning(getI18NBundle().getMessage(
179: "jbi.ui.ant.print.jbi.verify.app.env.info.header",
180: getValidTarget()));
181: logWarning(getI18NBundle().getMessage(
182: "jbi.ui.ant.print.jbi.verify.app.env.info.separator"));
183: logWarning(getI18NBundle().getMessage(
184: "jbi.ui.ant.print.jbi.verify.app.env.sa.name")
185: + ": " + saName);
186: logWarning(getI18NBundle().getMessage(
187: "jbi.ui.ant.print.jbi.verify.app.env.service.units")
188: + ": " + numSUs);
189: logWarning(getI18NBundle().getMessage(
190: "jbi.ui.ant.print.jbi.verify.app.env.sa.description")
191: + ": " + (saDesc + "").trim());
192:
193: if (!allComponentsInstalled) {
194: StringBuffer missingCompString = new StringBuffer();
195: for (int i = 0; i < missingComponents.length; i++) {
196: missingCompString.append(" " + missingComponents[i]);
197: }
198: logWarning(getI18NBundle()
199: .getMessage(
200: "jbi.ui.ant.print.jbi.verify.app.env.commponents.not.installed")
201: + ": " + (missingCompString.toString() + "").trim());
202: }
203:
204: for (int i = 0; i < endpointInfo.length; i++) {
205: logWarning("\n"
206: + getI18NBundle()
207: .getMessage(
208: "jbi.ui.ant.print.jbi.verify.app.env.endpoint.configuration"));
209: logWarning(getI18NBundle()
210: .getMessage(
211: "jbi.ui.ant.print.jbi.verify.app.env.info.separator"));
212:
213: Object[] endpointValues = endpointInfo[i]
214: .getAll(endpointNames);
215: logWarning(getI18NBundle()
216: .getMessage(
217: "jbi.ui.ant.print.jbi.verify.app.env.endpoint.name")
218: + ": " + (String) endpointValues[0]);
219: logWarning(getI18NBundle().getMessage(
220: "jbi.ui.ant.print.jbi.verify.app.env.service.unit")
221: + ": " + (String) endpointValues[1]);
222: logWarning(getI18NBundle()
223: .getMessage(
224: "jbi.ui.ant.print.jbi.verify.app.env.endpoint.component")
225: + ": " + (String) endpointValues[2]);
226: logWarning(getI18NBundle()
227: .getMessage(
228: "jbi.ui.ant.print.jbi.verify.app.env.endpoint.status")
229: + ": " + (String) endpointValues[3]);
230: String[] appVars = (String[]) endpointValues[4];
231: if (appVars != null && appVars.length > 0) {
232: logWarning("Missing Application Variables ");
233: for (int j = 0; j < appVars.length; j++) {
234: logWarning("\t" + appVars[j]);
235: }
236: logWarning("");
237: }
238:
239: String[] appConfigs = (String[]) endpointValues[5];
240: if (appConfigs != null && appConfigs.length > 0) {
241: logWarning("Missing Application Configurations ");
242: for (int j = 0; j < appConfigs.length; j++) {
243: logWarning("\t" + appConfigs[j]);
244: }
245: logWarning("");
246: }
247: }
248:
249: if (compData.containsKey(attributeNames[7])) {
250: String[] eeReportFieldNames = { "ServiceUnitName",
251: "JavaEEVerifierReport" };
252:
253: CompositeData[] javaEEVerifierReports = (CompositeData[]) compData
254: .get(attributeNames[7]);
255: if (javaEEVerifierReports != null
256: && javaEEVerifierReports.length > 0) {
257: logWarning("");
258: logWarning(getI18NBundle()
259: .getMessage(
260: "jbi.ui.ant.print.jbi.verify.app.env.ee.verify.report"));
261: logWarning(getI18NBundle()
262: .getMessage(
263: "jbi.ui.ant.print.jbi.verify.app.env.info.separator"));
264: }
265:
266: StringWriter stringWriter = new StringWriter();
267: PrintWriter msgWriter = new PrintWriter(stringWriter);
268:
269: for (int i = 0; i < javaEEVerifierReports.length; i++) {
270: String serviceUnitName = (String) javaEEVerifierReports[i]
271: .get(eeReportFieldNames[0]);
272: logWarning(getI18NBundle()
273: .getMessage(
274: "jbi.ui.ant.print.jbi.verify.app.env.service.unit")
275: + ": " + serviceUnitName);
276: TabularData reportTable = (TabularData) javaEEVerifierReports[i]
277: .get(eeReportFieldNames[1]);
278: Set rows = reportTable.keySet();
279: for (Object row : rows) {
280: Object[] key = ((java.util.List) row).toArray();
281: CompositeData rptCompData = reportTable.get(key);
282: msgWriter.println();
283: printCompositeDataRecursively(rptCompData,
284: msgWriter, "");
285: }
286: printMessage(stringWriter.getBuffer().toString());
287: stringWriter.flush();
288: }
289:
290: msgWriter.close();
291: stringWriter.close();
292: }
293:
294: if (!((mTemplateDir == null) || (mTemplateDir.compareTo("") == 0))) {
295: logWarning("");
296: logWarning(getI18NBundle()
297: .getMessage(
298: "jbi.ui.ant.print.jbi.verify.app.env.info.separator"));
299: logWarning(getI18NBundle()
300: .getMessage(
301: "jbi.ui.ant.print.jbi.verify.app.env.templates.create.msg",
302: new String[] { mTemplateDir }));
303: }
304:
305: }
306:
307: /**
308: * returns i18n key. tasks implement this method.
309: * @return i18n key for the success status
310: */
311: protected String getTaskFailedStatusI18NKey() {
312: return FAILED_STATUS_KEY;
313: }
314:
315: /**
316: * returns i18n key. tasks implement this method.
317: * @return i18n key for the failed status
318: */
319: protected String getTaskSuccessStatusI18NKey() {
320: return SUCCESS_STATUS_KEY;
321: }
322: }
|