1616
1717'use strict' ;
1818
19+ /*!
20+ * @module debug/controller
21+ */
22+
1923var fs = require ( 'fs' ) ;
20- var path = require ( 'path' ) ;
2124var assert = require ( 'assert' ) ;
22- var crypto = require ( 'crypto' ) ;
23- var pjson = require ( '../package.json' ) ;
2425var qs = require ( 'querystring' ) ;
2526var utils = require ( '@google/cloud-diagnostics-common' ) . utils ;
26- var StatusMessage = require ( './apiclasses .js' ) . StatusMessage ;
27+ var Debuggee = require ( './debuggee .js' ) ;
2728
2829/** @const {string} Cloud Debug API endpoint */
2930var API = 'https://clouddebugger.googleapis.com/v2/controller' ;
3031
31- /* c.f. the Java Debugger agent */
32- /** @const {string} */ var DEBUGGEE_MODULE_LABEL = 'module' ;
33- /** @const {string} */ var DEBUGGEE_MAJOR_VERSION_LABEL = 'version' ;
34- /** @const {string} */ var DEBUGGEE_MINOR_VERSION_LABEL = 'minorversion' ;
35-
36-
3732/**
3833 * @constructor
3934 */
40- function DebugletApi ( config , debug ) {
35+ function Controller ( config , debug ) {
4136 config = config || { } ;
4237
4338 /** @priavate {Debug} */
@@ -68,7 +63,7 @@ function DebugletApi(config, debug) {
6863 * @param {Logger } logger a logger
6964 * @param {!function(?Error) } callback
7065 */
71- DebugletApi . prototype . init = function ( uid , logger , callback ) {
66+ Controller . prototype . init = function ( uid , logger , callback ) {
7267 var that = this ;
7368 that . uid_ = uid ;
7469 that . nextWaitToken_ = null ;
@@ -105,7 +100,7 @@ DebugletApi.prototype.init = function(uid, logger, callback) {
105100 * Register to the API
106101 * @param {!function(?Error,Object=) } callback
107102 */
108- DebugletApi . prototype . register = function ( callback ) {
103+ Controller . prototype . register = function ( callback ) {
109104 this . register_ ( null , callback ) ;
110105} ;
111106
@@ -114,7 +109,7 @@ DebugletApi.prototype.register = function(callback) {
114109 * Register an error to the API
115110 * @param {!string } errorMessage to be reported to the Debug API
116111 */
117- DebugletApi . prototype . registerError = function ( message ) {
112+ Controller . prototype . registerError = function ( message ) {
118113 this . register_ ( message , function ( ) { } ) ;
119114} ;
120115
@@ -126,66 +121,12 @@ DebugletApi.prototype.registerError = function(message) {
126121 * @param {!function(?Error,Object=) } callback
127122 * @private
128123 */
129- DebugletApi . prototype . register_ = function ( errorMessage , callback ) {
124+ Controller . prototype . register_ = function ( errorMessage , callback ) {
130125 var that = this ;
131-
132- var cwd = process . cwd ( ) ;
133- var mainScript = path . relative ( cwd , process . argv [ 1 ] ) ;
134-
135- var version = 'google.com/node-' +
136- ( that . onGCP ? 'gcp' : 'standalone' ) +
137- '/v' + pjson . version ;
138- var desc = process . title + ' ' + mainScript ;
139- var labels = {
140- 'main script' : mainScript ,
141- 'process.title' : process . title ,
142- 'node version' : process . versions . node ,
143- 'V8 version' : process . versions . v8 ,
144- 'agent.name' : pjson . name ,
145- 'agent.version' : pjson . version ,
146- 'projectid' : that . project_
147- } ;
148-
149- var serviceName = that . serviceName_ ;
150- if ( serviceName ) {
151- desc += ' module:' + serviceName ;
152- labels [ DEBUGGEE_MODULE_LABEL ] = serviceName ;
153- }
154-
155- var serviceVersion = that . serviceVersion_ ;
156- if ( serviceVersion ) {
157- desc += ' version:' + serviceVersion ;
158- if ( serviceVersion !== 'default' ) {
159- labels [ DEBUGGEE_MAJOR_VERSION_LABEL ] = serviceVersion ;
160- }
161- }
162-
163- var descriptor = that . descriptor_ ;
164- if ( descriptor ) {
165- desc += ' description:' + descriptor ;
166- }
167-
168- if ( process . env . GAE_MINOR_VERSION ) {
169- labels [ DEBUGGEE_MINOR_VERSION_LABEL ] = process . env . GAE_MINOR_VERSION ;
170- }
171-
172- var uniquifier = desc + version + that . uid_ + that . sourceContext_ +
173- JSON . stringify ( labels ) ;
174- uniquifier = crypto . createHash ( 'sha1' ) . update ( uniquifier ) . digest ( 'hex' ) ;
175-
176- var debuggee = {
177- project : that . project_ ,
178- uniquifier : uniquifier ,
179- description : desc ,
180- agentVersion : version ,
181- labels : labels ,
182- sourceContexts : [ that . sourceContext_ ]
183- } ;
184-
185- if ( errorMessage ) {
186- debuggee . status = new StatusMessage ( StatusMessage . UNSPECIFIED , errorMessage ,
187- true ) ;
188- }
126+ var debuggee = new Debuggee (
127+ that . project_ , that . uid_ ,
128+ { service : that . serviceName_ , version : that . serviceVersion_ } ,
129+ that . sourceContext_ , that . descriptor_ , errorMessage , that . onGCP ) ;
189130
190131 var options = {
191132 uri : API + '/debuggees/register' ,
@@ -214,7 +155,7 @@ DebugletApi.prototype.register_ = function(errorMessage, callback) {
214155 * Fetch the list of breakpoints from the server. Assumes we have registered.
215156 * @param {!function(?Error,Object=,Object=) } callback accepting (err, response, body)
216157 */
217- DebugletApi . prototype . listBreakpoints = function ( callback ) {
158+ Controller . prototype . listBreakpoints = function ( callback ) {
218159 var that = this ;
219160 assert ( that . debuggeeId_ , 'should register first' ) ;
220161 var query = { success_on_timeout : true } ;
@@ -250,7 +191,7 @@ DebugletApi.prototype.listBreakpoints = function(callback) {
250191 * @param {!Breakpoint } breakpoint
251192 * @param {!Function } callback accepting (err, body)
252193 */
253- DebugletApi . prototype . updateBreakpoint =
194+ Controller . prototype . updateBreakpoint =
254195 function ( breakpoint , callback ) {
255196 assert ( this . debuggeeId_ , 'should register first' ) ;
256197
@@ -280,4 +221,4 @@ DebugletApi.prototype.updateBreakpoint =
280221 }
281222 } ;
282223
283- module . exports = DebugletApi ;
224+ module . exports = Controller ;
0 commit comments