diff --git a/generated,README.md/create_cluster.js b/generated,README.md/create_cluster.js new file mode 100644 index 0000000000..57f19fc1ff --- /dev/null +++ b/generated,README.md/create_cluster.js @@ -0,0 +1,79 @@ +// 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 cluster. + * @param {string} projectId string project identifier + * @param {string} location Compute Engine region + * @param {string} realmId the realm to use + * @param {string} gameClusterId unique identifier for the new Game Cluster + * @param {string} gkeClusterId the GKE cluster to connect to + * @param {string} gkeLocation the location of the GKE cluster + */ +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'LOCATION_ID', + realmId = 'REALM_ID', + gameClusterId = 'GAME_CLUSTER_ID', + gkeClusterName = 'GKE_CLUSTER_NAME' +) { + // [START cloud_game_servers_create_cluster] + /** + * 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 to locate this cluster in'; + // const gameClusterId = 'A unique ID for this Game Server Cluster'; + // const gkeClusterName= 'The full resource name of the GKE cluster to use'; + const { + GameServerClustersServiceClient, + } = require('@google-cloud/game-servers'); + + const client = new GameServerClustersServiceClient(); + + async function createGameServerCluster() { + const request = { + // Provide full resource name of a Game Server Realm + 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: gkeClusterName, + }, + namespace: 'default', + }, + }, + }; + + const [operation] = await client.createGameServerCluster(request); + const [result] = await operation.promise(); + + console.log('Game Server Cluster created:'); + console.log(`\tCluster name: ${result.name}`); + console.log(`\tCluster description: ${result.description}`); + console.log( + `\tGKE cluster: ${result.connectionInfo.gkeClusterReference.cluster}` + ); + // [END cloud_game_servers_create_cluster] + } + + createGameServerCluster(); +} + +main(...process.argv.slice(2)); diff --git a/generated,README.md/delete_cluster.js b/generated,README.md/delete_cluster.js new file mode 100644 index 0000000000..8ef0e09fea --- /dev/null +++ b/generated,README.md/delete_cluster.js @@ -0,0 +1,58 @@ +// 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 Server cluster + * @param {string} projectId string project identifier + * @param {string} location Compute Engine region + * @param {string} realmId the realm to use + * @param {string} gameClusterId the game cluster to delete + */ +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'LOCATION_ID', + realmId = 'REALM_ID', + gameClusterId = 'GAME_CLUSTER_ID' +) { + // [START cloud_game_servers_delete_cluster] + /** + * 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 to locate this cluster in'; + // const gameClusterId = 'The unique ID for this Game Server Cluster'; + const { + GameServerClustersServiceClient, + } = require('@google-cloud/game-servers'); + + const client = new GameServerClustersServiceClient(); + + async function deleteGameServerCluster() { + const request = { + // Provide full resource name of a Game Server Realm + name: `projects/${projectId}/locations/${location}/realms/${realmId}/gameServerClusters/${gameClusterId}`, + }; + + await client.deleteGameServerCluster(request); + + console.log('Game Server cluster deleted'); + // [END cloud_game_servers_delete_cluster] + } + + deleteGameServerCluster(); +} + +main(...process.argv.slice(2)); diff --git a/generated,README.md/get_cluster.js b/generated,README.md/get_cluster.js new file mode 100644 index 0000000000..8cebc8ff75 --- /dev/null +++ b/generated,README.md/get_cluster.js @@ -0,0 +1,63 @@ +// 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 Server cluster + * @param {string} projectId string project identifier + * @param {string} location Compute Engine region + * @param {string} realmId the realm to use + * @param {string} gameClusterId the game cluster to get + */ +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'LOCATION_ID', + realmId = 'REALM_ID', + gameClusterId = 'GAME_CLUSTER_ID' +) { + // [START cloud_game_servers_get_cluster] + /** + * 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 to locate this cluster in'; + // const gameClusterId = 'The unique ID for this Game Server Cluster'; + const { + GameServerClustersServiceClient, + } = require('@google-cloud/game-servers'); + + const client = new GameServerClustersServiceClient(); + + async function getGameServerCluster() { + const request = { + // Provide full resource name of a Game Server Realm + name: `projects/${projectId}/locations/${location}/realms/${realmId}/gameServerClusters/${gameClusterId}`, + }; + + const [cluster] = await client.getGameServerCluster(request); + + console.log('Game Server Cluster:'); + console.log(`\tCluster name: ${cluster.name}`); + console.log(`\tCluster description: ${cluster.description}`); + console.log( + `\tGKE cluster: ${cluster.connectionInfo.gkeClusterReference.cluster}` + ); + // [END cloud_game_servers_get_cluster] + } + + getGameServerCluster(); +} + +main(...process.argv.slice(2)); diff --git a/generated,README.md/list_clusters.js b/generated,README.md/list_clusters.js new file mode 100644 index 0000000000..d2faa73f53 --- /dev/null +++ b/generated,README.md/list_clusters.js @@ -0,0 +1,63 @@ +// 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 Game Server clusters + * @param {string} projectId string project identifier + * @param {string} location Compute Engine region + * @param {string} realmId the realm to use + */ +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'LOCATION_ID', + realmId = 'REALM_ID' +) { + // [START cloud_game_servers_list_clusters] + /** + * 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 to locate this cluster in'; + const { + GameServerClustersServiceClient, + } = require('@google-cloud/game-servers'); + + const client = new GameServerClustersServiceClient(); + + async function listGameServerClusters() { + const request = { + // Provide full resource name of a Game Server Realm + parent: `projects/${projectId}/locations/${location}/realms/${realmId}`, + }; + + const results = await client.listGameServerClusters(request); + const [clusters] = results; + + for (const cluster of clusters) { + console.log('Game Server Cluster:'); + console.log(`\tCluster name: ${cluster.name}`); + console.log(`\tCluster description: ${cluster.description}`); + console.log( + `\tGKE cluster: ${cluster.connectionInfo.gkeClusterReference.cluster}` + ); + } + // [END cloud_game_servers_list_clusters] + } + + listGameServerClusters(); +} + +main(...process.argv.slice(2)); diff --git a/generated,README.md/test/clean.js b/generated,README.md/test/clean.js index 7436f1870a..cf62661619 100644 --- a/generated,README.md/test/clean.js +++ b/generated,README.md/test/clean.js @@ -46,7 +46,7 @@ module.exports = async () => { clustersRequest ); const [clusters] = clustersResult; - for (const cluster of clusters.gameServerClusters) { + for (const cluster of clusters) { const deleteClusterRequest = { name: cluster.name, }; diff --git a/generated,README.md/test/create_cluster.test.js b/generated,README.md/test/create_cluster.test.js new file mode 100644 index 0000000000..dc0bb66235 --- /dev/null +++ b/generated,README.md/test/create_cluster.test.js @@ -0,0 +1,91 @@ +// 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 +// +// 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/1046198160504/locations/us-west1-a/clusters/grpc-bug-cluster'; + +describe('Game Servers Create Cluster Test', () => { + const realmsClient = new RealmsServiceClient(); + const gameClustersClient = new GameServerClustersServiceClient(); + let realmId, gameClusterId; + + before(async () => { + await cleanup(); + + // Create a realm + const projectId = await realmsClient.getProjectId(); + realmId = `create-realm-${uuid.v4()}`; + gameClusterId = `test-${uuid.v4()}`; + + const request = { + parent: `projects/${projectId}/locations/${LOCATION}`, + realmId: realmId, + realm: { + timeZone: 'US/Pacific', + description: 'Test Game Server realm', + }, + }; + + const [operation] = await realmsClient.createRealm(request); + await operation.promise(); + }); + + it('should create a Game Server cluster', async () => { + const projectId = await realmsClient.getProjectId(); + gameClusterId = `test-${uuid.v4()}`; + + const create_output = execSync( + `node create_cluster.js ${projectId} ${LOCATION} ${realmId} ${gameClusterId} ${GKE_CLUSTER_NAME}` + ); + assert.match(create_output, /Cluster name:/); + }); + + after(async () => { + const projectId = await realmsClient.getProjectId(); + + // 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(); + }); +}); diff --git a/generated,README.md/test/delete_cluster.test.js b/generated,README.md/test/delete_cluster.test.js new file mode 100644 index 0000000000..c09a1b528a --- /dev/null +++ b/generated,README.md/test/delete_cluster.test.js @@ -0,0 +1,112 @@ +// 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 +// +// 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/1046198160504/locations/us-west1-a/clusters/grpc-bug-cluster'; + +describe('Game Servers Delete Cluster Test', () => { + const realmsClient = new RealmsServiceClient(); + const gameClustersClient = new GameServerClustersServiceClient(); + let projectId, realmId, gameClusterId; + + before(async () => { + await cleanup(); + + // Create a realm + projectId = await realmsClient.getProjectId(); + realmId = `delete-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 delete a Game Server cluster in a realm', async () => { + const create_output = execSync( + `node delete_cluster.js ${projectId} ${LOCATION} ${realmId} ${gameClusterId}` + ); + assert.match(create_output, /Game Server cluster deleted/); + }); + + 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}`, + }; + try { + const [operation1] = await gameClustersClient.deleteGameServerCluster( + deleteClusterRequest + ); + await operation1.promise(); + } catch (ex) { + console.log(ex); + console.log(`Realm ID: ${realmId}`); + console.log(`Cluster ID: ${gameClusterId}`); + } + // Delete the realm + const deleteRealmRequest = { + name: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}`, + }; + const [operation2] = await realmsClient.deleteRealm(deleteRealmRequest); + await operation2.promise(); + }); +}); diff --git a/generated,README.md/test/get_cluster.test.js b/generated,README.md/test/get_cluster.test.js new file mode 100644 index 0000000000..fc0a761ae2 --- /dev/null +++ b/generated,README.md/test/get_cluster.test.js @@ -0,0 +1,111 @@ +// 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 +// +// 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/1046198160504/locations/us-west1-a/clusters/grpc-bug-cluster'; + +describe('Game Servers Get Cluster Test', () => { + const realmsClient = new RealmsServiceClient(); + const gameClustersClient = new GameServerClustersServiceClient(); + let realmId, gameClusterId; + + before(async () => { + await cleanup(); + + // Create a realm + const projectId = await realmsClient.getProjectId(); + realmId = `get-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 get a Game Server cluster in a realm', async () => { + const projectId = await realmsClient.getProjectId(); + + const create_output = execSync( + `node get_cluster.js ${projectId} ${LOCATION} ${realmId} ${gameClusterId}` + ); + assert.match(create_output, /Cluster name:/); + }); + + after(async () => { + const projectId = await realmsClient.getProjectId(); + + // 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(); + }); +}); diff --git a/generated,README.md/test/list_clusters.test.js b/generated,README.md/test/list_clusters.test.js new file mode 100644 index 0000000000..51d5478742 --- /dev/null +++ b/generated,README.md/test/list_clusters.test.js @@ -0,0 +1,111 @@ +// 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 +// +// 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/1046198160504/locations/us-west1-a/clusters/grpc-bug-cluster'; + +describe('Game Servers List Clusters Test', () => { + const realmsClient = new RealmsServiceClient(); + const gameClustersClient = new GameServerClustersServiceClient(); + let realmId, gameClusterId; + + before(async () => { + await cleanup(); + + // Create a realm + const projectId = await realmsClient.getProjectId(); + realmId = `list-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 list Game Server clusters in a realm', async () => { + const projectId = await realmsClient.getProjectId(); + + const create_output = execSync( + `node list_clusters.js ${projectId} ${LOCATION} ${realmId}` + ); + assert.match(create_output, /Cluster name:/); + }); + + after(async () => { + const projectId = await realmsClient.getProjectId(); + + // 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(); + }); +});