JSON转换(从动态json中提取值并进行转换)

时间:2019-06-20 04:36:23

标签: java json

我将在请求JSON中传递多个卷,如下所示。我如何修改下面的SPEC以适合它,以便可以选择动态多个卷并对其进行转换。我也添加了代码,下面是我通过的两个卷

"resourceTypeBSProperties": [
              {
                "type": "TEST1",
                "IOPS": "1000",
                "kmsKey": "aws ckms id",
                "size": "30",
                "isEncryptionRequired": "true",
                "mountPoint": "/opt/abc"
              },
              {
                "type": "TEST2",
                "kmsKey": "aws ckms id",
                "size": "30",
                "isEncryptionRequired": "true",
                "mountPoint": "/opt/abc"
              }

API Spec适用于单个卷,但不适用于多个卷。如何更改SPEC以及代码中需要进行哪些更改。

Request JSON - ##

        {
          "number": "RM000001",
          "variables": {
            "apiName": "provComputeVM",
            "serviceName": "Virtual Machines",
            "provider": "Amazon",
            "applicationName": "TEST",
            "environmentType": "TEST",
            "platfrom": "Linux",
            "noOfInstances": "1",
            "availabilityZone": "North Carolina",
            "resourceTypeCompute": "Compute",
            "computeName": "VMTest",
            "instanceType": "Small Instance (m1.small)",
            "servertype": "Application Server",
            "HostName": "HN546GDA455",
            "Tenancy": "Default",
            "EnableTerminationProtection": "true",
            "SecurityGroups": [
              "sg-135355",
              "sg-135356"
            ],
            "Subnet": [
              "subnet-000001",
              "subnet-000002"
            ],
            "resourceTypeOS": "OS",
            "OsName": " Redhat Linux",
            "resourceTypeBS": "Block Storage",
            "resourceTypeBSProperties": [
              {
                "type": "TEST1",
                "IOPS": "1000",
                "kmsKey": "aws ckms id",
                "size": "30",
                "isEncryptionRequired": "true",
                "mountPoint": "/opt/abc"
              },
              {
                "type": "TEST2",
                "kmsKey": "aws ckms id",
                "size": "30",
                "isEncryptionRequired": "true",
                "mountPoint": "/opt/abc"
              }
            ],
          }
        }

API SPEC-(预配置)

 {
          "type": "object",
          "$schema": "http://TESTAPI/api/provision/compute",
          "properties": {
            "genericDetails": {
              "apiName": {
                "type": "String",
                "dataSource": "External",
                "description": "",
                "allowedValues": [
                  "Provisioning"
                ],
                "rquirementFlag": "mandatory"
              },
              "requestId": {
                "type": "String",
                "dataSource": "External",
                "description": "Uniquely identifies the request in SNOW",
                "sampleValue": "RITM00167913",
                "rquirementFlag": "mandatory"
              },
              "serviceName": {
                "type": "String",
                "dataSource": "External",
                "description": "",
                "allowedValues": [
                  "Virtual Machine"
                ],
                "rquirementFlag": "mandatory"
              },
              "applicationName": {
                "type": "String",
                "dataSource": "External",
                "constraints": "Needs to be  on boarded into CAP",
                "description": "",
                "rquirementFlag": "mandatory"
              },
            },
            "requestSpecificDetails": {
              "zones": {
                "type": "String",
                "dataSource": "External",
                "constraints": "zones",
                "description": "",
                "rquirementFlag": "optional"
              },
              "endDate": {
                "type": "String",
                "dataSource": "External",
                "constraints": "Needs to be  on boarded into CAP",
                "description": "End date of virtual machine",
                "rquirementFlag": "optional"
              },
              "location": {
                "type": "String",
                "dataSource": "External",
                "constraints": "location",
                "description": "",
                "rquirementFlag": "optional"
              },
              "provider": {
                "type": "String",
                "dataSource": "External",
                "description": "",
                "allowedValues": [
                  "Amazon",
                  "Azure"
                ],
                "rquirementFlag": "mandatory"
              },

              "environment": {
                "type": "String",
                "dataSource": "External",
                "constraints": "Needs to be  on boarded into CAP",
                "description": "Application environment.",
                "rquirementFlag": "optional"
              },
              "environmentType": {
                "type": "String",
                "dataSource": "External",
                "constraints": "Needs to be  on boarded into CAP",
                "description": "",
                "rquirementFlag": "mandatory"
              },
              "resourceTypeList": {
                "type": "List<CAP::ResourceType>",
                "dataSource": "External",
                "description": "Collection of resources to be provisioned",
                "ResourceTypes": [
                  {
                    "resource": [
                      {
                        "resource": {
                          "type": "List<String>",
                          "dataSource": "External",
                          "description": "",
                          "rquirementFlag": "mandatory"
                        },
                        "Properties": {
                          "tags": {
                            "type": "List<tag name, value>",
                            "dataSource": "External",
                            "description": "",
                            "rquirementFlag": "optional"
                          },
                          "Subnet": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "ID of the subnet that the ec2 instance will reside into",
                            "dependendsOn": [
                              "VPC"
                            ],
                            "propertyType": "Config Resource",
                            "rquirementFlag": "mandatory"
                          },
                          "Tenancy": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "AWS EC2 tenancy",
                            "defaultValue": "default",
                            "propertyType": "Config Attribute",
                            "allowedValues": [
                              "default",
                              "dedicated",
                              "host"
                            ],
                            "rquirementFlag": "optional"
                          },
                          "iamRole": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "AWS reference ID of IAM role to be assigned.",
                            "propertyType": "Config Resource",
                            "rquirementFlag": "optional"
                          },
                          "Vm Alias": {
                            "type": "String",
                            "length": 15,
                            "dataSource": "External",
                            "description": "",
                            "sampleValue": "myDB",
                            "externalName": "Name",
                            "propertyType": "Config Attribute",
                            "rquirementFlag": "mandatory"
                          },
                          "schedule": {
                            "type": "List<actionName, schedulePattern>",
                            "dataSource": "External",
                            "properties": {
                              "actionName": {
                                "type": "String",
                                "dataSource": "External",
                                "description": "Name of life cycle action to be scheduled",
                                "allowedValues": [
                                  "start",
                                  "stop"
                                ],
                                "rquirementFlag": "mandatory"
                              },
                              "schedulePattern": {
                                "type": "String",
                                "dataSource": "External",
                                "description": "",
                                "sampleValue": "0 15 10 ? * *",
                                "rquirementFlag": "mandatory"
                              }
                            },
                            "description": "",
                            "propertyType": "Config Attribute",
                            "rquirementFlag": "optional"
                          },
                          "sshKeyName": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "",
                            "propertyType": "Config Resource",
                            "rquirementFlag": "optional"
                          },
                          "Server Types": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "",
                            "propertyType": "Config Resource",
                            "rquirementFlag": "mandatory"
                          },
                          "Security Group": {
                            "type": "List<String>",
                            "dataSource": "Internal And External",
                            "description": "Reference ID's",
                            "dependendsOn": [
                              "VPC"
                            ],
                            "propertyType": "Config Resource",
                            "rquirementFlag": "optional"
                          },
                          "Termination Protection": {
                            "type": "Boolean",
                            "dataSource": "External",
                            "description": "",
                            "defaultValue": "false",
                            "externalName": "Termination Protection",
                            "propertyType": "Config Attribute",
                            "allowedValues": [
                              "true",
                              "false"
                            ],
                            "rquirementFlag": "optional"
                          }
                        }
                      }
                    ],
                    "resourceType": "Compute",
                    "rquirementFlag": "mandatory"
                  },
                  {
                    "resource": [
                      {
                        "resource": {
                          "type": "List<String>",
                          "dataSource": "External",
                          "description": "",
                          "rquirementFlag": "mandatory"
                        },
                        "properties": {
                          "name": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "Name of the resource",
                            "allowedValues": [
                              "RHL 6.9  or any other OS available in SNOW"
                            ],
                            "rquirementFlag": "mandatory"
                          }
                        }
                      }
                    ],
                    "resourceType": "OS",
                    "rquirementFlag": "mandatory"
                  },
                  {
                    "resource": [
                      {
                        "resource": {
                          "type": "List<String>",
                          "dataSource": "External",
                          "description": "",
                          "rquirementFlag": "mandatory"
                        },
                        "Properties": {
                          "iops": {
                            "type": "Integer",
                            "dataSource": "External",
                            "description": "",
                            "dependendsOn": [
                              "Block Storage:type"
                            ],
                            "rquirementFlag": "optional"
                          },
                          "size": {
                            "type": "Integer",
                            "dataSource": "External",
                            "description": "size of volume in GB",
                            "rquirementFlag": "mandatory"
                          },
                          "tags": {
                            "type": "List<tag name, vlue>",
                            "dataSource": "External",
                            "description": "",
                            "rquirementFlag": "optional"
                          },
                          "type": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "AWS volume type required",
                            "allowedValues": [
                              "TEST",
                              "TEST1",
                              "TEST2"
                            ],
                            "rquirementFlag": "mandatory"
                          },
                          "kmsKey": {
                            "type": "string",
                            "dataSource": "External",
                            "description": "",
                            "rquirementFlag": "optional"
                          },
                          "driveName": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "drive name for volume mounting",
                            "rquirementFlag": "mandatory"
                          },
                          "mountPoint": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "",
                            "dependendsOn": [
                              "OS"
                            ],
                            "rquirementFlag": "mandatory"
                          },
                          "isEncryptionRequired": {
                            "type": "Boolean",
                            "dataSource": "External",
                            "description": "",
                            "rquirementFlag": "optional"
                          }
                        }
                      }
                    ],
                    "description": "",
                    "resourceType": "Block Storage",
                    "rquirementFlag": "optional"
                  },
                  {
                    "comments": "",
                    "resource": [
                      {
                        "resource": {
                          "type": "List<String>",
                          "dataSource": "External",
                          "description": "",
                          "rquirementFlag": "mandatory"
                        },
                        "Properties": {
                          "name": {
                            "type": "String",
                            "dataSource": "External",
                            "description": "Name of the monitoring resource",
                            "allowedValues": [
                              "Cloudwatch"
                            ],
                            "rquirementFlag": "mandatory"
                          },
                          "cpuUtilization": {
                            "type": "Integer",
                            "default": "70",
                            "dataSource": "External",
                            "description": "",
                            "rquirementFlag": "optional"
                          },
                          "memoryUtilization": {
                            "type": "Integer",
                            "default": "70",
                            "dataSource": "External",
                            "description": "",
                            "rquirementFlag": "optional"
                          }
                        }
                      }
                    ],
                    "resourceType": "Monitoring",
                    "rquirementFlag": "optional"
                  }
                ],
                "rquirementFlag": "mandatory"
              },
              "providerAccountId": {
                "type": "Integer",
                "dataSource": "External",
                "constraints": "",
                "description": "",
                "rquirementFlag": "mandatory"
              },
              "providerManagedService": {
                "type": "boolean",
                "dataSource": "External",
                "description": "",
                "defaultValue": "false",
                "rquirementFlag": "mandatory"
              }
            }
          },
          "jsonTransformerMap": {
            "genericDetails.apiName": "apiName",
            "genericDetails.requestId": "number",
            "genericDetails.serviceName": "serviceName",
            "genericDetails.applicationName": "applicationName",
            "genericDetails.changeRequestId": "changeRequestId",
            "requestSpecificDetails.location": "availabilityZone",
            "requestSpecificDetails.environmentType": "environmentType",
            "requestSpecificDetails.providerAccountId": "providerAccountId",
            "requestSpecificDetails.resourceTypeList[0].resources[0].resource[0]": "instanceType",
            "requestSpecificDetails.resourceTypeList[1].resources[0].resource[0]": "OsName",
            "requestSpecificDetails.resourceTypeList[2].resources[0].resource[0]": "type",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.Name": "computeName",
            "requestSpecificDetails.resourceTypeList[1].resources[0].Properties.name": "OsName",
            "requestSpecificDetails.resourceTypeList[2].resources[0].Properties.iops": "IOPS",
            "requestSpecificDetails.resourceTypeList[2].resources[0].Properties.size": "size",
            "requestSpecificDetails.resourceTypeList[2].resources[0].Properties.type": "type",
            "requestSpecificDetails.resourceTypeList[2].resources[0].Properties.kmsKey": "kmsKey",
            "requestSpecificDetails.resourceTypeList[2].resources[0].Properties.fileMount": "mountPoint",
            "requestSpecificDetails.resourceTypeList[2].resources[0].Properties.isEncryptionRequired": "isEncryptionRequired",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.Tenancy": "Tenancy",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.iamRole": "iamRole",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.Subnet": "Subnet",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.Host Name": "Host Name",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.sshKeyName": "sshKeyName",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.tags[0].key": "key",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.Server Types": "Server Types",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.instanceType": "instanceType",
            "requestSpecificDetails.resourceTypeList[2].resources[0].Properties.isMountRequired": "isMountRequired",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.Security Group[index]": "SecurityGroups[i]",
            "requestSpecificDetails.resourceTypeList[0].resources[0].Properties.Termination Protection": "EnableTerminationProtection"
          },
          "Business Logic Data": {
            "executionMethod": "populateVMProvisioningData",
            "locationCategory": "Zone",
            "requiresPreApiExecutionTask": "true",
            "customTransformationFunction": ""
          },
          "resultantJsonStructure": {
            "genericDetails": {
              "apiName": "",
              "requestId": "",
              "serviceName": "",
              "applicationName": "",
              "changeRequestId": ""
            },
            "requestSpecificDetails": {
              "zones": "",
              "endDate": "",
              "location": "",
              "provider": "",
              "costCenter": "",
              "environment": "",
              "pricingModel": "",
              "noOfInstances": "1",
              "environmentType": "",
              "resourceTypeList": [
                {
                  "resources": [
                    {
                      "resource": [

                      ],
                      "Properties": {
                        "Name": "",
                        "tags": [
                          {
                            "key": "",
                            "value": ""
                          }
                        ],
                        "Subnet": "",
                        "Tenancy": "",
                        "iamRole": "",
                        "schedule": [
                          {
                            "action": "",
                            "schedulePattern": ""
                          },
                          {
                            "action": "",
                            "schedulePattern": ""
                          }
                        ],
                        "Host Name": "",
                        "sshKeyName": "",
                        "Server Types": "",
                        "instanceType": "",
                        "Security Group": [

                        ],
                        "Termination Protection": ""
                      }
                    }
                  ],
                  "resourceType": "Compute"
                },
                {
                  "resources": [
                    {
                      "resource": [

                      ],
                      "Properties": {
                        "name": ""
                      }
                    }
                  ],
                  "resourceType": "OS"
                },
                {
                  "resources": [
                    {
                      "resource": [

                      ],
                      "Properties": {
                        "iops": "",
                        "size": "",
                        "type": "",
                        "kmsKey": "",
                        "driveName": "",
                        "fileMount": "",
                        "volumeTags": [

                        ],
                        "isMountRequired": "",
                        "isEncryptionRequired": ""
                      }
                    }
                  ],
                  "resourceType": "Block Storage"
                }
              ],
              "providerAccountId": "",
              "providerManagedService": ""
            }
          }
        }

0 个答案:

没有答案