int main(int argc, const char *argv[]) { InitModuleObjects(); int ret = 0; bool dryRun = false; bool offline = false; StringAttr daliServer, envPath; enum CmdType { cmd_none, cmd_swap, cmd_auto, cmd_history, cmd_email, cmd_swapped, cmd_reset, cmd_resetspares, cmd_addspares, cmd_removespares, cmd_resethistory }; CmdType cmd = cmd_none; ArgvIterator iter(argc, argv); try { bool stop=false; StringArray params; for (; !ret&&!iter.done(); iter.next()) { const char *arg = iter.query(); if ('-' == *arg) { bool value; if (iter.matchFlag(value, "-dryrun")) dryRun = value; else if (iter.matchFlag(value, "-offline")) offline = value; else { PROGLOG("Unknown option"); ret = 2; usage(); break; } } else { switch (cmd) { case cmd_none: if (strieq("swap", arg)) cmd = cmd_swap; else if (strieq("auto", arg)) cmd = cmd_auto; else if (strieq("history", arg)) cmd = cmd_history; else if (strieq("email", arg)) cmd = cmd_email; else if (strieq("swapped", arg)) cmd = cmd_swapped; else if (strieq("reset", arg)) cmd = cmd_reset; else if (strieq("resetspares", arg)) cmd = cmd_resetspares; else if (strieq("addspares", arg)) cmd = cmd_addspares; else if (strieq("removespares", arg)) cmd = cmd_removespares; else if (strieq("resethistory", arg)) cmd = cmd_resethistory; else { PROGLOG("Unknown command"); usage(); ret = 2; } break; default: params.append(iter.query()); break; } } } unsigned requiredParams=UINT_MAX; switch (cmd) { case cmd_swap: requiredParams = 4; break; case cmd_addspares: case cmd_removespares: requiredParams = 3; break; case cmd_auto: case cmd_history: case cmd_email: case cmd_swapped: case cmd_reset: case cmd_resetspares: case cmd_resethistory: requiredParams = 2; break; } if (params.ordinality() < requiredParams) { usage(); ret = 2; } else { StringAttr daliServer = params.item(0); StringAttr clusterName = params.item(1); DaliClient dclient(daliServer); StringBuffer logname; splitFilename(argv[0], NULL, NULL, &logname, NULL); addFileTimestamp(logname, true); logname.append(".log"); StringBuffer lf; openLogFile(lf, logname.str(),0,false,true); queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix); Owned<IRemoteConnection> conn = querySDS().connect("/Environment", myProcessSession(), RTM_LOCK_READ, SDS_LOCK_TIMEOUT); IPropertyTree *environment = conn->queryRoot(); StringBuffer xpath("Software/ThorCluster[@name=\""); xpath.append(clusterName).append("\"]"); IPropertyTree *cluster = environment->queryPropTree(xpath.str()); if (!cluster) { PROGLOG("Unknown cluster: %s", clusterName.get()); ret = 3; } if (!ret) { Owned<IPropertyTree> options = createPTreeFromIPT(cluster); conn.clear(); if (options&&options->getPropBool("@enableSysLog",true)) UseSysLogForOperatorMessages(); switch (cmd) { case cmd_auto: { if (!autoSwapNode(clusterName, dryRun)) ret = 3; break; } case cmd_swap: { const char *oldip=params.item(2); const char *newip=params.item(3); if (!swapNode(clusterName, oldip, newip)) ret = 3; break; } case cmd_history: case cmd_swapped: case cmd_email: { unsigned days = params.isItem(2) ? atoi(params.item(2)) : 0; // for history or swapped switch (cmd) { case cmd_history: swapNodeHistory(clusterName, days, NULL); break; case cmd_swapped: swappedList(clusterName, days, NULL); break; case cmd_email: { bool sendSwapped = false; bool sendHistory = false; if (params.isItem(2)) { if (strieq("swapped", params.item(2))) sendSwapped = true; else if (strieq("history", params.item(2))) sendHistory = true; } emailSwap(clusterName, NULL, true, sendSwapped, sendHistory); break; } } break; } case cmd_reset: case cmd_resetspares: { StringBuffer response; if (!resetClusterGroup(clusterName, "ThorCluster", cmd==cmd_resetspares, response)) { WARNLOG("%s", response.str()); ret = 3; } break; } case cmd_addspares: case cmd_removespares: { SocketEndpointArray allEps; unsigned p=2; do { const char *ipOrRange = params.item(p); SocketEndpointArray epa; epa.fromText(ipOrRange, 0); ForEachItemIn(e, epa) allEps.append(epa.item(e)); p++; } while (p<params.ordinality()); StringBuffer response; bool res; if (cmd == cmd_addspares) res = addClusterSpares(clusterName, "ThorCluster", allEps, response); else res = removeClusterSpares(clusterName, "ThorCluster", allEps, response); if (!res) { WARNLOG("%s", response.str()); ret = 3; } break; } case cmd_resethistory: { Owned<IRemoteConnection> conn = querySDS().connect("/SwapNode", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT); if (conn) { StringBuffer groupName; getClusterGroupName(*options, groupName); VStringBuffer xpath("Thor[@group=\"%s\"]", groupName.str()); if (conn->queryRoot()->removeProp(xpath.str())) PROGLOG("SwapNode info for cluster %s removed", clusterName.get()); else PROGLOG("SwapNode info for cluster %s not found", clusterName.get()); } break; } } } } UseSysLogForOperatorMessages(false); } catch (IException *e) { EXCLOG(e,"SWAPNODE"); e->Release(); ret = -1; } ExitModuleObjects(); return ret; }
IPropertyTree* CFileSpraySoapBindingEx::createPTreeForXslt(const char* method, const char* dfuwuid) { Owned<IEnvironmentFactory> factory = getEnvironmentFactory(); Owned<IConstEnvironment> m_constEnv = factory->openEnvironment(); Owned<IPropertyTree> pEnvRoot = &m_constEnv->getPTree(); IPropertyTree* pEnvSoftware = pEnvRoot->queryPropTree("Software"); Owned<IPropertyTree> pRoot = createPTreeFromXMLString("<Environment/>"); IPropertyTree* pSoftware = pRoot->addPropTree("Software", createPTree("Software")); if (pEnvSoftware) { StringBuffer dfuwuidSourcePartIP, wuxml; if(dfuwuid && *dfuwuid) { Owned<IDFUWorkUnitFactory> dfuwu_factory = getDFUWorkUnitFactory(); Owned<IConstDFUWorkUnit> dfuwu = dfuwu_factory->openWorkUnit(dfuwuid, false); if(dfuwu) { dfuwu->toXML(wuxml); Owned<IPropertyTree> wu = createPTreeFromXMLString(wuxml.str()); if (wu) { const char* ip = wu->queryProp("Source/Part/@node"); if (ip && *ip) dfuwuidSourcePartIP.append(ip); } } } Owned<IPropertyTreeIterator> it = pEnvSoftware->getElements("DropZone"); ForEach(*it) { IPropertyTree* pDropZone = pSoftware->addPropTree("DropZone", &it->get()); //get IP Address of the computer associated with this drop zone const char* pszComputer = it->query().queryProp("@computer"); if (!strcmp(pszComputer, ".")) pszComputer = "localhost"; StringBuffer xpath; xpath.appendf("Hardware/Computer[@name='%s']/@netAddress", pszComputer); StringBuffer sNetAddr; const char* pszNetAddr = pEnvRoot->queryProp(xpath.str()); if (strcmp(pszNetAddr, ".")) { sNetAddr.append(pszNetAddr); } else { StringBuffer ipStr; IpAddress ipaddr = queryHostIP(); ipaddr.getIpText(ipStr); if (ipStr.length() > 0) { #ifdef MACHINE_IP sNetAddr.append(MACHINE_IP); #else sNetAddr.append(ipStr.str()); #endif } } pDropZone->addProp("@netAddress", sNetAddr.str()); if ((dfuwuidSourcePartIP.length() > 0) && (sNetAddr.length() > 0)) { IpAddress ip1(dfuwuidSourcePartIP.str()), ip2(sNetAddr.str()); if (ip1.ipequals(ip2)) pDropZone->addProp("@sourceNode", "1"); } Owned<IConstMachineInfo> machine; if (strcmp(pszNetAddr, ".")) machine.setown(m_constEnv->getMachineByAddress(sNetAddr.str())); else { machine.setown(m_constEnv->getMachineByAddress(pszNetAddr)); if (!machine) machine.setown(m_constEnv->getMachineByAddress(sNetAddr.str())); } if (machine) { //int os = machine->getOS(); StringBuffer dir; pDropZone->getProp("@directory", dir); if (machine->getOS() == MachineOsLinux || machine->getOS() == MachineOsSolaris) { dir.replace('\\', '/');//replace all '\\' by '/' pDropZone->setProp("@linux", "true"); } else { dir.replace('/', '\\'); dir.replace('$', ':'); } pDropZone->setProp("@directory", dir); } } //For Spray files on Thor Cluster, fetch all the group names for all the thor instances (and dedup them) BoolHash uniqueThorClusterGroupNames; it.setown(pEnvSoftware->getElements("ThorCluster")); ForEach(*it) { StringBuffer thorClusterGroupName; IPropertyTree& cluster = it->query(); getClusterGroupName(cluster, thorClusterGroupName); if (!thorClusterGroupName.length()) continue; bool* found = uniqueThorClusterGroupNames.getValue(thorClusterGroupName.str()); if (found && *found) continue; uniqueThorClusterGroupNames.setValue(thorClusterGroupName.str(), true); IPropertyTree* newClusterTree = pSoftware->addPropTree("ThorCluster", &it->get()); newClusterTree->setProp("@name", thorClusterGroupName.str()); //set group name into @name for spray target } it.setown(pEnvSoftware->getElements("EclAgentProcess")); ForEach(*it) { IPropertyTree &cluster = it->query(); const char* name = cluster.queryProp("@name"); if (!name||!*name) continue; unsigned ins = 0; Owned<IPropertyTreeIterator> insts = cluster.getElements("Instance"); ForEach(*insts) { const char *na = insts->query().queryProp("@netAddress"); if (!na || !*na) { insts->query().setProp("@gname", name); continue; } SocketEndpoint ep(na); if (ep.isNull()) continue; ins++; StringBuffer gname("hthor__"); //StringBuffer gname; gname.append(name); if (ins>1) gname.append('_').append(ins); insts->query().setProp("@gname", gname.str()); } pSoftware->addPropTree("EclAgentProcess", &it->get()); } if (stricmp(method, "CopyInput") == 0) //Limit for this method only { it.setown(pEnvSoftware->getElements("RoxieCluster")); ForEach(*it) pSoftware->addPropTree("RoxieCluster", &it->get()); } if (wuxml.length() > 0) pSoftware->addPropTree("DfuWorkunit", createPTreeFromXMLString(wuxml.str())); } return pRoot.getClear(); }
IPropertyTree* CFileSpraySoapBindingEx::createPTreeForXslt(double clientVersion, const char* method, const char* dfuwuid) { Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true); Owned<IConstEnvironment> constEnv = factory->openEnvironment(); Owned<IPropertyTree> pEnvRoot = &constEnv->getPTree(); IPropertyTree* pEnvSoftware = pEnvRoot->queryPropTree("Software"); Owned<IPropertyTree> pRoot = createPTreeFromXMLString("<Environment/>"); IPropertyTree* pSoftware = pRoot->addPropTree("Software", createPTree("Software")); if (pEnvSoftware) { StringBuffer dfuwuidSourcePartIP, wuxml; if(dfuwuid && *dfuwuid) { Owned<IDFUWorkUnitFactory> dfuwu_factory = getDFUWorkUnitFactory(); Owned<IConstDFUWorkUnit> dfuwu = dfuwu_factory->openWorkUnit(dfuwuid, false); if(dfuwu) { dfuwu->toXML(wuxml); Owned<IPropertyTree> wu = createPTreeFromXMLString(wuxml.str()); if (wu) { const char* ip = wu->queryProp("Source/Part/@node"); if (ip && *ip) dfuwuidSourcePartIP.append(ip); } } } appendDropZones(clientVersion, constEnv, dfuwuidSourcePartIP.str(), pSoftware); //For Spray files on Thor Cluster, fetch all the group names for all the thor instances (and dedup them) BoolHash uniqueThorClusterGroupNames; Owned<IPropertyTreeIterator> it =pEnvSoftware->getElements("ThorCluster"); ForEach(*it) { StringBuffer thorClusterGroupName; IPropertyTree& cluster = it->query(); getClusterGroupName(cluster, thorClusterGroupName); if (!thorClusterGroupName.length()) continue; bool* found = uniqueThorClusterGroupNames.getValue(thorClusterGroupName.str()); if (found && *found) continue; uniqueThorClusterGroupNames.setValue(thorClusterGroupName.str(), true); IPropertyTree* newClusterTree = pSoftware->addPropTree("ThorCluster", &it->get()); newClusterTree->setProp("@name", thorClusterGroupName.str()); //set group name into @name for spray target } it.setown(pEnvSoftware->getElements("EclAgentProcess")); ForEach(*it) { IPropertyTree &cluster = it->query(); const char* name = cluster.queryProp("@name"); if (!name||!*name) continue; unsigned ins = 0; Owned<IPropertyTreeIterator> insts = cluster.getElements("Instance"); ForEach(*insts) { const char *na = insts->query().queryProp("@netAddress"); if (!na || !*na) { insts->query().setProp("@gname", name); continue; } SocketEndpoint ep(na); if (ep.isNull()) continue; ins++; StringBuffer gname("hthor__"); //StringBuffer gname; gname.append(name); if (ins>1) gname.append('_').append(ins); insts->query().setProp("@gname", gname.str()); } pSoftware->addPropTree("EclAgentProcess", &it->get()); } if (stricmp(method, "CopyInput") == 0) //Limit for this method only { it.setown(pEnvSoftware->getElements("RoxieCluster")); ForEach(*it) pSoftware->addPropTree("RoxieCluster", &it->get()); } if (wuxml.length() > 0) pSoftware->addPropTree("DfuWorkunit", createPTreeFromXMLString(wuxml.str())); } return pRoot.getClear(); }