Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

how to create custom ambari view with spring feture?

Highlighted

how to create custom ambari view with spring feture?

New Contributor

Hi,

I know that ambari gives a example view with name of "hello-spring-view", but there is only one controller in the example, no Service and no DAO, which means I cannot persist my data into database. So, I'm trying to create a custom view using spring with Service and DAO. But once I add the following spring configuration to WEB-INF/web.xml, rebuild the view project, restart ambari-server, I will get an error in log.

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
</context-param>

Here is the error message:

2019-06-17 17:36:40,173  WARN [main] WebAppContext:554 - Failed startup of context o.e.j.w.WebAppContext@46875fae{mvcDemo,/views/PRODUCT_VIEW/1.0.0/INSTANCE,file:///var/lib/ambari-server/resources/views/work/PRODUCT_VIEW%7B1.0.0%7D/,UNAVAILABLE}{/var/lib/ambari-server/resources/views/work/PRODUCT_VIEW{1.0.0}}
java.lang.IllegalStateException: Context attribute is not of type WebApplicationContext: Root WebApplicationContext: startup date [Mon Jun 17 17:36:39 CST 2019]; root of context hierarchy
        at org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(WebApplicationContextUtils.java:123)
        at org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(WebApplicationContextUtils.java:98)
        at org.springframework.web.context.support.WebApplicationContextUtils.findWebApplicationContext(WebApplicationContextUtils.java:144)
        at org.springframework.web.filter.DelegatingFilterProxy.findWebApplicationContext(DelegatingFilterProxy.java:308)
        at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:233)
        at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:236)
        at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:139)
        at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:741)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:374)
        at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:848)
        at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
        at org.eclipse.jetty.server.Server.start(Server.java:419)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
        at org.eclipse.jetty.server.Server.doStart(Server.java:386)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.apache.ambari.server.controller.AmbariServer.run(AmbariServer.java:570)
        at org.apache.ambari.server.controller.AmbariServer.main(AmbariServer.java:1108)

Any help is welcome. Thanks in advance.


5 REPLIES 5
Highlighted

Re: how to create custom ambari view with spring feture?

Super Mentor

@Frank k

Can you please share more details about what you have actually written inside the "applicationContext.xml" file?

Also the sample "https://github.com/apache/ambari/tree/trunk/ambari-views/examples/hello-spring-view" view comes with Spring 4. So are you using the same Annotation based controllers?

Which version of spring JARs are you using inside your custom view application?

Which version of ambari are you using ?

Highlighted

Re: how to create custom ambari view with spring feture?

Super Mentor

@Frank k

Also just in case if you have already placed some Spring4 related JARs inside your custom views "WEB-INF/lib" then please remove them and then try again.

Once you redeploy your Views then please make sure to perform the following steps to remove the previously deployed extracted view.

# ambari-server stop
# rm -rf /var/lib/ambari-server/resources/views/work/*
# echo "NOW deploy your custom view freshly ....."
# ambari-server start

.

Highlighted

Re: how to create custom ambari view with spring feture?

New Contributor

Sorry, My bad, Ambari version is 2.7.1

Highlighted

Re: how to create custom ambari view with spring feture?

New Contributor

@Jay Kumar SenSharma

Thanks for your rapid reply.

I've just pushed my code "https://github.com/xihuanbanku/product-view".

And also, you can find my spring version in pom.xml is 4.3.17.RELEASE.

Ambari version is 2.7.3.

I'm pretty sure the configuration of spring is good , because I could deploy the same war file in to Tomcat, and it works well.

Highlighted

Re: how to create custom ambari view with spring feture?

New Contributor

Or maybe you could share me a spring view which contains database operation.

Don't have an account?
Coming from Hortonworks? Activate your account here