Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1069547] Limit the choice of resource groups and destinations
Browse files Browse the repository at this point in the history
based on the bundle type.

Conflicts:

	modules/core/dbutils/pom.xml
	modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
  • Loading branch information
spinder committed Aug 19, 2014
1 parent ee293f8 commit bd08052
Show file tree
Hide file tree
Showing 20 changed files with 695 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
import org.rhq.core.clientapi.descriptor.plugin.Bundle;
import org.rhq.core.clientapi.descriptor.plugin.BundleConfigFullCopy;
import org.rhq.core.clientapi.descriptor.plugin.BundleConfigPropertyReference;
import org.rhq.core.clientapi.descriptor.plugin.BundleDestination;
import org.rhq.core.clientapi.descriptor.plugin.BundleDestinationBaseDir;
import org.rhq.core.clientapi.descriptor.plugin.BundleDestinationDefinition;
import org.rhq.core.clientapi.descriptor.plugin.BundleTargetDescriptor;
import org.rhq.core.clientapi.descriptor.plugin.BundleTargetDescriptor.DestinationBaseDir;
import org.rhq.core.clientapi.descriptor.plugin.BundleTraitReference;
import org.rhq.core.clientapi.descriptor.plugin.ContentDescriptor;
import org.rhq.core.clientapi.descriptor.plugin.DiscoveryCallbacksType;
Expand Down Expand Up @@ -171,7 +173,34 @@ public void parseDescriptor() throws InvalidPluginDescriptorException {
// case we are defining callbacks on types in our own plugin
parseDiscoveryCallbacks();

return;
parseBundleTypeTargets();
}

private void parseBundleTypeTargets() {
parseBundleTypeTarget(pluginDescriptor.getPlatforms());
parseBundleTypeTarget(pluginDescriptor.getServers());
parseBundleTypeTarget(pluginDescriptor.getServices());
}

private void parseBundleTypeTarget(List<? extends ResourceDescriptor> resourceTypes) {
for (ResourceDescriptor d : resourceTypes) {
if (d.getBundle() != null) {
ResourceType rt = getResourceTypeFromPlugin(d.getName(), pluginDescriptor.getName());
BundleType bt = rt.getBundleType();
parseBundleTypeTarget(bt, d.getBundle().getTargets());
}
}
}

private void parseBundleTypeTarget(BundleType bundleType, Bundle.Targets target) {
if (target == null) {
return;
}

for (Bundle.Targets.ResourceType ref : target.getResourceType()) {
ResourceType rt = getResourceTypeFromPlugin(ref.getName(), ref.getPlugin());
bundleType.addTargetedResourceType(rt);
}
}

private void parseDiscoveryCallbacks() throws InvalidPluginDescriptorException {
Expand Down Expand Up @@ -613,31 +642,40 @@ private void parseResourceDescriptor(ResourceDescriptor resourceDescriptor, Reso
if (bundle != null) {
String typeName = bundle.getType();
resourceType.setBundleType(new BundleType(typeName, resourceType));
// do NOT parse the target types of bundle type right now so that we don't
// require the plugin writer to order the types herself
}

BundleTargetDescriptor bundleTarget = resourceDescriptor.getBundleTarget();
if (bundleTarget != null) {
List<Object> destDefs = bundleTarget.getDestinationBaseDirOrDestinationDefinition();
List<BundleDestination> destDefs = bundleTarget.getDestinationBaseDirOrDestinationDefinition();
if (destDefs != null && destDefs.size() > 0) {
Configuration c = new Configuration();
ResourceTypeBundleConfiguration bundleConfiguration = new ResourceTypeBundleConfiguration(c);
for (Object destDef : destDefs) {
if (destDef instanceof DestinationBaseDir) {
DestinationBaseDir destBaseDir = (DestinationBaseDir) destDef;
for (BundleDestination destDef : destDefs) {
if (destDef instanceof BundleDestinationBaseDir) {
BundleDestinationBaseDir destBaseDir = (BundleDestinationBaseDir) destDef;
String name = destBaseDir.getName();
String valueContext = destBaseDir.getValueContext();
String valueName = destBaseDir.getValueName();
String description = destBaseDir.getDescription();
List<String> accepts = new ArrayList<String>();
for(BundleDestination.Accepts accept : destBaseDir.getAccepts()) {
accepts.add(accept.getBundleType());
}
bundleConfiguration.addBundleDestinationBaseDirectory(name, valueContext, valueName,
description);
} else if (destDef instanceof BundleTargetDescriptor.DestinationDefinition) {
BundleTargetDescriptor.DestinationDefinition def =
(BundleTargetDescriptor.DestinationDefinition) destDef;
description, accepts);
} else if (destDef instanceof BundleDestinationDefinition) {
BundleDestinationDefinition def = (BundleDestinationDefinition) destDef;

ResourceTypeBundleConfiguration.BundleDestinationDefinition.Builder bld = bundleConfiguration
.createDestinationDefinitionBuilder(def.getName());
bld.withDescription(def.getDescription()).withConnectionString(def.getConnection());

for (BundleDestination.Accepts accept : def.getAccepts()) {
bld.addAcceptedBundleType(accept.getBundleType());
}

for (JAXBElement<?> ref : def.getReferencedConfiguration()
.getMapPropertyRefOrListPropertyRefOrSimplePropertyRef()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.artifact.versioning.ComparableVersion;
Expand All @@ -55,9 +54,11 @@
import org.rhq.core.clientapi.agent.metadata.PluginDependencyGraph;
import org.rhq.core.clientapi.agent.metadata.PluginDependencyGraph.PluginDependency;
import org.rhq.core.clientapi.descriptor.group.expressions.CannedGroupExpressions;
import org.rhq.core.clientapi.descriptor.plugin.Bundle;
import org.rhq.core.clientapi.descriptor.plugin.ParentResourceType;
import org.rhq.core.clientapi.descriptor.plugin.PlatformDescriptor;
import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
import org.rhq.core.clientapi.descriptor.plugin.ResourceDescriptor;
import org.rhq.core.clientapi.descriptor.plugin.RunsInsideType;
import org.rhq.core.clientapi.descriptor.plugin.ServerDescriptor;
import org.rhq.core.clientapi.descriptor.plugin.ServiceDescriptor;
Expand Down Expand Up @@ -233,6 +234,8 @@ private static void addOptionalDependency(PlatformDescriptor platform,
}

addOptionalDependency(platform.getRunsInside(), dependencies);

addOptionalBundleDependency(platform, dependencies);
return;
}

Expand All @@ -247,6 +250,9 @@ private static void addOptionalDependency(ServerDescriptor server,

addOptionalDependency(server.getRunsInside(), dependencies);
addOptionalDependency(server.getSourcePlugin(), dependencies);


addOptionalBundleDependency(server, dependencies);
return;
}

Expand All @@ -258,7 +264,8 @@ private static void addOptionalDependency(ServiceDescriptor service,

addOptionalDependency(service.getRunsInside(), dependencies);
addOptionalDependency(service.getSourcePlugin(), dependencies);
return;

addOptionalBundleDependency(service, dependencies);
}

private static void addOptionalDependency(RunsInsideType runsInside,
Expand All @@ -273,6 +280,14 @@ private static void addOptionalDependency(RunsInsideType runsInside,
return;
}

private static void addOptionalBundleDependency(ResourceDescriptor resource, List<PluginDependency> dependencies) {
if (resource.getBundle() != null && resource.getBundle().getTargets() != null) {
for (Bundle.Targets.ResourceType t : resource.getBundle().getTargets().getResourceType()) {
addOptionalDependency(t.getPlugin(), dependencies);
}
}
}

private static void addOptionalDependency(String pluginName,
List<PluginDependencyGraph.PluginDependency> dependencies) {

Expand All @@ -291,7 +306,6 @@ private static void addOptionalDependency(String pluginName,
/**
* Retrieves file content as string from given jar
* @param pluginJarFileUrl URL to a plugin jar file
* @param additionPath addition file path within JAR (eg. META-INF/mydescriptor.xml)
* @return content of additionPath file as String, or null if file does not exist in JAR
* @throws PluginContainerException if we fail to read content
*/
Expand Down
Loading

0 comments on commit bd08052

Please sign in to comment.