123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2012 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.
- ############################################################################## */
- //disable the harmless warning about very long symbol names > 255 chars in debug mode
- //this is typical with STL
- #pragma warning( disable : 4786 )
- #include "jliball.hpp"
- #include "environment.hpp"
- #include "XMLTags.h"
- #include "buildset.hpp"
- #include "Constants.h"
- #include <set>
- #include <string>
- using std::set;
- using std::string;
- static set<string> s_failedConnections;
- //for getcwd
- #ifdef _WINDOWS
- #else
- #include <dirent.h>
- #include <unistd.h>
- #endif
- //---------------------------------------------------------------------------
- // getAccountInfo
- //---------------------------------------------------------------------------
- void getAccountInfo(const char* computer, StringAttr& user, StringAttr& pwd, IConstEnvironment* pConstEnv)
- {
- if (!pConstEnv)
- throw MakeStringException(-1, "No environment is available!");
- Owned<IConstMachineInfo> machine = pConstEnv->getMachine(computer);
- if (!machine)
- {
- StringBuffer sComputer(computer);
- StringBuffer sExtra;
- if (sExtra.length() == 0)
- machine.setown( pConstEnv->getMachineByAddress(computer) );
- if (!machine)
- throw MakeStringException(-1, "The computer '%s' is undefined!", computer);
- }
- Owned<IConstDomainInfo> domain = machine->getDomain();
- if (!domain)
- throw MakeStringException(-1, "The computer '%s' does not have any domain information!", computer);
- StringBuffer x;
- domain->getName(StringBufferAdaptor(x));
- if (x.length())
- x.append(PATHSEPCHAR);
- domain->getAccountInfo(StringBufferAdaptor(x), StringAttrAdaptor(pwd));
- user.set(x.str());
- }
- bool connectionRemoteMachine(const StringBuffer& sPath, IConstEnvironment* pConstEnv)
- {
- bool rc = true;
- if (sPath.length() > 2 && sPath[0] == '\\' && sPath[1] == '\\')
- {
- const char* spath = sPath.str();
- const char* cpos = strchr(spath + 2, '\\');
- int pos = cpos? cpos - spath : -1;
- if (pos != -1)
- {
- char szComp[128];
- strncpy(szComp, spath + 2, pos);
- StringBuffer computer(szComp);
- StringAttr userid;
- StringAttr pswd;
- try {
- //if computer is defined in hardware section then use its associated
- //login information, if any
- getAccountInfo(computer, userid, pswd, pConstEnv);
- } catch (...)
- {
- userid.clear();
- pswd.clear();
- }
- }
- }
- return rc;
- }
- // Various helper functions for managing build sets
- bool connectBuildSet(IPropertyTree* pBuild, IPropertyTree* pBuildSet, StringBuffer& buildSetPath, IConstEnvironment* pConstEnv)
- {
- bool rc = true;
- buildSetPath.clear();
- // Get InstallSet file name from BuildSet node
- const char* szVal = pBuild->queryProp(XML_ATTR_URL);
- if (szVal && *szVal)
- {
- buildSetPath = szVal;
- rc = connectionRemoteMachine(buildSetPath, pConstEnv);
- buildSetPath.append(PATHSEPCHAR);
- }
- //szVal = pBuildSet->queryProp(XML_ATTR_PATH);
- //if (szVal && *szVal)
- //buildSetPath.append(szVal).append(PATHSEPCHAR);
- buildSetPath.append("componentfiles").append(PATHSEPCHAR).append("configxml").append(PATHSEPCHAR);
- buildSetPath.replace('\\', PATHSEPCHAR);
- return rc;
- }
- IPropertyTree *loadInstallSet(IPropertyTree *pBuild, IPropertyTree *pBuildSet, IConstEnvironment* pConstEnv)
- {
- // Create fully qualified path to InstallSet file
- IPropertyTree* pInstallSet = NULL;
- StringBuffer sFilename;
- if (connectBuildSet(pBuild, pBuildSet, sFilename, pConstEnv))
- {
- // Get InstallSet file name from BuildSet node
- const char* szVal = pBuildSet->queryProp(XML_ATTR_INSTALLSET);
- if (szVal && *szVal)
- sFilename.append(szVal);
- else
- sFilename.append(DEFAULT_INSTALLSET);
- pInstallSet = createPTreeFromXMLFile(sFilename);
- }
- return pInstallSet;
- }
- IPropertyTree *loadSchema(IPropertyTree *pBuild, IPropertyTree *pBuildSet, StringBuffer& sSchemaPath, IConstEnvironment* pConstEnv)
- {
- IPropertyTree* pSchema = NULL;
- sSchemaPath.clear();
- try
- {
- if (pBuild && pBuildSet && connectBuildSet(pBuild, pBuildSet, sSchemaPath, pConstEnv))
- {
- const char *schemaName = pBuildSet->queryProp("@schema");
- if (schemaName && *schemaName)
- {
- sSchemaPath.append(schemaName);
- pSchema = createPTreeFromXMLFile(sSchemaPath);
- }
- else
- {
- const char *processName = pBuildSet->queryProp("@processName");
- if (processName && *processName)
- {
- char szXsdPath[_MAX_PATH+1];
- #ifdef _WINDOWS
- if (GetModuleFileName(NULL, szXsdPath, _MAX_PATH))
- {
- char* pchSlash = strrchr(szXsdPath, PATHSEPCHAR);
- #else
- if (getcwd(szXsdPath,_MAX_PATH))
- {
- char* pchSlash = szXsdPath + strlen(szXsdPath);
- strcat(pchSlash, PATHSEPSTR);
- #endif
- strcpy(pchSlash+1, "generic.xsd");
- sSchemaPath = szXsdPath;
- }
- pSchema = createPTreeFromXMLFile(sSchemaPath);
- if (pSchema)
- {
- IPropertyTree* pNode = pSchema->queryPropTree("xs:element");
- pNode->setProp("@name", processName);
- pNode = pNode->queryPropTree("xs:complexType/xs:sequence/xs:element/xs:complexType/xs:attribute[@name=\"directory\"]");
- if (pNode)
- {
- const char *name = pBuildSet->queryProp("@name");
- StringBuffer sPath("c$\\");
- if (name)
- sPath.append(name);
- pNode->setProp("@default", sPath);
- }
- }
- }
- }
- }
- }
- catch(IException *E)
- {
- StringBuffer buf;
- (E->errorMessage(buf).str());
- E->Release();
- }
- catch(...)
- {
- }
- return pSchema;
- }
- IPropertyTree *loadDefaultSchema()
- {
- return createPTreeFromXMLString(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">"
- " <xs:element name=\"ThorCluster\">"
- " <xs:complexType>"
- " <xs:attribute name=\"build\" type=\"xs:string\" use=\"required\">"
- " <xs:annotation><xs:appinfo>"
- " <tooltip>The build name to be deployed</tooltip>"
- " </xs:appinfo></xs:annotation>"
- " </xs:attribute>"
- " <xs:attribute name=\"buildSet\" type=\"seisint:buildSet\" use=\"required\">"
- " <xs:annotation><xs:appinfo>"
- " <viewType>hidden</viewType>"
- " </xs:appinfo></xs:annotation>"
- " </xs:attribute>"
- " <xs:attribute name=\"name\" type=\"xs:string\" use=\"required\">"
- " <xs:annotation><xs:appinfo>"
- " <tooltip>Name for this process</tooltip>"
- " </xs:appinfo></xs:annotation>"
- " </xs:attribute>"
- " <xs:attribute name=\"description\" type=\"xs:string\" use=\"optional\">"
- " <xs:annotation><xs:appinfo>"
- " <tooltip>Description for this process</tooltip>"
- " </xs:appinfo></xs:annotation>"
- " </xs:attribute>"
- " <xs:attribute name=\"daliServers\" type=\"seisint:daliServers\" use=\"optional\">"
- " <xs:annotation><xs:appinfo>"
- " <tooltip>Select the dali process to be used</tooltip>"
- " </xs:appinfo></xs:annotation>"
- " </xs:attribute>"
- " </xs:complexType>"
- " </xs:element>"
- "</xs:schema>"
- );
- }
|