DeploymentClientUtilspublic class DeploymentClientUtils extends Object
Fields Summary |
---|
private static final String | APPS_CONFIG_MBEAN | private static ObjectName | applicationsMBean |
Methods Summary |
---|
public static final void | changeStateOfModule(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID, java.lang.String type, com.sun.enterprise.deployapi.SunTarget target, boolean enable)
//System.out.println("DBG_PRINT : Changing state in target " + target.getName() + " to " + enable);
if (mbsc!=null) {
Object[] params = new Object[]{moduleID, type, target.getName()};
String[] signature = new String[]{"java.lang.String", "java.lang.String", "java.lang.String"};
if (enable) {
mbsc.invoke(applicationsMBean, "enable", params, signature);
} else {
mbsc.invoke(applicationsMBean, "disable", params, signature);
}
}
return;
| public static final com.sun.enterprise.deployment.backend.DeploymentStatus | createApplicationReference(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID, com.sun.enterprise.deployapi.SunTarget target, java.util.Map options)
//System.out.println("DBG_PRINT : create-app-ref for target = " + target.getName());
if (mbsc!=null) {
Object[] params = new Object[]{target.getName(), moduleID, options};
String[] signature = new String[]{"java.lang.String", "java.lang.String", "java.util.Map"};
return (DeploymentStatus) (mbsc.invoke(
applicationsMBean, "createApplicationReference", params, signature));
}
return null;
| public static com.sun.enterprise.deployment.backend.DeploymentStatus | createLifecycleModuleReference(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID, java.lang.String target, java.util.Map options)
if (mbsc!=null) {
String[] signature = new String[] {"java.lang.String", "java.lang.String", "java.util.Map"};
Object[] params = new Object[] {moduleID, target, options};
return((DeploymentStatus)mbsc.invoke(applicationsMBean, "createLifecycleModuleReference", params, signature));
}
return null;
| public static final com.sun.enterprise.deployment.backend.DeploymentStatus | deleteApplicationReference(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID, com.sun.enterprise.deployapi.SunTarget target, java.util.Map options)
//System.out.println("DBG_PRINT : del-app-ref for target = " + target.getName());
if (mbsc!=null) {
String[] signature = new String[]{"java.lang.String", "java.lang.String", "java.util.Map"};
Object[] params = new Object[]{target.getName(), moduleID, options};
return (DeploymentStatus) (mbsc.invoke(
applicationsMBean, "deleteApplicationReference", params, signature));
}
return null;
| public static void | doWsdlFilePublishing(com.sun.enterprise.deployment.backend.DeploymentStatus status, com.sun.appserv.management.client.ConnectionSource conn)
if (status == null) { return; }
String sep = DeploymentStatus.KEY_SEPARATOR;
String key = DeploymentStatus.MODULE_ID;
String moduleID = status.getProperty(key);
key = moduleID + sep + DeploymentStatus.SUBMODULE_COUNT;
if (status.getProperty(key) == null) { //standalone module
doWsdlFilePublishing(moduleID, status, conn);
} else {
int counter = (Integer.valueOf(status.getProperty(key))).intValue();
for (int i = 0; i < counter; i++) { //for each submodule
key = moduleID + sep + DeploymentStatus.MODULE_ID + sep +
String.valueOf(i);
String subModuleID = status.getProperty(key);
doWsdlFilePublishing(subModuleID, status, conn);
}
}
| private static void | doWsdlFilePublishing(java.lang.String keyPrefix, com.sun.enterprise.deployment.backend.DeploymentStatus status, com.sun.appserv.management.client.ConnectionSource conn)
String sep = DeploymentStatus.KEY_SEPARATOR;
String key = keyPrefix + sep + DeploymentStatus.MODULE_TYPE;
ModuleType moduleType = ModuleType.getModuleType((new Integer(status.getProperty(key))).intValue());
//only EAR, WAR and EJB archives could contain wsdl files for publish
if (!(ModuleType.EAR.equals(moduleType) ||
ModuleType.WAR.equals(moduleType) ||
ModuleType.EJB.equals(moduleType))) {
return;
}
key = keyPrefix + sep + DeploymentStatus.WSDL_PUBLISH_URL;
String clientPublishURL = status.getProperty(key);
if (clientPublishURL == null) { // No file publishing
return;
}
URL u = new URL(clientPublishURL);
String destinationDir = (new File(u.getFile())).getAbsolutePath();
key = keyPrefix + sep + DeploymentStatus.WSDL_FILE_ENTRIES + sep +
DeploymentStatus.COUNT;
int counter = (Integer.valueOf(status.getProperty(key))).intValue();
for (int i = 0; i < counter; i++) {
key = keyPrefix + sep + DeploymentStatus.WSDL_FILE_ENTRIES + sep +
String.valueOf(i);
String entryName =
(status.getProperty(key)).replace('/", File.separatorChar);
key = key + sep + DeploymentStatus.WSDL_LOCATION;
String wsdlFileLocation = status.getProperty(key);
// publish file, preserving its location relative to the module
// wsdl directory.
File outputFile = new File(destinationDir, entryName);
File parentDir = outputFile.getParentFile();
if( !parentDir.exists() ) {
boolean madeDirs = parentDir.mkdirs();
if( !madeDirs ) {
throw new IOException("Error creating "+outputFile);
}
}
downloadFile(new File(wsdlFileLocation), outputFile, conn);
//@@@ should log the location
}
| public static java.lang.String | downloadClientStubs(java.lang.String moduleID, java.lang.String destDir, com.sun.appserv.management.client.ConnectionSource dasConnection)
Object[] params = new Object[] {moduleID};
String[] signature = new String[] {"java.lang.String"};
MBeanServerConnection mbsc =
dasConnection.getExistingMBeanServerConnection();
try {
ModuleType moduleType = getModuleType(mbsc, moduleID);
// only ejb, appclient, application are applicable for
// retrieving client stubs
if (!(ModuleType.EJB.equals(moduleType) ||
ModuleType.CAR.equals(moduleType) ||
ModuleType.EAR.equals(moduleType))) {
DOLUtils.getDefaultLogger().log(
Level.WARNING, "retrieve_client_stub_not_applicable",
new Object[] {moduleID, moduleType});
return null;
}
//Note that we still rely on the SystemsServiceMBean to retrieve
//the client jar location from the server. This should only
//happen on DAS.
ObjectName ssMBean = ObjectNames.getSystemServicesObjectName();
String filePath = (String) mbsc.invoke(
ssMBean, "getClientStubJarLocation", params, signature);
File srcFile = new File(filePath);
downloadFile(srcFile, new File(destDir, srcFile.getName()), dasConnection);
String exportedFileLocation =
new File(destDir, srcFile.getName()).getAbsolutePath();
return exportedFileLocation;
}catch(Exception e) {
throw (IOException)(new IOException(e.getLocalizedMessage()).initCause(e));
}
| public static void | downloadFile(java.io.File srcFile, java.io.File destFile, com.sun.appserv.management.client.ConnectionSource dasConnection)
File destDir = destFile.getParentFile();
if (!destDir.exists() || !destDir.isDirectory() || !destDir.canWrite()) {
//@@@ i18n
throw new IOException(
"Problem accessing directory " + destDir.getPath());
}
UploadDownloadMgr downloadMgr =
ProxyFactory.getInstance(dasConnection).getDomainRoot().getUploadDownloadMgr();
int chunkSize = 32 * 1024;
FileOutputStream fos = null;
try {
Object downloadID = downloadMgr.initiateDownload(srcFile, false);
fos = new FileOutputStream(destFile);
boolean done = false;
while (!done)
{
byte[] bytes = downloadMgr.downloadBytes(downloadID, chunkSize);
fos.write(bytes, 0, bytes.length);
if (bytes.length < chunkSize) { done = true; }
}
} finally {
if (fos != null) {
try { fos.close(); }
catch (Exception e) {}
}
}
| public static java.util.Map | getDeployedTargetList(com.sun.appserv.management.client.ConnectionSource dasConnection, java.lang.String id)
// Create a Map of target names
Map deployedTargets = new HashMap();
// Get all targets from AMX
DomainConfig domainCfg = ProxyFactory.getInstance(dasConnection).getDomainRoot().getDomainConfig();
final Map serverProxies = domainCfg.getStandaloneServerConfigMap();
final Map clusterProxies = domainCfg.getClusterConfigMap();
String[] serverNames = (String[])serverProxies.keySet().toArray(new String[0]);
String[] clusterNames = (String[])clusterProxies.keySet().toArray(new String[0]);
// Now for each stand alone server targets, check if this id is deployed on that target
// If so, add this target to the map
for(int i=0; i<serverNames.length; i++) {
StandaloneServerConfig tgtProxy = (StandaloneServerConfig)
serverProxies.get(serverNames[i]);
DeployedItemRefConfig refProxy = (DeployedItemRefConfig)
tgtProxy.getContainee(
XTypes.DEPLOYED_ITEM_REF_CONFIG, id);
if(refProxy != null) {
deployedTargets.put(serverNames[i], new Boolean(refProxy.getEnabled()));
}
}
// Now for each cluster targets, check if this id is deployed on that target
// If so, add this target to the map
for(int i=0; i<clusterNames.length; i++) {
ClusterConfig tgtProxy = (ClusterConfig)clusterProxies.get(
clusterNames[i]);
DeployedItemRefConfig refProxy = (DeployedItemRefConfig)
tgtProxy.getContainee(
XTypes.DEPLOYED_ITEM_REF_CONFIG, id);
if(refProxy != null) {
deployedTargets.put(clusterNames[i], new Boolean(refProxy.getEnabled()));
}
}
return deployedTargets;
| public static com.sun.enterprise.deployment.backend.DeploymentStatus | getDeploymentStatusFromAdminStatus(com.sun.appserv.management.deploy.DeploymentStatus stat)
DeploymentStatus tmp = new DeploymentStatus();
tmp.setStageStatus(stat.getStageStatus());
if(stat.getThrowable() != null) {
tmp.setStageException(stat.getThrowable());
}
tmp.setStageDescription(stat.getStageDescription());
tmp.setStageStatusMessage(stat.getStageStatusMessage());
Iterator it = stat.getSubStages();
while(it.hasNext()) {
com.sun.appserv.management.deploy.DeploymentStatus stageStatus =
DeploymentSupport.mapToDeploymentStatus((Map)it.next());
tmp.addSubStage(getDeploymentStatusFromAdminStatus(stageStatus));
}
if (stat.getAdditionalStatus() != null) {
it = stat.getAdditionalStatus().entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
tmp.addProperty((String)entry.getKey(), (String)entry.getValue());
}
}
return tmp;
| public static final javax.enterprise.deploy.shared.ModuleType | getModuleType(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID)
if (mbsc!=null) {
String[] signature = new String[]{"java.lang.String"};
Object[] params = new Object[]{moduleID};
Integer modType = (Integer) mbsc.invoke(applicationsMBean, "getModuleType", params, signature);
if(modType != null) {
return XModuleType.getModuleType(modType.intValue());
}
}
return null;
| public static java.lang.String | getTargetStringFromTargetList(com.sun.enterprise.deployapi.SunTarget[] targetList)
StringBuffer sb = new StringBuffer();
for (int i = 0; i < targetList.length; i++) {
sb.append(targetList[i].getName());
if (i != targetList.length -1) {
sb.append(",");
}
}
return sb.toString();
| public static boolean | isLifecycleModule(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID)
if (mbsc!=null) {
String[] signature = new String[] {"java.lang.String"};
Object[] params = new Object[] {moduleID};
Boolean ret = (Boolean)mbsc.invoke(applicationsMBean, "isLifecycleModuleRegistered", params, signature);
if(Boolean.TRUE.equals(ret)) {
return true;
}
}
return false;
| public static boolean | isModuleDeployed(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID)
if (moduleID == null) {
return false;
}
if (mbsc!=null) {
String[] signature = new String[] {"java.lang.String"};
Object[] params = new Object[] {moduleID};
Object result = mbsc.invoke(applicationsMBean, "getModuleType",
params, signature);
if (result != null) {
return true;
}
}
return false;
| public static boolean | isNewTarget(java.util.Map deployedTargets, com.sun.enterprise.deployapi.SunTarget[] targetList)
// During redeploy, if only one target is given and it is "domain", then
// there is no need to check if this is a new target
if( (targetList.length == 1) && (TargetType.DOMAIN.equals(targetList[0].getName())) ) {
return false;
}
if(deployedTargets.size() != targetList.length) {
return true;
}
Map tmpMap = new HashMap();
tmpMap.putAll(deployedTargets);
for(int i=0; i<targetList.length; i++) {
if(tmpMap.get(targetList[i].getName()) == null) {
return true;
}
}
return false;
| public static boolean | isTargetListComplete(java.util.Map deployedTargets, com.sun.enterprise.deployapi.SunTarget[] targetList)
Map tmpMap = new HashMap();
tmpMap.putAll(deployedTargets);
for(int i=0; i<targetList.length; i++) {
if(tmpMap.get(targetList[i].getName()) != null) {
tmpMap.remove(targetList[i].getName());
}
}
if(tmpMap.size() != 0) {
return false;
}
return true;
| public static final java.lang.String | mapModuleTypeToXType(javax.enterprise.deploy.shared.ModuleType moduleType)
if (ModuleType.EAR.equals(moduleType)) {
return XTypes.J2EE_APPLICATION_CONFIG;
} else if (ModuleType.EJB.equals(moduleType)) {
return XTypes.EJB_MODULE_CONFIG;
} else if (ModuleType.RAR.equals(moduleType)) {
return XTypes.RAR_MODULE_CONFIG;
} else if (ModuleType.WAR.equals(moduleType)) {
return XTypes.WEB_MODULE_CONFIG;
} else if (ModuleType.CAR.equals(moduleType)) {
return XTypes.APP_CLIENT_MODULE_CONFIG;
}
return null;
| public static com.sun.enterprise.deployment.backend.DeploymentStatus | removeLifecycleModuleReference(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID, java.lang.String target)
if (mbsc!=null) {
String[] signature = new String[] {"java.lang.String", "java.lang.String"};
Object[] params = new Object[] {moduleID, target};
return((DeploymentStatus)mbsc.invoke(applicationsMBean, "removeLifecycleModuleReference", params, signature));
}
return null;
| public static void | setResourceOptions(java.util.Map options, java.lang.String rAction, com.sun.enterprise.deployapi.SunTarget[] targetList)
options.put(DeploymentProperties.RESOURCE_ACTION, rAction);
options.put(DeploymentProperties.RESOURCE_TARGET_LIST,
getTargetStringFromTargetList(targetList));
| public static void | setResourceOptions(java.util.Map options, java.lang.String rAction, java.lang.String target)
options.put(DeploymentProperties.RESOURCE_ACTION, rAction);
options.put(DeploymentProperties.RESOURCE_TARGET_LIST,
target);
| public static final com.sun.enterprise.deployment.backend.DeploymentStatus | startApplication(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID, com.sun.enterprise.deployapi.SunTarget target, java.util.Map options)
//System.out.println("DBG_PRINT : app start for target = " + target.getName());
if (mbsc!=null) {
String[] signature = new String[]{"java.lang.String", "java.lang.String", "java.util.Map"};
Object[] params = new Object[]{moduleID, target.getName(), options};
return (DeploymentStatus) (mbsc.invoke(
applicationsMBean, "start", params, signature));
}
return null;
| public static final com.sun.enterprise.deployment.backend.DeploymentStatus | stopApplication(javax.management.MBeanServerConnection mbsc, java.lang.String moduleID, com.sun.enterprise.deployapi.SunTarget target, java.util.Map options)
//System.out.println("DBG_PRINT : app stop for target = " + target.getName());
if (mbsc!=null) {
String[] signature = new String[]{"java.lang.String", "java.lang.String", "java.util.Map"};
Object[] params = new Object[]{moduleID, target.getName(), options};
return (DeploymentStatus) (mbsc.invoke(
applicationsMBean, "stop", params, signature));
}
return null;
|
|