This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
ContextMonitorTask.java
171 lines (141 loc) · 5.9 KB
/
ContextMonitorTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright 1999-2008 University of Chicago
*
* 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
*
* http://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.
*/
package org.globus.workspace.cloud.client.tasks;
import org.globus.workspace.common.print.Print;
import org.globus.workspace.client.WorkspaceCLIMain;
import org.globus.workspace.client.Opts;
import org.globus.workspace.cloud.client.cluster.KnownHostsTask;
import org.globus.workspace.client_core.ExecutionProblem;
import java.util.ArrayList;
import edu.emory.mathcs.backport.java.util.concurrent.Callable;
public class ContextMonitorTask implements Callable {
private final String eprPath;
private final String name;
private final String idAuthz;
private final String reportDir;
private final long pollMs;
private final String knownHostsFile;
private String knownHostsDir;
private final String knownHostsTasksStr;
private final Print pr;
public ContextMonitorTask(String ctxEprPath,
String identityAuthorization,
String shortName,
String reportDirectory,
String sshKnownHostsFile,
KnownHostsTask[] knownHostTasks,
long pollMilliseconds,
Print print) throws ExecutionProblem {
if (print == null) {
throw new IllegalArgumentException("print may not be null");
}
this.pr = print;
this.eprPath = ctxEprPath;
this.name = shortName;
this.idAuthz = identityAuthorization;
this.reportDir = reportDirectory;
this.pollMs = pollMilliseconds;
if (knownHostTasks == null || knownHostTasks.length == 0) {
this.knownHostsFile = null;
this.knownHostsTasksStr = null;
this.knownHostsDir = null;
} else {
this.knownHostsFile = sshKnownHostsFile;
final StringBuffer buf = new StringBuffer(64);
for (int i = 0; i < knownHostTasks.length; i++) {
if (i > 0) {
buf.append(",");
}
final KnownHostsTask task = knownHostTasks[i];
buf.append(task.ipaddr)
.append("::")
.append(task.interfaceName);
if (task.printName != null) {
buf.append("::")
.append(task.printName);
}
if (task.perHostDir) {
if (this.knownHostsDir == null) {
if (task.perHostDirPath == null) {
throw new ExecutionProblem("expecting path here");
}
this.knownHostsDir = task.perHostDirPath;
}
if (this.knownHostsDir != null) {
if (!this.knownHostsDir.equals(task.perHostDirPath)) {
throw new ExecutionProblem("expecting identical " +
"path here, not supporting per-sshkey " +
"file/directory paths yet");
}
}
}
}
this.knownHostsTasksStr = buf.toString();
}
if (this.knownHostsTasksStr != null) {
if (this.knownHostsFile == null && this.knownHostsDir == null) {
throw new ExecutionProblem("known-host tasks " +
"but no path/dir to adjust");
}
}
}
public Object call() throws Exception {
return new Integer(this.execute());
}
int execute() {
// Could change this now to use the client API more directly, but
// there is not a significant advantage to do so right now.
final ArrayList cmdList = new ArrayList(4);
if (this.pr.isDebugEnabled()) {
cmdList.add("--" + Opts.DEBUG_OPT_STRING);
}
cmdList.add("--" + Opts.EPRFILE2_OPT_STRING);
cmdList.add(this.eprPath);
cmdList.add("--" + Opts.CTX_MONITOR_OPT_STRING);
cmdList.add("--" + Opts.POLL_DELAY_OPT_STRING);
cmdList.add(Long.toString(this.pollMs));
if (this.reportDir != null) {
cmdList.add("--" + Opts.REPORTDIR_OPT_STRING);
cmdList.add(this.reportDir);
}
cmdList.add("--" + Opts.AUTHORIZATION_OPT_STRING);
if (this.idAuthz != null) {
cmdList.add(this.idAuthz);
} else {
cmdList.add("host");
}
if (this.name != null) {
cmdList.add("--" + Opts.DISPLAY_NAME_OPT_STRING);
cmdList.add(this.name);
}
if (this.knownHostsTasksStr != null) {
if (this.knownHostsFile != null) {
cmdList.add("--" + Opts.SSHHOSTS_OPT_STRING);
cmdList.add(this.knownHostsFile);
}
cmdList.add("--" + Opts.ADJUST_SSHHOSTS_OPT_STRING);
cmdList.add(this.knownHostsTasksStr);
if (this.knownHostsDir != null) {
cmdList.add("--" + Opts.SSHHOSTSDIR_OPT_STRING);
cmdList.add(this.knownHostsDir);
}
}
final String[] cmd =
(String[]) cmdList.toArray(new String[cmdList.size()]);
// Could change this now to use the client API more directly.
return WorkspaceCLIMain.mainNoExit(cmd, this.pr);
}
}