Knowledge 19 - CCB1089 Making the Most of the MID Server
okay well good morning I am mark Scott I am a senior software engineer with TV consulting when most people meet me they say two things the first one is hey you're a man with two first names actually I have three but when I introduce myself as Mark Eric Scott people think I'm a serial killer the second thing is do you know you look like Seth Rogen and the answer is painfully yes all right so this is making the most of the mid server if you're a project manager you're probably not supposed to be here this is the safe harbor notice this is the IT equivalent of some side effects they happen I have to say this I hate these things but everything I say is 100% true just kidding all right so this is me I am a software developer mainly in the C sharp MVC Web API I've been doing that for about seven years three years on ServiceNow platform I love it and I was a speaker at knowledge seventeen if you guys remember on source control right now I'm working on delivering some client implementations TB consulting is an MSP we helped implement for our clients and I'm marrying service now with the hyper-converged infrastructure called Nutanix if you want to learn more about that we've got booth and this is my mr. peanut picture I have a great story about this when I did this when I originally did my talk Brett all occur said hey you have to tell this story so a few years ago I worked for a start-up we were series a funded working on series B we had a lot of those deaf Cowboys I was one of them the the HR lady came into our office and said hey we're having the employee pictures taken please dress your best and I said what does that mean because I'm a smart ass software developer and she said just look nice and I said okay and I went out and I bought a top hat monocle three-piece suit and not pictured is the cane and I took that picture i sat down in front of the photographer and I said this is what I'm wearing and they said ha ha ha now take it off I said no and they said well we've got investors coming to see the company directory and I said who do you think is writing the software for the company directory and she kind of looked at me mouths gape and I said it's gonna happen one of two ways I'm either going to hard-code it in or you're going to let it happen but either way it's going in there it made it in there again we have a booth at p7 if you want to learn a little bit more of a practical application of what you're about to learn today we have a product called NX fusion and it's helping us integrate with Nutanix all right so quick agenda I love mid servers so if you don't know all the functionality of a mid server that's ok I'm gonna go over that today I'm also got a couple of demos and then we're gonna go over the art of the possible it's a lot of what we're gonna do is a little abstract ok so again we'll learn why mid servers are awesome and what they can do to make them work for you why we use it will define and understand the ECC queue will augment some of the stuff with some Java and we'll understand how to communicate to and from our ServiceNow instances to our mid servers alright a little mid server number one 101 raise your hand if you know what mid stands for yeah not a lot men image mint instrumentation and discovery that's what the mid server stands for I always thought it was because it was between your firewall and your ServiceNow instance it actually stands for our management instrument in instrumentation and discovery I can run as a Windows service or a UNIX daemon it sits behind your organization's firewall and allows you to talk to applications that you may not want to expose out to the Internet keep on your corporate write in your corporate network without traversing the Internet this slide is really cool because you can see that you can actually stick mid servers in the cloud and run discovery on cloud you can put them inside your firewall you can them anywhere they can discover desktops routers windows servers anything they're really really great at doing discovery and that's what most people use them for it is also a java application so you don't have to worry about installing a whole bunch of drivers or custom custom code from ServiceNow they have this one package that it's down to you very quick install I've done it in ten minutes or less it's very quick to stand up and you can have as many as you want no licensing implications you can put as many into your network and you don't have to pay for each one you get those for free all right so what are some good things that we can use the mid server for so long running transactions anything that has to go to a database and pull a whole bunch of information back anything that runs a complex function or super interesting code or something that you just can't get done with the JavaScript or workflow inside of the platform and again so again things that the platform can't do you could even do image or video processing and we'll see a little tiny bit of that in one of my demos today so the bad anything the user is waiting on will learn why the ECC queue is actually not a very quick process and anything that needs i've also the mid server runs headless you can't see what's going on there's no graphical user interface to interact with it so anything that needs human eyeballs you have to scrap that idea to use the mid server so this is a very busy slide but this is stolen straight from a ServiceNow presentation this is exactly how the ECC queue and the mid server interact the main focus here is that it's cyclical everything goes into the ECC queue database table the AMD channel pulls that out pushes it into a listener that runs on the mid server the mid server queues that work to be done it comes back into the ECC queue saying that yes I have completed this work and finally it writes that into the table again very very very there's a lot of code going on in this that you don't have to worry about when you're when you start delving into mid server architecture okay these are the Java packages so this is literally code that you can write inside of Java and Eclipse IDE any any IDE that writes Java you can write this code package it into what's called a jar file and then you can ship that jar file down to your mid server using the ServiceNow interface you don't have to log on to each individual mid server you can actually just upload as an attachment and it will distribute to all the Midd servers in your network automatically if you need to do an update again attach it as an attachment everything goes down to the mid server you don't have to manage it ServiceNow has taken that away from you you don't have to worry about it anymore it has to run or return something to the ECC queue and that has to be something serializable that's a programmer term for data it's data that I can consume so is it a string which is just numbers and letters is it JSON or bytes or it could be nothing maybe it's set it and forget it we're just gonna push it to the mid server run that code and let it go the main thing here to notice is this packages packaged up at the top there that allows you to name and namespace all of your code then when you get down to it you have your class and you can instantiate your class using that packages using the packages directive down at the bottom there in the JavaScript where you start with mid server script includes you can actually call Java code from JavaScript inside the ServiceNow package as long as it's loaded into the mid server Oh a couple of best practices we always want to call Java packages from mid server script includes I am a huge fan of script includes my entire team puts all of our logic and script includes because it makes it reusable we can use them anywhere doesn't matter we can call them from client site we can call them from server side mid server script includes work very much the same way I can call that script include from any other part in my code and return results if needed this is kind of my own personal best practice but I like to log all my console messages to a log file so one of the things to really kind of wrap your head around is that when you install custom code into a mid server it's running on the mid server it's not running in your ServiceNow instance so when I do a console dot log or a print out or any any one of those functions that would give me some debug information it lives on the mid server so what I like to do is I like to have the Java package actually say all my logging calls write them to a file and then later when I'm very frustrated and I have to actually jump on the server I can look through that and see what the heck was going on with my code at that time long running processes so long running processes need to run async that's just a basic fundamental understanding of what the ServiceNow platform does and software development practices in general don't lock the UI don't make the users sit there and wait with that little spinning icon it doesn't make any sense let those things run in the background let them update the the the tickets or the the records that you have without making the user wait for it work that into your workflows and I this one just seems so so really obvious to me but I wanted to put it up here anyway deploy a dev or a test mid server if whenever you're doing anything with code that doesn't even mean mid server always have a dev or a test we don't like to run code in production we don't like to change code in production that's why we have change we have to make sure that we have a good place set up where we can run all of the code without worrying about it coming down or impacting business okay now we're gonna get into some demos my first demo is building a streaming socket server so when I set out on this I'm like well I need data where am I going to get this data from Twitter if you know me and I know I have a couple of my Twitter followers in here I love Twitter I'm constantly on and the best way I can figure out to come up with a bunch of data is to get you guys involved so in a few minutes here I'm going to throw up a hashtag I'd like you to hash send some tweets out if you have twitter with that hashtag but first let's do some perspective so this isn't really a typical setup for the mid server initially I have a request that goes out that says hey can you please spin up this new streaming socket server cool the ECC queue takes that processes it and pushes it into my mid server my mid server being smart enough to call my packages on my jar file calls out to my jar file that request creates a brand new thread that thread stays alive for the course of this cycle my request comes back to the ECC queue saying hey I'm done that request goes back into my service now tables and that portion disconnects completely so now I have this thread running out there on this server and ServiceNow doesn't have to know anything about it it's just running finally we'll have your guys as tweets come in there in the JSON format it'll go into this footer streaming API that Twitter controls it will then be emitted into my streaming socket server where I then push it into a custom API that I have developed on ServiceNow and then into my tables so let's see it so this is the hashtag it's the name of the session or the the code of the session so what we're gonna do switch over to my ServiceNow instance here alright so we're gonna go Twitter and I have this server management UI page it does one thing it has one button it's a beautiful user interface if you guys need training on this see me after I'm gonna click the button it says start server Twitter streaming server was started that's it so I'm going to our tweets so you can see it's actually been capturing a lot of these for quite a while so I'm gonna go ahead and tweet one out right now and please if you guys are tweeting as well do it do it do so alright like mine sent there and hit refresh whoo look at that a lot of you guys that's awesome thank you all right so you can see I've got this number here I call this time difference in seconds and what I'm doing is I'm actually keeping a rolling average so what this does is I count the time that the tweet hit Twitter's database there's a time stack rated time stamp on that that gets emitted into my API my API then uses the created day time to do a difference 5.7 seconds using the mid server and a streaming socket server I can get your tweets in in five seconds no polling no asking Twitter hey give me more no deduplication and none of it we're just pulling all these in near-real-time from the mid server do one more refresh and see if we got anybody else I'd like to also shout out to my wife who is at home right now my mid server runs in my garage and I have a full 40 year AK in my garage with like this one block of compute the compute block maybe overpowering the circuit in my house so she can't microwave anything between 10 a.m. and 11 a.m. when my demos done so I would I would like for you guys to you know tweet some good things about my sessions so that I can say look honey it was all worth it okay cool that was fun all right my next demo here is the I messed these slides up that's alright so the next demo here is a little bit of machine learning can anyone tell me or raise your hand if you know the difference or what is the true difference between machine learning and AI anybody want to take a stab at that okay so the true the true blue difference between AI and machine learning is that machine learning is written either in R or Python by a software developer ai is written in PowerPoint by your sales team so whoever that was that's totally stole my thunder you get a prize we've got some swag bags please go pick that up because I was not expecting that but hey I'm not a total failure I can still be used as a bad example alright so what I have written is an integration into ServiceNow now how many of you guys are fans with a Silicon Valley show or I'm sorry the HBO show Silicon Valley okay yeah is anybody slightly offended by that show because you may want to avert your eyes so one of the things that they build on that show is an app and the app is called a seafood it was based on an app that was created earlier in the season called not hot dog it was an AI algorithm that could go out and classify your food was a hot dog or not I'm not a data scientist so when I submitted this first of all I submitted this session as kind of a joke because I wanted to pack as many buzzwords into it as possible and I knew the machine learning would peak interest then it was selected and I had to figure out what the heck I was going to do so I took I took the nut hot dog concept and integrated it into ServiceNow so all right so what I have is well let's let's step back for just a little bit because I want to explain how this works so what R is is R as a it's just a language it's a scripting language very similar to JavaScript in in the sense that it's more towards machine learning and and and building machine learning algorithms what's kind of weird about R is there's no real way it's not like a program it's not compiled so you have to call to it so my mid server actually calls to the R script file and that's how it does its classification and again this is the mid server that's sitting in my garage that's preventing my wife from microwaving her breakfast so I have my incidence table here alright so let's find an incident and I'm working with all the demo data so let's go to this one and what I have pull this over onto my screen here is I have the weirdest subdirectory ever it's called hot dogs and if my IT people are watching this and and like they're seeing what's happening on my screen right now please don't judge me too harshly so what we're gonna do is we're going to upload a hot dog as an attachment so let's pick one here I pick this one with mustard that one looks good we're gonna plop it right on our interface so what's going on right now is this is going into this attachments table assistant table has a business rule on it that says hey when I see an upload come in give me all the data pipe it out to the mid server the mid server will go to my our script run the analysis to determine if this is a hot dogger not turn it all back there's a business rule that says hey when you're done with this update the ticket and I have the most interesting incident management system in the world because I have a hot dog subsection here so we have two fields hot dog confidence we are 100% confident that's a hot dog good news and just in case you didn't get it there's a checkbox on the other side that says is hot dog so we've got you covered well that's great but how do I know not that just everything comes back with a hot dog all right well I have the second most interesting subdirectory in my computer not hot dogs good news I'm not but we'll all prove it so let's go let's grab a hamburger because the opposite of hot dog is always hamburger we're gonna upload this and what's gonna happen is it's gonna go back to the mid server do some classification and it's gonna come back as soon as it uploads wait for it there it is and hot dog confidence is now under 1% so we've uncheck the box that's it all right so what all right maybe yeah maybe I've trained it for hot dogs and hamburgers let's just make sure here's a falcon heavy rocket it kind of looks like a hot dog maybe I'll trip up my AI now there it is so it's less than 1% that it is sure that is a hot dog all right so I guess I'll do me I will hope that I do not come back and my AI is wrong because that would be very embarrassing okay so apparently I'm a little more of a hot dog than a falcon heavy rocket who knew all right so great cool story that it's fun we had some laughs who cares well one of the things that I've seen a lot of companies doing is they're pushing pushing pushing pushing towards their service or their support staff being on social media has anybody ever put a ticket in with Spotify yeah because you have to tweet them you have to send them a DM you have to get them involved on social media they don't have a 1-800 number that I know of or a support email address that I can find so everybody's on social media what does that mean for you guys well if I can get to the people faster if I can pull those tweets in faster I know what the heck's going on I know that if my clients are mad or saying there's a service down a product offering that isn't working and they're tweeting about it I can actually pull that into my ServiceNow instance much faster I don't have to wait five 10 15 minutes after they've tweeted I can get to them very very quickly CSR's are going to be using social media now to be pulling that in you want to smash the two examples together what about if I took all the twit the tweets that were coming in about my company and I put them through some sort of machine learning some sentiment analysis it made me very happy to see that in the keynote the other day we could actually get a gauge on how our our customers are feeling about a product and offering a hashtag anything we could start pulling those analytics into our ServiceNow system and actually triaging them as incidents or events so yeah cool but what's the hot dog thing have to do with it well the app in Silicon Valley eventually became an explicit image filter how many of you with confidence can say that there isn't anything unsavory uploaded into your sis attachments table I can't why are we not doing this analysis on these things Europe just passed article 13 how many of you know if your instance is house is house ting housing copyrighted material and you're doing business in Europe it's going to come up so we can start applying these machine learning concepts we can start moving these workloads out to the mid server and doing a lot with them we can start doing these image manipulation we can do daemon or anything you can think of a little bit of java code and put it on your mid server and run a payload through it and what comes back is important it's very valuable to your business all right so submit the surveys I jokingly said if no one submitted the survey I could then submit a five and automatically give myself a five but that's up to you social experiment I wanted to say thank you thank you guys for coming thank you for making it all the way up to this ballroom I know that's not a short Trek and thank you for having me I'll take questions if you guys have questions or we can let you guys have a couple minutes back you you
https://www.youtube.com/watch?v=lMoLIy19lKY