bool deletePkgInfo(const char *name, const char *target, const char *process, bool globalScope)
{
    Owned<IRemoteConnection> pkgSetsConn = querySDS().connect("/PackageSets/", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT);
    if (!pkgSetsConn)
        throw MakeStringException(PKG_NONE_DEFINED, "No package sets defined");

    IPropertyTree* packageSets = pkgSetsConn->queryRoot();

    StringBuffer pkgSetId;
    buildPkgSetId(pkgSetId, process);
    VStringBuffer pkgSet_xpath("PackageSet[@id='%s']", pkgSetId.str());
    IPropertyTree *pkgSetRegistry = packageSets->queryPropTree(pkgSet_xpath.str());
    if (!pkgSetRegistry)
        throw MakeStringException(PKG_TARGET_NOT_DEFINED, "No package sets defined for %s", process);

    StringBuffer lcTarget(target);
    target = lcTarget.toLowerCase().str();

    StringBuffer lcName(name);
    name = lcName.toLowerCase().str();

    Owned<IPropertyTree> mapEntry;
    StringBuffer xpath;
    if (!globalScope)
    {
        xpath.appendf("PackageMap[@id='%s::%s'][@querySet='%s']", target, name, target);
        mapEntry.setown(pkgSetRegistry->getPropTree(xpath.str()));
    }
    if (!mapEntry)
    {
        xpath.clear().appendf("PackageMap[@id='%s'][@querySet='%s']", name, target);
        mapEntry.setown(pkgSetRegistry->getPropTree(xpath.str()));
        if (!mapEntry)
            throw MakeStringException(PKG_DELETE_NOT_FOUND, "Unable to delete %s - information not found", lcName.str());
    }
    StringAttr pmid(mapEntry->queryProp("@id"));
    pkgSetRegistry->removeTree(mapEntry);

    xpath.clear().appendf("PackageSet/PackageMap[@id='%s']", pmid.get());
    if (!packageSets->hasProp(xpath))
    {
        Owned<IRemoteConnection> pkgMapsConn = querySDS().connect("/PackageMaps/", myProcessSession(), RTM_LOCK_WRITE, SDS_LOCK_TIMEOUT);
        if (!pkgMapsConn)
            throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve PackageMaps information from dali [/PackageMaps]");
        IPropertyTree *pkgMaps = pkgMapsConn->queryRoot();
        if (!pkgMaps)
            throw MakeStringException(PKG_DALI_LOOKUP_ERROR, "Unable to retrieve PackageMaps information from dali [/PackageMaps]");
        IPropertyTree *mapTree = pkgMaps->queryPropTree(xpath.clear().appendf("PackageMap[@id='%s']", pmid.get()).str());
        if (mapTree)
            pkgMaps->removeTree(mapTree);
    }
    return true;
}
    void doCreate(const char *partname, const char *xml, unsigned updateFlags, StringArray &filesNotFound)
    {
        createPart(partname, xml);

        if (pmExisting)
        {
            if (!checkFlag(PKGADD_MAP_REPLACE))
                throw MakeStringException(PKG_NAME_EXISTS, "PackageMap %s already exists, either delete it or specify overwrite", pmid.str());
        }

        cloneDfsInfo(updateFlags, filesNotFound);

        if (pmExisting)
            packageMaps->removeTree(pmExisting);

        Owned<IPropertyTree> pmTree = createPTree("PackageMap", ipt_ordered);
        pmTree->setProp("@id", pmid);
        pmTree->setPropBool("@multipart", true);
        pmTree->addPropTree("Part", pmPart.getClear());
        packageMaps->addPropTree("PackageMap", pmTree.getClear());

        VStringBuffer xpath("PackageMap[@id='%s'][@querySet='%s']", pmid.str(), target.get());
        Owned<IPropertyTree> pkgSet = getPkgSetRegistry(process, false);
        IPropertyTree *psEntry = pkgSet->queryPropTree(xpath);

        if (!psEntry)
        {
            psEntry = pkgSet->addPropTree("PackageMap", createPTree("PackageMap"));
            psEntry->setProp("@id", pmid);
            psEntry->setProp("@querySet", target);
        }
        makePackageActive(pkgSet, psEntry, target, checkFlag(PKGADD_MAP_ACTIVATE));
    }
    void convertExisting()
    {
        Linked<IPropertyTree> pmPart = pmExisting;
        const char *s = strstr(pmid.str(), "::");
        if (s)
            pmPart->addProp("@id", s+2);
        packageMaps->removeTree(pmExisting);

        Owned<IPropertyTree> pmTree = createPTree("PackageMap", ipt_ordered);
        pmTree->setProp("@id", pmid);
        pmTree->setPropBool("@multipart", true);
        pmTree->addPropTree("Part", pmPart.getClear());
        pmExisting = packageMaps->addPropTree("PackageMap", pmTree.getClear());
    }
Ejemplo n.º 4
0
void SWProcess::computerDeleted(const char* ipAddress, const char* computerName, const char *instanceXMLTagName)
{
   IPropertyTree * software = m_envHelper->getEnvTree()->queryPropTree(XML_TAG_SOFTWARE);
   Owned<IPropertyTreeIterator> compIter = software->getElements(m_processName);

   const char *instance = (instanceXMLTagName)? instanceXMLTagName: m_instanceElemName.str();

   synchronized block(mutex);
   ForEach (*compIter)
   {
      IPropertyTree * comp = &compIter->query();
      Owned<IPropertyTreeIterator> instanceIter = comp->getElements(instance);
      ForEach (*instanceIter)
      {
         IPropertyTree * instance = &instanceIter->query();
         if ((instance->hasProp(m_ipAttribute.str()) && stricmp(instance->queryProp(m_ipAttribute.str()), ipAddress)) ||
             (instance->hasProp("@computer") && stricmp(instance->queryProp("@computer"), computerName)))
            comp->removeTree(instance);
      }
   }
}
    void addPart(const char *partname, const char *xml, unsigned updateFlags, StringArray &filesNotFound)
    {
        init();

        if (!pmExisting)
        {
            doCreate(partname, xml, updateFlags, filesNotFound);
            return;
        }

        createPart(partname, xml);

        VStringBuffer xpath("Part[@id='%s']", partname);
        IPropertyTree *existingPart = pmExisting->queryPropTree(xpath);
        if (existingPart && !checkFlag(PKGADD_SEG_REPLACE))
            throw MakeStringException(PKG_NAME_EXISTS, "Package Part %s already exists, remove, or specify 'delete previous'", partname);

        cloneDfsInfo(updateFlags, filesNotFound);

        if (existingPart)
            pmExisting->removeTree(existingPart);

        pmExisting->addPropTree("Part", pmPart.getClear());
    }
void addPackageMapInfo(const char *xml, StringArray &filesNotFound, const char *process, const char *target, const char *pmid, const char *packageSetName, const char *lookupDaliIp, const char *srcCluster, const char *prefix, bool activate, bool overWrite, IUserDescriptor* userdesc, bool allowForeignFiles, bool preloadAll)
{
    if (!xml || !*xml)
        throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "PackageMap info not provided");

    if (srcCluster && *srcCluster)
    {
        if (!isProcessCluster(lookupDaliIp, srcCluster))
            throw MakeStringException(PKG_INVALID_CLUSTER_TYPE, "Process cluster %s not found on %s DALI", srcCluster, lookupDaliIp ? lookupDaliIp : "local");
    }

    Owned<IConstWUClusterInfo> clusterInfo = getTargetClusterInfo(target);
    if (!clusterInfo)
        throw MakeStringException(PKG_TARGET_NOT_DEFINED, "Could not find information about target cluster %s ", target);

    Owned<IPropertyTree> pmTree = createPTreeFromXMLString(xml);
    if (!pmTree)
        throw MakeStringExceptionDirect(PKG_INFO_NOT_DEFINED, "Invalid PackageMap info");

    StringBuffer lcPmid(pmid);
    pmid = lcPmid.toLowerCase().str();
    pmTree->setProp("@id", pmid);

    Owned<IPropertyTreeIterator> iter = pmTree->getElements("Package");
    ForEach(*iter)
    {
        IPropertyTree &item = iter->query();
        if (preloadAll)
            item.setPropBool("@preload", true);
        Owned<IPropertyTreeIterator> superFiles = item.getElements("SuperFile");
        ForEach(*superFiles)
        {
            IPropertyTree &superFile = superFiles->query();
            StringBuffer lc(superFile.queryProp("@id"));
            const char *id = lc.toLowerCase().str();
            if (*id == '~')
                id++;
            superFile.setProp("@id", id);

            Owned<IPropertyTreeIterator> subFiles = superFile.getElements("SubFile");
            ForEach(*subFiles)
            {
                IPropertyTree &subFile = subFiles->query();
                id = subFile.queryProp("@value");
                if (id && *id == '~')
                {
                    StringAttr value(id+1);
                    subFile.setProp("@value", value.get());
                }
            }
        }
    }

    VStringBuffer xpath("PackageMap[@id='%s']", pmid);
    Owned<IRemoteConnection> globalLock = querySDS().connect("/PackageMaps", myProcessSession(), RTM_LOCK_WRITE|RTM_CREATE_QUERY, SDS_LOCK_TIMEOUT);
    IPropertyTree *packageMaps = globalLock->queryRoot();
    IPropertyTree *pmExisting = packageMaps->queryPropTree(xpath);

    xpath.appendf("[@querySet='%s']", target);
    Owned<IPropertyTree> pkgSet = getPkgSetRegistry(process, false);
    IPropertyTree *psEntry = pkgSet->queryPropTree(xpath);

    if (!overWrite && (psEntry || pmExisting))
        throw MakeStringException(PKG_NAME_EXISTS, "Package name %s already exists, either delete it or specify overwrite", pmid);

    cloneFileInfoToDali(filesNotFound, pmTree, lookupDaliIp, clusterInfo, srcCluster, prefix, overWrite, userdesc, allowForeignFiles);

    if (pmExisting)
        packageMaps->removeTree(pmExisting);
    packageMaps->addPropTree("PackageMap", pmTree.getClear());

    if (!psEntry)
    {
        psEntry = pkgSet->addPropTree("PackageMap", createPTree("PackageMap"));
        psEntry->setProp("@id", pmid);
        psEntry->setProp("@querySet", target);
    }
    makePackageActive(pkgSet, psEntry, target, activate);
}
 void removePart(const char *partname)
 {
     init();
     pmExisting->removeTree(ensurePart(partname));
 }