|
From: <ian...@us...> - 2008-02-07 02:31:46
|
Revision: 720
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=720&view=rev
Author: iansmith
Date: 2008-02-06 18:28:03 -0800 (Wed, 06 Feb 2008)
Log Message:
-----------
Added a migration to fix the SimRecords in the database to have the fields we want and dropped the old fields we were not using.
This checkin does not change functionality, it just does the same things as the old version with this new datamodel. Tests and various places were updated to reflect the new data model and semantics, including "retirement" of sims.
For hibernate reasons, I was forced to add some bogus code in SimRecords. This only increases the size of the SimRecord class' code by a few bytes, so it seemed better than fighting hibernate.
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/SimDocument.java
maven/trunk/ogoglio-common/src/test/java/com/ogoglio/xml/test/XMLTest.java
maven/trunk/ogoglio-server/pom.xml
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/migrate/OgoglioServerMigration.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/ServiceInitializationPersistTasks.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SimPersistTasks.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SimRecord.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SpacePersistTasks.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/Sim.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/site/SimServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/StatusServlet.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/xml/server/DocumentFactory.java
maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java
Added Paths:
-----------
maven/trunk/ogoglio-server/src/main/resources/hibernate/migration-3.xml
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/SimDocument.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/SimDocument.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/SimDocument.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -27,26 +27,26 @@
public static final String SIM_URI = "simuri";
- public static final String DISPLAY_NAME = "displayname";
+ public static final String REACHABLE = "reachable";
- public static final String ACTIVE = "active";
+ public static final String RETIRED = "retired";
XMLElement data = null;
- public SimDocument(long simID, URI simURI, String displayName, boolean active) {
- if (active && simURI == null) {
- throw new IllegalArgumentException("Active sims need a URI: " + simURI);
+ public SimDocument(long simID, URI simURI, boolean reachable, boolean retired) {
+ if (reachable && simURI == null) {
+ throw new IllegalArgumentException("Reachable sims need a URI: " + simURI);
}
- if (displayName == null) {
- throw new IllegalArgumentException("You must name the sim");
+ if (!retired && simURI == null) {
+ throw new IllegalArgumentException("Non-retired sims need a URI: " + simURI);
}
data = new XMLElement(NAME);
if (simURI != null) {
data.setAttribute(SIM_URI, simURI.toString());
}
data.setAttribute(SIM_ID, simID);
- data.setAttribute(DISPLAY_NAME, displayName);
- data.setAttribute(ACTIVE, active);
+ data.setAttribute(REACHABLE, reachable);
+ data.setAttribute(RETIRED, retired);
}
public SimDocument(XMLElement data) {
@@ -54,11 +54,14 @@
throw new IllegalArgumentException("SimDocument data is null");
}
if (!NAME.equals(data.getName())) {
- throw new IllegalArgumentException("SimDocument data is not named Auth: " + data);
+ throw new IllegalArgumentException("SimDocument data is not named Sim: " + data);
}
- if (data.getBooleanAttribute(ACTIVE, false) && data.getStringAttribute(SIM_URI) == null) {
- throw new IllegalArgumentException("No sim URI in active sim document");
+ if (data.getBooleanAttribute(REACHABLE, false) && data.getStringAttribute(SIM_URI) == null) {
+ throw new IllegalArgumentException("No sim URI in reachable sim document");
}
+ if (data.getBooleanAttribute(RETIRED, false) && data.getStringAttribute(SIM_URI) == null) {
+ throw new IllegalArgumentException("No sim URI in a non-retired sim document");
+ }
this.data = data;
}
@@ -74,12 +77,12 @@
return data.getLongAttribute(SIM_ID);
}
- public boolean isActive() {
- return data.getBooleanAttribute(ACTIVE, false);
+ public boolean isReachable() {
+ return data.getBooleanAttribute(REACHABLE, false);
}
- public String getDisplayName() {
- return data.getStringAttribute(DISPLAY_NAME);
+ public boolean isRetired() {
+ return data.getBooleanAttribute(RETIRED, false);
}
public URI getSimURI() {
Modified: maven/trunk/ogoglio-common/src/test/java/com/ogoglio/xml/test/XMLTest.java
===================================================================
--- maven/trunk/ogoglio-common/src/test/java/com/ogoglio/xml/test/XMLTest.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-common/src/test/java/com/ogoglio/xml/test/XMLTest.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -122,23 +122,29 @@
}
public void testSimDocuments() {
- SimDocument simDoc1 = new SimDocument(1, simURI1, displayName1, true);
+ SimDocument simDoc1 = new SimDocument(1, simURI1, true, false);
assertEquals(1, simDoc1.getSimID());
- assertEquals(displayName1, simDoc1.getDisplayName());
assertEquals(simURI1, simDoc1.getSimURI());
- assertEquals(true, simDoc1.isActive());
+ assertEquals(true, simDoc1.isReachable());
+ assertEquals(false, simDoc1.isRetired());
SimDocument simDoc2 = new SimDocument(XMLElement.parseElementFromString(simDoc1.toElement().toString()));
- assertEquals(displayName1, simDoc2.getDisplayName());
assertEquals(simURI1, simDoc2.getSimURI());
- assertEquals(true, simDoc2.isActive());
+ assertEquals(true, simDoc2.isReachable());
+ assertEquals(false, simDoc2.isRetired());
try {
- new SimDocument(1, null, displayName1, true);
- fail("Shouldn't allow null URIs when active");
+ new SimDocument(1, null, true, true);
+ fail("Shouldn't allow null URIs when reachable");
} catch (IllegalArgumentException e) {
//this should happen
}
+ try {
+ new SimDocument(1, null, false, false);
+ fail("Shouldn't allow null URIs when not retired");
+ } catch (IllegalArgumentException e) {
+ //this should happen
+ }
String displayName = "Rolling Donuts";
ThingDocument doc1 = new ThingDocument(1, displayName, 2, "susan", "susan", 1, new Transform3D(), null);
Modified: maven/trunk/ogoglio-server/pom.xml
===================================================================
--- maven/trunk/ogoglio-server/pom.xml 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/pom.xml 2008-02-07 02:28:03 UTC (rev 720)
@@ -207,7 +207,6 @@
<!-- these are for the populate -->
<configuration>
-
<serviceURI>${ogoglio.baseURL}</serviceURI>
<username>${ogoglio.bootstrapUser}</username>
<password>${ogoglio.bootstrapUserPW}</password>
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/migrate/OgoglioServerMigration.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/migrate/OgoglioServerMigration.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/migrate/OgoglioServerMigration.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -17,10 +17,10 @@
public static final OgoglioServerMigration SINGLETON = new OgoglioServerMigration();
// THIS IS THE CRITICAL VERSION NUMBER
- private static final int DB_VERSION_NUMBER = 2;
+ private static final int DB_VERSION_NUMBER = 3;
// this is the set of semantic migrations, in order
- private static final Migration[] migration = { new AccountsForTesting(), new NoopMigration() };
+ private static final Migration[] migration = { new AccountsForTesting(), new NoopMigration(), new NoopMigration() };
public Migration[] getMigrationList() {
return migration;
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/ServiceInitializationPersistTasks.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/ServiceInitializationPersistTasks.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/ServiceInitializationPersistTasks.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -21,8 +21,6 @@
public class ServiceInitializationPersistTasks {
- public static final String LOCAL_SIM_DISPLAY_NAME = "Localhost Sim";
-
public static final String DEFAULT_LAND_DISPLAY_NAME = "Default Land";
public static final String DEFAULT_DOOR_DISPLAY_NAME = "Default Door";
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SimPersistTasks.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SimPersistTasks.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SimPersistTasks.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -28,8 +28,10 @@
public static final String SIM_BY_ID = "com.ogoglio.persist.simBySimID";
- public static final String SIMS_BY_ACTIVE = "com.ogoglio.persist.simsByActive";
+ public static final String SIMS_BY_REACHABLE_AND_RETIRED= "com.ogoglio.persist.simsByReachableAndRetired";
+ public static final String SIMS_BY_REACHABLE= "com.ogoglio.persist.simsByReachable";
+
public static final String SIMS = "com.ogoglio.persist.sims";
public static SimRecord[] findSims(SessionFactory sessionFactory) throws PersistException {
@@ -55,10 +57,10 @@
return (SimRecord) task.execute();
}
- public static SimRecord createSim(final String displayName, final URI simURI, final int eventPort, final boolean active, SessionFactory sessionFactory) throws PersistException {
+ public static SimRecord createSim(final URI simURI, final boolean reachable, final boolean retired, SessionFactory sessionFactory) throws PersistException {
HibernateTask task = new HibernateTask() {
public Object run(Session hibernateSession) {
- SimRecord record = new SimRecord(displayName, simURI, eventPort, active);
+ SimRecord record = new SimRecord(simURI, reachable, retired);
hibernateSession.save(record);
return record;
}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SimRecord.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SimRecord.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SimRecord.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -19,18 +19,14 @@
public class SimRecord {
- public static final int DEFAULT_EVENT_PORT = 8932;
-
private long simID = -1;
- private String displayName = null;
-
private String simURIString = null;
- private int eventPort = -1;
+ private boolean reachable = false;
+
+ private boolean retired = false;
- private boolean active = false;
-
/***
* The SimRecord stores the connection information for a simulation server which can simultaneously simulate multiple spaces
*/
@@ -39,29 +35,28 @@
}
- public SimRecord(String displayName, URI simURI, int eventPort, boolean active) {
- this.displayName = displayName;
+ public SimRecord(URI simURI, boolean reachable, boolean retired) {
if (simURI != null) {
this.simURIString = simURI.toString();
}
- this.eventPort = eventPort;
- this.active = active;
+ this.reachable=reachable;
+ this.retired=retired;
}
- public boolean isActive() {
- return active;
+ public boolean isReachable() {
+ return reachable;
}
- public void setActive(boolean active) {
- this.active = active;
+ public void setReachable(boolean reachable) {
+ this.reachable= reachable;
}
- public String getDisplayName() {
- return displayName;
+ public boolean isRetired() {
+ return retired;
}
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
+ public void setRetired(boolean retired) {
+ this.retired= retired;
}
public long getSimID() {
@@ -106,12 +101,26 @@
public int hashCode() {
return ("SimRecord-YO" + getSimID()).hashCode();
}
-
- public int getEventPort() {
- return eventPort;
+
+ /*
+ * This is pretty darn evil. XXX EVIL XXX
+ */
+ private String getDisplayName() { //FIELD NO LONGER EXISTS
+ return null;
}
-
- public void setEventPort(int eventPort) {
- this.eventPort = eventPort;
+
+ private void setDisplayName(String IGNORED) { //FIELD NO LONGER EXISTS
}
+ private boolean getActive() { //FIELD NO LONGER EXISTS
+ return false;
+ }
+
+ private void setActive(boolean IGNORED) { //FIELD NO LONGER EXISTS
+ }
+ private int getEventPort() { //FIELD NO LONGER EXISTS
+ return 0;
+ }
+
+ private void setEventPort(int IGNORED) { //FIELD NO LONGER EXISTS
+ }
}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SpacePersistTasks.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SpacePersistTasks.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/persist/SpacePersistTasks.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -169,7 +169,7 @@
task.execute();
}
- private static SimRecord findSimIfActive(final SpaceRecord spaceRecord, SessionFactory sessionFactory) throws PersistException {
+ private static SimRecord findSimFromSpaceIfReachable(final SpaceRecord spaceRecord, SessionFactory sessionFactory) throws PersistException {
HibernateTask task = new HibernateTask() {
public Object run(Session hibernateSession) {
SimRecord simRecord = null;
@@ -177,10 +177,9 @@
Query simQuery = hibernateSession.getNamedQuery(SimPersistTasks.SIM_BY_ID);
simQuery.setLong("simID", spaceRecord.getSimID());
simRecord = (SimRecord) simQuery.uniqueResult();
- if (simRecord == null || simRecord.isActive() == false) {
+ if (simRecord == null || simRecord.isReachable()== false) {
spaceRecord.setSimID(-1);
updateRecordAndUpdateModifiedTime(spaceRecord, hibernateSession, true);
- simRecord = null;
return null;
} else {
return simRecord;
@@ -194,68 +193,68 @@
return (SimRecord) task.execute();
}
- private static void markInactive(SimRecord record, SessionFactory sessionFactory) throws PersistException {
- record.setActive(false);
+ private static void markNotReachable(SimRecord record, SessionFactory sessionFactory) throws PersistException {
+ record.setReachable(false);
SimPersistTasks.update(record, sessionFactory);
}
public static SimRecord findOrAssignSim(final SpaceRecord spaceRecord, SessionFactory sessionFactory) throws PersistException {
return findOrAssignSim(spaceRecord, sessionFactory, true);
}
- public static void verifyActiveSims(SimRecord[] purportedActive, SessionFactory sessionFactory) throws PersistException {
+ public static void verifyReachableSims(SimRecord[] puportedReachable, SessionFactory sessionFactory) throws PersistException {
//let's see if they are ok
- for (int i=0; i<purportedActive.length;++i) {
+ for (int i=0; i<puportedReachable.length;++i) {
try {
- URI simURI=purportedActive[i].getSimURI();
+ URI simURI=puportedReachable[i].getSimURI();
HttpURLConnection connection = (HttpURLConnection) simURI.toURL().openConnection();
connection.setRequestMethod("GET");
connection.setAllowUserInteraction(false);
+ connection.setReadTimeout(3000);
if (connection.getResponseCode()!=200) {
Log.warn("Can't get a connection to "+simURI+"! Marking inactive!");
- markInactive(purportedActive[i], sessionFactory);
+ markNotReachable(puportedReachable[i], sessionFactory);
} else {
Log.info("Verified connection to "+simURI);
}
} catch (MalformedURLException e) {
- Log.warn("Can't understand the URI "+purportedActive[i].getSimURI()+"! Marking inactive!");
- markInactive(purportedActive[i], sessionFactory);
+ Log.warn("Can't understand the URI "+puportedReachable[i].getSimURI()+"! Marking inactive!");
+ markNotReachable(puportedReachable[i], sessionFactory);
} catch (ProtocolException e) {
- Log.warn("Can't understand the URI protocol "+purportedActive[i].getSimURI()+"! Marking inactive!");
- markInactive(purportedActive[i], sessionFactory);
+ Log.warn("Can't understand the URI protocol "+puportedReachable[i].getSimURI()+"! Marking inactive!");
+ markNotReachable(puportedReachable[i], sessionFactory);
} catch (IOException e) {
- Log.warn("Can't connect to "+purportedActive[i].getSimURI()+"! Marking inactive! IOException:"+e.getMessage());
- markInactive(purportedActive[i], sessionFactory);
+ Log.warn("Can't connect to "+puportedReachable[i].getSimURI()+"! Marking inactive! IOException:"+e.getMessage());
+ markNotReachable(puportedReachable[i], sessionFactory);
}
}
}
public static SimRecord findOrAssignSim(final SpaceRecord spaceRecord, SessionFactory sessionFactory, boolean use_network) throws PersistException {
- SimRecord rec = findSimIfActive(spaceRecord, sessionFactory);
- SimRecord[] active;
+ SimRecord rec = findSimFromSpaceIfReachable(spaceRecord, sessionFactory);
if (rec!=null) {
//assume that if we have a sim ID already assigned we are ok
return rec;
}
- active=findAllActiveSims(spaceRecord, sessionFactory);
- if (active.length==0) {
- throw new PersistException("Unable to find any active sims!");
+ SimRecord[] assignable=findAllReachableAndNotRetiredSims(spaceRecord, sessionFactory);
+ if (assignable.length==0) {
+ throw new PersistException("Unable to find any sims that we can assign to!");
}
//has it been a while?
long now=System.currentTimeMillis();
if ((now-lastTestOfSimServers<TEST_SIM_INTERVAL_MS) || (!use_network)) {
- return pickSimRandomly(spaceRecord, sessionFactory, active);
+ return pickSimRandomly(spaceRecord, sessionFactory, assignable);
}
//update the time check
lastTestOfSimServers=now;
- verifyActiveSims(active,sessionFactory);
+ verifyReachableSims(findAllReachableSims(spaceRecord, sessionFactory),sessionFactory);
- active=findAllActiveSims(spaceRecord, sessionFactory);
- if (active.length==0) {
- throw new PersistException("Unable to find any active sims (after doing a check)!");
+ assignable=findAllReachableAndNotRetiredSims(spaceRecord, sessionFactory);
+ if (assignable.length==0) {
+ throw new PersistException("Unable to find any reachable sims (after doing a check)!");
}
- return pickSimRandomly(spaceRecord, sessionFactory, active);
+ return pickSimRandomly(spaceRecord, sessionFactory, assignable);
}
private static SimRecord pickSimRandomly(final SpaceRecord spaceRecord, SessionFactory sessionFactory, SimRecord[] active) throws PersistException {
@@ -267,17 +266,30 @@
return rec;
}
- private static SimRecord[] findAllActiveSims(final SpaceRecord spaceRecord, SessionFactory sessionFactory) throws PersistException {
+ private static SimRecord[] findAllReachableSims(final SpaceRecord spaceRecord, SessionFactory sessionFactory) throws PersistException {
HibernateTask task = new HibernateTask() {
public Object run(Session hibernateSession) {
- Query simsQuery = hibernateSession.getNamedQuery(SimPersistTasks.SIMS_BY_ACTIVE);
- simsQuery.setBoolean("active", true);
+ Query simsQuery = hibernateSession.getNamedQuery(SimPersistTasks.SIMS_BY_REACHABLE);
+ simsQuery.setBoolean("reachable", true);
return (SimRecord[]) simsQuery.list().toArray(new SimRecord[0]);
}
};
task.setSessionFactory(sessionFactory);
return (SimRecord[]) task.execute();
}
+
+ private static SimRecord[] findAllReachableAndNotRetiredSims(final SpaceRecord spaceRecord, SessionFactory sessionFactory) throws PersistException {
+ HibernateTask task = new HibernateTask() {
+ public Object run(Session hibernateSession) {
+ Query simsQuery = hibernateSession.getNamedQuery(SimPersistTasks.SIMS_BY_REACHABLE_AND_RETIRED);
+ simsQuery.setBoolean("reachable", true);
+ simsQuery.setBoolean("retired", false);
+ return (SimRecord[]) simsQuery.list().toArray(new SimRecord[0]);
+ }
+ };
+ task.setSessionFactory(sessionFactory);
+ return (SimRecord[]) task.execute();
+ }
public static SpaceRecord createSpace(final String displayName, final String ownerUsername, SessionFactory sessionFactory) throws PersistException {
HibernateTask task = new HibernateTask() {
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/Sim.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/Sim.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/Sim.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -94,7 +94,7 @@
ArgumentUtils.assertNotNull(sessionFactory);
this.sessionFactory = sessionFactory;
- messageHandler = new SimMessageHandler(simRecord.getEventPort(), this, descriptor);
+ messageHandler = new SimMessageHandler(this, descriptor);
snapshotTimer.schedule(new SnapshotTask(), 300000, SNAPSHOT_FREQUENCY);
reaperTimer.schedule(new ReaperTask(), 30000, VACANCY_TIME_TILL_SHUTDOWN);
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SimMessageHandler.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -32,7 +32,7 @@
private Sim sim = null;
- public SimMessageHandler(int port, Sim sim, WebAPIDescriptor descriptor) throws IOException {
+ public SimMessageHandler(Sim sim, WebAPIDescriptor descriptor) throws IOException {
channelServer = new NetworkChannelServer(this, descriptor.getCometSimURI(), false, this);
this.sim = sim;
//Log.info("Started SimMessageHandler on port " + channelServer.getLocator().getPort());
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/site/SimServlet.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/site/SimServlet.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/site/SimServlet.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -38,7 +38,6 @@
import com.ogoglio.client.WebAPIDescriptor;
import com.ogoglio.media.MediaService;
import com.ogoglio.persist.AccountRecord;
-import com.ogoglio.persist.PossessionPersistTasks;
import com.ogoglio.persist.ServiceInitializationPersistTasks;
import com.ogoglio.persist.SimPersistTasks;
import com.ogoglio.persist.SimRecord;
@@ -58,7 +57,6 @@
import com.ogoglio.xml.PageDocument;
import com.ogoglio.xml.SettingDocument;
import com.ogoglio.xml.SpaceDocument;
-import com.ogoglio.xml.SpaceMemberDocument;
import com.ogoglio.xml.SpaceSimulatorDocument;
import com.ogoglio.xml.TemplateDocument;
import com.ogoglio.xml.ThingDocument;
@@ -104,12 +102,13 @@
SimRecord simRecord = SimPersistTasks.findSimsBySimURI(simURI, getSessionFactory());
if (simRecord != null) {
//error
- Log.warn("Marking sim server active @ " + simRecord.getSimURI() + " [it was already in the database]! Ignored.");
- simRecord.setActive(true);
+ Log.warn("Marking sim server as ready @ " + simRecord.getSimURI() + " [it was already in the database]! Ignored.");
+ simRecord.setReachable(true);
+ simRecord.setRetired(false);
SimPersistTasks.update(simRecord, getSessionFactory());
} else {
Log.info("Starting up sim @ " + simURI);
- simRecord = SimPersistTasks.createSim(ServiceInitializationPersistTasks.LOCAL_SIM_DISPLAY_NAME, simURI, SimRecord.DEFAULT_EVENT_PORT, true, getSessionFactory());
+ simRecord = SimPersistTasks.createSim(simURI, true, false, getSessionFactory());
}
WebAPIDescriptor descriptor;
String serviceURI = (String) envCtx.lookup("ogoglio/baseURL");
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/StatusServlet.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/StatusServlet.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/site/StatusServlet.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -611,7 +611,7 @@
for (int i = 0; i < simRecord.length; ++i) {
SimRecord sim = simRecord[i];
try {
- buffer.append("Sim Server:" + sim.getDisplayName() + " [" + sim.getSimID() + "] " + sim.getSimURI() + "\n");
+ buffer.append("Sim Server: [" + sim.getSimID() + "] " + sim.getSimURI() + "\n");
buffer.append("===============================================\n");
if (!isOnLocalhost(sim)) {
String hackedURI=dodgyConversionOfSimURI(sim.getSimURI().toString());
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/xml/server/DocumentFactory.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/xml/server/DocumentFactory.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/xml/server/DocumentFactory.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -32,7 +32,7 @@
}
public static SimDocument documentFromRecord(SimRecord record) {
- return new SimDocument(record.getSimID(), record.getSimURI(), record.getDisplayName(), record.isActive());
+ return new SimDocument(record.getSimID(), record.getSimURI(), record.isReachable(), record.isRetired());
}
public static SpaceDocument documentFromRecord(SpaceRecord requestedRecord) {
Added: maven/trunk/ogoglio-server/src/main/resources/hibernate/migration-3.xml
===================================================================
--- maven/trunk/ogoglio-server/src/main/resources/hibernate/migration-3.xml (rev 0)
+++ maven/trunk/ogoglio-server/src/main/resources/hibernate/migration-3.xml 2008-02-07 02:28:03 UTC (rev 720)
@@ -0,0 +1,337 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ Copyright 2007,2008 Transmutable (http://transmutable.com/)
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+-->
+
+<hibernate-mapping>
+
+ <class name="com.ogoglio.persist.ServiceStateRecord"
+ table="ServiceStateRecords">
+ <id name="serviceStateID">
+ <generator class="identity" />
+ </id>
+ <property name="registrationState" not-null="true" />
+ </class>
+
+ <class name="com.ogoglio.persist.PendingEmailValidationRecord"
+ table="PendingEmailValidationRecords">
+ <id name="email">
+ <generator class="assigned" />
+ </id>
+ <property name="username" not-null="true" />
+ <property name="secret" not-null="true" />
+ <property name="creationDate" />
+ </class>
+
+ <class name="com.ogoglio.persist.PossessionRecord"
+ table="PossessionRecords">
+ <id name="possessionID">
+ <generator class="identity" />
+ </id>
+
+ <property name="ownerUsername" not-null="true" />
+ <property name="templateID" />
+ <property name="spaceID" />
+ <property name="thingID" />
+ </class>
+
+ <class name="com.ogoglio.persist.SpaceRecord"
+ table="SpaceRecords">
+ <id name="spaceID" access="field">
+ <generator class="identity" />
+ </id>
+
+ <property name="displayName" not-null="true" />
+ <property name="ownerUsername" not-null="true" update="false" />
+ <property name="published" />
+ <property name="maxGuests" />
+ <property name="displaySea" access="field" />
+ <property name="seaLevel" />
+ <property name="simID" />
+ <property name="lastModifiedTime" />
+ <property name="bgRed" />
+ <property name="bgGreen" />
+ <property name="bgBlue" />
+ </class>
+
+ <class name="com.ogoglio.persist.SpaceMemberRecord"
+ table="SpaceMemberRecords">
+ <id name="spaceMemberID">
+ <generator class="identity" />
+ </id>
+
+ <property name="spaceID" update="false" />
+ <property name="memberUsername" not-null="true" />
+ <property name="banned" />
+ <property name="role" />
+ </class>
+
+ <class name="com.ogoglio.persist.SimRecord" table="SimRecords">
+ <id name="simID">
+ <generator class="identity" />
+ </id>
+ <property name="simURIString" column="simURI" />
+ <property name="reachable" />
+ <property name="retired" />
+ </class>
+
+ <class name="com.ogoglio.persist.AccountRecord"
+ table="AccountRecords">
+ <id name="username">
+ <generator class="assigned" />
+ </id>
+ <property name="email" not-null="true" unique="true" />
+ <property name="emailValid" />
+ <property name="accountlevel" not-null="true" />
+ <property name="passwordHash" />
+ <property name="firstName" />
+ <property name="lastName" />
+ <property name="homepage" />
+ <property name="creationDate" update="false" />
+ <property name="cookie" />
+ <property name="frozenUntil" />
+ <property name="defaultBodyConfigurationID" />
+ <property name="voiceURI" />
+ <property name="textURI" />
+ </class>
+
+ <class name="com.ogoglio.persist.TemplateRecord"
+ table="TemplateRecords">
+ <id name="templateID">
+ <generator class="identity" />
+ </id>
+
+ <property name="ownerUsername" not-null="true" />
+ <property name="displayName" not-null="true" />
+ <property name="description" />
+ <property name="seat" />
+ <property name="attachment" />
+
+ <set name="supportFiles" table="TemplateTemplateSupportFiles"
+ cascade="all">
+ <key column="templateID" />
+ <many-to-many column="templateSupportFileID" unique="true"
+ class="com.ogoglio.persist.TemplateSupportFileRecord" />
+ </set>
+
+ <property name="seatX" />
+ <property name="seatY" />
+ <property name="seatZ" />
+ <property name="seatRX" />
+ <property name="seatRY" />
+ <property name="seatRZ" />
+ <property name="seatRW" />
+
+ </class>
+
+ <class name="com.ogoglio.appdev.migrate.DBVersionRecord"
+ table="DBVersion">
+ <id name="versionId">
+ <generator class="identity" />
+ </id>
+ <property name="version" not-null="true" />
+ </class>
+
+ <class name="com.ogoglio.persist.TemplateSupportFileRecord"
+ table="TemplateSupportFileRecords">
+ <id name="templateSupportFileID">
+ <generator class="identity" />
+ </id>
+ <property name="supportFile" />
+ <property name="script" not-null="true" />
+ <property name="levelOfDetail" not-null="true" />
+ <property name="lastChanged" not-null="true" />
+ </class>
+
+ <class name="com.ogoglio.persist.BodyDataRecord"
+ table="BodyDataRecords">
+ <id name="bodyDataID">
+ <generator class="identity" />
+ </id>
+ <property name="displayName" not-null="true" />
+ <property name="fileName" not-null="true" unique="true" />
+ </class>
+
+ <class name="com.ogoglio.persist.BodyConfigurationRecord"
+ table="BodyConfigurationRecords">
+ <id name="bodyConfigurationID">
+ <generator class="identity" />
+ </id>
+ <property name="ownerUsername" not-null="true" />
+ <property name="displayName" not-null="true" />
+ <property name="bodyDataID" />
+ <property name="baseTextureName" />
+ </class>
+
+ <class name="com.ogoglio.persist.BodySettingRecord"
+ table="BodySettingRecords">
+ <id name="bodySettingID">
+ <generator class="identity" />
+ </id>
+ <property name="settingName" not-null="true" />
+ <property name="setting" />
+ <property name="bodyConfigurationID" />
+ </class>
+
+ <class name="com.ogoglio.persist.AttachmentRecord"
+ table="AttachmentRecords">
+ <id name="attachmentID">
+ <generator class="identity" />
+ </id>
+ <property name="templateOwner" />
+ <property name="templateID" />
+ <property name="bodyConfigurationID" />
+ </class>
+
+ <query name="com.ogoglio.persist.bodyData">
+ <![CDATA[ from com.ogoglio.persist.BodyDataRecord order by bodyDataID asc ]]>
+ </query>
+ <query name="com.ogoglio.persist.bodyDataByID">
+ <![CDATA[ from com.ogoglio.persist.BodyDataRecord as record where record.bodyDataID = :bodyDataID ]]>
+ </query>
+ <query name="com.ogoglio.persist.bodyDataByFileName">
+ <![CDATA[ from com.ogoglio.persist.BodyDataRecord as record where record.fileName = :fileName ]]>
+ </query>
+ <query
+ name="com.ogoglio.persist.bodyConfigurationByUsernameAndBodyDataID">
+ <![CDATA[ from com.ogoglio.persist.BodyConfigurationRecord as record where record.ownerUsername = :username and record.bodyDataID = :bodyDataID ]]>
+ </query>
+ <query name="com.ogoglio.persist.bodyConfigurationsByUsername">
+ <![CDATA[ from com.ogoglio.persist.BodyConfigurationRecord as record where record.ownerUsername = :username ]]>
+ </query>
+ <query name="com.ogoglio.persist.bodyConfigurationByID">
+ <![CDATA[ from com.ogoglio.persist.BodyConfigurationRecord as record where record.bodyConfigurationID = :bodyConfigurationID ]]>
+ </query>
+ <query name="com.ogoglio.persist.bodySettingsByConfigurationID">
+ <![CDATA[ from com.ogoglio.persist.BodySettingRecord as record where record.bodyConfigurationID = :bodyConfigurationID ]]>
+ </query>
+ <query
+ name="com.ogoglio.persist.bodySettingByConfigurationIDAndSettingName">
+ <![CDATA[ from com.ogoglio.persist.BodySettingRecord as record where record.bodyConfigurationID = :bodyConfigurationID and record.settingName = :settingName ]]>
+ </query>
+ <query name="com.ogoglio.persist.attachmentsByConfigurationID">
+ <![CDATA[ from com.ogoglio.persist.AttachmentRecord as record where record.bodyConfigurationID = :bodyConfigurationID ]]>
+ </query>
+ <query name="com.ogoglio.persist.attachmentByID">
+ <![CDATA[ from com.ogoglio.persist.AttachmentRecord as record where record.attachmentID = :attachmentID ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.serviceStateRecords">
+ <![CDATA[ from com.ogoglio.persist.ServiceStateRecord ]]>
+ </query>
+
+ <query
+ name="com.ogoglio.persist.pendingEmailValidationsByUsername">
+ <![CDATA[ from com.ogoglio.persist.PendingEmailValidationRecord as record where record.username = :username ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.pendingEmailValidationByEmail">
+ <![CDATA[ from com.ogoglio.persist.PendingEmailValidationRecord as record where record.email = :email ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.pendingEmailValidationBySecret">
+ <![CDATA[ from com.ogoglio.persist.PendingEmailValidationRecord as record where record.secret = :secret ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.possessionByPossessionID">
+ <![CDATA[ from com.ogoglio.persist.PossessionRecord as possession where possession.possessionID = :possessionID ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.possessionsByOwnerUsername">
+ <![CDATA[ from com.ogoglio.persist.PossessionRecord as possession where possession.ownerUsername = :ownerUsername ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.possessionsBySpaceID">
+ <![CDATA[ from com.ogoglio.persist.PossessionRecord as possession where possession.spaceID = :spaceID ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.possessionsByTemplateID">
+ <![CDATA[ from com.ogoglio.persist.PossessionRecord as possession where possession.templateID = :templateID ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.templateByID">
+ <![CDATA[ from com.ogoglio.persist.TemplateRecord as template where template.templateID = :templateID ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.templateByIDs">
+ <![CDATA[ from com.ogoglio.persist.TemplateRecord as template where template.templateID in ( :templateIDs ) ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.templateByOwner">
+ <![CDATA[ from com.ogoglio.persist.TemplateRecord as template where template.ownerUsername = :ownerUsername ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.accountByUsername">
+ <![CDATA[ from com.ogoglio.persist.AccountRecord as account where account.username = :username ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.accountByEmail">
+ <![CDATA[ from com.ogoglio.persist.AccountRecord as account where account.email = :email ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.accountByCookie">
+ <![CDATA[ from com.ogoglio.persist.AccountRecord as account where account.cookie = :cookie ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.simByURI">
+ <![CDATA[ from com.ogoglio.persist.SimRecord as sim where sim.simURIString = :simURI ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.simBySimID">
+ <![CDATA[ from com.ogoglio.persist.SimRecord as sim where sim.simID = :simID ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.simsByReachableAndRetired">
+ <![CDATA[ from com.ogoglio.persist.SimRecord as sim where sim.reachable = :reachable and sim.retired = :retired]]>
+ </query>
+
+ <query name="com.ogoglio.persist.simsByReachable">
+ <![CDATA[ from com.ogoglio.persist.SimRecord as sim where sim.reachable = :reachable ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.sims">
+ <![CDATA[ from com.ogoglio.persist.SimRecord ]]>
+ </query>
+
+ <query name="com.ogoglio.appdev.migrate.dbversions">
+ <![CDATA[ from com.ogoglio.appdev.migrate.DBVersionRecord ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.accounts">
+ <![CDATA[ from com.ogoglio.persist.AccountRecord ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.possessions">
+ <![CDATA[ from com.ogoglio.persist.PossessionRecord order by PossessionID asc ]]>
+ </query>
+ <query name="com.ogoglio.persist.spaces">
+ <![CDATA[ from com.ogoglio.persist.SpaceRecord order by SpaceID asc]]>
+ </query>
+ <query name="com.ogoglio.persist.spacemembers">
+ <![CDATA[ from com.ogoglio.persist.SpaceMemberRecord order by SpaceMemberID asc]]>
+ </query>
+
+ <query name="com.ogoglio.persist.spacesByOwnerUsername">
+ <![CDATA[ from com.ogoglio.persist.SpaceRecord as space where space.ownerUsername = :ownerUsername ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.spaceBySpaceID">
+ <![CDATA[ from com.ogoglio.persist.SpaceRecord as space where space.spaceID = :spaceID ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.spaceMembersBySpaceID">
+ <![CDATA[ from com.ogoglio.persist.SpaceMemberRecord as spaceMember where spaceMember.spaceID = :spaceID ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.spaceMembershipByMemberUsername">
+ <![CDATA[ from com.ogoglio.persist.SpaceMemberRecord as spaceMember where spaceMember.memberUsername = :memberUsername ]]>
+ </query>
+
+ <query name="com.ogoglio.persist.spaceMemberByUsername">
+ <![CDATA[ from com.ogoglio.persist.SpaceMemberRecord as spaceMember where spaceMember.spaceID = :spaceID and spaceMember.memberUsername = :username ]]>
+ </query>
+</hibernate-mapping>
Modified: maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java
===================================================================
--- maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java 2008-02-07 01:01:18 UTC (rev 719)
+++ maven/trunk/ogoglio-server/src/test/java/com/ogoglio/persist/test/PersistTest.java 2008-02-07 02:28:03 UTC (rev 720)
@@ -37,6 +37,7 @@
import com.ogoglio.persist.SpaceRecord;
import com.ogoglio.persist.TemplatePersistTasks;
import com.ogoglio.persist.TemplateRecord;
+import com.ogoglio.util.ArgumentUtils;
import com.ogoglio.util.Log;
import com.ogoglio.util.PropStorage;
@@ -64,7 +65,7 @@
try {
SimRecord simRecord1 = SimPersistTasks.findSimsBySimURI(simURI1, sessionFactory);
if (simRecord1 != null) {
- Log.test("Destroying leftover sim record test state:" + simRecord1.getDisplayName());
+ Log.test("Destroying leftover sim record test state:" + simRecord1.getSimID());
SimPersistTasks.delete(simRecord1, sessionFactory);
}
} catch (PersistException e) {
@@ -225,16 +226,12 @@
private SpaceRecord checkSpaceAndSimTasks() throws PersistException {
SimRecord simRecord1;
// ok to create sim now on that URI
- simRecord1 = SimPersistTasks.createSim(displayName1, simURI1, 2048, true, sessionFactory);
- verifySimProps(simRecord1, displayName1, simURI1, -1, 2048);
+ simRecord1 = SimPersistTasks.createSim(simURI1, true, false, sessionFactory);
+ verifySimProps(simRecord1, simURI1, -1);
- String displayName2 = "moon unit";
- simRecord1.setDisplayName(displayName2);
- SimPersistTasks.update(simRecord1, sessionFactory);
- assertEquals(displayName2, simRecord1.getDisplayName());
// better test is to load it from db
SimRecord simRecord2 = SimPersistTasks.findSimsBySimURI(simURI1, sessionFactory);
- verifySimProps(simRecord2, displayName2, simURI1, -1, 2048);
+ verifySimProps(simRecord2, simURI1, -1);
// it's the same sim on the same URI so better have same id?
assertEquals(simRecord1.getSimID(), simRecord2.getSimID());
@@ -253,39 +250,46 @@
SimRecord assignedSimRecord = SpacePersistTasks.findOrAssignSim(spaceRecord2, sessionFactory, false);
assertNotNull(assignedSimRecord);
- assertTrue(assignedSimRecord.isActive());
+ assertTrue(assignedSimRecord.isReachable());
+ assertFalse(assignedSimRecord.isRetired());
- //System.out.println("XXX ASSIGNED TO SIM:"
- // + assignedSimRecord.getSimID() + ","
- // + assignedSimRecord.getSimURI() + " -->\n" + "space was "
- // + spaceRecord2.getSpaceID() + " now on "
- // + spaceRecord2.getSimID() + ","
- // + spaceRecord2.getDisplayName());
- /*
- * IES: I spent a lot of time looking at this and could not see any
- * way to test this given that IES: that assigned sim is random.
- * Apparently, before we were depending on a random number IES:
- * sequence doing something we expected.
- * assertEquals(simRecord1.getSimURI(),
- * assignedSimRecord.getSimURI());
- * assertEquals(simRecord1.getDisplayName(),
- * assignedSimRecord.getDisplayName());
- * assertEquals(simRecord1.getSimID(),
- * assignedSimRecord.getSimID()); assertEquals(simRecord1,
- * assignedSimRecord);
- */
-
+ //bogus sim
+ URI bossaNova=ArgumentUtils.createURI("http://bossanova.example.com");
+ SimRecord bogus1 = SimPersistTasks.createSim(bossaNova,true, false, sessionFactory);
+ SimRecord[] arrayOfOne=new SimRecord[] {bogus1};
+
+ //verify that right now we are reachable
+ assertTrue(SimPersistTasks.findSimsBySimURI(bossaNova,sessionFactory).isReachable());
+ //check on that URI
+ SpacePersistTasks.verifyReachableSims(arrayOfOne, sessionFactory);
+ assertFalse(SimPersistTasks.findSimsBySimURI(bossaNova,sessionFactory).isReachable());
+ //ok it's not reachable, clean up
+ SimPersistTasks.delete(bogus1, sessionFactory);
+
+ //make a new space
+ SpaceRecord spaceMen3 = SpacePersistTasks.createSpace(spaceName1, username1, sessionFactory);
+ assertNotNull(spaceMen3);
+ //mark the sim as retired so we can't assign to it
+ simRecord1.setRetired(true);
+ SimPersistTasks.update(simRecord1, sessionFactory);
+ //we cannot assign this space
+ try {
+ SpacePersistTasks.findOrAssignSim(spaceMen3, sessionFactory);
+ fail("Should not be able to assign new spaces to a retired sim!");
+ } catch (PersistException IGNORED) {
+ //we expected this
+ }
+ SpacePersistTasks.deleteSpace(spaceMen3, sessionFactory);
+
//subtle: need to return 2 ... because these differ in the assignment of the simid
//since we assigned the spaceRecord2 version to a sim
return spaceRecord2;
}
- private void verifySimProps(SimRecord rec, String name, URI uri, int not_id, int port) {
+ private void verifySimProps(SimRecord rec, URI uri, int not_id) {
assertNotNull(rec);
- assertEquals(name, rec.getDisplayName());
assertEquals(uri, rec.getSimURI());
assertFalse(not_id == rec.getSimID());
- assertEquals(port, rec.getEventPort());
}
private void verifyTemplateProps(String templateName1, TemplateRecord templateRec1) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|