0

in order to achieve some automation I am looking for a way for a complete hybris server startup via java code.

What I have tried so far was a startup with those commands

1)

de.hybris.platform.core.Registry.setCurrentTenantByID("master");
de.hybris.platform.core.Registry.activateMasterTenant();

2)

 de.hybris.platform.core.Registry.startup()

both ways I achieved a startup of hybris server but I need to access localhost:9002 or localhost:9001 but they are not available when I start server like that. There was nothing on those ports :/

Theo
  • 57
  • 5
  • It would a better idea to execute ant build.xml programmatically, see: https://coderanch.com/t/582057/java/execute-ant-build-xml-programatically – Benkerroum Mohamed Nov 21 '19 at 07:59
  • Thanks, that a good idea and it lets me start the server as needed. Any idea how I can find out when the server is up and continue with next step in my automation process which needs the server to be up? – Theo Nov 21 '19 at 08:55
  • You can set a `BuildListener` to `antProject` like: `antProject.addBuildListener(new BuildListener(){})`, and implement the interface methods – Benkerroum Mohamed Nov 21 '19 at 09:03
  • I have added the BuildListener but unfortunately it will never go into targetFinished() implementation. I think thats because unless the server is stopped the target is not finished? Any idea? – Theo Nov 21 '19 at 14:00

2 Answers2

0

Consider executing your hybris server shell script as below from a java program :

Mac OS

Process process = Runtime.getRuntime().exec("./hybrisserver.sh", null, new File("<PATH_TO_PLATFORM>"));
process.waitFor();

I have just tested it on Mac OS and with this hybris gets started successfully and I can access it over browser. Good luck!

FOR WINDOWS (haven't tested it)

Process process = Runtime.getRuntime().exec("cmd /c hybrisserver.bat, null, new File("<PATH_TO_PLATFORM>"));
process.waitFor();
www.hybriscx.com
  • 1,129
  • 4
  • 22
0

You can try the following ideas :

  • Keep checking log file output INFO: Server startup in 26438 ms, because it's the last log entry after a complete hybris start.
  • Keep trying to connect/knocking for the 9002/9001 port either using netstat script or using java socket. (a successful connection means the server is up)
  • There is an event in Hybris called AfterTenantRestartEvent, you can create a scriptjob as a listener for that event, then trigger your code when the event is catched.

public class MyAfterTenantStartupEventListener extends AbstractEventListener {

private final List<AfterTenantRestartEvent> eventsRecorded = new ArrayList<AfterTenantRestartEvent>();

@Override
protected void onEvent(final AfterTenantRestartEvent event)
{
    doSomething();
}

script Groovy, and insert it using an impex.

INSERT_UPDATE Script;code[unique=true]  ;scriptType(code)   ;content
                    ;EventListenerScript    ;GROOVY             ;<EventListenerCode> 

Then use this ImpEx to create a job.

INSERT_UPDATE ScriptingJob  ;code[unique=true]      ;scriptURI
                            ;helloWorldScriptJob    ;model://helloWorldScript 

2.3. Cron Job create an instance of the CronJobModel and attach to it the scripting job

INSERT_UPDATE CronJob   ;code[unique=true]          ;job(code)              ;sessionLanguage(isocode)   ;sessionUser(uid)
                        ;helloWorldScriptCronJob    ;helloWorldScriptJob    ;en                         ;admin 

More information:

https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/6.6.0.0/en-US/8c53e973866910149f7f95676060d3de.html?q=script%20listener

https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/6.6.0.0/en-US/07e3db4b90b24eb39522cb26ceb34544.html?q=script%20listener

Mohamed
  • 131
  • 1
  • 5