Skip to content

Commit

Permalink
Added killing processes feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-flynn committed Aug 12, 2018
1 parent 7db43e0 commit e535444
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 25 deletions.
4 changes: 2 additions & 2 deletions audience-display/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class App extends React.Component<IProps, IState> {
SocketProvider.initialize((this.props.cookies.get("host") as string));
EMSProvider.initialize((this.props.cookies.get("host") as string));
} else {
SocketProvider.initialize("127.0.0.1"); // Debug/local IPv4
EMSProvider.initialize("127.0.0.1"); // Debug/local IPv4
SocketProvider.initialize("192.168.100.114"); // Debug/local IPv4
EMSProvider.initialize("192.168.100.114"); // Debug/local IPv4
}
SocketProvider.on("connect", () => {
console.log("Connected to SocketIO.");
Expand Down
18 changes: 18 additions & 0 deletions ems-core/main/process-communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ const localIPv4 = require("local-ipv4-address");
const ipRegex = /\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b/;
const isProd = process.env.NODE_ENV === "production";

ipcMain.on("kill-ecosystem", (event) => {
logger.info("Killing application ecosystem...");
pm2.connect((err) => {
if (err) {
event.sender.send("kill-ecosystem-error", err);
} else {
pm2.killDaemon((errList) => {
pm2.disconnect();
if (errList) {
event.sender.send("kill-ecosystem-error");
} else {
event.sender.send("kill-ecosystem-success");
}
});
}
});
});

ipcMain.on("list-ecosystem", (event) => {
logger.info("Listing application ecosystem...");
pm2.connect((err) => {
Expand Down
2 changes: 1 addition & 1 deletion ems-core/package.electron.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ems-core",
"author": "The Orange Alliance",
"description": "An improved event experience.",
"version": "2.3.0",
"version": "2.4.0",
"private": true,
"main": "public/desktop/electron.js",
"homepage": "./public/desktop/"
Expand Down
2 changes: 1 addition & 1 deletion ems-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ems-core",
"version": "2.3.0",
"version": "2.4.0",
"private": true,
"main": "public/electron.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion ems-core/public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let win;

function createWindow () {
// Create the splash screen window.
let splashWin = new BrowserWindow({width: 480, height: 360, alwaysOnTop: true, frame: false, show: false});
let splashWin = new BrowserWindow({width: 480, height: 360, frame: false, show: false});
splashWin.loadURL(url.format({
pathname: path.join(__dirname, "./splash.html"),
protocol: "file:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,4 @@ export function mapDispatchToProps(dispatch: Dispatch<ApplicationActions>) {
};
}

export default connect(mapStateToProps, mapDispatchToProps)(EnergyImpactBlueScorecard);
export default connect(mapStateToProps, mapDispatchToProps)(EnergyImpactBlueScorecard as any);
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,4 @@ export function mapDispatchToProps(dispatch: Dispatch<ApplicationActions>) {
};
}

export default connect(mapStateToProps, mapDispatchToProps)(EnergyImpactRedScorecard);
export default connect(mapStateToProps, mapDispatchToProps)(EnergyImpactRedScorecard as any);
12 changes: 12 additions & 0 deletions ems-core/src/shared/managers/ProcessManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ class ProcessManager {
});
}

public killEcosystem(): Promise<any> {
return new Promise<any>((resolve, reject) => {
ipcRenderer.once("kill-ecosystem-success", () => {
resolve();
});
ipcRenderer.once("kill-ecosystem-error", (event: any, error: any) => {
reject(new AppError(1015, "PM2_KILL", error));
});
ipcRenderer.send("kill-ecosystem");
});
}

public startProcess(process: Process, host?: string): Promise<Process> {
return new Promise<Process>((resolve, reject) => {
ipcRenderer.once("start-process-success", (event: any, startedProcess: any) => {
Expand Down
63 changes: 46 additions & 17 deletions ems-core/src/views/settings/containers/NetworkConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ interface IProps {
interface IState {
updateIP: string,
updateIPValid: boolean,
modalOpen: boolean
networkModalOpen: boolean,
processModalOpen: boolean
}

const ipRegex = /\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b/;
Expand All @@ -43,13 +44,17 @@ class NetworkConfig extends React.Component<IProps, IState> {
this.state = {
updateIP: "",
updateIPValid: false,
modalOpen: false
networkModalOpen: false,
processModalOpen: false
};

this.setUpdateIP = this.setUpdateIP.bind(this);
this.updateNetworkHost = this.updateNetworkHost.bind(this);
this.deleteProcesses = this.deleteProcesses.bind(this);
this.openModal = this.openModal.bind(this);
this.closeModal = this.closeModal.bind(this);
this.openProcessModal = this.openProcessModal.bind(this);
this.closeProcessModal = this.closeProcessModal.bind(this);
}

public componentWillMount() {
Expand All @@ -59,7 +64,7 @@ class NetworkConfig extends React.Component<IProps, IState> {
}

public render() {
const {updateIP, updateIPValid, modalOpen} = this.state;
const {updateIP, updateIPValid, networkModalOpen, processModalOpen} = this.state;
const processes = this.props.processList.map(process => {
return <ProcessDescriptor key={process.id} process={process}/>;
});
Expand All @@ -68,7 +73,8 @@ class NetworkConfig extends React.Component<IProps, IState> {
});
return (
<Tab.Pane className="tab-subview">
<RestrictedAccessModal open={modalOpen} onClose={this.closeModal} onSuccess={this.updateNetworkHost}/>
<RestrictedAccessModal open={networkModalOpen} onClose={this.closeModal} onSuccess={this.updateNetworkHost}/>
<RestrictedAccessModal open={processModalOpen} onClose={this.closeProcessModal} onSuccess={this.deleteProcesses}/>
<h3>Network Config</h3>
<Divider />
<Card fluid={true} color={getTheme().secondary}>
Expand Down Expand Up @@ -114,17 +120,11 @@ class NetworkConfig extends React.Component<IProps, IState> {
<Card.Content className="card-header"><h3>Process Management</h3></Card.Content>
<Card.Content>
{processActions}
{/*<Grid columns="equal">*/}
{/*<Grid.Row>*/}
{/*<Grid.Column><Button fluid={true} color="red">Stop All</Button></Grid.Column>*/}
{/*</Grid.Row>*/}
{/*<Grid.Row>*/}
{/*<Grid.Column><Button fluid={true} color="green">Start All</Button></Grid.Column>*/}
{/*</Grid.Row>*/}
{/*<Grid.Row>*/}
{/*<Grid.Column><Button fluid={true} color="orange">Restart All</Button></Grid.Column>*/}
{/*</Grid.Row>*/}
{/*</Grid>*/}
<Grid columns="equal">
<Grid.Row>
<Grid.Column><Button fluid={true} color="red" onClick={this.openProcessModal}>Delete All (Restricted)</Button></Grid.Column>
</Grid.Row>
</Grid>
</Card.Content>
</Card>
</Card.Group>
Expand Down Expand Up @@ -160,12 +160,41 @@ class NetworkConfig extends React.Component<IProps, IState> {
});
}

private deleteProcesses() {
this.props.setNavigationDisabled(true);
this.props.setProcessActionsDisabled(true);
ProcessManager.killEcosystem().then(() => {
ProcessManager.listEcosystem().then((procList: Process[]) => {
this.props.updateProcessList(procList);
this.props.setNavigationDisabled(false);
this.props.setProcessActionsDisabled(false);
DialogManager.showInfoBox("EMS", "All processes have been killed. Please restart EMS, or else the entire system will not function.");
}).catch((error: AppError) => {
this.props.setNavigationDisabled(false);
this.props.setProcessActionsDisabled(false);
DialogManager.showInfoBox("EMS", "All processes have been killed. Please restart EMS, or else the entire system will not function.");
});
}).catch((error: AppError) => {
this.props.setNavigationDisabled(false);
this.props.setProcessActionsDisabled(false);
DialogManager.showErrorBox(error);
});
}

private openModal() {
this.setState({modalOpen: true});
this.setState({networkModalOpen: true});
}

private closeModal() {
this.setState({modalOpen: false});
this.setState({networkModalOpen: false});
}

private openProcessModal() {
this.setState({processModalOpen: true});
}

private closeProcessModal() {
this.setState({processModalOpen: false});
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "event-management-system",
"description": "Hub for all programs in the EMS suite.",
"version": "2.3.0",
"version": "2.4.0",
"private": true,
"scripts": {
"api": "cd ems-api/ && npm start",
Expand Down

0 comments on commit e535444

Please sign in to comment.