<service-logic
    xmlns='http://www.onap.org/sdnc/svclogic'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.onap.org/sdnc/svclogic ./svclogic.xsd' module='GENERIC-RESOURCE-API' version='${project.version}'>
    <method rpc='bbs-internet-profile-network-topology-operation-create-huawei' mode='sync'>
        <block atomic="true">
            <call module='GENERIC-RESOURCE-API' rpc='bbs-internet-profile-network-topology-operation-common-huawei' mode='sync' ></call>
            <execute plugin="org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode" method="sendRequest">
                <parameter name="templateFileName" value="`$prop.restapi.templateDir + '/bbs-internet-profile-operation.json'`" />
                <parameter name="restapiUrl" value="`$prop.sdncRestApi.thirdpartySdnc.url + '/CreateInternetProfileInstance'`" />
                <parameter name="contentType" value="application/json"/>
                <parameter name="httpMethod" value="post"/>
                <parameter name="responsePrefix" value="service-result"/>
                <outcome value='failure'>
                    <return status='failure'>
                        <parameter name='ack-final' value='Y'/>
                        <parameter name="error-code" value="500" />
                        <parameter name="error-message" value="Error failed to call CreateInternetProfileInstance" />
                    </return>
                </outcome>
                <outcome value='success'>
                    <switch test="`$service-result.errors.error[0].error-message`">
                        <outcome value='Other'>
                            <return status='failure'>
                                <parameter name='ack-final' value='Y'/>
                                <parameter name="error-code" value="500" />
                                <parameter name="error-message" value="`'Error CreateInternetProfileInstance return: '+$service-result.errors.error[0].error-message`" />
                            </return>
                        </outcome>
                        <outcome value=''>
                            <block></block>
                        </outcome>
                    </switch>
                </outcome>
            </execute>
            <block>
                <execute plugin="org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils" method="generateUUID">
                    <parameter name="ctx-destination" value="prop.random-data"/>
                    <outcome value='success'>
                        <execute plugin='org.onap.ccsdk.sli.core.slipluginutils.SliStringUtils' method='split' >
                            <parameter name="ctx_memory_result_key" value="prop.random-data-list"/>
                            <parameter name="original_string" value="`$prop.random-data`"/>
                            <parameter name="regex" value="-"/>
                            <outcome value='success'></outcome>
                        </execute>
                    </outcome>
                </execute>
                <set>
                    <parameter name='vnf-id' value="`$prop.random-data-list[3]`"/>
                    <parameter name='vnf-name' value="`'vnf-'+$prop.random-data-list[4]`"/>
                </set>
                <save plugin="org.onap.ccsdk.sli.adaptors.aai.AAIService" resource="generic-vnf" key="generic-vnf.vnf-id = $vnf-id" >
                    <parameter name= "vnf-id" value = "`$vnf-id`"/>
                    <parameter name=  "vnf-name" value = "`$vnf-name`"/>
                    <parameter name=  "vnf-type" value = "InternetProfile"/>
                    <parameter name=  "service-id" value = "`$network-topology-operation-input.service-information.service-id`"/>
                    <parameter name=  "prov-status" value = "ACTIVE"/>
                    <parameter name=  "orchestration-status" value = "Active"/>
                    <parameter name=  "is-closed-loop-disabled" value = "false" />
                    <parameter name=  "model-invariant-id" value = "`$network-topology-operation-input.network-information.onap-model-information.model-invariant-uuid`"/>
                    <parameter name=  "model-version-id" value = "`$network-topology-operation-input.network-information.onap-model-information.model-uuid`"/>
                    <parameter name=  "model-customization-id" value = "`$network-topology-operation-input.network-information.onap-model-information.model-customization-uuid`"/>
                    <outcome value='failure'>
                        <return status='failure'>
                            <parameter name='ack-final' value='Y'/>
                            <parameter name="error-code" value="500" />
                            <parameter name="error-message" value="Failure calling AAI to save generic-vnf" />
                        </return>
                    </outcome>
                    <outcome value='not-found'>
                        <return status='failure'>
                            <parameter name='ack-final' value='Y'/>
                            <parameter name="error-code" value="500" />
                            <parameter name="error-message" value="generic-vnf instance does not exist in AAI" />
                        </return>
                    </outcome>
                    <outcome value='success'></outcome>
                </save>
                <save plugin="org.onap.ccsdk.sli.adaptors.aai.AAIService" resource="service-instance:metadata"
 key="service-instance.service-instance-id = $network-topology-operation-input.service-information.service-id  
	AND customer.global-customer-id = $network-topology-operation-input.service-information.global-customer-id
	  AND service-subscription.service-type = $network-topology-operation-input.service-information.subscription-service-type
	  AND service-instance.service-instance-id =  $network-topology-operation-input.service-information.service-instance-id"  force="true" pfx="tmp.AnAI-data">
                    <parameter name="metadata.metadatum[0].metaname" value="service-type" />
                    <parameter name="metadata.metadatum[0].metaval" value="`$prop.bbs.service_type`" />
                    <parameter name="metadata.metadatum[1].metaname" value="up-speed" />
                    <parameter name="metadata.metadatum[1].metaval" value="`$prop.bbs.up_speed`" />
                    <parameter name="metadata.metadatum[2].metaname" value="down-speed" />
                    <parameter name="metadata.metadatum[2].metaval" value="`$prop.bbs.down_speed`" />
                    <parameter name="metadata.metadatum[3].metaname" value="cvlan" />
                    <parameter name="metadata.metadatum[3].metaval" value="`$prop.bbs.c_vlan`" />
                    <parameter name="metadata.metadatum[4].metaname" value="svlan" />
                    <parameter name="metadata.metadatum[4].metaval" value="`$prop.bbs.s_vlan`" />
                    <parameter name="metadata.metadatum[5].metaname" value="expected-ont-id" />
                    <parameter name="metadata.metadatum[5].metaval" value="`$prop.bbs.ont_sn`" />
                    <parameter name="metadata.metadatum[6].metaname" value="rgw-mac-address" />
                    <parameter name="metadata.metadatum[6].metaval" value="`$prop.bbs.mac`" />
                    <outcome value='failure'>
                        <return status='failure'>
                            <parameter name='ack-final' value='Y'/>
                            <parameter name="error-code" value="500" />
                            <parameter name="error-message" value="Failure calling AAI to save metadatum" />
                        </return>
                    </outcome>
                    <outcome value='not-found'>
                        <return status='failure'>
                            <parameter name='ack-final' value='Y'/>
                            <parameter name="error-code" value="500" />
                            <parameter name="error-message" value="metadatum instance does not exist in AAI" />
                        </return>
                    </outcome>
                    <outcome value='success'></outcome>
                </save>
                <save plugin="org.onap.ccsdk.sli.adaptors.aai.AAIService" resource="service-instance:relationship-list" 
      key="service-instance.service-instance-id =  $network-topology-operation-input.service-information.service-id
         AND customer.global-customer-id = $network-topology-operation-input.service-information.global-customer-id
         AND service-subscription.service-type =  $network-topology-operation-input.service-information.subscription-service-type 
         AND service-instance.service-instance-id =  $network-topology-operation-input.service-information.service-instance-id" force="true" pfx="tmp.AnAI-data">
                    <parameter name="relationship-list.relationship[0].related-to" value="generic-vnf" />
                    <parameter name="relationship-list.relationship[0].related-link" value="`'/network/generic-vnfs/generic-vnf/' + $vnf-id`" />
                    <parameter name="relationship-list.relationship[0].relationship-data[0].relationship-key" value="generic-vnf.vnf-id" />
                    <parameter name="relationship-list.relationship[0].relationship-data[0].relationship-value" value="`$vnf-id`" />
                    <outcome value='failure'>
                        <return status='failure'>
                            <parameter name='ack-final' value='Y'/>
                            <parameter name="error-code" value="500" />
                            <parameter name="error-message" value="Failure calling AAI to save metadatum" />
                        </return>
                    </outcome>
                    <outcome value='not-found'>
                        <return status='failure'>
                            <parameter name='ack-final' value='Y'/>
                            <parameter name="error-code" value="500" />
                            <parameter name="error-message" value="metadatum instance does not exist in AAI" />
                        </return>
                    </outcome>
                    <outcome value='success'></outcome>
                </save>
            </block>
            <return status='success'>
                <parameter name="ack-final-indicator" value="Y" />
                <parameter name="error-code" value="200" />
                <parameter name="error-message" value="`$error-message`" />
            </return>
        </block>
    </method>
</service-logic>