private static Resource convertToPojoResource(Resource resource, boolean includeDescendants) { Resource pojoResource = new Resource(resource.getId()); pojoResource.setUuid(resource.getUuid()); pojoResource.setResourceKey(resource.getResourceKey()); pojoResource.setResourceType(resource.getResourceType()); pojoResource.setMtime(resource.getMtime()); pojoResource.setInventoryStatus(resource.getInventoryStatus()); Configuration pcCopy = resource.getPluginConfiguration(); if (pcCopy != null) { pcCopy = pcCopy.deepCopy(); } pojoResource.setPluginConfiguration(pcCopy); pojoResource.setName(resource.getName()); pojoResource.setDescription(resource.getDescription()); pojoResource.setLocation(resource.getLocation()); pojoResource.setVersion(resource.getVersion()); if (resource.getParentResource() != null) { pojoResource.setParentResource(convertToPojoResource(resource.getParentResource(), false)); } if (includeDescendants) { for (Resource childResource : resource.getChildResources()) { if (isVisibleInInventory(childResource)) { pojoResource.addChildResource(convertToPojoResource(childResource, true)); } } } return pojoResource; }
public MockInventoryManager() { super(pcConfig, null, pluginManager, new EventManager(pcConfig)); platformType = new ResourceType( "platformResourceTypeName", "pluginName", ResourceCategory.PLATFORM, null); bundleHandlerType = new ResourceType("bhRTypeName", "pluginName", ResourceCategory.SERVER, platformType); serverTypeFS = new ResourceType( "typeName-fileSystem", "pluginName", ResourceCategory.SERVER, platformType); serverTypePC = new ResourceType( "typeName-plugConfig", "pluginName", ResourceCategory.SERVER, platformType); serverTypeRC = new ResourceType( "typeName-reSconfig", "pluginName", ResourceCategory.SERVER, platformType); serverTypeMT = new ResourceType("typeName-trait", "pluginName", ResourceCategory.SERVER, platformType); int id = 1; platform = new Resource("platformKey", "platformName", platformType); platform.setId(id++); bundleHandler = new Resource("bhKey", "bhName", bundleHandlerType); bundleHandler.setId(id++); bundleHandler.setParentResource(platform); bundleHandler.setUuid(UUID.randomUUID().toString()); serverFS = new Resource("serverKey-fileSystem", "serverName-fileSystem", serverTypeFS); serverFS.setId(id++); serverFS.setParentResource(platform); serverPC = new Resource("serverKey-plugConfig", "serverName-plugConfig", serverTypePC); serverPC.setId(id++); serverPC.setParentResource(platform); serverRC = new Resource("serverKey-resConfig", "serverName-resConfig", serverTypeRC); serverRC.setId(id++); serverRC.setParentResource(platform); serverMT = new Resource("serverKey-traitConfig", "serverName-traitConfig", serverTypeMT); serverMT.setId(id++); serverMT.setParentResource(platform); typeResourceMap.put(platformType, platform); typeResourceMap.put(bundleHandlerType, bundleHandler); typeResourceMap.put(serverTypeFS, serverFS); typeResourceMap.put(serverTypePC, serverPC); typeResourceMap.put(serverTypeRC, serverRC); typeResourceMap.put(serverTypeMT, serverMT); ResourceContainer platformContainer = new ResourceContainer(platform, null); ResourceContainer bundleHandlerContainer = new ResourceContainer(bundleHandler, null); ResourceContainer serverContainerFS = new ResourceContainer(serverFS, null); ResourceContainer serverContainerPC = new ResourceContainer(serverPC, null); ResourceContainer serverContainerRC = new ResourceContainer(serverRC, null); ResourceContainer serverContainerMT = new ResourceContainer(serverMT, null); idResourceContainerMap.put(platform.getId(), platformContainer); idResourceContainerMap.put(bundleHandler.getId(), bundleHandlerContainer); idResourceContainerMap.put(serverFS.getId(), serverContainerFS); idResourceContainerMap.put(serverPC.getId(), serverContainerPC); idResourceContainerMap.put(serverRC.getId(), serverContainerRC); idResourceContainerMap.put(serverMT.getId(), serverContainerMT); bundleHandlerContainer.setResourceContext(new MockResourceContext(bundleHandler)); // each different resource type that supports bundle deployments needs to define its // bundle configuration to denote where the base directory location is found. // Today we support four ways: via plugin config property, resource config property, // measurement trait value, or strictly on the root file system (using no resource specific // value) ResourceTypeBundleConfiguration rtbc = new ResourceTypeBundleConfiguration(new Configuration()); rtbc.addBundleDestinationBaseDirectory( BUNDLE_CONFIG_NAME_FS, Context.fileSystem.name(), BUNDLE_CONFIG_CONTEXT_VALUE_FS, null); serverTypeFS.setResourceTypeBundleConfiguration(rtbc); rtbc = new ResourceTypeBundleConfiguration(new Configuration()); rtbc.addBundleDestinationBaseDirectory( BUNDLE_CONFIG_NAME_PC, Context.pluginConfiguration.name(), BUNDLE_CONFIG_CONTEXT_VALUE_PC, null); serverTypePC.setResourceTypeBundleConfiguration(rtbc); rtbc = new ResourceTypeBundleConfiguration(new Configuration()); rtbc.addBundleDestinationBaseDirectory( BUNDLE_CONFIG_NAME_RC, Context.resourceConfiguration.name(), BUNDLE_CONFIG_CONTEXT_VALUE_RC, null); serverTypeRC.setResourceTypeBundleConfiguration(rtbc); rtbc = new ResourceTypeBundleConfiguration(new Configuration()); rtbc.addBundleDestinationBaseDirectory( BUNDLE_CONFIG_NAME_MT, Context.measurementTrait.name(), BUNDLE_CONFIG_CONTEXT_VALUE_MT, null); serverTypeMT.setResourceTypeBundleConfiguration(rtbc); // each different resource needs to specify where exactly it wants the bundles deployed // using the different contexts that are supported. Configuration pluginConfiguration = new Configuration(); pluginConfiguration.put( new PropertySimple(BUNDLE_CONFIG_CONTEXT_VALUE_PC, BUNDLE_CONFIG_LOCATION_PC)); serverPC.setPluginConfiguration(pluginConfiguration); Configuration resourceConfiguration = new Configuration(); resourceConfiguration.put( new PropertySimple(BUNDLE_CONFIG_CONTEXT_VALUE_RC, BUNDLE_CONFIG_LOCATION_RC)); serverRC.setResourceConfiguration(resourceConfiguration); MeasurementDefinition definition = new MeasurementDefinition(serverTypeMT, BUNDLE_CONFIG_CONTEXT_VALUE_MT); definition.setDataType(DataType.TRAIT); definition.setId(123); MeasurementSchedule schedule = new MeasurementSchedule(definition, serverMT); schedule.setId(123123); MeasurementScheduleRequest scheduleRequest = new MeasurementScheduleRequest(schedule); Set<MeasurementScheduleRequest> schedules = new HashSet<MeasurementScheduleRequest>(1); schedules.add(scheduleRequest); serverContainerMT.setMeasurementSchedule(schedules); }