Search in sources :

Example 1 with NameConflictException

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException in project controller by opendaylight.

the class ModuleMXBeanEntryBuilder method checkUniqueRuntimeBeanAttributesName.

private static void checkUniqueRuntimeBeanAttributesName(final ModuleMXBeanEntry mxBeanEntry, final Map<String, QName> uniqueGeneratedClassesNames) {
    for (RuntimeBeanEntry runtimeBeanEntry : mxBeanEntry.getRuntimeBeans()) {
        for (String runtimeAttName : runtimeBeanEntry.getYangPropertiesToTypesMap().keySet()) {
            if (mxBeanEntry.getAttributes().keySet().contains(runtimeAttName)) {
                QName qName1 = uniqueGeneratedClassesNames.get(runtimeBeanEntry.getJavaNameOfRuntimeMXBean());
                QName qName2 = uniqueGeneratedClassesNames.get(mxBeanEntry.getGloballyUniqueName());
                throw new NameConflictException(runtimeAttName, qName1, qName2);
            }
        }
    }
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ConfigConstants.createConfigQName(org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName) NameConflictException(org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException)

Example 2 with NameConflictException

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException in project controller by opendaylight.

the class ModuleMXBeanEntryBuilder method checkUniqueRuntimeBeansGeneratedClasses.

private static void checkUniqueRuntimeBeansGeneratedClasses(final Map<String, QName> uniqueGeneratedClassesNames, final DataSchemaNode when, final Collection<RuntimeBeanEntry> runtimeBeans) {
    for (RuntimeBeanEntry runtimeBean : runtimeBeans) {
        final String javaNameOfRuntimeMXBean = runtimeBean.getJavaNameOfRuntimeMXBean();
        if (uniqueGeneratedClassesNames.containsKey(javaNameOfRuntimeMXBean)) {
            QName firstDefinedQName = uniqueGeneratedClassesNames.get(javaNameOfRuntimeMXBean);
            throw new NameConflictException(javaNameOfRuntimeMXBean, firstDefinedQName, when.getQName());
        }
        uniqueGeneratedClassesNames.put(javaNameOfRuntimeMXBean, when.getQName());
    }
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ConfigConstants.createConfigQName(org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName) NameConflictException(org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException)

Example 3 with NameConflictException

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException in project controller by opendaylight.

the class ModuleMXBeanEntryBuilder method processCaseSchemaNode.

private <HAS_CHILDREN_AND_QNAME extends DataNodeContainer & SchemaNode> void processCaseSchemaNode(final Map<String, ModuleMXBeanEntry> result, final Map<String, QName> uniqueGeneratedClassesNames, final String configModulePrefix, final Map<String, IdentitySchemaNode> moduleIdentities, final Map<String, IdentitySchemaNode> unaugmentedModuleIdentities, final AugmentationSchemaNode augmentation, final DataSchemaNode when) {
    CaseSchemaNode choiceCaseNode = (CaseSchemaNode) when;
    if (!choiceCaseNode.getWhenCondition().isPresent()) {
        return;
    }
    java.util.Optional<RevisionAwareXPath> xPath = choiceCaseNode.getWhenCondition();
    checkState(xPath.isPresent(), "Choice node %s does not have a when condition", choiceCaseNode);
    Matcher matcher = getWhenConditionMatcher(configModulePrefix, xPath.get());
    if (matcher.matches() == false) {
        return;
    }
    String moduleLocalNameFromXPath = matcher.group(1);
    IdentitySchemaNode moduleIdentity = moduleIdentities.get(moduleLocalNameFromXPath);
    unaugmentedModuleIdentities.remove(moduleLocalNameFromXPath);
    checkState(moduleIdentity != null, "Cannot find identity %s matching augmentation %s", moduleLocalNameFromXPath, augmentation);
    Map<String, QName> providedServices = findProvidedServices(moduleIdentity, currentModule, qNamesToSIEs, schemaContext);
    String javaNamePrefix = TypeProviderWrapper.findJavaNamePrefix(moduleIdentity);
    Map<String, AttributeIfc> yangToAttributes = null;
    // runtime-data
    Collection<RuntimeBeanEntry> runtimeBeans = null;
    HAS_CHILDREN_AND_QNAME dataNodeContainer = getDataNodeContainer(choiceCaseNode);
    if (EXPECTED_CONFIGURATION_AUGMENTATION_SCHEMA_PATH.equals(augmentation.getTargetPath())) {
        LOG.debug("Parsing configuration of {}", moduleLocalNameFromXPath);
        yangToAttributes = fillConfiguration(dataNodeContainer, currentModule, typeProviderWrapper, qNamesToSIEs, schemaContext, packageName);
        checkUniqueAttributesWithGeneratedClass(uniqueGeneratedClassesNames, when.getQName(), yangToAttributes);
    } else if (EXPECTED_STATE_AUGMENTATION_SCHEMA_PATH.equals(augmentation.getTargetPath())) {
        LOG.debug("Parsing state of {}", moduleLocalNameFromXPath);
        try {
            runtimeBeans = fillRuntimeBeans(dataNodeContainer, currentModule, typeProviderWrapper, packageName, moduleLocalNameFromXPath, javaNamePrefix);
        } catch (NameConflictException e) {
            throw new NameConflictException(e.getConflictingName(), when.getQName(), when.getQName());
        }
        checkUniqueRuntimeBeansGeneratedClasses(uniqueGeneratedClassesNames, when, runtimeBeans);
        Set<RuntimeBeanEntry> runtimeBeanEntryValues = Sets.newHashSet(runtimeBeans);
        for (RuntimeBeanEntry entry : runtimeBeanEntryValues) {
            checkUniqueAttributesWithGeneratedClass(uniqueGeneratedClassesNames, when.getQName(), entry.getYangPropertiesToTypesMap());
        }
    } else {
        throw new IllegalArgumentException("Cannot parse augmentation " + augmentation);
    }
    boolean hasDummyContainer = choiceCaseNode.equals(dataNodeContainer) == false;
    String nullableDummyContainerName = hasDummyContainer ? dataNodeContainer.getQName().getLocalName() : null;
    if (result.containsKey(moduleLocalNameFromXPath)) {
        // either fill runtimeBeans or yangToAttributes, merge
        ModuleMXBeanEntry moduleMXBeanEntry = result.get(moduleLocalNameFromXPath);
        if (yangToAttributes != null && moduleMXBeanEntry.getAttributes() == null) {
            moduleMXBeanEntry.setYangToAttributes(yangToAttributes);
        } else if (runtimeBeans != null && moduleMXBeanEntry.getRuntimeBeans() == null) {
            moduleMXBeanEntry.setRuntimeBeans(runtimeBeans);
        }
        checkState(Objects.equals(nullableDummyContainerName, moduleMXBeanEntry.getNullableDummyContainerName()), "Mismatch in module " + moduleMXBeanEntry.toString() + " - dummy container must be present/missing in" + " both state and configuration");
    } else {
        ModuleMXBeanEntry.ModuleMXBeanEntryInitial initial = new ModuleMXBeanEntry.ModuleMXBeanEntryInitialBuilder().setIdSchemaNode(moduleIdentity).setPackageName(packageName).setJavaNamePrefix(javaNamePrefix).setNamespace(currentModule.getNamespace().toString()).setqName(ModuleUtil.getQName(currentModule)).build();
        // construct ModuleMXBeanEntry
        ModuleMXBeanEntry moduleMXBeanEntry = new ModuleMXBeanEntry(initial, yangToAttributes, providedServices, runtimeBeans);
        moduleMXBeanEntry.setYangModuleName(currentModule.getName());
        moduleMXBeanEntry.setYangModuleLocalname(moduleLocalNameFromXPath);
        moduleMXBeanEntry.setNullableDummyContainerName(nullableDummyContainerName);
        result.put(moduleLocalNameFromXPath, moduleMXBeanEntry);
    }
}
Also used : Set(java.util.Set) Matcher(java.util.regex.Matcher) QName(org.opendaylight.yangtools.yang.common.QName) ConfigConstants.createConfigQName(org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName) NameConflictException(org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException) IdentitySchemaNode(org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode) RevisionAwareXPath(org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)

Example 4 with NameConflictException

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException in project controller by opendaylight.

the class ModuleMXBeanEntryNameConflictTest method testNameConflicts.

@Ignore
@Test
public void testNameConflicts() {
    for (final String moduleName : testedModules) {
        final Module testedModule = loadYangs(moduleName, moduleName);
        try {
            LOG.debug("Testing {}", moduleName);
            ModuleMXBeanEntry.create(testedModule, new HashMap<>(), this.context, new TypeProviderWrapper(new TypeProviderImpl(this.context)), PACKAGE_NAME);
            fail(moduleName + " did not cause a name conflict and should");
        } catch (final NameConflictException e) {
            assertEquals(this.testedYangModulesToExpectedConflictingName.get(moduleName), e.getConflictingName());
        }
    }
}
Also used : Module(org.opendaylight.yangtools.yang.model.api.Module) TypeProviderImpl(org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl) NameConflictException(org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

NameConflictException (org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException)4 ConfigConstants.createConfigQName (org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName)3 QName (org.opendaylight.yangtools.yang.common.QName)3 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)1 TypeProviderImpl (org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl)1 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)1 IdentitySchemaNode (org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1 RevisionAwareXPath (org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath)1