Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 587503 Details for
Bug 826235
Deployment of bundle fails because of corrupted war archive
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
JON script library
paas.js (text/javascript), 15.99 KB, created by
Jochen Cordes
on 2012-05-29 20:18:35 UTC
(
hide
)
Description:
JON script library
Filename:
MIME Type:
Creator:
Jochen Cordes
Created:
2012-05-29 20:18:35 UTC
Size:
15.99 KB
patch
obsolete
>/*=============================================================================== > * > * Utility functions for PaaS (Plaform as a Service) using JON-CLI. > * > * @author Jochen Cordes, Red Hat GmbH > * > *===============================================================================*/ > >/** > * Finds a group via it's name > * > * @param groupName The group's name > * @return group if a group has been found, <code>null</code> otherwise > */ > >function findGroup(groupName){ > var resourceGroupCriteria = new ResourceGroupCriteria; > var group = null; > > resourceGroupCriteria.addFilterName(groupName); > resourceGroupCriteria.fetchExplicitResources(false); > > var resourceGroups = ResourceGroupManager.findResourceGroupsByCriteria(resourceGroupCriteria); > > if (resourceGroups != null && resourceGroups.size() > 0){ > group = resourceGroups.get(0); > } > > return group; >} > >/** > * Creates a group. > * > * @param groupName group-name > * @param resourceType resource-type > * @param description description > */ >function createGroup(groupName, resourceType, description){ > var resourceGroup = new ResourceGroup(groupName, resourceType); > > resourceGroup.setRecursive(false); > resourceGroup.setDescription(description); > > ResourceGroupManager.createResourceGroup(resourceGroup); >} > >/** > * Deletes a group > * > * @param groupId ID of the group > * > */ >function deleteGroup(groupId){ > ResourceGroupManager.deleteResourceGroup(groupId); >} > >/** > * Creates a dynamic group > * > * @param groupName Name of the group > * @param expression Expression to use to form the group > * @description Description of the dynamic group > */ >function createDynamicGroup(groupName, resourceType, expression, description){ > var resourceGroup = new ResourceGroup(groupName, resourceType); > resourceGroup.setDescription(description); > > var groupDefinition = new GroupDefinition(); > groupDefinition.setExpression(expression); > > resourceGroup.setGroupDefinition(groupDefinition); > > ResourceGroupManager.createResourceGroup(resourceGroup); >} > >/** > * Looks up a resource-type via type-name and plugin-name > * > * @param typeName The type-name > * @param plugin-name The plugin-name > * @return resourceType > */ > >function getResourceType(typeName, pluginName){ > var resourceType = ResourceTypeManager.getResourceTypeByNameAndPlugin(typeName, pluginName); > > return resourceType; >} > >/** > * Finds a Web-AppServer via it's name. > * > * @param webAppServerInstanceName The name of the Web-AppServer instance > * @return webAppServerInstance if found, <code>null</code> otherwise > */ >function findWebAppServerInstance(webAppServerInstanceName){ > var webAppServerInstanceCriteria = new ResourceCriteria; > var webAppServerInstance = null; > > webAppServerInstanceCriteria.addFilterName(webAppServerInstanceName); > > var webAppServerInstances = ResourceManager.findResourcesByCriteria(webAppServerInstanceCriteria); > > if (webAppServerInstances != null && webAppServerInstances.size() > 0) > webAppServerInstance = webAppServerInstances.get(0); > > return webAppServerInstance; >} > >/** > * Adds a Web-AppServer to a group > * > * @param webAppServerInstanceName Name of the Web-AppServer > * @param groupName Name the group > */ > >function addWebAppServerInstanceToGroup(webAppServerInstanceName, groupName){ > var webAppServerInstance = findWebAppServerInstance(webAppServerInstanceName); > > if (webAppServerInstance == null){ > throw "WebAppServerInstance " + webAppServerInstanceName + " was not found." > } > > var group = findGroup(groupName); > > if (group == null){ > throw "Group \"" + groupName + "\" was not found." > } > > ResourceGroupManager.addResourcesToGroup(group.getId(),[webAppServerInstance.getId()]); >} > >/** > * Removes a Web-AppServer from a group > * > * @param webAppServerInstanceName Name of the Web-AppServer > * @param groupName Name of the group > */ >function removeWebAppServerInstanceFromGroup(webAppServerInstanceName, groupName){ > var webAppServerInstance = findWebAppServerInstance(webAppServerInstanceName); > > if (webAppServerInstance == null){ > throw "WebAppServerInstance " + webAppServerInstanceName + " was not found." > } > > var group = findGroup(groupName); > > if (group == null){ > throw "Group \"" + groupName + "\" was not found." > } > > ResourceGroupManager.removeResourcesFromGroup(group.getId(),[webAppServerInstance.getId()]); >} > >/** > */ >function stopWebAppServerInstance(webAppServerInstanceName){ > var webAppServerInstance = findWebAppServerInstance(webAppServerInstanceName); > > if (webAppServerInstance == null){ > throw "WebAppServerInstance " + webAppServerInstanceName + " was not found." > } > > var availability = webAppServerInstance.getCurrentAvailability(); > > if ("DOWN".equals(availability.getAvailabilityType())){ > throw "WebAppServerInstance \"" + webAppServerInstanceName + "\" already down." > } else if (availability.getAvailabilityType == null){ > throw "WebAppServerInstance \"" + webAppServerInstanceName + "\" is in an unknown state." > } > > scheduleOperationOnWebAppServerInstance(webAppServerInstance, "shutdown"); >} > >/** > */ >function startWebAppServerInstance(webAppServerInstanceName){ > var webAppServerInstance = findWebAppServerInstance(webAppServerInstanceName); > > if (webAppServerInstance == null){ > throw "WebAppServerInstance \"" + webAppServerInstanceName + "\" was not found." > } > > var availability = webAppServerInstance.getCurrentAvailability(); > > if ("UP".equals(availability.getAvailabilityType())){ > throw "WebAppServerInstance \"" + webAppServerInstanceName + "\" already up." > } else if (availability.getAvailabilityType == null){ > throw "WebAppServerInstance \"" + webAppServerInstanceName + "\" is in an unknown state." > } > > scheduleOperationOnWebAppServerInstance(webAppServerInstance, "start"); >} > >/** > * Restarts a Web-AppServer > * > * @param webAppServerInstanceName The name of the Web-AppServer > */ >function restartWebAppServerInstance(webAppServerInstanceName){ > var webAppServerInstance = findWebAppServerInstance(webAppServerInstanceName); > > if (webAppServerInstance == null){ > throw "WebAppServerInstance \"" + webAppServerInstanceName + "\" was not found." > } > > scheduleOperationOnWebAppServerInstance(webAppServerInstance, "restart"); >} > >/** > * Schedules an operation such as start,stop or restart on a Web-AppServer > * > * @param webAppServerInstance The Web-AppServer instance > * @param operationName The name of the operation [start|stop|restart] > */ >function scheduleOperationOnWebAppServerInstance(webAppServerInstance, operationName){ > var history = null; > > if (webAppServerInstance == null){ > throw "WebAppServerInstance \"" + webAppServerInstanceName + "\" was not found."; > } > > var availabilityBefore = webAppServerInstance.getCurrentAvailability(); > > var conf = new Configuration; > var schedule = OperationManager.scheduleResourceOperation(webAppServerInstance.getId(), operationName, 0, 0, 0, 0, conf, "Executing "+operationName+" on WebAppServer."); > > while (!webAppServerInstance.getCurrentAvailability().equals(availabilityBefore)) { > java.lang.Thread.currentThread().sleep(5000); > } >} > >/** > * Creates a bundle > * > * @param urlName The URL > * @param bundleName The name of the bundle > * @bundleVersionUsr > * > * @return bundle if version does not exist or is a higher version > */ >function createBundle(urlName, bundleName, bundleVersionUsr) { > var versionExists = false; > > var bundle = getBundle(bundleName); > > if (bundle != null){ > var bundleVersions = bundle.getBundleVersions(); > var versionCount = bundleVersions.size(); > > if (versionCount > 0) { > versionExists = bundleVersionExists(bundleName, bundleVersionUsr); > > if (versionExists) { > throw "Bundle with name \"" + bundleName + "\" and version "+bundleVersionUsr+" already exists." > } > > var versions = bundle.bundleVersions; > var versionSize = versions.size() > var latestVersion = versions.get(versionSize - 1).version; > > if(latestVersion > bundleVersionUsr) { > throw "Bundle with name \"" + bundleName + "\" already exists with a higher version ["+latestVersion+"]" > } > } > } > > if (bundle == null || !versionExists) { > // Create bundle version > if (urlName.startsWith("http://")){ > bundle = BundleManager.createBundleVersionViaURL(new java.net.URL(urlName)); > } else { > bundle = BundleManager.createBundleVersionViaByteArray(readFile(urlName)); > } > } > > return bundle; >} > >/** > * Reads a file into a byte-array > * > * @param fileName Name of the file > */ >function readFile(fileName){ > var inputStream = new java.io.FileInputStream(new java.io.File(urlName)); > var outputStream = new java.io.ByteArrayOutputStream(); > var bytes = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 8092); > var n = 0; > > while ((n = inputStream.read(bytes)) > 0){ > outputStream.write(bytes,0,n); > } > > print("File size: "+outputStream.toByteArray().length); > > return outputStream.toByteArray(); >} > >/** > * Returns a bundle by it's name > * > * @param bundleName The name of the bundle > */ >function getBundle(bundleName){ > var bundle = null; > > var criteria = new BundleCriteria(); > criteria.addFilterName(bundleName); > criteria.fetchBundleVersions(true); > > bundleArray = BundleManager.findBundlesByCriteria(criteria); > > var bundleSize = bundleArray.totalSize; > if (bundleSize >= 1) { > bundle = bundleArray.get(bundleSize - 1); > } > > return bundle; >} > >/** > * Checks if a bundle with the specified version exists > * > * @param bundleName Name of the bundle > * @param bundleVersionUsr > */ >function bundleVersionExists(bundleName, bundleVersionUsr){ > var versionExists = false; > var bundle = getBundle(bundleName); > > if (bundle != null){ > var bundleVersions = bundle.getBundleVersions(); > var versionCount = bundleVersions.size(); > > if (versionCount > 0) { > for ( var i = 0; i < bundleVersions.size(); i++){ > var bundleVersion = bundleVersions.get(i); > var bundleVersionInSystem = bundleVersion.version; > > if (bundleVersionInSystem.equals(bundleVersionUsr)) { > versionExists = true; > break; > } > } > } > } > > return versionExists; >} > >/** > * Deploys a bundle to a group. > * > * @param bundleName Name of the bundle > * @param groupName Name of the group > * @param destinationName Name of the destination > * @param destinationDesc Description of the destination > * @param destinationLocation The location of the destination > * @param bundleVersionUsr > * @param deploymentDesc Description of the deployment > * > */ >function deployBundle(bundleName, groupName, destinationName, destinationDesc, destinationLocation, bundleVersionUsr, deploymentDesc) { > // Find the bundle > var bundle = getBundle(bundleName); > > if (bundle == null){ > throw "Bundle with name \"" + bundleName + "\" does not exist"; > } > > if (!bundleVersionExists(bundleName,bundleVersionUsr)){ > throw "Bundle with name \"" + bundleName + "\" and version "+bundleVersionUsr+" does not exist." > } > > // Find the group to be used > var group = findGroup(groupName); > > if (group == null){ > throw "Group "+groupName+" could not be found." > } > > // Ensure destionation exists > var destination = null; > var bdc = new BundleDestinationCriteria(); > bdc.addFilterGroupId(group.id); > bdc.addFilterBundleId(bundle.id); > > var destinations = BundleManager.findBundleDestinationsByCriteria(bdc); > if (!destinations.isEmpty()) { > for ( var i = 0; i < destinations.size(); i++) { > var dest = destinations.get(i); > var name = dest.name; > var dir = dest.deployDir; > > if (dir.equalsIgnoreCase(destinationLocation)) { > destination = dest; > break; > } > } > } > > if (destination == null) { > destination = BundleManager.createBundleDestination(bundle.id,destinationName, destinationDesc, "Profile Directory", > destinationLocation, group.id); > } > > // deploy > var bundleversionIndex = (bundleVersionUsr - 1.0) ; > var versionToDeploy = bundle.getBundleVersions().get(bundleversionIndex); > var deployment = BundleManager.createBundleDeployment(versionToDeploy.getId(), destination.getId(), deploymentDesc, new Configuration); > > BundleManager.scheduleBundleDeployment(deployment.getId(), true); >} > >/** > * Get metric data > * > * @param groupName Name of the group > * @metricDisplayName Name of the metric as display in the UE. > */ >function getMetrics(groupName, metricDisplayName){ > var resourceType = ResourceTypeManager.getResourceTypeByNameAndPlugin("JBossAS Server","JBossAS5"); > var group = findGroup(groupName); > > if (group == null){ > throw "Group \"" + groupName + "\" not found." > } > > var measurementDefinition = getMeasurementDefinition(metricDisplayName, resourceType); > > var resourceCriteria = new ResourceCriteria(); > resourceCriteria.addFilterExplicitGroupIds(group.id); > var resource = ResourceManager.findResourcesByCriteria(resourceCriteria).get(0); > var metrics = MeasurementDataManager.findLiveData(resource.id, [measurementDefinition.id]); > > if (metrics == null){ > throw "No metrics found for metric \"" + metricDisplayName + "\"."; > } > > return metrics; >} > >/** > * Export metric data for a Web-AppServer. > * > * @param webAppServerInstanceName Name of the Web-AppServer > * @param metricDisplayName The name of the metric as displayed in the UI > */ >function exportMetricForWebAppServerInstance(webAppServerInstanceName,metricDisplayName){ > var resourceType = ResourceTypeManager.getResourceTypeByNameAndPlugin("JBossAS Server","JBossAS5"); > var webAppServerInstance = findWebAppServerInstance(webAppServerInstanceName); > > if (webAppServerInstance == null){ > throw "WebAppServerInstance \"" + webAppServerInstanceName + "\" was not found." > } > > var metricDefinition = getMeasurementDefinition(metricDisplayName,resourceType); > > > exporter.file = 'metric-'+webAppServerInstanceName.replace(" ","_")+ "-" + metricDisplayName.replace(" ","_"); > exporter.format = 'csv' > var start = new Date() - 8* 3600 * 1000; > var end = new Date() > var data = MeasurementDataManager.findDataForResource(webAppServerInstance.getId(),[metricDefinition.getId()],start,end,60); > exporter.write(data.get(0)); >} > >/** > * Get the measurement definition > * > * @param metricDisplayName Display-name of the metric as in the UE > * @param resourceType The resource-type > */ >function getMeasurementDefinition(metricDisplayName, resourceType){ > var measurementDefinitions = null; > var measurementDefinitionCriteria = new MeasurementDefinitionCriteria; > > measurementDefinitionCriteria.addFilterDisplayName(metricDisplayName); > measurementDefinitionCriteria.addFilterResourceTypeId(resourceType.id); > > measurementDefinitions = MeasurementDefinitionManager.findMeasurementDefinitionsByCriteria(measurementDefinitionCriteria); > > return measurementDefinitions.get(0); >} > >/* > * Import Web-AppServerInstance from the discovery queue > * > * @param typeName The type-name > * @param pluginName The plugin-name > */ > >function importResources(typeName, pluginName) { > var criteria = ResourceCriteria(); > > criteria.addFilterInventoryStatus(InventoryStatus.NEW); > criteria.addFilterPluginName(pluginName); > criteria.addFilterResourceTypeName(typeName); > > var resources = ResourceManager.findResourcesByCriteria(criteria); > var resourceIds = []; > > if (resources.size() > 0) { > for (i = 0; i < resources.size(); i++) { > resource = resources.get(i); > resourceIds[i] = resource.id; > } > } > DiscoveryBoss.importResources(resourceIds); >} > >/** > * Remove item from the inventory > * > * @param resourceName The name of the resource to remove from the inventory > */ >function removeResource(resourceName){ > var criteria = new ResourceCriteria(); > criteria.addFilterName(resourceName); > > var resources = ResourceManager.findResourcesByCriteria(criteria); > var resourceIds = []; > > if (resources.size() > 0) { > for (i = 0; i < resources.size(); i++) { > resource = resources.get(i); > resourceIds[i] = resource.id; > } > } > > ResourceManager.uninventoryResources(resourceIds); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 826235
:
587502
| 587503 |
587504
|
587505
|
587506
|
587507
|
587536