<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
    xmlns="http://www.vmware.com/vcloud/extensibility/v1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:meta="http://www.vmware.com/vcloud/meta"
    jaxb:extensionBindingPrefixes="meta"
    elementFormDefault="qualified"
    targetNamespace="http://www.vmware.com/vcloud/extensibility/v1.0"
    version="1.0">

    <xs:include schemaLocation="extensibility-core.xsd"/>

    <xs:element name="Requirements">
        <xs:complexType>
            <xs:sequence>
               <xs:element name="Context" type="ContextType" minOccurs="0" maxOccurs="unbounded">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            Zero or more context entries that will apply to all subjects defined in this
                            &lt;Requirements&gt; element
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name = "Subject" type="SubjectType" minOccurs="0" maxOccurs="unbounded">
                </xs:element>
        </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="RequirementType">
        <xs:sequence>
            <xs:element name="Data" type="DataType" minOccurs="1" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        One or more name value pairs that define the requirement.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="type" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    A URN that indicates the type of requirement.  Type URNs must take the
                    form 'urn:placement:requirementType:*'
                </xs:documentation>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:anyURI">
                    <xs:pattern value="urn:placement:requirementType:.+" />
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="locked" default="true" type="xs:boolean">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    A flag indicating whether this requirement can be modified or
                    removed (locked=false).  If true, this requirement cannot be
                    modified or removed.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="SubjectType">
        <xs:sequence>
            <xs:element name="Context" type="ContextType"
                minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        Zero or more context entries that apply only to the containing subject
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Requirement" type="RequirementType"
                minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        Zero or more placement requirements that apply to the subject
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="id" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    The placement subject's ID
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="existing" type="xs:boolean" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    True if this is an existing subject.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="type" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    Specifies the type of this placement subject.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="existingSubjectUri" type="xs:anyURI" use="optional">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    URI representation of an existing placement subject.
                     Will not exist for new subjects (existing=false).
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="VmAffinityDataType">
        <xs:annotation>
            <xs:appinfo>
                <meta:jsonSubTypeInfo name="vmAffinity" />
            </xs:appinfo>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="DataType">
                <xs:sequence maxOccurs="unbounded">
                    <xs:element name="Value">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="Vm" type="xs:anyURI" />
                                <xs:element name="AffinityType" type="xs:string" />
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:element name="Solutions">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Context" type="ContextType" minOccurs="0" maxOccurs="unbounded">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            Zero or more context entries that will apply to all subject proposals defined in this
                            &lt;Solutions&gt; element
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="SubjectProposal" type="SubjectProposalType" minOccurs="0" maxOccurs="unbounded">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            Zero or more subject proposals that have been calculated as part of the placement solution
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="SubjectProposalType">
        <xs:sequence>
            <xs:element name="Requirement" type="RequirementType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        Zero or more placement requirements that apply to the subject
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="RankData" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                         The rank data for the particular subject and hub.  Each RankData can contain hub ranks and metrics
                         calculated on a fabric by fabric basis.
                    </xs:documentation>
                </xs:annotation>
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="HubRank" maxOccurs="unbounded">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="RankMetrics">
                                        <xs:annotation>
                                            <xs:documentation xml:lang="en">
                                                 A collection of resource metrics that are used to rank the hub
                                            </xs:documentation>
                                        </xs:annotation>
                                        <xs:complexType>
                                            <xs:sequence>
                                                <xs:element name="RankMetric" minOccurs="0" maxOccurs="unbounded">
                                                    <xs:complexType>
                                                        <xs:attribute name="name" type="xs:string" use="required">
                                                            <xs:annotation>
                                                                <xs:documentation xml:lang="en">
                                                                     The name of the metric
                                                                </xs:documentation>
                                                            </xs:annotation>
                                                        </xs:attribute>
                                                        <xs:attribute name="reservedCapacity" use="required">
                                                            <xs:annotation>
                                                                <xs:documentation xml:lang="en">
                                                                    A non-negative amount of reserved capacity
                                                                </xs:documentation>
                                                            </xs:annotation>
                                                            <xs:simpleType>
                                                                <xs:restriction base="xs:long">
                                                                    <xs:minInclusive value="0" />
                                                                </xs:restriction>
                                                            </xs:simpleType>
                                                        </xs:attribute>
                                                        <xs:attribute name="totalCapacity" use="required">
                                                            <xs:annotation>
                                                                <xs:documentation xml:lang="en">
                                                                    An non-negative total capacity
                                                                </xs:documentation>
                                                            </xs:annotation>
                                                            <xs:simpleType>
                                                                <xs:restriction base="xs:long">
                                                                    <xs:minInclusive value="0" />
                                                                </xs:restriction>
                                                            </xs:simpleType>
                                                        </xs:attribute>
                                                        <xs:attribute name="expectedCapacityConsumption" use="required">
                                                            <xs:annotation>
                                                                <xs:documentation xml:lang="en">
                                                                    An non-negative amount of expected comsumption
                                                                </xs:documentation>
                                                            </xs:annotation>
                                                            <xs:simpleType>
                                                                <xs:restriction base="xs:long">
                                                                    <xs:minInclusive value="0" />
                                                                </xs:restriction>
                                                            </xs:simpleType>
                                                        </xs:attribute>
                                                        <xs:attribute name="utilization" use="required">
                                                            <xs:annotation>
                                                                <xs:documentation xml:lang="en">
                                                                    Utilization percentage as a value from 0-1
                                                                </xs:documentation>
                                                            </xs:annotation>
                                                            <xs:simpleType>
                                                                <xs:restriction base="xs:double">
                                                                    <xs:minInclusive value="0" />
                                                                    <xs:maxInclusive value="1.0" />
                                                                </xs:restriction>
                                                            </xs:simpleType>
                                                        </xs:attribute>
                                                    </xs:complexType>
                                                </xs:element>
                                            </xs:sequence>
                                        </xs:complexType>
                                    </xs:element>
                                    <xs:element name="StorageFabricData" type="StorageFabricDataType" maxOccurs="1" minOccurs="0">
                                        <xs:annotation>
                                            <xs:documentation xml:lang="en">
                                                 Storage placement result on this hub for the specified subject.
                                            </xs:documentation>
                                        </xs:annotation>
                                    </xs:element>
                                </xs:sequence>
                                <xs:attribute name="deploymentTime" type="xs:int" use="required">
                                </xs:attribute>
                                <xs:attribute name="preference" use="required">
                                    <xs:simpleType>
                                        <xs:restriction base="xs:anyURI">
                                            <xs:pattern value="urn:placement:hubPreference:.+" />
                                        </xs:restriction>
                                    </xs:simpleType>
                                </xs:attribute>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                    <xs:attribute name="hubUri" type="xs:anyURI" use="required">
                    </xs:attribute>
                </xs:complexType>
            </xs:element>
            <xs:element name="RejectedHubs">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="RejectedHub" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="message" type="LocalizableMessageType" minOccurs="1" maxOccurs="1" />
                                </xs:sequence>
                                <xs:attribute name="hubUri" use="required" type="xs:anyURI" />
                                <xs:attribute name="subjectId" use="required" type="xs:anyURI" />
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="subjectId" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    The ID of the placement subject
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="subjectType" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                     The type of the subject which is being placed. Valid types are:
                     VirtualMachine, NamedDisk, VirtualMachineNic, Media, or Gateway
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="existingSubjectUri" type="xs:anyURI" use="optional">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    URI representation of an existing placement subject.
                     Will not exist for new subjects (existing=false).
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="existing" type="xs:boolean" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    True if this is an existng subject
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:element name="PlacementProposalType">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="SubjectProposal" type="SubjectProposalType" minOccurs="1" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                         The current proposal for a subject detailing the requirements of the subject,
                         the ranks of the varios hubs, and the list of rejected hubs.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="ProposedSolution" type="ProposedSolutionType" minOccurs="1" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                         A proposal for placing a subject on a specific hub.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="AffinityRules" type="AffinityRulesType" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        Rules regarding affinity between subject VMs.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    </xs:element>

    <xs:complexType name="AffinityRulesType">
        <xs:sequence>
            <xs:element name="AffinityRule" type="AffinityRuleType" minOccurs="1" maxOccurs="2">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        An affinity rule specifies two VMs that should be placed on the same host.
                         An anti-affinity rule specifies VMs that should not be placed on the same host
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="AffinityRuleType">
        <xs:sequence>
            <xs:element name="Subject" minOccurs="2" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        A subject associated with this rule, either because it is the subject of the
                         placement request or because it has an affinity with the subject of the
                         placement request. Subjects that are included in an affinity rule that
                         affects this placement but not otherwise specified in the request cannot
                         be migrated or replaced as part of this placement. The current hub
                         assignment for these subjects is included within this rule.
                    </xs:documentation>
                </xs:annotation>
                <xs:complexType>
                    <xs:attribute name="subjectUri" use="required" type="xs:anyURI"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="SubjectHubAssignment" type="SubjectHubAssignmentType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        A mapping of a subject that is part of this rule but isn't part of the
                         placement request to the hub on which it resides. This subject to hub mapping
                         cannot be changed as this subject is not part of this placement request.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="affinityScopeType" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    The scope of this affinity rule.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="affinityPolarity" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                     The polarity of this affinity rule: affinity v.s. antiaffinity.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="ProposedSolutionType">
        <xs:sequence>
            <xs:element name="SubjectHubAssignment" type="SubjectHubAssignmentType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                         A mapping of a subect to a hub and a set of storage containers on that hub.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="SubjectHubAssignmentType">
        <xs:sequence>
            <xs:element name="Message" type="LocalizableMessageType" minOccurs="0" maxOccurs="unbounded" >
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        Message(s) indicating why hub assignment has changed or cannot be completed.
                          If hub assignment cannot be completed, this message is logged as the reason
                         for the previously assigned hub being rejected.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="StorageAssignment" type="StorageFabricDataType" minOccurs="0" maxOccurs="1">
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                         Storage container(s) chosen for the subject. If hub assignment cannot be
                          completed, this element will not be present.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="subjectId" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    The ID of the placement subject
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="hubUri" type="xs:anyURI" use="optional">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    URI representation of the hub the subject is to be placed on.
                    If no hub is suitable, Message can be set to indicate the reason.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="StorageFabricDataType">
        <xs:sequence>
            <xs:element name="StorageContainer" type="StorageContainer" maxOccurs="1" minOccurs="0" >
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        The target storage container where the subject should be created.
                        If the subject is a VM, this specifies the storage container for the VM
                        and all disks that don't contain a VmDiskStorageContainer value.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="VmDiskStorageContainer" maxOccurs="unbounded" minOccurs="0">
            <xs:complexType>
                <xs:annotation>
                    <xs:documentation xml:lang="en">
                        The target storage container where the disk should be created.
                    </xs:documentation>
                </xs:annotation>
                <xs:attribute name="valRef" type="xs:anyURI" use="required">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            A URL of the form 'moref://{vc-server-uuid}/{objectType}#{moref}'
                            that identifies either a vSphere datastore or storage pod on which
                            this disk is to be placed.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
                <xs:attribute name="VmDiskRef" type="xs:anyURI" use="required">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            A URL of the form 'VmDiskRef://{EXISTING_DISK}/{diskObjectId}' or
                            'VmDiskRef://{NEW_DISK}/{busNumber}?{busSubType}#{unitNumber}'
                            that uniquely identifies a disk of a VM.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="subjectType" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                     The type of the subject which is being placed. Valid types are:
                     VirtualMachine, NamedDisk, VirtualMachineNic, Media, or Gateway
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
</xs:schema>