Skip to content
This repository was archived by the owner on Dec 4, 2021. It is now read-only.

Commit 813f349

Browse files
authored
Printer Health Check RPC (routes and tests) (#56)
* Adds routes and tests for PrinterHealthCheck * Regenerated client and server files for Printer Health Check RPC
1 parent e4456de commit 813f349

9 files changed

Lines changed: 107 additions & 66 deletions

File tree

client/api/2DPrinting.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
const express = require('express');
22
const router = express.Router();
3-
const { healthCheck, updateSignText } = require('../ledsign/led_sign_client');
4-
const { sendPrintRequest } = require('../printing/print_client');
5-
const { send3dPrintRequest } = require('../printing_3d/print_3d_client');
3+
const { healthCheck, sendPrintRequest } = require('../printing/print_client');
64
const {
7-
OK, BAD_REQUEST, NOT_FOUND, LED_SIGN_IP
5+
OK, BAD_REQUEST, NOT_FOUND
86
} = require('../config/config');
97
const { addSignLog } = require('../util/logging-helpers');
108

9+
router.post('/Printer/healthCheck', (req, res) => {
10+
healthCheck()
11+
.then(response => {
12+
return res.status(OK).send({ ...response });
13+
})
14+
.catch(error => {
15+
return res.status(NOT_FOUND).send({ ...error });
16+
});
17+
});
18+
1119
router.post('/Printer/sendPrintRequest', (req, res) => {
1220
const { raw, copies, sides, pageRanges, destination } = req.body;
1321
sendPrintRequest(raw, copies, sides, pageRanges, destination)

client/api/LedSign.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const express = require('express');
22
const router = express.Router();
33
const { healthCheck, updateSignText } = require('../ledsign/led_sign_client');
4-
const { sendPrintRequest } = require('../printing/print_client');
5-
const { send3dPrintRequest } = require('../printing_3d/print_3d_client');
64
const {
75
OK, BAD_REQUEST, NOT_FOUND, LED_SIGN_IP
86
} = require('../config/config');

client/printing/print_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function healthCheck() {
77
const client = new services.PrinterClient(
88
'localhost:50051', grpc.credentials.createInsecure()
99
);
10-
const healthCheckRequest = new messages.PrintRequest();
10+
const healthCheckRequest = new messages.PrinterHealthCheckUpRequest();
1111
return new Promise(function(resolve, reject) {
1212
client.healthCheck(healthCheckRequest, function(err, response) {
1313
if (err || !response) {

client/printing/print_grpc_pb.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
var grpc = require('grpc');
55
var print_pb = require('./print_pb.js');
66

7-
function serialize_HealthCheckUpRequest(arg) {
8-
if (!(arg instanceof print_pb.HealthCheckUpRequest)) {
9-
throw new Error('Expected argument of type HealthCheckUpRequest');
10-
}
11-
return Buffer.from(arg.serializeBinary());
12-
}
13-
14-
function deserialize_HealthCheckUpRequest(buffer_arg) {
15-
return print_pb.HealthCheckUpRequest.deserializeBinary(new Uint8Array(buffer_arg));
16-
}
17-
187
function serialize_PrintRequest(arg) {
198
if (!(arg instanceof print_pb.PrintRequest)) {
209
throw new Error('Expected argument of type PrintRequest');
@@ -37,6 +26,17 @@ function deserialize_PrintResponse(buffer_arg) {
3726
return print_pb.PrintResponse.deserializeBinary(new Uint8Array(buffer_arg));
3827
}
3928

29+
function serialize_PrinterHealthCheckUpRequest(arg) {
30+
if (!(arg instanceof print_pb.PrinterHealthCheckUpRequest)) {
31+
throw new Error('Expected argument of type PrinterHealthCheckUpRequest');
32+
}
33+
return Buffer.from(arg.serializeBinary());
34+
}
35+
36+
function deserialize_PrinterHealthCheckUpRequest(buffer_arg) {
37+
return print_pb.PrinterHealthCheckUpRequest.deserializeBinary(new Uint8Array(buffer_arg));
38+
}
39+
4040
function serialize_PrinterHealthStatus(arg) {
4141
if (!(arg instanceof print_pb.PrinterHealthStatus)) {
4242
throw new Error('Expected argument of type PrinterHealthStatus');
@@ -65,10 +65,10 @@ var PrinterService = exports.PrinterService = {
6565
path: '/Printer/HealthCheck',
6666
requestStream: false,
6767
responseStream: false,
68-
requestType: print_pb.HealthCheckUpRequest,
68+
requestType: print_pb.PrinterHealthCheckUpRequest,
6969
responseType: print_pb.PrinterHealthStatus,
70-
requestSerialize: serialize_HealthCheckUpRequest,
71-
requestDeserialize: deserialize_HealthCheckUpRequest,
70+
requestSerialize: serialize_PrinterHealthCheckUpRequest,
71+
requestDeserialize: deserialize_PrinterHealthCheckUpRequest,
7272
responseSerialize: serialize_PrinterHealthStatus,
7373
responseDeserialize: deserialize_PrinterHealthStatus,
7474
},

client/printing/print_pb.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ var jspb = require('google-protobuf');
1111
var goog = jspb;
1212
var global = Function('return this')();
1313

14-
goog.exportSymbol('proto.HealthCheckUpRequest', null, global);
1514
goog.exportSymbol('proto.PrintRequest', null, global);
1615
goog.exportSymbol('proto.PrintResponse', null, global);
16+
goog.exportSymbol('proto.PrinterHealthCheckUpRequest', null, global);
1717
goog.exportSymbol('proto.PrinterHealthStatus', null, global);
1818

1919
/**
@@ -417,12 +417,12 @@ proto.PrintResponse.prototype.setMessage = function(value) {
417417
* @extends {jspb.Message}
418418
* @constructor
419419
*/
420-
proto.HealthCheckUpRequest = function(opt_data) {
420+
proto.PrinterHealthCheckUpRequest = function(opt_data) {
421421
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
422422
};
423-
goog.inherits(proto.HealthCheckUpRequest, jspb.Message);
423+
goog.inherits(proto.PrinterHealthCheckUpRequest, jspb.Message);
424424
if (goog.DEBUG && !COMPILED) {
425-
proto.HealthCheckUpRequest.displayName = 'proto.HealthCheckUpRequest';
425+
proto.PrinterHealthCheckUpRequest.displayName = 'proto.PrinterHealthCheckUpRequest';
426426
}
427427

428428

@@ -437,8 +437,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) {
437437
* for transitional soy proto support: http://goto/soy-param-migration
438438
* @return {!Object}
439439
*/
440-
proto.HealthCheckUpRequest.prototype.toObject = function(opt_includeInstance) {
441-
return proto.HealthCheckUpRequest.toObject(opt_includeInstance, this);
440+
proto.PrinterHealthCheckUpRequest.prototype.toObject = function(opt_includeInstance) {
441+
return proto.PrinterHealthCheckUpRequest.toObject(opt_includeInstance, this);
442442
};
443443

444444

@@ -447,11 +447,11 @@ proto.HealthCheckUpRequest.prototype.toObject = function(opt_includeInstance) {
447447
* @param {boolean|undefined} includeInstance Whether to include the JSPB
448448
* instance for transitional soy proto support:
449449
* http://goto/soy-param-migration
450-
* @param {!proto.HealthCheckUpRequest} msg The msg instance to transform.
450+
* @param {!proto.PrinterHealthCheckUpRequest} msg The msg instance to transform.
451451
* @return {!Object}
452452
* @suppress {unusedLocalVariables} f is only used for nested messages
453453
*/
454-
proto.HealthCheckUpRequest.toObject = function(includeInstance, msg) {
454+
proto.PrinterHealthCheckUpRequest.toObject = function(includeInstance, msg) {
455455
var f, obj = {
456456
memberName: jspb.Message.getFieldWithDefault(msg, 1, "")
457457
};
@@ -467,23 +467,23 @@ proto.HealthCheckUpRequest.toObject = function(includeInstance, msg) {
467467
/**
468468
* Deserializes binary data (in protobuf wire format).
469469
* @param {jspb.ByteSource} bytes The bytes to deserialize.
470-
* @return {!proto.HealthCheckUpRequest}
470+
* @return {!proto.PrinterHealthCheckUpRequest}
471471
*/
472-
proto.HealthCheckUpRequest.deserializeBinary = function(bytes) {
472+
proto.PrinterHealthCheckUpRequest.deserializeBinary = function(bytes) {
473473
var reader = new jspb.BinaryReader(bytes);
474-
var msg = new proto.HealthCheckUpRequest;
475-
return proto.HealthCheckUpRequest.deserializeBinaryFromReader(msg, reader);
474+
var msg = new proto.PrinterHealthCheckUpRequest;
475+
return proto.PrinterHealthCheckUpRequest.deserializeBinaryFromReader(msg, reader);
476476
};
477477

478478

479479
/**
480480
* Deserializes binary data (in protobuf wire format) from the
481481
* given reader into the given message object.
482-
* @param {!proto.HealthCheckUpRequest} msg The message object to deserialize into.
482+
* @param {!proto.PrinterHealthCheckUpRequest} msg The message object to deserialize into.
483483
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
484-
* @return {!proto.HealthCheckUpRequest}
484+
* @return {!proto.PrinterHealthCheckUpRequest}
485485
*/
486-
proto.HealthCheckUpRequest.deserializeBinaryFromReader = function(msg, reader) {
486+
proto.PrinterHealthCheckUpRequest.deserializeBinaryFromReader = function(msg, reader) {
487487
while (reader.nextField()) {
488488
if (reader.isEndGroup()) {
489489
break;
@@ -507,21 +507,21 @@ proto.HealthCheckUpRequest.deserializeBinaryFromReader = function(msg, reader) {
507507
* Serializes the message to binary data (in protobuf wire format).
508508
* @return {!Uint8Array}
509509
*/
510-
proto.HealthCheckUpRequest.prototype.serializeBinary = function() {
510+
proto.PrinterHealthCheckUpRequest.prototype.serializeBinary = function() {
511511
var writer = new jspb.BinaryWriter();
512-
proto.HealthCheckUpRequest.serializeBinaryToWriter(this, writer);
512+
proto.PrinterHealthCheckUpRequest.serializeBinaryToWriter(this, writer);
513513
return writer.getResultBuffer();
514514
};
515515

516516

517517
/**
518518
* Serializes the given message to binary data (in protobuf wire
519519
* format), writing to the given BinaryWriter.
520-
* @param {!proto.HealthCheckUpRequest} message
520+
* @param {!proto.PrinterHealthCheckUpRequest} message
521521
* @param {!jspb.BinaryWriter} writer
522522
* @suppress {unusedLocalVariables} f is only used for nested messages
523523
*/
524-
proto.HealthCheckUpRequest.serializeBinaryToWriter = function(message, writer) {
524+
proto.PrinterHealthCheckUpRequest.serializeBinaryToWriter = function(message, writer) {
525525
var f = undefined;
526526
f = message.getMemberName();
527527
if (f.length > 0) {
@@ -537,13 +537,13 @@ proto.HealthCheckUpRequest.serializeBinaryToWriter = function(message, writer) {
537537
* optional string member_name = 1;
538538
* @return {string}
539539
*/
540-
proto.HealthCheckUpRequest.prototype.getMemberName = function() {
540+
proto.PrinterHealthCheckUpRequest.prototype.getMemberName = function() {
541541
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
542542
};
543543

544544

545545
/** @param {string} value */
546-
proto.HealthCheckUpRequest.prototype.setMemberName = function(value) {
546+
proto.PrinterHealthCheckUpRequest.prototype.setMemberName = function(value) {
547547
jspb.Message.setProto3StringField(this, 1, value);
548548
};
549549

proto/print.proto

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
syntax = "proto3";
22

3-
43
service Printer {
54
rpc PrintPage (PrintRequest) returns (PrintResponse);
6-
rpc HealthCheck (HealthCheckUpRequest) returns (PrinterHealthStatus);
5+
rpc HealthCheck (PrinterHealthCheckUpRequest) returns (PrinterHealthStatus);
76
}
87

98
message PrintRequest {
@@ -17,10 +16,10 @@ message PrintResponse {
1716
string message = 1;
1817
}
1918

20-
message HealthCheckUpRequest {
19+
message PrinterHealthCheckUpRequest {
2120
string member_name = 1;
2221
}
2322

2423
message PrinterHealthStatus {
2524
string message = 1;
26-
}
25+
}

server/printing/print_pb2.py

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/printing/print_pb2_grpc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, channel):
2020
)
2121
self.HealthCheck = channel.unary_unary(
2222
'/Printer/HealthCheck',
23-
request_serializer=print__pb2.HealthCheckUpRequest.SerializeToString,
23+
request_serializer=print__pb2.PrinterHealthCheckUpRequest.SerializeToString,
2424
response_deserializer=print__pb2.PrinterHealthStatus.FromString,
2525
)
2626

@@ -50,7 +50,7 @@ def add_PrinterServicer_to_server(servicer, server):
5050
),
5151
'HealthCheck': grpc.unary_unary_rpc_method_handler(
5252
servicer.HealthCheck,
53-
request_deserializer=print__pb2.HealthCheckUpRequest.FromString,
53+
request_deserializer=print__pb2.PrinterHealthCheckUpRequest.FromString,
5454
response_serializer=print__pb2.PrinterHealthStatus.SerializeToString,
5555
),
5656
}
@@ -90,7 +90,7 @@ def HealthCheck(request,
9090
timeout=None,
9191
metadata=None):
9292
return grpc.experimental.unary_unary(request, target, '/Printer/HealthCheck',
93-
print__pb2.HealthCheckUpRequest.SerializeToString,
93+
print__pb2.PrinterHealthCheckUpRequest.SerializeToString,
9494
print__pb2.PrinterHealthStatus.FromString,
9595
options, channel_credentials,
9696
call_credentials, compression, wait_for_ready, timeout, metadata)

0 commit comments

Comments
 (0)