Skip to content
Browse files

Adding cloud summary page

  • Loading branch information...
1 parent e820166 commit dcb1af1a893afc3e1b084db4d9a13b2d78c309e6 @trisberg committed
View
10 .classpath
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
View
18 .project
@@ -3,7 +3,6 @@
<name>visitors</name>
<comment></comment>
<projects>
- <project>Servers</project>
</projects>
<buildSpec>
<buildCommand>
@@ -22,30 +21,23 @@
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.springframework.ide.eclipse.core.springbuilder</name>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
- <nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
- <nature>org.springframework.ide.eclipse.core.springnature</nature>
- <nature>com.springsource.sts.roo.core.nature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>
View
12 .settings/.jsdtscope
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/webapp"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
+ <attributes>
+ <attribute name="hide" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
View
43 .settings/org.eclipse.ajdt.core.prefs
@@ -1,43 +0,0 @@
-#Thu Sep 22 12:20:43 EDT 2011
-eclipse.preferences.version=1
-org.aspectj.ajdt.core.compiler.BuildOptions.showweavemessages=false
-org.aspectj.ajdt.core.compiler.lint.BrokeSerialVersionCompatibility=ignore
-org.aspectj.ajdt.core.compiler.lint.CannotImplementLazyTJP=ignore
-org.aspectj.ajdt.core.compiler.lint.InvalidAbsoluteTypeName=warning
-org.aspectj.ajdt.core.compiler.lint.NeedSerialVersionUIDField=ignore
-org.aspectj.ajdt.core.compiler.lint.NoInterfaceCtorJoinpoint=warning
-org.aspectj.ajdt.core.compiler.lint.ShadowNotInStructure=ignore
-org.aspectj.ajdt.core.compiler.lint.TypeNotExposedToWeaver=warning
-org.aspectj.ajdt.core.compiler.lint.UnresolvableMember=warning
-org.aspectj.ajdt.core.compiler.lint.WildcardTypeName=ignore
-org.aspectj.ajdt.core.compiler.lint.adviceDidNotMatch=warning
-org.aspectj.ajdt.core.compiler.lint.annotationAsTargetForDecpIgnored=warning
-org.aspectj.ajdt.core.compiler.lint.calculatingSerialVersionUID=ignore
-org.aspectj.ajdt.core.compiler.lint.cantFindType=error
-org.aspectj.ajdt.core.compiler.lint.cantFindTypeAffectingJPMatch=warning
-org.aspectj.ajdt.core.compiler.lint.cantMatchArrayTypeOnVarargs=ignore
-org.aspectj.ajdt.core.compiler.lint.elementAlreadyAnnotated=warning
-org.aspectj.ajdt.core.compiler.lint.enumAsTargetForDecpIgnored=warning
-org.aspectj.ajdt.core.compiler.lint.invalidTargetForAnnotation=warning
-org.aspectj.ajdt.core.compiler.lint.multipleAdviceStoppingLazyTjp=ignore
-org.aspectj.ajdt.core.compiler.lint.noExplicitConstructorCall=warning
-org.aspectj.ajdt.core.compiler.lint.noGuardForLazyTjp=ignore
-org.aspectj.ajdt.core.compiler.lint.noJoinpointsForBridgeMethods=warning
-org.aspectj.ajdt.core.compiler.lint.runtimeExceptionNotSoftened=warning
-org.aspectj.ajdt.core.compiler.lint.swallowedExceptionInCatchBlock=ignore
-org.aspectj.ajdt.core.compiler.lint.uncheckedAdviceConversion=warning
-org.aspectj.ajdt.core.compiler.lint.uncheckedArgument=warning
-org.aspectj.ajdt.core.compiler.lint.unmatchedTargetKind=warning
-org.aspectj.ajdt.core.compiler.lint.unorderedAdviceAtShadow=ignore
-org.aspectj.ajdt.core.compiler.list.UnmatchedSuperTypeInCall=warning
-org.aspectj.ajdt.core.compiler.weaver.XHasMember=false
-org.aspectj.ajdt.core.compiler.weaver.XNoInline=false
-org.aspectj.ajdt.core.compiler.weaver.XNotReweavable=false
-org.aspectj.ajdt.core.compiler.weaver.XSerializableAspects=false
-org.aspectj.ajdt.core.compiler.weaver.outxml=true
-org.aspectj.ajdt.core.compiler.weaver.timers=false
-org.aspectj.ajdt.core.compiler.weaver.verbose=false
-org.aspectj.ajdt.core.complier.lint.aspectExcludedByConfiguration=ignore
-org.eclipse.ajdt.core.builder.incrementalCompilationOptimizations=true
-org.eclipse.ajdt.core.compiler.nonStandardOptions=
-org.eclipse.ajdt.core.compiler.useProjectSettings=true
View
9 .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,9 @@
+#Wed Oct 05 18:07:44 EDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
View
5 .settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,5 @@
+#Wed Oct 05 18:07:44 EDT 2011
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
View
11 .settings/org.eclipse.wst.common.component
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+ <wb-module deploy-name="visitors">
+ <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
+ <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
+ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
+ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
+ <property name="context-root" value="visitors"/>
+ <property name="java-output-path" value="/visitors/target/classes"/>
+ </wb-module>
+</project-modules>
View
7 .settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <fixed facet="wst.jsdt.web"/>
+ <installed facet="java" version="1.6"/>
+ <installed facet="jst.web" version="2.5"/>
+ <installed facet="wst.jsdt.web" version="1.0"/>
+</faceted-project>
View
1 .settings/org.eclipse.wst.jsdt.ui.superType.container
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
View
1 .settings/org.eclipse.wst.jsdt.ui.superType.name
@@ -0,0 +1 @@
+Window
View
13 .springBeans
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beansProjectDescription>
- <version>1</version>
- <pluginVersion><![CDATA[2.5.0.201010141000-RC1]]></pluginVersion>
- <configSuffixes>
- <configSuffix><![CDATA[xml]]></configSuffix>
- </configSuffixes>
- <enableImports><![CDATA[true]]></enableImports>
- <configs>
- </configs>
- <configSets>
- </configSets>
-</beansProjectDescription>
View
36 src/main/java/org/cloudfoundry/demo/Cloud.java
@@ -0,0 +1,36 @@
+package org.cloudfoundry.demo;
+
+import org.bson.types.ObjectId;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document
+public class Cloud {
+
+ @Id
+ ObjectId id;
+
+ String address;
+
+ Long visitCount;
+
+ public ObjectId getId() {
+ return id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public Long getVisitCount() {
+ return visitCount;
+ }
+
+ public void setVisitCount(Long visitCount) {
+ this.visitCount = visitCount;
+ }
+}
View
78 src/main/java/org/cloudfoundry/demo/CloudRepository.java
@@ -0,0 +1,78 @@
+package org.cloudfoundry.demo;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.data.mongodb.core.CollectionCallback;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Repository;
+import org.springframework.web.client.RestTemplate;
+
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.MongoException;
+
+@Repository
+public class CloudRepository {
+
+ private final static String CLOUDS = "clouds";
+
+ @Autowired
+ private MongoTemplate mongoTemplate;
+
+ public List<Cloud> getClouds() {
+ List<Cloud> clouds = mongoTemplate.findAll(Cloud.class, CLOUDS);
+ for (Cloud cloud : clouds) {
+ Long count = getCloudCount(cloud.address);
+ if (count != null) {
+ cloud.setVisitCount(count);
+ saveCloud(cloud);
+ }
+ }
+ return clouds;
+ }
+
+ public void saveCloud(Cloud cloud) {
+ mongoTemplate.save(cloud, CLOUDS);
+ }
+
+ public void deleteCloud(String id) {
+ Query query = new Query(Criteria.where("id").is(id));
+ mongoTemplate.remove(query, CLOUDS);
+ }
+
+ public String getDump() {
+ final StringBuilder mongoData = new StringBuilder();
+ mongoTemplate.execute(CLOUDS,
+ new CollectionCallback<String>() {
+ public String doInCollection(DBCollection collection) throws MongoException, DataAccessException {
+ for (DBObject dbo : collection.find()) {
+ mongoData.append(dbo.toString());
+ mongoData.append(" ");
+ }
+ return null;
+ }
+ });
+ return mongoData.toString();
+ }
+
+ private Long getCloudCount(String address) {
+ RestTemplate rt = new RestTemplate();
+ String value;
+ try {
+ value = rt.getForObject(address + "/count", String.class);
+ } catch (Exception e) {
+ return null;
+ }
+ Long ret;
+ try {
+ ret = Long.valueOf(value);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ return ret;
+ }
+}
View
47 src/main/java/org/cloudfoundry/demo/HomeController.java
@@ -2,6 +2,7 @@
import java.text.DateFormat;
import java.util.Date;
+import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
@@ -11,7 +12,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
-import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -26,6 +28,9 @@
@Autowired
private VisitRepository visitRepository;
+ @Autowired
+ private CloudRepository cloudRepository;
+
/**
* Simply selects the home view to render by returning its name.
*/
@@ -54,14 +59,50 @@ public String home(Locale locale, Model model, HttpServletRequest request) {
return "home";
}
- @RequestMapping(value={"/dump"}, method=RequestMethod.GET)
+ @RequestMapping(value="/clouds", method=RequestMethod.GET)
+ public String clouds(Model model) {
+ List<Cloud> clouds = cloudRepository.getClouds();
+ long total = 0;
+ for (Cloud cloud : clouds) {
+ if (cloud.getVisitCount() != null) {
+ total += cloud.getVisitCount();
+ }
+ }
+ model.addAttribute("cloudList", clouds);
+ model.addAttribute("cloud", new Cloud());
+ model.addAttribute("total", total);
+ return "clouds";
+ }
+
+ @RequestMapping(value="/cloud/delete/{cloudId}", method=RequestMethod.GET)
+ public String cloudDelete(@PathVariable("cloudId") String cloudId) {
+ cloudRepository.deleteCloud(cloudId);
+ return "redirect:/clouds";
+ }
+
+ @RequestMapping(value="/clouds", method=RequestMethod.POST)
+ public String addCloud(@ModelAttribute("cloud") Cloud newCloud) {
+ if (newCloud != null) {
+ cloudRepository.saveCloud(newCloud);
+ }
+ return "redirect:/clouds";
+ }
+
+ @RequestMapping(value="/count", method=RequestMethod.GET)
+ public String count(Model model) {
+ model.addAttribute("count", visitRepository.getCount());
+ return "count";
+ }
+
+ @RequestMapping(value="/dump", method=RequestMethod.GET)
public String dump(Model model) {
model.addAttribute("aggregates", visitRepository.getAggregates());
model.addAttribute("mongodata", visitRepository.getDump());
+ model.addAttribute("clouds", cloudRepository.getDump());
return "dump";
}
- @RequestMapping(value={"/clear"}, method=RequestMethod.GET)
+ @RequestMapping(value="/clear", method=RequestMethod.GET)
public String clear(Model model) {
visitRepository.clear();
return "redirect:/";
View
4 src/main/java/org/cloudfoundry/demo/VisitRepository.java
@@ -78,6 +78,10 @@ public String doInCollection(DBCollection collection) throws MongoException, Dat
return aggregateData.toString();
}
+ public Long getCount() {
+ return mongoTemplate.getCollection(mongoTemplate.getCollectionName(Visit.class)).count();
+ }
+
public String getDump() {
final StringBuilder mongoData = new StringBuilder();
mongoTemplate.execute(LAST10,
View
13 src/main/webapp/WEB-INF/spring/root-context.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:cloud="http://schema.cloudfoundry.org/spring"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
- http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
+ http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
@@ -21,8 +21,7 @@
host="${cloud.services.mongodb.connection.host}"
port="${cloud.services.mongodb.connection.port}"
username="${cloud.services.mongodb.connection.username}"
- password="${cloud.services.mongodb.connection.password}"
- write-concern="NONE"/>
+ password="${cloud.services.mongodb.connection.password}"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory"/>
View
121 src/main/webapp/WEB-INF/views/clouds.jsp
@@ -0,0 +1,121 @@
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
+<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
+<%@ page session="false" %>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+ <meta name="author" content="VMware" />
+ <meta name="copyright" content="Copyright VMware 2011. All Rights Reserved." />
+ <title>Cloud Foundry @ Visitors</title>
+ <link rel="stylesheet" href="/resources/styles/main.css">
+ <!--[if IE]><link rel="stylesheet" href="/resources/styles/ie.css"><![endif]-->
+ </head>
+ <body>
+ <div class="header">
+ <div class="site-wrap">
+ <div class="logo">
+ <a href="http://www.cloudfoundry.com">Cloud Foundry</a>
+ </div>
+ <div class="supernav">
+ <div class="vmware">
+ <a href="http://www.vmware.com" >VMware</a>
+ </div>
+ <div class="nav-menu">
+ <a href="http://www.springsource.org/spring-data/mongodb">
+ <img src="resources/images/spring-data-mongodb.png" width="450" alt="Spring Data MongoDB" /></a>
+ </div>
+ </div>
+ </div>
+ </div>
+ <!-- Main Container Start-->
+ <div id="main">
+ <div class="container">
+ <div class="content-wrap content">
+ <div class="site-wrap">
+ <h1>Clouds</h1>
+
+ <h4>The visitor counts for all clouds:</h4>
+ <table width="60%">
+ <thead>
+ <tr>
+ <th width="60%"><u>Cloud Address</u></th>
+ <th width="30%" align="right"><u>Visits</u></th>
+ <th width="10%"></th>
+ </tr>
+ </thead>
+ <tbody>
+ <c:forEach var="cloud" items="${cloudList}">
+ <tr>
+ <td>${cloud.address}</td>
+ <td>${cloud.visitCount}</td>
+ <td>[ <a href="cloud/delete/${cloud.id}">X</a> ]</td>
+ </tr>
+ </c:forEach>
+ <tr>
+ <td>TOTAL</td>
+ <td>${total}</td>
+ <td></td>
+ </tr>
+ </tbody>
+ </table>
+
+ <p>&nbsp;</p>
+ <p>&nbsp;</p>
+
+ <form:form modelAttribute="cloud">
+ <fieldset>
+ <div>
+ <div>
+ <label for="address">New Cloud Address:</label>
+ </div>
+ <div>
+ <form:input class="span-9" path="address" />
+ </div>
+ </div>
+ <div>
+ <button type="submit" id="proceed" name="_proceed">Add</button>
+ </div>
+ </fieldset>
+ </form:form>
+
+ </div>
+ </div>
+ </div>
+ </div>
+ <!-- Main Container End-->
+
+ <!-- Footer Start-->
+ <div class="footer">
+ <div class="site-wrap">
+ <div class="social-media-logos left">
+ <a class="twitter" href="http://twitter.com/cloudfoundry" target="_blank">Twitter</a>
+ <a class="facebook" href="http://www.facebook.com/cloudfoundry" target="_blank">Facebook</a>
+ <a class="youtube" href="http://www.youtube.com/cloudfoundry" target="_blank">You Tube</a>
+ </div>
+ <div class="links right">
+ <!-- <a href="http://www.cloudfoundry.com/faq" target="_blank">FAQ</a>
+ |
+ <a href="http://support.cloudfoundry.com/forums" target="_blank">Forums</a>
+ |
+ <a href="http://support.cloudfoundry.com/home" target="_blank">Support</a>
+ |
+ <a href="http://blog.cloudfoundry.com/" target="_blank">Blog</a>
+ |
+ <a href="http://www.cloudfoundry.com/terms" target="_blank">Terms</a>
+ |
+ <a href="http://www.cloudfoundry.com/legal" target="_blank">Legal</a>
+ |
+ <a href="http://www.vmware.com/help/privacy.html" target="_blank">Privacy</a> -->
+
+ <div class="copyright">
+ Copyright &copy; 2011. <a href="http://www.vmware.com/" target="_blank">VMware, Inc</a>. All rights reserved.
+ </div>
+ </div>
+ </div>
+ </div>
+ <!--Footer End-->
+
+ </body>
+</html>
View
1 src/main/webapp/WEB-INF/views/count.jsp
@@ -0,0 +1 @@
+${count}
View
1 src/main/webapp/WEB-INF/views/dump.jsp
@@ -36,6 +36,7 @@
<p><c:out value="${aggregates}"/></p>
<p><c:out value="${mongodata}"/></p>
+ <p><c:out value="${clouds}"/></p>
<a href="/">Home</a>
</div>

0 comments on commit dcb1af1

Please sign in to comment.
Something went wrong with that request. Please try again.