Manipulation d'attributs supplémentaires pour une application déployée

Vous pouvez manipuler des attributs pour une application déployée via la console d'administration, l'outil wsadmin ou par programmation. Utilisez cet exemple pour manipuler des attributs qui ne sont pas exposés pendant ou après l'installation d'application via l'objet AppDeploymentTask.

Avant de commencer

Cette tâche suppose une connaissance de base de la programmation MBean et des interfaces ConfigService. Voir la documentation relative aux API pour en savoir plus sur la programmation de MBean et les interfaces ConfigService.

Pourquoi et quand exécuter cette tâche

Procédez comme suit pour que votre application déployée manipule des attributs qui ne sont pas exposés via l'objet AppDeploymentTask. Les attributs sont enregistrés dans le fichier deployment.xml créé dans le référentiel de configuration pour chaque application déployée.

Procédure

  1. Créez une session.
  2. Connectez-vous à WebSphere Application Server.
  3. Localisez l'objet ApplicationDeployment.
  4. Manipulez les attributs.
  5. Sauvegardez les modifications.
  6. Nettoyez la session.

Résultats

Une fois le code exécuté, les attributs sont mis à jour dans le fichier deployment.xml pour l'application déployée.

Exemple

L'exemple suivant explique comment manipuler les attributs startingWeight, warClassLoaderPolicy et classloader en suivant la procédure précédente.

import java.util.Properties;

import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.ObjectName;

import com.ibm.websphere.management.AdminClient;
import com.ibm.websphere.management.AdminClientFactory;
import com.ibm.websphere.management.Session;
import com.ibm.websphere.management.configservice.ConfigService;
import com.ibm.websphere.management.configservice.ConfigServiceHelper;
import com.ibm.websphere.management.configservice.ConfigServiceProxy;
import com.ibm.websphere.management.exception.ConfigServiceException;
import com.ibm.websphere.management.exception.ConnectorException;

public class AppManagementSample1 {

	public static void main(String[] args) {
		String hostName = "localhost";
		String port = "8880";
		String appName = "ivtApp";

		ConfigService configService = null;

		// create a session.
		Session session = new Session();

		// establish connection to the server.
		try {
			Properties props = new Properties();
			props.setProperty(AdminClient.CONNECTOR_TYPE, 
					AdminClient.CONNECTOR_TYPE_SOAP);
			props.setProperty(AdminClient.CONNECTOR_HOST, hostName);
			props.setProperty(AdminClient.CONNECTOR_PORT, port);
			AdminClient adminClient = 
				AdminClientFactory.createAdminClient(props);

			// create a config service proxy object.
			configService = new ConfigServiceProxy(adminClient);

			// Locate the application object.
			ObjectName rootID = configService.resolve(session,
					"Deployment="+appName)[0];
			System.out.println ("rootID is: " + rootID);

			// Locate the ApplicationDeployment object from the root. 
			ObjectName appDeplPattern = ConfigServiceHelper.createObjectName
						(null, "ApplicationDeployment");
			/*
			ObjectName appDeplID = configService.queryConfigObjects(session, 
					rootID, appDeplPattern, null)[0];
			*/
			AttributeList list1 = configService.getAttributes(session, 
					rootID, new String[]{"deployedObject"}, false);
			ObjectName appDeplID = (ObjectName)
				ConfigServiceHelper.getAttributeValue(list1, "deployedObject");
			System.out.println ("appDeplID: " + appDeplID);
			
			// Locate the class loader.
			
			// Change the starting weight through the startingWeight attribute. The starting weight 
       // affects the order in which applications start.
			AttributeList attrList = new AttributeList();
			Integer newWeight = new Integer (10);
			attrList.add(new Attribute("startingWeight", newWeight));

			// Change the WAR class loader policy through the warClassLoaderPolicy attribute by 
       // specifying SINGLE or MULTIPLE.
			// SINGLE=one classloader for all WAR modules
			attrList.add(new Attribute("warClassLoaderPolicy", "SINGLE"));

			// Set the class loader mode to PARENT_FIRST or PARENT_LAST.
			AttributeList clList = (AttributeList) configService.getAttribute
				(session, appDeplID, "classloader");
			ConfigServiceHelper.setAttributeValue (clList, "mode",
				"PARENT_LAST");
			attrList.add (new Attribute ("classloader", clList));

			// Set the new values.
			configService.setAttributes(session,  appDeplID, attrList);

			// Save your changes.
			configService.save(session, false);

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
            // Clean up the session.
			try {
				configService.discard(session);
			}
			catch (ConfigServiceException csEx)
			{
				csEx.printStackTrace();
			}
			catch (ConnectorException cnEx)
			{
				cnEx.printStackTrace();
			}
		}		
	}
}

Icône indiquant le type de rubrique Rubrique de tâche



Icône d'horodatage Dernière mise à jour: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjmx_config_appdeploy
Nom du fichier : tjmx_config_appdeploy.html