Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Added podName column to instance model. #5369

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface InstanceColumn {
id: 'id' | 'ipAddress' | 'currentUsers' | 'locationId' | 'channelId' | 'action'
id: 'id' | 'ipAddress' | 'currentUsers' | 'locationId' | 'channelId' | 'podName' | 'action'
label: string
minWidth?: number
align?: 'right'
Expand All @@ -21,6 +21,12 @@ export const instanceColumns: InstanceColumn[] = [
minWidth: 65,
align: 'right'
},
{
id: 'podName',
label: 'Pod Name',
minWidth: 200,
align: 'right'
},
{
id: 'action',
label: 'Action',
Expand All @@ -35,5 +41,6 @@ export interface InstanceData {
currentUsers: Number
locationId: any
channelId: string
podName: string
action: any
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ const InstanceTable = (props: Props) => {
ipAddress: string,
currentUsers: Number,
locationId: any,
channelId: string
channelId: string,
podName: string
): InstanceData => {
return {
id,
ipAddress,
currentUsers,
locationId: locationId?.name || '',
channelId,
podName,
action: (
<a
href="#h"
Expand All @@ -110,7 +112,7 @@ const InstanceTable = (props: Props) => {
}

const rows = adminInstances.instances.value.map((el: any) =>
createData(el.id, el.ipAddress, el.currentUsers, el.location, el.channelId || '')
createData(el.id, el.ipAddress, el.currentUsers, el.location, el.channelId || '', el.podName)
)

return (
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/dbmodels/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface InstanceInterface {
channelId: string
currentUsers: number
ended: boolean
podName: string
assigned: boolean
assignedAt: Date
}
1 change: 1 addition & 0 deletions packages/common/src/interfaces/AdminBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface Instance {
ipAddress?: string
channelId?: string
currentUsers: number
podName: string
ended: boolean
createdAt: string
updatedAt: string
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/interfaces/AdminParty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface Instance {
channelId?: string
currentUsers: number
ended: boolean
podName: string
createdAt: string
updatedAt: string
locationId: string
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/interfaces/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Instance {
ipAddress: string
locationId: string
channelId: string
podName?: string
ended?: boolean
assigned?: boolean
assignedAt?: Date
Expand All @@ -14,6 +15,7 @@ export const InstanceSeed: Instance = {
id: '',
ipAddress: '',
currentUsers: 0,
podName: '',
locationId: '',
channelId: ''
}
Expand Down
1 change: 1 addition & 0 deletions packages/gameserver/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const createApp = (): Application => {
if (config.kubernetes.enabled || process.env.APP_ENV === 'development' || config.gameserver.mode === 'local') {
agonesSDK.connect()
agonesSDK.ready().catch((err) => {
console.log(err)
throw new Error(
'\x1b[33mError: Agones is not running!. If you are in local development, please run xrengine/scripts/sh start-agones.sh and restart server\x1b[0m'
)
Expand Down
17 changes: 10 additions & 7 deletions packages/gameserver/src/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const assignExistingInstance = async (app: Application, existingInstance, channe
currentUsers: existingInstance.currentUsers + 1,
channelId: channelId,
locationId: locationId,
podName: config.kubernetes.enabled ? app.gameServer?.objectMeta?.name : 'local',
assigned: false,
assignedAt: null!
})
Expand Down Expand Up @@ -210,7 +211,8 @@ const handleInstance = async (
currentUsers: 1,
locationId: locationId,
channelId: channelId,
ipAddress: ipAddress
ipAddress: ipAddress,
podName: config.kubernetes.enabled ? app.gameServer?.objectMeta?.name : 'local'
} as InstanceMetadata
await createNewInstance(app, newInstance)
} else {
Expand Down Expand Up @@ -392,17 +394,18 @@ const loadGameserver = async (

const isReady = status.state === 'Ready'
const isNeedingNewServer =
!engineStarted &&
!config.kubernetes.enabled &&
(status.state === 'Shutdown' ||
app.instance == null ||
app.instance.locationId !== locationId ||
app.instance.channelId !== channelId)

if (isReady || isNeedingNewServer) {
engineStarted = true
await handleInstance(app, status, locationId, channelId, userId)
if (sceneId != null) await loadEngine(app, sceneId)
if (!engineStarted && sceneId != null) {
engineStarted = true
await loadEngine(app, sceneId)
}
} else {
try {
const instance = await app.service('instance').get(app.instance.id)
Expand All @@ -411,6 +414,7 @@ const loadGameserver = async (
await app.service('instance').patch(app.instance.id, {
currentUsers: (instance.currentUsers as number) + 1,
assigned: false,
podName: config.kubernetes.enabled ? app.gameServer?.objectMeta?.name : 'local',
assignedAt: null!
})
return true
Expand Down Expand Up @@ -439,6 +443,7 @@ const shutdownGameserver = async (app: Application, instanceId: string) => {
allocated: false
})
}
app.instance.ended = true
if (config.kubernetes.enabled) {
delete app.instance
const gsName = app.gameServer.objectMeta.name
Expand Down Expand Up @@ -508,9 +513,7 @@ const handleUserDisconnect = async (app: Application, connection, user, instance

// count again here, as it may have changed
const activeUsersCount = getActiveUsersCount(user)
if (activeUsersCount < 1) {
await shutdownGameserver(app, instanceId)
}
if (activeUsersCount < 1) await shutdownGameserver(app, instanceId)
}

const onConnection = (app: Application) => async (connection: SocketIOConnectionType) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export default (app: Application) => {
channelId: {
type: DataTypes.STRING
},
podName: {
type: DataTypes.STRING
},
currentUsers: {
type: DataTypes.INTEGER,
defaultValue: 0
Expand Down