//For every ECLWatchVisible dropzones, read: dropZoneName, directory, and, if available, computer.
//For every Servers/Server in ECLWatchVisible dropzones, read: directory,
// server name, and hostname(or IP). Create dropzone("@name", "@directory", "@computer",
// "@netAddress", "@linux", "@sourceNode") tree into pSoftware.
void CFileSpraySoapBindingEx::appendDropZones(double clientVersion, IConstEnvironment* env, const char* dfuwuidSourcePartIP, IPropertyTree* softwareTree)
{
    Owned<IConstDropZoneInfoIterator> dropZoneItr = env->getDropZoneIterator();
    ForEach(*dropZoneItr)
    {
        IConstDropZoneInfo& dropZoneInfo = dropZoneItr->query();
        if (!dropZoneInfo.isECLWatchVisible()) //This code is used by ECLWatch. So, skip the DZs not for ECLWatch.
            continue;

        SCMStringBuffer dropZoneName, directory, computerName;
        dropZoneInfo.getName(dropZoneName);
        dropZoneInfo.getDirectory(directory);
        if (!dropZoneName.length() || !directory.length())
            continue;

        bool isLinux = getPathSepChar(directory.str()) == '/' ? true : false;
        Owned<IConstDropZoneServerInfoIterator> dropZoneServerItr = dropZoneInfo.getServers();
        ForEach(*dropZoneServerItr)
        {
            IConstDropZoneServerInfo& dropZoneServer = dropZoneServerItr->query();

            StringBuffer name, server, networkAddress;
            dropZoneServer.getName(name);
            dropZoneServer.getServer(server);
            if (name.isEmpty() || server.isEmpty())
                continue;

            IPropertyTree* dropZone = softwareTree->addPropTree("DropZone", createPTree());
            dropZone->setProp("@name", dropZoneName.str());
            dropZone->setProp("@computer", name.str());
            dropZone->setProp("@directory", directory.str());
            if (isLinux)
                dropZone->setProp("@linux", "true");

            IpAddress ipAddr;
            ipAddr.ipset(server.str());
            ipAddr.getIpText(networkAddress);
            if (!ipAddr.isNull())
            {
                dropZone->addProp("@netAddress", networkAddress);

                if (!isEmptyString(dfuwuidSourcePartIP))
                {
                    IpAddress ip(dfuwuidSourcePartIP);
                    if (ip.ipequals(ipAddr))
                        dropZone->addProp("@sourceNode", "1");
                }
            }
        }
    }
}
Beispiel #2
0
    virtual int run()
    {
        Thread::Link();

        int ret = 0;
        try
        {
            char peername[256];
            int clientport = m_client->peer_name(peername, 256);

            char inbuf[1024];
            char outbuf[1024];
            memset(inbuf, 0, 1024);
            memset(outbuf, 0, 1024);

            unsigned int len = 0;
            unsigned int lenread = 0;
            m_client->read(inbuf, 8, 8, lenread);
            if(lenread != 8)
            {
                DBGLOG("didn't get the first 8 bytes, invalid socks request.");
                return -1;
            }

            len += lenread;
            m_client->read(inbuf + len, 0, 1, lenread);
            StringBuffer username;
            while(lenread > 0)
            {
                len += lenread;
                if(len >= 1023)
                {
                    len = 0;
                }
                if(inbuf[len - 1] == '\0')
                {
                    break;
                }
                char c = inbuf[len - 1];
                username.append(c);
                m_client->read(inbuf + len, 0, 1, lenread);
            }
            
            if(http_tracelevel >= 5)
                fprintf(m_ofile, "\n>>receivd SOCKS request from %s:%d, user %s\n", peername, clientport, username.str());

            outbuf[0] = '\0';
            outbuf[1] = (char)0x5a;

            m_client->write(outbuf, 8);

            char ubyte = inbuf[2];
            char lbyte = inbuf[3];
            unsigned short port = (unsigned short)ubyte;
            port = port << 8;
            port += lbyte;

            // TBD IPV6 (should use serialize/deserialize)

            IpAddress ip;
            ip.setNetAddress(4,inbuf+4);        
                                                

            StringBuffer ipstr;
            ip.getIpText(ipstr);
            if(http_tracelevel >= 5)
                fprintf(m_ofile, "\n>>The request is for %s:%d\n", ipstr.str(), port);      

            SocketEndpoint ep;
            ep.set(port, ip);
            m_remotesocket.setown(ISocket::connect(ep));

            m_client->set_nonblock(false);
            m_remotesocket->set_nonblock(false);
            CReadWriteThread t1(m_client.get(), m_remotesocket.get(), m_ofile);
            CReadWriteThread t2(m_remotesocket.get(), m_client.get(), m_ofile);
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            m_remotesocket->shutdown();
            m_remotesocket->close();
            m_client->shutdown();
            m_client->close();
        }
        catch(IException *excpt)
        {
            StringBuffer errMsg;
            DBGLOG("%s", excpt->errorMessage(errMsg).str());
            ret = -1;
        }
        catch(...)
        {
            DBGLOG("unknown exception");
            ret = -1;
        }

        Thread::Release();

        return 0;
    }
void Cws_machineEx::ConvertAddress( const char* originalAddress, StringBuffer& newAddress)
{
    if (!originalAddress || !*originalAddress)
        throw MakeStringException(ECLWATCH_INVALID_IP_OR_COMPONENT, "No network address or computer name specified!");

    StringArray sArray;
    sArray.appendList(originalAddress, ":");

    if (sArray.ordinality() < 4)
        throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Incomplete arguments");

    const char* address = sArray.item(0);
    const char* compType= sArray.item(1);
    const char* compName= sArray.item(2);
    const char* OS        = sArray.item(3);
    const char* path      = sArray.item(4);

    StringBuffer process;
    if (sArray.ordinality() > 5)
    {
        const char* ClusterType   = sArray.item(5);
        if (ClusterType && *ClusterType)
        {
            if (strcmp("THORMACHINES",ClusterType) == 0)
            {
                process.append("ThorMasterProcess");
            }
            else if (strcmp("ROXIEMACHINES",ClusterType) == 0)
            {
                process.append("RoxieServerProcess");
            }
        }
    }

    if (strchr(address, '.')) //have an IP address
    {
        newAddress.clear().append(originalAddress);
        return;
    }

    StringBuffer xpath;
    if (!strcmp(compType, "RoxieCluster"))
    {
        xpath.append("RoxieServer");
    }
    else if (!strcmp(compType, "ThorCluster"))
    {
        xpath.append("ThorMaster");
    }
    else if (!strcmp(compType, "HoleCluster"))
    {
        xpath.append("HoleControl");
    }
    else
        throw MakeStringException(ECLWATCH_INVALID_COMPONENT_TYPE, "Failed to resolve address for component type '%s'", compType);

    Owned<IPropertyTree> pComponent = getComponent(compType, address);
    xpath.append("Process[1]/@computer");
    const char* computer = pComponent->queryProp(xpath.str());

    if (!computer || !*computer)
        throw MakeStringException(ECLWATCH_INVALID_COMPONENT_INFO, "Failed to resolve computer for %s '%s'!", compType, address);

    Owned<IConstEnvironment> pConstEnv = getConstEnvironment();
    Owned<IConstMachineInfo> pConstMc  = pConstEnv->getMachine(computer);

    SCMStringBuffer sAddress;
    pConstMc->getNetAddress(sAddress);
#ifndef OLD_START_STOP
    {
        StringBuffer sConfigAddress;
        sConfigAddress.append(sAddress.str());

        if (!strcmp(sAddress.str(), "."))
        {
            StringBuffer ipStr;
            IpAddress ipaddr = queryHostIP();
            ipaddr.getIpText(ipStr);
            if (ipStr.length() > 0)
            {
#ifdef MACHINE_IP
                sAddress.set(MACHINE_IP);
#else
                sAddress.set(ipStr.str());
#endif
            }
        }

        if (process.length() > 0)
            newAddress.clear().appendf("%s|%s:%s:%s:%s:%s", sAddress.str(), sConfigAddress.str(), process.str(), compName, OS, path);
        else
            newAddress.clear().appendf("%s|%s:%s:%s:%s:%s", sAddress.str(), sConfigAddress.str(), compType, compName, OS, path);
    }
#else
        if (process.length() > 0)
            newAddress.clear().appendf("%s:%s:%s:%s:%s", sAddress.str(), process.str(), compName, OS, path);
        else
            newAddress.clear().appendf("%s:%s:%s:%s:%s", sAddress.str(), compType, compName, OS, path);
        //newAddress.clear().appendf("%s:ThorMasterProcess:%s:%s:%s", sAddress.str(), compName, OS, path);
#endif
    return;
}
   virtual void doWork()
   {
        if (m_useHPCCInit)
        {
            //address specified can be either IP or name of component
            const char* address = m_sAddress.str();
            const char* configAddress = m_sConfigAddress.str();
            if (!address || !*address)
                throw MakeStringException(ECLWATCH_INVALID_IP_OR_COMPONENT, "Invalid address or component name was specified!");

            if (!strchr(address, '.')) //not an IP address
            {
                const char* compType = m_pResult->getCompType();
                const char* compName = address;

                if (!compType || !*compType)
                    throw MakeStringException(ECLWATCH_INVALID_COMPONENT_TYPE, "No component type specified!");

                StringBuffer xpath;
                if (!strcmp(compType, "RoxieCluster"))
                {
                    xpath.append("RoxieServer");
                }
                else if (!strcmp(compType, "ThorCluster"))
                {
                    xpath.append("ThorMaster");
                }
                else if (!strcmp(compType, "HoleCluster"))
                {
                    xpath.append("HoleControl");
                }
                else
                    throw MakeStringException(ECLWATCH_INVALID_COMPONENT_TYPE, "Failed to resolve component type '%s'", compType);

                Owned<IPropertyTree> pComponent = m_pService->getComponent(compType, compName);
                xpath.append("Process[1]/@computer");
                const char* computer = pComponent->queryProp(xpath.str());

                if (!computer || !*computer)
                    throw MakeStringException(ECLWATCH_INVALID_COMPONENT_INFO, "Failed to resolve computer for %s '%s'!", compType, compName);

                Owned<IConstEnvironment> pConstEnv = m_pService->getConstEnvironment();
                Owned<IConstMachineInfo> pConstMc  = pConstEnv->getMachine(computer);

                SCMStringBuffer sAddress;
                pConstMc->getNetAddress(sAddress);

                if (!stricmp(m_sAddress.str(), m_sConfigAddress.str()))
                {
                    m_sAddress.clear().append(sAddress.str());
                    m_sConfigAddress = m_sAddress;
                    m_pResult->setAddress( sAddress.str() );
                }
                else
                {
                    m_sAddress.clear().append(sAddress.str());
                    m_pResult->setAddress( sAddress.str() );
                    if (configAddress && !strchr(configAddress, '.')) //not an IP address
                    {
                        Owned<IPropertyTree> pComponent = m_pService->getComponent(compType, configAddress);
                        xpath.append("Process[1]/@computer");
                        const char* computer = pComponent->queryProp(xpath.str());

                        if (!computer || !*computer)
                            throw MakeStringException(ECLWATCH_INVALID_COMPONENT_INFO, "Failed to resolve computer for %s '%s'!", compType, configAddress);

                        Owned<IConstEnvironment> pConstEnv = m_pService->getConstEnvironment();
                        Owned<IConstMachineInfo> pConstMc  = pConstEnv->getMachine(computer);

                        SCMStringBuffer sAddress;
                        pConstMc->getNetAddress(sAddress);
                        m_sConfigAddress.clear().append(sAddress.str());
                    }
                }
            }

            if ((m_sAddress.length() > 0) && !stricmp(m_sAddress.str(), "."))
            {
                StringBuffer ipStr;
                IpAddress ipaddr = queryHostIP();
                ipaddr.getIpText(ipStr);
                if (ipStr.length() > 0)
                {
#ifdef MACHINE_IP
                    m_sAddress.clear().append(MACHINE_IP);
#else
                    m_sAddress.clear().append(ipStr.str());
#endif
                    m_pResult->setAddress( m_sAddress.str() );
                }
            }

#ifdef OLD_START_STOP
            int OS = m_pResult->getOS();

            StringBuffer sPath( m_pResult->getPath() );
            if (OS == 0)
                sPath.replace('$', ':');
            else
                if (sPath.charAt(0) != '/')
                    sPath.insert(0, '/');
            m_sCommand.clear().append(sPath).append( OS==0 ? '\\' : '/');
            m_sCommand.append(m_bStop ? "stop" : "startup");
            if (OS == 0)
                m_sCommand.append(".bat");
            m_sCommand.append(' ');

            m_sCommand.append(sPath);
#else
            StringBuffer sPath( m_pResult->getPath() );
            if (sPath.charAt(sPath.length() - 1) == '/')
                sPath.setLength(sPath.length() - 1);
            if (sPath.length() > 0)
            {
                char* pStr = (char*) sPath.str();
                char* ppStr = strchr(pStr, '/');
                while (ppStr)
                {
                    ppStr++;
                    pStr = ppStr;
                    ppStr = strchr(pStr, '/');
                }

                if (!m_bStop)
                    m_sCommand.appendf("sudo /etc/init.d/hpcc-init -c %s start", pStr);
                else
                    m_sCommand.appendf("sudo /etc/init.d/hpcc-init -c %s stop", pStr);
            }
#endif
            m_pResult->setCommand( m_sCommand.str() );
        }
        else
        {
            //address specified can be either IP or name of component
            const char* address = m_sAddress.str();
            if (!address || !*address)
                throw MakeStringException(ECLWATCH_INVALID_IP_OR_COMPONENT, "Invalid address or component name was specified!");

            if (!strchr(address, '.')) //not an IP address
            {
                const char* compType = m_pResult->getCompType();
                const char* compName = address;

                if (!compType || !*compType)
                    throw MakeStringException(ECLWATCH_INVALID_COMPONENT_TYPE, "No component type specified!");

                StringBuffer xpath;
                if (!strcmp(compType, "RoxieCluster"))
                {
                    xpath.append("RoxieServer");
                }
                else if (!strcmp(compType, "ThorCluster"))
                {
                    xpath.append("ThorMaster");
                }
                else if (!strcmp(compType, "HoleCluster"))
                {
                    xpath.append("HoleControl");
                }
                else
                    throw MakeStringException(ECLWATCH_INVALID_COMPONENT_TYPE, "Failed to resolve component type '%s'", compType);

                Owned<IPropertyTree> pComponent = m_pService->getComponent(compType, compName);
                xpath.append("Process[1]/@computer");
                const char* computer = pComponent->queryProp(xpath.str());

                if (!computer || !*computer)
                    throw MakeStringException(ECLWATCH_INVALID_COMPONENT_INFO, "Failed to resolve computer for %s '%s'!", compType, compName);

                Owned<IConstEnvironment> pConstEnv = m_pService->getConstEnvironment();
                Owned<IConstMachineInfo> pConstMc  = pConstEnv->getMachine(computer);

                SCMStringBuffer sAddress;
                pConstMc->getNetAddress(sAddress);

                m_sAddress.clear().append(sAddress.str());
                m_pResult->setAddress( sAddress.str() );
            }

            int OS = m_pResult->getOS();

            StringBuffer sPath( m_pResult->getPath() );
            if (OS == 0)
                sPath.replace('$', ':');
            else
                if (sPath.charAt(0) != '/')
                    sPath.insert(0, '/');

            m_sCommand.clear().append(sPath).append( OS==0 ? '\\' : '/');
            m_sCommand.append(m_bStop ? "stop" : "startup");
            if (OS == 0)
                m_sCommand.append(".bat");
            m_sCommand.append(' ');

            m_sCommand.append(sPath);
            m_pResult->setCommand( m_sCommand.str() );
        }
        CRemoteExecThreadParam::doWork();
    }
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();
}