|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ALSBConfigurationMBean
Provides various API to query, export and import resources, obtain validation errors, get and set environment values, and in general manage resources in an ALSB domain.
SessionManagementMBean.createSession(String)
API. This mbean instance is then used to perform configuration operations in that session.
The mbean instance is destroyed when the corresponding session is activated or discarded.
More information about Sessions can be found in javadoc for SessionManagementMBean
SessionManagementMBean
.
SessionManagementMBean
.
/** // Imports a configuration jar file, replaces environment values, activates it, and exports // the resource again. // @throws Exception / static private void simpleImportExport(String importFileName, String passphrase) throws Exception { SessionManagementMBean sm = ... // obtain the mbean to create a session; // obtain the raw bytes that make up the configuration jar file File importFile = new File(importFileName); byte[] bytes = readBytes(importFile); // create a session String sessionName = "session." + System.currentTimeMillis(); sm.createSession(sessionName); // obtain the ALSBConfigurationMBean that operates on the // session that has just been created ALSBConfigurationMBean alsbSession = getConfigMBean(sessionName); // import configuration into the session. First we upload the // jar file, which will stage it temporarily. alsbSession.uploadJarFile(bytes); // then we import the jar file ImportResult result = alsbSession.importUploaded( null, // import everything in the jar file true, // whether to include dependencies. This could be false // since we are importing everything in the jar file. false, // import as is, potentially overwriting the existing // environment values that may have been previously // customized. We will customize them explicitly below passphrase // non-null if configuration jar file contains // sensitive information that has been encrypted ); // print out status if (result.getImported().size() > 0) { System.out.println("The following resources have been successfully imported."); for (Ref ref : result.getImported()) { System.out.println("\t" + ref); } } if (result.getFailed().size() > 0) { System.out.println("The following resources have failed to be imported."); for (Map.Entry e : result.getFailed().entrySet()) { Ref ref = e.getKey(); // Diagnostics object contains validation errors // that caused the failure to import this resource Diagnostics d = e.getValue(); System.out.println("\t" + ref + ". reason: " + d); } // discard the changes to the session and exit System.out.println("Discarding the session."); sm.discardSession(sessionName); System.exit(1); } // peform changes on the imported data as needed. Usually // environment values need to be changed if configuration // is being moved from testing to production, or between // different domains. ... // activate the session sm.activateSession(sessionName, "description"); // export information from the core data ALSBConfigurationMBean alsbcore = getConfigMBean(null); byte[] contents = alsbcore.export(Collections.singleton(Ref.DEFAULT_PROJECT_REF), // export everything under the default project true, // also export any other resources that // resources in default project may depend on null); // do not encrypt sensitive information // the byte contents can be saved as jar file }
// change environment values that differ between domains. // we simply change the string "localhost" to "productionhost" // in all the URIs EnvValueQuery evquery = new EnvValueQuery( null, // search across all resource types Collections.singleton(EnvValueTypes.URI_ENV_VALUE_TYPE), // search only the URIs null, // search across all projects and folders. true, // only search across resources that are // actually modified/imported in this session "localhost", // the string we want to replace false // not a complete match of URI. any URI // that has "localhost" as substring will match ); int count = alsbSession.replaceEnvValues(evquery, "productionhost"); System.out.println(count + " instances have been replaced."); // perform an even finer grained environment value replacement. // replace all file paths/URLs that start with "file:///c:/" and // replace with "file:///c:/{project/folder of the resource}, // essentially making the file structure conform to the project // structure // find all env values in all resources that have been modified in // the session evquery = new EnvValueQuery(null, null, null, true, null, false); ArrayListenvValuesToChange = new ArrayList (); String prefix = "file:///c:/"; for (QualifiedEnvValue qev : alsbSession.findEnvValues(evquery)) { if (qev.getValue() instanceof String && qev.getValue().toString().startsWith(prefix)) { Ref ref = qev.getOwner(); String oldValue = (String) qev.getValue(); String newValue = oldValue.substring(0, prefix.length()) + ref.getFullName() + // insert "/" separated path for the resource "/" + oldValue.substring(prefix.length()); QualifiedEnvValue newEnvValue = new QualifiedEnvValue(qev.getOwner(), qev.getEnvValueType(), qev.getLocation(), newValue); envValuesToChange.add(newEnvValue); System.out.println("Env value " + qev.getOwner() + " : " + qev.getEnvValueType() + " : " + qev.getLocation() + " : " + qev.getValue() + " will be changed to " + newValue); } } // now directly set the env values alsbSession.assignEnvValues(envValuesToChange);
ALSBConfigurationMBean alsbCore = getConfigMBean(null); ProxyServiceQuery query = new ProxyServiceQuery(); // find all proxy services using https transport and WSDL based query.setTransportScheme("https"); query.setWSDLBasedService(true); Set refs = alsbCore.getRefs(query); System.out.println("Resources that satisfy the search criteria are:"); for (Ref ref : refs) { System.out.println(ref); }
Field Summary | |
---|---|
static String |
NAME
|
static String |
TYPE
|
Method Summary | |
---|---|
void |
assignEnvValues(Collection<QualifiedEnvValue> envValues)
Sets one or more environment value directly. |
byte[] |
export(Collection<Ref> refsToExport,
boolean includeDependencies,
String passphrase)
Exports the given collection of references and returns bytes that make up the export data. |
Collection<QualifiedEnvValue> |
findEnvValues(EnvValueQuery query)
Searches environment specific values based on the given query |
Map<Ref,Diagnostics> |
getDiagnostics(Collection<Ref> refs)
Obtains diagnostic information about the given resources. |
Set<Ref> |
getRefs(Ref root)
Returns all the resources, folders or projects that are under the given root. |
Set<Ref> |
getRefs(ResourceQuery query)
Searches a particular resource type based on the given resource query and returns references to resources that satisfy the given criteria. |
String |
getSession()
Returns the name of the session that this mbean operates on |
ImportResult |
importUploaded(Collection<Ref> refs,
boolean includeDependencies,
boolean preserveExistingEnvValues,
String passphrase)
Imports selected resources/projects/folders from the previously uploaded jar file into the session. |
int |
replaceEnvValues(EnvValueQuery query,
String replacement)
Find environment values as indicated by the query and replace all occurences of the env value pattern (as returned by EnvValueQuery.getSearchString() )
with the given parameter. |
Set<Ref> |
uploadJarFile(byte[] data)
Obtains configuration data from a configuration jar file and locally (temporarily) stages it on the server. |
Methods inherited from interface weblogic.management.mbeanservers.Service |
---|
getName, getParentAttribute, getParentService, getPath, getType |
Field Detail |
---|
static final String NAME
static final String TYPE
Method Detail |
---|
String getSession()
Set<Ref> getRefs(ResourceQuery query) throws Exception
query
- the query
Exception
Set<Ref> getRefs(Ref root) throws NotFoundException
Ref.DOMAIN
), a project or a folder. The
result does not contain the given root argument.
NotFoundException
- if the given root is not found
IllegalArgumentException
- if the root is null, or is a resource reference.Map<Ref,Diagnostics> getDiagnostics(Collection<Ref> refs) throws Exception
refs
- the resource references for which to return the diagnostics.
A null refs value returns all available diagnostics.
Exception
byte[] export(Collection<Ref> refsToExport, boolean includeDependencies, String passphrase) throws Exception
refsToExport
- array of references to items to be exported. A reference to a resource
causes that resource to be exported. If there is a reference to a folder, project, or the
domain (via Ref.DOMAIN
) then all resources under these are exported as well.
In order to export all the resources simply call this method with Ref.DOMAIN
.includeDependencies
- whether to include dependencies of the resources that are given in the
refsToExport parameterpassphrase
- the passphrase to use if encryption will be done
Exception
Set<Ref> uploadJarFile(byte[] data) throws Exception
importUploaded(java.util.Collection, boolean, boolean, java.lang.String)
method.
data
- contents of a previously exported configuration jar file.
Exception
ImportResult importUploaded(Collection<Ref> refs, boolean includeDependencies, boolean preserveExistingEnvValues, String passphrase) throws Exception
refs
- references to the resources/folders/projects to be imported. An entity can be
listed multiple times (directly or indirectly via its parent folder/project). A reference
to project, folder will cause all resources in the configuration jar file under that location
to be imported. If null or Ref.DOMAIN
all resources in the config jar are imported.includeDependencies
- whether to include dependencies of the resources that are given in the
refs parameter which are also in uploaded jar file.preserveExistingEnvValues
- This flag controls whether certain environment values inside of a resource
will be overwritten or preserved during an import. The import always overwrites any existing data, except
environment values that are found in both the existing data and imported data. If this argument is true,
the import of a resource (which already exists) proceeds as follows:
passphrase
- the pass phrase to use for decrypting resources that have been encrypted. Null
value can be given if the jar file is known to not have been encrypted.
Exception
Collection<QualifiedEnvValue> findEnvValues(EnvValueQuery query)
query
- the search criteria for the environment values.
int replaceEnvValues(EnvValueQuery query, String replacement) throws Exception
EnvValueQuery.getSearchString()
)
with the given parameter.
query
- the query that indicates which env values to findreplacement
- the replacement text. This text will be substituted for the env
value pattern given in the query.
Exception
void assignEnvValues(Collection<QualifiedEnvValue> envValues) throws NotFoundException, UpdateException
findEnvValues(com.bea.wli.config.env.EnvValueQuery)
method to obtain the location
of a particular environment value.
envValues
- Environment values to set.
NotFoundException
- if a resource is not found
UpdateException
- if any other exception occurs while updating the env values
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |