|
|||||||||
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 }
/** // Imports a configuration jar file, applies customization, activates it and exports the resources 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 get the default import plan and modify the plan if required ALSBJarInfo jarInfo = getImportJarInf(); ALSBImportPlan importPlan = jarInfo.getDefaultImportPlan(); // Modify the plan if required and pass it to importUploaeded method ImportResult result = alsbSession.importUploaded(importPlan); // Pass null to importUploaded method to mean the default import plan. //ImportResult result = alsbSession.importUploaded(null); // 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 the customization to assign/replace environment values and // to modify the references. ... // activate the session sm.activateSession(sessionName, "description"); // export information from the core data ALSBConfigurationMBean alsbcore = getConfigMBean(null); //export the information at project level, pass only a collection of project refs to this method byte[] contentsProj = alsbcore.exportProjects(Collections.singleton(Ref.DEFAULT_PROJECT_REF),null); // 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)
Deprecated. in 2.6 in favor of #customize(java.util.List .
Please see EnvValueCustomization |
void |
clone(Ref sourceRef,
Ref targetRef)
Clones a given source project, folder or resource with a new identity. |
void |
createFolder(Ref folderRef,
String description)
Creates a folder with the given reference and description. |
void |
createProject(Ref projectRef,
String description)
Creates a project with the given reference, and project description. |
void |
customize(List<Customization> customizations)
This API supports multiple customizations at one place. |
void |
delete(Collection<Ref> refs)
Deletes the given collection of references. |
boolean |
exists(Ref ref)
Returns true if an entity exists in the domain. |
byte[] |
export(Collection<Ref> refsToExport,
boolean includeDependencies,
String passphrase)
Exports the given collection of references and returns bytes that make up the export data. |
byte[] |
exportProjects(Collection<Ref> projectrefs,
String passphrase)
Export resources at the project level. |
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. |
Object |
getEnvValue(Ref ref,
String envType,
String location)
returns the environment value with the given type and location in the given resource. |
ALSBJarInfo |
getImportJarInfo()
Returns detailed information about the entities in the previously staged configuration jar file |
Set<Ref> |
getRefs(BaseQuery query)
Searches for resources using the given query and returns a set of refs. |
Set<Ref> |
getRefs(Ref root)
Returns all the resources, folders or projects that are under the given root. |
String |
getSession()
Returns the name of the session that this mbean operates on |
ImportResult |
importUploaded(ALSBImportPlan importPlan)
Import an already uploaded jar file in this session. |
ImportResult |
importUploaded(Collection<Ref> refs,
boolean includeDependencies,
boolean preserveExistingEnvValues,
String passphrase)
Deprecated. in 2.6. Use importUploaded(com.bea.wli.sb.management.importexport.ALSBImportPlan) |
BulkImportResult |
importZip(Ref location,
byte[] zipcontent,
Map<String,String> extensions)
Imports the resources from a zip file. |
Set<Ref> |
mapReferences(Collection<Ref> resourcesToConsider,
Map<Ref,Ref> refMap)
Modifies the existing references from all the resources in the given list (resourcesToConsider) to a new set of references passed in the refMap. |
void |
move(Ref source,
Ref target)
This method is used to change the identity of a resource or to map an existing project or folder to another project or folder. |
int |
replaceEnvValues(EnvValueQuery query,
String replacement)
Deprecated. in 2.6 in favor of #customize(java.util.List .
Please see FindAndReplaceCustomization |
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(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
importUploaded(com.bea.wli.sb.management.importexport.ALSBImportPlan)
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
#customize(java.util.List)
.
Please see FindAndReplaceCustomization
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
#customize(java.util.List)
.
Please see EnvValueCustomization
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 valuesvoid clone(Ref sourceRef, Ref targetRef) throws AlreadyExistsException, NotFoundException, CreateException
Cloning a resource simply creates a copy of that resource with the given target identity. The clone will remain to have the same references as the original one. Moreover any other resources that were referencing the original resource will continue to reference the original. (This behavior is different when cloning a project or folder).
Cloning a location (project or folder) works differently from cloning a resource. It effectively clones all artifacts under that location (including folders) to a different location. Moreover the following are also performed.
sourceRef
- the reference to the resource, project or folder to be cloned.targetRef
- the new identity of the cloned resource, project or folder. If the sourceRef
is a resource, the targetRef must be of the same resource type. If sourceRef is a location
(project or folder) the targetRef must be a location too. However the user can specify a folder
in the sourceRef and a project as the targetRef, or vice versa. The former effectively promotes
a folder to be a project, whereas the latter demotes a project to be a folder.
AlreadyExistsException
- if the target resource, project or folder (targetRef) already exists
NotFoundException
- if the source is not found or if the parent location (project or folder) of the
targetRef does not exist. For example if a folder "P1/sourceFolder" is to be cloned as "P2/F2/F3/targetFolder"
the parent location, which is "P2/F2/F3" must exist.
CreateException
- if there is any other error while creating a resource.Set<Ref> mapReferences(Collection<Ref> resourcesToConsider, Map<Ref,Ref> refMap) throws NotFoundException, UpdateException
resourcesToConsider
- list of resources to be modified with the new referencesrefMap
- map of references. key is the old ref and value is the new ref
IllegalArgumentException
- if the refMap is not valid
NotFoundException
- if the resource given in the resourcesToConsider does not exist
UpdateException
- if there is any error while trying to update the resourcesSet<Ref> getRefs(BaseQuery query) throws NotFoundException
query
- You can pass either ResourceQuery
or
DependencyQuery
.
NotFoundException
- if a resource to a reference is not foundBulkImportResult importZip(Ref location, byte[] zipcontent, Map<String,String> extensions) throws Exception
com.bea.wli.sb.util.ZipUtils#getDefaultExtensionMap()
method to get
the default extension to resource mapping.
location
- the reference of the project or folder that will receive the resources.
If the location does not exist it throws NotFoundException.zipcontent
- the byte content of the zip file to loadextensions
- the map IllegalArgumentException
- if the file is not a valid zip file
NotFoundException
- if the location specified doesn't exist
Exception
- If there is any exception during importbyte[] exportProjects(Collection<Ref> projectrefs, String passphrase) throws Exception
export(java.util.Collection, boolean, java.lang.String)
when imported to a target domain. Resource that are in the
target domain, but not in the jar file are deleted by default. This behavior could be
overwritten or customized by modifying the import plan. Folders are not
deleted even if they don't exist in the jar file.
projectrefs
- references to projects to be exportedpassphrase
-
Exception
ImportResult importUploaded(ALSBImportPlan importPlan) throws Exception
importPlan
- ALSBImportPlan
. A null value causes the default plan to be used.
Exception
ALSBJarInfo getImportJarInfo() throws NotFoundException, Exception
NotFoundException
- if no configuration jar has been uploaded, or a previously
uploaded jar file has been imported
Exception
void customize(List<Customization> customizations) throws Exception
customizations
- Customization
Exception
void move(Ref source, Ref target) throws NotFoundException, AlreadyExistsException, UpdateException
More precisely a mapping from A1/A2/.../An to B1/B2/.../Bm will change identity of all projects, folders, and resources under A1/A2/.../An (inclusive) to have a location prefix of B1/B2/.../Bm. For example if there is a folder A1/A2/.../An/Foo, it will become B1/B2/.../Bm/Foo.
source
- reference to the source project/folder/resourcetarget
- reference to the target project/folder/resource
NotFoundException
- is source or target ref is not found
AlreadyExistsException
- while moving resources if another resource with
the target's identity already exists.
And while moving location if a resource in the source location conflicts
with another resource with the same name in the target location.
UpdateException
- any other failure is wrapped inside
this exception.void delete(Collection<Ref> refs) throws NotFoundException, DeleteException
refs
- the collection of references to delete
NotFoundException
- if a reference is not found
DeleteException
- if there is any error while deleting a resource.
For example, if the user tries to delete System Projectvoid createProject(Ref projectRef, String description) throws AlreadyExistsException, CreateException
projectRef
- reference to the project being createddescription
- description associated with the project
CreateException
- if there is any error while creating project
AlreadyExistsException
- if the project user is trying to create already exists
IllegalArgumentException
- if the ref is not a project refvoid createFolder(Ref folderRef, String description) throws AlreadyExistsException, NotFoundException, CreateException
folderRef
- reference to a folderdescription
- description associated with the folder.
CreateException
- if a folder with the same name under the given parent exists.
AlreadyExistsException
- if the project user is trying to create already exists
NotFoundException
- if the parent of folderRef doesn't exist
IllegalArgumentException
- if the ref is not a folder refObject getEnvValue(Ref ref, String envType, String location) throws NotFoundException
ref
- resource refenvType
- environment value typelocation
- environment value location
NotFoundException
- if the resource is not foundboolean exists(Ref ref)
ref
- reference to the entity
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |