001: /**
002: * $Id: InstanceInfoBean.java,v 1.7 2006/08/24 05:08:16 pd109850 Exp $
003: * Copyright 2005 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.admin.console.fabric;
014:
015: import com.sun.portal.admin.common.util.AdminClientUtil;
016: import com.sun.portal.admin.common.InstanceAttributes;
017:
018: import javax.faces.context.FacesContext;
019: import javax.servlet.http.HttpServletRequest;
020: import javax.management.ObjectName;
021: import java.util.Iterator;
022: import java.util.Set;
023: import java.util.Map;
024: import java.util.HashSet;
025: import java.util.Collections;
026: import java.util.logging.Level;
027:
028: public class InstanceInfoBean extends FabricBaseBean {
029:
030: private Map valuesMap = Collections.EMPTY_MAP;
031: private String instanceId;
032:
033: public InstanceInfoBean() {
034: fetchInfo();
035: }
036:
037: public String getPortalInstance() {
038: return instanceId;
039: }
040:
041: public String getHost() {
042: return getValueFromMap(InstanceAttributes.HOST);
043: }
044:
045: public String getPort() {
046: return getValueFromMap(InstanceAttributes.PORT);
047: }
048:
049: public String getProtocol() {
050: return getValueFromMap(InstanceAttributes.SCHEME);
051: }
052:
053: public String getType() {
054: Map fabric = getResourceStringMap("fabric");
055: return (String) fabric.get(getWCType());
056: }
057:
058: public String getWCType() {
059: return getValueFromMap(InstanceAttributes.WEB_CONTAINER_TYPE);
060: }
061:
062: public String getInstanceName() {
063: return getValueFromMap(InstanceAttributes.WEB_CONTAINER_INSTANCE);
064: }
065:
066: public String getInstallDir() {
067: return getValueFromMap(InstanceAttributes.WEB_CONTAINER_INSTALL_DIR);
068: }
069:
070: public String getInstanceDir() {
071: return getValueFromMap(InstanceAttributes.WEB_CONTAINER_INSTANCE_DIR);
072: }
073:
074: public String getDeployedApps() {
075: return getListFromMap(InstanceAttributes.DEPLOYED_WEBAPPS);
076: }
077:
078: public String getDocRoot() {
079: return getValueFromMap(InstanceAttributes.WEB_CONTAINER_DOC_ROOT);
080: }
081:
082: private String getListFromMap(String key) {
083: String value = "";
084: Set valueSet = (Set) valuesMap.get(key);
085: if (valueSet != null && !valueSet.isEmpty()) {
086: Iterator iter = valueSet.iterator();
087: while (iter.hasNext()) {
088: value += iter.next() + "<br>";
089: }
090: }
091: return value;
092: }
093:
094: private String getValueFromMap(String key) {
095: String value = "";
096: Set valueSet = (Set) valuesMap.get(key);
097: if (valueSet != null) {
098: value = valueSet.toString();
099: // Strip out the [ ] chars from the toSring value
100: if (value.length() > 2) {
101: value = value.substring(1, value.length() - 1);
102: }
103: }
104: return value;
105: }
106:
107: private void fetchInfo() {
108:
109: // Get the portal Id from session
110: String portalId = (String) getSessionAttribute(ATTR_SELECTED_PORTAL);
111:
112: HttpServletRequest req = (HttpServletRequest) FacesContext
113: .getCurrentInstance().getExternalContext().getRequest();
114: // Get the instance id from the request params.
115: // If its not available fall back to the
116: instanceId = (String) req.getParameter(ATTR_SELECTED_INSTANCE);
117: if (instanceId == null || instanceId.trim().length() < 1) {
118: instanceId = (String) getSessionAttribute(ATTR_SELECTED_INSTANCE);
119: } else {
120: // Set it into the session
121: setSessionAttribute(ATTR_SELECTED_INSTANCE, instanceId);
122: }
123:
124: // Only a selected few of the webcontainer attributes are displayed
125: // in the UI
126: Set attrKeys = new HashSet();
127: attrKeys.add(InstanceAttributes.WEB_CONTAINER_TYPE);
128: attrKeys.add(InstanceAttributes.HOST);
129: attrKeys.add(InstanceAttributes.PORT);
130: attrKeys.add(InstanceAttributes.SCHEME);
131: attrKeys.add(InstanceAttributes.WEB_CONTAINER_INSTANCE);
132: attrKeys.add(InstanceAttributes.WEB_CONTAINER_INSTANCE_DIR);
133: attrKeys.add(InstanceAttributes.WEB_CONTAINER_INSTALL_DIR);
134: attrKeys.add(InstanceAttributes.WEB_CONTAINER_DOC_ROOT);
135: attrKeys.add(InstanceAttributes.WEB_CONTAINER_ADMIN_HOST);
136: attrKeys.add(InstanceAttributes.WEB_CONTAINER_ADMIN_PORT);
137: attrKeys.add(InstanceAttributes.WEB_CONTAINER_ADMIN_SCHEME);
138: attrKeys.add(InstanceAttributes.DEPLOYED_WEBAPPS);
139:
140: // Set the right params and signature
141: Object[] params = {
142: AdminClientUtil.PORTAL_SERVER_INSTANCE_MBEAN_TYPE,
143: attrKeys };
144: String[] signature = { "java.lang.String", "java.util.Set" };
145:
146: try {
147: // Get the MBean object for the newly created portal
148: ObjectName objName = AdminClientUtil
149: .getInstanceMBeanObjectName(
150: AdminClientUtil.DEFAULT_DOMAIN, portalId,
151: instanceId);
152:
153: log(Level.FINEST, "Invoking MBean method for: "
154: + instanceId);
155: // Invoke the delete instance operation
156: valuesMap = (Map) getMBeanServerConnection().invoke(
157: objName, "getMultipleAttributeValues", params,
158: signature);
159: } catch (Exception e) {
160: log(
161: Level.SEVERE,
162: "InstanceInfoBean.fetchInfo(): Unable to fetch Instance Information",
163: e);
164: // TODO add alert
165: }
166:
167: }
168:
169: public String ok() {
170: return "gotoInstancesHome";
171: }
172:
173: }
|