瀏覽代碼

HPCC-20586 Initial DFUServer XSD Conversion

Convert XSD to new format

Signed-off-by: Ken Rowland <kenneth.rowland@lexisnexisrisk.com>
Ken Rowland 6 年之前
父節點
當前提交
d1f3c0e241

+ 4 - 3
configuration/config2/EnvironmentMgr.cpp

@@ -378,17 +378,18 @@ bool EnvironmentMgr::removeEnvironmentNode(const std::string &nodeId)
 {
     bool rc = false;
     std::shared_ptr<EnvironmentNode> pNode = findEnvironmentNodeById(nodeId);
+    std::vector<std::string> deletedNodeIds;
 
     if (pNode)
     {
         std::shared_ptr<EnvironmentNode> pParentNode = pNode->getParent();
-        if (pParentNode->removeChild(pNode))
+        if (pParentNode->removeChild(pNode, deletedNodeIds))
         {
-            m_nodeIds.erase(nodeId);
+            for (auto delNodeId: deletedNodeIds)
+                m_nodeIds.erase(delNodeId);
             rc = true;
         }
     }
-
     return rc;
 }
 

+ 14 - 1
configuration/config2/EnvironmentNode.cpp

@@ -28,13 +28,15 @@ void EnvironmentNode::addChild(std::shared_ptr<EnvironmentNode> pNode)
 }
 
 
-bool EnvironmentNode::removeChild(const std::shared_ptr<EnvironmentNode> pNode)
+bool EnvironmentNode::removeChild(const std::shared_ptr<EnvironmentNode> pNode, std::vector<std::string> &removedNodeIds)
 {
     bool removed = false;
     for (auto it=m_children.begin(); it!= m_children.end() && !removed; ++it)
     {
         if (pNode == it->second)
         {
+            pNode->removeAllChildren(removedNodeIds);
+            removedNodeIds.emplace_back(pNode->getId());
             m_children.erase(it);
             removed = true;
         }
@@ -43,6 +45,17 @@ bool EnvironmentNode::removeChild(const std::shared_ptr<EnvironmentNode> pNode)
 }
 
 
+void EnvironmentNode::removeAllChildren(std::vector<std::string> &removedNodeIds)
+{
+    for (auto &childNodeIt: m_children)
+    {
+        childNodeIt.second->removeAllChildren(removedNodeIds);
+        removedNodeIds.emplace_back(childNodeIt.second->getId());
+    }
+    m_children.clear();
+}
+
+
 bool EnvironmentNode::addAttribute(const std::string &name, std::shared_ptr<EnvironmentValue> pValue)
 {
     auto retValue = m_attributes.insert(std::make_pair(name, pValue));

+ 2 - 1
configuration/config2/EnvironmentNode.hpp

@@ -39,7 +39,8 @@ class DECL_EXPORT EnvironmentNode : public std::enable_shared_from_this<Environm
         ~EnvironmentNode() { }
         const std::string &getName() const { return m_name;  }
         void addChild(std::shared_ptr<EnvironmentNode> pNode);
-        bool removeChild(std::shared_ptr<EnvironmentNode> pNode);
+        bool removeChild(std::shared_ptr<EnvironmentNode> pNode, std::vector<std::string> &removedNodeIds);
+        void removeAllChildren(std::vector<std::string> &removedNodeIds);
         void getChildren(std::vector<std::shared_ptr<EnvironmentNode>> &children, const std::string &name=std::string("")) const;
         bool hasChildren() const { return m_children.size() != 0; }
         int getNumChildren() const { return m_children.size(); }

+ 9 - 0
configuration/config2/EnvironmentValue.cpp

@@ -18,6 +18,15 @@
 #include "EnvironmentValue.hpp"
 #include "EnvironmentNode.hpp"
 
+
+EnvironmentValue::~EnvironmentValue()
+{
+    //
+    // Tell the schema vallue that we are going away
+    m_pSchemaValue->removeEnvironmentValue(shared_from_this());
+}
+
+
 bool EnvironmentValue::setValue(const std::string &value, Status *pStatus, bool forceSet)
 {
     bool rc = true;

+ 2 - 2
configuration/config2/EnvironmentValue.hpp

@@ -25,7 +25,7 @@
 
 class EnvironmentNode;
 
-class DECL_EXPORT EnvironmentValue
+class DECL_EXPORT EnvironmentValue : public std::enable_shared_from_this<EnvironmentValue>
 {
     public:
 
@@ -34,7 +34,7 @@ class DECL_EXPORT EnvironmentValue
         EnvironmentValue(const std::shared_ptr<EnvironmentNode> &pMyNode, const std::shared_ptr<SchemaValue> &pCfgValue, const std::string &name, const std::string initValue) :
             EnvironmentValue(pMyNode, pCfgValue, name) { m_value = initValue; }
 
-        ~EnvironmentValue() { }
+        ~EnvironmentValue();
         bool setValue(const std::string &value, Status *pStatus, bool forceSet=false);
         bool isValueSet() const { return !m_value.empty(); }
         const std::string &getValue() const { return m_value.empty() ? getForcedValue() : m_value;  }

+ 28 - 9
configuration/config2/SchemaValue.cpp

@@ -177,19 +177,25 @@ void SchemaValue::resetEnvironment()
 // replicates the new value throughout the environment
 void SchemaValue::mirrorValueToEnvironment(const std::string &oldValue, const std::string &newValue, Status *pStatus)
 {
+    for (auto &pSchemaValue: m_mirrorToSchemaValues)
+    {
+        pSchemaValue->doMirroroToEnvironmentValues(oldValue, newValue, pStatus);
+    }
+}
+
+
+void SchemaValue::doMirroroToEnvironmentValues(const std::string &oldValue, const std::string &newValue, Status *pStatus)
+{
     std::string msg = "Value automatically changed from " + oldValue + " to " + newValue;
-    for (auto mirrorCfgIt = m_mirrorToSchemaValues.begin(); mirrorCfgIt != m_mirrorToSchemaValues.end(); ++mirrorCfgIt)
+    for (auto &envValueIt: m_envValues)
     {
-        for (auto &envValueIt: m_envValues)
+        std::shared_ptr<EnvironmentValue> pEnvValue = envValueIt.lock();
+        if (pEnvValue && pEnvValue->getValue() == oldValue)
         {
-            std::shared_ptr<EnvironmentValue> pEnvValue = envValueIt.lock();
-            if (pEnvValue && pEnvValue->getValue() == oldValue)
+            pEnvValue->setValue(newValue, nullptr, true);
+            if (pStatus != nullptr)
             {
-                pEnvValue->setValue(newValue, nullptr, true);
-                if (pStatus != nullptr)
-                {
-                    pStatus->addMsg(statusMsg::change, msg, pEnvValue->getEnvironmentNode()->getId(), pEnvValue->getSchemaValue()->getDisplayName());
-                }
+                pStatus->addMsg(statusMsg::change, msg, pEnvValue->getEnvironmentNode()->getId(), pEnvValue->getSchemaValue()->getDisplayName());
             }
         }
     }
@@ -389,3 +395,16 @@ bool SchemaValue::isHidden(const EnvironmentValue *pEnvValue) const
     }
     return hidden;
 }
+
+
+void SchemaValue::removeEnvironmentValue(const std::shared_ptr<EnvironmentValue> &pEnvValue)
+{
+    for (auto it = m_envValues.begin(); it != m_envValues.end(); ++it)
+    {
+        if ((*it).lock() == pEnvValue)
+        {
+            m_envValues.erase(it);
+            break;
+        }
+    }
+}

+ 6 - 0
configuration/config2/SchemaValue.hpp

@@ -74,6 +74,7 @@ class DECL_EXPORT SchemaValue
         void mirrorValueToEnvironment(const std::string &oldValue, const std::string &newValue, Status *pStatus = nullptr);
         void addEnvironmentValue(const std::shared_ptr<EnvironmentValue> &pEnvValue) { m_envValues.push_back(pEnvValue); }
         void getAllEnvironmentValues(std::vector<std::shared_ptr<EnvironmentValue>> &envValues) const;
+        void removeEnvironmentValue(const std::shared_ptr<EnvironmentValue> &pEnvValue);
         void validate(Status &status, const std::string &id, const EnvironmentValue *pEnvValue = nullptr) const;
         bool getAllowedValues(std::vector<AllowedValue> &allowedValues, const std::shared_ptr<const EnvironmentNode> &pEnvNode) const;
         void setAutoGenerateType(const std::string &type) { m_autoGenerateType = type; }
@@ -95,6 +96,11 @@ class DECL_EXPORT SchemaValue
 
     protected:
 
+        void doMirroroToEnvironmentValues(const std::string &oldValue, const std::string &newValue, Status *pStatus = nullptr);
+
+
+    protected:
+
         // DON'T FORGET IF DATA ADDED, IT MAY MAY TO BE COPIED IN THE COPY CONSTRUCTOR!!
         std::shared_ptr<SchemaType> m_pType;
         std::string m_name;

+ 70 - 0
initfiles/componentfiles/configschema/xsd/dfuserver.xsd

@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+#    HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+-->
+
+<xs:schema
+        xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"
+        xmlns:hpcc="someuri">
+    <xs:include schemaLocation="types.xsd"/>
+    <hpcc:insert hpcc:schemaPath="/Environment/Software">
+        <xs:element name="DfuServerProcess" hpcc:displayName="DFU Server Process" hpcc:itemType="dfuserver" minOccurs="0" maxOccurs="unbounded"
+                    hpcc:class="component" hpcc:docid="DF.t1">
+            <xs:complexType>
+                <xs:sequence>
+                    <xs:element name="SSH" hpcc:displayName="SSH Options" hpcc:tooltip="Options for using SSH remote execution"
+                                minOccurs="1" maxOccurs="1" hpcc:docid="DF.t2">
+                        <xs:complexType>
+                            <xs:attribute name="SSHidentityfile" hpcc:displayName="Identity File" type="xs:string"
+                                          hpcc:presetValue="$HOME/.ssh/id_rsa" hpcc:tooltip="location of identity file (private key) on Thor master"/>
+                            <xs:attribute name="SSHusername" hpcc:displayName="Username" type="xs:string"
+                                          hpcc:presetValye="hpcc" hpcc:tooltip="Username to use when running Thor slaves"/>
+                            <xs:attribute name="SSHpassword" hpcc:displayName="Password" type="xs:string" hpcc:modifiers="password"
+                                          hpcc:tooltip="Fixed password - only required if no identity file present NB **insecure**"/>
+                            <xs:attribute name="SSHtimeout" hpcc:displayName="Timeout (s)" type="xs:nonNegativeInteger"
+                                          hpcc:presetVaue="0" hpcc:tooltip="Timeout in seconds for SSH connects"/>
+                            <xs:attribute name="SSHretries" hpcc:displayName="Retries" type="xs:nonNegativeInteger"
+                                          hpcc:presetValue="3" hpcc:tooltip="Number of times to retry failed connect"/>
+                        </xs:complexType>
+                    </xs:element>
+
+                    <xs:element name="Instance" hpcc:itemType="hwinstance" maxOccurs="unbounded" hpcc:class="elementSet" hpcc:requiredInstanceComponents="/Evnironment/Software/[#itemType='dafilesrv']">
+                        <xs:complexType>
+                            <xs:attributeGroup ref="computerNodeReference"/>
+                            <xs:attribute name="directory" type="absolutePath" hpcc:hidden="true"/>
+                        </xs:complexType>
+                    </xs:element>
+
+                    <xs:element name="Notes" hpcc:displayName="Notes" type="usernotes"/>
+
+                </xs:sequence>
+                <xs:attributeGroup ref="buildInfo"/>
+                <xs:attribute name="name" type="xs:string" use="required" hpcc:displayName="Name" hpcc:autoGenerateType="prefix_" hpcc:autoGenerateValue="dfuserver"
+                              hpcc:uniqueKey="dfuserver_name" hpcc:tooltip="Name for this DFU Server process"/>
+                <xs:attribute name="description" type="xs:string" hpcc:displayName="Description" hpcc:presetValue="DFU Server process" hpcc:tooltip="Description for this process"/>
+                <xs:attribute name="daliServers" hpcc:displayName="Dali Server" type="xs:string" hpcc:sourceKey="daliprocess_name"
+                              use="required" hpcc:tooltip="Specifies the dali server to which this DFU server is attached"/>
+                <xs:attribute name="queue" hpcc:displayName="Queue" type="xs:string" use="required" hpcc:presetValue="dfuserver_queue"
+                              hpcc:tooltip="Specifies the queue name to which DFU server jobs are sent"/>
+                <xs:attribute name="monitorqueue" hpcc:displayName="Monitor Queue" type="xs:string" use="required" hpcc:presetValue="dfuserver_monitor_queue"
+                              hpcc:tooltip="Specifies the queue name to which DFU monitoring jobs are sent"/>
+                <xs:attribute name="monitorinterval" hpcc:displayname="Monitor Interval (s)" type="xs:nonNegativeInteger"
+                              hpcc:presetValue="900" hpcc:tooltip="Specifies the polling interval for DFU monitoring (in seconds)"/>
+                <xs:attribute name="transferBufferSize" hpcc:displayName="Transfer Buffer Size (bytes)" type="xs:nonNegativeInteger"
+                              hpcc:presetValue="65536" hpcc:tooltip="Default buffer size used when transferring data"/>
+            </xs:complexType>
+        </xs:element>
+    </hpcc:insert>
+</xs:schema>