Skip to content

Commit

Permalink
docs(samples): Add Game Server deployment samples (#92)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
  • Loading branch information
pooneh-m and JustinBeckwith authored Jul 16, 2020
1 parent a2da450 commit 15559ef
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 11 deletions.
84 changes: 76 additions & 8 deletions generated,README.md/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/ma
__Usage:__


`node samples/create_cluster.js`
`node samples/create_cluster.js <project_id> <location> <realmId> <clusterId> <gke_cluster_name>`


-----
Expand All @@ -63,7 +63,24 @@ View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/ma
__Usage:__


`node samples/create_realm.js`
`node samples/create_realm.js <project_id> <location> <realmId>`


-----




### Create_deployment

View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/master/samples/create_deployment.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-game-servers&page=editor&open_in_editor=samples/create_deployment.js,samples/README.md)

__Usage:__


`node samples/create_deployment.js <project_id> <deploymentId>`


-----
Expand All @@ -80,7 +97,7 @@ View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/ma
__Usage:__


`node samples/delete_cluster.js`
`node samples/delete_cluster.js <project_id> <location> <realmId> <clusterId>`


-----
Expand All @@ -97,7 +114,24 @@ View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/ma
__Usage:__


`node samples/delete_realm.js`
`node samples/delete_realm.js <project_id> <location> <realmId>`


-----




### Delete_deployment

View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/master/samples/delete_deployment.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-game-servers&page=editor&open_in_editor=samples/delete_deployment.js,samples/README.md)

__Usage:__


`node samples/delete_deployment.js <project_id> <deploymentId>`


-----
Expand All @@ -114,7 +148,7 @@ View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/ma
__Usage:__


`node samples/get_cluster.js`
`node samples/get_cluster.js <project_id> <location> <realmId> <clusterId>`


-----
Expand All @@ -131,7 +165,24 @@ View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/ma
__Usage:__


`node samples/get_realm.js`
`node samples/get_realm.js <project_id> <location> <realmId>`


-----




### Get_deployment

View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/master/samples/get_deployment.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-game-servers&page=editor&open_in_editor=samples/get_deployment.js,samples/README.md)

__Usage:__


`node samples/get_deployment.js <project_id> <deploymentId>`


-----
Expand All @@ -148,7 +199,7 @@ View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/ma
__Usage:__


`node samples/list_clusters.js`
`node samples/list_clusters.js <project_id> <location> <realmId>`


-----
Expand All @@ -165,7 +216,24 @@ View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/ma
__Usage:__


`node samples/list_realms.js`
`node samples/list_realms.js <project_id> <location>`


-----




### List_deployments

View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/master/samples/list_deployments.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-game-servers&page=editor&open_in_editor=samples/list_deployments.js,samples/README.md)

__Usage:__


`node samples/list_deployments.js <project_id>`


-----
Expand Down
4 changes: 2 additions & 2 deletions generated,README.md/create_cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* @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
* @param {string} gkeClusterName The full resource name of the GKE cluster to use
*/
async function main(
projectId = 'YOUR_PROJECT_ID',
Expand Down Expand Up @@ -54,6 +53,7 @@ async function main(
connectionInfo: {
gkeClusterReference: {
// Provide full resource name of a Kubernetes Engine cluster
// In the form of 'projects/<project-id>/locations/<location>/clusters/<gke-cluster-name>'
cluster: gkeClusterName,
},
namespace: 'default',
Expand Down
66 changes: 66 additions & 0 deletions generated,README.md/create_deployment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 Deployment.
* @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_create_deployment]
const {
GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function createGameServerDeployment() {
/**
* 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: `projects/${projectId}/locations/global`,
deploymentId: deploymentId,
gameServerDeployment: {
description: 'nodejs test deployment',
},
};

const [operation] = await client.createGameServerDeployment(request);
const [result] = await operation.promise();

console.log('Game Server Deployment created:');
console.log(`\t Deployment name: ${result.name}`);
console.log(`\t Deployment description: ${result.description}`);
}

createGameServerDeployment();

// [END cloud_game_servers_create_deployment]
}

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;
});
60 changes: 60 additions & 0 deletions generated,README.md/delete_deployment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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 Deployment.
* @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_delete_deployment]
const {
GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function deleteGameServerDeployment() {
/**
* 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 = {
// The full resource name
name: client.gameServerDeploymentPath(projectId, 'global', deploymentId),
};

await client.deleteGameServerDeployment(request);

console.log('deleted.');
}

deleteGameServerDeployment();

// [END cloud_game_servers_delete_deployment]
}

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;
});
64 changes: 64 additions & 0 deletions generated,README.md/get_deployment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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 Deployment.
* @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_get_deployment]
const {
GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function getGameServerDeployment() {
/**
* 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 = {
// The full resource name
name: client.gameServerDeploymentPath(projectId, 'global', deploymentId),
};

const [deployment] = await client.getGameServerDeployment(request);
console.log(`Deployment name: ${deployment.name}`);
console.log(`Deployment description: ${deployment.description}`);

const createTime = deployment.createTime;
const createDate = new Date(createTime.seconds * 1000);
console.log(`Deployment created on: ${createDate.toLocaleDateString()}\n`);
}

getGameServerDeployment();

// [END cloud_game_servers_get_deployment]
}

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;
});
Loading

0 comments on commit 15559ef

Please sign in to comment.