...
To design an artifact as a component executor, we should define a Class that inherit AbstractScriptComponentFunction and override function to run actions.
- Python sampleDefine Artifacts:
Code Block |
---|
language | py |
---|
title | Define a Python Artifact |
---|
linenumbers | true |
---|
|
from org.onap.ccsdk.cds.blueprintsprocessor.services.execution import AbstractScriptComponentFunction
class someArtifact(AbstractScriptComponentFunction): |
...
Code Block |
---|
language | java |
---|
title | Define a Kotlin Artifact |
---|
linenumbers | true |
---|
|
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
open class SampleScriptArtifact : AbstractScriptComponentFunction() {
} |
An artifact need to implement at least 2 functions in order to be valid:
Code Block |
---|
language | py |
---|
title | Implement component process |
---|
linenumbers | true |
---|
|
def process(self, resource_assignment):
try:
######################### Component action here ########################
#Do action here
########################### End ##########################
except JavaException, err:
log.error("Java Exception in the script {}", err)
except Exception, err:
log.error("Python Exception in the script {}", err)
return None |
Code Block |
---|
language | py |
---|
title | Implement component recover |
---|
linenumbers | true |
---|
|
def recover(self, runtime_exception, resource_assignment):
log.error("Exception in the script {}", runtime_exception)
print self.addError(runtime_exception.cause.message)
return None |
- Functions available in Artifact script
The main library available while running a Component in CDS is the BlueprintRuntimeService. This provides to the user the Blueprint running context and run-time execution functions.The following shows functions available for all the different Components execution from a python script:
...