Skip to content

Commit

Permalink
Add proper debug attach
Browse files Browse the repository at this point in the history
- Now properly detect existense of debug ports for streams and tasks.
- Shuffle things around in debug classes.
- Relates spring-attic#3
  • Loading branch information
jvalkeal committed Nov 2, 2019
1 parent 56078c7 commit 120915b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 41 deletions.
17 changes: 12 additions & 5 deletions src/commands/stream-debug-attach-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
* limitations under the License.
*/
import { injectable, inject } from 'inversify';
import { Command } from '@pivotal-tools/vscode-extension-di';
import { Command, DITYPES } from '@pivotal-tools/vscode-extension-di';
import { COMMAND_SCDF_STREAM_DEBUG_ATTACH } from '../extension-globals';
import { TYPES } from '../types';
import { InstanceNode } from '../explorer/models/instance-node';
import { DebugManager } from '../debug/debug-manager';
import { NotificationManager } from '@pivotal-tools/vscode-extension-core';

@injectable()
export class StreamDebugAttachCommand implements Command {

constructor(
@inject(TYPES.DebugManager) private debugManager: DebugManager
@inject(TYPES.DebugManager) private debugManager: DebugManager,
@inject(DITYPES.NotificationManager) private notificationManager: NotificationManager
) {}

get id() {
Expand All @@ -33,9 +35,14 @@ export class StreamDebugAttachCommand implements Command {

async execute(node: InstanceNode) {
const streamName = node.streamName;
const appName = node.appName;
const appType = node.appType;
const serverRegistration = node.registration;
const debugHandler = this.debugManager.getStreamDebugHandler(streamName, appName, serverRegistration);
debugHandler.attach();

this.debugManager.getStreamDebugHandler(streamName, appType, serverRegistration)
.then(handler => {
handler.attach();
}, error => {
this.notificationManager.showMessage('Unable to start debug');
});
}
}
15 changes: 11 additions & 4 deletions src/commands/tasks-debug-attach-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
* limitations under the License.
*/
import { injectable, inject } from 'inversify';
import { Command } from '@pivotal-tools/vscode-extension-di';
import { Command, DITYPES } from '@pivotal-tools/vscode-extension-di';
import { COMMAND_SCDF_TASKS_DEBUG_ATTACH } from '../extension-globals';
import { TYPES } from '../types';
import { ExecutionNode } from '../explorer/models/execution-node';
import { DebugManager } from '../debug/debug-manager';
import { NotificationManager } from '@pivotal-tools/vscode-extension-core';

@injectable()
export class TasksDebugAttachCommand implements Command {

constructor(
@inject(TYPES.DebugManager) private debugManager: DebugManager
@inject(TYPES.DebugManager) private debugManager: DebugManager,
@inject(DITYPES.NotificationManager) private notificationManager: NotificationManager
) {}

get id() {
Expand All @@ -34,7 +36,12 @@ export class TasksDebugAttachCommand implements Command {
async execute(node: ExecutionNode) {
const executionId = node.executionId;
const serverRegistration = node.registration;
const debugHandler = this.debugManager.getTaskDebugHandler(executionId, serverRegistration);
debugHandler.attach();

this.debugManager.getTaskDebugHandler(executionId, serverRegistration)
.then(handler => {
handler.attach();
}, error => {
this.notificationManager.showMessage('Unable to start debug');
});
}
}
25 changes: 7 additions & 18 deletions src/debug/debug-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/

import { DebugConfiguration } from 'vscode';
import { ServerRegistration } from '../service/server-registration-manager';
import { DebugProvider } from './debug-provider';
import { ScdfModel } from '../service/scdf-model';
import { ScdfTaskExecutionEntry } from '../service/scdf-model';

export interface DebugHandler {

Expand All @@ -28,53 +27,43 @@ export interface DebugHandler {
export class DefaultStreamDebugHandler implements DebugHandler {

constructor(
private serverRegistration: ServerRegistration,
private streamName: string,
private appName: string,
private port: number,
private debugProvider: DebugProvider
) {}

public async attach(): Promise<void> {
const model = new ScdfModel(this.serverRegistration);
const deployment = model.getStreamDeployment(this.streamName);
const entry = await deployment;
const name = `Debug (Attach) - ${this.streamName} ${this.appName}`;
const port = +entry.deploymentProperties.log['spring.cloud.deployer.local.debug-port'];

const config: DebugConfiguration = {
type: 'java',
name: name,
request: 'attach',
hostName: "localhost",
port: port
port: this.port
};

this.debugProvider.startDebug(config);
}
}

export class DefaultTaskDebugHandler implements DebugHandler {

constructor(
private serverRegistration: ServerRegistration,
private execution: ScdfTaskExecutionEntry,
private executionId: number,
private port: number,
private debugProvider: DebugProvider
) {}

public async attach(): Promise<void> {
const model = new ScdfModel(this.serverRegistration);
const execution = await model.getTaskExecution(this.executionId);
const name = `Debug (Attach) - ${execution.taskName} ${this.executionId}`;
const port = +execution.deploymentProperties['deployer.timestamp.local.debug-port'];

const name = `Debug (Attach) - ${this.execution.taskName} ${this.executionId}`;
const config: DebugConfiguration = {
type: 'java',
name: name,
request: 'attach',
hostName: "localhost",
port: port
port: this.port
};

this.debugProvider.startDebug(config);
}
}
71 changes: 57 additions & 14 deletions src/debug/debug-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
import { injectable, multiInject } from 'inversify';
import { ServerRegistration } from '../service/server-registration-manager';
import { DefaultStreamDebugHandler, DebugHandler, DefaultTaskDebugHandler } from './debug-handler';
import { DebugHandler, DefaultStreamDebugHandler, DefaultTaskDebugHandler } from './debug-handler';
import { TYPES } from '../types';
import { DebugProvider } from './debug-provider';
import { ScdfModel } from '../service/scdf-model';

@injectable()
export class DebugManager {
Expand All @@ -26,22 +27,64 @@ export class DebugManager {
@multiInject(TYPES.DebugProvider) private debugProviders: DebugProvider[]
) {}

public getStreamDebugHandler(
streamName: string,
appName: string,
public getTaskDebugHandler(
executionId: number,
serverRegistration: ServerRegistration
): DebugHandler {
// find debug provider which supports our env
const debugProvider = this.debugProviders[0];
return new DefaultStreamDebugHandler(serverRegistration, streamName, appName, debugProvider);
): Thenable<DebugHandler> {
return new Promise(async (resolve, reject) => {
let port: number | undefined;
// TODO: find debug provider which supports our env
const debugProvider = this.debugProviders[0];

const model = new ScdfModel(serverRegistration);
const execution = await model.getTaskExecution(executionId);

const props = execution.deploymentProperties;
if (props) {
const regex = /deployer\.\w+\.local\.debug-port/;
for (const key in props) {
if (key.match(regex)) {
const portString = props[key];
if (portString) {
port = +portString;
}
break;
}
}
}
if (port) {
resolve(new DefaultTaskDebugHandler(execution, executionId, port, debugProvider));
} else {
reject(new Error(`Debug port unknown for task execution ${executionId}`));
}
});
}

public getTaskDebugHandler(
executionId: number,
public getStreamDebugHandler(
streamName: string,
appType: string,
serverRegistration: ServerRegistration
): DebugHandler {
// find debug provider which supports our env
const debugProvider = this.debugProviders[0];
return new DefaultTaskDebugHandler(serverRegistration, executionId, debugProvider);
): Thenable<DebugHandler> {
return new Promise(async (resolve, reject) => {
let port: number | undefined;
// TODO: find debug provider which supports our env
const debugProvider = this.debugProviders[0];
const model = new ScdfModel(serverRegistration);
const deployment = model.getStreamDeployment(streamName);
const entry = await deployment;
const props = entry.deploymentProperties[appType];
if (props) {
const portString = props['spring.cloud.deployer.local.debug-port'];
if (portString) {
port = +portString;
}
}
if (port) {
resolve(new DefaultStreamDebugHandler(streamName, appType, port, debugProvider));
} else {
reject(new Error(`Debug port unknown for app ${appType}`));
}
});
}

}
1 change: 1 addition & 0 deletions src/explorer/models/instance-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class InstanceNode extends BaseNode {
label: string,
public readonly streamName: string,
public readonly appName: string,
public readonly appType: string,
iconManager: IconManager,
public readonly registration: ServerRegistration
) {
Expand Down
2 changes: 2 additions & 0 deletions src/explorer/models/runtime-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class RuntimeNode extends BaseNode {
label: string,
public readonly streamName: string,
public readonly appName: string,
public readonly appType: string,
iconManager: IconManager,
private readonly instances: ScdfStreamRuntimeApplicationInstanceEntry[],
public readonly registration: ServerRegistration
Expand All @@ -47,6 +48,7 @@ export class RuntimeNode extends BaseNode {
instance.id,
this.streamName,
this.appName,
this.appType,
this.getIconManager(),
this.registration));
});
Expand Down
1 change: 1 addition & 0 deletions src/explorer/models/stream-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class StreamNode extends BaseNode {
application.name,
this.streamName,
application.id,
application.name,
this.getIconManager(),
application.instances,
this.registration));
Expand Down

0 comments on commit 120915b

Please sign in to comment.