logo

NJP

Making the Most of the MID Server - Redux

Import · May 28, 2019 · video

good afternoon everyone my name is Mark
Scott I am a senior software engineer for TB consulting and this is making the
most of the mid server redux we will be going over my knowledge 19 presentation
that I gave on utilizing the mid server to do your bidding there will be a live Q&A after this
stream so please go ahead and enter any questions that you have into the chat
and I will make sure that I get to them if I do not you can respond to me on
social media and we will get to your questions
as quickly as we can so without further ado this is making the most of the mid
server sorry about that all right okay like I
said my name is Mark Scott I am a ServiceNow software engineer for TB
consulting I have seven years software development experience in C#, MVC and
Web API I was building enterprise applications for our clients at TB
consulting we decided to switch it up and start a ServiceNow practice and I've
been on ever since I was also a knowledge 17 speaker on source control
and implementing that inside the ServiceNow platform currently I am
delivering some client implementations we're an implementer a TV consulting as
an MSP so we go out and do implementations for our clients and help
them get the most out of their ServiceNow implementations
I'm also tasked with marrying service now and a hyper-converged infrastructure
called Nutanix Nutanix is an all-in-one box that allows you to virtualize
anything within your infrastructure and what we've built is a integration into
Nutanix to pull that information into your asset CMDB and be able to look at
your new technics infrastructure from the ServiceNow side of things if you're
interested in that please let me know we can get you some more information okay
so a little housekeeping here so let's start with our agenda the first thing
that we're gonna go through is all about mid servers so what are they how do they
work and why do we use them we're gonna do some demos I've got two demos for you
today and then we're gonna go over the art of the possible so what what why is
this important and why are we doing this so our first objective let's learn why
mid servers are really awesome I think mid servers are awesome and I
think by the end of this presentation you'll also think that mid servers are
awesome and let's learn a little bit more about what we can do to make them
work inside of our organizations well so learn what makes a mid server why we use
a mid server we'll define and understand the ECC queue and augmenting the mid
server with Java we'll also understand how to communicate
to and from the mid server using that ECC queue so this is a really busy slide this is
mid server 101 so where does the actual mid server sit and how does it work
inside of your firewall so as we can see from this slide your mid server can
connect to Linux infrastructure of desktop infrastructure routers windows
servers you can even put mid servers up into the cloud and allow it to find AWS
infrastructure as your infrastructure one of the cool things about the mid
server though is that it allows you to take on workloads so for example
discovery actually happens through your mid server you place that mid server
behind your firewall you tell discovery what IP ranges you want to scan and that
allows you to pull in all the asset and information about your infrastructure
into your ServiceNow instance so some of the good things that Emmett server can
be used for anything with a long-running transaction so if I've got a long
database query if I've got to go download a file off the internet if I've
got to go make an API call these are excellent uses for the mid server
because it just sits behind our firewall and it can do that work without us tying
up our ServiceNow instance that's really key our ServiceNow instance is doing
good things for us it's taking in our tickets it's hosting our service portal
it's allowing workflows to happen without interruption we don't really
want to push workloads into ServiceNow so that it doesn't function properly
it's not it needs to be able to do the work that it's good at doing which is
taking all that information and aggregating into one place we don't want
to put too much work load on our ServiceNow instances complex functions
so let's say that we have a library or a package that runs without maybe a
JavaScript implementation or there's just no way to call it from within the
platform well we can load that into the mid server and execute that code
remotely and we'll see a couple of examples of that in a few minutes here
anything that the ServiceNow platform cannot do so if there's functionality
that you're just lacking in the ServiceNow platform you can make up for
that with the mid server you can write your own custom code run that on the mid
server and have that initiated and then lastly we
could do some image or video processing anything that again takes a while and
needs to come back we can offload that to the mid server and allow the mid
server to do that function for us so let's talk about some not great use
cases anything the user is waiting on so what we don't want to do is lock up the
UI so that users are waiting for our response to come back if we've got a
long-running process that runs on the mid server last thing we want to do is
the user sitting there waiting and we've got that spinning icon of death also
anything that needs eyeballs since the mid server is headless it's run as a
Java package that sits on top of a server and it doesn't really have any
user interaction we can't have anything so that anything that needs a button
pushed or an approval process anything like that doesn't doesn't work if we're
going to push that payload to the mid server okay this is a very busy slide
but let's not get too bogged down into it the main purpose of this slide is to
show that the ECC queue in the mid server communicate in a very cyclical
fashion so what ends up happening is a record is inserted into the ECC queue
table it has a database listener we can see that about midway through our slide
here that that is pushed into the amb channel now the mid server is always
listening to that a and B channel through the mid server a and B client
that a and B client reads that work in comes down the mid server processes that
it does whatever it's told to do and then at the end of that it pushes it
back into the ECC queue monitor which is here the ECC queue monitor pushes it
back into the ECC queue and then there's another insert into the ECC queue with
the database listener really all this is just a big fancy word for I will insert
records into a table that the mid server will then do work on the mid server will
do the work and the results of that work will then be pushed back into the ECC
queue table okay that's great but how do we actually call the code from the mid
server well it's actually fairly easy so once we've loaded the jar file into
the mid server now a jar file is it's Java code that has been packaged up into
a single executable file and push down what's nice is that the
ServiceNow instance ServiceNow itself doesn't require you to maintain or edit
that keep that code up-to-date in a specific way so what you can do is
actually push that jar file down and it will push to all your mid servers
individually you don't have to update each one you can use the platform to
monitor and manage which packet which code package is being pushed down to the
mid servers so once it's been pushed what we can do is inside of our
JavaScript which is very similar to a mid server script include they're
actually called mid server script includes we can call this packages dot
it's a very special naming convention and basically what happens when I say
packages something is that hey I'm gonna call out
to some extra code that's living on the mid server and I'm gonna call a function
inside of a class now for example this is for a classification for an image and
you can see that the package is called comm dot TV consulting well I start that
off again on this side with the mid server script include down at the bottom
packages comm TV consulting and continue on from there you can see that I call
this classifier of class here that classifier class corresponds to some
code that I have here and then I called this classifier dot classify I actually
have a classify method inside of this code that it's then being called out to
so you can see very quickly how writing a little bit of Java code and then
inserting it into our java script and calling it from your java script we can
actually call out to that code very simply and it makes our jobs a lot
easier so a couple of best practices for doing this I always always always like
to call the Java packages from mid server script includes in fact it's not
just about calling it from a mid server script include but then anything that
I'm calling from that mid server script include I wrap into another script
include and that just makes my code so much more maintainable and one one
single point of failure one single point of anything that I need to go and change
I can go and change that I don't have to worry about making too many edits to
something I and I can reuse that mid server script
include or that script include wherever I needed to go it travels with me I also
have found this the hard way but since the mid server doesn't run a
headed version which means that I don't see anything nothing happens when I when
I execute code it just happens in the background what ends up happening is any
any error messages any informational messages or debugging messages that I
would normally get actually get pushed out to nowhere I don't have any way of
reading that so what I like to do is I like to log all my console messages to a
log file that way when something goes wrong or if I needed to debug something
what I can do is I can open up that log file later read through all my messages
and I can now write about where my code either crashed or if something happened
unexpectedly or if everything worked just fine long running processes need to
run a sink in the background so this is this is less mid server specific and
more just ServiceNow specific right it's always always always good practice to
make sure that your users aren't waiting on the UI so the last thing I want to do
is click a button and then just watch my mouse wheel spin there in a circle so
what what we tend to do a TV consulting is we push all of that logic into an
async business rule or an async task or an async workflow that allows all those
long learning processes to happen and then when they're done I can update any
records that I was editing or manipulating on the fly deploy a dev for
a test mid server now this sounds pretty obvious but I've talked about a lot of
people that just don't do this you know religiously what I what I say
is look Devin tests are made to be broken so I can come through I can make
code I can crash code I can do bad things my mid server can go up or down
without impacting production that's an obvious thing the other thing is we have
a lot of alerts and monitoring well the last thing I need to do in the middle of
the day is take a production outage or trigger an alert that my infrastructure
team then needs to go and debug not knowing that maybe I caused it so always
always always try to deploy at least a dev server if not a dev and a testiment
server so you can put your package your code up
send it down and allow everyone to use that server without causing issues okay
so now we get to the fun part this I have as a demo of my streaming socket
server before we can jump into that though I want to give everyone just a
little tiny bit of perspective so what we're gonna do is we're going to build a
streaming socket server on our mid server this is a little different than
the way a mid server would normally work what happens is the request comes into
our ECC queue the ECC queue then relays that request to the mid server the mid
server then calls into my custom jar package and my custom to our package
creates a thread now the thread opens the Twitter streaming API which allows
me to then take my request and return it back to the ECC queue is completed the
request comes back down to ServiceNow ServiceNow says hey my request is done
and this portion disconnects completely but you'll notice that the thread still
is running on our mid server all right so now a tweets going to come in it's in
a JSON format and we can read all the data from the tweet in in a JSON it's
gonna be pushed down the twitter streaming API twitter dreaming api is
going to alert the thread that's running in my custom jar package on the mid
server that tweet is then going to be emitted back out of the jar file into a
custom api that I've developed in the ServiceNow mid server or I'm sorry in
the ServiceNow platform that tweet will then be ingested and stored in the
ServiceNow database it's pretty simple once you actually start to think about
it but the main problem here is that that thread is always running
so once the mid server disconnects that thread stays alive and can still process
all the information that's coming in from the Twitter streaming API so enough
talk let's see it in action let's switch over to my instance here so I have
Twitter up and running a little premature before we do that so
let's go and start our tweet service here all right so I have a service
management interface here it is incredibly simple to use this it
literally has one button start server so I push this button and that's what's
going to start our request to go out and the mid server will start up its thread
so we can see the Twitter streaming server has started we're going to hit OK
okay so now let's switch to Twitter I'm going to compose a new tweet and what
I'm going to use is the hashtag from my session from knowledge 19 because that's
the special session that's a special hashtag that my thread is looking for
this is really cool give myself a little pat on the back here hit tweet okay so
it's not that sweet anybody that's watching this online right now can
actually go and hit hashtag CCB 1008 nine and your tweets will actually end
up in my ServiceNow instance itself as well all right
let's switch back to ServiceNow so let's look at our tweets here now I've got a
lot of tweets that have come in in the last month or so a lot of these I've
saved because I'm nostalgic from knowledge 19 and you can see this is my
tweet that I just sent so CCB 1089 this is really cool you can see it came from
me and I have this interesting column here
time difference SEC what this actually means is this calculates the time that
it was stored in the Twitter data base then emitted from the Twitter API
streaming API into my mid server and my mid server down into my ServiceNow
instance you can see that it's six point four five seconds my average time for
getting a tweet from Twitter's database into my database is five point seven
four seconds the thing to note here is that this isn't using a polling engine
we're not going and asking Twitter for give me more tweets that have this
hashtag in it I'm not running on a scheduled job these are coming in
near-real-time almost as live as I possibly
so that I can process this much faster if you want to jump into it let's take a
look at the tweet real fast so this is really all that I have I have the entire
JSON payload of that tweet which has all of all the information about my user
about the tweet everything and I parse a couple of that out so I pull the content
out I pull the username out this tweet is an auto-generated number that I have
from the ServiceNow instance and I'm calculating the time in seconds here and
that's about it so that's that's getting Twitter into the ServiceNow interface
very quickly very fast and utilizing the mid server and not the platform all
right okay so the next little demo that I have for you is actually modeled off
of a TV show so one of my favorite shows is called Silicon Valley it's from HBO
and one of the things that they do on that show which is really really cool in
my opinion is they actually build an app that can categorize whether or not an
image taken on a cell phone is a hot dog or not a hot dog they call it oddly
enough not hot dog so when looking for this presentation I tried to figure out
well I'm not a data scientist how can I build a machine learning algorithm into
the ServiceNow platform without too much hassle well what I decided to build was
a not hot dog classifier all right so let's take a look at it so what we're
gonna do is we're gonna go to our incident table here and I'm gonna look
for open incidents I'll scroll through a couple here let's see okay so let's open
this incident incident number two okay so on my desktop what I have is
probably the most interesting subfolder in the world it is literally just called
hot dogs and what we're going to do is we're going to take one of these hot dog
images we'll take this one right here and we're going to pull that over and
we're gonna upload it into my incident and what this is gonna do is this is
going to take all the bytes from that image it's going to push them over to
the mid server that I have running the mid server is going to run a machine
learning algorithm to see is this a hot dog or not and it's gonna return those
results to my ticket here and as we can see I actually have the most interesting
ITSM system in the world I have a sub a sub section here called hot dog I can
click on this sub section here and I have two two little variables here my
first one is my favorite variable that I ever created it's called hot dog
confidence and what this does is this takes that that value that was returned
back from the mid server and it is a hundred percent right now so I am one
hundred percent of hot dog it knows exactly what this is and in case it
wasn't super super obvious to you have this is hot dog check box here so if my
hot dog confidence is over a certain level I have a check box that gets
checked is hot dog and that has been checked as we updated or uploaded this
totem all right let's try it again let's dig we can find a different one so
I've got let's do here's a hot dog with some toppings here so let's pull this
over and we'll upload this and give it a second to upload and again it's going
out to the mid server the mid server is doing this classification it's coming
back and that hot dog confidence is ninety eight point eight eight so it is
still a hot dog well that's great how do we know that I didn't just train these
four hot dogs and I keep uploading hot dogs well I have the second most
interesting sub folder in the world not hot dogs all right so we've got a couple
of food items to pick from here so I'm gonna I'm gonna pick hamburger here this
hamburger looks good pull that over and upload that into my ticket as an
attachment we're gonna watch as it uploads and
classifies and comes back so we see here very quickly the hot dog
confidence on that hamburger was actually less than 1%
so we've unchecked our box here all right mark that's cool but how do I know
that you didn't just machine learning algorithm food all right so this is me
this is my mr. peanut picture I have a great great story about being explicit
versus implicit that leads into this picture I welcome anyone to ask me that
I can tell the story later so let's see if I'm a hot dog so let's pull this down
I'm gonna upload this one more time here and we're gonna say but I am one point
zero eight percent hot dog which is probably more than I would like to be I
would ideally like to be zero percent but this does pretty good as well so you
can see it's unchecked our hot dog box and kept that unchecked as well all
right all right all right let's see let's try to trick it okay so this is a
falcon heavy rocket and I guess it's kind of in the shape of a hot dog right
it's long and cylindrical so let's pull that over and see if that gives us any
different results all right so a falcon heavy rocket is actually less of a hot
dog than I am who knew okay so we've proved our point let's go back so the art of the possible
here so that's great we've we built this super fast
Twitter integration into ServiceNow but why would that matter to me well one of
the big trends right now is getting help online so how do you get help online a
lot of times there's a phone number sometimes a form to fill out but I I've
actually run into a few companies now where I have to actually message them on
either Facebook Twitter or some sort of social network well if you're a company
that is pushing your customer service representatives that that way maybe you
want to know exactly what kind of tickets are coming in maybe you want to
up a ticket and allow that ticket to open
tickets from Twitter or Facebook you can do that very very very quickly which
allows that that that CSR to get on that problem faster so if you have a problem
with the service you have an outage potentially you can you can be the first
to know about that from from Twitter or Facebook social messaging all right so
let's keep going so what about the hot dog thing what a
great funny demo but who cares well one of the big problems right now that we're
seeing in Europe especially has just passed article 13 which says that you
will not be hosting any copyrighted images on any internet-connected
platform that would include ServiceNow so how do we know that we aren't
uploading copyrighted material into our ServiceNow instances aside from that how
do we know that potentially the attachments that people are uploading
may not be work appropriate we may actually have explicit content being
uploaded into our ServiceNow instances and not know about it which would be
unfortunate so we can actually build these machine learning algorithms and
these image processing capabilities and push them down into our mid server and
allow them to classify those images and determine if they are explicit or not
and finally putting all of this together potentially what we could do is we could
pull these tweets in from Twitter or pull in direct messages anything from
any social media platform we can then take take that and run machine learning
algorithms and do sentiment analysis they are people generally happy with our
product are people mad is there an outage do we have something going on and
we can bubble those up to the top as more important tickets that need to be
addressed then the hey I really love your product okay so that's that's it
that's all I have for you guys today I'd like to thank you for joining and
what I'm gonna do now is I'm going to switch over and see if there are any
questions in the chat which I will check now and I don't see any so
with that I am going to end this dream and I thank you guys for attending if
you have more questions please reach out my social media information is at the
end of this deck on top of my email address so if you have questions please
let me know I'd love to hear from you thank you very much you you

View original source

https://www.youtube.com/watch?v=VQvzYNKcOk0