Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Install component's IDL

Note
In case you haven't done this step already, you must Build and install IDL first.

Create component

Code Block
languagebash
cd ~/workspace
getTemplateForDirectory MODROOT_WS pyHelloComp
cd pyHelloComp/src
mkdir ws
touch ws/__init__.py
touch ws/HelloComponentImpl.py
vim Makefile

...

Code Block
languagepy
titlepyHelloComp/src/ws/HelloComponentImpl.py
# Client stubs and definitions, such as structs, enums, etc.
import workshop
# Skeleton infrastructure for server implementation
import workshop__POA
  
# Base component implementation
from Acspy.Servants.ACSComponent import ACSComponent
# Services provided by the container to the component
from Acspy.Servants.ContainerServices import ContainerServices
# Basic component lifecycle (initialize, execute, cleanUp and aboutToAbort methods)
from Acspy.Servants.ComponentLifecycle import ComponentLifecycle
  
class HelloComponentImpl(workshop__POA.HelloComponent, ACSComponent, ContainerServices, ComponentLifecycle):
    def __init__(self):
        ACSComponent.__init__(self)
        ContainerServices.__init__(self)
        self._logger = self.getLogger()
    def printHello(self):
        print("Just printing 'Hello World!'")
        return "Hello World!"

Compile component

Code Block
languagebash
make all install

Add component to CDB

Code Block
languagebash
vim $ACS_CDB/CDB/MACI/Components/Components.xml

Add the following item:

Code Block
languagebash
titleComponents.xml
<e Name="HelloWorldPython"
   Code="ws.HelloComponentImpl"
   Type="IDL:acsws/workshop/HelloComponent:1.0"
   Container="aragornContainer" ImplLang="py" />export INTROOT=~/workspace/introot
export PYTHONPATH=$INTROOT/lib/python/site-packages:/alma/ACS-2021AUG/ACSSW/lib/python/site-packages
make all install

Testing

Create client python file:

...

Code Block
languagepy
title~/workspace/client.py
from Acspy.Clients.SimpleClient import PySimpleClient
 
client = PySimpleClient()
component 
hc_py = client.getComponent("PY_HELLO_COMPHelloWorldPython")

print(hc_pycomponent.printHello())

Run clientcomponent:

Code Block
languagebash
# in one terminal
acsStop
acsStart
# in a different terminal
acsStartContainer -py aragornContainer
# in a different terminal
python client.py

Example output:

Code Block
...
Hello World!
...

...