-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add samples for GameServerConfigs (#98)
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
- Loading branch information
1 parent
d32da4d
commit 71ce195
Showing
8 changed files
with
457 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Copyright 2020, Google LLC. | ||
// 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. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Create a Game Servers Config. | ||
* @param {string} projectId string project identifier | ||
* @param {string} deploymentId unique identifier for the parent Game Server Deployment | ||
* @param {string} configId unique identifier for the new Game Server Config | ||
* @param {string} fleetName fleet name to be stored in Agones | ||
*/ | ||
async function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
deploymentId = 'DEPLOYMENT_ID', | ||
configId = 'CONFIG_ID', | ||
fleetName = 'FLEET_NAME' | ||
) { | ||
// [START cloud_game_servers_config_create] | ||
const { | ||
GameServerConfigsServiceClient, | ||
} = require('@google-cloud/game-servers'); | ||
|
||
const client = new GameServerConfigsServiceClient(); | ||
|
||
async function createGameServerConfig() { | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const deploymentId = 'A unique ID for the Game Server Deployment'; | ||
// const configId = 'A unique ID for the Game Server Config'; | ||
// const fleetName = 'The fleet name to be stored in Agones'; | ||
// fleet is the spec portion of an agones Fleet. It must be in JSON format. | ||
// See https://agones.dev/site/docs/reference/fleet/ for more on fleets. | ||
const fleet = ` | ||
{ | ||
"replicas": 10, | ||
"scheduling": "Packed", | ||
"strategy": { | ||
"type": "RollingUpdate", | ||
"rollingUpdate": { | ||
"maxSurge": "25%", | ||
"maxUnavailable": "25%" | ||
} | ||
}, | ||
"template": { | ||
"metadata": { | ||
"labels": { | ||
"gameName": "udp-server" | ||
} | ||
}, | ||
"spec": { | ||
"ports": [ | ||
{ | ||
"name": "default", | ||
"portPolicy": "Dynamic", | ||
"containerPort": 2156, | ||
"protocol": "TCP" | ||
} | ||
], | ||
"health": { | ||
"initialDelaySeconds": 30, | ||
"periodSeconds": 60 | ||
}, | ||
"sdkServer": { | ||
"logLevel": "Info", | ||
"grpcPort": 9357, | ||
"httpPort": 9358 | ||
}, | ||
"template": { | ||
"spec": { | ||
"containers": [ | ||
{ | ||
"name": "dedicated", | ||
"image": "gcr.io/agones-images/udp-server:0.17", | ||
"imagePullPolicy": "Always", | ||
"resources": { | ||
"requests": { | ||
"memory": "200Mi", | ||
"cpu": "500m" | ||
}, | ||
"limits": { | ||
"memory": "200Mi", | ||
"cpu": "500m" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
const request = { | ||
parent: client.gameServerDeploymentPath( | ||
projectId, | ||
'global', | ||
deploymentId | ||
), | ||
configId: configId, | ||
gameServerConfig: { | ||
fleetConfigs: [ | ||
{ | ||
name: fleetName, | ||
fleetSpec: fleet, | ||
}, | ||
], | ||
description: 'nodejs test config', | ||
}, | ||
}; | ||
|
||
const [operation] = await client.createGameServerConfig(request); | ||
const [result] = await operation.promise(); | ||
|
||
console.log('Game Server Config created:'); | ||
console.log(`\t Config name: ${result.name}`); | ||
console.log(`\t Config description: ${result.description}`); | ||
} | ||
|
||
createGameServerConfig(); | ||
|
||
// [END cloud_game_servers_config_create] | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020, Google LLC. | ||
// 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. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Delete a Game Servers Config. | ||
* @param {string} projectId string project identifier | ||
* @param {string} deploymentId unique identifier for the new Game Server Deployment | ||
* @param {string} configId unique identifier for the new Game Server Config | ||
*/ | ||
async function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
deploymentId = 'DEPLOYMENT_ID', | ||
configId = 'CONFIG_ID' | ||
) { | ||
// [START cloud_game_servers_config_delete] | ||
const { | ||
GameServerConfigsServiceClient, | ||
} = require('@google-cloud/game-servers'); | ||
|
||
const client = new GameServerConfigsServiceClient(); | ||
|
||
async function deleteGameServerConfig() { | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const deploymentId = 'A unique ID for the Game Server Deployment'; | ||
// const configId = 'A unique ID for the Game Server Config'; | ||
const request = { | ||
// The full resource name | ||
name: client.gameServerConfigPath( | ||
projectId, | ||
'global', | ||
deploymentId, | ||
configId | ||
), | ||
}; | ||
|
||
const [operation] = await client.deleteGameServerConfig(request); | ||
await operation.promise(); | ||
console.log(`Config with name ${request.name} deleted.`); | ||
} | ||
|
||
deleteGameServerConfig(); | ||
|
||
// [END cloud_game_servers_config_delete] | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2020, Google LLC. | ||
// 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. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Get a Game Servers Config. | ||
* @param {string} projectId string project identifier | ||
* @param {string} deploymentId unique identifier for the new Game Server Deployment | ||
* @param {string} configId unique identifier for the new Game Server Config | ||
*/ | ||
async function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
deploymentId = 'DEPLOYMENT_ID', | ||
configId = 'CONFIG_ID' | ||
) { | ||
// [START cloud_game_servers_config_get] | ||
const { | ||
GameServerConfigsServiceClient, | ||
} = require('@google-cloud/game-servers'); | ||
|
||
const client = new GameServerConfigsServiceClient(); | ||
|
||
async function getGameServerConfig() { | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const deploymentId = 'A unique ID for the Game Server Deployment'; | ||
// const configId = 'A unique ID for the Game Server Config'; | ||
const request = { | ||
// The full resource name | ||
name: client.gameServerConfigPath( | ||
projectId, | ||
'global', | ||
deploymentId, | ||
configId | ||
), | ||
}; | ||
|
||
const [config] = await client.getGameServerConfig(request); | ||
console.log(`Config name: ${config.name}`); | ||
console.log(`Config description: ${config.description}`); | ||
|
||
const createTime = config.createTime; | ||
const createDate = new Date(createTime.seconds * 1000); | ||
console.log(`Config created on: ${createDate.toLocaleDateString()}\n`); | ||
} | ||
|
||
getGameServerConfig(); | ||
|
||
// [END cloud_game_servers_config_get] | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2020, Google LLC. | ||
// 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. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* List all the Game Servers Configs. | ||
* @param {string} projectId string project identifier | ||
* @param {string} deploymentId unique identifier for the new Game Server Deployment | ||
*/ | ||
async function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
deploymentId = 'DEPLOYMENT_ID' | ||
) { | ||
// [START cloud_game_servers_config_list] | ||
const { | ||
GameServerConfigsServiceClient, | ||
} = require('@google-cloud/game-servers'); | ||
|
||
const client = new GameServerConfigsServiceClient(); | ||
|
||
async function listGameServerConfigs() { | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const deploymentId = 'A unique ID for the Game Server Deployment'; | ||
const request = { | ||
parent: client.gameServerDeploymentPath( | ||
projectId, | ||
'global', | ||
deploymentId | ||
), | ||
}; | ||
|
||
const [results] = await client.listGameServerConfigs(request); | ||
for (const config of results) { | ||
console.log(`Config name: ${config.name}`); | ||
console.log(`Config description: ${config.description}`); | ||
|
||
const createTime = config.createTime; | ||
const createDate = new Date(createTime.seconds * 1000); | ||
console.log(`Config created on: ${createDate.toLocaleDateString()}\n`); | ||
} | ||
} | ||
|
||
listGameServerConfigs(); | ||
|
||
// [END cloud_game_servers_config_list] | ||
} | ||
|
||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); |
Oops, something went wrong.