2
2
3
3
import codeine .SnoozeKeeper ;
4
4
import codeine .configuration .IConfigurationManager ;
5
+ import codeine .configuration .Links ;
5
6
import codeine .configuration .PathHelper ;
6
7
import codeine .credentials .CredHelper ;
7
8
import codeine .jsons .auth .EncryptionUtils ;
@@ -54,13 +55,15 @@ public class CommandNodeServlet extends AbstractServlet {
54
55
private SnoozeKeeper snoozeKeeper ;
55
56
@ Inject
56
57
private PeerStatus projectStatusUpdater ;
58
+ @ Inject
59
+ private Links links ;
57
60
58
61
59
62
@ Override
60
63
public void myPost (HttpServletRequest request , HttpServletResponse res ) {
61
64
log .info ("start handle command" );
62
- if (Boolean .parseBoolean (getParameter (request , Constants .UrlParameters .FORCE ))
63
- || experimentalConfJsonStore .get ().allow_concurrent_commands_in_peer ()) {
65
+ if (Boolean .parseBoolean (getParameter (request , Constants .UrlParameters .FORCE )) || experimentalConfJsonStore
66
+ .get ().allow_concurrent_commands_in_peer ()) {
64
67
executeCommandNotSync (request , res );
65
68
} else {
66
69
executeCommandSync (request , res );
@@ -69,15 +72,13 @@ public void myPost(HttpServletRequest request, HttpServletResponse res) {
69
72
}
70
73
71
74
/**
72
- * this prevents multiple commands on the same peer, so preventing upgrade the peer during
73
- * command for example
75
+ * this prevents multiple commands on the same peer, so preventing upgrade the peer during command for example
74
76
*/
75
77
private void executeCommandNotSync (HttpServletRequest request , HttpServletResponse res ) {
76
78
executeInternal (request , res );
77
79
}
78
80
79
- private synchronized void executeCommandSync (HttpServletRequest request ,
80
- HttpServletResponse res ) {
81
+ private synchronized void executeCommandSync (HttpServletRequest request , HttpServletResponse res ) {
81
82
executeInternal (request , res );
82
83
}
83
84
@@ -89,13 +90,10 @@ private void executeInternal(HttpServletRequest request, HttpServletResponse res
89
90
String parameter = Constants .UrlParameters .DATA_NAME ;
90
91
String data = getParameter (request , parameter );
91
92
CommandInfo commandInfo = gson ().fromJson (data , CommandInfo .class );
92
- String data2 = getParameter (request ,
93
- Constants .UrlParameters .DATA_ADDITIONAL_COMMAND_INFO_NAME );
94
- CommandInfoForSpecificNode commandInfo2 = gson ()
95
- .fromJson (data2 , CommandInfoForSpecificNode .class );
93
+ String data2 = getParameter (request , Constants .UrlParameters .DATA_ADDITIONAL_COMMAND_INFO_NAME );
94
+ CommandInfoForSpecificNode commandInfo2 = gson ().fromJson (data2 , CommandInfoForSpecificNode .class );
96
95
if (null != commandInfo2 .key ()) {
97
- String decrypt = EncryptionUtils
98
- .decrypt (Constants .CODEINE_API_TOKEN_DERIVER , commandInfo2 .key ());
96
+ String decrypt = EncryptionUtils .decrypt (Constants .CODEINE_API_TOKEN_DERIVER , commandInfo2 .key ());
99
97
validateKey (decrypt );
100
98
} else {
101
99
log .warn ("key is null" , new RuntimeException ());
@@ -106,8 +104,8 @@ private void executeInternal(HttpServletRequest request, HttpServletResponse res
106
104
ProjectJson project = getProject (commandInfo .project_name ());
107
105
boolean windows_peer = project .operating_system () == OperatingSystem .Windows ;
108
106
if (null != script_content ) {
109
- cmdScript = new ShellScript (file , script_content , project .operating_system (),
110
- commandInfo2 . tmp_dir (), null , null , null );
107
+ cmdScript = new ShellScript (file , script_content , project .operating_system (), commandInfo2 . tmp_dir (),
108
+ null , null , null );
111
109
file = cmdScript .create ();
112
110
} else {
113
111
log .info ("command not found " + file );
@@ -151,19 +149,24 @@ private void executeInternal(HttpServletRequest request, HttpServletResponse res
151
149
};
152
150
Map <String , String > env = Maps .newHashMap ();
153
151
env .put (Constants .EXECUTION_ENV_PROJECT_NAME , commandInfo .project_name ());
152
+ if (commandInfo2 .command_id () != null ) {
153
+ env .put (Constants .EXECUTION_ENV_COMMAND_STATUS_LINK , links
154
+ .getWebServerCommandStatus (commandInfo .project_name (), commandInfo .name (),
155
+ commandInfo2 .command_id ()));
156
+ }
157
+ env .put (Constants .EXECUTION_ENV_COMMAND_NAME , commandInfo .name ());
154
158
env .put (Constants .EXECUTION_ENV_NODE_NAME , commandInfo2 .node_name ());
155
159
env .put (Constants .EXECUTION_ENV_NODE_ALIAS , commandInfo2 .node_alias ());
156
- env .put (Constants .EXECUTION_ENV_NODE_TAGS ,
157
- StringUtils .collectionToString (getTags (commandInfo .project_name (), commandInfo2 .node_name ()),";" ));
158
- env . put ( Constants . EXECUTION_ENV_CODEINE_SERVER ,
159
- globalConfigurationJsonStore .get ().web_server_host ());
160
+ env .put (Constants .EXECUTION_ENV_NODE_TAGS , StringUtils
161
+ .collectionToString (projectStatusUpdater . getTags (commandInfo .project_name (), commandInfo2 .node_name ()),
162
+ ";" ));
163
+ env . put ( Constants . EXECUTION_ENV_CODEINE_SERVER , globalConfigurationJsonStore .get ().web_server_host ());
160
164
env .put (Constants .EXECUTION_ENV_CODEINE_SERVER_PORT ,
161
165
globalConfigurationJsonStore .get ().web_server_port ().toString ());
162
166
env .putAll (commandInfo2 .environment_variables ());
163
167
env .putAll (getEnvParams (commandInfo ));
164
- Result result = new ProcessExecuterBuilder (cmd ,
165
- pathHelper .getProjectDir (commandInfo .project_name ())).cmdForOutput (cmdForOutput )
166
- .timeoutInMinutes (commandInfo .timeoutInMinutes ()).function (function ).env (env )
168
+ Result result = new ProcessExecuterBuilder (cmd , pathHelper .getProjectDir (commandInfo .project_name ()))
169
+ .cmdForOutput (cmdForOutput ).timeoutInMinutes (commandInfo .timeoutInMinutes ()).function (function ).env (env )
167
170
.user (cred ).build ().execute ();
168
171
writer .println (Constants .COMMAND_RESULT + result .exit ());
169
172
writer .flush ();
0 commit comments