Get ahead
VMware offers training and certification to turbo-charge your progress.
Learn moreAfter many months of development, I am proud to announce the release of Hyperic 4.5. In this release, we migrated Hyperic from an EJB application running on JBoss to a Spring web application running on Tomcat. The detailed migration steps are covered in my Case Study on Migrating Hyperic from EJB to Spring, originally presented at the recent SpringOne 2GX. In this post, I would like to highlight a few of my favorite things about the conversion.
After the conversion, we were able to take advantage of Spring's integration testing support to test our new service layer of converted EJBs as well as their underlying DAOs. By simply adding a few annotations, we were able to bootstrap our entire application context in less than 30 seconds and run each test method in a dedicated transaction that was automatically rolled back at the end of the test. This support proved very valuable in allowing us to quickly increase our test coverage by 18% and 12% in our open source and enterprise codebases respectively.
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:META-INF/spring/*-context.xml")
public class AppdefManagerTest {
@Autowired
private AppdefManager appdefManager;
@Before
public void setUp() throws Exception {
createPlatformType("TestPlatform", "test");
}
@Test
public void testGetControllablePlatformTypes() throws Exception {
Map<String, AppdefEntityID> platformTypes = appdefManager
.getControllablePlatformTypes(subject);
assertEquals(1, platformTypes.size());
assertEquals("TestPlatform", platformTypes.keySet().iterator().next());
}
}
public void publishMessage(String name, Serializable sObj) {
TopicConnection conn = null;
TopicSession session = null;
if (_ic == null)
_ic = new InitialContext();
if (_factory == null)
_factory = _ic.lookup(CONN_FACTORY_JNDI);
TopicConnectionFactory tFactory = (TopicConnectionFactory) _factory;
Topic topic = getTopic(name);
if (topic != null) {
// Now create a connection to send a message
if (_tConn != null)
conn = _tConn;
else
conn = tFactory.createTopicConnection();
if (conn == null)
_log.error("TopicConnection cannot be created");
if (_tSession != null)
session = _tSession;
else
session = conn.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
// Create a publisher and publish the message
TopicPublisher publisher = session.createPublisher(topic);
ObjectMessage msg = session.createObjectMessage();
msg.setObject(sObj);
publisher.publish(msg);
...
}
public void publishMessage(String name, Serializable sObj) {
eventsJmsTemplate.convertAndSend(name, sObj);
}
public int getServicesCount(AuthzSubject subject) {
Statement stmt = null;
ResultSet rs = null;
Integer subjectId = subject.getId();
try {
Connection conn = getDBConn();
String sql = "SELECT COUNT(SVC.ID) FROM TBL_SERVICE";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException e) {
log.error("Caught SQL Exception finding Services by type: " + e, e);
throw new SystemException(e);
} finally {
DBUtil.closeJDBCObjects(LOG_CTX, null, stmt, rs);
}
return 0;
}
public int getServicesCount(AuthzSubject subject) {
return jdbcTemplate.queryForInt("SELECT COUNT(SVC.ID) FROM TBL_SERVICE");
}
That's quite a weight loss plan! Simply by converting to Spring and not changing any functionality, we reduced both the open source and enterprise codebases by approximately 7%.
These are just a few of the benefits provided by switching to Spring and Tomcat in this release. There are really just too many to list in a single blog post!
This release also contains monitoring and management for three of the VMware vFabric platform services, including vFabric GemFire 6.5 distributed caching system, RabbitMQ enterprise messaging system, and the new vFabric tc Server 2.1 Java runtime server also released this week. Support for vFabric tc Server existed in previous releases of Hyperic; however, in 4.5 the plugin is now bundled with the Hyperic distributions, and is no longer a separate download. Look for more information on monitoring GemFire and RabbitMQ in a future blog post.
While migrating, we also took the opportunity to move our code repository from subversion to git. To download the source from the git code repository go to http://git.springsource.org/hq. We also switched our build system from ant to maven. All of the Hyperic modules needed for development of custom plugins or features can now be downloaded from our maven repository at http://maven.hyperic.org/release.