diff --git a/conf/cm-cicada.yaml b/conf/cm-cicada.yaml index aa170e5..3369fcb 100644 --- a/conf/cm-cicada.yaml +++ b/conf/cm-cicada.yaml @@ -27,14 +27,6 @@ cm-cicada: schema: http login: default password: default - - id: tumblebug_api - type: http - description: TumbleBug API - host: 192.168.110.14 - port: 1323 - schema: http - login: default - password: default dag_directory_host: "./_airflow/airflow-home/dags" dag_directory_container: "/usr/local/airflow/dags" # Use dag_directory_host for dag_directory_container, if this value is empty listen: diff --git a/dao/taskComponent.go b/dao/taskComponent.go index f4e368d..c6b90cc 100644 --- a/dao/taskComponent.go +++ b/dao/taskComponent.go @@ -61,10 +61,12 @@ func TaskComponentGetList(page int, row int) (*[]model.TaskComponent, error) { } func TaskComponentCreate(taskComponent *model.TaskComponent) (*model.TaskComponent, error) { - taskComponent.CreatedAt = time.Now() - taskComponent.UpdatedAt = time.Now() + now := time.Now() + + taskComponent.CreatedAt = now + taskComponent.UpdatedAt = now - result := db.DB.Create(taskComponent) + result := db.DB.Session(&gorm.Session{SkipHooks: true}).Create(taskComponent) err := result.Error if err != nil { return nil, err @@ -74,6 +76,8 @@ func TaskComponentCreate(taskComponent *model.TaskComponent) (*model.TaskCompone } func TaskComponentUpdate(taskComponent *model.TaskComponent) error { + taskComponent.UpdatedAt = time.Now() + result := db.DB.Model(&model.TaskComponent{}).Where("id = ?", taskComponent.ID).Updates(taskComponent) err := result.Error if err != nil { diff --git a/dao/workflow.go b/dao/workflow.go index 952d26d..51433a1 100644 --- a/dao/workflow.go +++ b/dao/workflow.go @@ -9,10 +9,12 @@ import ( ) func WorkflowCreate(workflow *model.Workflow) (*model.Workflow, error) { - workflow.CreatedAt = time.Now() - workflow.UpdatedAt = time.Now() + now := time.Now() + + workflow.CreatedAt = now + workflow.UpdatedAt = now - result := db.DB.Create(workflow) + result := db.DB.Session(&gorm.Session{SkipHooks: true}).Create(workflow) err := result.Error if err != nil { return nil, err diff --git a/lib/airflow/example/task_component/beetle_task_infra_migration.json b/lib/airflow/example/task_component/beetle_task_infra_migration.json index e3b7e71..f23e1db 100644 --- a/lib/airflow/example/task_component/beetle_task_infra_migration.json +++ b/lib/airflow/example/task_component/beetle_task_infra_migration.json @@ -1,97 +1,7 @@ { - "name": "beetle_task_infra_migration", - "description": "Do infra migration with beetle.", - "data": { - "options": { - "api_connection_id": "beetle_api", - "endpoint": "/beetle/migration/ns/mig01/mci", - "method": "POST", - "request_body": "{\n \"name\": \"recommended-infra01\",\n \"installMonAgent\": \"no\",\n \"label\": \"DynamicVM\",\n \"systemLabel\": \"\",\n \"description\": \"Made in CB-TB\",\n \"vm\": [\n {\n \"name\": \"recommended-vm01\",\n \"subGroupSize\": \"3\",\n \"label\": \"DynamicVM\",\n \"description\": \"Description\",\n \"commonSpec\": \"azure+koreacentral+standard_b4ls_v2\",\n \"commonImage\": \"azure+koreacentral+ubuntu22.04\",\n \"rootDiskType\": \"default\",\n \"rootDiskSize\": \"default\",\n \"vmUserPassword\": \"test\",\n \"connectionName\": \"azure-koreacentral\"\n }\n ]\n}" - }, - "param_option": { - "params": { - "required": ["name", "vm"], - "properties": { - "description": { - "type": "string", - "example": "Made in CB-TB" - }, - "installMonAgent": { - "description": "InstallMonAgent Option for CB-Dragonfly agent installation ([yes/no] default:yes)", - "type": "string", - "default": "yes", - "enum": ["yes", "no"], - "example": "no" - }, - "label": { - "description": "Label is for describing the mcis in a keyword (any string can be used)", - "type": "string", - "example": "DynamicVM" - }, - "name": { - "type": "string", - "example": "mcis01" - }, - "systemLabel": { - "description": "SystemLabel is for describing the mcis in a keyword (any string can be used) for special System purpose", - "type": "string", - "example": "" - }, - "vm": { - "type": "array", - "items": { - "required": ["commonImage", "commonSpec"], - "properties": { - "commonImage": { - "description": "CommonImage is field for id of a image in common namespace", - "type": "string", - "example": "ubuntu18.04" - }, - "commonSpec": { - "description": "CommonSpec is field for id of a spec in common namespace", - "type": "string", - "example": "aws-ap-northeast-2-t2-small" - }, - "connectionName": { - "description": "if ConnectionName is given, the VM tries to use associtated credential. if not, it will use predefined ConnectionName in Spec objects", - "type": "string" - }, - "description": { - "type": "string", - "example": "Description" - }, - "label": { - "type": "string", - "example": "DynamicVM" - }, - "name": { - "description": "VM name or subGroup name if is (not empty) && (> 0). If it is a group, actual VM name will be generated with -N postfix.", - "type": "string", - "example": "g1-1" - }, - "rootDiskSize": { - "description": "\"default\", Integer (GB): [\"50\", ..., \"1000\"]", - "type": "string", - "example": "default, 30, 42, ..." - }, - "rootDiskType": { - "description": "\"\", \"default\", \"TYPE1\", AWS: [\"standard\", \"gp2\", \"gp3\"], Azure: [\"PremiumSSD\", \"StandardSSD\", \"StandardHDD\"], GCP: [\"pd-standard\", \"pd-balanced\", \"pd-ssd\", \"pd-extreme\"], ALIBABA: [\"cloud_efficiency\", \"cloud\", \"cloud_essd\"], TENCENT: [\"CLOUD_PREMIUM\", \"CLOUD_SSD\"]", - "type": "string", - "example": "default, TYPE1, ..." - }, - "subGroupSize": { - "description": "if subGroupSize is (not empty) && (> 0), subGroup will be gernetad. VMs will be created accordingly.", - "type": "string", - "example": "3" - }, - "vmUserPassword": { - "type": "string" - } - } - } - } - } - } - } - } + "name": "beetle_task_recommend_infra", + "description": "Do infra recommendation with beetle.", + "api_connection_id": "beetle_api", + "swagger_yaml_endpoint": "/beetle/api/doc.yaml", + "endpoint": "/migration/ns/{nsId}/mci" } diff --git a/lib/airflow/example/task_component/beetle_task_recommend_infra.json b/lib/airflow/example/task_component/beetle_task_recommend_infra.json index bc09cb7..480c140 100644 --- a/lib/airflow/example/task_component/beetle_task_recommend_infra.json +++ b/lib/airflow/example/task_component/beetle_task_recommend_infra.json @@ -1,587 +1,7 @@ { "name": "beetle_task_recommend_infra", "description": "Do infra recommendation with beetle.", - "data": { - "options": { - "api_connection_id": "beetle_api", - "endpoint": "/beetle/recommendation/mci", - "method": "POST", - "request_body": "{\n \"desiredProvider\": \"aws\",\n \"desiredRegion\": \"ap-northeast-2\",\n \"onpremiseInfraModel\": {\n \"network\": {\n \"ipv4Networks\": [\n \"172.26.240.0/20\"\n ],\n \"ipv6Networks\": [\n \"string\"\n ]\n },\n \"servers\": [\n {\n \"cpu\": {\n \"architecture\": \"x86_64\",\n \"cores\": 18,\n \"cpus\": 2,\n \"maxSpeed\": 3.6,\n \"model\": \"Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz\",\n \"threads\": 36,\n \"vendor\": \"GenuineIntel\"\n },\n \"dataDisks\": [\n {\n \"available\": 0,\n \"label\": \"string\",\n \"totalSize\": 1024,\n \"type\": \"SSD\",\n \"used\": 0\n }\n ],\n \"hostname\": \"string\",\n \"interfaces\": [\n {\n \"ipv4CidrBlocks\": [\n \"string\"\n ],\n \"ipv6CidrBlocks\": [\n \"string\"\n ],\n \"macAddress\": \"string\",\n \"mtu\": 0,\n \"name\": \"string\",\n \"state\": \"string\"\n }\n ],\n \"memory\": {\n \"available\": 0,\n \"totalSize\": 128,\n \"type\": \"DDR4\",\n \"used\": 0\n },\n \"os\": {\n \"id\": \"ubuntu\",\n \"idLike\": \"debian\",\n \"name\": \"Ubuntu\",\n \"prettyName\": \"Ubuntu 22.04.3 LTS\",\n \"version\": \"22.04.3 LTS (Jammy Jellyfish)\",\n \"versionCodename\": \"jammy\",\n \"versionId\": \"22.04\"\n },\n \"rootDisk\": {\n \"available\": 0,\n \"label\": \"string\",\n \"totalSize\": 1024,\n \"type\": \"SSD\",\n \"used\": 0\n },\n \"routingTable\": [\n {\n \"destination\": \"string\",\n \"gateway\": \"string\",\n \"interface\": \"string\",\n \"linkState\": \"string\",\n \"metric\": 0,\n \"protocol\": \"string\",\n \"scope\": \"string\",\n \"source\": \"string\"\n }\n ]\n }\n ]\n }\n}" - }, - "param_option": { - "params": { - "required": [ - "servers" - ], - "properties": { - "servers": { - "type": "array", - "items": { - "type": "object", - "properties": { - "compute": { - "required": [ - "compute_resource", - "os" - ], - "properties": { - "compute_resource": { - "type": "object", - "required": [ - "cpu", - "memory" - ], - "properties": { - "cpu": { - "type": "object", - "required": [ - "cores", - "cpus", - "threads" - ], - "properties": { - "cache": { - "description": "KB", - "type": "integer" - }, - "cores": { - "description": "ea", - "type": "integer" - }, - "cpus": { - "description": "ea", - "type": "integer" - }, - "max_speed": { - "description": "MHz", - "type": "integer" - }, - "model": { - "type": "string" - }, - "threads": { - "description": "ea", - "type": "integer" - }, - "vendor": { - "type": "string" - } - } - }, - "data_disk": { - "type": "array", - "items": { - "type": "object", - "properties": { - "label": { - "type": "string" - }, - "size": { - "description": "GB", - "type": "integer" - }, - "type": { - "type": "string" - } - } - } - }, - "memory": { - "type": "object", - "required": [ - "size" - ], - "properties": { - "size": { - "description": "MB", - "type": "integer" - }, - "speed": { - "description": "MHz", - "type": "integer" - }, - "type": { - "type": "string" - } - } - }, - "root_disk": { - "type": "object", - "properties": { - "label": { - "type": "string" - }, - "size": { - "description": "GB", - "type": "integer" - }, - "type": { - "type": "string" - } - } - } - } - }, - "connection": { - "type": "array", - "items": { - "type": "object", - "properties": { - "keypair": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "private_key": { - "type": "string" - }, - "public_key": { - "type": "string" - } - } - } - } - } - }, - "os": { - "type": "object", - "required": [ - "os" - ], - "properties": { - "kernel": { - "type": "object", - "properties": { - "architecture": { - "type": "string" - }, - "release": { - "type": "string" - }, - "version": { - "type": "string" - } - } - }, - "node": { - "type": "object", - "properties": { - "hostname": { - "type": "string" - }, - "hypervisor": { - "type": "string" - }, - "machineid": { - "type": "string" - }, - "timezone": { - "type": "string" - } - } - }, - "os": { - "type": "object", - "required": [ - "release", - "vendor" - ], - "properties": { - "architecture": { - "type": "string" - }, - "name": { - "type": "string" - }, - "release": { - "type": "string" - }, - "vendor": { - "type": "string" - }, - "version": { - "type": "string" - } - } - } - } - } - } - }, - "gpu": { - "type": "object", - "properties": { - "drm": { - "type": "array", - "items": { - "type": "object", - "properties": { - "driver_date": { - "type": "string" - }, - "driver_description": { - "type": "string" - }, - "driver_name": { - "type": "string" - }, - "driver_version": { - "type": "string" - } - } - } - }, - "nvidia": { - "type": "array", - "items": { - "type": "object", - "properties": { - "device_attribute": { - "type": "object", - "properties": { - "cuda_version": { - "type": "string" - }, - "driver_version": { - "type": "string" - }, - "gpu_uuid": { - "type": "string" - }, - "product_architecture": { - "type": "string" - }, - "product_brand": { - "type": "string" - }, - "product_name": { - "type": "string" - } - } - }, - "performance": { - "type": "object", - "properties": { - "bar1_memory_total": { - "description": "mb", - "type": "integer" - }, - "bar1_memory_usage": { - "description": "percent", - "type": "integer" - }, - "bar1_memory_used": { - "description": "mb", - "type": "integer" - }, - "fb_memory_total": { - "description": "mb", - "type": "integer" - }, - "fb_memory_usage": { - "description": "percent", - "type": "integer" - }, - "fb_memory_used": { - "description": "mb", - "type": "integer" - }, - "gpu_usage": { - "description": "percent", - "type": "integer" - } - } - } - } - } - } - } - }, - "network": { - "type": "object", - "properties": { - "csp": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "nlb": { - "type": "array", - "items": { - "type": "object", - "properties": { - "description": { - "type": "string" - }, - "health_checker": { - "type": "string" - }, - "id": { - "type": "string" - }, - "listener": { - "type": "string" - }, - "name": { - "type": "string" - }, - "target_group": { - "type": "string" - } - } - } - }, - "security_group": { - "type": "array", - "items": { - "type": "object", - "properties": { - "description": { - "type": "string" - }, - "firewall_rule": { - "type": "array", - "items": { - "type": "object", - "properties": { - "action": { - "description": "allow, deny", - "type": "string" - }, - "direction": { - "description": "inbound, outbound", - "type": "string" - }, - "dst": { - "type": "string" - }, - "dst_ports": { - "type": "string" - }, - "priority": { - "description": "Lower has higher priority", - "type": "integer" - }, - "protocol": { - "description": "TCP, UDP, ICMP", - "type": "string" - }, - "src": { - "type": "string" - }, - "src_ports": { - "type": "string" - } - } - } - }, - "id": { - "type": "string" - }, - "name": { - "type": "string" - }, - "vnet_id": { - "type": "string" - } - } - } - }, - "vpc": { - "type": "array", - "items": { - "type": "object", - "properties": { - "address_space": { - "description": "IPv4 CIDR or IPv6 CIDR", - "type": "array", - "items": { - "type": "string" - } - }, - "dns_server": { - "type": "array", - "items": { - "type": "object", - "properties": { - "dns_server": { - "description": "IPv4 or IPv6 DNS Server Addresses", - "type": "array", - "items": { - "type": "string" - } - } - } - } - }, - "id": { - "type": "string" - }, - "region": { - "type": "string" - }, - "subnet": { - "type": "array", - "items": { - "type": "object", - "properties": { - "ipv4_cidr": { - "description": "IPv4 Network Address with CIDR Prefix Length", - "type": "string" - }, - "ipv6_cidr": { - "description": "IPv6 Network Address with CIDR Prefix Length", - "type": "string" - }, - "name": { - "type": "string" - } - } - } - } - } - } - } - } - }, - "host": { - "type": "object", - "properties": { - "dns": { - "type": "object", - "properties": { - "dns_server": { - "description": "IPv4 or IPv6 DNS Server Addresses", - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "firewall_rule": { - "type": "array", - "items": { - "type": "object", - "properties": { - "action": { - "description": "allow, deny", - "type": "string" - }, - "direction": { - "description": "inbound, outbound", - "type": "string" - }, - "dst": { - "type": "string" - }, - "dst_ports": { - "type": "string" - }, - "priority": { - "description": "Lower has higher priority", - "type": "integer" - }, - "protocol": { - "description": "TCP, UDP, ICMP", - "type": "string" - }, - "src": { - "type": "string" - }, - "src_ports": { - "type": "string" - } - } - } - }, - "network_interface": { - "type": "array", - "items": { - "type": "object", - "properties": { - "address": { - "type": "array", - "items": { - "type": "string" - } - }, - "gateway": { - "type": "array", - "items": { - "type": "string" - } - }, - "interface": { - "type": "string" - }, - "mac_address": { - "type": "string" - }, - "mtu": { - "type": "integer" - } - } - } - }, - "route": { - "type": "array", - "items": { - "type": "object", - "properties": { - "destination": { - "type": "string" - }, - "netmask": { - "type": "string" - }, - "next_hop": { - "type": "string" - } - } - } - } - } - } - } - }, - "storage": { - "type": "object", - "properties": { - "mount_point": { - "type": "object", - "properties": { - "mounted_information": { - "type": "array", - "items": { - "type": "object", - "properties": { - "destination": { - "type": "string" - }, - "filesystem": { - "type": "string" - }, - "option": { - "type": "string" - }, - "source": { - "type": "string" - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } + "api_connection_id": "beetle_api", + "swagger_yaml_endpoint": "/beetle/api/doc.yaml", + "endpoint": "/recommendation/mci" } diff --git a/lib/airflow/example/task_component/honeybee_register_target_info_to_source_group.json b/lib/airflow/example/task_component/honeybee_register_target_info_to_source_group.json index c58d50e..f603626 100644 --- a/lib/airflow/example/task_component/honeybee_register_target_info_to_source_group.json +++ b/lib/airflow/example/task_component/honeybee_register_target_info_to_source_group.json @@ -1,65 +1,7 @@ { "name": "honeybee_register_target_info_to_source_group", "description": "Register target information to the source group by honeybee.", - "data": { - "options": { - "api_connection_id": "honeybee_api", - "endpoint": "/honeybee/source_group/{sgId}/target", - "method": "POST", - "request_body": "" - }, - "param_option": { - "params": { - "required": [], - "properties": { - } - } - }, - "path_params": { - "required": [ - "sgId" - ], - "properties": { - "TargetInfo": { - "type": "object", - "required": [ - "id", - "resourceType" - ], - "properties": { - "description": { - "type": "string" - }, - "id": { - "type": "string" - }, - "label": { - "type": "string" - }, - "name": { - "type": "string" - }, - "resourceType": { - "type": "string" - }, - "systemLabel": { - "type": "string" - }, - "systemMessage": { - "type": "string" - }, - "targetAction": { - "type": "string" - }, - "targetStatus": { - "type": "string" - }, - "uid": { - "type": "string" - } - } - } - } - } - } + "api_connection_id": "honeybee_api", + "swagger_yaml_endpoint": "/honeybee/api/doc.yaml", + "endpoint": "/source_group/{sgId}/target" } diff --git a/lib/airflow/example/task_component/honeybee_task_get_infra_refined.json b/lib/airflow/example/task_component/honeybee_task_get_infra_refined.json index fe57c01..3581bbe 100644 --- a/lib/airflow/example/task_component/honeybee_task_get_infra_refined.json +++ b/lib/airflow/example/task_component/honeybee_task_get_infra_refined.json @@ -1,30 +1,7 @@ { "name": "honeybee_task_get_infra_refined", "description": "Get refined infra information from honeybee.", - "data": { - "options": { - "api_connection_id": "honeybee_api", - "endpoint": "/honeybee/source_group/{sgId}/infra/refined", - "method": "GET", - "request_body": "" - }, - "param_option": { - "params": { - "required": [], - "properties": { - } - }, - "path_params": { - "required": [ - "sgId" - ], - "properties": { - "sgId": { - "type": "string", - "description": "ID of the source group." - } - } - } - } - } + "api_connection_id": "honeybee_api", + "swagger_yaml_endpoint": "/honeybee/api/doc.yaml", + "endpoint": "/source_group/{sgId}/infra/refined" } diff --git a/lib/airflow/example/task_component/honeybee_task_import_infra.json b/lib/airflow/example/task_component/honeybee_task_import_infra.json index 8c4d0c5..01d325c 100644 --- a/lib/airflow/example/task_component/honeybee_task_import_infra.json +++ b/lib/airflow/example/task_component/honeybee_task_import_infra.json @@ -1,30 +1,7 @@ { "name": "honeybee_task_import_infra", "description": "Import infra information by honeybee.", - "data": { - "options": { - "api_connection_id": "honeybee_api", - "endpoint": "/honeybee/source_group/{sgId}/import/infra", - "method": "POST", - "request_body": "" - }, - "param_option": { - "params": { - "required": [], - "properties": { - } - } - }, - "path_params": { - "required": [ - "sgId" - ], - "properties": { - "sgId": { - "type": "string", - "description": "ID of the source group." - } - } - } - } + "api_connection_id": "honeybee_api", + "swagger_yaml_endpoint": "/honeybee/api/doc.yaml", + "endpoint": "/source_group/{sgId}/import/infra" } diff --git a/lib/airflow/example/workflow_template/migrate_infra_workflow.json b/lib/airflow/example/workflow_template/migrate_infra_workflow.json index dff7f4c..f453430 100644 --- a/lib/airflow/example/workflow_template/migrate_infra_workflow.json +++ b/lib/airflow/example/workflow_template/migrate_infra_workflow.json @@ -17,22 +17,13 @@ "dependencies": [] }, { - "name": "infra_get", - "task_component": "honeybee_task_get_infra_refined_for_recommendation_request", - "request_body": "", - "path_params": { - "sgId": "3e635238-0c4b-4f6e-9062-906f3dd5f571", + "name": "infra_recommend", + "task_component": "beetle_task_recommend_infra", + "request_body": "infra_import", + "query_params": { "CSP": "aws", "region": "ap-northeast-2" }, - "dependencies": [ - "infra_import" - ] - }, - { - "name": "infra_recommend", - "task_component": "beetle_task_recommend_infra", - "request_body": "infra_get", "dependencies": [ "infra_get" ] diff --git a/pkg/api/rest/docs/docs.go b/pkg/api/rest/docs/docs.go index 76c97de..334cb16 100644 --- a/pkg/api/rest/docs/docs.go +++ b/pkg/api/rest/docs/docs.go @@ -1622,7 +1622,7 @@ const docTemplate = `{ ], "properties": { "data": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData" + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData" }, "name": { "type": "string" @@ -1757,56 +1757,43 @@ const docTemplate = `{ } } }, - "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Options": { + "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure": { "type": "object", - "required": [ - "api_connection_id", - "endpoint", - "method", - "request_body" - ], "properties": { - "api_connection_id": { - "type": "string" - }, - "endpoint": { - "type": "string" - }, - "method": { - "type": "string" + "properties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef" + } }, - "request_body": { - "type": "string" + "required": { + "type": "array", + "items": { + "type": "string" + } } } }, - "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParamOption": { + "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef": { "type": "object", - "required": [ - "params" - ], "properties": { - "params": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params" + "items": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef" + }, + "properties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef" + } }, - "path_params": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params" - } - } - }, - "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params": { - "type": "object", - "required": [ - "properties", - "required" - ], - "properties": { - "properties": {}, "required": { "type": "array", "items": { "type": "string" } + }, + "type": { + "type": "string" } } }, @@ -1871,7 +1858,10 @@ const docTemplate = `{ "type": "string" }, "data": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData" + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData" + }, + "description": { + "type": "string" }, "id": { "type": "string" @@ -1884,18 +1874,34 @@ const docTemplate = `{ } } }, - "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData": { + "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData": { "type": "object", - "required": [ - "options", - "param_option" - ], "properties": { + "body_params": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure" + }, "options": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Options" + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentOptions" + }, + "path_params": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure" }, - "param_option": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParamOption" + "query_params": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure" + } + } + }, + "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentOptions": { + "type": "object", + "properties": { + "api_connection_id": { + "type": "string" + }, + "endpoint": { + "type": "string" + }, + "method": { + "type": "string" } } }, diff --git a/pkg/api/rest/docs/swagger.json b/pkg/api/rest/docs/swagger.json index 3313e4c..44a6e9d 100644 --- a/pkg/api/rest/docs/swagger.json +++ b/pkg/api/rest/docs/swagger.json @@ -1615,7 +1615,7 @@ ], "properties": { "data": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData" + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData" }, "name": { "type": "string" @@ -1750,56 +1750,43 @@ } } }, - "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Options": { + "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure": { "type": "object", - "required": [ - "api_connection_id", - "endpoint", - "method", - "request_body" - ], "properties": { - "api_connection_id": { - "type": "string" - }, - "endpoint": { - "type": "string" - }, - "method": { - "type": "string" + "properties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef" + } }, - "request_body": { - "type": "string" + "required": { + "type": "array", + "items": { + "type": "string" + } } } }, - "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParamOption": { + "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef": { "type": "object", - "required": [ - "params" - ], "properties": { - "params": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params" + "items": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef" + }, + "properties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef" + } }, - "path_params": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params" - } - } - }, - "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params": { - "type": "object", - "required": [ - "properties", - "required" - ], - "properties": { - "properties": {}, "required": { "type": "array", "items": { "type": "string" } + }, + "type": { + "type": "string" } } }, @@ -1864,7 +1851,10 @@ "type": "string" }, "data": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData" + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData" + }, + "description": { + "type": "string" }, "id": { "type": "string" @@ -1877,18 +1867,34 @@ } } }, - "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData": { + "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData": { "type": "object", - "required": [ - "options", - "param_option" - ], "properties": { + "body_params": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure" + }, "options": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Options" + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentOptions" + }, + "path_params": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure" }, - "param_option": { - "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParamOption" + "query_params": { + "$ref": "#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure" + } + } + }, + "github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentOptions": { + "type": "object", + "properties": { + "api_connection_id": { + "type": "string" + }, + "endpoint": { + "type": "string" + }, + "method": { + "type": "string" } } }, diff --git a/pkg/api/rest/docs/swagger.yaml b/pkg/api/rest/docs/swagger.yaml index 51ad0de..d5719d4 100644 --- a/pkg/api/rest/docs/swagger.yaml +++ b/pkg/api/rest/docs/swagger.yaml @@ -51,7 +51,7 @@ definitions: github_com_cloud-barista_cm-cicada_pkg_api_rest_model.CreateTaskComponentReq: properties: data: - $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData' + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData' name: type: string required: @@ -143,41 +143,31 @@ definitions: - data - name type: object - github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Options: + github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure: properties: - api_connection_id: - type: string - endpoint: - type: string - method: - type: string - request_body: - type: string - required: - - api_connection_id - - endpoint - - method - - request_body - type: object - github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParamOption: - properties: - params: - $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params' - path_params: - $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params' - required: - - params + properties: + additionalProperties: + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef' + type: object + required: + items: + type: string + type: array type: object - github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Params: + github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef: properties: - properties: {} + items: + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef' + properties: + additionalProperties: + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.PropertyDef' + type: object required: items: type: string type: array - required: - - properties - - required + type: + type: string type: object github_com_cloud-barista_cm-cicada_pkg_api_rest_model.SimpleMsg: properties: @@ -217,7 +207,9 @@ definitions: created_at: type: string data: - $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData' + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData' + description: + type: string id: type: string name: @@ -229,15 +221,25 @@ definitions: - id - name type: object - github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskData: + github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentData: properties: + body_params: + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure' options: - $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.Options' - param_option: - $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParamOption' - required: - - options - - param_option + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentOptions' + path_params: + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure' + query_params: + $ref: '#/definitions/github_com_cloud-barista_cm-cicada_pkg_api_rest_model.ParameterStructure' + type: object + github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskComponentOptions: + properties: + api_connection_id: + type: string + endpoint: + type: string + method: + type: string type: object github_com_cloud-barista_cm-cicada_pkg_api_rest_model.TaskDirectly: properties: diff --git a/pkg/api/rest/model/taskComponent.go b/pkg/api/rest/model/taskComponent.go index 31b91f8..0aad66a 100644 --- a/pkg/api/rest/model/taskComponent.go +++ b/pkg/api/rest/model/taskComponent.go @@ -7,34 +7,43 @@ import ( "time" ) -type Options struct { - APIConnectionID string `json:"api_connection_id" mapstructure:"api_connection_id" validate:"required"` - Endpoint string `json:"endpoint" mapstructure:"endpoint" validate:"required"` - Method string `json:"method" mapstructure:"method" validate:"required"` - RequestBody string `json:"request_body" mapstructure:"request_body" validate:"required"` +type PropertyDef struct { + Type string `json:"type"` + Required []string `json:"required,omitempty"` + Properties map[string]PropertyDef `json:"properties,omitempty"` + Items *PropertyDef `json:"items,omitempty"` } -type ParamOption struct { - Params Params `json:"params" mapstructure:"params" validate:"required"` - PathParams Params `json:"path_params" mapstructure:"path_params"` +type ParameterStructure struct { + Required []string `json:"required,omitempty"` + Properties map[string]PropertyDef `json:"properties,omitempty"` } -type TaskData struct { - Options Options `json:"options" mapstructure:"options" validate:"required"` - ParmaOption ParamOption `json:"param_option" mapstructure:"param_option" validate:"required"` +type TaskComponentOptions struct { + APIConnectionID string `json:"api_connection_id"` + Endpoint string `json:"endpoint"` + Method string `json:"method"` +} + +type TaskComponentData struct { + Options TaskComponentOptions `json:"options"` + BodyParams ParameterStructure `json:"body_params,omitempty"` + PathParams ParameterStructure `json:"path_params,omitempty"` + QueryParams ParameterStructure `json:"query_params,omitempty"` } type TaskComponent struct { - ID string `gorm:"primaryKey" json:"id" mapstructure:"id" validate:"required"` - Name string `gorm:"index:,column:name,unique;type:text collate nocase" json:"name" mapstructure:"name" validate:"required"` - Data TaskData `gorm:"column:data" json:"data" mapstructure:"data" validate:"required"` - CreatedAt time.Time `gorm:"column:created_at" json:"created_at" mapstructure:"created_at"` - UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" mapstructure:"updated_at"` + ID string `gorm:"primaryKey" json:"id" mapstructure:"id" validate:"required"` + Name string `gorm:"index:,column:name,unique;type:text collate nocase" json:"name" mapstructure:"name" validate:"required"` + Description string `gorm:"column:description" json:"description"` + Data TaskComponentData `gorm:"column:data" json:"data" mapstructure:"data" validate:"required"` + CreatedAt time.Time `gorm:"column:created_at;autoCreateTime:false" json:"created_at" mapstructure:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;autoCreateTime:false" json:"updated_at" mapstructure:"updated_at"` } type CreateTaskComponentReq struct { - Name string `json:"name" mapstructure:"name" validate:"required"` - Data TaskData `gorm:"column:data" json:"data" mapstructure:"data" validate:"required"` + Name string `json:"name" mapstructure:"name" validate:"required"` + Data TaskComponentData `gorm:"column:data" json:"data" mapstructure:"data" validate:"required"` } type Params struct { @@ -42,11 +51,11 @@ type Params struct { Properties interface{} `json:"properties" mapstructure:"properties" validate:"required"` } -func (d TaskData) Value() (driver.Value, error) { +func (d TaskComponentData) Value() (driver.Value, error) { return json.Marshal(d) } -func (d *TaskData) Scan(value interface{}) error { +func (d *TaskComponentData) Scan(value interface{}) error { if value == nil { return nil } diff --git a/pkg/api/rest/model/workflow.go b/pkg/api/rest/model/workflow.go index 1412428..3f2da61 100644 --- a/pkg/api/rest/model/workflow.go +++ b/pkg/api/rest/model/workflow.go @@ -84,8 +84,8 @@ type Workflow struct { ID string `gorm:"primaryKey" json:"id" mapstructure:"id" validate:"required"` Name string `gorm:"index:,column:name,unique;type:text collate nocase" json:"name" mapstructure:"name" validate:"required"` Data Data `gorm:"column:data" json:"data" mapstructure:"data" validate:"required"` - CreatedAt time.Time `gorm:"column:created_at" json:"created_at" mapstructure:"created_at"` - UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" mapstructure:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;autoCreateTime:false" json:"created_at" mapstructure:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;autoCreateTime:false" json:"updated_at" mapstructure:"updated_at"` } type CreateWorkflowReq struct { @@ -150,19 +150,19 @@ type TaskLog struct { Content string `json:"content,omitempty"` } type EventLogs struct { - EventLogs []EventLog `json:"event_logs"` - TotalEntries int `json:"total_entries"` + EventLogs []EventLog `json:"event_logs"` + TotalEntries int `json:"total_entries"` } type EventLog struct { - WorkflowRunID string `json:"workflow_run_id"` - RunID string `json:"run_id,omitempty"` - WorkflowID string `json:"workflow_id"` - TaskID string `json:"task_id"` - TaskName string `json:"task_name"` - Event string `json:"event,omitempty"` - When time.Time `json:"when,omitempty"` - Extra string `json:"extra,omitempty"` + WorkflowRunID string `json:"workflow_run_id"` + RunID string `json:"run_id,omitempty"` + WorkflowID string `json:"workflow_id"` + TaskID string `json:"task_id"` + TaskName string `json:"task_name"` + Event string `json:"event,omitempty"` + When time.Time `json:"when,omitempty"` + Extra string `json:"extra,omitempty"` } func (d Data) Value() (driver.Value, error) {