-
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.
* feat: Add update samples * Address feedback * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4ab00d4
commit c6dc56c
Showing
7 changed files
with
421 additions
and
1 deletion.
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
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,115 @@ | ||
// Copyright 2021 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 | ||
// | ||
// https://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'; | ||
|
||
const {assert} = require('chai'); | ||
const cleanup = require('./clean.js'); | ||
const {describe, it, before, after} = require('mocha'); | ||
const { | ||
RealmsServiceClient, | ||
GameServerClustersServiceClient, | ||
} = require('@google-cloud/game-servers'); | ||
|
||
const cp = require('child_process'); | ||
const uuid = require('uuid'); | ||
|
||
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); | ||
|
||
const LOCATION = 'us-central1'; | ||
const GKE_CLUSTER_NAME = | ||
process.env.SAMPLE_CLUSTER_NAME || | ||
'projects/217093627905/locations/us-central1/clusters/gke-shared-default'; | ||
|
||
describe('Game Servers Update Cluster Test', () => { | ||
const realmsClient = new RealmsServiceClient(); | ||
const gameClustersClient = new GameServerClustersServiceClient(); | ||
let realmId, gameClusterId, projectId; | ||
|
||
before(async () => { | ||
await cleanup(); | ||
|
||
// Create a realm | ||
projectId = await realmsClient.getProjectId(); | ||
realmId = `update-realm-${uuid.v4()}`; | ||
gameClusterId = `test-${uuid.v4()}`; | ||
|
||
const createRealmRequest = { | ||
parent: `projects/${projectId}/locations/${LOCATION}`, | ||
realmId: realmId, | ||
realm: { | ||
timeZone: 'US/Pacific', | ||
description: 'Test Game Server realm', | ||
}, | ||
}; | ||
|
||
const [operation1] = await realmsClient.createRealm(createRealmRequest); | ||
await operation1.promise(); | ||
|
||
// Create a cluster | ||
const createClusterRequest = { | ||
parent: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}`, | ||
gameServerClusterId: gameClusterId, | ||
gameServerCluster: { | ||
description: 'My Game Server Cluster', | ||
connectionInfo: { | ||
gkeClusterReference: { | ||
// Provide full resource name of a Kubernetes Engine cluster | ||
cluster: GKE_CLUSTER_NAME, | ||
}, | ||
namespace: 'default', | ||
}, | ||
}, | ||
}; | ||
|
||
const [operation2] = await gameClustersClient.createGameServerCluster( | ||
createClusterRequest | ||
); | ||
await operation2.promise(); | ||
}); | ||
|
||
it('should update a Game Server cluster in a realm', async () => { | ||
const update_output = execSync( | ||
`node update_cluster.js ${projectId} ${LOCATION} ${realmId} ${gameClusterId}` | ||
); | ||
assert.match(update_output, /Cluster updated:/); | ||
|
||
const get_output = execSync( | ||
`node get_cluster.js ${projectId} ${LOCATION} ${realmId} ${gameClusterId}` | ||
); | ||
assert.match( | ||
get_output, | ||
/Cluster description: My updated Game Server Cluster/ | ||
); | ||
}); | ||
|
||
after(async () => { | ||
// Delete the Game Server cluster | ||
const deleteClusterRequest = { | ||
// Provide full resource name of a Game Server Realm | ||
name: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}/gameServerClusters/${gameClusterId}`, | ||
}; | ||
const [operation1] = await gameClustersClient.deleteGameServerCluster( | ||
deleteClusterRequest | ||
); | ||
await operation1.promise(); | ||
|
||
// Delete the realm | ||
const deleteRealmRequest = { | ||
name: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}`, | ||
}; | ||
const [operation2] = await realmsClient.deleteRealm(deleteRealmRequest); | ||
await operation2.promise(); | ||
}); | ||
}); |
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,70 @@ | ||
// Copyright 2021 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 | ||
// | ||
// https://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'; | ||
|
||
const {assert} = require('chai'); | ||
const cleanup = require('./clean.js'); | ||
const {describe, it, before, after} = require('mocha'); | ||
const {RealmsServiceClient} = require('@google-cloud/game-servers'); | ||
|
||
const cp = require('child_process'); | ||
const uuid = require('uuid'); | ||
|
||
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); | ||
|
||
const LOCATION = 'us-central1'; | ||
|
||
describe('Game Servers Update Realms Test', () => { | ||
const client = new RealmsServiceClient(); | ||
let realmId, projectId; | ||
|
||
before(async () => { | ||
projectId = await client.getProjectId(); | ||
|
||
// Clean up any stray realms | ||
await cleanup(); | ||
|
||
realmId = `test-${uuid.v4()}`; | ||
|
||
await client.createRealm({ | ||
parent: `projects/${projectId}/locations/${LOCATION}`, | ||
realmId: realmId, | ||
realm: { | ||
timeZone: 'US/Pacific', | ||
description: 'Test Game Realm', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should update a realm', async () => { | ||
const update_output = execSync( | ||
`node update_realm.js ${projectId} ${LOCATION} ${realmId}` | ||
); | ||
assert.match(update_output, /Realm updated:/); | ||
|
||
const get_output = execSync( | ||
`node get_realm.js ${projectId} ${LOCATION} ${realmId}` | ||
); | ||
assert.match(get_output, /Realm description: My updated Game Server realm/); | ||
}); | ||
|
||
after(async () => { | ||
const request = { | ||
name: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}`, | ||
}; | ||
const [operation] = await client.deleteRealm(request); | ||
await operation.promise(); | ||
}); | ||
}); |
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,80 @@ | ||
// Copyright 2021, 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'; | ||
|
||
/** | ||
* Update a Game Servers cluster. | ||
* @param {string} projectId string project identifier | ||
* @param {string} location Compute Engine region for the realm | ||
* @param {string} realmId the realm to use | ||
* @param {string} gameClusterId unique identifier for the Game Cluster | ||
*/ | ||
async function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
location = 'LOCATION_ID', | ||
realmId = 'REALM_ID', | ||
gameClusterId = 'GAME_CLUSTER_ID' | ||
) { | ||
// [START cloud_game_servers_cluster_update] | ||
const { | ||
GameServerClustersServiceClient, | ||
} = require('@google-cloud/game-servers'); | ||
|
||
const client = new GameServerClustersServiceClient(); | ||
|
||
async function updateGameServerCluster() { | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const location = 'A Compute Engine region, e.g. "us-central1"'; | ||
// const realmId = 'The ID of the realm of this cluster'; | ||
// const gameClusterId = 'A unique ID for this Game Server Cluster'; | ||
const request = { | ||
// Provide full resource name of a Game Server Cluster | ||
gameServerCluster: { | ||
name: client.gameServerClusterPath( | ||
projectId, | ||
location, | ||
realmId, | ||
gameClusterId | ||
), | ||
labels: { | ||
'label-key-1': 'label-value-1', | ||
}, | ||
description: 'My updated Game Server Cluster', | ||
}, | ||
updateMask: { | ||
paths: ['labels', 'description'], | ||
}, | ||
}; | ||
|
||
const [operation] = await client.updateGameServerCluster(request); | ||
const [result] = await operation.promise(); | ||
|
||
console.log(`Cluster updated: ${result.name}`); | ||
} | ||
|
||
updateGameServerCluster(); | ||
// [END cloud_game_servers_cluster_update] | ||
} | ||
|
||
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,73 @@ | ||
// Copyright 2021, 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'; | ||
|
||
/** | ||
* Update a Game Servers Deployment. | ||
* @param {string} projectId string project identifier | ||
* @param {string} deploymentId unique identifier for the Game Server Deployment | ||
*/ | ||
async function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
deploymentId = 'DEPLOYMENT_ID' | ||
) { | ||
// [START cloud_game_servers_deployment_update] | ||
const { | ||
GameServerDeploymentsServiceClient, | ||
} = require('@google-cloud/game-servers'); | ||
|
||
const client = new GameServerDeploymentsServiceClient(); | ||
|
||
async function updateGameServerDeployment() { | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const deploymentId = 'The unique ID for the Game Server Deployment'; | ||
const request = { | ||
gameServerDeployment: { | ||
name: client.gameServerDeploymentPath( | ||
projectId, | ||
'global', | ||
deploymentId | ||
), | ||
labels: { | ||
'label-key-1': 'label-value-1', | ||
}, | ||
description: 'My updated Game Server deployment', | ||
}, | ||
updateMask: { | ||
paths: ['labels', 'description'], | ||
}, | ||
}; | ||
|
||
const [operation] = await client.updateGameServerDeployment(request); | ||
const [result] = await operation.promise(); | ||
|
||
console.log(`Deployment updated: ${result.name}`); | ||
} | ||
|
||
updateGameServerDeployment(); | ||
|
||
// [END cloud_game_servers_deployment_update] | ||
} | ||
|
||
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.