瀏覽代碼

Merge pull request #3487 from garonsky/issue-2942_Add_Functionality_to_add_custom_attribute

HPCC-2942 Configmgr - Add custom attributes

Reviewed-By: Kevin Wang <kevin.wang@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 年之前
父節點
當前提交
346bdf710b

+ 2 - 0
deployment/deploy/XMLTags.h

@@ -87,6 +87,7 @@
 #define XML_TAG_LOCALENVCONFFILE       "LocalEnvConfFile"
 
 #define XML_ATTR_AGENTPORT             "@agentPort"
+#define XML_ATTR_ATTRIB                "@attrib"
 #define XML_ATTR_ATTRSERVER            "@attrServer"
 #define XML_ATTR_BACKUPCOMPUTER        "@backupComputer"
 #define XML_ATTR_BLOBDIRECTORY         "@blobDirectory"
@@ -174,6 +175,7 @@
 #define XML_ATTR_OPSYS                 "@opSys"
 #define XML_ATTR_OPTIMIZESQL           "@optimizeSQL"
 #define XML_ATTR_ORPHANSASERROR        "@orphansAsError"
+#define XML_ATTR_PARAMS                "@params"
 #define XML_ATTR_PASSWORD              "@password"
 #define XML_ATTR_PATH                  "@path"
 #define XML_ATTR_PERFDATALEVEL         "@perfDataLevel"

+ 65 - 9
esp/files/scripts/configmgr/configmgr.js

@@ -1811,11 +1811,57 @@ function createEnvXmlView(allrows, compName, subRecordIndex) {
         width: "100%"
       });
 
+      function onContextMenuBeforeAddAttribute(p_sType, p_aArgs, menuitem)
+      {
+        var name = prompt("Enter Attribute Name:");
+
+        if (name.length == 0)
+        {
+          alert("Attribute name can not be empty!");
+          return;
+        }
+
+        var record = top.document.rightDT.getRecordSet().getRecord(top.document.rightDT.getSelectedRows()[0]);
+        var pp = parseParamsForXPath(record.getData('params'), "", "", false, true);
+
+        var xmlStr = "<XmlArgs><Setting operation=\"add\" params= \"" + pp + "\" attrib= \"" + (menuitem.element.outerText.trimRight() == 'Add Tag' ? name : "@" + name) + "\"/></XmlArgs>";
+
+        YAHOO.util.Connect.asyncRequest('POST', '/WsDeploy/HandleAttributeAdd', {
+          success: function(o) {
+            top.document.forms['treeForm'].isChanged.value = "true";
+            top.document.choice = new Array();
+            top.document.choice[0] = top.document.rightDT.getRecordIndex(top.document.rightDT.getSelectedRows()[0])+1;
+            var recDepth =  top.document.rightDT.getRecord(top.document.choice[0])._oData.depth;
+
+            var index = 0;
+            for (counter = top.document.choice[0]; counter >= 0; counter--)
+            {
+              if (top.document.rightDT.getRecord(counter)._oData.depth < recDepth)
+              {
+                top.document.choice[index] = top.document.rightDT.getRecord(counter).getData('params');
+                recDepth = top.document.rightDT.getRecord(counter)._oData.depth;
+                index++;
+              }
+            }
+
+            top.document.doJumpToChoice = true;
+            doPageRefresh();
+
+             YAHOO.util.UserAction.click(top.document.rightDT.getFirstTrEl());
+           },
+          failure: function(o) {
+            alert("Failed to add attribute.  (XPath maybe ambiguous. A manual edit of the XML configuration file maybe required to add this attribute.) ");
+            },
+          scope: this
+        },
+          top.document.navDT.getFileName(true) + 'XmlArgs=' + xmlStr + '&bLeaf=' +  false );
+        }
+
       function onContextMenuBeforeShowDeleteContextMenu(p_sType, p_aArgs) {
         var record = top.document.rightDT.getRecordSet().getRecord(top.document.rightDT.getSelectedRows()[0]);
         var pp = parseParamsForXPath( record.getData('params'), top.document.rightDT.getRecordSet().getRecord(top.document.rightDT.getSelectedRows()[0]).getData('name'),
                    top.document.rightDT.getRecordSet().getRecord(top.document.rightDT.getSelectedRows()[0]).getData('value'),
-                   record.getData('hasChildren') == undefined ? false : record.getData('hasChildren') );
+                   record.getData('hasChildren') == undefined ? false : record.getData('hasChildren'), false);
 
         var xmlStr = "<XmlArgs><Setting operation=\"delete\" params= \"" + pp + "\"/></XmlArgs>";
 
@@ -1859,12 +1905,23 @@ function createEnvXmlView(allrows, compName, subRecordIndex) {
         top.document.ContextMenuCenter = this;
       }
 
-      function onTriggerContextMenu(p_oEvent)
+      function onShowContextMenu(p_oEvent)
       {
-        if (top.document.rightDT.getRecord(top.document.rightDT.getSelectedRows()[0])._oData.hasChildren == true)  // only allow attributes to be deleted
-          this.cancel();
+        if (top.document.rightDT.getRecord(top.document.rightDT.getSelectedRows()[0])._oData.hasChildren == true)  // only allow attributes to be delete
+        {
+          top.document.ContextMenuCenter.getRoot().body.lastElementChild.childNodes[0].hidden = true;
+          top.document.ContextMenuCenter.getRoot().body.lastElementChild.childNodes[1].hidden = false;
+        }
+        else
+        {
+          top.document.ContextMenuCenter.getRoot().body.lastElementChild.childNodes[0].hidden = false;
+          top.document.ContextMenuCenter.getRoot().body.lastElementChild.childNodes[1].hidden = true;
+        }
       }
-      var aMenuItemsX = [{text: "Delete", onclick: { fn: onContextMenuBeforeShowDeleteContextMenu}  }];
+
+     var aMenuItemsX = [ { text: "Delete",        onclick: { fn: onContextMenuBeforeShowDeleteContextMenu} },
+                          { text: "Add Attribute", onclick: { fn: onContextMenuBeforeAddAttribute}, }
+                        ];
       top.document.rightDT = dt;
       top.document.rightDT.expandRecord = function(id) {
       var recSet = top.document.rightDT.getRecordSet();
@@ -1903,8 +1960,7 @@ function createEnvXmlView(allrows, compName, subRecordIndex) {
       var oContextMenuX = new YAHOO.widget.ContextMenu( "EnvironmentTabCM2", { trigger: dt.getTbodyEl(), lazyload: true, itemdata: aMenuItemsX, container: tabNameTemp});
       top.document.ContextMenuCenter = oContextMenuX;
 
-
-     oContextMenuX.subscribe("triggerContextMenu", onTriggerContextMenu);
+      oContextMenuX.subscribe("show", onShowContextMenu);
 
       oContextMenuX.dt = dt;
       oContextMenuX.subscribe("beforeShow",onContextMenuXBeforeShow);
@@ -3599,7 +3655,7 @@ function setChildrenOf(parent, rec) {
   childrenOf[parent][childrenOf[parent].length] = rec;
 }
 
-function parseParamsForXPath(params, key, value, hasChildren)
+function parseParamsForXPath(params, key, value, hasChildren, skip)
 {
   var splitParams = params.split(":");
   var xpath = "";
@@ -3642,7 +3698,7 @@ function parseParamsForXPath(params, key, value, hasChildren)
   {
     xpath = xpath + "]";
   }
-  else
+  else if (skip == false)
   {
     if (xpath[xpath.length-1] == '/')
     {

+ 16 - 1
esp/scm/WsDeploy.ecm

@@ -260,6 +260,19 @@ ESPrequest HandleAttributeDeleteRequest
     ESPstruct WsDeployReqInfo ReqInfo;
 };
 
+ESPrequest HandleAttributeAddRequest
+{
+    string Operation;
+    string XmlArgs;
+    ESPstruct WsDeployReqInfo ReqInfo;
+};
+
+ESPresponse [exceptions_inline, encode(0)] HandleAttributeAddResponse
+{
+    string Status;
+    string CompName;
+};
+
 ESPresponse [exceptions_inline, encode(0)] HandleAttributeDeleteResponse
 {
     string Status;
@@ -566,7 +579,9 @@ ESPservice [exceptions_inline("xslt/exceptions.xslt")] WsDeploy
         HandleRoxieOperation(HandleRoxieOperationRequest, HandleRoxieOperationResponse);
     ESPmethod[description("Add computers to Thor topology"), help("")] 
         HandleThorTopology(HandleThorTopologyRequest, HandleThorTopologyResponse);
-   ESPmethod[description("Handle branch or leaf deletes from XML view"), help("")]
+    ESPmethod[description("Handle add fom XML view"), help("")]
+        HandleAttributeAdd(HandleAttributeAddRequest, HandleAttributeAddResponse);
+    ESPmethod[description("Handle branch or leaf deletes from XML view"), help("")]
         HandleAttributeDelete(HandleAttributeDeleteRequest, HandleAttributeDeleteResponse);
     ESPmethod[description("Handle new component operations like add & delete in the environment"), help("")] 
         HandleComponent(HandleComponentRequest, HandleComponentResponse);

+ 44 - 0
esp/services/WsDeploy/WsDeployService.cpp

@@ -4222,6 +4222,39 @@ bool CWsDeployFileInfo::getBuildServerDirs(IEspContext &context, IEspGetBuildSer
   return true;
 }
 
+bool CWsDeployFileInfo::handleAttributeAdd(IEspContext &context, IEspHandleAttributeAddRequest &req, IEspHandleAttributeAddResponse &resp)
+{
+  synchronized block(m_mutex);
+  const char* xmlArg = req.getXmlArgs();
+
+  if (!xmlArg || !*xmlArg)
+    return false;
+
+  Owned<IPropertyTree> pSrcTree = createPTreeFromXMLString(xmlArg);
+  Owned<IPropertyTreeIterator> iter = pSrcTree->getElements("Setting[@operation='add']");
+
+  if (iter->first() == false)
+    return false;
+
+  IPropertyTree* pSetting = &iter->query();
+  Owned<IPropertyTree> pEnvRoot = getEnvTree(context, &req.getReqInfo());
+  StringBuffer xpath =  pSetting->queryProp(XML_ATTR_PARAMS);
+  StringBuffer attribName = pSetting->queryProp(XML_ATTR_ATTRIB);
+
+  if (attribName.length() == 0)
+    throw MakeStringException(-1,"Attribute name can't be empty!");
+
+  IPropertyTree* pComp =  pEnvRoot->getPropTree(xpath.str());
+
+  if (pComp != NULL)
+    pComp->addProp(attribName.str(), "");
+
+  resp.setStatus("true");
+  resp.setCompName(XML_TAG_SOFTWARE);
+
+  return true;
+}
+
 bool CWsDeployFileInfo::handleAttributeDelete(IEspContext &context, IEspHandleAttributeDeleteRequest &req, IEspHandleAttributeDeleteResponse &resp)
 {
   synchronized block(m_mutex);
@@ -6937,6 +6970,12 @@ bool CWsDeployEx::onHandleComponent(IEspContext &context, IEspHandleComponentReq
   return fi->handleComponent(context, req, resp);
 }
 
+bool CWsDeployEx::onHandleAttributeAdd(IEspContext &context, IEspHandleAttributeAddRequest &req, IEspHandleAttributeAddResponse &resp)
+{
+  CWsDeployFileInfo* fi = getFileInfo(req.getReqInfo().getFileName());
+  return fi->handleAttributeAdd(context, req, resp);
+}
+
 bool CWsDeployEx::onHandleAttributeDelete(IEspContext &context, IEspHandleAttributeDeleteRequest &req, IEspHandleAttributeDeleteResponse &resp)
 {
   CWsDeployFileInfo* fi = getFileInfo(req.getReqInfo().getFileName());
@@ -7199,6 +7238,11 @@ bool CWsDeployExCE::onHandleComponent(IEspContext &context, IEspHandleComponentR
   return supportedInEEOnly();
 }
 
+bool CWsDeployExCE::onHandleAttributeAdd(IEspContext &context, IEspHandleAttributeAddRequest &req, IEspHandleAttributeAddResponse &resp)
+{
+  return supportedInEEOnly();
+}
+
 bool CWsDeployExCE::onHandleAttributeDelete(IEspContext &context, IEspHandleAttributeDeleteRequest &req, IEspHandleAttributeDeleteResponse &resp)
 {
   return supportedInEEOnly();

+ 3 - 0
esp/services/WsDeploy/WsDeployService.hpp

@@ -473,6 +473,7 @@ public:
     virtual bool handleRoxieOperation(IEspContext &context, IEspHandleRoxieOperationRequest &req, IEspHandleRoxieOperationResponse &resp);
     virtual bool handleThorTopology(IEspContext &context, IEspHandleThorTopologyRequest &req, IEspHandleThorTopologyResponse &resp);
     virtual bool handleAttributeDelete(IEspContext &context, IEspHandleAttributeDeleteRequest &req, IEspHandleAttributeDeleteResponse &resp);
+    virtual bool handleAttributeAdd(IEspContext &context, IEspHandleAttributeAddRequest &req, IEspHandleAttributeAddResponse &resp);
     virtual bool handleComponent(IEspContext &context, IEspHandleComponentRequest &req, IEspHandleComponentResponse &resp);
     virtual bool handleComponentCopy(IPropertyTree *pComponents, IPropertyTree *pEnvRoot);
     virtual bool handleHardwareCopy(IPropertyTree *pComponents, IPropertyTree *pEnvRoot);
@@ -954,6 +955,7 @@ public:
     virtual bool onGetComputersForRoxie(IEspContext &context, IEspGetComputersForRoxieRequest &req, IEspGetComputersForRoxieResponse &resp);
     virtual bool onHandleRoxieOperation(IEspContext &context, IEspHandleRoxieOperationRequest &req, IEspHandleRoxieOperationResponse &resp);
     virtual bool onHandleThorTopology(IEspContext &context, IEspHandleThorTopologyRequest &req, IEspHandleThorTopologyResponse &resp);
+    virtual bool onHandleAttributeAdd(IEspContext &context, IEspHandleAttributeAddRequest &req, IEspHandleAttributeAddResponse &resp);
     virtual bool onHandleAttributeDelete(IEspContext &context, IEspHandleAttributeDeleteRequest &req, IEspHandleAttributeDeleteResponse &resp);
     virtual bool onHandleComponent(IEspContext &context, IEspHandleComponentRequest &req, IEspHandleComponentResponse &resp);
     virtual bool onHandleInstance(IEspContext &context, IEspHandleInstanceRequest &req, IEspHandleInstanceResponse &resp);
@@ -1026,6 +1028,7 @@ public:
     virtual bool onHandleRoxieOperation(IEspContext &context, IEspHandleRoxieOperationRequest &req, IEspHandleRoxieOperationResponse &resp);
     virtual bool onHandleThorTopology(IEspContext &context, IEspHandleThorTopologyRequest &req, IEspHandleThorTopologyResponse &resp);
     virtual bool onHandleAttributeDelete(IEspContext &context, IEspHandleAttributeDeleteRequest &req, IEspHandleAttributeDeleteResponse &resp);
+    virtual bool onHandleAttributeAdd(IEspContext &context, IEspHandleAttributeAddRequest &req, IEspHandleAttributeAddResponse &resp);
     virtual bool onHandleComponent(IEspContext &context, IEspHandleComponentRequest &req, IEspHandleComponentResponse &resp);
     virtual bool onHandleInstance(IEspContext &context, IEspHandleInstanceRequest &req, IEspHandleInstanceResponse &resp);
     virtual bool onHandleEspServiceBindings(IEspContext &context, IEspHandleEspServiceBindingsRequest &req, IEspHandleEspServiceBindingsResponse &resp);