Package org.rhq.core.domain.configuration

Examples of org.rhq.core.domain.configuration.PropertyMap


    }

    protected Property translateMapProperty(MapPropertyType object, String defaultName) {
        String name = object.getName();
        List<Object> mapXml = object.getSimplePropertyOrListPropertyOrMapProperty();
        PropertyMap map = new PropertyMap((name != null) ? name : defaultName);
        for (Object mapItem : mapXml) {
            if (mapItem instanceof SimplePropertyType) {
                map.put(translateSimpleProperty((SimplePropertyType) mapItem, null));
            } else if (mapItem instanceof ListPropertyType) {
                map.put(translateListProperty((ListPropertyType) mapItem, null));
            } else if (mapItem instanceof MapPropertyType) {
                map.put(translateMapProperty((MapPropertyType) mapItem, null));
            } else {
                throw new IllegalStateException("Unknown JAXB type: " + object); // did the schema change?
            }
        }
        return map;
View Full Code Here


        }

        // Build a new list containing the event sources that are enabled.
        List<PropertyMap> enabledEventSources = new ArrayList<PropertyMap>();
        for (Property prop : logEventSources.getList()) {
            PropertyMap logEventSource = (PropertyMap) prop;
            String enabled = logEventSource.getSimpleValue(LogEventSourcePropertyNames.ENABLED, null);
            if (enabled == null) {
                throw new IllegalStateException("Required property [" + LogEventSourcePropertyNames.ENABLED
                                    + "] is not defined in map.");
            }
            if (Boolean.valueOf(enabled)) {
                enabledEventSources.add(logEventSource);
            }
        }

        // Log a warning then return if SIGAR isn't available, since LogFileEventPoller depends on it. We only log this
        // warning if at least one event source is enabled, since otherwise the user probably doesn't care.
        boolean sigarAvailable = this.resourceContext.getSystemInformation().isNative();
        if (!sigarAvailable && !enabledEventSources.isEmpty()) {
            boolean nativeSystemInfoDisabled = SystemInfoFactory.isNativeSystemInfoDisabled();
            ResourceType resourceType = this.resourceContext.getResourceType();
            List<String> logFilePaths = getLogFilePaths(enabledEventSources);
            LOG.warn("Log files " + logFilePaths + " for [" + resourceType.getPlugin() + ":"
                + resourceType.getName() + "] Resource with key [" + this.resourceContext.getResourceKey()
                + "] cannot be polled, because log file polling requires RHQ native support, which "
                + ((nativeSystemInfoDisabled) ? "has been disabled for this Agent" : "is not available on this platform") + ".");
            return;
        }

        // Start up log file pollers for each of the enabled event sources.
        for (PropertyMap logEventSource : enabledEventSources) {
            String logFilePath = logEventSource.getSimpleValue(LogEventSourcePropertyNames.LOG_FILE_PATH, null);
            if (logFilePath == null) {
                throw new IllegalStateException("Required property [" + LogEventSourcePropertyNames.LOG_FILE_PATH
                                    + "] is not defined in map.");
            }
            File logFile = new File(logFilePath);
            if (!logFile.canRead()) {
                LOG.warn("LOGFILE: Logfile at location " + logFilePath + " does not exist or is not readable. "
                    + "The poller will be started but no events will be polled until the file is created.");
            }

            Log4JLogEntryProcessor processor = new Log4JLogEntryProcessor(LOG_ENTRY_EVENT_TYPE, logFile);
            String dateFormatString = logEventSource.getSimpleValue(LogEventSourcePropertyNames.DATE_FORMAT, null);
            if (dateFormatString != null) {
                try {
                    DateFormat dateFormat = new SimpleDateFormat(dateFormatString); // TODO locale specific ?
                    processor.setDateFormat(dateFormat);
                } catch (IllegalArgumentException e) {
                    throw new InvalidPluginConfigurationException("Date format [" + dateFormatString
                        + "] is not a valid simple date format.");
                }
            }
            String includesPatternString = logEventSource.getSimpleValue(
                LogEventSourcePropertyNames.INCLUDES_PATTERN, null);
            if (includesPatternString != null) {
                try {
                    Pattern includesPattern = Pattern.compile(includesPatternString);
                    processor.setIncludesPattern(includesPattern);
                } catch (PatternSyntaxException e) {
                    throw new InvalidPluginConfigurationException("Includes pattern [" + includesPatternString
                        + "] is not a valid regular expression.");
                }
            }
            String minimumSeverityString = logEventSource.getSimpleValue(
                LogEventSourcePropertyNames.MINIMUM_SEVERITY, null);
            if (minimumSeverityString != null) {
                EventSeverity minimumSeverity = EventSeverity.valueOf(minimumSeverityString.toUpperCase());
                processor.setMinimumSeverity(minimumSeverity);
            }
View Full Code Here

        if (!sigarAvailable) {
            return;
        }

        for (Iterator<PropertyMap> iterator = this.startedEventSources.iterator(); iterator.hasNext(); ) {
            PropertyMap logEventSource = iterator.next();
            EventContext eventContext = this.resourceContext.getEventContext();
            String logFilePath = logEventSource.getSimpleValue(LogEventSourcePropertyNames.LOG_FILE_PATH, null);
            eventContext.unregisterEventPoller(LOG_ENTRY_EVENT_TYPE, logFilePath);
            iterator.remove();
        }
    }
View Full Code Here

                new PropertyDefinitionSimple("prop2", "prop2 descr", false, PropertySimpleType.PASSWORD)));
        def.put(listDef);

        Configuration config = new Configuration();
        PropertyList list =
            new PropertyList("list", new PropertyMap("map", new PropertySimple("prop1", "value1"), new PropertySimple(
                "prop2", "value1")), new PropertyMap("map", new PropertySimple("prop1", "value2"), new PropertySimple(
                "prop2", "value2")));
        config.put(list);

        ConfigurationInstanceDescriptor instance =
            ConfigurationInstanceDescriptorUtil.createConfigurationInstance(def, config);
View Full Code Here

        assertEquals(propDef.getClass(), PropertyDefinitionMap.class, "Unexpected type of the property definition");
        assertEquals(prop.getClass(), PropertyMap.class, "Unexpecetd type of the property");

        PropertyDefinitionMap mapDef = (PropertyDefinitionMap) propDef;
        PropertyMap mapProp = (PropertyMap) prop;

        assertEquals(mapDef.getMap().size(), 2, "Unexpected number of map member definitions");
        assertEquals(mapProp.getMap().size(), 2, "Unexpected number of map members");

        PropertyDefinition m1Def = mapDef.get("m1");
        PropertyDefinition m2Def = mapDef.get("m2");
        Property m1Prop = mapProp.get("m1");
        Property m2Prop = mapProp.get("m2");

        assertEquals(m1Def.getClass(), PropertyDefinitionSimple.class);
        assertEquals(m2Def.getClass(), PropertyDefinitionSimple.class);
        assertEquals(m1Prop.getClass(), PropertySimple.class);
        assertEquals(m2Prop.getClass(), PropertySimple.class);
View Full Code Here

        assertEquals(m1Def.getType(), PropertySimpleType.INTEGER);
        assertEquals(m2Def.getType(), PropertySimpleType.STRING);

        assertEquals(listProp.getList().size(), 2, "Unexpected number of maps in the list");

        PropertyMap firstMapValue = (PropertyMap) listProp.getList().get(0);
        PropertyMap secondMapValue = (PropertyMap) listProp.getList().get(1);

        assertEquals(firstMapValue.getName(), "map");
        assertEquals(secondMapValue.getName(), "map");

        assertEquals(firstMapValue.getSimpleValue("m1", null), "1", "Unexpected value of m1 property in the first map.");
        assertEquals(firstMapValue.getSimpleValue("m2", null), "m1", "Unexpected value of m2 property in the first map.");

        assertEquals(secondMapValue.getSimpleValue("m1", null), "2", "Unexpected value of m1 property in the second map.");
        assertEquals(secondMapValue.getSimpleValue("m2", null), "m2", "Unexpected value of m2 property in the second map.");
    }
View Full Code Here

                results.put(list);

                Collection<Distro> distros = getAllCobblerDistros().values();
                for (Distro d : distros) {
                    if (pattern == null || pattern.matcher(d.getName()).matches()) {
                        PropertyMap map = new PropertyMap("distro");
                        map.put(new PropertySimple("name", d.getName()));
                        map.put(new PropertySimple("breed", d.getBreed()));
                        map.put(new PropertySimple("osversion", d.getOsVersion()));
                        map.put(new PropertySimple("arch", d.getArch()));
                        map.put(new PropertySimple("initrd", d.getInitrd()));
                        map.put(new PropertySimple("kernel", d.getKernel()));
                        list.add(map);
                    }
                }
            } else if (name.equals("getCobblerProfiles")) {
                String searchRegex = parameters.getSimpleValue("searchRegex", null);
                Pattern pattern = null;
                if (searchRegex != null) {
                    pattern = Pattern.compile(searchRegex);
                }

                Configuration results = controlResults.getComplexResults();
                PropertyList list = new PropertyList("profiles");
                results.put(list);

                List<Profile> profiles = getAllCobblerProfiles();
                for (Profile p : profiles) {
                    if (pattern == null || pattern.matcher(p.getName()).matches()) {
                        PropertyMap map = new PropertyMap("profile");
                        map.put(new PropertySimple("name", p.getName()));
                        map.put(new PropertySimple("distro", p.getDistro()));
                        map.put(new PropertySimple("kickstart", p.getKickstart()));
                        list.add(map);
                    }
                }
            } else if (name.equals("removeCobblerDistros")) {
                String searchRegex = parameters.getSimpleValue("searchRegex", null);
View Full Code Here

                            list.setName(refProp.getTargetName());

                            transferred.put(list);
                            break;
                        case MAP:
                            PropertyMap map = pluginConfiguration.getMap(refProp.getName()).deepCopy(false);
                            map.setName(refProp.getTargetName());

                            transferred.put(map);
                            break;
                        case SIMPLE:
                            PropertySimple simple = pluginConfiguration.getSimple(refProp.getName()).deepCopy(false);
                            simple.setName(refProp.getTargetName());

                            transferred.put(simple);
                            break;
                        case FULL:
                            for (Property p : pluginConfiguration.getProperties()) {
                                Property copy = p.deepCopy(false);
                                if (refProp.getTargetName() != null) {
                                    copy.setName(refProp.getTargetName() + copy.getName());
                                }
                                transferred.put(copy);
                            }
                            break;
                        }
                        break;
                    case RESOURCE_CONFIGURATION:
                        switch (refProp.getType()) {
                        case LIST:
                            PropertyList list = resourceConfiguration.getList(refProp.getName()).deepCopy(false);
                            list.setName(refProp.getTargetName());

                            transferred.put(list);
                            break;
                        case MAP:
                            PropertyMap map = resourceConfiguration.getMap(refProp.getName()).deepCopy(false);
                            map.setName(refProp.getTargetName());

                            transferred.put(map);
                            break;
                        case SIMPLE:
                            PropertySimple simple = resourceConfiguration.getSimple(refProp.getName()).deepCopy(false);
View Full Code Here

        Property prop = config.get("Inner");
        assert prop!=null;
        assert prop instanceof PropertyMap : "Inner is no map";

        PropertyMap pm = (PropertyMap) prop;
        Map<String, Property> innerMap = pm.getMap();
        assert innerMap.size()==1;

        assert inner.containsKey("Foo");

    }
View Full Code Here

        assert prop instanceof PropertyList : "list is no list";

        PropertyList pl = (PropertyList) prop;
        List<Property> propertyList = pl.getList();
        assert propertyList.size()==1;
        PropertyMap innerMapProperty = (PropertyMap) propertyList.get(0);

        Map<String, Property> propertyMap = innerMapProperty.getMap();
        assert propertyMap.size()==1;
        Map<String,Property> innerMap = propertyMap;

        assert innerMap.containsKey("Foo");
        Property property = innerMapProperty.get("Foo");
        assert property != null;
        assert property instanceof PropertySimple;
        PropertySimple ps = (PropertySimple) property;
        assert ps.getStringValue().equals("Bar");
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.configuration.PropertyMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.