This topic contains 5 replies, has 2 voices, and was last updated by  Eliot Muir 9 years ago.

HTTP API add_channel: New project GUIDs?

  • Hi,
    I’m trying out a new thing now. I’d like to add a new channel to the Iguana instance over the HTTP API.

    In case you’re wondering, here is the code (ugly, but just a proof of concept):

    
    using (var client = new WebClient())
    {
        var values = InitParams();
        values["config"] = configData;
        var response = client.UploadValues(getUrl("add_channel"), values);
        string configtxt = Encoding.Default.GetString(response);
        MessageBox.Show("Channel added.");
    
        XPathDocument configdoc = new XPathDocument(new StringReader(configtxt));
        XPathNavigator nav = configdoc.CreateNavigator();
        nav = nav.SelectSingleNode("/channel/from_mapper");
        if (nav == null)
        {
            MessageBox.Show("Cannot read /channel/from_mapper in config.");
            return;
        }
    
        string luaguid = nav.GetAttribute("guid", string.Empty);
        string luamilestone = nav.GetAttribute("milestone", string.Empty);
    
        values = InitParams();
        values["project"] = encodedData;
        values["guid"] = luaguid;
        response = client.UploadValues(getUrl("import_project"), values);
        MessageBox.Show(Encoding.Default.GetString(response));
    
        values = InitParams();
        values["milestone_name"] = luamilestone;
        values["guid"] = luaguid;
        response = client.UploadValues(getUrl("save_project_milestone"), values);
        MessageBox.Show(Encoding.Default.GetString(response));
    }
    

    With some helper methods:

    
    private string getUrl(string command)
    {
        string url = string.Format("http://{0}:{1}/{2}", textBoxServer.Text, textBoxPort.Text, command);
        return url;
    }
    
    private NameValueCollection InitParams()
    {
        var values = new NameValueCollection();
        values["username"] = textBoxUser.Text;
        values["password"] = passwordBox1.Password;
        return values;
    }
    

    My question is: When I add a new channel, it preservies the channel GUID from the config I give it, but the LUA projects receive a new GUID. I’d like to preserve the GUID, so it is always the same. Is there any way to achieve this?

    Or would I have to stop the Iguana service, add the snippet to IguanaConfiguration.xml myself, and start it again? In this case, I could just as well add the LUA code and the milestone by calling fossil manually, and the HTTP API would be kind of pointless for me.

    Hi Roho,

    Not that we know of. We’ve been working with the Channel API a lot ourselves over the last couple of months. So far it hasn’t seemed to be all that critical to make that a constant.

    If you look our Iguana apps with the channel manager:

    http://help.interfaceware.com/section/iguana-apps

    With the channel manager when we serialize out a channel we don’t keep the GUIDs of the translators in the repo. We rename the translator instances based on the name of the channel they are in and the type of translator, for example:

    https://github.com/interfaceware/iguana-web-apps/tree/master/Bed%20Monitor%20-%201.Fake%20ADT%20Feed_from

    At some point we’ll probably tweak things so that we stop exporting the translator GUIDs into the GIT altogether since it just creates noise.

    If you are playing with these APIs I suggest starting with the Channel Manager app:

    http://help.interfaceware.com/kb/a-live-dashboard-showing-er-bed-status

    The Channel Manager app uses this module:

    https://github.com/interfaceware/iguana-web-apps/blob/master/shared/iguana/channel.lua

    We spent a bit of time refactoring that piece down to be a very clean implementation – it identifies the translator instances nicely with the function:

    function iguana.channel.getTranslators(ChannelConfig)

    You give a channel configuration to it and it gives you back a nice hash table of the GUIDs of the associated translator instances with different keys for types. It made it possible to write the export relatively elegantly since we could write code like this:


    local TranList = iguana.channel.getTranslators(NewChanDef)
    os.ts.time()
    for TransType,Guid in pairs(TranList) do
    local Start = os.ts.time()
    local ZipData = BuildTransZip(RepoDir, Definition..'_'..TransType, Guid)
    local EndTime = os.ts.time()
    trace(EndTime-Start)
    os.ts.time()
    Api:importProject{project=ZipData, guid=Guid, sample_data='replace', live=true}
    os.ts.time()
    Api:saveProjectMilestone{guid=Guid, milestone_name='Channel Manager '..os.date(), live=true}
    os.ts.time()
    end

    We put APIs filter.zip.inflate and filter.zip.deflate into Iguana 5.6.5 that do in memory ZIPing and unzipping of the file data from the translators.

    I would recommend working through the channel API over manipulating Fossil directly for a few reasons:

    • You can use the channel API on a live Iguana instance which is pretty sweet for being able to implement things like pushing a channel out to two active-active Iguana instances
    • We’re evolving how the project structure works to make it more flexible and easier to work with. I am hopeful we can actually get the ability for Iguana to work natively with an external repo – GIT would be my first choice since the ecosystem is really impressive – gitHub is pretty amazing.
    • The channel manager is helpful tool moving channels from development, to test and production

    This document gives you a bit of idea of what is possible:

    http://help.interfaceware.com/kb/high-availability-and-promoting-interfaces-from-development-to-test-to-production

    I would recommend you start playing with the channel manager as a starting point. Heads up – Iguana 5.6.6 which being cut today will have the ability to edit the Javascript, CSS and HTML that is used in the projects.

    We’re open to accepting patches into these apps if it almost does what you want with a tweak or two.

    Hi Eliot,

    thank you for the valuable hints! So probably the project GUIDs are not really important. Even in the project import zip file, the folder can be named “00000000000000000000000000000000”, and it works.

    My approach of revision control is to copy the directory Iguana\edit\admin over into the SVN repository and check it in there. (Unfortunately we are stuck with Svn, no chance to use Git any time soon). And there they are again: subdirectories with the project guids! So it would be a small nuisance if the guids are different. But it is not so bad, because most of the code is in the “shared” directory, and the main.lua files seldom change.

    But still, I guess we’ll prefer the channel API over fossil manipulation, for the reasons you mentioned. (Also: Fossil manipulation needs admin rights to write under “C:\Program Files”!)

    Only on our Continuous Integration build server, I don’t think we’ll install a running Iguana instance. There, our MSBuild solution which bakes the SQLite file by hand works fine.

    Also, I’d love to visit you in Toronto, but it’s a bit far away. A pity! Perhaps you plan to visit Europe some time?

    Kind regards

    Robin

    Some time – I get out there now and then… can’t in all places at all times 😉

    That approach will work too.

You must be logged in to reply to this topic.