Search in sources :

Example 1 with FtlTemplate

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate in project controller by opendaylight.

the class CodeWriter method writeMbe.

public List<File> writeMbe(final ModuleMXBeanEntry mbe, final File targetBaseDir, final File mainBaseDir) {
    try {
        List<File> generatedFiles = Lists.newArrayList();
        Map<GeneratedObject, Boolean> /*overwrite*/
        gos = new HashMap<>();
        // generate mx interface and abstract factory
        // TOs
        Map<String, GeneralClassTemplate> tosFromMbe = TemplateFactory.tOsFromMbe(mbe);
        for (GeneralClassTemplate template : tosFromMbe.values()) {
            gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(template, COPYRIGHT), true);
        }
        // MXBean interface
        GeneralInterfaceTemplate ifcTemplate = TemplateFactory.mXBeanInterfaceTemplateFromMbe(mbe);
        gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(ifcTemplate, COPYRIGHT), true);
        // generate abstract factory
        gos.put(new AbsFactoryGeneratedObjectFactory().toGeneratedObject(mbe, COPYRIGHT), true);
        // generate abstract module
        gos.put(new AbsModuleGeneratedObjectFactory().toGeneratedObject(mbe, COPYRIGHT), true);
        // generate concrete factory
        StubFactoryTemplate concreteFactory = TemplateFactory.stubFactoryTemplateFromMbe(mbe);
        gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(concreteFactory, COPYRIGHT), false);
        // generate concrete module
        gos.put(new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(mbe, COPYRIGHT, Optional.<String>absent()), false);
        // write runtime bean MXBeans and registrators
        List<FtlTemplate> allFtlFiles = getRuntimeBeanFtlTemplates(mbe.getRuntimeBeans());
        for (FtlTemplate template : allFtlFiles) {
            gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(template, COPYRIGHT), true);
        }
        generatedFiles.addAll(persistGeneratedObjects(targetBaseDir, mainBaseDir, gos));
        // purge nulls
        for (Iterator<File> it = generatedFiles.iterator(); it.hasNext(); ) {
            if (it.next() == null) {
                it.remove();
            }
        }
        return generatedFiles;
    } catch (Exception e) {
        String message = "An error occurred during Module generating, mbe:" + mbe.getJavaNamePrefix();
        LOG.error(message, e);
        throw new RuntimeException(message, e);
    }
}
Also used : GeneralInterfaceTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate) HashMap(java.util.HashMap) GeneralClassTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate) AbsFactoryGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsFactoryGeneratedObjectFactory) GenericGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.GenericGeneratedObjectFactory) IOException(java.io.IOException) ConcreteModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.ConcreteModuleGeneratedObjectFactory) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) StubFactoryTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.StubFactoryTemplate) AbsModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsModuleGeneratedObjectFactory) FtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate) RuntimeRegistratorFtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate) File(java.io.File)

Example 2 with FtlTemplate

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate in project controller by opendaylight.

the class ModuleMXBeanEntryPluginTest method testThreadsJavaPlugin.

@Test
public void testThreadsJavaPlugin() {
    Map<String, ModuleMXBeanEntry> /* identity local name */
    namesToMBEs = loadThreadsJava();
    {
        // check threadfactory-naming
        ModuleMXBeanEntry threadFactoryNaming = namesToMBEs.get(THREADFACTORY_NAMING_MXB_NAME);
        Collection<RuntimeBeanEntry> runtimeBeans = threadFactoryNaming.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(4));
        // first one should be root
        {
            RuntimeBeanEntry rootRB = findFirstByYangName(runtimeBeans, THREADFACTORY_NAMING_MXB_NAME);
            assertThat(rootRB.isRoot(), is(true));
            assertThat(rootRB.getAttributes().size(), is(1));
            JavaAttribute attribute = (JavaAttribute) rootRB.getAttributes().iterator().next();
            assertThat(attribute.getAttributeYangName(), is("created-sessions"));
            assertThat(rootRB.getYangName(), is(THREADFACTORY_NAMING_MXB_NAME));
            Map<String, FtlTemplate> ftlMap = TemplateFactory.getTOAndMXInterfaceFtlFiles(rootRB);
            assertThat(ftlMap.size(), is(1));
            GeneralInterfaceTemplate rootGeneratorInterface = (GeneralInterfaceTemplate) ftlMap.get("NamingThreadFactoryRuntimeMXBean.java");
            assertNotNull(rootGeneratorInterface);
            assertThat(rootGeneratorInterface.getPackageName(), is(PACKAGE_NAME));
            assertThat(rootGeneratorInterface.getFullyQualifiedName(), is(PACKAGE_NAME + ".NamingThreadFactoryRuntimeMXBean"));
            assertThat(rootGeneratorInterface.getTypeDeclaration().getExtended(), is(Arrays.asList("org.opendaylight.controller.config.api.runtime.RuntimeBean")));
            assertThat(rootGeneratorInterface.getMethods().size(), is(1));
            Method getCreatedSessions = findFirstMethodByName(rootGeneratorInterface.getMethods(), "getCreatedSessions");
            assertThat(getCreatedSessions.getName(), is("getCreatedSessions"));
            assertThat(getCreatedSessions.getParameters().isEmpty(), is(true));
            assertThat(getCreatedSessions.getReturnType(), is(Long.class.getName()));
        }
    }
    {
        ModuleMXBeanEntry threadFactoryNaming = namesToMBEs.get(THREADFACTORY_NAMING_MXB_NAME);
        Collection<RuntimeBeanEntry> runtimeBeans = threadFactoryNaming.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(4));
        {
            RuntimeBeanEntry streamRB = findFirstByNamePrefix(runtimeBeans, "ThreadStream");
            assertNotNull(streamRB);
            assertFalse(streamRB.getKeyYangName().isPresent());
            assertFalse(streamRB.getKeyJavaName().isPresent());
            Map<String, AttributeIfc> attributeMap = streamRB.getYangPropertiesToTypesMap();
            assertEquals(4, attributeMap.size());
            TOAttribute toAttr = (TOAttribute) attributeMap.get("peer");
            assertNotNull(toAttr);
            JavaAttribute timestampAttr = (JavaAttribute) attributeMap.get("timestamp");
            assertNotNull(timestampAttr);
            JavaAttribute stateAttr = (JavaAttribute) attributeMap.get("state");
            assertNotNull(stateAttr);
            ListAttribute innerStreamList = (ListAttribute) attributeMap.get("inner-stream-list");
            assertNotNull(innerStreamList);
            Map<String, FtlTemplate> ftlMap = TemplateFactory.getTOAndMXInterfaceFtlFiles(streamRB);
            assertThat(ftlMap.size(), is(3));
            GeneralInterfaceTemplate streamGeneralInterface = (GeneralInterfaceTemplate) ftlMap.get("ThreadStreamRuntimeMXBean.java");
            assertThat(streamGeneralInterface.getMethods().size(), is(4));
            Method getPeer = findFirstMethodByName(streamGeneralInterface.getMethods(), "getPeer");
            assertNotNull(getPeer);
            assertThat(getPeer.getReturnType(), is(PACKAGE_NAME + ".Peer"));
            // test TO
            GeneralClassTemplate peerTO = (GeneralClassTemplate) ftlMap.get("pack2.Peer");
            assertThat(peerTO.getPackageName(), is(PACKAGE_NAME));
            assertThat(peerTO.getTypeDeclaration().getExtended().isEmpty(), is(true));
            assertThat(peerTO.getFullyQualifiedName(), is(PACKAGE_NAME + ".Peer"));
            assertThat(peerTO.getMethods().size(), is(5 + 2));
            Method getPort = findFirstMethodByName(peerTO.getMethods(), "getPort");
            assertNotNull(getPort);
            Method setPort = findFirstMethodByName(peerTO.getMethods(), "setPort");
            assertNotNull(setPort);
            Method getCoreSize = findFirstMethodByName(peerTO.getMethods(), "getCoreSize");
            Method setCoreSize = findFirstMethodByName(peerTO.getMethods(), "setCoreSize");
            assertNotNull(setCoreSize);
            assertNotNull(getCoreSize);
        }
    }
}
Also used : GeneralInterfaceTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate) RuntimeBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry) GeneralClassTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate) Method(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method) TOAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) Collection(java.util.Collection) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) FtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute) Test(org.junit.Test) ModuleMXBeanEntryTest(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntryTest)

Example 3 with FtlTemplate

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate in project controller by opendaylight.

the class RuntimeRegistratorFtlFileTest method testRootWithoutAnything.

@Test
public void testRootWithoutAnything() {
    RuntimeBeanEntry rootRB = prepareRootRB(Collections.<RuntimeBeanEntry>emptyList());
    Map<String, FtlTemplate> createdFtls = RuntimeRegistratorFtlTemplate.create(rootRB);
    assertThat(createdFtls.size(), is(2));
    String rootRegistratorName = RuntimeRegistratorFtlTemplate.getJavaNameOfRuntimeRegistration(rootRB.getJavaNamePrefix());
    FtlTemplate rootFtlFile = createdFtls.get(rootRegistratorName);
    assertNotNull(rootFtlFile);
    assertThat(createdFtls.values().size(), is(2));
}
Also used : RuntimeBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry) RuntimeRegistratorFtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate) FtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate) RuntimeRegistratorTest(org.opendaylight.controller.config.yangjmxgenerator.RuntimeRegistratorTest) Test(org.junit.Test)

Example 4 with FtlTemplate

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate in project controller by opendaylight.

the class RuntimeRegistratorFtlFileTest method testHierarchy2.

@Test
public void testHierarchy2() {
    RuntimeBeanEntry grandChildRB = prepareChildRB(Collections.<RuntimeBeanEntry>emptyList(), "grand");
    RuntimeBeanEntry childRB = prepareChildRB(Arrays.asList(grandChildRB), "");
    RuntimeBeanEntry rootRB = prepareRootRB(Arrays.asList(childRB));
    Map<String, FtlTemplate> createdFtls = RuntimeRegistratorFtlTemplate.create(rootRB);
    assertThat(createdFtls.values().size(), is(4));
}
Also used : RuntimeBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry) RuntimeRegistratorFtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate) FtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate) RuntimeRegistratorTest(org.opendaylight.controller.config.yangjmxgenerator.RuntimeRegistratorTest) Test(org.junit.Test)

Aggregations

FtlTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate)4 Test (org.junit.Test)3 RuntimeBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry)3 RuntimeRegistratorFtlTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate)3 RuntimeRegistratorTest (org.opendaylight.controller.config.yangjmxgenerator.RuntimeRegistratorTest)2 GeneralClassTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate)2 GeneralInterfaceTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate)2 File (java.io.File)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ModuleMXBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)1 ModuleMXBeanEntryTest (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntryTest)1 AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)1 JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)1 ListAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)1 TOAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute)1 StubFactoryTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.StubFactoryTemplate)1 Method (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method)1 AbsFactoryGeneratedObjectFactory (org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsFactoryGeneratedObjectFactory)1