# The JPython API to XCAT # @author : Sriram Krishnan[srikrish@extreme.indiana.edu] import sys #import the class we need from python from ui.python import CompositionTool # Create a composition tool. Declare it as global # so that all the functions can access the component. global compositionTool compositionTool = CompositionTool() compositionTool.initialize() # This method expects the XML file describing the # component, and creates a component wrapper for # it. A live instance can be created by invoking # the createInstance() method def createComponent(componentName): componentWrapper = compositionTool.create(componentName) return componentWrapper # setMachineName(componentWrapper, machineName) specifies # the machine on which we would like to instantiate # the component. def setMachineName(componentWrapper, machineName): componentWrapper.setMachineName(machineName) return # setCreationMechanism(componentWrapper, creationMechanism) # specifies the creation mechanism to be used while creating # the component instance. def setCreationMechanism(componentWrapper, creationMechanism): componentWrapper.setCreationMechanism(creationMechanism) return # createInstance takes in a handle to the component # model that we want to create and then creates a # live instance of this component. def createInstance(componentWrapper): compositionTool.instantiate(componentWrapper) return # connectPorts connects the uses port 'usesPort' of # the component 'usesPortComponent' to the provides port # 'providesPort' of the component 'providesPortComponent'. def connectPorts(usesPortComponent, usesPortName, providesPortComponent, providesPortName): compositionTool.connect(usesPortComponent, usesPortName, providesPortComponent, providesPortName) return # method that takes in the component specified by the componentWrapper, the # fully qualified name of the uses port, its type (which is a uri), the name under # which the provides port is registered, the method name, and the parameters, and # invokes the method on it. All parameters are strings, except the methodParams, # which is an array of java objects. def invokeMethodOnComponent(componentWrapper, usesPortClassName, usesPortType, providesPortName, methodName, methodParams) : retVal = compositionTool.executeMethod(componentWrapper, usesPortClassName, usesPortType, providesPortName, methodName, methodParams) return retVal