Proces Controller Object
This commit is contained in:
parent
37cd129b8b
commit
622da2d238
2 changed files with 131 additions and 31 deletions
|
|
@ -51,7 +51,7 @@ public class JobServClient {
|
|||
* Spawns a new blockingStub for network operations with the server
|
||||
*/
|
||||
public JobServClient(ManagedChannel channel) {
|
||||
this.channel = channel;
|
||||
this.channel = channel;
|
||||
blockingStub = ShellServerGrpc.newBlockingStub(this.channel);
|
||||
}
|
||||
|
||||
|
|
@ -146,8 +146,8 @@ public class JobServClient {
|
|||
/*
|
||||
* sends PID to server
|
||||
* returns process exit code
|
||||
* returns a 0-255 return code or 277 if still running
|
||||
* or 278 if error in API
|
||||
* returns a 0-255 return code or 256 if still running
|
||||
* or 257 if error in API
|
||||
*/
|
||||
public int getProcessReturn(int pid) {
|
||||
logger.info("[+] Requesting return code of a job");
|
||||
|
|
@ -162,7 +162,7 @@ public class JobServClient {
|
|||
response = blockingStub.getReturn(request);
|
||||
} catch (StatusRuntimeException e) {
|
||||
logger.log(Level.WARNING, "(API Failure) Failed to get return code: " + e.getStatus());
|
||||
return 278;
|
||||
return 257;
|
||||
}
|
||||
|
||||
return response.getProcessReturnCode();
|
||||
|
|
@ -211,14 +211,13 @@ public class JobServClient {
|
|||
|
||||
JobServClient client;
|
||||
try {
|
||||
SslContextBuilder builder = GrpcSslContexts.forClient();
|
||||
builder.trustManager(new File(args[2]));
|
||||
builder.keyManager(new File(args[1]), new File(args[0]));
|
||||
SslContextBuilder builder = GrpcSslContexts.forClient();
|
||||
builder.trustManager(new File(args[2]));
|
||||
builder.keyManager(new File(args[1]), new File(args[0]));
|
||||
|
||||
ManagedChannel channel = NettyChannelBuilder.forAddress(args[3], Integer.parseInt(args[4]))
|
||||
.sslContext(builder.build())
|
||||
.build();
|
||||
|
||||
ManagedChannel channel = NettyChannelBuilder.forAddress(args[3], Integer.parseInt(args[4]))
|
||||
.sslContext(builder.build())
|
||||
.build();
|
||||
client = new JobServClient(channel);
|
||||
|
||||
// Likely bad port
|
||||
|
|
@ -226,7 +225,7 @@ public class JobServClient {
|
|||
System.out.println("Invalid Port");
|
||||
return;
|
||||
|
||||
// bad cert or key format
|
||||
// bad cert or key format
|
||||
} catch (SSLException e) {
|
||||
System.out.println(e.getMessage());
|
||||
return;
|
||||
|
|
@ -253,19 +252,19 @@ public class JobServClient {
|
|||
|
||||
case "output":
|
||||
candidatePid = getPidArg(args, 6);
|
||||
if (candidatePid < 0) {
|
||||
break;
|
||||
}
|
||||
if (candidatePid < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
String processOutput = client.getProcessOutput(candidatePid);
|
||||
System.out.println(processOutput);
|
||||
break;
|
||||
|
||||
|
||||
case "status":
|
||||
candidatePid = getPidArg(args, 6);
|
||||
if (candidatePid < 0) {
|
||||
break;
|
||||
}
|
||||
if (candidatePid < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
Boolean processStatus = client.getProcessStatus(candidatePid);
|
||||
System.out.printf("Process is currently running? %b\n", processStatus);
|
||||
|
|
@ -273,9 +272,9 @@ public class JobServClient {
|
|||
|
||||
case "kill":
|
||||
candidatePid = getPidArg(args, 6);
|
||||
if (candidatePid < 0) {
|
||||
break;
|
||||
}
|
||||
if (candidatePid < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
client.killProcess(candidatePid);
|
||||
System.out.println("End process request recieved!");
|
||||
|
|
@ -283,9 +282,9 @@ public class JobServClient {
|
|||
|
||||
case "return":
|
||||
candidatePid = getPidArg(args, 6);
|
||||
if (candidatePid < 0) {
|
||||
break;
|
||||
}
|
||||
if (candidatePid < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
int returnCode = client.getProcessReturn(candidatePid);
|
||||
|
||||
|
|
@ -314,15 +313,15 @@ public class JobServClient {
|
|||
* returns -1 (an invalid PID) if bad index or unparsable int
|
||||
*/
|
||||
private static int getPidArg(String[] args, int index) {
|
||||
if (args.length < index) {
|
||||
System.out.println("Improper formatting, try client --help");
|
||||
return -1;
|
||||
}
|
||||
if (args.length < index) {
|
||||
System.out.println("Improper formatting, try client --help");
|
||||
return -1;
|
||||
}
|
||||
|
||||
try {
|
||||
return Integer.parseInt(args[6]);
|
||||
|
||||
} catch (InputMismatchException e) {
|
||||
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println(args[6] + " is not a valid int, much less a valid pid");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue