diff --git a/src/com/projectswg/CombinedLightspeed.java b/src/com/projectswg/CombinedLightspeed.java index 6cfde99..dd7cd39 100644 --- a/src/com/projectswg/CombinedLightspeed.java +++ b/src/com/projectswg/CombinedLightspeed.java @@ -34,13 +34,13 @@ import javax.swing.JFileChooser; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; +import com.projectswg.lightspeed.server.ServerServerData; import com.projectswg.lightspeed_frontend.LightspeedFrontendGUI; -import com.projectswg.lightspeed_frontend.data.SharedServerData; public class CombinedLightspeed { public static void main(String [] args) { - SharedServerData server = getServer(); + ServerServerData server = getServer(); if (server == null) return; AtomicBoolean running = new AtomicBoolean(true); @@ -49,7 +49,7 @@ public class CombinedLightspeed { running.set(false); } - private static SharedServerData getServer() { + private static ServerServerData getServer() { try { if (System.getProperty("os.name").toLowerCase().contains("win")) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); @@ -61,7 +61,7 @@ public class CombinedLightspeed { chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) return null; - SharedServerData server = new SharedServerData("LIGHTSPEED"); + ServerServerData server = new ServerServerData("LIGHTSPEED"); server.setDirectory(chooser.getSelectedFile().getAbsolutePath()); return server; } diff --git a/src/com/projectswg/LightweightLightspeed.java b/src/com/projectswg/LightweightLightspeed.java index f58d0cf..79c65f0 100644 --- a/src/com/projectswg/LightweightLightspeed.java +++ b/src/com/projectswg/LightweightLightspeed.java @@ -34,11 +34,11 @@ import com.projectswg.common.info.ConfigFile; import com.projectswg.common.info.LightweightDataManager; import com.projectswg.common.info.Log; import com.projectswg.lightspeed.LightspeedManager; -import com.projectswg.lightspeed_frontend.data.SharedServerData; +import com.projectswg.lightspeed.server.ServerServerData; public class LightweightLightspeed { - public static int runConcurrent(SharedServerData server, AtomicBoolean running) { + public static int runConcurrent(ServerServerData server, AtomicBoolean running) { Thread mainThread = Thread.currentThread(); LightspeedManager.setDataManager(createDataManager(0, server)); Runtime.getRuntime().addShutdownHook(new Thread(() -> { @@ -54,7 +54,7 @@ public class LightweightLightspeed { return runLightspeedConcurrent(running); } - public static void run(int port, SharedServerData server) { + public static void run(int port, ServerServerData server) { Thread mainThread = Thread.currentThread(); AtomicBoolean running = new AtomicBoolean(true); LightspeedManager.setDataManager(createDataManager(port, server)); @@ -66,7 +66,7 @@ public class LightweightLightspeed { LightspeedManager.getDataManager().terminate(); } - private static LightweightDataManager createDataManager(int port, SharedServerData server) { + private static LightweightDataManager createDataManager(int port, ServerServerData server) { LightweightDataManager dataManager = new LightweightDataManager(); dataManager.initialize(); Config lightspeed = dataManager.getConfig(ConfigFile.LIGHTSPEED); diff --git a/src/com/projectswg/common/data/BackendData.java b/src/com/projectswg/common/data/BackendData.java index 6ba1929..5b05765 100644 --- a/src/com/projectswg/common/data/BackendData.java +++ b/src/com/projectswg/common/data/BackendData.java @@ -29,17 +29,17 @@ package com.projectswg.common.data; import java.util.List; -import com.projectswg.lightspeed_frontend.data.SharedBuildData; -import com.projectswg.lightspeed_frontend.data.SharedDeploymentData; -import com.projectswg.lightspeed_frontend.data.SharedServerData; +import com.projectswg.lightspeed.build.ServerBuildData; +import com.projectswg.lightspeed.deployment.ServerDeploymentData; +import com.projectswg.lightspeed.server.ServerServerData; public interface BackendData { - SharedServerData getServer(String serverId); - List getServerList(); - void insertServer(SharedServerData server); - void insertBuild(SharedBuildData build); - void insertDeployment(SharedDeploymentData deployment); + ServerServerData getServer(String serverId); + List getServerList(); + void insertServer(ServerServerData server); + void insertBuild(ServerBuildData build); + void insertDeployment(ServerDeploymentData deployment); void removeServer(String serverId); } diff --git a/src/com/projectswg/common/data/HeavyweightBackendData.java b/src/com/projectswg/common/data/HeavyweightBackendData.java index 3004c4d..f836653 100644 --- a/src/com/projectswg/common/data/HeavyweightBackendData.java +++ b/src/com/projectswg/common/data/HeavyweightBackendData.java @@ -31,40 +31,39 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import com.projectswg.common.info.RelationalDatabase; import com.projectswg.common.info.RelationalServerFactory; -import com.projectswg.lightspeed_frontend.data.SharedBuildData; -import com.projectswg.lightspeed_frontend.data.SharedDeploymentData; -import com.projectswg.lightspeed_frontend.data.SharedServerData; +import com.projectswg.lightspeed.build.ServerBuildData; +import com.projectswg.lightspeed.deployment.ServerDeploymentData; +import com.projectswg.lightspeed.server.ServerServerData; public class HeavyweightBackendData implements BackendData { - private final Map serverMap; + private final Map serverMap; public HeavyweightBackendData() { this.serverMap = new HashMap<>(); loadServers(); } - public void insertServer(SharedServerData server) { + public void insertServer(ServerServerData server) { synchronized (serverMap) { if (serverMap.put(server.getName(), server) != null) return; } try (ServerTable serverTable = new ServerTable()) { - serverTable.insertServer(new SQLServerData(server.getName(), server.getDirectory(), server.getJvmArguments())); + serverTable.insertServer(new SQLServerData(server)); } } - public void insertBuild(SharedBuildData build) { + public void insertBuild(ServerBuildData build) { try (BuildHistoryTable buildTable = new BuildHistoryTable()) { buildTable.insertBuildHistory(new SQLBuildData(build)); } } - public void insertDeployment(SharedDeploymentData deployment) { + public void insertDeployment(ServerDeploymentData deployment) { try (DeploymentTable deploymentTable = new DeploymentTable()) { deploymentTable.insertDeployment(new SQLDeploymentData(deployment)); } @@ -79,19 +78,17 @@ public class HeavyweightBackendData implements BackendData { } } - public List getServerList() { - List servers = new ArrayList<>(serverMap.size()); + public List getServerList() { + List servers; synchronized (serverMap) { - for (Entry e : serverMap.entrySet()) { - servers.add(e.getValue()); - } + servers = new ArrayList<>(serverMap.values()); } return servers; } - public SharedServerData getServer(String serverId) { + public ServerServerData getServer(String serverId) { synchronized (serverMap) { - SharedServerData server = serverMap.get(serverId); + ServerServerData server = serverMap.get(serverId); if (server == null) return server; try (RelationalDatabase db = RelationalServerFactory.getServerDatabase("lightspeed.db")) { @@ -106,7 +103,7 @@ public class HeavyweightBackendData implements BackendData { try (RelationalDatabase db = RelationalServerFactory.getServerDatabase("lightspeed.db")) { try (ServerTable serverTable = new ServerTable(db)) { for (String serverId : serverTable.getServerStrings()) { - SharedServerData server = createServerFromInfo(serverTable.getServerById(serverId)); + ServerServerData server = createServerFromInfo(serverTable.getServerById(serverId)); fetchBuildHistory(db, server); serverMap.put(serverId, server); } @@ -115,34 +112,34 @@ public class HeavyweightBackendData implements BackendData { } } - private void fetchBuildHistory(RelationalDatabase db, SharedServerData server) { + private void fetchBuildHistory(RelationalDatabase db, ServerServerData server) { try (BuildHistoryTable buildTable = new BuildHistoryTable(db)) { for (SQLBuildData info : buildTable.getBuildHistory(server.getName())) { - SharedBuildData build = createBuildFromInfo(server, info); + ServerBuildData build = createBuildFromInfo(server, info); fetchDeploymentHistory(db, server, build); server.addBuild(build); } } } - private void fetchDeploymentHistory(RelationalDatabase db, SharedServerData server, SharedBuildData build) { + private void fetchDeploymentHistory(RelationalDatabase db, ServerServerData server, ServerBuildData build) { try (DeploymentTable deploymentTable = new DeploymentTable(db)) { for (SQLDeploymentData info : deploymentTable.getDeployments(server.getName())) { - SharedDeploymentData deployment = createDeploymentFromInfo(build, info); + ServerDeploymentData deployment = createDeploymentFromInfo(build, info); server.addDeployment(deployment); } } } - private SharedServerData createServerFromInfo(SQLServerData info) { - SharedServerData server = new SharedServerData(info.getId()); + private ServerServerData createServerFromInfo(SQLServerData info) { + ServerServerData server = new ServerServerData(info.getId()); server.setDirectory(info.getDir()); server.setJvmArguments(info.getJvmArgs()); return server; } - private SharedBuildData createBuildFromInfo(SharedServerData server, SQLBuildData info) { - SharedBuildData build = new SharedBuildData(info.getId(), server); + private ServerBuildData createBuildFromInfo(ServerServerData server, SQLBuildData info) { + ServerBuildData build = new ServerBuildData(info.getId(), server); build.setTime(info.getCompletedTime()); build.setBuildString(info.getBuildString()); build.setTestString(info.getTestString()); @@ -154,8 +151,8 @@ public class HeavyweightBackendData implements BackendData { return build; } - private SharedDeploymentData createDeploymentFromInfo(SharedBuildData build, SQLDeploymentData info) { - SharedDeploymentData deployment = new SharedDeploymentData(info.getId(), build); + private ServerDeploymentData createDeploymentFromInfo(ServerBuildData build, SQLDeploymentData info) { + ServerDeploymentData deployment = new ServerDeploymentData(info.getId(), build); deployment.setStartTime(info.getStartTime()); deployment.setEndTime(info.getEndTime()); return deployment; diff --git a/src/com/projectswg/common/data/LightweightBackendData.java b/src/com/projectswg/common/data/LightweightBackendData.java index ef081c6..f8edba8 100644 --- a/src/com/projectswg/common/data/LightweightBackendData.java +++ b/src/com/projectswg/common/data/LightweightBackendData.java @@ -32,40 +32,40 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.projectswg.lightspeed_frontend.data.SharedBuildData; -import com.projectswg.lightspeed_frontend.data.SharedDeploymentData; -import com.projectswg.lightspeed_frontend.data.SharedServerData; +import com.projectswg.lightspeed.build.ServerBuildData; +import com.projectswg.lightspeed.deployment.ServerDeploymentData; +import com.projectswg.lightspeed.server.ServerServerData; public class LightweightBackendData implements BackendData { - private final Map serverMap; + private final Map serverMap; public LightweightBackendData() { serverMap = new HashMap<>(); } @Override - public SharedServerData getServer(String serverId) { + public ServerServerData getServer(String serverId) { return serverMap.get(serverId); } @Override - public List getServerList() { + public List getServerList() { return new ArrayList<>(serverMap.values()); } @Override - public void insertServer(SharedServerData server) { + public void insertServer(ServerServerData server) { serverMap.put(server.getName(), server); } @Override - public void insertBuild(SharedBuildData build) { + public void insertBuild(ServerBuildData build) { } @Override - public void insertDeployment(SharedDeploymentData deployment) { + public void insertDeployment(ServerDeploymentData deployment) { } diff --git a/src/com/projectswg/common/data/SQLBuildData.java b/src/com/projectswg/common/data/SQLBuildData.java index 7136f69..0cfecd2 100644 --- a/src/com/projectswg/common/data/SQLBuildData.java +++ b/src/com/projectswg/common/data/SQLBuildData.java @@ -29,8 +29,6 @@ package com.projectswg.common.data; import com.projectswg.common.utilities.TimeUtilities; import com.projectswg.lightspeed.build.ServerBuildData; -import com.projectswg.lightspeed.build.InstallationState; -import com.projectswg.lightspeed_frontend.data.SharedBuildData; import me.joshlarson.json.JSONObject; @@ -47,20 +45,7 @@ class SQLBuildData { private boolean cancelled; private TestDetails testDetails; - public SQLBuildData(long id, String serverId, ServerBuildData installation) { - this.id = id; - this.serverId = serverId; - this.buildString = installation.getBuildString(); - this.testString = installation.getTestString(); - this.completedTime = installation.getCompletedTime(); - this.compileTime = installation.getCompileTime(); - this.buildSuccess = installation.isBuildSuccess(); - this.testSuccess = installation.isTestSuccess(); - this.cancelled = installation.getState() == InstallationState.CANCELLED; - this.testDetails = installation.getTestDetails(); - } - - public SQLBuildData(SharedBuildData build) { + public SQLBuildData(ServerBuildData build) { this.id = build.getId(); this.serverId = build.getServer().getName(); this.buildString = build.getBuildString(); diff --git a/src/com/projectswg/common/data/SQLDeploymentData.java b/src/com/projectswg/common/data/SQLDeploymentData.java index c42cbc6..d808cd3 100644 --- a/src/com/projectswg/common/data/SQLDeploymentData.java +++ b/src/com/projectswg/common/data/SQLDeploymentData.java @@ -28,7 +28,7 @@ package com.projectswg.common.data; import com.projectswg.common.utilities.TimeUtilities; -import com.projectswg.lightspeed_frontend.data.SharedDeploymentData; +import com.projectswg.lightspeed.deployment.ServerDeploymentData; import me.joshlarson.json.JSONObject; @@ -40,7 +40,7 @@ class SQLDeploymentData { private long startTime; private long endTime; - public SQLDeploymentData(SharedDeploymentData deployment) { + public SQLDeploymentData(ServerDeploymentData deployment) { this.id = deployment.getId(); this.serverId = deployment.getServer().getName(); this.buildId = deployment.getBuild().getId(); diff --git a/src/com/projectswg/common/data/SQLServerData.java b/src/com/projectswg/common/data/SQLServerData.java index c267043..dbac0de 100644 --- a/src/com/projectswg/common/data/SQLServerData.java +++ b/src/com/projectswg/common/data/SQLServerData.java @@ -27,6 +27,8 @@ ***********************************************************************************/ package com.projectswg.common.data; +import com.projectswg.lightspeed.server.ServerServerData; + class SQLServerData { private final String id; @@ -39,6 +41,12 @@ class SQLServerData { this.jvmArgs = jvmArgs; } + public SQLServerData(ServerServerData server) { + this.id = server.getName(); + this.dir = server.getDirectory(); + this.jvmArgs = server.getJvmArguments(); + } + public String getId() { return id; } diff --git a/src/com/projectswg/common/intents/LaunchStarshipIntent.java b/src/com/projectswg/common/intents/LaunchStarshipIntent.java index aa21a5b..eb78d83 100644 --- a/src/com/projectswg/common/intents/LaunchStarshipIntent.java +++ b/src/com/projectswg/common/intents/LaunchStarshipIntent.java @@ -28,28 +28,28 @@ package com.projectswg.common.intents; import com.projectswg.common.control.Intent; -import com.projectswg.lightspeed_frontend.data.SharedBuildData; +import com.projectswg.lightspeed.build.ServerBuildData; public class LaunchStarshipIntent extends Intent { public static final String TYPE = "LaunchStarshipIntent"; - private SharedBuildData build; + private ServerBuildData build; public LaunchStarshipIntent() { this(null); } - public LaunchStarshipIntent(SharedBuildData build) { + public LaunchStarshipIntent(ServerBuildData build) { super(TYPE); setBuild(build); } - public SharedBuildData getBuild() { + public ServerBuildData getBuild() { return build; } - public void setBuild(SharedBuildData build) { + public void setBuild(ServerBuildData build) { this.build = build; } diff --git a/src/com/projectswg/common/intents/PrepareStarshipIntent.java b/src/com/projectswg/common/intents/PrepareStarshipIntent.java index 4923366..5a01625 100644 --- a/src/com/projectswg/common/intents/PrepareStarshipIntent.java +++ b/src/com/projectswg/common/intents/PrepareStarshipIntent.java @@ -28,28 +28,28 @@ package com.projectswg.common.intents; import com.projectswg.common.control.Intent; -import com.projectswg.lightspeed_frontend.data.SharedServerData; +import com.projectswg.lightspeed.server.ServerServerData; public class PrepareStarshipIntent extends Intent { public static final String TYPE = "PrepareStarshipIntent"; - private SharedServerData server; + private ServerServerData server; public PrepareStarshipIntent() { this(null); } - public PrepareStarshipIntent(SharedServerData server) { + public PrepareStarshipIntent(ServerServerData server) { super(TYPE); setServer(server); } - public SharedServerData getServer() { + public ServerServerData getServer() { return server; } - public void setServer(SharedServerData server) { + public void setServer(ServerServerData server) { this.server = server; } diff --git a/src/com/projectswg/lightspeed/DeploymentService.java b/src/com/projectswg/lightspeed/DeploymentService.java index 61a3477..60db943 100644 --- a/src/com/projectswg/lightspeed/DeploymentService.java +++ b/src/com/projectswg/lightspeed/DeploymentService.java @@ -31,9 +31,7 @@ import java.io.File; import java.net.InetSocketAddress; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; @@ -45,19 +43,13 @@ import com.projectswg.common.info.RelationalDatabase; import com.projectswg.common.info.RelationalServerFactory; import com.projectswg.common.intents.InboundPacketIntent; import com.projectswg.common.intents.LaunchStarshipIntent; -import com.projectswg.common.intents.OutboundPacketIntent; import com.projectswg.common.network.packets.Packet; import com.projectswg.common.network.packets.post.PostDeployPacket; import com.projectswg.common.network.packets.post.PostStopDeployPacket; -import com.projectswg.common.network.packets.request.RequestDeploymentHistoryPacket; -import com.projectswg.common.network.packets.request.RequestPacket; -import com.projectswg.common.network.packets.response.ResponseDeploymentHistoryPacket; -import com.projectswg.common.network.packets.response.ResponseDeploymentStatusPacket; import com.projectswg.common.utilities.TimeUtilities; +import com.projectswg.lightspeed.build.ServerBuildData; import com.projectswg.lightspeed.deployment.ServerDeploymentData; -import com.projectswg.lightspeed_frontend.data.SharedBuildData; -import com.projectswg.lightspeed_frontend.data.SharedDeploymentData; -import com.projectswg.lightspeed_frontend.data.SharedServerData; +import com.projectswg.lightspeed.server.ServerServerData; public class DeploymentService extends Service { @@ -78,13 +70,8 @@ public class DeploymentService extends Service { ResultSet set = db.executeQuery("SELECT MAX(id) FROM deployments"); if (set.next()) deploymentId.set(set.getLong(1)); - for (SharedServerData server : getBackendData().getServerList()) { - SharedDeploymentData last = server.getLastDeployment(); - if (last != null) { - ServerDeploymentData d = new ServerDeploymentData(last); - deployments.put(server.getName(), d); - } - } + else + Assert.fail(); } catch (SQLException e) { e.printStackTrace(); } @@ -106,9 +93,9 @@ public class DeploymentService extends Service { @Override public void onIntentReceived(Intent i) { if (i instanceof LaunchStarshipIntent) { - SharedBuildData build = ((LaunchStarshipIntent) i).getBuild(); + ServerBuildData build = ((LaunchStarshipIntent) i).getBuild(); Log.i(this, "Deploying %s", build.getServer().getName()); - ServerDeploymentData deployment = new ServerDeploymentData(new SharedDeploymentData(deploymentId.incrementAndGet(), build)); + ServerDeploymentData deployment = new ServerDeploymentData(deploymentId.incrementAndGet(), build); launch(deployment); } else if (i instanceof InboundPacketIntent) { processInboundPacketIntent(((InboundPacketIntent) i).getAddress(), ((InboundPacketIntent) i).getPacket()); @@ -119,8 +106,6 @@ public class DeploymentService extends Service { switch (p.getType()) { case POST_DEPLOY: launchStarship(((PostDeployPacket) p).getServerId()); break; case POST_STOP_DEPLOY: processStopDeployment((PostStopDeployPacket) p); break; - case REQUEST_DEPLOYMENT_STATUS: processRequestDeploymentStatus(address, ((RequestPacket) p).getRequestId()); break; - case REQUEST_DEPLOYMENT_HISTORY:processRequestDeploymentHistory(address, ((RequestDeploymentHistoryPacket) p)); break; default: break; } } @@ -135,42 +120,15 @@ public class DeploymentService extends Service { } } - private void processRequestDeploymentStatus(InetSocketAddress address, long requestId) { - List deployments = new ArrayList<>(this.deployments.size()); - synchronized (this.deployments) { - for (ServerDeploymentData deployment : this.deployments.values()) { - deployments.add(new SharedDeploymentData(deployment.getId(), deployment.getBuild())); - } - } - new OutboundPacketIntent(address, ResponseDeploymentStatusPacket.create(requestId, deployments)).broadcast(); - } - - private void processRequestDeploymentHistory(InetSocketAddress address, RequestDeploymentHistoryPacket req) { - SharedServerData server = getBackendData().getServer(req.getServerId()); - Assert.notNull(server); - List deployments = server.getDeployments(); - synchronized (this.deployments) { - for (ServerDeploymentData deployment : this.deployments.values()) { - if (deployment.getServer().getName().equals(req.getServerId())) { - SharedDeploymentData data = new SharedDeploymentData(deployment.getId(), deployment.getBuild()); - data.setStartTime(deployment.getStartTime()); - data.setEndTime(deployment.getEndTime()); - deployments.add(data); - } - } - } - new OutboundPacketIntent(address, ResponseDeploymentHistoryPacket.create(req.getRequestId(), deployments)).broadcast(); - } - private void launchStarship(String serverId) { - SharedServerData server = getBackendData().getServer(serverId); - SharedBuildData build = server.getLastBuild(); + ServerServerData server = getBackendData().getServer(serverId); + ServerBuildData build = server.getLastBuild(); if (!launchStarshipChecks(build)) return; new LaunchStarshipIntent(build).broadcast(); } - private boolean launchStarshipChecks(SharedBuildData build) { + private boolean launchStarshipChecks(ServerBuildData build) { if (build == null) { Log.e(this, "Unable to launch - no build found!"); return false; @@ -222,7 +180,7 @@ public class DeploymentService extends Service { private void onDeploymentEnded(ServerDeploymentData deployment) { deployment.setEndTime(TimeUtilities.getTime()); - getBackendData().insertDeployment(deployment.getDeploymentData()); + getBackendData().insertDeployment(deployment); Log.i(this, "%s has finished deploying after %.2f minutes", deployment.getServer().getName(), (deployment.getEndTime()-deployment.getStartTime())/60E3); } diff --git a/src/com/projectswg/lightspeed/LightspeedManager.java b/src/com/projectswg/lightspeed/LightspeedManager.java index 85b093d..8b3005e 100644 --- a/src/com/projectswg/lightspeed/LightspeedManager.java +++ b/src/com/projectswg/lightspeed/LightspeedManager.java @@ -29,21 +29,25 @@ package com.projectswg.lightspeed; import com.projectswg.common.control.Manager; import com.projectswg.lightspeed.build.BuildService; +import com.projectswg.lightspeed.server.ServerService; public class LightspeedManager extends Manager { private final GitListenerService gitListenerService; + private final ServerService serverService; private final BuildService buildService; private final DeploymentService deploymentService; private final CommunicationService communicationService; public LightspeedManager() { gitListenerService = new GitListenerService(); + serverService = new ServerService(); buildService = new BuildService(); deploymentService = new DeploymentService(); communicationService = new CommunicationService(); addChildService(gitListenerService); + addChildService(serverService); addChildService(buildService); addChildService(deploymentService); addChildService(communicationService); diff --git a/src/com/projectswg/lightspeed/StarshipProcess.java b/src/com/projectswg/lightspeed/StarshipProcess.java index cd9a317..09f4265 100644 --- a/src/com/projectswg/lightspeed/StarshipProcess.java +++ b/src/com/projectswg/lightspeed/StarshipProcess.java @@ -130,7 +130,7 @@ public class StarshipProcess { while (gobbler.readLine() != null) ; // gobble. } catch (IOException e) { - if (Assert.debug()) + if (Assert.debug() && (e.getMessage() == null || !e.getMessage().toLowerCase().contains("closed"))) e.printStackTrace(); } } diff --git a/src/com/projectswg/lightspeed/build/BuildService.java b/src/com/projectswg/lightspeed/build/BuildService.java index a9a60f2..1e67dd0 100644 --- a/src/com/projectswg/lightspeed/build/BuildService.java +++ b/src/com/projectswg/lightspeed/build/BuildService.java @@ -29,14 +29,11 @@ package com.projectswg.lightspeed.build; import java.io.File; import java.io.IOException; -import java.net.InetSocketAddress; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; @@ -48,24 +45,16 @@ import com.projectswg.common.info.RelationalDatabase; import com.projectswg.common.info.RelationalServerFactory; import com.projectswg.common.intents.InboundPacketIntent; import com.projectswg.common.intents.LaunchStarshipIntent; -import com.projectswg.common.intents.OutboundPacketIntent; import com.projectswg.common.intents.PrepareStarshipIntent; import com.projectswg.common.network.packets.Packet; import com.projectswg.common.network.packets.post.PostBuildPacket; -import com.projectswg.common.network.packets.post.PostCreateServerPacket; -import com.projectswg.common.network.packets.post.PostDeleteServerPacket; import com.projectswg.common.network.packets.post.PostStopBuildPacket; -import com.projectswg.common.network.packets.request.RequestBuildHistoryPacket; -import com.projectswg.common.network.packets.request.RequestPacket; -import com.projectswg.common.network.packets.response.ResponseBuildHistoryPacket; -import com.projectswg.common.network.packets.response.ResponseServerListPacket; import com.projectswg.lightspeed.build.ServerBuildData.InstallationCallback; -import com.projectswg.lightspeed_frontend.data.SharedBuildData; -import com.projectswg.lightspeed_frontend.data.SharedServerData; +import com.projectswg.lightspeed.server.ServerServerData; public class BuildService extends Service { - private final BuildMethod buildMethod; + private final JavaBuildMethod buildMethod; private final AtomicLong buildId; private final Map inprogress; @@ -101,36 +90,29 @@ public class BuildService extends Service { private void onPrepareStarshipIntent(PrepareStarshipIntent psi) { Log.i(this, "Building %s...", psi.getServer().getName()); - ServerBuildData installation = buildMethod.createJar(psi.getServer().getDirectory(), new InstallationCallback() { - public void onStateChanged(InstallationState oldState, InstallationState newState) { } - public void onCompleted() { BuildService.this.onCompleted(psi.getServer().getName()); } - public void onCancelled() { BuildService.this.onCancelled(psi.getServer().getName()); } + ServerBuildData installation = buildMethod.createJar(buildId.incrementAndGet(), psi.getServer(), new InstallationCallback() { + public void onStateChanged(ServerBuildData build, InstallationState oldState, InstallationState newState) { } + public void onCompleted(ServerBuildData build) { BuildService.this.onCompleted(psi.getServer().getName(), build); } + public void onCancelled(ServerBuildData build) { BuildService.this.onCancelled(psi.getServer().getName(), build); } }); synchronized (inprogress) { ServerBuildData old = inprogress.put(psi.getServer().getName(), installation); if (old != null) - old.cancel(); + old.setState(InstallationState.CANCELLED); } } private void onInboundPacketIntent(InboundPacketIntent ipi) { - InetSocketAddress address = ipi.getAddress(); Packet p = ipi.getPacket(); switch (p.getType()) { case POST_BUILD: processBuild((PostBuildPacket) p); break; case POST_STOP_BUILD: processPostStopBuild((PostStopBuildPacket) p); break; - case POST_CREATE_SERVER: processPostCreateServer((PostCreateServerPacket) p); break; - case POST_DELETE_SERVER: processPostDeleteServer((PostDeleteServerPacket) p); break; - case REQUEST_BUILD_HISTORY: - sendBuildHistoryResponse(address, ((RequestPacket) p).getRequestId(), ((RequestBuildHistoryPacket) p).getServerId()); - break; - case REQUEST_SERVER_LIST: sendServerListResponse(address, ((RequestPacket) p).getRequestId()); break; default: break; } } private void processBuild(PostBuildPacket p) { - SharedServerData server = getBackendData().getServer(p.getServerId()); + ServerServerData server = getBackendData().getServer(p.getServerId()); if (server != null) new PrepareStarshipIntent(server).broadcast(); } @@ -139,86 +121,51 @@ public class BuildService extends Service { synchronized (inprogress) { ServerBuildData installation = inprogress.get(p.getServerId()); if (installation != null) - installation.cancel(); + installation.setState(InstallationState.CANCELLED); } } - private void processPostCreateServer(PostCreateServerPacket p) { - SharedServerData server = p.getServer(); - getBackendData().insertServer(p.getServer()); - Log.i(this, "Creating server: id=%s, directory=%s, jvm_arguments=%s", server.getName(), server.getDirectory(), server.getJvmArguments()); - } - - private void processPostDeleteServer(PostDeleteServerPacket p) { - getBackendData().removeServer(p.getServerId()); - Log.i(this, "Deleting server: id=%s", p.getServerId()); - } - - private void sendBuildHistoryResponse(InetSocketAddress address, long requestId, String serverId) { - SharedServerData server = getBackendData().getServer(serverId); - List builds; - if (server == null) - builds = new ArrayList<>(); - else - builds = server.getBuilds(); - new OutboundPacketIntent(address, ResponseBuildHistoryPacket.create(requestId, builds)).broadcast(); - } - - private void sendServerListResponse(InetSocketAddress address, long requestId) { - List servers = getBackendData().getServerList(); - List serverStrings = new ArrayList<>(servers.size()); - for (SharedServerData server : servers) - serverStrings.add(server.getName()); - new OutboundPacketIntent(address, ResponseServerListPacket.create(requestId, serverStrings)).broadcast(); - } - - private void onCompleted(String serverId) { - ServerBuildData installation; + private void onCompleted(String serverId, ServerBuildData build) { synchronized (inprogress) { - installation = inprogress.remove(serverId); + Assert.notNull(inprogress.remove(serverId)); } - if (installation == null) { - Log.e(this, "Build Success - error while retrieving inprogress information. Server: %s", serverId); - return; - } - processBuildCompleted(buildId.incrementAndGet(), serverId, installation); + processBuildCompleted(buildId.incrementAndGet(), serverId, build); } - private void onCancelled(String serverId) { + private void onCancelled(String serverId, ServerBuildData build) { ServerBuildData installation; synchronized (inprogress) { installation = inprogress.remove(serverId); } if (installation != null) { Log.i(this, "Build cancelled: %s", serverId); - SharedServerData server = getBackendData().getServer(serverId); + ServerServerData server = getBackendData().getServer(serverId); Assert.notNull(server); - getBackendData().insertBuild(new SharedBuildData(buildId.incrementAndGet(), server, installation)); + getBackendData().insertBuild(build); } else { Assert.fail(); } } - private void processBuildCompleted(long id, String serverId, ServerBuildData installation) { - try (RelationalDatabase db = RelationalServerFactory.getServerDatabase("lightspeed.db")) { - SharedServerData server = getBackendData().getServer(serverId); - if (server == null) { - Log.e(this, "Build Success - error while retrieving server information. Server: %s", serverId); - return; - } - if (installation.getJar() != null) { - File jar = new File("data/releases/"+serverId+".jar"); - Files.copy(installation.getJar().toPath(), jar.toPath(), StandardCopyOption.REPLACE_EXISTING); - } - SharedBuildData build = new SharedBuildData(buildId.incrementAndGet(), server, installation); - getBackendData().insertBuild(build); - processPostBuild(build); - } catch (IOException e) { - e.printStackTrace(); + private void processBuildCompleted(long id, String serverId, ServerBuildData build) { + ServerServerData server = getBackendData().getServer(serverId); + if (server == null) { + Log.e(this, "Build Success - error while retrieving server information. Server: %s", serverId); + return; } + if (build.getJar() != null) { + File jar = new File("data/releases/"+serverId+".jar"); + try { + Files.copy(build.getJar().toPath(), jar.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + e.printStackTrace(); + } + } + getBackendData().insertBuild(build); + processPostBuild(build); } - private void processPostBuild(SharedBuildData build) { + private void processPostBuild(ServerBuildData build) { if (build.isBuildSuccess() && build.isTestSuccess()) { Log.i(this, "Build Success! Server: %s", build.getServer().getName()); new LaunchStarshipIntent(build).broadcast(); diff --git a/src/com/projectswg/lightspeed/build/JavaBuildMethod.java b/src/com/projectswg/lightspeed/build/JavaBuildMethod.java index c80eebc..b9c1f8c 100644 --- a/src/com/projectswg/lightspeed/build/JavaBuildMethod.java +++ b/src/com/projectswg/lightspeed/build/JavaBuildMethod.java @@ -36,8 +36,9 @@ import com.projectswg.lightspeed.build.java_builder.CustomJavaBuild; import com.projectswg.lightspeed.build.java_builder.CustomJavaException; import com.projectswg.lightspeed.build.java_builder.CustomJavaInstall; import com.projectswg.lightspeed.build.java_builder.CustomJavaTest; +import com.projectswg.lightspeed.server.ServerServerData; -public class JavaBuildMethod implements BuildMethod { +public class JavaBuildMethod { private final CustomJavaBuild build; private final CustomJavaTest test; @@ -49,10 +50,10 @@ public class JavaBuildMethod implements BuildMethod { install = new CustomJavaInstall(new File(getJdk() + "/bin/jar")); } - @Override - public ServerBuildData createJar(String repo, InstallationCallback callback) { + public ServerBuildData createJar(long buildId, ServerServerData server, InstallationCallback callback) { + String repo = server.getDirectory(); String processedRepo = processRepositoryArgument(repo); - ServerBuildData buildData = new ServerBuildData(new File(repo)); + ServerBuildData buildData = new ServerBuildData(buildId, server); new Thread(() -> { createJar(processedRepo, buildData, callback); }).start(); @@ -86,7 +87,7 @@ public class JavaBuildMethod implements BuildMethod { updateState(buildData, callback, InstallationState.INSTALLING); install.createRawJar(buildData, "main.ProjectSWG"); - buildData.setCompletedTime(TimeUtilities.getTime()); + buildData.setTime(TimeUtilities.getTime()); updateState(buildData, callback, InstallationState.SUCCESS); } catch (CustomJavaException e) { System.err.println(e.getMessage()); @@ -109,11 +110,11 @@ public class JavaBuildMethod implements BuildMethod { InstallationState oldState = buildData.getState(); buildData.setState(newState); if (callback != null) - callback.onStateChanged(oldState, newState); + callback.onStateChanged(buildData, oldState, newState); if (callback != null && newState == InstallationState.CANCELLED) - callback.onCancelled(); + callback.onCancelled(buildData); else if (callback != null && (newState == InstallationState.SUCCESS || newState == InstallationState.FAILED)) - callback.onCompleted(); + callback.onCompleted(buildData); } } diff --git a/src/com/projectswg/lightspeed/build/ServerBuildData.java b/src/com/projectswg/lightspeed/build/ServerBuildData.java index 458cf42..d0e7b2c 100644 --- a/src/com/projectswg/lightspeed/build/ServerBuildData.java +++ b/src/com/projectswg/lightspeed/build/ServerBuildData.java @@ -28,118 +28,121 @@ package com.projectswg.lightspeed.build; import java.io.File; + import com.projectswg.common.data.TestDetails; +import com.projectswg.lightspeed.server.ServerServerData; +import com.projectswg.lightspeed_frontend.data.SharedBuildData; public class ServerBuildData { - private final File directory; + private final SharedBuildData shared; + private final ServerServerData server; private InstallationState state; - private String build; - private String test; private File jar; - private TestDetails testDetails; - private long completedTime; - private double compileTime; - private boolean buildSuccess; - private boolean testSuccess; - public ServerBuildData(File directory) { - this.directory = directory; + public ServerBuildData(long id, ServerServerData server) { + this.shared = new SharedBuildData(id, server.getShared()); + this.server = server; this.state = InstallationState.IDLE; - this.build = ""; - this.test = ""; this.jar = null; - this.testDetails = null; - this.completedTime = 0; - this.compileTime = 0; - this.buildSuccess = false; - this.testSuccess = false; } - public File getDirectory() { - return directory; + public SharedBuildData getShared() { + return shared; } - public InstallationState getState() { - return state; + public ServerServerData getServer() { + return server; + } + + public long getId() { + return shared.getId(); + } + + public long getTime() { + return shared.getTime(); } public String getBuildString() { - return build; + return shared.getBuildString(); } public String getTestString() { - return test; + return shared.getTestString(); + } + + public double getCompileTime() { + return shared.getCompileTime(); + } + + public boolean isBuildSuccess() { + return shared.isBuildSuccess(); + } + + public boolean isTestSuccess() { + return shared.isTestSuccess(); + } + + public boolean isCancelled() { + return shared.isCancelled(); + } + + public TestDetails getTestDetails() { + return shared.getTestDetails(); } public File getJar() { return jar; } - public TestDetails getTestDetails() { - return testDetails; + public void setTime(long time) { + shared.setTime(time); } - public long getCompletedTime() { - return completedTime; + public void setBuildString(String buildString) { + shared.setBuildString(buildString); } - public double getCompileTime() { - return compileTime; + public void setTestString(String testString) { + shared.setTestString(testString); } - public boolean isBuildSuccess() { - return buildSuccess; + public void setCompileTime(double compileTime) { + shared.setCompileTime(compileTime); } - public boolean isTestSuccess() { - return testSuccess; + public void setBuildSuccess(boolean buildSuccess) { + shared.setBuildSuccess(buildSuccess); + } + + public void setTestSuccess(boolean testSuccess) { + shared.setTestSuccess(testSuccess); + } + + public void setCancelled(boolean cancelled) { + shared.setCancelled(cancelled); + } + + public void setTestDetails(TestDetails testDetails) { + shared.setTestDetails(testDetails); + } + + public InstallationState getState() { + return state; } public void setState(InstallationState state) { this.state = state; } - public void setBuildString(String build) { - this.build = build; - } - - public void setTestString(String test) { - this.test = test; - } - public void setJar(File jar) { this.jar = jar; } - public void setTestDetails(TestDetails testDetails) { - this.testDetails = testDetails; - } - - public void setCompletedTime(long completedTime) { - this.completedTime = completedTime; - } - - public void setCompileTime(double compileTime) { - this.compileTime = compileTime; - } - - public void setBuildSuccess(boolean buildSuccess) { - this.buildSuccess = buildSuccess; - } - - public void setTestSuccess(boolean testSuccess) { - this.testSuccess = testSuccess; - } - - public void cancel() { - this.state = InstallationState.CANCELLED; - } - public interface InstallationCallback { - void onStateChanged(InstallationState oldState, InstallationState newState); - void onCompleted(); - void onCancelled(); + void onStateChanged(ServerBuildData build, InstallationState oldState, InstallationState newState); + void onCompleted(ServerBuildData build); + void onCancelled(ServerBuildData build); } } diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java index 4066f60..e64eaca 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java @@ -46,7 +46,7 @@ public class CustomJavaBuild { } public void compile(ServerBuildData buildData, String file) throws CustomJavaException { - String repo = buildData.getDirectory().getAbsolutePath(); + String repo = buildData.getServer().getDirectory(); file = file.replace('.', File.separatorChar); String [] command = { javac.getAbsolutePath(), diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java index 7eec348..c2a0018 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java @@ -57,7 +57,7 @@ public class CustomJavaInstall { } public void createRawJar(ServerBuildData buildData, String file) throws CustomJavaException { - String repo = buildData.getDirectory().getAbsolutePath(); + String repo = buildData.getServer().getDirectory(); File manifestFile = createManifest(repo, file); String manifest = manifestFile.getAbsolutePath(); CustomJavaCommon.execute(getCommandLineArgs(repo, manifest), new File(repo)); diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java index b598c66..f181bf7 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java @@ -50,7 +50,7 @@ public class CustomJavaTest { public TestDetails test(ServerBuildData buildData) { StringBuilder outBuilder = new StringBuilder(); - int ret = executeTest(buildData.getDirectory().getAbsolutePath(), outBuilder); + int ret = executeTest(buildData.getServer().getDirectory(), outBuilder); String out = outBuilder.toString(); TestDetails details = parseOutput(ret, out); buildData.setTestDetails(details); diff --git a/src/com/projectswg/lightspeed/deployment/ServerDeploymentData.java b/src/com/projectswg/lightspeed/deployment/ServerDeploymentData.java index 2e5670e..ad7d0a8 100644 --- a/src/com/projectswg/lightspeed/deployment/ServerDeploymentData.java +++ b/src/com/projectswg/lightspeed/deployment/ServerDeploymentData.java @@ -28,36 +28,38 @@ package com.projectswg.lightspeed.deployment; import com.projectswg.lightspeed.StarshipProcess; -import com.projectswg.lightspeed_frontend.data.SharedBuildData; +import com.projectswg.lightspeed.build.ServerBuildData; +import com.projectswg.lightspeed.server.ServerServerData; import com.projectswg.lightspeed_frontend.data.SharedDeploymentData; -import com.projectswg.lightspeed_frontend.data.SharedServerData; public class ServerDeploymentData { - private final SharedDeploymentData data; + private final SharedDeploymentData shared; + private final ServerBuildData build; private final PSWGData pswgData; private StarshipProcess process; - public ServerDeploymentData(SharedDeploymentData data) { - this.data = data; + public ServerDeploymentData(long id, ServerBuildData build) { + this.shared = new SharedDeploymentData(id, build.getShared()); + this.build = build; this.process = null; this.pswgData = new PSWGData(); } - public SharedDeploymentData getDeploymentData() { - return data; + public SharedDeploymentData getShared() { + return shared; + } + + public ServerBuildData getBuild() { + return build; + } + + public ServerServerData getServer() { + return build == null ? null : build.getServer(); } public long getId() { - return data.getId(); - } - - public SharedServerData getServer() { - return data.getBuild().getServer(); - } - - public SharedBuildData getBuild() { - return data.getBuild(); + return shared.getId(); } public StarshipProcess getProcess() { @@ -65,15 +67,15 @@ public class ServerDeploymentData { } public long getStartTime() { - return data.getStartTime(); + return shared.getStartTime(); } public long getEndTime() { - return data.getEndTime(); + return shared.getEndTime(); } public boolean isAlive() { - return data.getEndTime() == 0; + return shared.getEndTime() == 0; } public PSWGData getPswgData() { @@ -85,11 +87,11 @@ public class ServerDeploymentData { } public void setStartTime(long startTime) { - data.setStartTime(startTime); + shared.setStartTime(startTime); } public void setEndTime(long endTime) { - data.setEndTime(endTime); + shared.setEndTime(endTime); } } diff --git a/src/com/projectswg/lightspeed/server/ServerServerData.java b/src/com/projectswg/lightspeed/server/ServerServerData.java new file mode 100644 index 0000000..d7d0b69 --- /dev/null +++ b/src/com/projectswg/lightspeed/server/ServerServerData.java @@ -0,0 +1,94 @@ +/*********************************************************************************** +* Copyright (c) 2015 /// Project SWG /// www.projectswg.com * +* * +* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * +* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * +* Our goal is to create an emulator which will provide a server for players to * +* continue playing a game similar to the one they used to play. We are basing * +* it on the final publish of the game prior to end-game events. * +* * +* This file is part of Holocore. * +* * +* -------------------------------------------------------------------------------- * +* * +* Holocore is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Affero General Public License as * +* published by the Free Software Foundation, either version 3 of the * +* License, or (at your option) any later version. * +* * +* Holocore is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with Holocore. If not, see . * +* * +***********************************************************************************/ +package com.projectswg.lightspeed.server; + +import java.util.TreeMap; + +import com.projectswg.lightspeed.build.ServerBuildData; +import com.projectswg.lightspeed.deployment.ServerDeploymentData; +import com.projectswg.lightspeed_frontend.data.SharedServerData; + +public class ServerServerData { + + private final SharedServerData shared; + private final TreeMap builds; + private final TreeMap deployments; + + public ServerServerData(String name) { + this.shared = new SharedServerData(name); + this.builds = new TreeMap<>(); + this.deployments = new TreeMap<>(); + } + + public SharedServerData getShared() { + return shared; + } + + public String getName() { + return shared.getName(); + } + + public String getDirectory() { + return shared.getDirectory(); + } + + public String getJvmArguments() { + return shared.getJvmArguments(); + } + + public void setDirectory(String directory) { + shared.setDirectory(directory); + } + + public void setJvmArguments(String jvmArgs) { + shared.setJvmArguments(jvmArgs); + } + + public void addBuild(ServerBuildData build) { + shared.addBuild(build.getShared()); + builds.put(build.getId(), build); + } + + public void addDeployment(ServerDeploymentData deployment) { + shared.addDeployment(deployment.getShared()); + deployments.put(deployment.getId(), deployment); + } + + public ServerBuildData getLastBuild() { + if (builds.isEmpty()) + return null; + return builds.lastEntry().getValue(); + } + + public ServerDeploymentData getLastDeployment() { + if (deployments.isEmpty()) + return null; + return deployments.lastEntry().getValue(); + } + +} diff --git a/src/com/projectswg/lightspeed/server/ServerService.java b/src/com/projectswg/lightspeed/server/ServerService.java new file mode 100644 index 0000000..192b526 --- /dev/null +++ b/src/com/projectswg/lightspeed/server/ServerService.java @@ -0,0 +1,63 @@ +/*********************************************************************************** +* Copyright (c) 2015 /// Project SWG /// www.projectswg.com * +* * +* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * +* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * +* Our goal is to create an emulator which will provide a server for players to * +* continue playing a game similar to the one they used to play. We are basing * +* it on the final publish of the game prior to end-game events. * +* * +* This file is part of Holocore. * +* * +* -------------------------------------------------------------------------------- * +* * +* Holocore is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Affero General Public License as * +* published by the Free Software Foundation, either version 3 of the * +* License, or (at your option) any later version. * +* * +* Holocore is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with Holocore. If not, see . * +* * +***********************************************************************************/ +package com.projectswg.lightspeed.server; + +import java.util.ArrayList; +import java.util.List; + +import com.projectswg.common.control.Intent; +import com.projectswg.common.control.Service; +import com.projectswg.common.intents.InboundPacketIntent; +import com.projectswg.common.intents.OutboundPacketIntent; +import com.projectswg.common.network.packets.Packet; +import com.projectswg.common.network.packets.request.RequestServerListPacket; +import com.projectswg.common.network.packets.response.ResponseServerListPacket; + +public class ServerService extends Service { + + public ServerService() { + registerForIntent(InboundPacketIntent.TYPE); + } + + public void onIntentReceived(Intent i) { + if (i instanceof InboundPacketIntent) + onInboundPacketIntent((InboundPacketIntent) i); + } + + private void onInboundPacketIntent(InboundPacketIntent i) { + Packet p = i.getPacket(); + if (p instanceof RequestServerListPacket) { + List servers = getBackendData().getServerList(); + List serverStrings = new ArrayList<>(servers.size()); + for (ServerServerData server : servers) + serverStrings.add(server.getName()); + new OutboundPacketIntent(i.getAddress(), ResponseServerListPacket.create(((RequestServerListPacket) p).getRequestId(), serverStrings)).broadcast(); + } + } + +} diff --git a/src/com/projectswg/lightspeed_frontend/data/SharedBuildData.java b/src/com/projectswg/lightspeed_frontend/data/SharedBuildData.java index 9156714..552b6e0 100644 --- a/src/com/projectswg/lightspeed_frontend/data/SharedBuildData.java +++ b/src/com/projectswg/lightspeed_frontend/data/SharedBuildData.java @@ -71,7 +71,7 @@ public class SharedBuildData { this(id, server); this.buildString = installation.getBuildString(); this.testString = installation.getTestString(); - this.time = installation.getCompletedTime(); + this.time = installation.getTime(); this.compileTime = installation.getCompileTime(); this.buildSuccess = installation.isBuildSuccess(); this.testSuccess = installation.isTestSuccess(); diff --git a/src/com/projectswg/lightspeed_frontend/data/SharedServerData.java b/src/com/projectswg/lightspeed_frontend/data/SharedServerData.java index 3309652..bf790eb 100644 --- a/src/com/projectswg/lightspeed_frontend/data/SharedServerData.java +++ b/src/com/projectswg/lightspeed_frontend/data/SharedServerData.java @@ -118,6 +118,7 @@ public class SharedServerData { public void addBuild(SharedBuildData build) { synchronized (builds) { + build.setServer(this); if (builds.put(build.getId(), build) == build) return; new BuildDataUpdateIntent(build.getServer().getName(), build.getId(), BuildUpdateType.BUILD_ADDED).broadcast(); diff --git a/src/com/projectswg/lightspeed_frontend/gui/LightspeedPrimaryView.java b/src/com/projectswg/lightspeed_frontend/gui/LightspeedPrimaryView.java index fc452a7..16e050f 100644 --- a/src/com/projectswg/lightspeed_frontend/gui/LightspeedPrimaryView.java +++ b/src/com/projectswg/lightspeed_frontend/gui/LightspeedPrimaryView.java @@ -29,6 +29,8 @@ package com.projectswg.lightspeed_frontend.gui; import java.net.InetSocketAddress; import java.net.URL; +import java.util.ArrayList; +import java.util.List; import java.util.ResourceBundle; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -36,6 +38,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import com.projectswg.common.control.Assert; import com.projectswg.common.control.IntentManager; +import com.projectswg.common.network.packets.post.PostBuildPacket; import com.projectswg.common.utilities.ThreadUtilities; import com.projectswg.lightspeed_frontend.Frontend; import com.projectswg.lightspeed_frontend.data.SharedBuildData; @@ -120,31 +123,39 @@ public class LightspeedPrimaryView extends VBox implements Initializable { setServerStatusText(frontend.isConnected()); setBuildStatusText(server == null ? null : server.getLastBuild()); setDeploymentStatusText(server == null ? null : server.getLastDeployment()); - if (frontend.isConnected()) { - MenuItem disconnect = new MenuItem("Disconnect"); - disconnect.setOnAction((event) -> frontend.disconnect()); - commonServerStatus.getItems().setAll(disconnect); - } else { - if (address != null) { - MenuItem connect = new MenuItem("Connect"); - connect.setOnAction((event) -> frontend.connect(address)); - commonServerStatus.getItems().setAll(connect); - } else { - commonServerStatus.getItems().clear(); - } - } }); } private void setServerStatusText(boolean connected) { commonServerStatus.setText(String.format("Server: %s", connected ? "Connected" : "Disconnected")); + if (connected) { + MenuItem disconnect = new MenuItem("Disconnect"); + disconnect.setOnAction((event) -> frontend.disconnect()); + commonServerStatus.getItems().setAll(disconnect); + } else { + if (address != null) { + MenuItem connect = new MenuItem("Connect"); + connect.setOnAction((event) -> frontend.connect(address)); + commonServerStatus.getItems().setAll(connect); + } else { + commonServerStatus.getItems().clear(); + } + } } private void setBuildStatusText(SharedBuildData build) { - String str = "N/A"; - if (build != null) - str = (build.isBuildSuccess() && build.isTestSuccess()) ? "Success" : "Failure"; - commonBuildStatus.setText(String.format("Build: %s", str)); + List items = new ArrayList<>(); + if (build != null) { + commonBuildStatus.setText(String.format("Build: %s", (build.isBuildSuccess() && build.isTestSuccess()) ? "Success" : "Failure")); + } else { + commonBuildStatus.setText("Build: N/A"); + } + if (frontend.isConnected() && server != null) { + MenuItem startBuild = new MenuItem("Start Build"); + startBuild.setOnAction((event) -> frontend.send(PostBuildPacket.create(server.getName()))); + items.add(startBuild); + } + commonBuildStatus.getItems().setAll(items); } private void setDeploymentStatusText(SharedDeploymentData deployment) { diff --git a/src/com/projectswg/lightspeed_frontend/gui/primary_tabs/BuildTab.java b/src/com/projectswg/lightspeed_frontend/gui/primary_tabs/BuildTab.java index e2baa1c..8111c81 100644 --- a/src/com/projectswg/lightspeed_frontend/gui/primary_tabs/BuildTab.java +++ b/src/com/projectswg/lightspeed_frontend/gui/primary_tabs/BuildTab.java @@ -40,6 +40,7 @@ import com.projectswg.lightspeed_frontend.data.SharedBuildData; import com.projectswg.lightspeed_frontend.data.SharedServerData; import com.projectswg.lightspeed_frontend.javafx.FrontendFXMLLoader; +import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -130,13 +131,15 @@ public class BuildTab extends GridPane implements Initializable { } private void updateUi() { - setServerName(); - setBuildId(); - setStatus(); - setTime(); - setCompileTime(); - setMode(); - setTests(); + Platform.runLater(() -> { + setServerName(); + setBuildId(); + setStatus(); + setTime(); + setCompileTime(); + setMode(); + setTests(); + }); } private void updateBuildList() { @@ -146,11 +149,13 @@ public class BuildTab extends GridPane implements Initializable { for (int i = 0; i < buildList.size(); i++) { builds[i] = Long.toString(buildList.get(i).getId()); } - buildComboBox.setItems(FXCollections.observableArrayList(builds)); - buildComboBox.getItems().add(0, ""); - if (selectedBuildData != null) { - selectBuild(selectedBuildData); - } + Platform.runLater(() -> { + buildComboBox.setItems(FXCollections.observableArrayList(builds)); + buildComboBox.getItems().add(0, ""); + if (selectedBuildData != null) { + selectBuild(selectedBuildData); + } + }); } private void setServerName() {