Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 2 - Refactoring of Alitheia-Core #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions alitheia/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,83 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jacoco</groupId>
<artifactId>
jacoco-maven-plugin
</artifactId>
<versionRange>
[0.7.2.201409121644,)
</versionRange>
<goals>
<goal>prepare-agent</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencies>
Expand Down Expand Up @@ -176,6 +252,18 @@
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.184</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
4 changes: 4 additions & 0 deletions alitheia/core/src/main/java/eu/sqooss/core/AlitheiaCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public static AlitheiaCore testInstance() {
return instance;
}

public static void setTestInstance(AlitheiaCore testInstance) {
instance = testInstance;
}

/**
* Register an external implementation of an AlitheiaCore service. It
* will override any internally defined implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public void execute(AdminAction a) {
DBService db = null;
if (AlitheiaCore.getInstance() != null) {
db = AlitheiaCore.getInstance().getDBService();
if (db.isDBSessionActive() != true) {
if (db.getSessionManager().isDBSessionActive() != true) {
commitDB = true;
db.startDBSession();
db.getSessionManager().startDBSession();
}
}

Expand All @@ -111,14 +111,14 @@ public void execute(AdminAction a) {
a.execute();
} catch (Exception e) {
if ((db != null) && commitDB)
db.rollbackDBSession();
db.getSessionManager().rollbackDBSession();
err("Error executing action " + a.mnemonic() + ", id " + a.id() +
"\nCause:" + e.getMessage(), e);
} finally {
ActionContainer ac = liveactions.get(a.id());
if (db != null)
if (db.isDBSessionActive() && commitDB)
db.commitDBSession();
if (db.getSessionManager().isDBSessionActive() && commitDB)
db.getSessionManager().commitDBSession();
ac.end = System.currentTimeMillis();
debug("Action " + a.id() + " finished in " + (ac.end - ac.start) + " msec" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import eu.sqooss.service.cluster.ClusterNodeService;
import eu.sqooss.service.db.ClusterNode;
import eu.sqooss.service.db.DBService;
import eu.sqooss.service.db.HQLQueryInterface;
import eu.sqooss.service.db.StoredProject;
import eu.sqooss.service.logging.Logger;
import eu.sqooss.service.updater.UpdaterService;
Expand Down Expand Up @@ -160,9 +161,9 @@ public boolean assignProject(StoredProject project) throws ClusterNodeActionExce
* @param projectname project's name to assign
*/
public boolean assignProject(String projectname) throws ClusterNodeActionException {
dbs.startDBSession();
dbs.getSessionManager().startDBSession();
StoredProject project = StoredProject.getProjectByName(projectname);
dbs.rollbackDBSession();
dbs.getSessionManager().rollbackDBSession();
if (project == null) {
//the project was not found, can't be assign
String errorMessage = "The project [" + projectname + "] was not found";
Expand Down Expand Up @@ -275,9 +276,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
// If empty, assign it to this clusternode
// Example: http://localhost:8088/clusternode?action=assign_project&projectname=iTALC&clusternode=sqoserver1

dbs.startDBSession();
dbs.getSessionManager().startDBSession();
project = StoredProject.getProjectByName(projectname);
dbs.rollbackDBSession();
dbs.getSessionManager().rollbackDBSession();
if (project==null) {
if (projectid!=null) {
long id = 0;
Expand All @@ -288,9 +289,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
sendXMLResponse(response, HttpServletResponse.SC_BAD_REQUEST, content);
break;
}
dbs.startDBSession();
project = dbs.findObjectById(StoredProject.class, id);
dbs.rollbackDBSession();
dbs.getSessionManager().startDBSession();
project = dbs.getQueryInterface().findObjectById(StoredProject.class, id);
dbs.getSessionManager().rollbackDBSession();
if (project==null) {
content = createXMLResponse(null,"Project with id:" + projectid + " not found", HttpServletResponse.SC_NOT_FOUND);
sendXMLResponse(response, HttpServletResponse.SC_NOT_FOUND, content);
Expand All @@ -306,9 +307,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
if (clusternode==null) {
node = thisNode;
} else {
dbs.startDBSession();
dbs.getSessionManager().startDBSession();
node = ClusterNode.getClusteNodeByName(clusternode);
dbs.rollbackDBSession();
dbs.getSessionManager().rollbackDBSession();
if (node==null) {
content = createXMLResponse(null,"ClusterNode " + clusternode + " not found", HttpServletResponse.SC_NOT_FOUND);
sendXMLResponse(response, HttpServletResponse.SC_NOT_FOUND, content);
Expand All @@ -335,9 +336,9 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
if (clusternode==null) {
node = thisNode;
} else {
dbs.startDBSession();
dbs.getSessionManager().startDBSession();
node = ClusterNode.getClusteNodeByName(clusternode);
dbs.rollbackDBSession();
dbs.getSessionManager().rollbackDBSession();
}
if (node==null){
content = createXMLResponse(null, "ClusterNode "+clusternode+" not found", HttpServletResponse.SC_NOT_FOUND);
Expand All @@ -346,7 +347,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
}

bcontent = new StringBuilder();
dbs.startDBSession();
dbs.getSessionManager().startDBSession();
Set<StoredProject> assignments = ClusterNode.thisNode().getProjects();
if ((assignments!=null) && (assignments.size()>0) ){
bcontent.append("\n");
Expand All @@ -357,23 +358,23 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
bcontent.append(">" + sp.getName() + "</project>\n");
}
}
dbs.rollbackDBSession();
dbs.getSessionManager().rollbackDBSession();
content = createXMLResponse(bcontent.toString(), "Project list processed succesfuly", HttpServletResponse.SC_OK);
sendXMLResponse(response, HttpServletResponse.SC_OK, content);
break;
case GET_KNOWN_SERVERS:
// valid parameters: No need for parameters!
// Example: http://localhost:8088/clusternode?action=get_known_servers
bcontent = new StringBuilder();
dbs.startDBSession();
List<ClusterNode> nodes = (List<ClusterNode>) dbs.doHQL("FROM ClusterNode",null);
dbs.getSessionManager().startDBSession();
List<ClusterNode> nodes = (List<ClusterNode>) dbs.getQueryInterface(HQLQueryInterface.class).doHQL("FROM ClusterNode",null);
if ((nodes!=null) && (nodes.size()>0) ){
bcontent.append("\n");
for (ClusterNode cn : nodes) {
bcontent.append("<clusternode id=\"" + cn.getId() + "\">" + cn.getName() + "</clusternode>\n");
}
}
dbs.rollbackDBSession();
dbs.getSessionManager().rollbackDBSession();
content = createXMLResponse(bcontent.toString(), "Clusternode list processed succesfuly", HttpServletResponse.SC_OK);
sendXMLResponse(response, HttpServletResponse.SC_OK, content);
break;
Expand Down Expand Up @@ -429,31 +430,31 @@ public boolean startUp() {
// At this point, this ClusterNode has not been registered to the
// database yet, so do it!
if (thisNode == null) { // paranoia check
dbs.startDBSession();
dbs.getSessionManager().startDBSession();
// Check if previously registered in DB
Map<String, Object> serverProps = new HashMap<String, Object>(1);
serverProps.put("name", localServerName);
List<ClusterNode> s = dbs.findObjectsByProperties(
List<ClusterNode> s = dbs.getQueryInterface().findObjectsByProperties(
ClusterNode.class, serverProps);

if (s.isEmpty()) {
// not registered yet, create a record in DB
thisNode = new ClusterNode();
thisNode.setName(localServerName);
if (!dbs.addRecord(thisNode)) {
if (!dbs.getQueryInterface().addRecord(thisNode)) {
logger.error("Failed to register ClusterNode <"
+ localServerName + ">");
dbs.rollbackDBSession();
dbs.getSessionManager().rollbackDBSession();
return false;
} else {
dbs.commitDBSession();
dbs.getSessionManager().commitDBSession();
logger.info("ClusterNode <" + localServerName
+ "> registered succesfully.");
return true;
}
} else {
// already registered, keep the record from DB
dbs.rollbackDBSession();
dbs.getSessionManager().rollbackDBSession();
thisNode = s.get(0);
logger.info("ClusterNode <" + localServerName
+ "> registered succesfully.");
Expand Down
Loading