16
16
import java .io .EOFException ;
17
17
import java .io .File ;
18
18
import java .io .FileOutputStream ;
19
- import java .io .InputStream ;
19
+ import java .io .IOException ;
20
20
import java .net .ConnectException ;
21
21
import java .net .URL ;
22
- import java .nio .charset .StandardCharsets ;
23
22
import java .util .zip .ZipEntry ;
24
23
import java .util .zip .ZipException ;
25
24
import java .util .zip .ZipInputStream ;
34
33
import software .amazon .awssdk .utils .StringUtils ;
35
34
36
35
public class AgentStartup implements Runnable {
37
- private static Logger logger = LogManager .getLogger (AgentStartup .class );
36
+ private static final Logger logger = LogManager .getLogger (AgentStartup .class );
38
37
private static final String SERVICE_RELATIVE_PATH = "/rest/v1/agent-service" ;
39
38
private static final String METHOD_SETTINGS = "/settings" ;
40
39
private static final String API_HARNESS_COMMAND = "./startAgent.sh" ;
@@ -54,14 +53,8 @@ public void run() {
54
53
URL url = new URL (controllerBaseUrl + SERVICE_RELATIVE_PATH + METHOD_SETTINGS );
55
54
logger .info ("Starting up: making call to tank service url to get settings.xml "
56
55
+ url .toExternalForm ());
57
- try ( InputStream settingsStream = url .openStream () ) {
58
- String settings = IOUtils .toString (settingsStream , StandardCharsets .UTF_8 );
59
- FileUtils .writeStringToFile (new File ("settings.xml" ), settings , StandardCharsets .UTF_8 );
60
- logger .info ("got settings file..." );
61
- } catch (ConnectException ce ) {
62
- logger .error ("Error creating connection to "
63
- + controllerBaseUrl + " : this is normal during the bake : " + ce .getMessage ());
64
- }
56
+ FileUtils .copyURLToFile (url , new File ("settings.xml" ));
57
+ logger .info ("got settings file..." );
65
58
// Download Support Files
66
59
url = new URL (controllerBaseUrl + SERVICE_RELATIVE_PATH + METHOD_SUPPORT );
67
60
logger .info ("Making call to tank service url to get support files " + url .toExternalForm ());
@@ -92,9 +85,12 @@ public void run() {
92
85
logger .info ("Starting apiharness with command: "
93
86
+ API_HARNESS_COMMAND + " -http=" + controllerBaseUrl + " " + jvmArgs );
94
87
Runtime .getRuntime ().exec (API_HARNESS_COMMAND + " -http=" + controllerBaseUrl + " " + jvmArgs );
95
- } catch (Exception e ) {
96
- logger .error ("Error in AgentStartup " + e , e );
97
- }
88
+ } catch (ConnectException ce ) {
89
+ logger .error ("Error creating connection to "
90
+ + controllerBaseUrl + " : this is normal during the bake : " + ce .getMessage ());
91
+ } catch (IOException e ) {
92
+ logger .error ("Error Executing API Harness Command: " + API_HARNESS_COMMAND + ": " + e , e );
93
+ } catch (InterruptedException e ) {}
98
94
}
99
95
100
96
public static void main (String [] args ) {
@@ -122,9 +118,7 @@ public static void main(String[] args) {
122
118
*/
123
119
private static void usage () {
124
120
System .out .println ("Tank Test Startup Usage:" );
125
- System .out
126
- .println ("java -cp agent-startup-pkg-1.0-all.jar com/intuit/tank/agent/AgentStartup <options>" );
121
+ System .out .println ("java -cp agent-startup-pkg-1.0-all.jar com/intuit/tank/agent/AgentStartup <options>" );
127
122
System .out .println ("-controller=<controller_base_url>: The url of the controller to get test info from" );
128
123
}
129
-
130
124
}
0 commit comments