Search in sources :

Example 1 with CaseSchemaNode

use of org.opendaylight.yangtools.yang.model.api.CaseSchemaNode 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 2 with CaseSchemaNode

use of org.opendaylight.yangtools.yang.model.api.CaseSchemaNode in project controller by opendaylight.

the class RuntimeBeanEntryTest method createRuntimeBean.

@Test
public void createRuntimeBean() {
    final CaseSchemaNode caseNode = Mockito.mock(CaseSchemaNode.class);
    doReturn(new HashSet<LeafSchemaNode>()).when(caseNode).getChildNodes();
    doReturn(new ArrayList<UnknownSchemaNode>()).when(caseNode).getUnknownSchemaNodes();
    final Map<String, RuntimeBeanEntry> runtimeBeans = RuntimeBeanEntry.extractClassNameToRuntimeBeanMap(PACKAGE_NAME, caseNode, "test-name", new TypeProviderWrapper(new TypeProviderImpl(this.context)), "test", this.jmxImplModule, this.context);
    assertEquals(1, runtimeBeans.size());
    final RuntimeBeanEntry runtimeMXBean = runtimeBeans.get("testRuntimeMXBean");
    assertTrue(runtimeMXBean.isRoot());
    assertEquals("test-name", runtimeMXBean.getYangName());
}
Also used : CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) TypeProviderImpl(org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl) Test(org.junit.Test)

Example 3 with CaseSchemaNode

use of org.opendaylight.yangtools.yang.model.api.CaseSchemaNode in project controller by opendaylight.

the class ModuleMXBeanEntryBuilder method build.

public Map<String, ModuleMXBeanEntry> build() {
    LOG.debug("Generating ModuleMXBeans of {} to package {}", currentModule.getNamespace(), packageName);
    String configModulePrefix;
    try {
        configModulePrefix = getConfigModulePrefixFromImport(currentModule);
    } catch (IllegalArgumentException e) {
        // this currentModule does not import config currentModule
        return Collections.emptyMap();
    }
    // get identities of base config:currentModule-type
    Map<String, IdentitySchemaNode> moduleIdentities = getIdentityMap();
    Map<String, QName> uniqueGeneratedClassesNames = new HashMap<>();
    // each currentModule name should have an augmentation defined
    Map<String, IdentitySchemaNode> unaugmentedModuleIdentities = new HashMap<>(moduleIdentities);
    Map<String, ModuleMXBeanEntry> result = new HashMap<>();
    for (AugmentationSchemaNode augmentation : currentModule.getAugmentations()) {
        Collection<DataSchemaNode> childNodes = augmentation.getChildNodes();
        if (areAllChildrenCaseSchemaNodes(childNodes)) {
            for (CaseSchemaNode childCase : castChildNodesToChoiceCases(childNodes)) {
                // TODO refactor, extract to standalone builder class
                processCaseSchemaNode(result, uniqueGeneratedClassesNames, configModulePrefix, moduleIdentities, unaugmentedModuleIdentities, augmentation, childCase);
            }
        }
    // skip if child nodes are not all cases
    }
    // clean up nulls
    cleanUpNulls(result);
    // check attributes name uniqueness
    checkAttributeNamesUniqueness(uniqueGeneratedClassesNames, result);
    checkUnaugumentedIdentities(unaugmentedModuleIdentities);
    LOG.debug("Number of ModuleMXBeans to be generated: {}", result.size());
    return result;
}
Also used : AugmentationSchemaNode(org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode) HashMap(java.util.HashMap) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) ConfigConstants.createConfigQName(org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName) IdentitySchemaNode(org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)

Aggregations

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