Skip to content

Commit

Permalink
Start changing debug model
Browse files Browse the repository at this point in the history
- This is not even close to a planned structure but putting
  out concept of some sort to be able to play with ideas
  for better debug abstraction for streams and tasks.
- This now also allows to result running task config if
  debug flags are set.
- Relates spring-attic#3
  • Loading branch information
jvalkeal committed Oct 30, 2019
1 parent 2bb797c commit 1e00f43
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 77 deletions.
13 changes: 8 additions & 5 deletions src/commands/stream-debug-attach-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ import { Command } 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 { StreamDebugManager } from '../debug/stream-debug-manager';
import { DebugManager } from '../debug/debug-manager';

@injectable()
export class StreamDebugAttachCommand implements Command {

constructor(
@inject(TYPES.StreamDebugManager) private streamDebugManager: StreamDebugManager
@inject(TYPES.DebugManager) private debugManager: DebugManager
) {}

get id() {
return COMMAND_SCDF_STREAM_DEBUG_ATTACH;
}

async execute(args: InstanceNode) {
const debugConfiguration = await this.streamDebugManager.streamAppInstanceDebugConfiguration(args);
this.streamDebugManager.launchDebug([debugConfiguration]);
async execute(node: InstanceNode) {
const streamName = node.streamName;
const appName = node.appName;
const serverRegistration = node.registration;
const debugHandler = this.debugManager.getStreamDebugHandler(streamName, appName, serverRegistration);
debugHandler.attach();
}
}
12 changes: 7 additions & 5 deletions src/commands/tasks-debug-attach-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ import { injectable, inject } from 'inversify';
import { Command } from '@pivotal-tools/vscode-extension-di';
import { COMMAND_SCDF_TASKS_DEBUG_ATTACH } from '../extension-globals';
import { TYPES } from '../types';
import { StreamDebugManager } from '../debug/stream-debug-manager';
import { ExecutionNode } from '../explorer/models/execution-node';
import { DebugManager } from '../debug/debug-manager';

@injectable()
export class TasksDebugAttachCommand implements Command {

constructor(
@inject(TYPES.StreamDebugManager) private streamDebugManager: StreamDebugManager
@inject(TYPES.DebugManager) private debugManager: DebugManager
) {}

get id() {
return COMMAND_SCDF_TASKS_DEBUG_ATTACH;
}

async execute(args: ExecutionNode) {
const debugConfiguration = await this.streamDebugManager.taskExecutionNodeDebugConfiguration(args);
this.streamDebugManager.launchDebug([debugConfiguration]);
async execute(node: ExecutionNode) {
const executionId = node.executionId;
const serverRegistration = node.registration;
const debugHandler = this.debugManager.getTaskDebugHandler(executionId, serverRegistration);
debugHandler.attach();
}
}
80 changes: 80 additions & 0 deletions src/debug/debug-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2019 the original author or authors.
*
* 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.
*/

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

export interface DebugHandler {

attach(): Promise<void>;

}

export class DefaultStreamDebugHandler implements DebugHandler {

constructor(
private serverRegistration: ServerRegistration,
private streamName: string,
private appName: string,
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
};

this.debugProvider.startDebug(config);
}
}

export class DefaultTaskDebugHandler implements DebugHandler {

constructor(
private serverRegistration: ServerRegistration,
private executionId: 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 config: DebugConfiguration = {
type: 'java',
name: name,
request: 'attach',
hostName: "localhost",
port: port
};

this.debugProvider.startDebug(config);
}
}
47 changes: 47 additions & 0 deletions src/debug/debug-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2019 the original author or authors.
*
* 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.
*/
import { injectable, multiInject } from 'inversify';
import { ServerRegistration } from '../service/server-registration-manager';
import { DefaultStreamDebugHandler, DebugHandler, DefaultTaskDebugHandler } from './debug-handler';
import { TYPES } from '../types';
import { DebugProvider } from './debug-provider';

@injectable()
export class DebugManager {

constructor(
@multiInject(TYPES.DebugProvider) private debugProviders: DebugProvider[]
) {}

public getStreamDebugHandler(
streamName: string,
appName: string,
serverRegistration: ServerRegistration
): DebugHandler {
// find debug provider which supports our env
const debugProvider = this.debugProviders[0];
return new DefaultStreamDebugHandler(serverRegistration, streamName, appName, debugProvider);
}

public getTaskDebugHandler(
executionId: number,
serverRegistration: ServerRegistration
): DebugHandler {
// find debug provider which supports our env
const debugProvider = this.debugProviders[0];
return new DefaultTaskDebugHandler(serverRegistration, executionId, debugProvider);
}
}
44 changes: 44 additions & 0 deletions src/debug/debug-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2019 the original author or authors.
*
* 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.
*/
import { DebugConfiguration, debug, WorkspaceFolder } from 'vscode';
import { injectable } from 'inversify';

export interface DebugProvider {

getDebugType(): string;

hasDebugger(): Promise<boolean>;

startDebug(config: DebugConfiguration): Promise<boolean>;
}

@injectable()
export class LocalDebugProvider implements DebugProvider {

public getDebugType(): string {
return 'java';
}

public async hasDebugger(): Promise<boolean> {
return true;
}

public async startDebug(config: DebugConfiguration): Promise<boolean> {
const folder: WorkspaceFolder | undefined = undefined;
const started = await debug.startDebugging(folder, config);
return started;
}
}
25 changes: 25 additions & 0 deletions src/debug/di.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2019 the original author or authors.
*
* 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.
*/
import { ContainerModule } from 'inversify';
import { DebugProvider, LocalDebugProvider } from './debug-provider';
import { TYPES } from '../types';
import { DebugManager } from './debug-manager';

const debugContainerModule = new ContainerModule((bind) => {
bind<DebugProvider>(TYPES.DebugProvider).to(LocalDebugProvider);
bind<DebugManager>(TYPES.DebugManager).to(DebugManager).inSingletonScope();
});
export default debugContainerModule;
63 changes: 0 additions & 63 deletions src/debug/stream-debug-manager.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/scdf-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import {
import { DITYPES, DiExtension } from '@pivotal-tools/vscode-extension-di';
import { TYPES } from './types';
import commandsContainerModule from './commands/di.config';
import debugContainerModule from './debug/di.config';
import { ScdfLanguageSupport } from './language/scdf-language-support';
import { AppsExplorerProvider } from './explorer/apps-explorer-provider';
import { StreamsExplorerProvider } from './explorer/streams-explorer-provider';
import { TasksExplorerProvider } from './explorer/tasks-explorer-provider';
import { ServerRegistrationStatusBarManagerItem } from './statusbar/server-registration-status-bar-manager-item';
import { ServerRegistrationManager } from './service/server-registration-manager';
import { StreamDebugManager } from './debug/stream-debug-manager';
import { JobsExplorerProvider } from './explorer/jobs-explorer-provider';
import { CONFIG_SCDF_NOTIFICATION_LOCATION } from './extension-globals';

Expand All @@ -47,6 +47,7 @@ export class ScdfExtension extends DiExtension {

public onContainer(container: Container): void {
super.onContainer(container);
container.load(debugContainerModule);
container.load(commandsContainerModule);

container.bind<string>(DITYPES.NotificationManagerLocationKey).toConstantValue(CONFIG_SCDF_NOTIFICATION_LOCATION);
Expand All @@ -65,8 +66,6 @@ export class ScdfExtension extends DiExtension {
const serverRegistrationManager = container.get<ServerRegistrationManager>(TYPES.ServerRegistrationManager);
container.bind<ExtensionActivateAware>(DITYPES.ExtensionActivateAware).toConstantValue(serverRegistrationManager);

container.bind<StreamDebugManager>(TYPES.StreamDebugManager).to(StreamDebugManager).inSingletonScope();

// to fire build flow
container.get<AppsExplorerProvider>(TYPES.AppsExplorerProvider);
container.get<StreamsExplorerProvider>(TYPES.StreamsExplorerProvider);
Expand Down
1 change: 1 addition & 0 deletions src/service/scdf-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface ScdfTaskExecutionEntry extends BaseEntry {
jobExecutionIds: number[];
parentExecutionId: number;
startTime: string;
deploymentProperties: DeploymentProperties;
taskExecutionStatus: string;
taskName: string;
}
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export const TYPES = {
TasksExplorerProvider: Symbol('TasksExplorerProvider'),
JobsExplorerProvider: Symbol('JobsExplorerProvider'),
ServerRegistrationStatusBarManagerItem: Symbol('ServerRegistrationStatusBarManagerItem'),
StreamDebugManager: Symbol('StreamDebugManager')
DebugManager: Symbol('DebugManager'),
DebugProvider: Symbol('DebugProvider')
};

0 comments on commit 1e00f43

Please sign in to comment.