Project

General

Profile

9709c.patch

Sergey Ivanovskiy, 01/28/2026 02:22 AM

Download (19 KB)

View differences:

new/src/com/goldencode/p2j/main/BrokerCore.java 2025-10-20 20:44:06 +0000
18 18
** 007 GBB 20240709 Hard-coded config names replaced by ConfigItem constants.
19 19
** 008 GBB 20240729 Initialize CentralLogger after SecurityManager is created.
20 20
** 009 AP  20250303 Added timeout for spawner launching.
21
** 010 SBI 20251019 Added dedicatedHost to log message, added PARAM_DEDICATED_MODE template parameter
22
**                  and BROKER_DEDICATED_MODE environment variable.
21 23
*/
22 24
/*
23 25
** This program is free software: you can redistribute it and/or modify
......
107 109
   /** CLASSPATH placeholder */
108 110
   public static final String PARAM_CP = "${remote.broker.classpath}";
109 111

  
112
   /** remote/agent/dedicatedMode placeholder */
113
   public static final String PARAM_DEDICATED_MODE = "${remote.agent.dedicatedMode}";
114

  
115
   /** remote/agent/host placeholder */
116
   public static final String PARAM_REMOTE_AGENT_HOST = "${remote.agent.host}";
117
   
118
   /** client:web:port placeholder */
119
   public static final String PARAM_CLIENT_WEB_PORT = "${remote.agent.port}";
120

  
110 121
   /** Broker P2J server address net:server:host */
111 122
   public static final String BROKER_HOST = "BROKER_HOST";
112 123
   
......
122 133
   /** Broker runtime class path */
123 134
   public static final String BROKER_CLASSPATH = "BROKER_CLASSPATH";
124 135

  
136
   /** Broker dedicatedHost */
137
   public static final String BROKER_DEDICATED_HOST = "BROKER_DEDICATED_HOST";
138

  
139
   /** web client port */
140
   public static final String WEB_CLIENT_PORT = "WEB_CLIENT_PORT";
141

  
142
   /** Broker dedicatedMode */
143
   public static final String BROKER_DEDICATED_MODE = "BROKER_DEDICATED_MODE";
144

  
125 145
   /** Logger. */
126 146
   private static final CentralLogger LOG = CentralLogger.get(BrokerCore.class.getName());
127 147

  
......
260 280
      args.getEnvironment().put(BROKER_PORT, port);
261 281
      args.getEnvironment().put(BROKER_JVMARGS, jvmargs);
262 282
      args.getEnvironment().put(BROKER_CLASSPATH, classpath);
283
      args.getEnvironment().put(BROKER_DEDICATED_HOST, dedicatedHost);
284
      args.getEnvironment().put(BROKER_DEDICATED_MODE,
285
                                String.valueOf(dedicatedMode));
263 286
      
264 287
      pb.environment().putAll(args.getEnvironment());
265 288
      
......
295 318
            command.add("-classpath");
296 319
            command.add(classpath);
297 320
         }
321
         else if (cmd.indexOf(BrokerCore.PARAM_REMOTE_AGENT_HOST) > -1)
322
         {
323
            command.add(cmd.replace(BrokerCore.PARAM_REMOTE_AGENT_HOST, dedicatedHost));
324
         }
325
         else if (cmd.indexOf(BrokerCore.PARAM_DEDICATED_MODE) > -1)
326
         {
327
            command.add(cmd.replace(BrokerCore.PARAM_DEDICATED_MODE, String.valueOf(dedicatedMode)));
328
         }
298 329
         else
299 330
         {
300 331
            command.add(cmd);
301 332
         }
302 333
      }
303 334
      
304
      // add client:web:host
305
      command.add("client:web:host=" + dedicatedHost);
306
      command.add("client:web:dedicatedMode=" + String.valueOf(dedicatedMode));
307
      
308 335
      LOG.logp(Level.INFO,
309 336
               "BrokerCore.spawn()",
310 337
               "",
......
444 471
         LOG.logp(Level.SEVERE,
445 472
                  BrokerCore.class.getName(),
446 473
                  "initialize",
447
                  "remote:agent:host should be configured as a network host name or IP address");
474
                  "remote:agent:host=" + dedicatedHost + " should be configured as a network host name or IP address");
448 475
      }
449 476
      // get the associated user account name
450 477
      associatedUser = cfg.getString("remote", "agent", "user", "");
451 478
      // get the dedicated broker mode
452
      dedicatedMode = cfg.getBoolean("remote", "agent", "dedicatedMode", false);
479
      dedicatedMode = cfg.getBoolean(ConfigItem.BROKER_DEDICATED_MODE, false);
453 480
      
454 481
      // JVM arguments
455 482
      String jargs = cfg.getString("remote", "java", "args", "");
new/src/com/goldencode/p2j/main/BrokerManager.java 2025-10-20 20:44:06 +0000
2 2
** Module   : BrokerManager.java
3 3
** Abstract : server side broker manager implementation.
4 4
**
5
** Copyright (c) 2014-2024, Golden Code Development Corporation.
5
** Copyright (c) 2014-2025, Golden Code Development Corporation.
6 6

  
7 7
**
8 8
** -#- -I- --Date-- ---------------------------------Description----------------------------------
......
19 19
** 008 GBB 20240709 CLIENT_IP constant moved here from WebDriverHandler.
20 20
**                  WebClientConfig renamed to WebAllocatedResources.
21 21
**                  Hard-coded config names replaced by ConfigItem constants.
22
** 009 SBI 20251016 Fixed registerBroker, removeUserHostWithCheck.
22 23
*/
23 24
/*
24 25
** This program is free software: you can redistribute it and/or modify
......
227 228
         {
228 229
            throw new RuntimeException("Only process accounts are allowed.");
229 230
         }
230
         
231
         params.setAgentAddress(host);
231 232
         // broker name if any
232 233
         params.setBrokerName(sm.getBrokerForProcess(params.getUserId()));
233 234
         if (params.getBrokerName() == null)
......
323 324
                                         Brokers brokers,
324 325
                                         BrokerSpawnParameters args)
325 326
   {
326
      return spawn(dedicatedUser, brokers, args, null, null, null);
327
      return spawn(null, dedicatedUser, brokers, args, null, null, null);
327 328
   }
328 329
   
329 330
   /**
......
351 352
    * 
352 353
    * @return  The result of remote spawn.
353 354
    */
354
   public static BrokerSpawnResult spawn(String dedicatedUser,
355
   public static BrokerSpawnResult spawn(ClientBuilder clientBuilder,
356
                                         String dedicatedUser,
355 357
                                         Brokers brokers,
356 358
                                         BrokerSpawnParameters args,
357 359
                                         WebClientAllocator allocator,
......
385 387
                                                                                uuid,
386 388
                                                                                dedicatedUser);
387 389
                  spawn = (clientConfig != null);
388
                  updateWebClientOptions(args, clientConfig);
390
                  updateWebClientOptions(clientBuilder, args, clientConfig);
389 391
               }
390 392
               if (spawn)
391 393
               {
......
426 428
                                                                             uuid,
427 429
                                                                             dedicatedUser);
428 430
               spawn = (clientConfig != null);
429
               updateWebClientOptions(args, clientConfig);
431
               updateWebClientOptions(clientBuilder, args, clientConfig);
430 432
            }
431 433
            if (spawn)
432 434
            {
......
518 520
                                               Map<String, List<String>> targetUserHosts)
519 521
   {
520 522
      List<String> userHosts = targetUserHosts.get(user);
521
      userHosts.remove(hostNameOrIpAddress);
522
      if (userHosts.isEmpty())
523
      if (userHosts != null)
524
      {
525
         userHosts.remove(hostNameOrIpAddress);
526
      }
527
      if (userHosts == null || userHosts.isEmpty())
523 528
      {
524 529
         targetUserHosts.remove(user);
525 530
      }
......
807 812
   /**
808 813
    * Update the command line parameters for the spawning process with the web client configuration.
809 814
    * 
815
    * @param    clientBuilder
816
    *           The client builder
810 817
    * @param    args
811 818
    *           The broker spawn parameters to update
812 819
    * @param    allocatedResources
813 820
    *           The allocated web resources
814 821
    */
815
   private static void updateWebClientOptions(BrokerSpawnParameters args,
822
   private static void updateWebClientOptions(ClientBuilder clientBuilder,
823
                                              BrokerSpawnParameters args,
816 824
                                              WebAllocatedResources allocatedResources)
817 825
   {
818 826
      if (allocatedResources != null)
......
820 828
         int port = allocatedResources.getPort();
821 829
         if (port > 0)
822 830
         {
831
            if (clientBuilder != null)
832
            {
833
               clientBuilder.updateCommand(allocatedResources.getUuid(), BrokerCore.PARAM_CLIENT_WEB_PORT, String.valueOf(port));
834
               ((WebClientBuilder) clientBuilder).getParams().updateOptions(allocatedResources);
835
            }
823 836
            args.getCommand().add(ConfigItem.PORT.fullOption() + "=" + port);
824 837
         }
825 838
         
new/src/com/goldencode/p2j/main/ClientBuilder.java 2025-10-27 08:36:22 +0000
37 37
** 022 CA  20240910 'net:socket:nio' is enabled by default only for Java 8.
38 38
** 023 CA  20250221 Added constants for the spawner modes.
39 39
** 024 AL2 20250523 'net:socket:nio' is disabled by default.
40
** 025 SBI 20251024 Added updateCommand.
40 41
*/
41 42

  
42 43
/*
......
156 157
   }
157 158
   
158 159
   /**
160
    * Update the spawn command registered for this UUID.
161
    * 
162
    * @param    uuid
163
    *           The UUID.
164
    * @param    templateParameterKey
165
    *           The template parameter key
166
    * @param    parameterValue
167
    *           The parameter value
168
    */
169
   public static void updateCommand(String uuid, String templateParameterKey, String parameterValue)
170
   {
171
      synchronized (pendingCmds)
172
      {
173
         String[] args = pendingCmds.get(uuid);
174
         if (args != null)
175
         {
176
            for (int i = 0; i < args.length; i++)
177
            {
178
               String arg = args[i];
179
               if (arg.indexOf(templateParameterKey) > -1)
180
               {
181
                  args[i] = arg.replace(templateParameterKey, parameterValue);
182
               }
183
            }
184
         }
185
      }
186
   }
187
   
188
   /**
159 189
    * Remove the spawn command registered for this UUID.
160 190
    * 
161 191
    * @param    uuid
......
279 309
         args.setPassword(params.getOsPass());
280 310
      }
281 311
   
282
      return BrokerManager.spawn(dedicatedUser, brokers, args, allocator, requestParameters, params.getUuid());
312
      return BrokerManager.spawn(this, dedicatedUser, brokers, args, allocator, requestParameters, params.getUuid());
283 313
   }
284 314
   
285 315
   /**
new/src/com/goldencode/p2j/main/NativeSecureConnection.java 2025-12-29 15:41:46 +0000
2 2
** Module   : NativeSecureConnection.java
3 3
** Abstract : Helper for connecting to a remote P2J server from native code, via JNI.
4 4
**
5
** Copyright (c) 2014-2024, Golden Code Development Corporation.
5
** Copyright (c) 2014-2025, Golden Code Development Corporation.
6 6
**
7 7
** -#- -I- --Date-- ---------------------------------Description---------------------------------
8 8
** 001 CA  20140211 Created initial version.
......
12 12
**     IAS 20210325 Added NIO configuration via BootstrapConfig
13 13
** 004 GBB 20230512 Logging methods replaced by CentralLogger/ConversionStatus.
14 14
** 005 GBB 20240729 Initialize CentralLogger in try-catch.
15
** 006 SBI 20251019 Resolved template variables PARAM_DEDICATED_MODE, PARAM_REMOTE_AGENT_HOST as an environment
16
**                  variables BROKER_DEDICATED_MODE and BROKER_DEDICATED_HOST respectively.
17
**         20251229 Throw NPEs if BROKER_DEDICATED_MODE or BROKER_DEDICATED_HOST environment variables are not set.
15 18
*/
16 19
/*
17 20
** This program is free software: you can redistribute it and/or modify
......
81 84
 */
82 85
public class NativeSecureConnection
83 86
{
87
   /** Error message template */
88
   private final static String ERROR_TEMPLATE = "Null value not allowed for %s";
89
   
84 90
   /**
85 91
    * Establish a secure connection to the target P2J server and retrieve the spawn command
86 92
    * registered with this request, via the specified UUID.
......
190 196
   private static String[] remote(String[] args)
191 197
   {
192 198
      // Get environment variables
193
      Map<String, String> env = System.getenv();      
199
      Map<String, String> env = System.getenv();
194 200
      // host
195
      String host = env.get(BrokerCore.BROKER_HOST);      
201
      String host = env.get(BrokerCore.BROKER_HOST);
196 202
      // secure port
197
      String port = env.get(BrokerCore.BROKER_PORT);      
203
      String port = env.get(BrokerCore.BROKER_PORT);
198 204
      // JVM arguments
199 205
      String jvmargs = env.get(BrokerCore.BROKER_JVMARGS);
200 206
      // classpath
201 207
      String classpath = env.get(BrokerCore.BROKER_CLASSPATH);
208
      // dedicatedHost
209
      String dedicatedHost = env.get(BrokerCore.BROKER_DEDICATED_HOST);
210
      // dedicatedMode
211
      String dedicatedMode = env.get(BrokerCore.BROKER_DEDICATED_MODE);
202 212

  
203 213
      // Command line arguments
204 214
      List<String> command = new LinkedList<String>();
......
211 221
         {
212 222
            if (host == null)
213 223
            {
214
               throw new NullPointerException("Null value not allowed for host.");
224
               throw new NullPointerException(String.format(ERROR_TEMPLATE, BrokerCore.BROKER_HOST));
215 225
            }
216 226
            // host
217 227
            command.add(cmd.replace(BrokerCore.PARAM_HOST, host));
......
221 231
         {
222 232
            if (port == null)
223 233
            {
224
               throw new NullPointerException("Null value not allowed for secure port.");
234
               throw new NullPointerException(String.format(ERROR_TEMPLATE, BrokerCore.BROKER_PORT));
225 235
            }
226 236
            // secure port
227 237
            command.add(cmd.replace(BrokerCore.PARAM_PORT, port));
......
230 240
         {
231 241
            if (jvmargs == null)
232 242
            {
233
               throw new NullPointerException("Null value not allowed for JVM arguments.");
243
               throw new NullPointerException(String.format(ERROR_TEMPLATE, BrokerCore.BROKER_JVMARGS));
234 244
            }
235 245
            // add JVM arguments
236 246
            String[] tokens = jvmargs.split("\\" + BrokerCore.BROKER_JVMARGS_SEPARATOR);
......
240 250
         {
241 251
            if (classpath == null)
242 252
            {
243
               throw new NullPointerException("Null value not allowed for CLASSPATH.");
253
               throw new NullPointerException(String.format(ERROR_TEMPLATE, BrokerCore.BROKER_CLASSPATH));
244 254
            }            
245 255
            // add CLASSAPTH
246 256
            command.add("-classpath");
247 257
            command.add(classpath);
248 258
         }
259
         else if (cmd.indexOf(BrokerCore.PARAM_REMOTE_AGENT_HOST) > -1)
260
         {
261
            if (dedicatedHost == null)
262
            {
263
               throw new NullPointerException(String.format(ERROR_TEMPLATE, BrokerCore.BROKER_DEDICATED_HOST));
264
            }            
265
            command.add(cmd.replace(BrokerCore.PARAM_REMOTE_AGENT_HOST, dedicatedHost));
266
         }
267
         else if (cmd.indexOf(BrokerCore.PARAM_DEDICATED_MODE) > -1)
268
         {
269
            if (dedicatedMode == null)
270
            {
271
               throw new NullPointerException(String.format(ERROR_TEMPLATE, BrokerCore.BROKER_DEDICATED_MODE));
272
            }            
273
            command.add(cmd.replace(BrokerCore.PARAM_DEDICATED_MODE, dedicatedMode));
274
         }
249 275
         else
250 276
         {
251 277
            command.add(cmd);
new/src/com/goldencode/p2j/main/WebClientBuilder.java 2025-12-29 15:41:46 +0000
39 39
** 017 GBB 20240719 Null check for project token.
40 40
** 018 GBB 20240730 Get the project token from the web parameters instead of resolving each time.
41 41
** 019 CA  20250221 Added constants for the spawner modes.
42
** 020 SBI 20251019 Added web client host parameter if SSO plugin is enabled and added BrokerCore.PARAM_DEDICATED_MODE
43
**                  template parameter as a value for ConfigItem.BROKER_DEDICATED_MODE(refs: #9709-146, #9709:147).
44
**         20251229 Improved "if" blocks.
42 45
*/
43 46
/*
44 47
** This program is free software: you can redistribute it and/or modify
......
162 165
         command.add(ConfigItem.SSO_STORAGE_ID.fullOption() + "=" + params.getStorageId());
163 166
      }
164 167
      
168
      if (remote)
169
      {
170
         command.add(ConfigItem.HOST.fullOption() + "=" + BrokerCore.PARAM_REMOTE_AGENT_HOST);
171
         command.add(ConfigItem.BROKER_DEDICATED_MODE.fullOption() + "=" + BrokerCore.PARAM_DEDICATED_MODE);
172
         command.add(ConfigItem.PORT.fullOption() + "=" + BrokerCore.PARAM_CLIENT_WEB_PORT);
173
      }
174
      
165 175
      UUID_OPTIONS.put(this.params.getUuid(), new PostInitOptions(dirOptions.getDriverType(),
166 176
                                                                  remote,
167 177
                                                                  dirOptions.getOverriddenOptions(),
new/src/com/goldencode/p2j/main/WebClientSpawner.java 2025-10-19 21:16:08 +0000
36 36
** 018 AI  20250904 Renamed accessedAtLeastOnce to safeRemoveListener.
37 37
** 019 SBI 20250910 Removed configuration parameters: MAX_LOST_PINGS and PING_DELAY.
38 38
** 020 TJD 20250807 Added SNI_HOST_CHECK option to control Jetty's SNIHostCheck feature
39
** 021 SBI 20251019 Reused ConfigItem.BROKER_DEDICATED_MODE.
39 40
*/
40 41
/*
41 42
** This program is free software: you can redistribute it and/or modify
......
413 414
         int port = config.getInt(ConfigItem.PORT, 0);
414 415
         String host = config.getString(ConfigItem.HOST, null);
415 416
         
416
         boolean dedicatedMode = config.getBoolean("client", "web", "dedicatedMode", false);
417
         boolean dedicatedMode = config.getBoolean(ConfigItem.BROKER_DEDICATED_MODE, false);
417 418
         
418 419
         // dedicated mode section placed just before the driver created
419 420
         if (dedicatedMode)
new/src/com/goldencode/p2j/util/ConfigItem.java 2025-10-19 21:16:08 +0000
20 20
**                  update readInClient to be able to read list of objects.
21 21
** 010 ES  20251008 Added UNITTEST_LEGACY_NAMES parameter.
22 22
** 011 TJD 20250807 Added SNI_HOST_CHECK option to control Jetty's SNIHostCheck feature
23
** 012 SBI 20251019 Added BROKER_DEDICATED_MODE remote/agent/dedicatedMode broker client settings.
23 24
*/
24 25
/*
25 26
** This program is free software: you can redistribute it and/or modify
......
598 599
   public static final ConfigItem<String> SPAWNER_UUID =
599 600
      new ConfigItem<>(String.class, "", "server", "spawner", "uuid", Type.RUNTIME);
600 601
   
602
   /**remote:agent:dedicatedMode broker configuration */
603
   public static final ConfigItem<Boolean> BROKER_DEDICATED_MODE =
604
         new ConfigItem<>(Boolean.class, "", "remote", "agent", "dedicatedMode", Type.RUNTIME);
605
   
601 606
   /** Enables web client debug logging in js. */
602 607
   public static final ConfigItem<Boolean> JS_DEBUG_LOGGING = new ConfigItem<>(Boolean.class,
603 608
                                                                               "enableDebugLogging",