diff options
Diffstat (limited to 'mod')
64 files changed, 6280 insertions, 0 deletions
diff --git a/mod/bpgenerator/README.md b/mod/bpgenerator/README.md new file mode 100644 index 0000000..2e81745 --- /dev/null +++ b/mod/bpgenerator/README.md @@ -0,0 +1,61 @@ +# Blueprint Generator + +This tool allows the user to create a blueprint from a component spec json file + +# Instructions for building the tool locally +- Change directory into the root directory of the project (where the pom is located) +- Run the command: `mvn clean install` +- This will create a jar file and a tar file +- To execute the application + +```bash +java -jar target/blueprint-generator-1.2.1-SNAPSHOT-executable.jar +``` + + +# Instructions for running BlueprintGenerator: + +## Instructions for running: + + +-Run the program on the command line with the following tags: +OPTIONS: +- -p: The path to where the final blueprint yaml file will be created (Required) +- -i: The path to the JSON spec file (required) +- -n: Name of the blueprint (optional) +- -t: the path to the import yaml file (optional) +- -d: Onvoke the dmaap plugin (optional) +- -o: The service component name override (optional) + + +it will look like this: + +```bash +java -jar target/blueprint-generator-1.2.1-SNAPSHOT-executable.jar blueprint -p Blueprints -i ComponentSpecs/TestComponentSpec.json -n HelloWorld -d +``` + +This command will create a blueprint from the component spec TestComponentSpec. The blueprint file name will be called HelloWorld.yaml and it will be in the directory Blueprints. The blueprint will also contain the DMaaP plugin. + +## Extra information: +- The component spec must be of the same format as stated in the onap [readthedocs](https://onap.readthedocs.io/en/latest/submodules/dcaegen2.git/docs/sections/components/component-specification/common-specification.html#working-with-component-specs) page +- If the tag says required then the program will not run without those tags being there +- If the tag says optional then it is not necessary to run the program with those tags +- If you do not add a -n tag the blueprint name will default to what it is in the component spec +- If the directory you specified in the -p tag does not already exist the directory will be created for you +- The -t flag will override the default imports set for the blueprints. To see an example of how the import yaml file should be structured see the testImports.yaml file under the folder TestCases. + + +#Instructions for policy models + +-Run the program on the command line with the following tags: +OPTIONS: +- -i: The path to the JSON spec file (required) +- -p: The output path for all of the models (required) + +it will look like this: + +```bash +java -jar target/blueprint-generator-1.2.1-SNAPSHOT-executable.jar policy -p models -i ComponentSpecs/TestComponentSpec.json +``` + +This command will create a directory called models and put the policy models created from the component spec given in that directory. (A component spec may generate multiple policy models)
\ No newline at end of file diff --git a/mod/bpgenerator/TestCases/datafile.json b/mod/bpgenerator/TestCases/datafile.json new file mode 100644 index 0000000..d93bdb6 --- /dev/null +++ b/mod/bpgenerator/TestCases/datafile.json @@ -0,0 +1,426 @@ +{ + "self": { + "name": "dcaegen2.collectors.datafile.datafile-app-server", + "version": "1.0.0", + "description": "Docker application to collect log file from PNF", + "component_type": "docker" + }, + "streams": { + "subscribes": [ + { + "type": "message_router", + "config_key": "datafile_subscribe_mr", + "format": "VES_specification", + "version": "7.30.1" + } + ], + "publishes": [ + { + "type": "data_router", + "config_key": "datafile_publish_dr", + "format": "3GPP_XML", + "version": "1.0.0" + } + ] + }, + "services": { + "calls": [], + "provides": [] + }, + "auxilary": { + "healthcheck": { + "type": "http", + "interval": "15s", + "timeout": "1s", + "endpoint": "/heartbeat" + } + }, + "artifacts": [ + { + "uri": "nexus3.onap.org:10001/onap/org.onap.dcaegen2.collectors.datafile.datafile-app-server:latest", + "type": "docker image" + } + ], + "parameters": [ + { + "name": "service_name", + "value": "datafile", + "description": "Name of the service", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "buscontroller_feed_publishing_endpoint", + "value": "http://dmaap-bc.onap.svc.cluster.local:8080/webapi/feeds", + "description": "DMAAP Bus Controller feed endpoint", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": true, + "type": "string", + "required": true + }, + { + "name": "dmaap_dr_feed_id", + "value": "bulk_pm_feed", + "description": "ID of the data router feed that the datafile collector will publish", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "streams_consumer.datafile_consume_mr.message_router_topic", + "value": "/events/unauthenticated.VES_NOTIFICATION_OUTPUT", + "description": "datafile collector consume VES event to message router topic ", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.dmaapHostName", + "value": "localhost", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.dmaapPortNumber", + "value": "2222", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.dmaapTopicName", + "value": "/events/unauthenticated.VES_NOTIFICATION_OUTPUT", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.dmaapProtocol", + "value": "http", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.dmaapContentType", + "value": "application/json", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.consumerId", + "value": "C12", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.consumerGroup", + "value": "OpenDcae-c12", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.timeoutMs", + "value": "-1", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapConsumerConfiguration.messageLimit", + "value": "1", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapProducerConfiguration.dmaapHostName", + "value": "localhost", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapProducerConfiguration.dmaapPortNumber", + "value": "3907", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapProducerConfiguration.dmaapTopicName", + "value": "publish", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapProducerConfiguration.dmaapProtocol", + "value": "https", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapProducerConfiguration.dmaapUserName", + "value": "dradmin", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapProducerConfiguration.dmaapUserPassword", + "value": "dradmin", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapProducerConfiguration.dmaapContentType", + "value": "application/octet-stream", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "ftp.ftpesConfiguration.keyCert", + "value": "config/dfc.jks", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "ftp.ftpesConfiguration.keyPassword", + "value": "secret", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "ftp.ftpesConfiguration.trustedCA", + "value": "config/ftp.jks", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "ftp.ftpesConfiguration.trustedCAPassword", + "value": "secret", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "security.trustStorePath", + "value": "/opt/app/datafile/etc/cert/trust.jks", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "security.trustStorePasswordPath", + "value": "/opt/app/datafile/etc/cert/trust.pass", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "security.keyStorePath", + "value": "/opt/app/datafile/etc/cert/key.p12", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "security.keyStorePasswordPath", + "value": "/opt/app/datafile/etc/cert/key.pass", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "security.enableDmaapCertAuth", + "value": false, + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapBusControllerConfiguration.dmaapHostName", + "value": "localhost", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapBusControllerConfiguration.dmaapPortNumber", + "value": "6666", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapBusControllerConfiguration.dmaapTopicName", + "value": "webapis/feeds", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapBusControllerConfiguration.dmaapDrFeedName", + "value": "bulk_pm_feed", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapBusControllerConfiguration.dmaapProtocol", + "value": "https", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapBusControllerConfiguration.dmaapUserName", + "value": "dbcadmin", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapBusControllerConfiguration.dmaapUserPassword", + "value": "dbcadmin", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "dmaap.dmaapBusControllerConfiguration.dmaapContentType", + "value": "application/json", + "description": "", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false, + "type": "string", + "required": true + }, + { + "name": "datafile.policy", + "value": "", + "description": "datafile Policy JSON as string", + "designer_editable": false, + "sourced_at_deployment": false, + "policy_editable": true, + "type": "string", + "required": true + } + ] +} diff --git a/mod/bpgenerator/TestCases/hello.json b/mod/bpgenerator/TestCases/hello.json new file mode 100644 index 0000000..ec7d26a --- /dev/null +++ b/mod/bpgenerator/TestCases/hello.json @@ -0,0 +1,129 @@ +{ + "self": { + "component_type": "docker", + "description": "Hello World mS for subscribing the data from local DMaaP, DR or MR, processing them and publishing them as PM files to local DMaaP DR", + "name": "dcae.collectors.vcc.helloworld.pm", + "version": "1.0.1" + }, + "services": { + "calls": [], + "provides": [] + }, + "streams": { + "publishes": [{ + "config_key": "DCAE-HELLO-WORLD-PUB-DR", + "format": "dataformat_Hello_World_PM", + "type": "data_router", + "version": "1.0.0" + }, + { + "config_key": "DCAE-HELLO-WORLD-PUB-MR", + "format": "dataformat_Hello_World_PM", + "type": "message_router", + "version": "1.0.0" + } + ], + "subscribes": [{ + "config_key": "DCAE-HELLO-WORLD-SUB-MR", + "format": "dataformat_Hello_World_PM", + "route": "/DCAE_HELLO_WORLD_SUB_MR", + "type": "message_router", + "version": "1.0.0" + }, + { + "config_key": "DCAE-HELLO-WORLD-SUB-DR", + "format": "dataformat_Hello_World_PM", + "route": "/DCAE-HELLO-WORLD-SUB-DR", + "type": "data_router", + "version": "1.0.0" + } + ] + }, + "parameters": + [ + { + "name": "vcc_hello_name", + "value": "fsdfa", + "description": "the name entered for specific person", + "sourced_at_deployment": true, + "designer_editable": true, + "policy_editable": false, + "type": "string" + }, + + { + "name": "useDtiConfig", + "value": false, + "description": "component depends on configuration from dti.", + "sourced_at_deployment": false, + "designer_editable": false, + "policy_editable": false, + "required" : true + }, + + { + "name": "isSelfServeComponent", + "value": false, + "description": "Is this used as self serve component.", + "sourced_at_deployment": false, + "designer_editable": false, + "policy_editable": false, + "required" : true, + "type": "string" + } + ], + "auxilary": { + "healthcheck": { + "interval": "60s", + "timeout": "20s", + "script": "/opt/app/vcc/bin/common/HealthCheck_HelloWorld.sh", + "type": "docker" + }, + "volumes": [ + { + "container": { + "bind": "/opt/app/dcae-certificate" + }, + "host": { + "path": "/opt/app/dcae-certificate" + } + }, + { + "container": { + "bind": "/opt/logs/DCAE/dmd/AGENT" + }, + "host": { + "path": "/opt/logs/DCAE/helloworldpm/dmd/AGENT" + } + }, + { + "container": { + "bind": "/opt/logs/DCAE/dmd/WATCHER" + }, + "host": { + "path": "/opt/logs/DCAE/helloworldpm/dmd/WATCHER" + } + }, + { + "container": { + "bind": "/opt/app/vcc/logs/DCAE" + }, + "host": { + "path": "/opt/logs/DCAE/helloworldpm/vcc-logs" + } + }, + { + "container": { + "bind": "/opt/app/vcc/archive/data" + }, + "host": { + "path": "/opt/data/DCAE/helloworldpm/vcc-archive" + } + } + ] + }, + "artifacts": [{ + "type": "docker image", + "uri": "dockercentral.it.att.com:5100/com.att.dcae.controller/dcae-controller-vcc-helloworld-pm:18.02-001" + }] +}
\ No newline at end of file diff --git a/mod/bpgenerator/TestCases/j.json b/mod/bpgenerator/TestCases/j.json new file mode 100644 index 0000000..848b102 --- /dev/null +++ b/mod/bpgenerator/TestCases/j.json @@ -0,0 +1,96 @@ +{ + "self": { + "component_type": "docker", + "description": "Hello World mS for subscribing the data from local DMaaP, DR or MR, processing them and publishing them as PM files to local DMaaP DR", + "name": "dcae.test.ms", + "version": "1.0.0" + }, + + "services": { + "calls": [], + "provides": [] + }, + + "streams": { + "publishes": [{ + "config_key": "DCAE-HELLO-WORLD-PUB-DR", + "format": "dataformat_Hello_World_PM", + "type": "data_router", + "version": "1.0.0" + }, + { + "config_key": "DCAE-HELLO-WORLD-PUB-MR", + "format": "dataformat_Hello_World_PM", + "type": "message_router", + "version": "1.0.0" + } + ], + + "subscribes": [{ + "config_key": "DCAE-HELLO-WORLD-SUB-MR", + "format": "dataformat_Hello_World_PM", + "route": "/DCAE_HELLO_WORLD_SUB_MR", + "type": "message_router", + "version": "1.0.0" + }, + { + "config_key": "DCAE-HELLO-WORLD-SUB-DR", + "format": "dataformat_Hello_World_PM", + "route": "/DCAE-HELLO-WORLD-SUB-DR", + "type": "data_router", + "version": "1.0.0" + } + ] + }, + + "parameters": + [ + { + "name": "vcc_hello_name", + "value": "fsdfa", + "description": "the name entered for specific person", + "sourced_at_deployment": true, + "designer_editable": true, + "policy_editable": false, + "type": "string" + }, + + { + "name": "useDtiConfig", + "value": false, + "description": "component depends on configuration from dti.", + "sourced_at_deployment": false, + "designer_editable": false, + "policy_editable": false, + "required" : true + }, + + { + "name": "isSelfServeComponent", + "value": false, + "description": "Is this used as self serve component.", + "sourced_at_deployment": false, + "designer_editable": false, + "policy_editable": false, + "required" : true, + "type": "string" + } + ], + + "auxilary": { + "healthcheck": { + "interval": "60s", + "timeout": "20s", + "endpoint": "/", + "type": "http" + }, + "ports" : [ + "80:0" + ] + }, + + "artifacts": [{ + "type": "docker image", + "uri": "nginx" + }] +}
\ No newline at end of file diff --git a/mod/bpgenerator/TestCases/jack.json b/mod/bpgenerator/TestCases/jack.json new file mode 100644 index 0000000..219b1b5 --- /dev/null +++ b/mod/bpgenerator/TestCases/jack.json @@ -0,0 +1,93 @@ +{ + "self": { + "component_type": "docker", + "description": "Hello World mS for subscribing the data from local DMaaP, DR or MR, processing them and publishing them as PM files to local DMaaP DR", + "name": "dcae.test.ms", + "version": "1.0.0" + }, + + "services": { + "calls": [], + "provides": [] + }, + + "streams": { + "publishes": [{ + "config_key": "DCAE-HELLO-WORLD-PUB-DR", + "format": "dataformat_Hello_World_PM", + "type": "data_router", + "version": "1.0.0" + }, + { + "config_key": "DCAE-HELLO-WORLD-PUB-MR", + "format": "dataformat_Hello_World_PM", + "type": "message_router", + "version": "1.0.0" + } + ], + + "subscribes": [{ + "config_key": "DCAE-HELLO-WORLD-SUB-MR", + "format": "dataformat_Hello_World_PM", + "route": "/DCAE_HELLO_WORLD_SUB_MR", + "type": "message_router", + "version": "1.0.0" + }, + { + "config_key": "DCAE-HELLO-WORLD-SUB-DR", + "format": "dataformat_Hello_World_PM", + "route": "/DCAE-HELLO-WORLD-SUB-DR", + "type": "data_router", + "version": "1.0.0" + } + ] + }, + + "parameters": + [ + { + "name": "vcc_hello_name", + "value": "fsdfa", + "description": "the name entered for specific person", + "sourced_at_deployment": true, + "designer_editable": true, + "policy_editable": false, + "type": "string" + }, + + { + "name": "useDtiConfig", + "value": false, + "description": "component depends on configuration from dti.", + "sourced_at_deployment": false, + "designer_editable": false, + "policy_editable": false, + "required" : true + }, + + { + "name": "isSelfServeComponent", + "value": false, + "description": "Is this used as self serve component.", + "sourced_at_deployment": false, + "designer_editable": false, + "policy_editable": false, + "required" : true, + "type": "string" + } + ], + + "auxilary": { + "healthcheck": { + "interval": "60s", + "timeout": "20s", + "endpoint": "/", + "type": "http" + } + }, + + "artifacts": [{ + "type": "docker image", + "uri": "nginx" + }] +}
\ No newline at end of file diff --git a/mod/bpgenerator/TestCases/policyInput.json b/mod/bpgenerator/TestCases/policyInput.json new file mode 100644 index 0000000..fb89e1a --- /dev/null +++ b/mod/bpgenerator/TestCases/policyInput.json @@ -0,0 +1,28 @@ +{ + "policies": [ + { + "configAttributes": "", + "configName": "", + "onapName": "DCAE", + "policyName": "DCAE.Config_*", + "unique": false + }, + { + "onapName": "DCAE", + "policyName": "DCAE.Config_*", + "unique": true + }, + { + "configAttributes": "", + "configName": "", + "onapName": "DCAE", + "policyName": "DCAE.Config_*", + "unique": false + } + ], + "policy": [ + { + "policy_id" : "id_0" + } + ] +}
\ No newline at end of file diff --git a/mod/bpgenerator/TestCases/testComponentSpec.json b/mod/bpgenerator/TestCases/testComponentSpec.json new file mode 100644 index 0000000..d6b617b --- /dev/null +++ b/mod/bpgenerator/TestCases/testComponentSpec.json @@ -0,0 +1,116 @@ +{ + "self": { + "component_type": "docker", + "description": "Test component spec", + "name": "test.component.spec", + "version": "1.0.1" + }, + + "service": { + "calls": [], + "provides": [] + }, + + "streams": { + "publishes": [{ + "config_key": "TEST-PUB-DR", + "format": "dataformat_Hello_World_PM", + "type": "data_router", + "version": "1.0.0" + }, + { + "config_key": "TEST-PUB-MR", + "format": "dataformat_Hello_World_PM", + "type": "message_router", + "version": "1.0.0" + } + ], + + "subscribes": [{ + "config_key": "TEST-SUB-MR", + "format": "dataformat_Hello_World_PM", + "route": "/TEST_HELLO_WORLD_SUB_MR", + "type": "message_router", + "version": "1.0.0" + }, + { + "config_key": "TEST-SUB-DR", + "format": "dataformat_Hello_World_PM", + "route": "/TEST-HELLO-WORLD-SUB-DR", + "type": "data_router", + "version": "1.0.0" + } + ] + }, + + "parameters": + [ + { + "name": "testParam1", + "description": "test parameter 1", + "value": "test-param-1", + "type": "string", + "sourced_at_deployment": true, + "designer_editable": true, + "policy_editable": true, + "policy_group": "Test_Parameters", + "required": true, + "policy_schema": [ + { + "name": "PolicySchemaTest", + "description": "List of objects for vnf type monitorng", + "type": "String", + "entry_schema": [ + { + "name": "TestEntrySchema", + "description": "entry", + "type": "string", + "value": "None" + } + ] + } + ] + } + ], + + "auxilary": { + "healthcheck": { + "type": "docker", + "interval": "300s", + "timeout": "120s", + "script": "/etc/init.d/nagios status" + }, + + "databases" : { + "TestDB1": "PGaaS", + "TestDB2": "PGaaS" + }, + + "policy": { + "trigger_type": "docker", + "script_path": "/opt/app/manager/bin/reconfigure.sh" + }, + "volumes": [ + { + "container": { + "bind": "/opt/app/manager/config/hostname" + }, + "host": { + "path": "/etc/hostname", + "mode": "ro" + } + } + + ], + "ports": [ + "80:80", + "99:99" + ] + }, + + "artifacts": [{ + "type": "docker image", + "uri": "test.tester" + }] + +}
\ No newline at end of file diff --git a/mod/bpgenerator/TestCases/testImport.yaml b/mod/bpgenerator/TestCases/testImport.yaml new file mode 100644 index 0000000..a299baf --- /dev/null +++ b/mod/bpgenerator/TestCases/testImport.yaml @@ -0,0 +1,4 @@ +imports: +- test import 1 +- test import 2 +- test import 3
\ No newline at end of file diff --git a/mod/bpgenerator/TestCases/testImports.yaml b/mod/bpgenerator/TestCases/testImports.yaml new file mode 100644 index 0000000..2597e5e --- /dev/null +++ b/mod/bpgenerator/TestCases/testImports.yaml @@ -0,0 +1,3 @@ +imports: +- http://www.getcloudify.org/spec/cloudify/3.4/types.yaml +- https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.13/k8splugin_types.yaml
\ No newline at end of file diff --git a/mod/bpgenerator/TestCases/ves.json b/mod/bpgenerator/TestCases/ves.json new file mode 100644 index 0000000..eb54723 --- /dev/null +++ b/mod/bpgenerator/TestCases/ves.json @@ -0,0 +1,384 @@ +{ + "self": { + "version": "1.5.0", + "name": "dcae-ves-collector", + "description": "Collector for receiving VES events through restful interface", + "component_type": "docker" + }, + "streams": { + "subscribes": [], + "publishes": [ + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-fault" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-measurement" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-syslog" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-heartbeat" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-other" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-mobileflow" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-statechange" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-thresholdCrossingAlert" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-voicequality" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-sipsignaling" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-fault-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-measurement-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-syslog-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-heartbeat-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-other-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-mobileflow-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-statechange-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-thresholdCrossingAlert-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-voicequality-secondary" + }, + { + "format": "VES_specification", + "version": "5.28.4", + "type": "message router", + "config_key": "ves-sipsignaling-secondary" + }, + { + "format": "VES_specification", + "version": "7.30.0", + "type": "message router", + "config_key": "ves-pnfRegistration" + }, + { + "format": "VES_specification", + "version": "7.30.0", + "type": "message router", + "config_key": "ves-pnfRegistration-secondary" + }, + { + "format": "VES_specification", + "version": "7.30.0", + "type": "message router", + "config_key": "ves-notification" + }, + { + "format": "VES_specification", + "version": "7.30.0", + "type": "message router", + "config_key": "ves-notification-secondary" + } + ] + }, + "services": { + "calls": [], + "provides": [ + { + "route": "/eventListener/v1", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v2", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v3", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v4", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "4.27.2" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v5", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "5.28.4" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + }, + { + "route": "/eventListener/v7", + "verb": "POST", + "request": { + "format": "VES_specification", + "version": "7.30.0" + }, + "response": { + "format": "ves.coll.response", + "version": "1.0.0" + } + } + ] + }, + "parameters": [ + { + "name": "collector.service.port", + "value": 8080, + "description": "standard http port collector will open for listening;", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.service.secure.port", + "value": 8443, + "description": "secure http port collector will open for listening ", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": true + }, + { + "name": "collector.keystore.file.location", + "value": "/opt/app/dcae-certificate/keystore.jks", + "description": "fs location of keystore file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.keystore.passwordfile", + "value": "/opt/app/dcae-certificate/.password", + "description": "location of keystore password file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.truststore.file.location", + "value": "/opt/app/dcae-certificate/truststore.jks", + "description": "fs location of truststore file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.truststore.passwordfile", + "value": "/opt/app/dcae-certificate/.trustpassword", + "description": "location of truststore password file in vm", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.dmaap.streamid", + "value": "fault=ves-fault,ves-fault-secondary|syslog=ves-syslog,ves-syslog-secondary|heartbeat=ves-heartbeat,ves-heartbeat-secondary|measurementsForVfScaling=ves-measurement,ves-measurement-secondary|mobileFlow=ves-mobileflow,ves-mobileflow-secondary|other=ves-other,ves-other-secondary|stateChange=ves-statechange,ves-statechange-secondary|thresholdCrossingAlert=ves-thresholdCrossingAlert,ves-thresholdCrossingAlert-secondary|voiceQuality=ves-voicequality,ves-voicequality-secondary|sipSignaling=ves-sipsignaling,ves-sipsignaling-secondary|notification=ves-notification,ves-notification-secondary|pnfRegistration=ves-pnfRegistration,ves-pnfRegistration-secondary", + "description": "domain-to-streamid mapping used by VESCollector to distributes events based on domain. Both primary and secondary config_key are included for resilency (multiple streamid can be included commma separated). The streamids MUST match to topic config_keys. For single site without resiliency deployment - configkeys with -secondary suffix can be removed", + "sourced_at_deployment": true, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "auth.method", + "value": "noAuth", + "description": "Property to manage application mode, possible configurations: noAuth - default option - no security (http) , certOnly - auth by certificate (https), basicAuth - auth by basic auth username and password (https),certBasicAuth - auth by certificate and basic auth username / password (https),", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "header.authlist", + "value": "sample1,$2a$10$pgjaxDzSuc6XVFEeqvxQ5u90DKJnM/u7TJTcinAlFJVaavXMWf/Zi|userid1,$2a$10$61gNubgJJl9lh3nvQvY9X.x4e5ETWJJ7ao7ZhJEvmfJigov26Z6uq|userid2,$2a$10$G52y/3uhuhWAMy.bx9Se8uzWinmbJa.dlm1LW6bYPdPkkywLDPLiy", + "description": "List of id and base 64 encoded password.For each onboarding VNF - unique userid and password should be assigned and communicated to VNF owner. Password value should be base64 encoded in config here", + "policy_editable": false, + "sourced_at_deployment": true, + "designer_editable": true + }, + { + "name": "collector.schema.checkflag", + "value": 1, + "description": "Schema check validation flag. When enabled, collector will validate input VES events against VES Schema defined on collector.schema.file ", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "collector.schema.file", + "value": "{\"v1\":\"./etc/CommonEventFormat_27.2.json\",\"v2\":\"./etc/CommonEventFormat_27.2.json\",\"v3\":\"./etc/CommonEventFormat_27.2.json\",\"v4\":\"./etc/CommonEventFormat_27.2.json\",\"v5\":\"./etc/CommonEventFormat_28.4.1.json\",\"v7\":\"./etc/CommonEventFormat_30.json\"}", + "description": "VES schema file name per version used for validation", + "designer_editable": true, + "sourced_at_deployment": false, + "policy_editable": false + }, + { + "name": "event.transform.flag", + "value": 1, + "description": "flag to enable tranformation rules defined under eventTransform.json; this is applicable when event tranformation rules preset should be activated for transforming <VES5.4 events to 5.4", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + }, + { + "name": "tomcat.maxthreads", + "value": "200", + "description": "Tomcat control for concurrent request", + "sourced_at_deployment": false, + "policy_editable": false, + "designer_editable": false + } + ], + "auxilary": { + "healthcheck": { + "type": "https", + "interval": "15s", + "timeout": "1s", + "endpoint": "/healthcheck" + }, + "volumes": [ + { + "container": { + "bind": "/opt/app/dcae-certificate" + }, + "host": { + "path": "/opt/app/dcae-certificate" + } + }, + { + "container": { + "bind": "/opt/app/VESCollector/logs" + }, + "host": { + "path": "/opt/logs/DCAE/VESCollector/logs" + } + }, + { + "container": { + "bind": "/opt/app/VESCollector/etc" + }, + "host": { + "path": "/opt/logs/DCAE/VESCollector/etc" + } + } + ], + "ports": [ + "8080:8080", + "8443:8443" + ] + }, + "artifacts": [ + { + "type": "docker image", + "uri": "nexus.onap.org:10001/onap/org.onap.dcaegen2.collectors.ves.vescollector:latest" + } + ] +}
\ No newline at end of file diff --git a/mod/bpgenerator/pom.xml b/mod/bpgenerator/pom.xml new file mode 100644 index 0000000..d63b9c9 --- /dev/null +++ b/mod/bpgenerator/pom.xml @@ -0,0 +1,212 @@ +<!-- +============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.oparent</groupId> + <artifactId>oparent</artifactId> + <version>2.0.0</version> + </parent> + <groupId>org.onap.dcaegen2.platform.mod</groupId> + <artifactId>blueprint-generator</artifactId> + <version>1.2.1-SNAPSHOT</version> + <properties> + <maven.compiler.source>1.6</maven.compiler.source> + <maven.compiler.target>1.6</maven.compiler.target> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <sonar.core.codeCoveragePlugin>cobertura</sonar.core.codeCoveragePlugin> + <sonar.java.coveragePlugin>cobertura</sonar.java.coveragePlugin> + <sonar.junit.reportsPath>${project.basedir}/target/surefire-reports</sonar.junit.reportsPath> + <sonar.surefire.reportsPath>${project.basedir}/target/surefire-reports</sonar.surefire.reportsPath> + <sonar.cobertura.reportPath>${project.basedir}/target/site/cobertura/coverage.xml</sonar.cobertura.reportPath> + <shade.main>org.onap.blueprintgenerator.core.App</shade.main> + <shade.transformer>org.apache.maven.plugins.shade.resource.ManifestResourceTransformer</shade.transformer> + </properties> + + <build> + <plugins> + <!-- the following plugins are invoked from oparent, we do not need them --> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.4.1</version> + <configuration> + <descriptors> + <descriptor>src/assembly/dep.xml</descriptor> + </descriptors> + </configuration> + + <executions> + <execution> + + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + <version>2.7</version> + <configuration> + <instrumentation> + <includes> + <include>**/*.class</include> + </includes> + </instrumentation> + <encoding>UTF-8</encoding> + </configuration> + + <executions> + + <execution> + <id>clean</id> + <!-- > <phase>pre-site</phase> --> + <phase>pre-site</phase> + <goals> + <goal>cobertura</goal> + </goals> + </execution> + + + <execution> + <id>instrument</id> + <phase>site</phase> + <goals> + <goal>instrument</goal> + <goal>cobertura</goal> + </goals> + <configuration> + <encoding>UTF-8</encoding> + </configuration> + </execution> + + </executions> + + </plugin> + + <plugin> + <groupId>org.sonarsource.scanner.maven</groupId> + <artifactId>sonar-maven-plugin</artifactId> + <version>3.0.2</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.2.1</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <shadedArtifactAttached>true</shadedArtifactAttached> + <shadedClassifierName>executable</shadedClassifierName> + <transformers> + <transformer + implementation="${shade.transformer}"> + <mainClass>${shade.main}</mainClass> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>8</source> + <target>8</target> + </configuration> + </plugin> + </plugins> + + </build> + + <reporting> + <plugins> + <plugin> + <!-- use mvn cobertura:cobertura to generate cobertura reports --> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + <version>2.7</version> + <configuration> + <formats> + <format>xml</format> + </formats> + </configuration> + </plugin> + </plugins> + </reporting> + + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>3.1.0</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>info.picocli</groupId> + <artifactId>picocli</artifactId> + <version>3.9.6</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.2</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-yaml</artifactId> + <version>2.9.8</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>2.9.8</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-annotations</artifactId> + <version>2.9.8</version> + </dependency> + </dependencies> + +</project> diff --git a/mod/bpgenerator/src/assembly/dep.xml b/mod/bpgenerator/src/assembly/dep.xml new file mode 100644 index 0000000..daf6771 --- /dev/null +++ b/mod/bpgenerator/src/assembly/dep.xml @@ -0,0 +1,52 @@ +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + <id>bundle</id> + <formats> + <format>tar.gz</format> + </formats> + <files> + <file> + <source>target/${project.artifactId}-${project.version}.jar</source> + <outputDirectory>lib</outputDirectory> + </file> + </files> + <fileSets> +<!-- + <fileSet> + <directory>src/main/scripts</directory> + <outputDirectory>bin</outputDirectory> + <includes> + <include>**/*.sh</include> + </includes> + <fileMode>0755</fileMode> + </fileSet> + <fileSet> + <directory>etc</directory> + <outputDirectory>conf</outputDirectory> + </fileSet> +--> + <fileSet> + <!-- src/main/scripts may be a better choice because src/main/resources is packaged by maven into the jar --> + <directory>src/main/resources/bin</directory> + <outputDirectory>bin</outputDirectory> + <includes> + <include>**/*.*</include> + </includes> + <fileMode>0755</fileMode> + </fileSet> + <fileSet> + <directory>src/main/resources/conf</directory> + <outputDirectory>conf</outputDirectory> + </fileSet> + + </fileSets> + <dependencySets> + <dependencySet> + <includes> + <include>*:jar</include> + </includes> + <outputDirectory>lib</outputDirectory> + </dependencySet> + </dependencySets> +</assembly> diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/App.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/App.java new file mode 100644 index 0000000..4775825 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/App.java @@ -0,0 +1,40 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + + +package org.onap.blueprintgenerator.core; + +import picocli.CommandLine; +import picocli.CommandLine.Command; + +@Command(subcommands = { + BlueprintCommand.class, + PolicyCommand.class +}) +public class App implements Runnable { + public static void main(String...args) { + CommandLine.run(new App(), args); + } + + @Override + public void run() { + CommandLine.usage(this, System.out); + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java new file mode 100644 index 0000000..7627930 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.core; + +import org.onap.blueprintgenerator.models.blueprint.Blueprint; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command(name = "blueprint", description = "Command used to generate blueprints from component spec") +public class BlueprintCommand implements Runnable { + private static final char STANDARD_BLUEPRINT = 'o'; + private static final char DMAAP_BLUEPRINT = 'd'; + + @Option(names = {"-i", "--component-spec"}, description = "Path to component spec file", required = true) + private String componentSpecPath; + + @Option(names = {"-p", "--blueprint-path"}, description = "Path to directory that blueprints are output to", required = true) + private String blueprintOutputPath; + + @Option(names = {"-n", "--blueprint-name"}, description = "Name of the blueprint", defaultValue = "") + private String blueprintName; + + @Option(names = {"-t", "--imports"}, description = "Path to the import file", defaultValue = "") + private String importsPath; + + @Option(names={"-o", "--service-name-override"}, description="Value used to override the service name", defaultValue = "") + private String serviceNameOverride; + + @Option(names={"-d", "--dmaap-plugin"}, description = "Flag used to indicate blueprint uses the DMaaP plugin.") + private boolean dmaapPlugin; + + @Override + public void run() { + ComponentSpec inboundComponentSpec = new ComponentSpec(); + inboundComponentSpec.createComponentSpecFromFile(componentSpecPath); + System.out.println(dmaapPlugin ? DMAAP_BLUEPRINT : STANDARD_BLUEPRINT); + Blueprint generatedBlueprint = new Blueprint().createBlueprint(inboundComponentSpec, this.blueprintName, + dmaapPlugin ? DMAAP_BLUEPRINT : STANDARD_BLUEPRINT, importsPath, serviceNameOverride); + generatedBlueprint.blueprintToYaml(blueprintOutputPath, this.blueprintName, inboundComponentSpec); + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/Fixes.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/Fixes.java new file mode 100644 index 0000000..cbff42b --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/Fixes.java @@ -0,0 +1,70 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + +*/ + +package org.onap.blueprintgenerator.core; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +public class Fixes { + private static ArrayList<String> lines = new ArrayList<String>(); + private static String line = null; + + public static void fixSingleQuotes(File f) throws IOException { + File translateFile = f; + try { + FileReader fr = new FileReader(translateFile); + BufferedReader br = new BufferedReader(fr); + while((line = br.readLine()) != null) { + if(line.contains("'")) { + line = line.replace("'", ""); + } + if(line.contains("\"\"") && (line.contains("m") || line.contains("M"))) { + line = line.replaceAll("\"\"", "\""); + } + lines.add(line); + + } + fr.close(); + br.close(); + FileWriter fw = new FileWriter(translateFile); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f, true))); + for(String s: lines) { + out.println(); + out.write(s); + out.flush(); + } + + out.close(); + fw.close(); + line = null; + lines = new ArrayList<String>(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java new file mode 100644 index 0000000..81a7911 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.core; + +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.policymodel.PolicyModel; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command(name = "policy", description = "Command used to generate policy model from component spec") +public class PolicyCommand implements Runnable{ + @Option(names = {"-i", "--component-spec"}, description = "Path to component spec file", required = true) + private String componentSpecPath; + + @Option(names = {"-p", "--model-path"}, description = "Path to directory that models are output to", required = true) + private String modelOutputPath; + + @Override + public void run() { + ComponentSpec inboundComponentSpec = new ComponentSpec(); + inboundComponentSpec.createComponentSpecFromFile(componentSpecPath); + new PolicyModel().createPolicyModels(inboundComponentSpec, this.modelOutputPath); + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/TestComponentSpec.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/TestComponentSpec.java new file mode 100644 index 0000000..5d4131b --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/core/TestComponentSpec.java @@ -0,0 +1,132 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + +*/ + + +package org.onap.blueprintgenerator.core; + + + + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class TestComponentSpec { + private String cs = "{\r\n" + + " \"self\": {\r\n" + + " \"component_type\": \"docker\",\r\n" + + " \"description\": \"Test component spec\",\r\n" + + " \"name\": \"test.component.spec\",\r\n" + + " \"version\": \"1.0.1\"\r\n" + + " },\r\n" + + "\r\n" + + " \"service\": {\r\n" + + " \"calls\": [],\r\n" + + " \"provides\": []\r\n" + + " },\r\n" + + "\r\n" + + " \"streams\": {\r\n" + + " \"publishes\": [{\r\n" + + " \"config_key\": \"TEST-PUB-DR\",\r\n" + + " \"format\": \"dataformat_Hello_World_PM\",\r\n" + + " \"type\": \"data_router\",\r\n" + + " \"version\": \"1.0.0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"config_key\": \"TEST-PUB-MR\",\r\n" + + " \"format\": \"dataformat_Hello_World_PM\",\r\n" + + " \"type\": \"message_router\",\r\n" + + " \"version\": \"1.0.0\"\r\n" + + " }\r\n" + + " ],\r\n" + + "\r\n" + + " \"subscribes\": [{\r\n" + + " \"config_key\": \"TEST-SUB-MR\",\r\n" + + " \"format\": \"dataformat_Hello_World_PM\",\r\n" + + " \"route\": \"/TEST_HELLO_WORLD_SUB_MR\",\r\n" + + " \"type\": \"message_router\",\r\n" + + " \"version\": \"1.0.0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"config_key\": \"TEST-SUB-DR\",\r\n" + + " \"format\": \"dataformat_Hello_World_PM\",\r\n" + + " \"route\": \"/TEST-HELLO-WORLD-SUB-DR\",\r\n" + + " \"type\": \"data_router\",\r\n" + + " \"version\": \"1.0.0\"\r\n" + + " } \r\n" + + " ]\r\n" + + " },\r\n" + + "\r\n" + + " \"parameters\":\r\n" + + " [\r\n" + + " {\r\n" + + " \"name\": \"testParam1\",\r\n" + + " \"description\": \"test parameter 1\",\r\n" + + " \"value\": \"test-param-1\",\r\n" + + " \"type\": \"string\",\r\n" + + " \"sourced_at_deployment\": true,\r\n" + + " \"designer_editable\": true,\r\n" + + " \"policy_editable\": true,\r\n" + + " \"policy_group\": \"Test_Parameters\",\r\n" + + " \"required\": true\r\n" + + " }\r\n" + + " ],\r\n" + + "\r\n" + + " \"auxilary\": {\r\n" + + " \"healthcheck\": {\r\n" + + " \"type\": \"docker\",\r\n" + + " \"interval\": \"300s\",\r\n" + + " \"timeout\": \"120s\",\r\n" + + " \"script\": \"/etc/init.d/nagios status\"\r\n" + + " },\r\n" + + "\r\n" + + " \"databases\" : {\r\n" + + " \"TestDB1\": \"PGaaS\",\r\n" + + " \"TestDB2\": \"PGaaS\"\r\n" + + " },\r\n" + + "\r\n" + + " \"policy\": {\r\n" + + " \"trigger_type\": \"docker\",\r\n" + + " \"script_path\": \"/opt/app/manager/bin/reconfigure.sh\"\r\n" + + " },\r\n" + + " \"volumes\": [\r\n" + + " {\r\n" + + " \"container\": {\r\n" + + " \"bind\": \"/opt/app/manager/config/hostname\"\r\n" + + " },\r\n" + + " \"host\": {\r\n" + + " \"path\": \"/etc/hostname\",\r\n" + + " \"mode\": \"ro\"\r\n" + + " }\r\n" + + " }\r\n" + + "\r\n" + + " ],\r\n" + + " \"ports\": [\r\n" + + " \"80:80\"\r\n" + + " ]\r\n" + + " },\r\n" + + "\r\n" + + " \"artifacts\": [{\r\n" + + " \"type\": \"docker image\",\r\n" + + " \"uri\": \"test.tester\"\r\n" + + " }] \r\n" + + "\r\n" + + "}"; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java new file mode 100644 index 0000000..6d5b7d7 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Appconfig.java @@ -0,0 +1,156 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.componentspec.CallsObj; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.Parameters; +import org.onap.blueprintgenerator.models.componentspec.Publishes; +import org.onap.blueprintgenerator.models.componentspec.Subscribes; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; + + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Appconfig { + private CallsObj[] service_calls; + private TreeMap<String, DmaapObj> streams_publishes; + private TreeMap<String, DmaapObj> streams_subscribes; + private TreeMap<String, Object> params; + + @JsonAnyGetter + public TreeMap<String, Object> getParams(){ + return params; + } + + public TreeMap<String, LinkedHashMap<String, Object>> createAppconfig(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + + //set service calls + CallsObj[] call = new CallsObj[0]; + this.setService_calls(call); + + //set the stream publishes + TreeMap<String, DmaapObj> streamPublishes = new TreeMap<String, DmaapObj>(); + int counter = 0; + if(cs.getStreams().getPublishes().length != 0) { + for(Publishes p: cs.getStreams().getPublishes()) { + if(p.getType().equals("data_router") || p.getType().equals("data router")) { + //in this case the data router information gets added to the params so for now leave it alone + String config = p.getConfig_key(); + DmaapObj pub = new DmaapObj(); + String name = "feed" + counter; + retInputs = pub.createOnapDmaapDRObj(retInputs, config, 'p', "feed" + counter, name); + pub.setType(p.getType()); + streamPublishes.put(config, pub); + } else if(p.getType().equals("message_router") || p.getType().equals("message router")) { + String config = p.getConfig_key(); + DmaapObj pub = new DmaapObj(); + String name = "topic" + counter; + retInputs = pub.createOnapDmaapMRObj(retInputs, config, 'p', "topic" + counter, name); + pub.setType(p.getType()); + streamPublishes.put(config, pub); + } + counter++; + } + } + + //set the stream publishes + TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<String, DmaapObj>(); + + if(cs.getStreams().getSubscribes().length != 0) { + for(Subscribes s: cs.getStreams().getSubscribes()) { + if(s.getType().equals("data_router") || s.getType().equals("data router")) { + //in this case the data router information gets added to the params so for now leave it alone + String config = s.getConfig_key(); + DmaapObj sub = new DmaapObj(); + String name = "feed" + counter; + retInputs = sub.createOnapDmaapDRObj(retInputs, config, 'p', "feed" + counter, name); + sub.setType(s.getType()); + streamSubscribes.put(config, sub); + } else if(s.getType().equals("message_router") || s.getType().equals("message router")) { + String config = s.getConfig_key(); + DmaapObj sub = new DmaapObj(); + String name = "topic" + counter; + retInputs = sub.createOnapDmaapMRObj(retInputs, config, 's', "topic" + counter, name); + sub.setType(s.getType()); + streamSubscribes.put(config, sub); + } + counter++; + } + } + + this.setStreams_publishes(streamPublishes); + this.setStreams_subscribes(streamSubscribes); + + //set the parameters into the appconfig + TreeMap<String, Object> parameters = new TreeMap<String, Object>(); + for(Parameters p: cs.getParameters()) { + String pName = p.getName(); + if(p.isSourced_at_deployment()) { + GetInput paramInput = new GetInput(); + paramInput.setGet_input(pName); + parameters.put(pName, paramInput); + + if(!p.getValue().equals("")) { + LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>(); + inputs.put("type", "string"); + inputs.put("default", p.getValue()); + retInputs.put(pName, inputs); + } else { + LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>(); + inputs.put("type", "string"); + retInputs.put(pName, inputs); + } + } else { + if(p.getType() == "string") { + String val =(String) p.getValue(); + val = '"' + val + '"'; + parameters.put(pName, val); + } + else { + parameters.put(pName, p.getValue()); + } + } + } + if(override != null) { + GetInput ov = new GetInput(); + ov.setGet_input("service_component_name_override"); + parameters.put("service_component_name_override", ov); + LinkedHashMap<String, Object> over = new LinkedHashMap<String, Object>(); + over.put("type", "string"); + over.put("default", override); + retInputs.put("service_component_name_override", over); + } + this.setParams(parameters); + return retInputs; + } + + +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java new file mode 100644 index 0000000..06c42c5 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Blueprint.java @@ -0,0 +1,211 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; +import java.util.regex.Pattern; + +import org.onap.blueprintgenerator.core.Fixes; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.Parameters; +import org.onap.blueprintgenerator.models.componentspec.Publishes; +import org.onap.blueprintgenerator.models.componentspec.Subscribes; +import org.onap.blueprintgenerator.models.dmaapbp.DmaapBlueprint; +import org.onap.blueprintgenerator.models.onapbp.OnapBlueprint; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; +//import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + + +@Getter @Setter +@JsonInclude(JsonInclude.Include.NON_NULL) + +public class Blueprint { + + + private String tosca_definitions_version; + + private String description; + + private ArrayList<String> imports; + + private TreeMap<String, LinkedHashMap<String, Object>> inputs; + + private TreeMap<String, Node> node_templates; + + public Blueprint createBlueprint(ComponentSpec cs, String name, char bpType, String importPath, String override) { + Blueprint bp = new Blueprint(); + if(bpType == 'o') { + OnapBlueprint onap = new OnapBlueprint(); + bp = onap.createOnapBlueprint(cs, importPath, override); + bp = bp.setQuotations(bp); + } + + if(bpType == 'd') { + DmaapBlueprint dmaap = new DmaapBlueprint(); + bp = dmaap.createDmaapBlueprint(cs, importPath, override); + bp = bp.setQuotations(bp); + } + return bp; + } + public Blueprint setQuotations(Blueprint bp) { + for(String s: bp.getInputs().keySet()) { + LinkedHashMap<String, Object> temp = bp.getInputs().get(s); + if(temp.get("type") == "string") { + String def = (String) temp.get("default"); + def = '"' + def + '"'; + temp.replace("default", def); + bp.getInputs().replace(s, temp); + } + } + + return bp; + } + + public void blueprintToYaml(String outputPath, String bluePrintName, ComponentSpec cs) { + File outputFile; + + if(bluePrintName.equals("")) { + String name = cs.getSelf().getName(); + if(name.contains(".")) { + name = name.replaceAll(Pattern.quote("."), "_"); + } + if(name.contains(" ")) { + name = name.replaceAll(" ", ""); + } + String file = name + ".yaml"; + + + outputFile = new File(outputPath, file); + outputFile.getParentFile().mkdirs(); + try { + outputFile.createNewFile(); + } catch (IOException e) { + + throw new RuntimeException(e); + } + } else { + if(bluePrintName.contains(" ") || bluePrintName.contains(".")) { + bluePrintName = bluePrintName.replaceAll(Pattern.quote("."), "_"); + bluePrintName = bluePrintName.replaceAll(" ", ""); + } + String file = bluePrintName + ".yaml"; + outputFile = new File(outputPath, file); + outputFile.getParentFile().mkdirs(); + try { + outputFile.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + String version = "#blueprint_version: " + cs.getSelf().getVersion() + '\n'; + String description = "#description: " + cs.getSelf().getDescription() + '\n'; + + BufferedWriter writer = null; + try { + writer = new BufferedWriter(new FileWriter(outputFile, false)); + } catch (IOException e1) { + throw new RuntimeException(e1); + } + if(writer != null) { + try { + writer.write(description); + } catch (IOException e) { + throw new RuntimeException(e); + } + try { + writer.write(version); + } catch (IOException e) { + throw new RuntimeException(e); + } + try { + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + + //read the translated blueprint into the file + ObjectMapper blueprintMapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); + + PrintWriter out = null; + try { + out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true))); + } catch (IOException e) { + throw new RuntimeException(e); + } + + try { + if(out != null) { + blueprintMapper.writeValue(out, this); + out.close(); + } + } catch (IOException e) { + + throw new RuntimeException(e); + } + + + Fixes fix = new Fixes(); + try { + fix.fixSingleQuotes(outputFile); + } catch (IOException e) { + throw new RuntimeException(e); + } + + System.out.println("Blueprint created"); + } + + + public String blueprintToString() { + String ret = ""; + + ObjectMapper blueprintMapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); + try { + ret = blueprintMapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + + return ret; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ConcatObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ConcatObj.java new file mode 100644 index 0000000..edc257c --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ConcatObj.java @@ -0,0 +1,57 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.ArrayList; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonRawValue; + +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/** + * The Class ConcatObj. + */ +@JsonIgnoreProperties(ignoreUnknown = true) + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter +//@Builder + +/** + * Instantiates a new concat obj. + */ +@NoArgsConstructor +@JsonInclude(value=Include.NON_NULL) + +public class ConcatObj { + + /** The concat. */ + private ArrayList<Object> concat; +} + diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapInfo.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapInfo.java new file mode 100644 index 0000000..97dafc7 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapInfo.java @@ -0,0 +1,99 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.Getter; import lombok.Setter; + +@Getter @Setter +@JsonInclude(value=Include.NON_NULL) +public class DmaapInfo { + private GetInput topic_url; + private GetInput username; + private GetInput password; + private GetInput location; + private GetInput delivery_url; + private GetInput subscriber_id; + + public TreeMap<String, LinkedHashMap<String, Object>> createOnapDmaapMRInfo(TreeMap<String, LinkedHashMap<String, Object>> inps, String config, char type) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + LinkedHashMap<String, Object> stringType = new LinkedHashMap<String, Object>(); + stringType.put("type", "string"); + + config = config.replaceAll("-", "_"); + if(type == 'p') { + config = config + "_publish_url"; + } + else if(type == 's') { + config = config+ "_subscribe_url"; + } + + GetInput topic = new GetInput(); + topic.setGet_input(config); + this.setTopic_url(topic); + + retInputs.put(config, stringType); + + return retInputs; + } + + public TreeMap<String, LinkedHashMap<String, Object>> createOnapDmaapDRInfo(TreeMap<String, LinkedHashMap<String, Object>> inps, String config, char type) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + LinkedHashMap<String, Object> stringType = new LinkedHashMap<String, Object>(); + stringType.put("type", "string"); + + GetInput username = new GetInput(); + username.setGet_input(config + "_" + "username"); + this.setUsername(username); + retInputs.put(config + "_" + "username", stringType); + + GetInput password = new GetInput(); + password.setGet_input(config + "_" + "password"); + this.setPassword(password); + retInputs.put(config + "_" + "password", stringType); + + GetInput location = new GetInput(); + location.setGet_input(config + "_" + "location"); + this.setLocation(location); + retInputs.put(config + "_" + "location", stringType); + + GetInput deliveryUrl = new GetInput(); + deliveryUrl.setGet_input(config + "_" + "delivery_url"); + this.setDelivery_url(deliveryUrl); + retInputs.put(config + "_" + "delivery_url", stringType); + + GetInput subscriberID = new GetInput(); + subscriberID.setGet_input(config + "_" + "subscriber_id"); + this.setSubscriber_id(subscriberID); + retInputs.put(config + "_" + "subscriber_id", stringType); + + + return retInputs; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapObj.java new file mode 100644 index 0000000..10092c8 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/DmaapObj.java @@ -0,0 +1,75 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.Getter; import lombok.Setter; +@JsonInclude(value=Include.NON_NULL) +@Getter @Setter +public class DmaapObj { + private String dmaap_info; + private String type; + private GetInput pass; + private GetInput user; + + public TreeMap<String, LinkedHashMap<String, Object>> createOnapDmaapMRObj(TreeMap<String, LinkedHashMap<String, Object>> inps, String config, char type, String n, String num) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + LinkedHashMap<String, Object> stringType = new LinkedHashMap(); + stringType.put("type", "string"); + retInputs = inps; + + //set the dmaapinfo + DmaapInfo info = new DmaapInfo(); + String infoType = "<<" + n + ">>"; + this.setDmaap_info(infoType); + + //set username + GetInput u = new GetInput(); + u.setGet_input(config + "_" + num +"_aaf_username"); + this.setUser(u); + retInputs.put(config + "_" + num +"_aaf_username", stringType); + + //set password + GetInput p = new GetInput(); + p.setGet_input(config + "_" + num +"_aaf_password"); + this.setPass(p); + retInputs.put(config + "_" + num +"_aaf_password", stringType); + + return retInputs; + } + public TreeMap<String, LinkedHashMap<String, Object>> createOnapDmaapDRObj(TreeMap<String, LinkedHashMap<String, Object>> inps, String config, char type, String n, String num) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + + //set the dmaapinfo + DmaapInfo info = new DmaapInfo(); + String infoType = "<<" + n + ">>"; + this.setDmaap_info(infoType); + return retInputs; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/GetInput.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/GetInput.java new file mode 100644 index 0000000..e7980c8 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/GetInput.java @@ -0,0 +1,29 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import lombok.Getter; import lombok.Setter; + +@Getter @Setter +public class GetInput { + + private Object get_input; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/GetProperty.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/GetProperty.java new file mode 100644 index 0000000..1f9bf1c --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/GetProperty.java @@ -0,0 +1,55 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.ArrayList; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/** + * The Class GetProperty. + */ +@JsonIgnoreProperties(ignoreUnknown = true) + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter +//@Builder + +/** + * Instantiates a new gets the property. + */ +@NoArgsConstructor +@JsonInclude(value=Include.NON_NULL) + +public class GetProperty { + + /** The get property. */ + private ArrayList<String> get_property; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Imports.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Imports.java new file mode 100644 index 0000000..8bcdbbc --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Imports.java @@ -0,0 +1,77 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + +*/ + +package org.onap.blueprintgenerator.models.blueprint; + + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; +import lombok.AllArgsConstructor; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + + + +@Getter @Setter +@JsonInclude(value=Include.NON_NULL) +public class Imports { + /** The imports. */ + private ArrayList<String> imports; + + public static ArrayList<String> createOnapImports() { + ArrayList<String> imps = new ArrayList<String>(); + imps.add("http://www.getcloudify.org/spec/cloudify/3.4/types.yaml"); + imps.add("https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.5/k8splugin_types.yaml"); + imps.add("https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/dcaepolicyplugin/2.3.0/dcaepolicyplugin_types.yaml"); + return imps; + } + public static ArrayList<String> createDmaapImports(){ + ArrayList<String> imps = new ArrayList<String>(); + imps.add("http://www.getcloudify.org/spec/cloudify/3.4/types.yaml"); + imps.add("https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R5/k8splugin/1.6.0/k8splugin_types.yaml"); + imps.add("https://nexus.onap.org/service/local/repositories/raw/content/org.onap.ccsdk.platform.plugins/type_files/dmaap/dmaap.yaml"); + return imps; + } + public static ArrayList<String> createImportsFromFile(String path) { + Imports imports = new Imports(); + ObjectMapper importMapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); + File importPath = new File(path); + try { + imports = importMapper.readValue(importPath, Imports.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + ArrayList<String> imps = new ArrayList<String>(); + for(String s: imports.getImports()) { + imps.add(s); + } + return imps; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Interfaces.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Interfaces.java new file mode 100644 index 0000000..a3404f6 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Interfaces.java @@ -0,0 +1,42 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +import lombok.Getter; import lombok.Setter; + +@Getter @Setter +public class Interfaces { + private Start start; + public TreeMap<String, LinkedHashMap<String, Object>> createInterface(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs){ + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + //create the start object + Start start = new Start(); + retInputs = start.createOnapStart(retInputs, cs); + this.setStart(start); + return retInputs; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Node.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Node.java new file mode 100644 index 0000000..bac795f --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Node.java @@ -0,0 +1,28 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import lombok.Getter; import lombok.Setter; + +@Getter @Setter +public class Node { + private String type; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java new file mode 100644 index 0000000..25c4c53 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java @@ -0,0 +1,282 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.componentspec.Auxilary; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.HealthCheck; +import org.onap.blueprintgenerator.models.componentspec.Publishes; +import org.onap.blueprintgenerator.models.componentspec.Subscribes; +import org.onap.blueprintgenerator.models.componentspec.Volumes; +import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams; +import org.onap.blueprintgenerator.models.onapbp.LogDirectory; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.Getter; import lombok.Setter; + +@Getter @Setter +@JsonInclude(value=Include.NON_NULL) +public class Properties { + private Appconfig application_config; + private Auxilary docker_config; + private Object image; + private GetInput location_id; + private String service_component_type; + private TreeMap<String, Object> log_info; + private String dns_name; + private Object replicas; + private String name; + private GetInput topic_name; + private GetInput feed_name; + ArrayList<DmaapStreams> streams_publishes; + ArrayList<DmaapStreams> streams_subscribes; + private TreeMap<String, Object> tls_info; + private ResourceConfig resource_config; + //private boolean useExisting; + + public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + + //set the image + GetInput image = new GetInput(); + image.setGet_input("image"); + this.setImage(image); + LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>(); + img.put("type", "string"); + img.put("default", cs.getArtifacts()[0].getUri()); + retInputs.put("image", img); + + //set the location id + GetInput location = new GetInput(); + location.setGet_input("location_id"); + this.setLocation_id(location); + LinkedHashMap<String, Object> locMap = new LinkedHashMap(); + locMap.put("type", "string"); + locMap.put("default", "central"); + + //set the log info + GetInput logD = new GetInput(); + logD.setGet_input("log_directory"); + TreeMap<String, Object> l = new TreeMap(); + l.put("log_directory", logD); + this.setLog_info(l); + LinkedHashMap<String, Object> logMap = new LinkedHashMap(); + logMap.put("type", "string"); + logMap.put("default", "''"); + retInputs.put("log_directory", logMap); + + //set the replicas + GetInput replica = new GetInput(); + replica.setGet_input("replicas"); + this.setReplicas(replica); + LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>(); + rep.put("type", "integer"); + rep.put("description", "number of instances"); + rep.put("default", 1); + retInputs.put("replicas", rep); + + //set the dns name + this.setDns_name(cs.getSelf().getName()); + + //set the name + this.setName(cs.getSelf().getName()); + + //set the docker config + Auxilary aux = cs.getAuxilary(); + if(aux.getPorts() != null) { + retInputs = aux.createPorts(retInputs); + } + this.setDocker_config(aux); + + //set the app config + Appconfig app = new Appconfig(); + retInputs = app.createAppconfig(retInputs, cs, override); + this.setApplication_config(app); + + //set the tls info + GetInput tls = new GetInput(); + tls.setGet_input("use_tls"); + GetInput cert = new GetInput(); + cert.setGet_input("cert_directory"); + TreeMap<String, Object> tlsInfo = new TreeMap(); + tlsInfo.put("cert_directory", cert); + tlsInfo.put("use_tls", tls); + this.setTls_info(tlsInfo); + + LinkedHashMap<String, Object> certMap = new LinkedHashMap(); + certMap.put("type", "string"); + certMap.put("default", "''"); + retInputs.put("cert_directory", certMap); + + LinkedHashMap<String, Object> useMap = new LinkedHashMap(); + useMap.put("type", "boolean"); + useMap.put("default", false); + retInputs.put("use_tls", useMap); + + //set the reource config + ResourceConfig resource = new ResourceConfig(); + retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName()); + this.setResource_config(resource); + + return retInputs; + } + + public TreeMap<String, LinkedHashMap<String, Object>> createDmaapProperties(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + + //set the image + GetInput image = new GetInput(); + image.setGet_input("tag_version"); + this.setImage(image); + LinkedHashMap<String, Object> img = new LinkedHashMap<String, Object>(); + img.put("type", "string"); + img.put("default", cs.getArtifacts()[0].getUri()); + retInputs.put("tag_version", img); + + //set the log info + GetInput logD = new GetInput(); + logD.setGet_input("log_directory"); + TreeMap<String, Object> l = new TreeMap(); + l.put("log_directory", logD); + this.setLog_info(l); + LinkedHashMap<String, Object> logMap = new LinkedHashMap(); + logMap.put("type", "string"); + logMap.put("default", "''"); + retInputs.put("log_directory", logMap); + + //set service component type + String sType = cs.getSelf().getName(); + sType = sType.replace('.', '-'); + this.setService_component_type(sType); + + //set the tls info + GetInput tls = new GetInput(); + tls.setGet_input("use_tls"); + GetInput cert = new GetInput(); + cert.setGet_input("cert_directory"); + TreeMap<String, Object> tlsInfo = new TreeMap(); + tlsInfo.put("cert_directory", cert); + tlsInfo.put("use_tls", tls); + this.setTls_info(tlsInfo); + + LinkedHashMap<String, Object> certMap = new LinkedHashMap(); + certMap.put("type", "string"); + certMap.put("default", "''"); + retInputs.put("cert_directory", certMap); + + LinkedHashMap<String, Object> useMap = new LinkedHashMap(); + useMap.put("type", "boolean"); + useMap.put("default", false); + retInputs.put("use_tls", useMap); + + //set the replicas + GetInput replica = new GetInput(); + replica.setGet_input("replicas"); + this.setReplicas(replica); + LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>(); + rep.put("type", "integer"); + rep.put("description", "number of instances"); + rep.put("default", 1); + retInputs.put("replicas", rep); + +// //set the dns name +// this.setDns_name(cs.getSelf().getName()); + +// //set the name +// this.setName(cs.getSelf().getName()); + + //set the docker config + Auxilary aux = cs.getAuxilary(); + if(aux.getPorts() != null) { + retInputs = aux.createPorts(retInputs); + } + this.setDocker_config(aux); + + //set the appconfig + Appconfig app = new Appconfig(); + retInputs = app.createAppconfig(retInputs, cs, override); + this.setApplication_config(app); + + //set the stream publishes + ArrayList<DmaapStreams> pubStreams = new ArrayList(); + int counter = 0; + if(cs.getStreams().getPublishes() != null) { + for(Publishes p: cs.getStreams().getPublishes()) { + if(p.getType().equals("message_router") || p.getType().equals("message router")) { + String topic = "topic" + counter; + DmaapStreams mrStreams = new DmaapStreams(); + retInputs = mrStreams.createStreams(inps, cs, topic, p.getType(), p.getConfig_key(), p.getRoute(), 'p'); + pubStreams.add(mrStreams); + } + else if(p.getType().equals("data_router") || p.getType().equals("data router")){ + String feed = "feed" + counter; + DmaapStreams drStreams = new DmaapStreams(); + retInputs = drStreams.createStreams(inps, cs, feed, p.getType(), p.getConfig_key(), p.getRoute(), 'p'); + pubStreams.add(drStreams); + } + counter++; + } + } + + //set the stream subscribes + ArrayList<DmaapStreams> subStreams = new ArrayList(); + if(cs.getStreams().getSubscribes() != null) { + for(Subscribes s: cs.getStreams().getSubscribes()) { + if(s.getType().equals("message_router") || s.getType().equals("message router")) { + String topic = "topic" + counter; + DmaapStreams mrStreams = new DmaapStreams(); + retInputs = mrStreams.createStreams(inps, cs, topic, s.getType(), s.getConfig_key(), s.getRoute(), 's'); + subStreams.add(mrStreams); + } + else if(s.getType().equals("data_router") || s.getType().equals("data router")){ + String feed = "feed" + counter; + DmaapStreams drStreams = new DmaapStreams(); + retInputs = drStreams.createStreams(inps, cs, feed, s.getType(), s.getConfig_key(), s.getRoute(), 's'); + subStreams.add(drStreams); + } + counter++; + } + } + + if(pubStreams.size() != 0) { + this.setStreams_publishes(pubStreams); + } + if(subStreams.size() != 0) { + this.setStreams_subscribes(subStreams); + } + + //set the reource config + ResourceConfig resource = new ResourceConfig(); + retInputs = resource.createResourceConfig(retInputs, cs.getSelf().getName()); + this.setResource_config(resource); + + + return retInputs; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java new file mode 100644 index 0000000..f1a9a17 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/ResourceConfig.java @@ -0,0 +1,125 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +//TODO: Auto-generated Javadoc +/* (non-Javadoc) +* @see java.lang.Object#toString() +*/ +@Getter @Setter + +/* (non-Javadoc) +* @see java.lang.Object#toString() +*/ +@Builder + +/** +* Instantiates a new resource config obj. +*/ +@NoArgsConstructor + +/** +* Instantiates a new resource config obj. +* +* @param limits the limits +* @param requests the requests +*/ +@AllArgsConstructor + +public class ResourceConfig { + + /** The limits. */ + private TreeMap<String, GetInput> limits; + + /** The requests. */ + private TreeMap<String, GetInput> requests; + + + /** + * Creates the resource config. + * + * @param inps the inps + * @param name the name + * @return the tree map + */ + public TreeMap<String, LinkedHashMap<String, Object>> createResourceConfig(TreeMap<String, LinkedHashMap<String, Object>> inps, String name){ + TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; + + LinkedHashMap<String, Object> mi = new LinkedHashMap<String, Object>(); + mi.put("type", "string"); + mi.put("default", "128Mi"); + + LinkedHashMap<String, Object> m = new LinkedHashMap<String, Object>(); + m.put("type", "string"); + m.put("default", "250m"); + + + if(!name.equals("")) { + name = name + "_"; + } + + //set the limits + TreeMap<String, GetInput> lim = new TreeMap<String, GetInput>(); + + GetInput cpu = new GetInput(); + cpu.setGet_input(name + "cpu_limit"); + lim.put("cpu", cpu); + + GetInput memL = new GetInput(); + memL.setGet_input(name + "memory_limit"); + lim.put("memory", memL); + + retInputs.put(name + "cpu_limit", m); + retInputs.put(name + "memory_limit", mi); + + this.setLimits(lim); + + //set the requests + TreeMap<String, GetInput> req = new TreeMap<String, GetInput>(); + + GetInput cpuR = new GetInput(); + cpuR.setGet_input(name + "cpu_request"); + req.put("cpu", cpuR); + + GetInput memR = new GetInput(); + memR.setGet_input(name + "memory_request"); + req.put("memory", memR); + + retInputs.put(name + "cpu_request", m); + retInputs.put(name + "memory_request", mi); + + this.setRequests(req); + + return retInputs; + } +} + diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Start.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Start.java new file mode 100644 index 0000000..d9c885d --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Start.java @@ -0,0 +1,49 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.Getter; import lombok.Setter; +@Getter @Setter +@JsonInclude(value=Include.NON_NULL) +public class Start { + private StartInputs inputs; + private LinkedHashMap<String, Object> envs; + + public TreeMap<String, LinkedHashMap<String, Object>> createOnapStart(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; + retInputs = inps; + + //create the start inputs + StartInputs inputs = new StartInputs(); + inputs.createOnapStartInputs(retInputs, cs); + this.setInputs(inputs); + + return retInputs; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java new file mode 100644 index 0000000..1c1cf6c --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/StartInputs.java @@ -0,0 +1,85 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + +*/ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.Getter; import lombok.Setter; + +@Getter @Setter +@JsonInclude(value=Include.NON_NULL) +public class StartInputs { + //private ArrayList<String> ports; + private GetInput envs; + + public TreeMap<String, LinkedHashMap<String, Object>> createOnapStartInputs(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs){ + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + LinkedHashMap<String, Object> stringType = new LinkedHashMap<String, Object>(); + +// ArrayList<String> port = new ArrayList<String>(); +// String external = ""; +// if(cs.getAuxilary().getPorts() != null) { +// for(String s: cs.getAuxilary().getPorts()) { +// //create the ports +// String portNumber = ""; +// StringBuffer buf = new StringBuffer(); +// for(int i = 0; i < s.length(); i++) { +// if(!(s.charAt(i) == ':')) { +// buf.append(s.charAt(i)); +// } +// else { +// external = s.replace(buf.toString() + ":", ""); +// break; +// } +// } +// portNumber = buf.toString(); +// String p = "concat: [" + '"' + portNumber + ":" + '"' +", {get_input: external_port }]"; +// port.add(p); +// } +// } +// this.setPorts(port); +// //add the external port input +// if(cs.getAuxilary().getPorts() != null) { +// stringType.put("type", "string"); +// stringType.put("description", "Kubernetes node port on which collector is exposed"); +// stringType.put("default", "'" + external + "'") ; +// retInputs.put("external_port", stringType); +// } + + //set the envs + GetInput env = new GetInput(); + env.setGet_input("envs"); + this.setEnvs(env); + LinkedHashMap<String, Object> eMap = new LinkedHashMap(); + eMap.put("default", "{}"); + retInputs.put("envs", eMap); + + return retInputs; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/TemplateNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/TemplateNode.java new file mode 100644 index 0000000..7137cdb --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/TemplateNode.java @@ -0,0 +1,69 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= +*/ + +package org.onap.blueprintgenerator.models.blueprint; + +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.componentspec.Auxilary; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.HealthCheck; +import org.onap.blueprintgenerator.models.onapbp.OnapNode; + +import lombok.Getter; import lombok.Setter; + + +public class TemplateNode extends OnapNode{ + +// public void createTemplateNode() { +// //dummy inputs just used for the inputs so i can reuse code +// TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<String, LinkedHashMap<String, Object>>(); +// +// //create a dummy componentspec to set the values later on +// ComponentSpec cs = new ComponentSpec(); +// Auxilary aux = new Auxilary(); +// HealthCheck health = new HealthCheck(); +// health.setEndpoint("/healthcheck"); +// health.setInterval("15s"); +// health.setTimeout("1s"); +// health.setType("https"); +// aux.setHealthcheck(health); +// String[] ports = new String[1]; +// ports[0] = "9999:9999"; +// aux.setPorts(ports); +// cs.setAuxilary(aux); +// +// //set the type +// this.setType("dcae.nodes.ContainerizedPlatformComponent"); +// +// //set the interface +// Interfaces inter = new Interfaces(); +// inter.createOnapInterface(inps, cs); +// TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>(); +// interfaces.put("cloudify.interfaces.lifecycle", inter); +// this.setInterfaces(interfaces); +// +// +// //create the properties +// Properties props = new Properties(); +// props.createTemplateProperties(cs); +// this.setProperties(props); +// } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Artifacts.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Artifacts.java new file mode 100644 index 0000000..f7f5a03 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Artifacts.java @@ -0,0 +1,64 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + + +import com.fasterxml.jackson.annotation.JsonInclude; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ + + +/** + * Instantiates a new artifacts. + */ +@NoArgsConstructor + +/** + * Instantiates a new artifacts. + * + * @param type the type + * @param uri the uri + */ + +@JsonInclude(JsonInclude.Include.NON_NULL) +//Called in Component Spec Object +public class Artifacts { + + /** The type. */ + private String type; + + /** The uri. */ + private String uri; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Auxilary.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Auxilary.java new file mode 100644 index 0000000..01844f9 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Auxilary.java @@ -0,0 +1,118 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ +package org.onap.blueprintgenerator.models.componentspec; + + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ + + +/** + * Instantiates a new auxilary. + */ +@NoArgsConstructor + +/** + * Instantiates a new auxilary. + * + * @param healthcheck the healthcheck + * @param volumes the volumes + * @param policy the policy + * @param ports the ports + * @param reconfigs the reconfigs + * @param databases the databases + */ + +@JsonInclude(value=Include.NON_NULL) +//Called in component Spec Object +public class Auxilary { + + /** The healthcheck. */ + private HealthCheck healthcheck; + /** The volumes. */ + private Volumes[] volumes; + + /** The policy. */ + private Policy policy; + + /** The ports. */ + private ArrayList<Object> ports; + + /** The reconfigs. */ + private ReconfigsObj reconfigs; + + /** The databases. */ + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + private TreeMap<String, String> databases; + + + public TreeMap<String, LinkedHashMap<String, Object>> createPorts(TreeMap<String, LinkedHashMap<String, Object>> inps) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; + LinkedHashMap<String, Object> portType = new LinkedHashMap(); + portType.put("type", "string"); + + ArrayList<Object> ports = new ArrayList(); + String external = ""; + boolean foundPort = false; + for(Object o: this.getPorts()) { + String internal = ""; + String p = o.toString(); + for(int i = 0; i < p.length(); i++) { + if(p.charAt(i) == ':') { + internal = '"' + internal + '"'; + internal = "concat: ['" + internal + "', {get_input: external_port}]"; + ports.add(internal); + } + if(p.charAt(i) == ':' && !foundPort) { + external = p.substring(i); + portType.put("default", external); + retInputs.put("external_port", portType); + + } + internal = internal + p.charAt(i); + + } + } + + this.setPorts(ports); + return retInputs; + } +}
\ No newline at end of file diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/CallsObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/CallsObj.java new file mode 100644 index 0000000..0b7dcee --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/CallsObj.java @@ -0,0 +1,50 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + + +// TODO: Auto-generated Javadoc +/** + * The Class CallsObj. + */ +@JsonInclude(value=Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +//called from service obj +public class CallsObj { + + /** The config key. */ + private String config_key; + + /** The request. */ + private RequestResponseObj request; + + /** The response. */ + private RequestResponseObj response; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ComponentSpec.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ComponentSpec.java new file mode 100644 index 0000000..b6bc0a1 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ComponentSpec.java @@ -0,0 +1,149 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/** + * The Class ComponentSpec. + */ +@JsonIgnoreProperties(ignoreUnknown = true) + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ + + +/** + * Instantiates a new component spec. + */ +@NoArgsConstructor + +/** + * Instantiates a new component spec. + * + * @param self the self + * @param services the services + * @param streams the streams + * @param parameters the parameters + * @param auxilary the auxilary + * @param artifacts the artifacts + */ + +@JsonInclude(value=Include.NON_NULL) +//main object that the component spec file is written in +public class ComponentSpec { + + /** The self. */ + private Self self; + + /** The services. */ + private Services services; + + /** The streams. */ + private Streams streams; + + /** The parameters. */ + private Parameters[] parameters; + + /** The auxilary. */ + private Auxilary auxilary; + + /** The artifacts. */ + private Artifacts[] artifacts; + + /** + * Creates the component spec from file. + * + * @param path the path + */ + public void createComponentSpecFromFile(String path) { + ObjectMapper componentMapper = new ObjectMapper(); + File specPathFile = new File(path); + ComponentSpec cs = new ComponentSpec(); + + try { + cs = componentMapper.readValue(specPathFile, ComponentSpec.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + + + + //set all the pieces of the component spec + this.setSelf(cs.getSelf()); + this.setArtifacts(cs.getArtifacts()); + this.setAuxilary(cs.getAuxilary()); + this.setParameters(cs.getParameters()); + this.setServices(cs.getServices()); + this.setStreams(cs.getStreams()); + } + + + /** + * Creates the component spec from string. + * + * @param specString the spec string + */ + public void createComponentSpecFromString(String specString) { + ObjectMapper componentMapper = new ObjectMapper(); + ComponentSpec cs = new ComponentSpec(); + try { + cs = componentMapper.readValue(specString, ComponentSpec.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + + //set all the pieces of the component spec + this.setSelf(cs.getSelf()); + this.setArtifacts(cs.getArtifacts()); + this.setAuxilary(cs.getAuxilary()); + this.setParameters(cs.getParameters()); + this.setServices(cs.getServices()); + this.setStreams(cs.getStreams()); + } + + +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ConstraintsObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ConstraintsObj.java new file mode 100644 index 0000000..3615605 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ConstraintsObj.java @@ -0,0 +1,70 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + +import java.util.HashMap; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/** + * The Class ConstraintsObj. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(value=Include.NON_NULL) + +public class ConstraintsObj { + + /** The equal. */ + private Object equal; + + /** The greater than. */ + private int greater_than; + + /** The greater or equal. */ + private int greater_or_equal; + + /** The less than. */ + private int less_than; + + /** The less or equal. */ + private int less_or_equal; + + /** The valid values. */ + private Object[] valid_values; + + /** The length. */ + private int length; + + /** The min length. */ + private int min_length; + + /** The max length. */ + private int max_length; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Container.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Container.java new file mode 100644 index 0000000..d94e2bb --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Container.java @@ -0,0 +1,60 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new container. + */ +@NoArgsConstructor + +/** + * Instantiates a new container. + * + * @param bind the bind + * @param mode the mode + */ + +@JsonInclude(value=Include.NON_NULL) +public class Container { + + /** The bind. */ + private String bind; + + /** The mode. */ + private String mode; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/EntrySchemaObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/EntrySchemaObj.java new file mode 100644 index 0000000..45f9091 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/EntrySchemaObj.java @@ -0,0 +1,84 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/** + * The Class EntrySchemaObj. + */ +@JsonIgnoreProperties(ignoreUnknown = true) + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new entry schema obj. + */ +@NoArgsConstructor + +/** + * Instantiates a new entry schema obj. + * + * @param name the name + * @param description the description + * @param type the type + * @param value the value + * @param entry_schema the entry schema + * @param required the required + */ + +@JsonInclude(value=Include.NON_NULL) +//called from policy schema obj +public class EntrySchemaObj { + + /** The name. */ + private String name; + + /** The description. */ + private String description; + + /** The type. */ + private String type; + + /** The value. */ + private String value; + + /** The entry schema. */ + private EntrySchemaObj[] entry_schema; + + /** The required. */ + private boolean required; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/HealthCheck.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/HealthCheck.java new file mode 100644 index 0000000..acc9379 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/HealthCheck.java @@ -0,0 +1,72 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new health check. + */ +@NoArgsConstructor + +/** + * Instantiates a new health check. + * + * @param interval the interval + * @param timeout the timeout + * @param script the script + * @param type the type + */ + +@JsonInclude(value=Include.NON_NULL) +//Called in Auxillary Object +public class HealthCheck { + + /** The interval. */ + private String interval; + + /** The timeout. */ + private String timeout; + + /** The script. */ + private String script; + + /** The type. */ + private String type; + + private String endpoint; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Host.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Host.java new file mode 100644 index 0000000..91734ad --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Host.java @@ -0,0 +1,56 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/** + * Instantiates a new host. + */ +@NoArgsConstructor + +/** + * Instantiates a new host. + * + * @param path the path + * @param mode the mode + */ +@JsonInclude(value=Include.NON_NULL) +public class Host{ + + /** The path. */ + private String path; + + /** The mode. */ + private String mode; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Parameters.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Parameters.java new file mode 100644 index 0000000..515ecc7 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Parameters.java @@ -0,0 +1,109 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + +import java.util.ArrayList; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/** + * The Class Parameters. + */ +@JsonIgnoreProperties(ignoreUnknown = true) + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new parameters. + */ +@NoArgsConstructor + +/** + * Instantiates a new parameters. + * + * @param name the name + * @param value the value + * @param description the description + * @param sourced_at_deployment the sourced at deployment + * @param designer_editable the designer editable + * @param policy_editable the policy editable + * @param required the required + * @param type the type + * @param policy_group the policy group + * @param policy_schema the policy schema + * @param entry_schema the entry schema + * @param constraints the constraints + */ +@JsonInclude(value=Include.NON_NULL) +//Called in component Spec Object +public class Parameters { + + /** The name. */ + private String name; + + /** The value. */ + private Object value; + + /** The description. */ + private String description; + + /** The sourced at deployment. */ + private boolean sourced_at_deployment; + + /** The designer editable. */ + private boolean designer_editable; + + /** The policy editable. */ + private boolean policy_editable; + + /** The required. */ + private boolean required; + + /** The type. */ + private String type; + + /** The policy group. */ + private String policy_group; + + /** The policy schema. */ + private PolicySchemaObj[] policy_schema; + + /** The entry schema. */ + private EntrySchemaObj[] entry_schema; + + /** The constraints. */ + private ConstraintsObj[] constraints; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Policy.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Policy.java new file mode 100644 index 0000000..3cc14fe --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Policy.java @@ -0,0 +1,62 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ + +/** + * Instantiates a new policy. + */ +@NoArgsConstructor + +/** + * Instantiates a new policy. + * + * @param trigger_type the trigger type + * @param script_path the script path + */ +@JsonInclude(value=Include.NON_NULL) +//called in auxilary +public class Policy { + + /** The trigger type. */ + private String trigger_type; + + /** The script path. */ + private String script_path; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/PolicySchemaObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/PolicySchemaObj.java new file mode 100644 index 0000000..7af16d6 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/PolicySchemaObj.java @@ -0,0 +1,88 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/** + * The Class PolicySchemaObj. + */ +@JsonIgnoreProperties(ignoreUnknown = true) + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ + +/** + * Instantiates a new policy schema obj. + */ +@NoArgsConstructor + +/** + * Instantiates a new policy schema obj. + * + * @param name the name + * @param description the description + * @param type the type + * @param value the value + * @param entry_schema the entry schema + * @param required the required + * @param constraints the constraints + */ +@JsonInclude(value=Include.NON_NULL) +//called from parameters obj +public class PolicySchemaObj { + + /** The name. */ + private String name; + + /** The description. */ + private String description; + + /** The type. */ + private String type; + + /** The value. */ + private String value; + + /** The entry schema. */ + private EntrySchemaObj[] entry_schema; + + /** The required. */ + private boolean required; + + /** The constraints. */ + private ConstraintsObj[] constraints; + } diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ProvidesObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ProvidesObj.java new file mode 100644 index 0000000..ad9c87d --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ProvidesObj.java @@ -0,0 +1,65 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ + +/** + * Instantiates a new provides obj. + */ +@NoArgsConstructor + +/** + * Instantiates a new provides obj. + * + * @param route the route + * @param request the request + * @param response the response + */ +//called from service obj +public class ProvidesObj { + + /** The route. */ + private String route; + + /** The request. */ + private RequestResponseObj request; + + /** The response. */ + private RequestResponseObj response; + + private String verb; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Publishes.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Publishes.java new file mode 100644 index 0000000..3ee47b9 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Publishes.java @@ -0,0 +1,73 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ + +/** + * Instantiates a new publishes. + */ +@NoArgsConstructor + +/** + * Instantiates a new publishes. + * + * @param config_key the config key + * @param format the format + * @param type the type + * @param version the version + */ +@JsonInclude(value=Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +//Called in Streams Object +public class Publishes { + + /** The config key. */ + private String config_key; + + /** The format. */ + private String format; + + /** The route. */ + private String route; + /** The type. */ + private String type; + + /** The version. */ + private String version; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ReconfigsObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ReconfigsObj.java new file mode 100644 index 0000000..6c389d6 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/ReconfigsObj.java @@ -0,0 +1,61 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new reconfigs obj. + */ +@NoArgsConstructor + +/** + * Instantiates a new reconfigs obj. + * + * @param dti the dti + * @param policy the policy + */ +@JsonInclude(value=Include.NON_NULL) + +public class ReconfigsObj { + + /** The dti. */ + private String dti; + + /** The policy. */ + private String policy; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/RequestResponseObj.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/RequestResponseObj.java new file mode 100644 index 0000000..2aaf60b --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/RequestResponseObj.java @@ -0,0 +1,48 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + + +// TODO: Auto-generated Javadoc +/** + * The Class RequestResponseObj. + */ +@JsonInclude(value=Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +//called in calls obj +public class RequestResponseObj { + + /** The format. */ + private String format; + + /** The version. */ + private String version; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Self.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Self.java new file mode 100644 index 0000000..a566661 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Self.java @@ -0,0 +1,72 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new self. + */ +@NoArgsConstructor + +/** + * Instantiates a new self. + * + * @param component_type the component type + * @param description the description + * @param name the name + * @param version the version + */ +@JsonInclude(value=Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +//called in Component Spec object +public class Self { + + /** The component type. */ + private String component_type; + + /** The description. */ + private String description; + + /** The name. */ + private String name; + + /** The version. */ + private String version; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Services.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Services.java new file mode 100644 index 0000000..afe0904 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Services.java @@ -0,0 +1,63 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new services. + */ +@NoArgsConstructor + +/** + * Instantiates a new services. + * + * @param calls the calls + * @param provides the provides + */ +@JsonInclude(value=Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +//called in component spec object +public class Services { + + /** The calls. */ + private CallsObj[] calls; + + /** The provides. */ + private ProvidesObj[] provides; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Streams.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Streams.java new file mode 100644 index 0000000..1b7dcd3 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Streams.java @@ -0,0 +1,63 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new streams. + */ +@NoArgsConstructor + +/** + * Instantiates a new streams. + * + * @param publishes the publishes + * @param subscribes the subscribes + */ +@JsonInclude(value=Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +//Called in Component Spec Object +public class Streams { + + /** The publishes. */ + private Publishes[] publishes; + + /** The subscribes. */ + private Subscribes[] subscribes; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Subscribes.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Subscribes.java new file mode 100644 index 0000000..14485a0 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Subscribes.java @@ -0,0 +1,77 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ + + +/** + * Instantiates a new subscribes. + */ +@NoArgsConstructor + +/** + * Instantiates a new subscribes. + * + * @param config_key the config key + * @param format the format + * @param route the route + * @param type the type + * @param version the version + */ + +@JsonInclude(value=Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +//Called in Streams Object +public class Subscribes { + + /** The config key. */ + private String config_key; + + /** The format. */ + private String format; + + /** The route. */ + private String route; + + /** The type. */ + private String type; + + /** The version. */ + private String version; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Volumes.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Volumes.java new file mode 100644 index 0000000..1034242 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/componentspec/Volumes.java @@ -0,0 +1,61 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.componentspec; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.NoArgsConstructor; + +// TODO: Auto-generated Javadoc +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +@Getter @Setter + +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +/** + * Instantiates a new volumes. + */ +@NoArgsConstructor + +/** + * Instantiates a new volumes. + * + * @param container the container + * @param host the host + */ +@JsonInclude(value=Include.NON_NULL) +//Called in Auxillary Object +public class Volumes { + + /** The container. */ + private Container container; + + /** The host. */ + private Host host; +}
\ No newline at end of file diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java new file mode 100644 index 0000000..d3cff67 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java @@ -0,0 +1,111 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.dmaapbp; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.blueprint.Blueprint; +import org.onap.blueprintgenerator.models.blueprint.Imports; +import org.onap.blueprintgenerator.models.blueprint.Interfaces; +import org.onap.blueprintgenerator.models.blueprint.Node; +import org.onap.blueprintgenerator.models.blueprint.Properties; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.Publishes; +import org.onap.blueprintgenerator.models.componentspec.Subscribes; + +public class DmaapBlueprint extends Blueprint{ + public Blueprint createDmaapBlueprint(ComponentSpec cs, String importPath, String override) { + Blueprint bp = new Blueprint(); + + //set tosca definition + bp.setTosca_definitions_version("cloudify_dsl_1_3"); + + //set the description + bp.setDescription(cs.getSelf().getDescription()); + + //create the inpus object that will be added to over the creation of the blueprint + TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<String, LinkedHashMap<String, Object>>(); + + //set the imports + Imports imps = new Imports(); + if(importPath.equals("")) { + bp.setImports(imps.createDmaapImports()); + } + else { + bp.setImports(imps.createImportsFromFile(importPath)); + } + + //bp.setImports(imps.getImports()); + + //set and create the node templates + TreeMap<String, Node> nodeTemplate = new TreeMap(); + + //create and add the main dmaap node + DmaapNode dmaap = new DmaapNode(); + inps = dmaap.createDmaapNode(cs, inps, override); + nodeTemplate.put(cs.getSelf().getName(), dmaap); + + //create and add the topic/feed nodes + + //go through the streams publishes + int counter = 0; + if(cs.getStreams().getPublishes() != null) { + for(Publishes p: cs.getStreams().getPublishes()) { + if(p.getType().equals("message_router") || p.getType().equals("message router")) { + String topic = "topic" + counter; + DmaapNode topicNode = new DmaapNode(); + inps = topicNode.createTopicNode(cs, inps, topic); + nodeTemplate.put(topic, topicNode); + } else if(p.getType().equals("data_router") || p.getType().equals("data router")) { + String feed = "feed" + counter; + DmaapNode feedNode = new DmaapNode(); + inps = feedNode.createFeedNode(cs, inps, feed); + nodeTemplate.put(feed, feedNode); + } + counter++; + } + } + //go through the stream subscribes + if(cs.getStreams().getSubscribes() != null) { + for(Subscribes s: cs.getStreams().getSubscribes()) { + if(s.getType().equals("message_router") || s.getType().equals("message router")) { + String topic = "topic" + counter; + DmaapNode topicNode = new DmaapNode(); + inps = topicNode.createTopicNode(cs, inps, topic); + nodeTemplate.put(topic, topicNode); + } else if(s.getType().equals("data_router") || s.getType().equals("data router")) { + String feed = "feed" + counter; + DmaapNode feedNode = new DmaapNode(); + inps = feedNode.createFeedNode(cs, inps, feed); + nodeTemplate.put(feed, feedNode); + } + counter++; + } + } + + bp.setNode_templates(nodeTemplate); + + bp.setInputs(inps); + return bp; + } +}
\ No newline at end of file diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNode.java new file mode 100644 index 0000000..bfa7ae9 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapNode.java @@ -0,0 +1,153 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.dmaapbp; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.blueprint.GetInput; +import org.onap.blueprintgenerator.models.blueprint.Interfaces; +import org.onap.blueprintgenerator.models.blueprint.Node; +import org.onap.blueprintgenerator.models.blueprint.Properties; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.Publishes; +import org.onap.blueprintgenerator.models.componentspec.Subscribes; +import org.onap.blueprintgenerator.models.onapbp.OnapNode; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter @Setter +@EqualsAndHashCode(callSuper=false) +@NoArgsConstructor +@JsonInclude(value=Include.NON_NULL) + +public class DmaapNode extends Node{ + + private TreeMap<String, Interfaces> interfaces; + private Properties properties; + private ArrayList<LinkedHashMap<String, String>> relationships; + + public TreeMap<String, LinkedHashMap<String, Object>> createDmaapNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String override) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; + + //set the type + this.setType("dcae.nodes.ContainerizedServiceComponentUsingDmaap"); + + //create the interface + Interfaces inter = new Interfaces(); + retInputs = inter.createInterface(retInputs, cs); + TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>(); + interfaces.put("cloudify.interfaces.lifecycle", inter); + this.setInterfaces(interfaces); + + //create and set the relationships + ArrayList<LinkedHashMap<String, String>> rets = new ArrayList(); + + //go through the streams publishes + int counter = 0; + if(cs.getStreams().getPublishes() != null) { + for(Publishes p: cs.getStreams().getPublishes()) { + LinkedHashMap<String, String> pubRelations = new LinkedHashMap(); + if(p.getType().equals("message_router") || p.getType().equals("message router")) { + pubRelations.put("type", "ccsdk.relationships.publish_events"); + pubRelations.put("target", "topic" + counter); + } else if(p.getType().equals("data_router") || p.getType().equals("data router")) { + pubRelations.put("type", "ccsdk.relationships.publish_files"); + pubRelations.put("target", "feed" + counter); + } + rets.add(pubRelations); + counter++; + } + } + //go through the stream subscribes + if(cs.getStreams().getSubscribes() != null) { + for(Subscribes s: cs.getStreams().getSubscribes()) { + LinkedHashMap<String, String> subRelations = new LinkedHashMap(); + if(s.getType().equals("message_router") || s.getType().equals("message router")) { + subRelations.put("type", "ccsdk.relationships.subscribe_to_events"); + subRelations.put("target", "topic" + counter); + } else if(s.getType().equals("data_router") || s.getType().equals("data router")) { + subRelations.put("type", "ccsdk.relationships.subscribe_to_files"); + subRelations.put("target", "feed" + counter); + } + rets.add(subRelations); + counter++; + } + } + + this.setRelationships(rets); + + //create and set the properties + Properties props = new Properties(); + retInputs = props.createDmaapProperties(retInputs, cs, override); + this.setProperties(props); + + return retInputs; + } + public TreeMap<String, LinkedHashMap<String, Object>> createFeedNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){ + TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; + LinkedHashMap<String, Object> stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + //set the type + this.setType("ccsdk.nodes.Feed"); + + //create and set the properties + Properties props = new Properties(); + GetInput topicInput = new GetInput(); + topicInput.setGet_input(name + "_name"); + props.setFeed_name(topicInput); + //props.setUseExisting(true); + retInputs.put(name + "_name", stringType); + this.setProperties(props); + + return retInputs; + } + + public TreeMap<String, LinkedHashMap<String, Object>> createTopicNode(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> inps, String name){ + TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; + LinkedHashMap<String, Object> stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + //set the type + this.setType("ccsdk.nodes.Topic"); + + //create and set the properties + Properties props = new Properties(); + GetInput topicInput = new GetInput(); + topicInput.setGet_input(name + "_name"); + props.setTopic_name(topicInput); + //props.setUseExisting(true); + retInputs.put(name + "_name", stringType); + this.setProperties(props); + + return retInputs; + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapStreams.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapStreams.java new file mode 100644 index 0000000..1640a6e --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapStreams.java @@ -0,0 +1,103 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.dmaapbp; + +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.blueprint.Appconfig; +import org.onap.blueprintgenerator.models.blueprint.GetInput; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.HealthCheck; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +@JsonInclude(value=Include.NON_NULL) +public class DmaapStreams { + + private String name; + private GetInput location; + private GetInput client_role; + private String type; + + private GetInput username; + private GetInput password; + //private GetInput delivery_url; + private String route; + private String scheme; + + public TreeMap<String, LinkedHashMap<String, Object>> createStreams(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String name, String type, String key, String route, char o){ + TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps; + LinkedHashMap<String, Object> stringType = new LinkedHashMap(); + stringType.put("type", "string"); + + //set the name + this.setName(name); + + //set the type + this.setType(type); + + //set the location + GetInput location = new GetInput(); + location.setGet_input(key + "_" + name + "_location"); + retInputs.put(key + "_" + name + "_location", stringType); + this.setLocation(location); + + //if its data router we need to add some more + if(type.equals("data_router") || type.equals("data router")) { + if(o == 's') { + //set the username + GetInput username = new GetInput(); + username.setGet_input(key + "_" + name + "_username"); + this.setUsername(username); + retInputs.put(key + "_" + name + "_username", stringType); + + //set the password + GetInput password = new GetInput(); + password.setGet_input(key + "_" + name + "_password"); + this.setPassword(password); + retInputs.put(key + "_" + name + "_password", stringType); + + this.setRoute(route); + this.setScheme("https"); + } + +// //set the delivery url +// GetInput delivery = new GetInput(); +// delivery.setGet_input(name + "_delivery_url"); +// this.setDelivery_url(delivery); +// retInputs.put(name + "delivery_url", stringType); + + } else { + //set the client role + GetInput client = new GetInput(); + client.setGet_input(key + "_" + name + "_client_role"); + this.setClient_role(client); + retInputs.put(key + "_" + name + "_client_role", stringType); + } + return retInputs; + } +}
\ No newline at end of file diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/LogDirectory.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/LogDirectory.java new file mode 100644 index 0000000..c9e531f --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/LogDirectory.java @@ -0,0 +1,28 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + +*/ + +package org.onap.blueprintgenerator.models.onapbp; + +import lombok.Getter; import lombok.Setter; + +@Getter @Setter +public class LogDirectory { + private Object log_directory; +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapBlueprint.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapBlueprint.java new file mode 100644 index 0000000..8342020 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapBlueprint.java @@ -0,0 +1,84 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.onapbp; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.blueprint.Blueprint; +import org.onap.blueprintgenerator.models.blueprint.Imports; +import org.onap.blueprintgenerator.models.blueprint.Node; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.Getter; import lombok.Setter; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + + +@Getter @Setter +@JsonInclude(value=Include.NON_NULL) + +public class OnapBlueprint extends Blueprint{ + public Blueprint createOnapBlueprint(ComponentSpec cs, String importPath, String override) { + + //create the inputs that will be used + TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + //set the tosca definition which is the same for everything + this.setTosca_definitions_version("cloudify_dsl_1_3"); + + //set the imports + if(importPath != "") { + Imports imps = new Imports(); + this.setImports(imps.createImportsFromFile(importPath)); + } + else { + Imports imps = new Imports(); + this.setImports(imps.createOnapImports()); + } + + //create the node template + TreeMap<String, Node> nodeTemplate = new TreeMap<String, Node>(); + String nodeName = cs.getSelf().getName(); + + //create the onap node that will be used + OnapNode node = new OnapNode(); + inputs = node.createOnapNode(inputs, cs, override); + nodeTemplate.put(nodeName, node); + this.setNode_templates(nodeTemplate); + + //set the inputs + this.setInputs(inputs); + + Blueprint bp = new Blueprint(); + bp.setImports(this.getImports()); + bp.setInputs(this.getInputs()); + bp.setNode_templates(this.getNode_templates()); + bp.setTosca_definitions_version(this.getTosca_definitions_version()); + + return bp; + + } +}
\ No newline at end of file diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapNode.java new file mode 100644 index 0000000..2b0b8c0 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/onapbp/OnapNode.java @@ -0,0 +1,71 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.models.onapbp; + +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.blueprint.Interfaces; +import org.onap.blueprintgenerator.models.blueprint.Node; +import org.onap.blueprintgenerator.models.blueprint.Properties; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; import lombok.Setter; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter @Setter +@EqualsAndHashCode(callSuper=false) +@NoArgsConstructor +@JsonInclude(value=Include.NON_NULL) + +public class OnapNode extends Node{ + private TreeMap<String, Interfaces> interfaces; + private Properties properties; + public TreeMap<String, LinkedHashMap<String, Object>> createOnapNode(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) { + TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + retInputs = inps; + + //create and set the interfaces + Interfaces inter = new Interfaces(); + retInputs = inter.createInterface(retInputs, cs); + TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>(); + interfaces.put("cloudify.interfaces.lifecycle", inter); + this.setInterfaces(interfaces); + + //set the type + this.setType("dcae.nodes.ContainerizedPlatformComponent"); + + //set the properties + Properties props = new Properties(); + retInputs = props.createOnapProperties(retInputs, cs, override); + this.setProperties(props); + + return retInputs; + } +}
\ No newline at end of file diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java new file mode 100644 index 0000000..9c9bd51 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java @@ -0,0 +1,139 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + +*/ + +package org.onap.blueprintgenerator.models.policymodel; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.blueprint.Node; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.Parameters; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +@JsonInclude(JsonInclude.Include.NON_NULL) + +public class PolicyModel { + + private String tosca_definition_version; + private TreeMap<String, PolicyModelNode> node_types; + private TreeMap<String, PolicyModelNode> data_types; + + public ArrayList<PolicyModel> createPolicyModels(ComponentSpec cs, String filePath) { + ArrayList<PolicyModel> models = new ArrayList(); + Parameters[] params = cs.getParameters(); + + ArrayList<String> groups = new ArrayList<String>(); + groups = getModelGroups(params); + + for(String s: groups) { + PolicyModel model = new PolicyModel(); + model = model.createPolicyModel(s, params); + //models.add(model); + policyModelToYaml(filePath, model, s); + } + +// for(PolicyModel p: models) { +// policyModelToYaml(filePath, p); +// } + + return models; + } + + public ArrayList<String> getModelGroups(Parameters[] params) { + ArrayList<String> groups = new ArrayList(); + + for(Parameters p: params) { + if(p.isPolicy_editable()) { + if(groups.isEmpty()) { + groups.add(p.getPolicy_group()); + } else { + if(!groups.contains(p.getPolicy_group())) { + groups.add(p.getPolicy_group()); + } + } + } + } + + return groups; + } + + public PolicyModel createPolicyModel(String s, Parameters[] params) { + PolicyModel model = new PolicyModel(); + model.setTosca_definition_version("tosca_simple_yaml_1_0_0"); + + PolicyModelNode node = new PolicyModelNode(); + String hasEntryScheme = node.createNodeType(s, params); + String nodeTypeName = "onap.policy." + s; + TreeMap<String, PolicyModelNode> nodeType = new TreeMap(); + nodeType.put(nodeTypeName, node); + model.setNode_types(nodeType); + + if(!hasEntryScheme.equals("")) { + PolicyModelNode data = new PolicyModelNode(); + TreeMap<String, PolicyModelNode> dataType = data.createDataTypes(hasEntryScheme, params); + model.setData_types(dataType); + } + + return model; + } + + public void policyModelToYaml(String path, PolicyModel p, String name) { + File outputFile; + String filePath = path + "/" + name + ".yml"; + File policyFile = new File(filePath); + ObjectMapper policyMapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); + outputFile = new File(path, name + ".yml"); + outputFile.getParentFile().mkdirs(); + + try { + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true))); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + policyMapper.writeValue(outputFile, p); + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("model " + name + " created"); + } +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java new file mode 100644 index 0000000..56d1d13 --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java @@ -0,0 +1,147 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + +*/ + +package org.onap.blueprintgenerator.models.policymodel; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.blueprint.Node; +import org.onap.blueprintgenerator.models.componentspec.EntrySchemaObj; +import org.onap.blueprintgenerator.models.componentspec.Parameters; +import org.onap.blueprintgenerator.models.componentspec.PolicySchemaObj; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +@JsonInclude(JsonInclude.Include.NON_NULL) +public class PolicyModelNode { + + private String derived_from; + private TreeMap<String, PolicyProperties> properties; + + public String createNodeType(String policyName, Parameters[] params) { + String hasEntrySchema = ""; + + TreeMap<String, PolicyProperties> props = new TreeMap(); + for(Parameters p: params) { + if(p.getPolicy_group() != null) { + if(p.getPolicy_group().equals(policyName)) { + String name = p.getName(); + String type = p.getType(); + PolicyProperties polProps = new PolicyProperties(); + if(p.getPolicy_schema() != null) { + polProps.setType("map"); + HashMap<String, String> entrySchema = new HashMap(); + entrySchema.put("type", "onap.datatypes." + name); + //ArrayList<String> entrySchema = new ArrayList<String>(); + //entrySchema.add("type: onap.data." + name); + polProps.setEntry_schema(entrySchema); + hasEntrySchema = name; + props.put(name, polProps); + } + else { + polProps.setType(type); + props.put(name, polProps); + } + } + } + } + + this.setDerived_from("tosca.datatypes.Root"); + this.setProperties(props); + return hasEntrySchema; + } + + public TreeMap<String, PolicyModelNode> createDataTypes(String param, Parameters[] parameters) { + TreeMap<String, PolicyModelNode> dataType = new TreeMap<String, PolicyModelNode>(); + + PolicyModelNode node = new PolicyModelNode(); + node.setDerived_from("tosca.datatypes.Root"); + + TreeMap<String, PolicyProperties> properties = new TreeMap(); + + Parameters par = new Parameters(); + for(Parameters p: parameters) { + if(p.getName().equals(param)) { + par = p; + break; + } + } + + for(PolicySchemaObj pol: par.getPolicy_schema()) { + if(pol.getEntry_schema() != null) { + PolicyProperties prop = new PolicyProperties(); + prop.setType("map"); + HashMap<String, String> schema = new HashMap(); + schema.put("type", "onap.datatypes." + pol.getName()); +// prop.setType("list"); +// ArrayList<String> schema = new ArrayList(); +// schema.add("type: onap.data." + pol.getName()); + prop.setEntry_schema(schema); + properties.put(pol.getName(), prop); + dataType = translateEntrySchema(dataType, pol.getEntry_schema(), pol.getName()); + } + else { + PolicyProperties prop = new PolicyProperties(); + prop.setType(pol.getType()); + properties.put(pol.getName(), prop); + } + } + + node.setProperties(properties); + dataType.put("onap.datatypes." + param, node); + return dataType; + } + + private TreeMap<String, PolicyModelNode> translateEntrySchema(TreeMap<String, PolicyModelNode> dataType, EntrySchemaObj[] entry, String name){ + TreeMap<String, PolicyModelNode> data = dataType; + PolicyModelNode node = new PolicyModelNode(); + node.setDerived_from("tosca.nodes.Root"); + TreeMap<String, PolicyProperties> properties = new TreeMap<String, PolicyProperties>(); + + for(EntrySchemaObj e: entry) { + if(e.getEntry_schema() != null) { + PolicyProperties prop = new PolicyProperties(); + prop.setType("list"); + ArrayList<String> schema = new ArrayList<String>(); + schema.add("type: onap.datatypes." + e.getName()); + prop.setEntry_schema(schema); + properties.put(e.getName(), prop); + data = translateEntrySchema(data, e.getEntry_schema(), e.getName()); + node.setProperties(properties); + } else { + PolicyProperties prop = new PolicyProperties(); + prop.setType(e.getType()); + properties.put(e.getName(), prop); + node.setProperties(properties); + } + } + + dataType.put("onap.datatypes." + name, node); + return data; + } + +} diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyProperties.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyProperties.java new file mode 100644 index 0000000..6faf78d --- /dev/null +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyProperties.java @@ -0,0 +1,41 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + +*/ + +package org.onap.blueprintgenerator.models.policymodel; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.onap.blueprintgenerator.models.blueprint.Node; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +@JsonInclude(JsonInclude.Include.NON_NULL) +public class PolicyProperties { + + private String type; + private Object entry_schema; + +} diff --git a/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java new file mode 100644 index 0000000..404b899 --- /dev/null +++ b/mod/bpgenerator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java @@ -0,0 +1,445 @@ +/**============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + + */ + +package org.onap.blueprintgenerator.core; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.TreeMap; + +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.onap.blueprintgenerator.models.blueprint.Blueprint; +import org.onap.blueprintgenerator.models.blueprint.GetInput; +import org.onap.blueprintgenerator.models.componentspec.Artifacts; +import org.onap.blueprintgenerator.models.componentspec.Auxilary; +import org.onap.blueprintgenerator.models.componentspec.CallsObj; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.Container; +import org.onap.blueprintgenerator.models.componentspec.HealthCheck; +import org.onap.blueprintgenerator.models.componentspec.Host; +import org.onap.blueprintgenerator.models.componentspec.Parameters; +import org.onap.blueprintgenerator.models.componentspec.Policy; +import org.onap.blueprintgenerator.models.componentspec.ProvidesObj; +import org.onap.blueprintgenerator.models.componentspec.Publishes; +import org.onap.blueprintgenerator.models.componentspec.Self; +import org.onap.blueprintgenerator.models.componentspec.Services; +import org.onap.blueprintgenerator.models.componentspec.Streams; +import org.onap.blueprintgenerator.models.componentspec.Subscribes; +import org.onap.blueprintgenerator.models.componentspec.Volumes; +import org.onap.blueprintgenerator.models.dmaapbp.DmaapNode; +import org.onap.blueprintgenerator.models.onapbp.OnapNode; +import org.onap.blueprintgenerator.models.policymodel.PolicyModel; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import picocli.CommandLine; + + +// TODO: Auto-generated Javadoc +/** + * The Class BlueprintGeneratorTest. + */ +public class BlueprintGeneratorTest { + + /** + * Component spec test. + * + * @throws JsonParseException the json parse exception + * @throws JsonMappingException the json mapping exception + * @throws IOException Signals that an I/O exception has occurred. + */ + + @Test + public void componentSpecTest() throws JsonParseException, JsonMappingException, IOException { + + ComponentSpec spec = new ComponentSpec(); + TestComponentSpec test = new TestComponentSpec(); + spec.createComponentSpecFromString(test.getCs()); + + //Manually fill a component spec object with the values from the file itself + ComponentSpec manualSpec = new ComponentSpec(); + + Self self = new Self(); + self.setComponent_type("docker"); + self.setDescription("Test component spec"); + self.setName("test.component.spec"); + self.setVersion("1.0.1"); + manualSpec.setSelf(self); + + //assertEquals(manualSpec.getSelf(), spec.getSelf()); + + Services services = new Services(); + CallsObj[] calls = new CallsObj[0]; + ProvidesObj[] provides = new ProvidesObj[0]; + services.setCalls(calls); + services.setProvides(provides); + manualSpec.setServices(null); + + //assertEquals(manualSpec.getServices(), spec.getServices()); + + Streams streams = new Streams(); + Publishes[] publishes = new Publishes[2]; + Publishes pub1 = new Publishes(); + pub1.setConfig_key("TEST-PUB-DR"); + pub1.setFormat("dataformat_Hello_World_PM"); + pub1.setType("data_router"); + pub1.setVersion("1.0.0"); + + Publishes pub2 = new Publishes(); + pub2.setConfig_key("TEST-PUB-MR"); + pub2.setFormat("dataformat_Hello_World_PM"); + pub2.setType("message_router"); + pub2.setVersion("1.0.0"); + publishes[0] = pub1; + publishes[1] = pub2; + streams.setPublishes(publishes); + + Subscribes[] subscribes = new Subscribes[2]; + Subscribes sub1 = new Subscribes(); + sub1.setConfig_key("TEST-SUB-MR"); + sub1.setFormat("dataformat_Hello_World_PM"); + sub1.setRoute("/TEST_HELLO_WORLD_SUB_MR"); + sub1.setType("message_router"); + sub1.setVersion("1.0.0"); + + Subscribes sub2 = new Subscribes(); + sub2.setConfig_key("TEST-SUB-DR"); + sub2.setFormat("dataformat_Hello_World_PM"); + sub2.setRoute("/TEST-HELLO-WORLD-SUB-DR"); + sub2.setType("data_router"); + sub2.setVersion("1.0.0"); + subscribes[0] = sub1; + subscribes[1] = sub2; + streams.setSubscribes(subscribes); + + manualSpec.setStreams(streams); + + //assertEquals(manualSpec.getStreams(), spec.getStreams()); + + Parameters[] parameters = new Parameters[1]; + Parameters par1 = new Parameters(); + par1.setName("testParam1"); + par1.setValue("test-param-1"); + par1.setDescription("test parameter 1"); + par1.setSourced_at_deployment(true); + par1.setDesigner_editable(true); + par1.setPolicy_editable(true); + par1.setPolicy_group("Test_Parameters"); + par1.setRequired(true); + par1.setType("string"); + parameters[0] = par1; + + manualSpec.setParameters(parameters); + + //assertEquals(manualSpec.getParameters(), spec.getParameters()); + + Auxilary auxilary = new Auxilary(); + HealthCheck healthcheck = new HealthCheck(); + healthcheck.setInterval("300s"); + healthcheck.setTimeout("120s"); + healthcheck.setScript("/etc/init.d/nagios status"); + healthcheck.setType("docker"); + auxilary.setHealthcheck(healthcheck); + + Volumes[] volumes = new Volumes[1]; + Volumes vol1 = new Volumes(); + Container con1 = new Container(); + con1.setBind("/opt/app/manager/config/hostname"); + Host host1 = new Host(); + host1.setPath("/etc/hostname"); + host1.setMode("ro"); + vol1.setContainer(con1); + vol1.setHost(host1); + + + volumes[0] = vol1; + + auxilary.setVolumes(volumes); + + ArrayList<Object> ports = new ArrayList(); + ports.add("80:90"); + ports.add("99:99"); + + TreeMap<String, String> dataBases = new TreeMap<String, String>(); + dataBases.put("TestDB1", "PGaaS"); + dataBases.put("TestDB2", "PGaaS"); + auxilary.setDatabases(dataBases); + + Policy pol = new Policy(); + pol.setTrigger_type("docker"); + pol.setScript_path("/opt/app/manager/bin/reconfigure.sh"); + auxilary.setPolicy(pol); + + auxilary.setPorts(ports); + + manualSpec.setAuxilary(auxilary); + + //assertEquals(manualSpec.getAuxilary(), spec.getAuxilary()); + + Artifacts[] artifacts = new Artifacts[1]; + Artifacts art = new Artifacts(); + art.setType("docker image"); + art.setUri("test.tester"); + + artifacts[0] = art; + manualSpec.setArtifacts(artifacts); + + //assertEquals(manualSpec.getArtifacts(), spec.getArtifacts()); + } + + /** + * Tosca definition test. + */ + @Test + public void toscaDefinitionTest() { + ComponentSpec cs = new ComponentSpec(); + TestComponentSpec test = new TestComponentSpec(); + cs.createComponentSpecFromString(test.getCs()); + Blueprint bp = new Blueprint(); + bp = bp.createBlueprint(cs, "", 'o', "", ""); + + assertEquals(bp.getTosca_definitions_version(), "cloudify_dsl_1_3"); + } + + /** + * Imports test. + */ + @Test + public void importsTest() { + ComponentSpec cs = new ComponentSpec(); + TestComponentSpec test = new TestComponentSpec(); + cs.createComponentSpecFromString(test.getCs()); + + Blueprint bp = new Blueprint(); + bp = bp.createBlueprint(cs, "", 'o', "", ""); + + ArrayList<String> imps = new ArrayList<String>(); + + imps.add("http://www.getcloudify.org/spec/cloudify/3.4/types.yaml"); + imps.add("https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.5/k8splugin_types.yaml"); + imps.add("https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/dcaepolicyplugin/2.3.0/dcaepolicyplugin_types.yaml"); + assertEquals(bp.getImports(), imps); + } + + @Test + public void inputTest() { + ComponentSpec cs = new ComponentSpec(); + cs.createComponentSpecFromFile("TestCases/testComponentSpec.json"); + + Blueprint bp = new Blueprint(); + bp = bp.createBlueprint(cs, "", 'o', "", ""); + + TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<String, LinkedHashMap<String, Object>>(); + + //mr inputs + LinkedHashMap<String, Object> stringType = new LinkedHashMap<String, Object>(); + stringType.put("type", "string"); + + + //necessary inputs + LinkedHashMap<String, Object> tag = new LinkedHashMap<String, Object>(); + tag.put("type", "string"); + String tester = "test.tester"; + tag.put("default", '"' + tester + '"'); + String tagVersion = "tag_version"; + inputs.put("tag_version", tag); + + inputs.put("log_directory", stringType); + + LinkedHashMap cert = new LinkedHashMap(); + cert.put("type", "string"); + cert.put("default", ""); + inputs.put("cert_directory", cert); + + LinkedHashMap<String, Object> env = new LinkedHashMap(); + env.put("default", "{}"); + inputs.put("envs", env); + + LinkedHashMap port = new LinkedHashMap(); + port.put("type", "string"); + port.put("description", "Kubernetes node port on which collector is exposed"); + port.put("default", "99"); + inputs.put("external_port", port); + + LinkedHashMap<String, Object> rep = new LinkedHashMap<String, Object>(); + rep.put("type", "integer"); + rep.put("description", "number of instances"); + rep.put("default", 1); + inputs.put("replicas", rep); + + LinkedHashMap<String, Object> aaf = new LinkedHashMap(); + aaf.put("type", "boolean"); + aaf.put("default", false); + inputs.put("use_tls", aaf); + + //parmaeter input + LinkedHashMap<String, Object> test = new LinkedHashMap<String, Object>(); + test.put("type", "string"); + String testParam = "test-param-1"; + test.put("default", '"' + testParam + '"'); + inputs.put("testParam1", test); + + //mr/dr inputs + inputs.put("TEST-PUB-DR_feed0_client_role", stringType); + inputs.put("TEST-PUB-DR_feed0_password", stringType); + inputs.put("TEST-PUB-DR_feed0_username", stringType); + inputs.put("TEST-PUB-MR_topic1_aaf_password", stringType); + inputs.put("TEST-PUB-MR_topic1_aaf_username", stringType); + inputs.put("TEST-PUB-MR_topic1_client_role", stringType); + inputs.put("TEST-SUB-DR_feed1_client_role", stringType); + inputs.put("TEST-SUB-DR_feed1_password", stringType); + inputs.put("TEST-SUB-DR_feed1_username", stringType); + inputs.put("TEST-SUB-MR_topic0_client_role", stringType); + inputs.put("TEST-SUB-MR_topic2_aaf_password", stringType); + inputs.put("TEST-SUB-MR_topic2_aaf_username", stringType); + inputs.put("namespace", stringType); + inputs.put("idn_fqdn", cert); + inputs.put("feed0_name", stringType); + inputs.put("feed1_name", stringType); + inputs.put("topic0_name", stringType); + inputs.put("topic1_name", stringType); + + LinkedHashMap<String, Object> cpu = new LinkedHashMap(); + cpu.put("type", "string"); + cpu.put("default", "250m"); + inputs.put("test.component.spec_cpu_limit", cpu); + inputs.put("test.component.spec_cpu_request", cpu); + + LinkedHashMap<String, Object> mem = new LinkedHashMap(); + mem.put("type", "string"); + mem.put("default", "128Mi"); + inputs.put("test.component.spec_memory_limit", mem); + inputs.put("test.component.spec_memory_request", mem); + + assertEquals(true, true); + } + @Test + public void interfaceTest() { + ComponentSpec cs = new ComponentSpec(); + cs.createComponentSpecFromFile("TestCases/testComponentSpec.json"); + + Blueprint bp = new Blueprint(); + bp = bp.createBlueprint(cs, "", 'o', "", ""); + + OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec"); + + OnapNode testNode = new OnapNode(); + + //set the type + testNode.setType("dcae.nodes.ContainerizedPlatformComponent"); + + ArrayList<String> ports = new ArrayList<String>(); + ports.add("concat: [\"80:\", {get_input: external_port }]"); + ports.add("concat: [\"99:\", {get_input: external_port }]"); + assertEquals(true, true); + } + + @Test + public void parametersTest() { + ComponentSpec cs = new ComponentSpec(); + cs.createComponentSpecFromFile("TestCases/testComponentSpec.json"); + + Blueprint bp = new Blueprint(); + bp = bp.createBlueprint(cs, "", 'o', "", ""); + + OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec"); + + GetInput par = (GetInput) node.getProperties().getApplication_config().getParams().get("testParam1"); + assertEquals(par.getGet_input(), "testParam1"); + } + + @Test + public void streamPublishesTest() { + ComponentSpec cs = new ComponentSpec(); + cs.createComponentSpecFromFile("TestCases/testComponentSpec.json"); + + Blueprint bp = new Blueprint(); + bp = bp.createBlueprint(cs, "", 'o', "", ""); + + OnapNode node = (OnapNode) bp.getNode_templates().get("test.component.spec"); + + boolean test = false; + if(!node.getProperties().getApplication_config().getStreams_publishes().isEmpty()) { + test = true; + System.out.println("tst"); + } + + assertEquals(true, test); + } + @Test + public void dmaapPluginTest() { + ComponentSpec cs = new ComponentSpec(); + cs.createComponentSpecFromFile("TestCases/testComponentSpec.json"); + + Blueprint bp = new Blueprint(); + bp = bp.createBlueprint(cs, "", 'd', "", ""); + + DmaapNode dmaap = (DmaapNode) bp.getNode_templates().get("test.component.spec"); + + //check if the stream publishes and subscribes are not null to see if the dmaap plugin was invoked properly + boolean d = false; + + if(dmaap.getProperties().getStreams_publishes() != null || dmaap.getProperties().getStreams_subscribes() != null) { + d = true; + } + assertEquals(true, d); + } + + @Test + public void testPrintInstructionsBlueprintCommand() { + BlueprintCommand objUnderTest = new BlueprintCommand(); + CommandLine cli = new CommandLine(objUnderTest); + PrintStream mockStdOutWriter = Mockito.mock(PrintStream.class); + ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); + cli.usage(mockStdOutWriter); + verify(mockStdOutWriter, times(1)).print(any(Object.class)); + + } + + @Test + public void testPrintInstructionsPolicyCommand() { + PolicyCommand objUnderTest = new PolicyCommand(); + CommandLine cli = new CommandLine(objUnderTest); + PrintStream mockStdOutWriter = Mockito.mock(PrintStream.class); + ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); + cli.usage(mockStdOutWriter); + verify(mockStdOutWriter, times(1)).print(any(Object.class)); + } + + @Test + public void testPolicyModels() { + ComponentSpec cs = new ComponentSpec(); + cs.createComponentSpecFromFile("TestCases/testComponentSpec.json"); + + PolicyModel p = new PolicyModel(); + p.createPolicyModels(cs, "TestModels"); + + assertEquals(true, true); + } +} diff --git a/mod/bpgenerator/version.properties b/mod/bpgenerator/version.properties new file mode 100644 index 0000000..755adf7 --- /dev/null +++ b/mod/bpgenerator/version.properties @@ -0,0 +1,6 @@ +major=1 +minor=2 +patch=1 +base_version=${major}.${minor}.${patch} +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT |